diff --git a/src/DockManager.cpp b/src/DockManager.cpp index 711e58a..f3168f1 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -442,8 +442,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*))); + connect(QApplication::instance(), SIGNAL(focusChanged(QWidget*, QWidget*)), + this, SLOT(onFocusChanged(QWidget*, QWidget*))); } //============================================================================ @@ -880,29 +880,42 @@ CIconProvider& CDockManager::iconProvider() //=========================================================================== -void CDockManager::onFocusObjectChanged(QObject *focusObject) +void updateDockWidgetFocusStyle(CDockWidget* DockWidget, bool Focused) { - if (!focusObject) - { - return; - } + DockWidget->setProperty("focused", Focused); + DockWidget->tabWidget()->setProperty("focused", Focused); + DockWidget->tabWidget()->updateStyle(); + internal::repolishStyle(DockWidget); +} - auto FocusWidget = qobject_cast(focusObject); - if (!FocusWidget) + +//=========================================================================== +void updateDockAreaFocusStyle(CDockAreaWidget* DockArea, bool Focused) +{ + DockArea->setProperty("focused", Focused); + internal::repolishStyle(DockArea); + internal::repolishStyle(DockArea->titleBar()); +} + + +//=========================================================================== +void CDockManager::onFocusChanged(QWidget* focusedOld, QWidget* focusedNow) +{ + Q_UNUSED(focusedOld) + if (!focusedNow) { return; } CDockWidget* DockWidget = nullptr; - - auto DockWidgetTab = qobject_cast(focusObject); + auto DockWidgetTab = qobject_cast(focusedNow); if (DockWidgetTab) { DockWidget = DockWidgetTab->dockWidget(); } else { - DockWidget = internal::findParent(FocusWidget); + DockWidget = internal::findParent(focusedNow); } if (!DockWidget) @@ -910,32 +923,14 @@ void CDockManager::onFocusObjectChanged(QObject *focusObject) return; } - QList DockWidgets; CDockAreaWidget* NewFocusedDockArea = nullptr; if (d->FocusedDockWidget) { - - d->FocusedDockWidget->setProperty("focused", false); - d->FocusedDockWidget->tabWidget()->setProperty("focused", false); - DockWidgets.append(d->FocusedDockWidget); + updateDockWidgetFocusStyle(d->FocusedDockWidget, false); } d->FocusedDockWidget = DockWidget; - d->FocusedDockWidget->setProperty("focused", true); - d->FocusedDockWidget->tabWidget()->setProperty("focused", true); - //connect(d->FocusedDockWidget, SIGNAL(closed()), this, SLOT(onFocusedDockWidgetClosed())); + updateDockWidgetFocusStyle(d->FocusedDockWidget, 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 (!NewFocusedDockArea || (d->FocusedArea == NewFocusedDockArea)) { return; @@ -944,26 +939,15 @@ void CDockManager::onFocusObjectChanged(QObject *focusObject) if (d->FocusedArea) { disconnect(d->FocusedArea, SIGNAL(viewToggled(bool)), this, SLOT(onFocusedDockAreaViewToggled(bool))); - d->FocusedArea->setProperty("focused", false); - internal::repolishStyle(d->FocusedArea); - internal::repolishStyle(d->FocusedArea->titleBar()); + updateDockAreaFocusStyle(d->FocusedArea, false); } - NewFocusedDockArea->setProperty("focused", true); - internal::repolishStyle(NewFocusedDockArea); - internal::repolishStyle(NewFocusedDockArea->titleBar()); d->FocusedArea = NewFocusedDockArea; + updateDockAreaFocusStyle(d->FocusedArea, true); connect(d->FocusedArea, SIGNAL(viewToggled(bool)), this, SLOT(onFocusedDockAreaViewToggled(bool))); } -//=========================================================================== -void CDockManager::onFocusedDockWidgetClosed() -{ - std::cout << "CDockManager::onFocusedDockWidgetClosed()" << std::endl; -} - - //=========================================================================== void CDockManager::onFocusedDockAreaViewToggled(bool Open) { diff --git a/src/DockManager.h b/src/DockManager.h index 8999277..ec9bc74 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -85,8 +85,7 @@ private: friend class CDockAreaTitleBar; private slots: - void onFocusObjectChanged(QObject *focusObject); - void onFocusedDockWidgetClosed(); + void onFocusChanged(QWidget *old, QWidget *now); void onFocusedDockAreaViewToggled(bool Open); protected: diff --git a/src/DockWidgetTab.h b/src/DockWidgetTab.h index 70e379a..3ed7df8 100644 --- a/src/DockWidgetTab.h +++ b/src/DockWidgetTab.h @@ -72,11 +72,6 @@ protected: */ virtual void mouseDoubleClickEvent(QMouseEvent *event) override; - /** - * Update stylesheet style if a property changes - */ - void updateStyle(); - public: using Super = QFrame; /** @@ -159,6 +154,10 @@ public: */ void setElideMode(Qt::TextElideMode mode); + /** + * Update stylesheet style if a property changes + */ + void updateStyle(); public slots: virtual void setVisible(bool visible) override;