diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index 864ad14..c2de95d 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -56,6 +56,7 @@ #include #include #include +#include #ifdef Q_OS_WIN #include @@ -129,7 +130,7 @@ static void appendFeaturStringToWindowTitle(ads::CDockWidget* DockWidget) */ static QIcon svgIcon(const QString& File) { - // This is a workaround, because because in item views SVG icons are not + // This is a workaround, because in item views SVG icons are not // properly scaled an look blurry or pixelate QIcon SvgIcon(File); SvgIcon.addPixmap(SvgIcon.pixmap(92)); @@ -180,6 +181,18 @@ static ads::CDockWidget* createEditorWidget(QMenu* ViewMenu) DockWidget->setIcon(svgIcon(":/adsdemo/images/edit.svg")); DockWidget->setFeature(ads::CDockWidget::CustomCloseHandling, true); ViewMenu->addAction(DockWidget->toggleViewAction()); + + QMenu* OptionsMenu = new QMenu(DockWidget); + OptionsMenu->setTitle(QObject::tr("Options")); + OptionsMenu->setToolTip(OptionsMenu->title()); + OptionsMenu->setIcon(svgIcon(":/adsdemo/images/custom-menu-button.svg")); + auto MenuAction = OptionsMenu->menuAction(); + // The object name of the action will be set for the QToolButton that + // is created in the dock area title bar. You can use this name for CSS + // styling + MenuAction->setObjectName("optionsMenu"); + DockWidget->setTitleBarActions({OptionsMenu->menuAction()}); + return DockWidget; } diff --git a/demo/demo.qrc b/demo/demo.qrc index 52735dd..d6c2a52 100644 --- a/demo/demo.qrc +++ b/demo/demo.qrc @@ -9,5 +9,6 @@ images/date_range.svg images/edit.svg images/grid_on.svg + images/custom-menu-button.svg diff --git a/demo/images/custom-menu-button.svg b/demo/images/custom-menu-button.svg new file mode 100644 index 0000000..fde0535 --- /dev/null +++ b/demo/images/custom-menu-button.svg @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Jemis Mali + + + + + diff --git a/src/DockAreaTabBar.cpp b/src/DockAreaTabBar.cpp index f70f75b..73f9f39 100644 --- a/src/DockAreaTabBar.cpp +++ b/src/DockAreaTabBar.cpp @@ -576,7 +576,6 @@ void CDockAreaTabBar::closeTab(int Index) { return; } - //Tab->hide(); emit tabCloseRequested(Index); } @@ -643,5 +642,6 @@ eDragState CDockAreaTabBar::dragState() const } // namespace ads + //--------------------------------------------------------------------------- // EOF DockAreaTabBar.cpp diff --git a/src/DockAreaTitleBar.cpp b/src/DockAreaTitleBar.cpp index 0c8347d..8aa096c 100644 --- a/src/DockAreaTitleBar.cpp +++ b/src/DockAreaTitleBar.cpp @@ -70,6 +70,7 @@ struct DockAreaTitleBarPrivate CDockAreaTabBar* TabBar; bool MenuOutdated = true; QMenu* TabsMenu; + QList DockWidgetActionsButtons; /** * Private data constructor @@ -188,7 +189,6 @@ void DockAreaTitleBarPrivate::createButtons() _this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)), SLOT(onTabsMenuActionTriggered(QAction*))); - // Undock button UndockButton = new CTitleBarButton(testConfigFlag(CDockManager::DockAreaHasUndockButton)); UndockButton->setObjectName("undockButton"); @@ -361,11 +361,39 @@ void CDockAreaTitleBar::onCurrentTabChanged(int Index) return; } + CDockWidget* DockWidget = d->TabBar->tab(Index)->dockWidget(); if (d->testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab)) { - CDockWidget* DockWidget = d->TabBar->tab(Index)->dockWidget(); d->CloseButton->setEnabled(DockWidget->features().testFlag(CDockWidget::DockWidgetClosable)); } + + if (!d->DockWidgetActionsButtons.isEmpty()) + { + for (auto Button : d->DockWidgetActionsButtons) + { + d->TopLayout->removeWidget(Button); + delete Button; + } + d->DockWidgetActionsButtons.clear(); + } + + auto Actions = DockWidget->titleBarActions(); + if (Actions.isEmpty()) + { + return; + } + + int InsertIndex = 2; + for (auto Action : Actions) + { + auto Button = new CTitleBarButton(true, this); + Button->setDefaultAction(Action); + Button->setAutoRaise(true); + Button->setPopupMode(QToolButton::InstantPopup); + Button->setObjectName(Action->objectName()); + d->TopLayout->insertWidget(InsertIndex++, Button, 0); + d->DockWidgetActionsButtons.append(Button); + } } diff --git a/src/DockWidget.cpp b/src/DockWidget.cpp index e6220a0..3080a62 100644 --- a/src/DockWidget.cpp +++ b/src/DockWidget.cpp @@ -80,6 +80,7 @@ struct DockWidgetPrivate QSize ToolBarIconSizeDocked = QSize(16, 16); QSize ToolBarIconSizeFloating = QSize(24, 24); bool IsFloatingTopLevel = false; + QList TitleBarActions; /** * Private data constructor @@ -817,6 +818,20 @@ bool CDockWidget::closeDockWidgetInternal(bool ForceClose) } +//============================================================================ +void CDockWidget::setTitleBarActions(QList actions) +{ + d->TitleBarActions = actions; +} + + +//============================================================================ +QList CDockWidget::titleBarActions() const +{ + return d->TitleBarActions; +} + + } // namespace ads //--------------------------------------------------------------------------- diff --git a/src/DockWidget.h b/src/DockWidget.h index b5e2681..dd0edb1 100644 --- a/src/DockWidget.h +++ b/src/DockWidget.h @@ -401,6 +401,22 @@ public: */ QSize toolBarIconSize(eState State) const; + /** + * Set the actions that will be shown in the dock area title bar + * if this dock widget is the active tab. + * You should not add to many actions to the title bar, because this + * will remove the available space for the tabs. If you have a number + * of actions, just add an action with a menu to show a popup menu + * button in the title bar. + */ + void setTitleBarActions(QList actions); + + /** + * Returns a list of actions that will be inserted into the dock area title + * bar if this dock widget becomes the current widget + */ + virtual QList titleBarActions() const; + #ifndef QT_NO_TOOLTIP /**