Skip to content

Commit

Permalink
Added support for global dock manager toolbar style and custom dock w…
Browse files Browse the repository at this point in the history
…idget toolbar style for dock widgets
  • Loading branch information
githubuser0xFFFF committed Oct 19, 2023
1 parent 0f8096e commit 420baee
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 0 deletions.
5 changes: 5 additions & 0 deletions demo/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ struct MainWindowPrivate
auto ToolBar = DockWidget->createDefaultToolBar();
ToolBar->addAction(ui.actionSaveState);
ToolBar->addAction(ui.actionRestoreState);
// For testing all calendar dock widgets have a the tool button style
// Qt::ToolButtonTextUnderIcon
DockWidget->setToolBarStyleSource(ads::CDockWidget::ToolBarStyleFromDockWidget);
DockWidget->setToolBarStyle(Qt::ToolButtonTextUnderIcon, ads::CDockWidget::StateFloating);
return DockWidget;
}

Expand Down Expand Up @@ -764,6 +768,7 @@ CMainWindow::CMainWindow(QWidget *parent) :

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

#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
connect(d->PerspectiveComboBox, SIGNAL(activated(QString)),
Expand Down
61 changes: 61 additions & 0 deletions src/DockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ struct DockManagerPrivate
CDockFocusController* FocusController = nullptr;
CDockWidget* CentralWidget = nullptr;
bool IsLeavingMinimized = false;
Qt::ToolButtonStyle ToolBarStyleDocked = Qt::ToolButtonIconOnly;
Qt::ToolButtonStyle ToolBarStyleFloating = Qt::ToolButtonTextUnderIcon;
QSize ToolBarIconSizeDocked = QSize(16, 16);
QSize ToolBarIconSizeFloating = QSize(24, 24);

/**
* Private data constructor
Expand Down Expand Up @@ -1361,6 +1365,63 @@ QString CDockManager::floatingContainersTitle()
return FloatingContainersTitle;
}


//===========================================================================
void CDockManager::setDockWidgetToolBarStyle(Qt::ToolButtonStyle Style, CDockWidget::eState State)
{
if (CDockWidget::StateFloating == State)
{
d->ToolBarStyleFloating = Style;
}
else
{
d->ToolBarStyleDocked = Style;
}
}


//===========================================================================
Qt::ToolButtonStyle CDockManager::dockWidgetToolBarStyle(CDockWidget::eState State) const
{
if (CDockWidget::StateFloating == State)
{
return d->ToolBarStyleFloating;
}
else
{
return d->ToolBarStyleDocked;
}
}


//===========================================================================
void CDockManager::setDockWidgetToolBarIconSize(const QSize& IconSize, CDockWidget::eState State)
{
if (CDockWidget::StateFloating == State)
{
d->ToolBarIconSizeFloating = IconSize;
}
else
{
d->ToolBarIconSizeDocked = IconSize;
}
}


//===========================================================================
QSize CDockManager::dockWidgetToolBarIconSize(CDockWidget::eState State) const
{
if (CDockWidget::StateFloating == State)
{
return d->ToolBarIconSizeFloating;
}
else
{
return d->ToolBarIconSizeDocked;
}
}


} // namespace ads

//---------------------------------------------------------------------------
Expand Down
30 changes: 30 additions & 0 deletions src/DockManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,36 @@ public Q_SLOTS:
*/
static QString floatingContainersTitle();

/**
* This function sets the tool button style for the given dock widget state.
* It is possible to switch the tool button style depending on the state.
* If a dock widget is floating, then here are more space and it is
* possible to select a style that requires more space like
* Qt::ToolButtonTextUnderIcon. For the docked state Qt::ToolButtonIconOnly
* might be better.
*/
void setDockWidgetToolBarStyle(Qt::ToolButtonStyle Style, CDockWidget::eState State);

/**
* Returns the tool button style for the given docking state.
* \see setToolBarStyle()
*/
Qt::ToolButtonStyle dockWidgetToolBarStyle(CDockWidget::eState State) const;

/**
* This function sets the tool button icon size for the given state.
* If a dock widget is floating, there is more space and increasing the
* icon size is possible. For docked widgets, small icon sizes, eg. 16 x 16
* might be better.
*/
void setDockWidgetToolBarIconSize(const QSize& IconSize, CDockWidget::eState State);

/**
* Returns the icon size for a given docking state.
* \see setToolBarIconSize()
*/
QSize dockWidgetToolBarIconSize(CDockWidget::eState State) const;

public Q_SLOTS:
/**
* Opens the perspective with the given name.
Expand Down
49 changes: 49 additions & 0 deletions src/DockWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ struct DockWidgetPrivate
CDockWidget::eMinimumSizeHintMode MinimumSizeHintMode = CDockWidget::MinimumSizeHintFromDockWidget;
WidgetFactory* Factory = nullptr;
QPointer<CAutoHideTab> SideTabWidget;
CDockWidget::eToolBarStyleSource ToolBarStyleSource = CDockWidget::ToolBarStyleFromDockManager;

/**
* Private data constructor
Expand Down Expand Up @@ -139,6 +140,11 @@ struct DockWidgetPrivate
* returns true on success.
*/
bool createWidgetFromFactory();

/**
* Use the dock manager toolbar style and icon size for the different states
*/
void setToolBarStyleFromDockManager();
};
// struct DockWidgetPrivate

Expand Down Expand Up @@ -331,6 +337,22 @@ bool DockWidgetPrivate::createWidgetFromFactory()
}


//============================================================================
void DockWidgetPrivate::setToolBarStyleFromDockManager()
{
if (!DockManager)
{
return;
}
auto State = CDockWidget::StateDocked;
_this->setToolBarIconSize(DockManager->dockWidgetToolBarIconSize(State), State);
_this->setToolBarStyle(DockManager->dockWidgetToolBarStyle(State), State);
State = CDockWidget::StateFloating;
_this->setToolBarIconSize(DockManager->dockWidgetToolBarIconSize(State), State);
_this->setToolBarStyle(DockManager->dockWidgetToolBarStyle(State), State);
}


//============================================================================
CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
QFrame(parent),
Expand Down Expand Up @@ -523,6 +545,15 @@ CDockManager* CDockWidget::dockManager() const
void CDockWidget::setDockManager(CDockManager* DockManager)
{
d->DockManager = DockManager;
if (!DockManager)
{
return;
}

if (ToolBarStyleFromDockManager == d->ToolBarStyleSource)
{
d->setToolBarStyleFromDockManager();
}
}


Expand Down Expand Up @@ -1284,6 +1315,24 @@ void CDockWidget::toggleAutoHide(SideBarLocation Location)
}


//============================================================================
void CDockWidget::setToolBarStyleSource(eToolBarStyleSource Source)
{
d->ToolBarStyleSource = Source;
if (ToolBarStyleFromDockManager == d->ToolBarStyleSource)
{
d->setToolBarStyleFromDockManager();
}
}


//============================================================================
CDockWidget::eToolBarStyleSource CDockWidget::toolBarStyleSource() const
{
return d->ToolBarStyleSource;
}


} // namespace ads

//---------------------------------------------------------------------------
Expand Down
17 changes: 17 additions & 0 deletions src/DockWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ private Q_SLOTS:
StateFloating
};

enum eToolBarStyleSource
{
ToolBarStyleFromDockManager,
ToolBarStyleFromDockWidget
};

/**
* Sets the widget for the dock widget to widget.
* The InsertMode defines how the widget is inserted into the dock widget.
Expand Down Expand Up @@ -473,6 +479,17 @@ private Q_SLOTS:
*/
void setToolBar(QToolBar* ToolBar);

/**
* Configures, if the dock widget uses the global tool bar styles from
* dock manager or if it uses its own tool bar style
*/
void setToolBarStyleSource(eToolBarStyleSource Source);

/**
* Returns the configured tool bar style source
*/
eToolBarStyleSource toolBarStyleSource() const;

/**
* This function sets the tool button style for the given dock widget state.
* It is possible to switch the tool button style depending on the state.
Expand Down

0 comments on commit 420baee

Please sign in to comment.