Skip to content

Commit efb9b87

Browse files
Added functions to insert custom dock area title bar widgets
1 parent d10d59a commit efb9b87

File tree

4 files changed

+46
-19
lines changed

4 files changed

+46
-19
lines changed

src/DockAreaTabBar.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ void CDockAreaTabBar::setCurrentIndex(int index)
170170
emit currentChanging(index);
171171
d->CurrentIndex = index;
172172
d->updateTabs();
173+
updateGeometry();
173174
emit currentChanged(index);
174175
}
175176

src/DockAreaTitleBar.cpp

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct DockAreaTitleBarPrivate
6666
QPointer<tTitleBarButton> TabsMenuButton;
6767
QPointer<tTitleBarButton> UndockButton;
6868
QPointer<tTitleBarButton> CloseButton;
69-
QBoxLayout* TopLayout;
69+
QBoxLayout* Layout;
7070
CDockAreaWidget* DockArea;
7171
CDockAreaTabBar* TabBar;
7272
bool MenuOutdated = true;
@@ -212,7 +212,7 @@ void DockAreaTitleBarPrivate::createButtons()
212212
TabsMenuButton->setMenu(TabsMenu);
213213
internal::setToolTip(TabsMenuButton, QObject::tr("List all tabs"));
214214
TabsMenuButton->setSizePolicy(ButtonSizePolicy);
215-
TopLayout->addWidget(TabsMenuButton, 0);
215+
Layout->addWidget(TabsMenuButton, 0);
216216
_this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)),
217217
SLOT(onTabsMenuActionTriggered(QAction*)));
218218

@@ -223,7 +223,7 @@ void DockAreaTitleBarPrivate::createButtons()
223223
internal::setToolTip(UndockButton, QObject::tr("Detach Group"));
224224
internal::setButtonIcon(UndockButton, QStyle::SP_TitleBarNormalButton, ads::DockAreaUndockIcon);
225225
UndockButton->setSizePolicy(ButtonSizePolicy);
226-
TopLayout->addWidget(UndockButton, 0);
226+
Layout->addWidget(UndockButton, 0);
227227
_this->connect(UndockButton, SIGNAL(clicked()), SLOT(onUndockButtonClicked()));
228228

229229
// Close button
@@ -241,7 +241,7 @@ void DockAreaTitleBarPrivate::createButtons()
241241
}
242242
CloseButton->setSizePolicy(ButtonSizePolicy);
243243
CloseButton->setIconSize(QSize(16, 16));
244-
TopLayout->addWidget(CloseButton, 0);
244+
Layout->addWidget(CloseButton, 0);
245245
_this->connect(CloseButton, SIGNAL(clicked()), SLOT(onCloseButtonClicked()));
246246
}
247247

@@ -250,7 +250,8 @@ void DockAreaTitleBarPrivate::createButtons()
250250
void DockAreaTitleBarPrivate::createTabBar()
251251
{
252252
TabBar = new CDockAreaTabBar(DockArea);
253-
TopLayout->addWidget(TabBar);
253+
TabBar->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
254+
Layout->addWidget(TabBar);
254255
_this->connect(TabBar, SIGNAL(tabClosed(int)), SLOT(markTabsMenuOutdated()));
255256
_this->connect(TabBar, SIGNAL(tabOpened(int)), SLOT(markTabsMenuOutdated()));
256257
_this->connect(TabBar, SIGNAL(tabInserted(int)), SLOT(markTabsMenuOutdated()));
@@ -314,18 +315,16 @@ CDockAreaTitleBar::CDockAreaTitleBar(CDockAreaWidget* parent) :
314315
d->DockArea = parent;
315316

316317
setObjectName("dockAreaTitleBar");
317-
d->TopLayout = new QBoxLayout(QBoxLayout::LeftToRight);
318-
d->TopLayout->setContentsMargins(0, 0, 0, 0);
319-
d->TopLayout->setSpacing(0);
320-
setLayout(d->TopLayout);
318+
d->Layout = new QBoxLayout(QBoxLayout::LeftToRight);
319+
d->Layout->setContentsMargins(0, 0, 0, 0);
320+
d->Layout->setSpacing(0);
321+
setLayout(d->Layout);
321322
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
322323

323324
d->createTabBar();
324-
d->TabBar->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
325325
auto horizontalSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
326-
d->TopLayout->addSpacerItem(horizontalSpacer);
326+
d->Layout->addSpacerItem(horizontalSpacer);
327327
d->createButtons();
328-
329328
}
330329

331330

@@ -449,7 +448,7 @@ void CDockAreaTitleBar::updateDockWidgetActionsButtons()
449448
{
450449
for (auto Button : d->DockWidgetActionsButtons)
451450
{
452-
d->TopLayout->removeWidget(Button);
451+
d->Layout->removeWidget(Button);
453452
delete Button;
454453
}
455454
d->DockWidgetActionsButtons.clear();
@@ -469,7 +468,7 @@ void CDockAreaTitleBar::updateDockWidgetActionsButtons()
469468
Button->setAutoRaise(true);
470469
Button->setPopupMode(QToolButton::InstantPopup);
471470
Button->setObjectName(Action->objectName());
472-
d->TopLayout->insertWidget(InsertIndex++, Button, 0);
471+
d->Layout->insertWidget(InsertIndex++, Button, 0);
473472
d->DockWidgetActionsButtons.append(Button);
474473
}
475474
}
@@ -634,6 +633,20 @@ void CDockAreaTitleBar::contextMenuEvent(QContextMenuEvent* ev)
634633
}
635634

636635

636+
//============================================================================
637+
void CDockAreaTitleBar::insertWidget(int index, QWidget *widget)
638+
{
639+
d->Layout->insertWidget(index, widget);
640+
}
641+
642+
643+
//============================================================================
644+
int CDockAreaTitleBar::indexOf(QWidget *widget) const
645+
{
646+
return d->Layout->indexOf(widget);
647+
}
648+
649+
637650
} // namespace ads
638651

639652
#include "DockAreaTitleBar.moc"

src/DockAreaTitleBar.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public slots:
9898

9999
public:
100100
using Super = QFrame;
101+
101102
/**
102103
* Default Constructor
103104
*/
@@ -129,6 +130,23 @@ public slots:
129130
*/
130131
virtual void setVisible(bool Visible) override;
131132

133+
/**
134+
* Inserts a custom widget at position index into this title bar.
135+
* If index is negative, the widget is added at the end.
136+
* You can use this function to insert custom widgets into the title bar.
137+
*/
138+
void insertWidget(int index, QWidget *widget);
139+
140+
/**
141+
* Searches for widget widget in this title bar.
142+
* You can use this function, to get the position of the default
143+
* widget in the tile bar.
144+
* \code
145+
* int tabBarIndex = TitleBar->indexOf(TitleBar->tabBar());
146+
* int closeButtonIndex = TitleBar->indexOf(TitleBar->button(TitleBarButtonClose));
147+
* \endcode
148+
*/
149+
int indexOf(QWidget *widget) const;
132150

133151
signals:
134152
/**

src/stylesheets/default.css

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,3 @@ QScrollArea#dockWidgetScrollArea
9292
}
9393

9494

95-
ads--CDockAreaTitleBar
96-
{
97-
background: red;
98-
}
99-

0 commit comments

Comments
 (0)