Add title label to the overlayed dock area

This commit is contained in:
Syarif Fakhri 2022-09-08 14:43:18 +08:00
parent 9bfd77a206
commit af549d8ca9
3 changed files with 37 additions and 7 deletions

View File

@ -49,10 +49,10 @@
#include "DockWidget.h"
#include "DockWidgetTab.h"
#include "DockAreaTabBar.h"
#include "IconProvider.h"
#include "DockComponentsFactory.h"
#include "DockFocusController.h"
#include "OverlayDockContainer.h"
#include "ElidingLabel.h"
#include <iostream>
@ -72,6 +72,7 @@ struct DockAreaTitleBarPrivate
QBoxLayout* Layout;
CDockAreaWidget* DockArea;
CDockAreaTabBar* TabBar;
CElidingLabel* OverlayTitleLabel;
bool MenuOutdated = true;
QMenu* TabsMenu;
QList<tTitleBarButton*> DockWidgetActionsButtons;
@ -91,6 +92,12 @@ struct DockAreaTitleBarPrivate
*/
void createButtons();
/**
* Creates the overlay title label, only displayed when the dock area is overlayed
*/
void createOverlayTitleLabel();
/**
* Creates the internal TabBar
*/
@ -207,6 +214,15 @@ void DockAreaTitleBarPrivate::createButtons()
}
//============================================================================
void DockAreaTitleBarPrivate::createOverlayTitleLabel()
{
OverlayTitleLabel = new CElidingLabel("");
OverlayTitleLabel->setObjectName("overlayTitleLabel");
Layout->addWidget(OverlayTitleLabel);
}
//============================================================================
void DockAreaTitleBarPrivate::createTabBar()
{
@ -287,6 +303,8 @@ CDockAreaTitleBar::CDockAreaTitleBar(CDockAreaWidget* parent) :
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
d->createTabBar();
d->createOverlayTitleLabel();
d->OverlayTitleLabel->setVisible(false); // Default hidden
d->Layout->addWidget(new CSpacerWidget(this));
d->createButtons();
@ -480,6 +498,13 @@ QAbstractButton* CDockAreaTitleBar::button(TitleBarButton which) const
}
//============================================================================
CElidingLabel* CDockAreaTitleBar::overlayTitleLabel() const
{
return d->OverlayTitleLabel;
}
//============================================================================
void CDockAreaTitleBar::setVisible(bool Visible)
{

View File

@ -41,6 +41,7 @@ namespace ads
class CDockAreaTabBar;
class CDockAreaWidget;
struct DockAreaTitleBarPrivate;
class CElidingLabel;
/**
* Title bar of a dock area.
@ -120,6 +121,11 @@ public:
*/
QAbstractButton* button(TitleBarButton which) const;
/**
* Returns the overlay title label, used when the dock area is overlayed
*/
CElidingLabel* overlayTitleLabel() const;
/**
* Updates the visibility of the dock widget actions in the title bar
*/

View File

@ -32,18 +32,15 @@
#include <QStackedLayout>
#include <QScrollBar>
#include <QScrollArea>
#include <QWheelEvent>
#include <QStyle>
#include <QPushButton>
#include <QDebug>
#include <QMenu>
#include <QSplitter>
#include <QXmlStreamWriter>
#include <QVector>
#include <QList>
#include "ElidingLabel.h"
#include "DockContainerWidget.h"
#include "DockWidget.h"
#include "FloatingDockContainer.h"
@ -54,7 +51,6 @@
#include "DockAreaTitleBar.h"
#include "DockComponentsFactory.h"
#include "DockWidgetTab.h"
#include "SideTabBar.h"
#include "DockWidgetSideTab.h"
#include "OverlayDockContainer.h"
@ -451,6 +447,7 @@ void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget,
d->tabBar()->insertTab(index, TabWidget);
d->tabBar()->blockSignals(false);
TabWidget->setVisible(!DockWidget->isClosed());
d->TitleBar->overlayTitleLabel()->setText(DockWidget->windowTitle());
DockWidget->setProperty(INDEX_PROPERTY, index);
d->MinSizeHint.setHeight(qMax(d->MinSizeHint.height(), DockWidget->minimumSizeHint().height()));
d->MinSizeHint.setWidth(qMax(d->MinSizeHint.width(), DockWidget->minimumSizeHint().width()));
@ -787,7 +784,9 @@ void CDockAreaWidget::updateTitleBarVisibility()
|| CDockManager::testConfigFlag(CDockManager::HideSingleCentralWidgetTitleBar));
Hidden |= (d->Flags.testFlag(HideSingleWidgetTitleBar) && openDockWidgetsCount() == 1);
d->TitleBar->setVisible(isOverlayed() ? true : !Hidden); // Titlebar must always be visible when overlayed so it can be dragged
d->TitleBar->tabBar()->setVisible(isOverlayed() ? false : !Hidden); // Never show tab bar when overlayed
auto tabBar = d->TitleBar->tabBar();
tabBar->setVisible(isOverlayed() ? false : !Hidden); // Never show tab bar when overlayed
d->TitleBar->overlayTitleLabel()->setVisible(isOverlayed()); // Always show when overlayed, never otherwise
}
}