From 1d68e27558f0921f990e4e6eb1cc7d42def4b649 Mon Sep 17 00:00:00 2001 From: mvidelgauz Date: Sun, 2 Feb 2020 17:22:05 +0200 Subject: [PATCH] Added DockAreaHasTabsMenuButton and DockAreaHasUndockButton to CDockManager config (#108) * Added DockAreaHasUndockButton and DockAreaHasTabsMenuButton configuration flag --- demo/MainWindow.cpp | 9 +++++- src/DockAreaTitleBar.cpp | 63 +++++++++++++++++++++++++--------------- src/DockManager.h | 8 +++++ 3 files changed, 55 insertions(+), 25 deletions(-) diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index 8f1567f..8abd4db 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -418,12 +418,19 @@ CMainWindow::CMainWindow(QWidget *parent) : // comment the following line if you want to use opaque undocking and // opaque splitter resizing CDockManager::setConfigFlags(CDockManager::DefaultNonOpaqueConfig); - //CDockManager::setConfigFlag(CDockManager::DockAreaHasCloseButton, false); // uncomment the following line if you want a fixed tab width that does // not change if the visibility of the close button changes //CDockManager::setConfigFlag(CDockManager::RetainTabSizeWhenCloseButtonHidden, true); + // uncomment the following line if you don't want close button on DockArea's title bar + //CDockManager::setConfigFlag(CDockManager::DockAreaHasCloseButton, false); + + // uncomment the following line if you don't want undock button on DockArea's title bar + //CDockManager::setConfigFlag(CDockManager::DockAreaHasUndockButton, false); + + // uncomment the following line if you don't want tabs menu button on DockArea's title bar + //CDockManager::setConfigFlag(CDockManager::DockAreaHasTabsMenuButton, false); // Now create the dock manager and its content d->DockManager = new CDockManager(this); diff --git a/src/DockAreaTitleBar.cpp b/src/DockAreaTitleBar.cpp index 4096b1e..9db076c 100644 --- a/src/DockAreaTitleBar.cpp +++ b/src/DockAreaTitleBar.cpp @@ -167,38 +167,53 @@ DockAreaTitleBarPrivate::DockAreaTitleBarPrivate(CDockAreaTitleBar* _public) : void DockAreaTitleBarPrivate::createButtons() { QSizePolicy ButtonSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); - // Tabs menu button - TabsMenuButton = new tTitleBarButton(); - TabsMenuButton->setObjectName("tabsMenuButton"); - TabsMenuButton->setAutoRaise(true); - TabsMenuButton->setPopupMode(QToolButton::InstantPopup); - setTitleBarButtonIcon(TabsMenuButton, QStyle::SP_TitleBarUnshadeButton, ads::DockAreaMenuIcon); - QMenu* TabsMenu = new QMenu(TabsMenuButton); + + if (testConfigFlag(CDockManager::DockAreaHasTabsMenuButton)) + { + // Tabs menu button + TabsMenuButton = new tTitleBarButton(); + TabsMenuButton->setObjectName("tabsMenuButton"); + TabsMenuButton->setAutoRaise(true); + TabsMenuButton->setPopupMode(QToolButton::InstantPopup); + setTitleBarButtonIcon(TabsMenuButton, QStyle::SP_TitleBarUnshadeButton, ads::DockAreaMenuIcon); + QMenu* TabsMenu = new QMenu(TabsMenuButton); #ifndef QT_NO_TOOLTIP - TabsMenu->setToolTipsVisible(true); + TabsMenu->setToolTipsVisible(true); #endif - _this->connect(TabsMenu, SIGNAL(aboutToShow()), SLOT(onTabsMenuAboutToShow())); - TabsMenuButton->setMenu(TabsMenu); + _this->connect(TabsMenu, SIGNAL(aboutToShow()), SLOT(onTabsMenuAboutToShow())); + TabsMenuButton->setMenu(TabsMenu); #ifndef QT_NO_TOOLTIP - TabsMenuButton->setToolTip(QObject::tr("List all tabs")); + TabsMenuButton->setToolTip(QObject::tr("List all tabs")); #endif - TabsMenuButton->setSizePolicy(ButtonSizePolicy); - TopLayout->addWidget(TabsMenuButton, 0); - _this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)), - SLOT(onTabsMenuActionTriggered(QAction*))); + TabsMenuButton->setSizePolicy(ButtonSizePolicy); + TopLayout->addWidget(TabsMenuButton, 0); + _this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)), + SLOT(onTabsMenuActionTriggered(QAction*))); + } + else + { + TabsMenuButton = new CInvisibleButton(); + } - // Undock button - UndockButton = new tTitleBarButton(); - UndockButton->setObjectName("undockButton"); - UndockButton->setAutoRaise(true); + if (testConfigFlag(CDockManager::DockAreaHasUndockButton)) + { + // Undock button + UndockButton = new tTitleBarButton(); + UndockButton->setObjectName("undockButton"); + UndockButton->setAutoRaise(true); #ifndef QT_NO_TOOLTIP - UndockButton->setToolTip(QObject::tr("Detach Group")); + UndockButton->setToolTip(QObject::tr("Detach Group")); #endif - setTitleBarButtonIcon(UndockButton, QStyle::SP_TitleBarNormalButton, ads::DockAreaUndockIcon); - UndockButton->setSizePolicy(ButtonSizePolicy); - TopLayout->addWidget(UndockButton, 0); - _this->connect(UndockButton, SIGNAL(clicked()), SLOT(onUndockButtonClicked())); + setTitleBarButtonIcon(UndockButton, QStyle::SP_TitleBarNormalButton, ads::DockAreaUndockIcon); + UndockButton->setSizePolicy(ButtonSizePolicy); + TopLayout->addWidget(UndockButton, 0); + _this->connect(UndockButton, SIGNAL(clicked()), SLOT(onUndockButtonClicked())); + } + else + { + UndockButton = new CInvisibleButton(); + } if (testConfigFlag(CDockManager::DockAreaHasCloseButton)) { diff --git a/src/DockManager.h b/src/DockManager.h index a81bbcc..c44dc84 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -157,17 +157,25 @@ public: DragPreviewShowsContentPixmap = 0x0800,///< If opaque undocking is disabled, the created drag preview window shows a copy of the content of the dock widget / dock are that is dragged DragPreviewHasWindowFrame = 0x1000,///< If opaque undocking is disabled, then this flag configures if the drag preview is frameless or looks like a real window AlwaysShowTabs = 0x2000,///< If this option is enabled, the tab of a dock widget is always displayed - even if it is the only visible dock widget in a floating widget. + DockAreaHasUndockButton = 0x4000, //!< If the flag is set each dock area has an undock button + DockAreaHasTabsMenuButton = 0x8000, //!< If the flag is set each dock area has a tabs menu button DefaultConfig = ActiveTabHasCloseButton | DockAreaHasCloseButton + | DockAreaHasUndockButton + | DockAreaHasTabsMenuButton | OpaqueSplitterResize | XmlCompressionEnabled | OpaqueUndocking, ///< the default configuration DefaultNonOpaqueConfig = ActiveTabHasCloseButton | DockAreaHasCloseButton + | DockAreaHasUndockButton + | DockAreaHasTabsMenuButton | XmlCompressionEnabled | DragPreviewShowsContentPixmap, ///< the default configuration for non opaque operations NonOpaqueWithWindowFrame = ActiveTabHasCloseButton | DockAreaHasCloseButton + | DockAreaHasUndockButton + | DockAreaHasTabsMenuButton | XmlCompressionEnabled | DragPreviewShowsContentPixmap | DragPreviewHasWindowFrame ///< the default configuration for non opaque operations that show a real window with frame