From 067338ef23687c0781a4cab9d55a2c4334c09822 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Sun, 10 May 2020 19:30:34 +0200 Subject: [PATCH] Enable styling of focused dockwidget --- src/DockManager.cpp | 74 +++++++++++++++++++++++++++++++++++++ src/DockManager.h | 3 ++ src/DockWidgetTab.cpp | 16 ++++++-- src/DockWidgetTab.h | 7 ++++ src/ads_globals.cpp | 13 +++++++ src/ads_globals.h | 7 ++++ src/stylesheets/default.css | 44 ++++++++++++++++++++-- 7 files changed, 156 insertions(+), 8 deletions(-) diff --git a/src/DockManager.cpp b/src/DockManager.cpp index 3cda957..2394d85 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -45,6 +45,8 @@ #include #include #include +#include +#include #include "FloatingDockContainer.h" #include "DockOverlay.h" @@ -53,6 +55,7 @@ #include "DockAreaWidget.h" #include "IconProvider.h" #include "DockingStateReader.h" +#include "DockAreaTitleBar.h" /** @@ -91,6 +94,7 @@ struct DockManagerPrivate CDockManager::eViewMenuInsertionOrder MenuInsertionOrder = CDockManager::MenuAlphabeticallySorted; bool RestoringState = false; QVector UninitializedFloatingWidgets; + QPointer FocusedDockWidget; /** * Private data constructor @@ -437,6 +441,8 @@ CDockManager::CDockManager(QWidget *parent) : d->ContainerOverlay = new CDockOverlay(this, CDockOverlay::ModeContainerOverlay); d->Containers.append(this); d->loadStylesheet(); + connect(QGuiApplication::instance(), SIGNAL(focusObjectChanged(QObject*)), + this, SLOT(onFocusObjectChanged(QObject*))); } //============================================================================ @@ -872,6 +878,74 @@ CIconProvider& CDockManager::iconProvider() } +//=========================================================================== +void CDockManager::onFocusObjectChanged(QObject *focusObject) +{ + auto FocusWidget = qobject_cast(focusObject); + if (!FocusWidget) + { + return; + } + auto DockWidget = internal::findParent(FocusWidget); + if (!DockWidget) + { + return; + } + + if (d->FocusedDockWidget.data() == DockWidget) + { + return; + } + + QList DockWidgets; + CDockAreaWidget* OldFocusedDockArea = nullptr; + CDockAreaWidget* NewFocusedDockArea = nullptr; + if (d->FocusedDockWidget) + { + d->FocusedDockWidget->setProperty("focused", false); + d->FocusedDockWidget->tabWidget()->setProperty("focused", false); + OldFocusedDockArea = d->FocusedDockWidget->dockAreaWidget(); + if (OldFocusedDockArea) + { + OldFocusedDockArea->setProperty("focused", false); + } + DockWidgets.append(d->FocusedDockWidget); + } + d->FocusedDockWidget = DockWidget; + d->FocusedDockWidget->setProperty("focused", true); + d->FocusedDockWidget->tabWidget()->setProperty("focused", true); + NewFocusedDockArea = d->FocusedDockWidget->dockAreaWidget(); + if (NewFocusedDockArea) + { + NewFocusedDockArea->setProperty("focused", true); + } + DockWidgets.append(d->FocusedDockWidget); + + for (auto DockWidget : DockWidgets) + { + DockWidget->tabWidget()->updateStyle(); + internal::repolishStyle(DockWidget); + } + + if (OldFocusedDockArea == NewFocusedDockArea) + { + return; + } + + if (OldFocusedDockArea) + { + internal::repolishStyle(OldFocusedDockArea); + internal::repolishStyle(OldFocusedDockArea->titleBar()); + } + + if (NewFocusedDockArea) + { + internal::repolishStyle(NewFocusedDockArea); + internal::repolishStyle(NewFocusedDockArea->titleBar()); + } +} + + } // namespace ads //--------------------------------------------------------------------------- diff --git a/src/DockManager.h b/src/DockManager.h index e556046..5de5fd6 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -84,6 +84,9 @@ private: friend struct FloatingDragPreviewPrivate; friend class CDockAreaTitleBar; +private slots: + void onFocusObjectChanged(QObject *focusObject); + protected: /** * Registers the given floating widget in the internal list of diff --git a/src/DockWidgetTab.cpp b/src/DockWidgetTab.cpp index 2061997..d290104 100644 --- a/src/DockWidgetTab.cpp +++ b/src/DockWidgetTab.cpp @@ -160,6 +160,7 @@ struct DockWidgetTabPrivate GlobalDragStartMousePosition = GlobalPos; DragStartMousePosition = _this->mapFromGlobal(GlobalPos); } + }; // struct DockWidgetTabPrivate @@ -467,10 +468,7 @@ void CDockWidgetTab::setActiveTab(bool active) } d->IsActiveTab = active; - style()->unpolish(this); - style()->polish(this); - d->TitleLabel->style()->unpolish(d->TitleLabel); - d->TitleLabel->style()->polish(d->TitleLabel); + updateStyle(); update(); updateGeometry(); @@ -641,6 +639,16 @@ void CDockWidgetTab::setElideMode(Qt::TextElideMode mode) } +//============================================================================ +void CDockWidgetTab::updateStyle() +{ + this->style()->unpolish(this); + this->style()->polish(this); + d->TitleLabel->style()->unpolish(d->TitleLabel); + d->TitleLabel->style()->polish(d->TitleLabel); +} + + } // namespace ads diff --git a/src/DockWidgetTab.h b/src/DockWidgetTab.h index 3be47a3..70e379a 100644 --- a/src/DockWidgetTab.h +++ b/src/DockWidgetTab.h @@ -39,6 +39,7 @@ namespace ads class CDockWidget; class CDockAreaWidget; struct DockWidgetTabPrivate; +class CDockManager; /** * A dock widget tab that shows a title and an icon. @@ -54,6 +55,7 @@ private: DockWidgetTabPrivate* d; ///< private data (pimpl) friend struct DockWidgetTabPrivate; friend class CDockWidget; + friend class CDockManager; void onDockWidgetFeaturesChanged(); private slots: @@ -70,6 +72,11 @@ protected: */ virtual void mouseDoubleClickEvent(QMouseEvent *event) override; + /** + * Update stylesheet style if a property changes + */ + void updateStyle(); + public: using Super = QFrame; /** diff --git a/src/ads_globals.cpp b/src/ads_globals.cpp index 4310dd2..79ad9e1 100644 --- a/src/ads_globals.cpp +++ b/src/ads_globals.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include "DockSplitter.h" #include "DockManager.h" @@ -118,6 +119,18 @@ void setButtonIcon(QAbstractButton* Button, QStyle::StandardPixmap StandarPixmap #endif } + +//============================================================================ +void repolishStyle(QWidget* w) +{ + if (!w) + { + return; + } + w->style()->unpolish(w); + w->style()->polish(w); +} + } // namespace internal } // namespace ads diff --git a/src/ads_globals.h b/src/ads_globals.h index 201189c..abcc332 100644 --- a/src/ads_globals.h +++ b/src/ads_globals.h @@ -251,6 +251,13 @@ void setToolTip(QObjectPtr obj, const QString &tip) void setButtonIcon(QAbstractButton* Button, QStyle::StandardPixmap StandarPixmap, ads::eIcon CustomIconId); + +/** + * Calls unpolish() / polish for the style of the given widget to update + * stylesheet if a property changes + */ +void repolishStyle(QWidget* w); + } // namespace internal } // namespace ads diff --git a/src/stylesheets/default.css b/src/stylesheets/default.css index 5f7185d..5ace174 100644 --- a/src/stylesheets/default.css +++ b/src/stylesheets/default.css @@ -9,10 +9,6 @@ ads--CDockContainerWidget background: palette(dark); } -ads--CDockContainerWidget QSplitter::handle -{ - background: palette(dark); -} ads--CDockAreaWidget { @@ -92,3 +88,43 @@ QScrollArea#dockWidgetScrollArea } +ads--CDockSplitter::handle +{ + background-color: palette(dark); + /* uncomment the following line if you would like to change the size of + the splitter handles */ + /* height: 1px; */ +} + + + +ads--CDockWidgetTab[focused="true"] +{ + background: palette(highlight); + border-color: palette(highlight); +} + +ads--CDockWidgetTab[focused="true"] QLabel +{ + color: palette(light); +} + + +ads--CDockAreaTitleBar +{ + background: transparent; + border-bottom: 2px solid palette(light); + padding-bottom: 0px; +} + +ads--CDockAreaWidget[focused="true"] ads--CDockAreaTitleBar +{ + background: transparent; + border-bottom: 2px solid palette(highlight); + padding-bottom: 0px; +} + + + + +