mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-11-15 13:15:43 +08:00
Added support for global dock manager toolbar style and custom dock widget toolbar style for dock widgets
This commit is contained in:
parent
0f8096e314
commit
420baeedfe
@ -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;
|
||||
}
|
||||
|
||||
@ -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)),
|
||||
|
@ -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
|
||||
@ -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
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -627,6 +627,36 @@ public:
|
||||
*/
|
||||
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.
|
||||
|
@ -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
|
||||
@ -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
|
||||
|
||||
@ -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),
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -176,6 +176,12 @@ public:
|
||||
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.
|
||||
@ -473,6 +479,17 @@ public:
|
||||
*/
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user