diff --git a/src/DockAreaTabBar.cpp b/src/DockAreaTabBar.cpp index 91a511c..89edc6f 100644 --- a/src/DockAreaTabBar.cpp +++ b/src/DockAreaTabBar.cpp @@ -170,6 +170,7 @@ void CDockAreaTabBar::setCurrentIndex(int index) emit currentChanging(index); d->CurrentIndex = index; d->updateTabs(); + updateGeometry(); emit currentChanged(index); } diff --git a/src/DockAreaTitleBar.cpp b/src/DockAreaTitleBar.cpp index 2af7860..3bfdc3c 100644 --- a/src/DockAreaTitleBar.cpp +++ b/src/DockAreaTitleBar.cpp @@ -66,7 +66,7 @@ struct DockAreaTitleBarPrivate QPointer TabsMenuButton; QPointer UndockButton; QPointer CloseButton; - QBoxLayout* TopLayout; + QBoxLayout* Layout; CDockAreaWidget* DockArea; CDockAreaTabBar* TabBar; bool MenuOutdated = true; @@ -212,7 +212,7 @@ void DockAreaTitleBarPrivate::createButtons() TabsMenuButton->setMenu(TabsMenu); internal::setToolTip(TabsMenuButton, QObject::tr("List all tabs")); TabsMenuButton->setSizePolicy(ButtonSizePolicy); - TopLayout->addWidget(TabsMenuButton, 0); + Layout->addWidget(TabsMenuButton, 0); _this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)), SLOT(onTabsMenuActionTriggered(QAction*))); @@ -223,7 +223,7 @@ void DockAreaTitleBarPrivate::createButtons() internal::setToolTip(UndockButton, QObject::tr("Detach Group")); internal::setButtonIcon(UndockButton, QStyle::SP_TitleBarNormalButton, ads::DockAreaUndockIcon); UndockButton->setSizePolicy(ButtonSizePolicy); - TopLayout->addWidget(UndockButton, 0); + Layout->addWidget(UndockButton, 0); _this->connect(UndockButton, SIGNAL(clicked()), SLOT(onUndockButtonClicked())); // Close button @@ -241,7 +241,7 @@ void DockAreaTitleBarPrivate::createButtons() } CloseButton->setSizePolicy(ButtonSizePolicy); CloseButton->setIconSize(QSize(16, 16)); - TopLayout->addWidget(CloseButton, 0); + Layout->addWidget(CloseButton, 0); _this->connect(CloseButton, SIGNAL(clicked()), SLOT(onCloseButtonClicked())); } @@ -250,7 +250,8 @@ void DockAreaTitleBarPrivate::createButtons() void DockAreaTitleBarPrivate::createTabBar() { TabBar = new CDockAreaTabBar(DockArea); - TopLayout->addWidget(TabBar); + TabBar->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); + Layout->addWidget(TabBar); _this->connect(TabBar, SIGNAL(tabClosed(int)), SLOT(markTabsMenuOutdated())); _this->connect(TabBar, SIGNAL(tabOpened(int)), SLOT(markTabsMenuOutdated())); _this->connect(TabBar, SIGNAL(tabInserted(int)), SLOT(markTabsMenuOutdated())); @@ -314,18 +315,16 @@ CDockAreaTitleBar::CDockAreaTitleBar(CDockAreaWidget* parent) : d->DockArea = parent; setObjectName("dockAreaTitleBar"); - d->TopLayout = new QBoxLayout(QBoxLayout::LeftToRight); - d->TopLayout->setContentsMargins(0, 0, 0, 0); - d->TopLayout->setSpacing(0); - setLayout(d->TopLayout); + d->Layout = new QBoxLayout(QBoxLayout::LeftToRight); + d->Layout->setContentsMargins(0, 0, 0, 0); + d->Layout->setSpacing(0); + setLayout(d->Layout); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); d->createTabBar(); - d->TabBar->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); auto horizontalSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); - d->TopLayout->addSpacerItem(horizontalSpacer); + d->Layout->addSpacerItem(horizontalSpacer); d->createButtons(); - } @@ -449,7 +448,7 @@ void CDockAreaTitleBar::updateDockWidgetActionsButtons() { for (auto Button : d->DockWidgetActionsButtons) { - d->TopLayout->removeWidget(Button); + d->Layout->removeWidget(Button); delete Button; } d->DockWidgetActionsButtons.clear(); @@ -469,7 +468,7 @@ void CDockAreaTitleBar::updateDockWidgetActionsButtons() Button->setAutoRaise(true); Button->setPopupMode(QToolButton::InstantPopup); Button->setObjectName(Action->objectName()); - d->TopLayout->insertWidget(InsertIndex++, Button, 0); + d->Layout->insertWidget(InsertIndex++, Button, 0); d->DockWidgetActionsButtons.append(Button); } } @@ -634,6 +633,20 @@ void CDockAreaTitleBar::contextMenuEvent(QContextMenuEvent* ev) } +//============================================================================ +void CDockAreaTitleBar::insertWidget(int index, QWidget *widget) +{ + d->Layout->insertWidget(index, widget); +} + + +//============================================================================ +int CDockAreaTitleBar::indexOf(QWidget *widget) const +{ + return d->Layout->indexOf(widget); +} + + } // namespace ads #include "DockAreaTitleBar.moc" diff --git a/src/DockAreaTitleBar.h b/src/DockAreaTitleBar.h index 7bd09ef..cd28842 100644 --- a/src/DockAreaTitleBar.h +++ b/src/DockAreaTitleBar.h @@ -98,6 +98,7 @@ public slots: public: using Super = QFrame; + /** * Default Constructor */ @@ -129,6 +130,23 @@ public: */ virtual void setVisible(bool Visible) override; + /** + * Inserts a custom widget at position index into this title bar. + * If index is negative, the widget is added at the end. + * You can use this function to insert custom widgets into the title bar. + */ + void insertWidget(int index, QWidget *widget); + + /** + * Searches for widget widget in this title bar. + * You can use this function, to get the position of the default + * widget in the tile bar. + * \code + * int tabBarIndex = TitleBar->indexOf(TitleBar->tabBar()); + * int closeButtonIndex = TitleBar->indexOf(TitleBar->button(TitleBarButtonClose)); + * \endcode + */ + int indexOf(QWidget *widget) const; signals: /** diff --git a/src/stylesheets/default.css b/src/stylesheets/default.css index 9df5844..5f7185d 100644 --- a/src/stylesheets/default.css +++ b/src/stylesheets/default.css @@ -92,8 +92,3 @@ QScrollArea#dockWidgetScrollArea } -ads--CDockAreaTitleBar -{ - background: red; -} -