Skip to content

Commit 3342fd6

Browse files
Vautour, AndréVautour, André
authored andcommitted
Support tabs at the bottom of dock widgets.
1 parent c1977c5 commit 3342fd6

File tree

4 files changed

+38
-14
lines changed

4 files changed

+38
-14
lines changed

src/DockAreaTitleBar.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,10 @@ void DockAreaTitleBarPrivate::createAutoHideTitleLabel()
260260
{
261261
AutoHideTitleLabel = new CElidingLabel("");
262262
AutoHideTitleLabel->setObjectName("autoHideTitleLabel");
263-
// At position 0 is the tab bar - insert behind tab bar
264-
Layout->insertWidget(1, AutoHideTitleLabel);
265-
AutoHideTitleLabel->setVisible(false); // Default hidden
266-
Layout->insertWidget(2 ,new CSpacerWidget(_this));
263+
// When the tabs are at the top, they will be at position 0, insert the label behind them, and hide it.
264+
Layout->addWidget(AutoHideTitleLabel);
265+
AutoHideTitleLabel->setVisible(CDockManager::testConfigFlag(CDockManager::TabsAtBottom));
266+
Layout->addWidget(new CSpacerWidget(_this));
267267
}
268268

269269

@@ -272,7 +272,9 @@ void DockAreaTitleBarPrivate::createTabBar()
272272
{
273273
TabBar = componentsFactory()->createDockAreaTabBar(DockArea);
274274
TabBar->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
275-
Layout->addWidget(TabBar);
275+
if (!CDockManager::testConfigFlag(CDockManager::TabsAtBottom))
276+
Layout->addWidget(TabBar);
277+
276278
_this->connect(TabBar, SIGNAL(tabClosed(int)), SLOT(markTabsMenuOutdated()));
277279
_this->connect(TabBar, SIGNAL(tabOpened(int)), SLOT(markTabsMenuOutdated()));
278280
_this->connect(TabBar, SIGNAL(tabInserted(int)), SLOT(markTabsMenuOutdated()));
@@ -351,8 +353,8 @@ CDockAreaTitleBar::CDockAreaTitleBar(CDockAreaWidget* parent) :
351353
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
352354

353355
d->createTabBar();
354-
d->createButtons();
355356
d->createAutoHideTitleLabel();
357+
d->createButtons();
356358

357359
setFocusPolicy(Qt::NoFocus);
358360
}
@@ -900,9 +902,12 @@ QString CDockAreaTitleBar::titleBarButtonToolTip(TitleBarButton Button) const
900902
//============================================================================
901903
void CDockAreaTitleBar::showAutoHideControls(bool Show)
902904
{
903-
d->TabBar->setVisible(!Show); // Auto hide toolbar never has tabs
905+
if (Show)
906+
d->TabBar->setVisible(false); // Auto hide toolbar never has tabs
907+
904908
d->MinimizeButton->setVisible(Show);
905-
d->AutoHideTitleLabel->setVisible(Show);
909+
if (!CDockManager::testConfigFlag(CDockManager::TabsAtBottom))
910+
d->AutoHideTitleLabel->setVisible(Show);
906911
}
907912

908913

src/DockAreaWidget.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,17 @@ class CDockAreaLayout
179179
parent->setUpdatesEnabled(false);
180180
}
181181

182-
auto LayoutItem = m_ParentLayout->takeAt(1);
183-
if (LayoutItem)
182+
if (m_CurrentWidget)
184183
{
185-
LayoutItem->widget()->setParent(nullptr);
184+
auto LayoutItem = m_ParentLayout->takeAt(1);
185+
if (LayoutItem)
186+
{
187+
LayoutItem->widget()->setParent(nullptr);
188+
}
189+
delete LayoutItem;
186190
}
187-
delete LayoutItem;
188191

189-
m_ParentLayout->addWidget(next);
192+
m_ParentLayout->insertWidget(1, next);
190193
if (prev)
191194
{
192195
prev->hide();
@@ -362,6 +365,14 @@ void DockAreaWidgetPrivate::createTitleBar()
362365
{
363366
TitleBar = componentsFactory()->createDockAreaTitleBar(_this);
364367
Layout->addWidget(TitleBar);
368+
if (CDockManager::testConfigFlag(CDockManager::TabsAtBottom))
369+
{
370+
// Title bar will be index 0, container widgets will be index 1,
371+
// so tabs will always be at the end of the layout.
372+
Layout->addWidget(tabBar());
373+
tabBar()->setVisible(CDockManager::testConfigFlag(CDockManager::AlwaysShowTabs));
374+
}
375+
365376
QObject::connect(tabBar(), &CDockAreaTabBar::tabCloseRequested, _this, &CDockAreaWidget::onTabCloseRequested);
366377
QObject::connect(TitleBar, &CDockAreaTitleBar::tabBarClicked, _this, &CDockAreaWidget::setCurrentIndex);
367378
QObject::connect(tabBar(), &CDockAreaTabBar::tabMoved, _this, &CDockAreaWidget::reorderDockWidget);
@@ -726,6 +737,7 @@ void CDockAreaWidget::setCurrentIndex(int index)
726737
TabBar->setCurrentIndex(index);
727738
d->ContentsLayout->setCurrentIndex(index);
728739
d->ContentsLayout->currentWidget()->show();
740+
d->TitleBar->autoHideTitleLabel()->setText(d->ContentsLayout->currentWidget()->windowTitle());
729741
Q_EMIT currentChanged(index);
730742
}
731743

@@ -889,6 +901,8 @@ void CDockAreaWidget::updateTitleBarVisibility()
889901
}
890902
}
891903
d->TitleBar->setVisible(!Hidden);
904+
if (CDockManager::testConfigFlag(CDockManager::TabsAtBottom))
905+
d->TitleBar->tabBar()->setVisible(openDockWidgetsCount() > 1);
892906
}
893907

894908
if (isAutoHideFeatureEnabled())

src/DockManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ public Q_SLOTS:
216216
DisableTabTextEliding = 0x4000000, //! Set this flag to disable eliding of tab texts in dock area tabs
217217
ShowTabTextOnlyForActiveTab =0x8000000, //! Set this flag to show label texts in dock area tabs only for active tabs
218218
DoubleClickUndocksWidget = 0x10000000, //!< If the flag is set, a double click on a tab undocks the widget
219+
TabsAtBottom = 0x20000000, //!< If the flag is set, tabs will be shown at the bottom instead of in the title bar.
219220

220221

221222
DefaultDockAreaButtons = DockAreaHasCloseButton

src/stylesheets/default.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ ads--CDockWidgetTab[activeTab="true"] QLabel {
8282
color: palette(foreground);
8383
}
8484

85+
#autoHideTitleLabel {
86+
padding-left: 4px;
87+
color: palette(foreground);
88+
}
8589

8690
#tabCloseButton {
8791
margin-top: 2px;
@@ -278,7 +282,7 @@ ads--CAutoHideDockContainer ads--CDockAreaWidget[focused="true"] ads--CDockAreaT
278282
}
279283

280284

281-
#autoHideTitleLabel {
285+
ads--CAutoHideDockContainer #autoHideTitleLabel {
282286
padding-left: 4px;
283287
color: palette(light);
284288
}

0 commit comments

Comments
 (0)