Skip to content

Commit 420baee

Browse files
Added support for global dock manager toolbar style and custom dock widget toolbar style for dock widgets
1 parent 0f8096e commit 420baee

File tree

5 files changed

+162
-0
lines changed

5 files changed

+162
-0
lines changed

demo/MainWindow.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ struct MainWindowPrivate
271271
auto ToolBar = DockWidget->createDefaultToolBar();
272272
ToolBar->addAction(ui.actionSaveState);
273273
ToolBar->addAction(ui.actionRestoreState);
274+
// For testing all calendar dock widgets have a the tool button style
275+
// Qt::ToolButtonTextUnderIcon
276+
DockWidget->setToolBarStyleSource(ads::CDockWidget::ToolBarStyleFromDockWidget);
277+
DockWidget->setToolBarStyle(Qt::ToolButtonTextUnderIcon, ads::CDockWidget::StateFloating);
274278
return DockWidget;
275279
}
276280

@@ -764,6 +768,7 @@ CMainWindow::CMainWindow(QWidget *parent) :
764768

765769
// Now create the dock manager and its content
766770
d->DockManager = new CDockManager(this);
771+
d->DockManager->setDockWidgetToolBarStyle(Qt::ToolButtonIconOnly, ads::CDockWidget::StateFloating);
767772

768773
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
769774
connect(d->PerspectiveComboBox, SIGNAL(activated(QString)),

src/DockManager.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ struct DockManagerPrivate
118118
CDockFocusController* FocusController = nullptr;
119119
CDockWidget* CentralWidget = nullptr;
120120
bool IsLeavingMinimized = false;
121+
Qt::ToolButtonStyle ToolBarStyleDocked = Qt::ToolButtonIconOnly;
122+
Qt::ToolButtonStyle ToolBarStyleFloating = Qt::ToolButtonTextUnderIcon;
123+
QSize ToolBarIconSizeDocked = QSize(16, 16);
124+
QSize ToolBarIconSizeFloating = QSize(24, 24);
121125

122126
/**
123127
* Private data constructor
@@ -1361,6 +1365,63 @@ QString CDockManager::floatingContainersTitle()
13611365
return FloatingContainersTitle;
13621366
}
13631367

1368+
1369+
//===========================================================================
1370+
void CDockManager::setDockWidgetToolBarStyle(Qt::ToolButtonStyle Style, CDockWidget::eState State)
1371+
{
1372+
if (CDockWidget::StateFloating == State)
1373+
{
1374+
d->ToolBarStyleFloating = Style;
1375+
}
1376+
else
1377+
{
1378+
d->ToolBarStyleDocked = Style;
1379+
}
1380+
}
1381+
1382+
1383+
//===========================================================================
1384+
Qt::ToolButtonStyle CDockManager::dockWidgetToolBarStyle(CDockWidget::eState State) const
1385+
{
1386+
if (CDockWidget::StateFloating == State)
1387+
{
1388+
return d->ToolBarStyleFloating;
1389+
}
1390+
else
1391+
{
1392+
return d->ToolBarStyleDocked;
1393+
}
1394+
}
1395+
1396+
1397+
//===========================================================================
1398+
void CDockManager::setDockWidgetToolBarIconSize(const QSize& IconSize, CDockWidget::eState State)
1399+
{
1400+
if (CDockWidget::StateFloating == State)
1401+
{
1402+
d->ToolBarIconSizeFloating = IconSize;
1403+
}
1404+
else
1405+
{
1406+
d->ToolBarIconSizeDocked = IconSize;
1407+
}
1408+
}
1409+
1410+
1411+
//===========================================================================
1412+
QSize CDockManager::dockWidgetToolBarIconSize(CDockWidget::eState State) const
1413+
{
1414+
if (CDockWidget::StateFloating == State)
1415+
{
1416+
return d->ToolBarIconSizeFloating;
1417+
}
1418+
else
1419+
{
1420+
return d->ToolBarIconSizeDocked;
1421+
}
1422+
}
1423+
1424+
13641425
} // namespace ads
13651426

13661427
//---------------------------------------------------------------------------

src/DockManager.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,36 @@ public Q_SLOTS:
627627
*/
628628
static QString floatingContainersTitle();
629629

630+
/**
631+
* This function sets the tool button style for the given dock widget state.
632+
* It is possible to switch the tool button style depending on the state.
633+
* If a dock widget is floating, then here are more space and it is
634+
* possible to select a style that requires more space like
635+
* Qt::ToolButtonTextUnderIcon. For the docked state Qt::ToolButtonIconOnly
636+
* might be better.
637+
*/
638+
void setDockWidgetToolBarStyle(Qt::ToolButtonStyle Style, CDockWidget::eState State);
639+
640+
/**
641+
* Returns the tool button style for the given docking state.
642+
* \see setToolBarStyle()
643+
*/
644+
Qt::ToolButtonStyle dockWidgetToolBarStyle(CDockWidget::eState State) const;
645+
646+
/**
647+
* This function sets the tool button icon size for the given state.
648+
* If a dock widget is floating, there is more space and increasing the
649+
* icon size is possible. For docked widgets, small icon sizes, eg. 16 x 16
650+
* might be better.
651+
*/
652+
void setDockWidgetToolBarIconSize(const QSize& IconSize, CDockWidget::eState State);
653+
654+
/**
655+
* Returns the icon size for a given docking state.
656+
* \see setToolBarIconSize()
657+
*/
658+
QSize dockWidgetToolBarIconSize(CDockWidget::eState State) const;
659+
630660
public Q_SLOTS:
631661
/**
632662
* Opens the perspective with the given name.

src/DockWidget.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ struct DockWidgetPrivate
9595
CDockWidget::eMinimumSizeHintMode MinimumSizeHintMode = CDockWidget::MinimumSizeHintFromDockWidget;
9696
WidgetFactory* Factory = nullptr;
9797
QPointer<CAutoHideTab> SideTabWidget;
98+
CDockWidget::eToolBarStyleSource ToolBarStyleSource = CDockWidget::ToolBarStyleFromDockManager;
9899

99100
/**
100101
* Private data constructor
@@ -139,6 +140,11 @@ struct DockWidgetPrivate
139140
* returns true on success.
140141
*/
141142
bool createWidgetFromFactory();
143+
144+
/**
145+
* Use the dock manager toolbar style and icon size for the different states
146+
*/
147+
void setToolBarStyleFromDockManager();
142148
};
143149
// struct DockWidgetPrivate
144150

@@ -331,6 +337,22 @@ bool DockWidgetPrivate::createWidgetFromFactory()
331337
}
332338

333339

340+
//============================================================================
341+
void DockWidgetPrivate::setToolBarStyleFromDockManager()
342+
{
343+
if (!DockManager)
344+
{
345+
return;
346+
}
347+
auto State = CDockWidget::StateDocked;
348+
_this->setToolBarIconSize(DockManager->dockWidgetToolBarIconSize(State), State);
349+
_this->setToolBarStyle(DockManager->dockWidgetToolBarStyle(State), State);
350+
State = CDockWidget::StateFloating;
351+
_this->setToolBarIconSize(DockManager->dockWidgetToolBarIconSize(State), State);
352+
_this->setToolBarStyle(DockManager->dockWidgetToolBarStyle(State), State);
353+
}
354+
355+
334356
//============================================================================
335357
CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
336358
QFrame(parent),
@@ -523,6 +545,15 @@ CDockManager* CDockWidget::dockManager() const
523545
void CDockWidget::setDockManager(CDockManager* DockManager)
524546
{
525547
d->DockManager = DockManager;
548+
if (!DockManager)
549+
{
550+
return;
551+
}
552+
553+
if (ToolBarStyleFromDockManager == d->ToolBarStyleSource)
554+
{
555+
d->setToolBarStyleFromDockManager();
556+
}
526557
}
527558

528559

@@ -1284,6 +1315,24 @@ void CDockWidget::toggleAutoHide(SideBarLocation Location)
12841315
}
12851316

12861317

1318+
//============================================================================
1319+
void CDockWidget::setToolBarStyleSource(eToolBarStyleSource Source)
1320+
{
1321+
d->ToolBarStyleSource = Source;
1322+
if (ToolBarStyleFromDockManager == d->ToolBarStyleSource)
1323+
{
1324+
d->setToolBarStyleFromDockManager();
1325+
}
1326+
}
1327+
1328+
1329+
//============================================================================
1330+
CDockWidget::eToolBarStyleSource CDockWidget::toolBarStyleSource() const
1331+
{
1332+
return d->ToolBarStyleSource;
1333+
}
1334+
1335+
12871336
} // namespace ads
12881337

12891338
//---------------------------------------------------------------------------

src/DockWidget.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ private Q_SLOTS:
176176
StateFloating
177177
};
178178

179+
enum eToolBarStyleSource
180+
{
181+
ToolBarStyleFromDockManager,
182+
ToolBarStyleFromDockWidget
183+
};
184+
179185
/**
180186
* Sets the widget for the dock widget to widget.
181187
* The InsertMode defines how the widget is inserted into the dock widget.
@@ -473,6 +479,17 @@ private Q_SLOTS:
473479
*/
474480
void setToolBar(QToolBar* ToolBar);
475481

482+
/**
483+
* Configures, if the dock widget uses the global tool bar styles from
484+
* dock manager or if it uses its own tool bar style
485+
*/
486+
void setToolBarStyleSource(eToolBarStyleSource Source);
487+
488+
/**
489+
* Returns the configured tool bar style source
490+
*/
491+
eToolBarStyleSource toolBarStyleSource() const;
492+
476493
/**
477494
* This function sets the tool button style for the given dock widget state.
478495
* It is possible to switch the tool button style depending on the state.

0 commit comments

Comments
 (0)