From 34cc91a9af1bcbfc76110bd22291c834348b8dc4 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Fri, 23 Jun 2023 21:06:52 +0200 Subject: [PATCH] Fixed #527 - updateDockWidgetFocusStyle() function error --- src/DockFocusController.cpp | 11 ++++++++++- src/DockFocusController.h | 6 ++++++ src/DockWidgetTab.cpp | 9 ++++++++- src/DockWidgetTab.h | 6 ++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/DockFocusController.cpp b/src/DockFocusController.cpp index a85d010..50928b1 100644 --- a/src/DockFocusController.cpp +++ b/src/DockFocusController.cpp @@ -49,6 +49,7 @@ struct DockFocusControllerPrivate #endif CDockManager* DockManager; bool ForceFocusChangedSignal = false; + bool TabPressed = false; /** * Private data constructor @@ -267,7 +268,9 @@ void CDockFocusController::onApplicationFocusChanged(QWidget* focusedOld, QWidge { Q_UNUSED(focusedOld); - if (d->DockManager->isRestoringState()) + // Ignore focus changes if we are restoring state, or if user clicked + // a tab wich in turn caused the focus change + if (d->DockManager->isRestoringState() || d->TabPressed) { return; } @@ -418,6 +421,12 @@ CDockWidget* CDockFocusController::focusedDockWidget() const return d->FocusedDockWidget.data(); } + +//========================================================================== +void CDockFocusController::setDockWidgetTabPressed(bool Value) +{ + d->TabPressed = Value; +} } // namespace ads //--------------------------------------------------------------------------- diff --git a/src/DockFocusController.h b/src/DockFocusController.h index 06ec049..27d9fc1 100644 --- a/src/DockFocusController.h +++ b/src/DockFocusController.h @@ -80,6 +80,12 @@ public: */ void clearDockWidgetFocus(CDockWidget* dockWidget); + /** + * Notifies the dock focus controller, that a the mouse is pressed or + * released + */ + void setDockWidgetTabPressed(bool Value); + public Q_SLOTS: /** * Request a focus change to the given dock widget diff --git a/src/DockWidgetTab.cpp b/src/DockWidgetTab.cpp index 5829a26..4c9b0c2 100644 --- a/src/DockWidgetTab.cpp +++ b/src/DockWidgetTab.cpp @@ -79,6 +79,7 @@ struct DockWidgetTabPrivate QSpacerItem* IconTextSpacer; QPoint TabDragStartPosition; QSize IconSize; + bool MousePressed = false; /** * Private data constructor @@ -372,10 +373,12 @@ void CDockWidgetTab::mousePressEvent(QMouseEvent* ev) if (ev->button() == Qt::LeftButton) { ev->accept(); + d->MousePressed = true; d->saveDragStartMousePosition(internal::globalPositionOf(ev)); d->DragState = DraggingMousePressed; if (CDockManager::testConfigFlag(CDockManager::FocusHighlighting)) { + d->focusController()->setDockWidgetTabPressed(true); d->focusController()->setDockWidgetTabFocused(this); } Q_EMIT clicked(); @@ -391,6 +394,7 @@ void CDockWidgetTab::mouseReleaseEvent(QMouseEvent* ev) { if (ev->button() == Qt::LeftButton) { + d->MousePressed = false; auto CurrentDragState = d->DragState; d->GlobalDragStartMousePosition = QPoint(); d->DragStartMousePosition = QPoint(); @@ -412,7 +416,9 @@ void CDockWidgetTab::mouseReleaseEvent(QMouseEvent* ev) d->FloatingWidget->finishDragging(); break; - default:; // do nothing + default: + d->focusController()->setDockWidgetTabPressed(false); + break; // do nothing } } else if (ev->button() == Qt::MiddleButton) @@ -802,6 +808,7 @@ void CDockWidgetTab::setIconSize(const QSize& Size) d->IconSize = Size; d->updateIcon(); } + } // namespace ads //--------------------------------------------------------------------------- // EOF DockWidgetTab.cpp diff --git a/src/DockWidgetTab.h b/src/DockWidgetTab.h index 11d0ba5..309ee41 100644 --- a/src/DockWidgetTab.h +++ b/src/DockWidgetTab.h @@ -178,6 +178,12 @@ public: */ void setIconSize(const QSize& Size); + /** + * Returns true, if the tab has been clicked and the mouse is currently + * pressed. + */ + bool mousePressed() const; + public Q_SLOTS: virtual void setVisible(bool visible) override;