From a3e979a8ad32a256a587addcf961165e60686e5e Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Wed, 3 Jun 2020 19:49:57 +0200 Subject: [PATCH] Disabled setFocus in CDockWidget::setActiveTab --- demo/MainWindow.cpp | 3 ++- src/DockManager.cpp | 29 ++++++++++++++++++++++------- src/DockManager.h | 2 +- src/DockWidgetTab.cpp | 2 +- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index fa87277..56b59a0 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -571,6 +571,7 @@ CMainWindow::CMainWindow(QWidget *parent) : // dock widget. // CDockManager::setConfigFlag(CDockManager::HideSingleCentralWidgetTitleBar, true); + //CDockManager::setConfigFlag(CDockManager::AlwaysShowTabs, true); CDockManager::setConfigFlag(CDockManager::FocusStyling, true); // Now create the dock manager and its content @@ -664,7 +665,7 @@ void CMainWindow::onViewVisibilityChanged(bool Visible) return; } - qDebug() << DockWidget->objectName() << " visibilityChanged(" << Visible << ")"; + //qDebug() << DockWidget->objectName() << " visibilityChanged(" << Visible << ")"; } diff --git a/src/DockManager.cpp b/src/DockManager.cpp index 207d264..b9b2e2d 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -267,10 +267,15 @@ bool DockManagerPrivate::restoreStateFromXml(const QByteArray &state, int versi } ADS_PRINT(s.attributes().value("UserVersion")); - v = s.attributes().value("UserVersion").toInt(&ok); - if (!ok || v != version) + // Older files do not support UserVersion so we skip this if the file does + // not have this attribute + if (!s.attributes().value("UserVersion").isEmpty()) { - return false; + v = s.attributes().value("UserVersion").toInt(&ok); + if (!ok || v != version) + { + return false; + } } s.setFileVersion(v); @@ -498,6 +503,12 @@ void DockManagerPrivate::updateDockWidgetFocus(CDockWidget* DockWidget) { updateDockWidgetFocusStyle(FocusedDockWidget, false); } + + if (DockWidget != FocusedDockWidget) + { + std::cout << "!!!!!!!!!!!! focusedDockWidgetChanged " << (FocusedDockWidget ? FocusedDockWidget->objectName().toStdString() : "-") + << " -> " << (DockWidget ? DockWidget->objectName().toStdString() : "-") << std::endl; + } FocusedDockWidget = DockWidget; updateDockWidgetFocusStyle(FocusedDockWidget, true); NewFocusedDockArea = FocusedDockWidget->dockAreaWidget(); @@ -567,7 +578,7 @@ CDockManager::CDockManager(QWidget *parent) : if (CDockManager::configFlags().testFlag(CDockManager::FocusStyling)) { connect(QApplication::instance(), SIGNAL(focusChanged(QWidget*, QWidget*)), - this, SLOT(onFocusChanged(QWidget*, QWidget*))); + this, SLOT(onApplicationFocusChanged(QWidget*, QWidget*))); } } @@ -1006,7 +1017,7 @@ CIconProvider& CDockManager::iconProvider() //=========================================================================== -void CDockManager::onFocusChanged(QWidget* focusedOld, QWidget* focusedNow) +void CDockManager::onApplicationFocusChanged(QWidget* focusedOld, QWidget* focusedNow) { std::cout << "CDockManager::onFocusChanged" << std::endl; Q_UNUSED(focusedOld) @@ -1033,9 +1044,11 @@ void CDockManager::onFocusChanged(QWidget* focusedOld, QWidget* focusedNow) return; } #else - if (!DockWidget || !DockWidget->tabWidget()->isVisible()) + if (!DockWidget || DockWidget->tabWidget()->isHidden()) { - return; + std::cout << "!DockWidget || !DockWidget->tabWidget()->isVisible() " << (DockWidget ? DockWidget->objectName().toStdString() : "0") << std::endl; + std::cout << "DockWidget->tabWidget()->isHidden() " << (DockWidget ? DockWidget->tabWidget()->isHidden() : false) << std::endl; + return; } #endif @@ -1066,9 +1079,11 @@ void CDockManager::onFocusedDockAreaViewToggled(bool Open) //=========================================================================== void CDockManager::emitWidgetDroppedSignals(QWidget* DroppedWidget) { + std::cout << "CDockManager::emitWidgetDroppedSignals" << std::endl; CDockWidget* DockWidget = qobject_cast(DroppedWidget); if (DockWidget) { + std::cout << "CDockManager::setWidgetFocus " << DockWidget->objectName().toStdString() << std::endl; CDockManager::setWidgetFocus(DockWidget->tabWidget()); emit dockWidgetDropped(DockWidget); return; diff --git a/src/DockManager.h b/src/DockManager.h index 9eda33d..e8b854a 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -85,7 +85,7 @@ private: friend class CDockAreaTitleBar; private slots: - void onFocusChanged(QWidget *old, QWidget *now); + void onApplicationFocusChanged(QWidget *old, QWidget *now); void onFocusedDockAreaViewToggled(bool Open); protected: diff --git a/src/DockWidgetTab.cpp b/src/DockWidgetTab.cpp index 21fb63d..9905a24 100644 --- a/src/DockWidgetTab.cpp +++ b/src/DockWidgetTab.cpp @@ -472,7 +472,7 @@ void CDockWidgetTab::setActiveTab(bool active) bool UpdateFocusStyle = false; if (active && !hasFocus()) { - setFocus(Qt::OtherFocusReason); + //setFocus(Qt::OtherFocusReason); UpdateFocusStyle = true; }