From 25eb02d07cb3d4e30a935d04e30d21a656761423 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Tue, 19 May 2020 22:53:52 +0200 Subject: [PATCH] Added support for focus styling of CFloatingWidgetTitleBra --- src/DockManager.cpp | 38 +++++++++++++++++++++++++++- src/FloatingDockContainer.h | 3 +-- src/linux/FloatingWidgetTitleBar.cpp | 12 ++++++++- src/linux/FloatingWidgetTitleBar.h | 9 +++++-- src/stylesheets/default.css | 7 +---- src/stylesheets/default_linux.css | 37 +++++++++++++++++++++++++++ 6 files changed, 94 insertions(+), 12 deletions(-) diff --git a/src/DockManager.cpp b/src/DockManager.cpp index 557bb5f..b5d4677 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -57,6 +57,10 @@ #include "DockingStateReader.h" #include "DockAreaTitleBar.h" +#ifdef Q_OS_LINUX +#include "linux/FloatingWidgetTitleBar.h" +#endif + /** * Initializes the resources specified by the .qrc file with the specified base @@ -96,6 +100,7 @@ struct DockManagerPrivate QVector UninitializedFloatingWidgets; QPointer FocusedDockWidget = nullptr; QPointer FocusedArea = nullptr; + QPointer FloatingWidget = nullptr; /** * Private data constructor @@ -450,6 +455,19 @@ void updateDockAreaFocusStyle(CDockAreaWidget* DockArea, bool Focused) } +//=========================================================================== +void updateFloatingWidgetFocusStyle(CFloatingDockContainer* FloatingWidget, bool Focused) +{ + auto TitleBar = qobject_cast(FloatingWidget->titleBarWidget()); + if (!TitleBar) + { + return; + } + TitleBar->setProperty("focused", Focused); + TitleBar->updateStyle(); +} + + //============================================================================ void DockManagerPrivate::updateDockWidgetFocus(CDockWidget* DockWidget) { @@ -476,6 +494,24 @@ void DockManagerPrivate::updateDockWidgetFocus(CDockWidget* DockWidget) FocusedArea = NewFocusedDockArea; updateDockAreaFocusStyle(FocusedArea, true); QObject::connect(FocusedArea, SIGNAL(viewToggled(bool)), _this, SLOT(onFocusedDockAreaViewToggled(bool))); + + // Linux specific focus stuff + auto NewFloatingWidget = FocusedDockWidget->dockContainer()->floatingWidget(); + if (FloatingWidget == NewFloatingWidget) + { + return; + } + + if (FloatingWidget) + { + updateFloatingWidgetFocusStyle(FloatingWidget, false); + } + FloatingWidget = NewFloatingWidget; + + if (FloatingWidget) + { + updateFloatingWidgetFocusStyle(FloatingWidget, true); + } } @@ -954,7 +990,7 @@ void CDockManager::onFocusChanged(QWidget* focusedOld, QWidget* focusedNow) DockWidget = internal::findParent(focusedNow); } - if (!DockWidget || !DockWidget->tabWidget()->isVisible()) + if (!DockWidget /*|| !DockWidget->tabWidget()->isVisible()*/) { return; } diff --git a/src/FloatingDockContainer.h b/src/FloatingDockContainer.h index 7defca3..fc92f7d 100644 --- a/src/FloatingDockContainer.h +++ b/src/FloatingDockContainer.h @@ -172,8 +172,7 @@ protected: /** * Call this function to update the window title */ - void updateWindowTitle(); - + void updateWindowTitle(); protected: // reimplements QWidget virtual void changeEvent(QEvent *event) override; diff --git a/src/linux/FloatingWidgetTitleBar.cpp b/src/linux/FloatingWidgetTitleBar.cpp index babcaaa..7b81cac 100644 --- a/src/linux/FloatingWidgetTitleBar.cpp +++ b/src/linux/FloatingWidgetTitleBar.cpp @@ -115,7 +115,7 @@ void FloatingWidgetTitleBarPrivate::createLayout() //============================================================================ CFloatingWidgetTitleBar::CFloatingWidgetTitleBar(CFloatingDockContainer *parent) : - QWidget(parent), + QFrame(parent), d(new FloatingWidgetTitleBarPrivate(this)) { d->FloatingWidget = parent; @@ -172,16 +172,26 @@ void CFloatingWidgetTitleBar::mouseMoveEvent(QMouseEvent *ev) Super::mouseMoveEvent(ev); } + //============================================================================ void CFloatingWidgetTitleBar::enableCloseButton(bool Enable) { d->CloseButton->setEnabled(Enable); } + //============================================================================ void CFloatingWidgetTitleBar::setTitle(const QString &Text) { d->TitleLabel->setText(Text); } + +//============================================================================ +void CFloatingWidgetTitleBar::updateStyle() +{ + internal::repolishStyle(this); + internal::repolishStyle(d->TitleLabel); +} + } // namespace ads diff --git a/src/linux/FloatingWidgetTitleBar.h b/src/linux/FloatingWidgetTitleBar.h index d09ed38..13914db 100644 --- a/src/linux/FloatingWidgetTitleBar.h +++ b/src/linux/FloatingWidgetTitleBar.h @@ -29,7 +29,7 @@ //============================================================================ // INCLUDES //============================================================================ -#include +#include namespace ads { @@ -45,7 +45,7 @@ struct FloatingWidgetTitleBarPrivate; * for the docking system to work properly, we use our own titlebar here to * capture the required mouse events. */ -class CFloatingWidgetTitleBar : public QWidget +class CFloatingWidgetTitleBar : public QFrame { Q_OBJECT private: @@ -75,6 +75,11 @@ public: */ void setTitle(const QString &Text); + /** + * Update stylesheet style if a property changes + */ + void updateStyle(); + signals: /** * This signal is emitted, if the close button is clicked. diff --git a/src/stylesheets/default.css b/src/stylesheets/default.css index 5ace174..0909d1d 100644 --- a/src/stylesheets/default.css +++ b/src/stylesheets/default.css @@ -97,7 +97,7 @@ ads--CDockSplitter::handle } - +/* Focus related styling */ ads--CDockWidgetTab[focused="true"] { background: palette(highlight); @@ -123,8 +123,3 @@ ads--CDockAreaWidget[focused="true"] ads--CDockAreaTitleBar border-bottom: 2px solid palette(highlight); padding-bottom: 0px; } - - - - - diff --git a/src/stylesheets/default_linux.css b/src/stylesheets/default_linux.css index 7a184be..7e8abd7 100644 --- a/src/stylesheets/default_linux.css +++ b/src/stylesheets/default_linux.css @@ -93,4 +93,41 @@ QScrollArea#dockWidgetScrollArea background: rgba(0, 0, 0, 32); } +/* Focus related styling */ +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; +} + + +ads--CFloatingDockContainer[isActiveWindow="true"] ads--CFloatingWidgetTitleBar +{ + background: palette(highlight); +} + + +ads--CFloatingDockContainer[isActiveWindow="true"] ads--CFloatingWidgetTitleBar > QLabel +{ + color: palette(light); +}