diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index c73a205..398f059 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -590,7 +590,7 @@ CMainWindow::CMainWindow(QWidget *parent) : // uncomment the following line to enable focus highlighting of the dock // widget that has the focus - // CDockManager::setConfigFlag(CDockManager::FocusHighlighting, true); + CDockManager::setConfigFlag(CDockManager::FocusHighlighting, true); // uncomment if you would like to enable an equal distribution of the // available size of a splitter to all contained dock widgets diff --git a/examples/deleteonclose/main.cpp b/examples/deleteonclose/main.cpp index d4da8c1..74150db 100644 --- a/examples/deleteonclose/main.cpp +++ b/examples/deleteonclose/main.cpp @@ -13,6 +13,10 @@ int main(int argc, char *argv[]) ads::CDockManager::setConfigFlag(ads::CDockManager::FocusHighlighting, true); ads::CDockManager::setConfigFlag(ads::CDockManager::AllTabsHaveCloseButton, true); auto dockManager = new ads::CDockManager(&w); + QObject::connect(dockManager, &ads::CDockManager::focusedDockWidgetChanged, [] (ads::CDockWidget* old, ads::CDockWidget* now) { + qDebug() << "CDockManager::focusedDockWidgetChanged: " << now->objectName() << " visible: " << now->isVisible(); + now->widget()->setFocus(); + }); QAction *action = new QAction("New Delete On Close", &w); w.menuBar()->addAction(action); diff --git a/src/DockFocusController.cpp b/src/DockFocusController.cpp index cf707e7..9cc93eb 100644 --- a/src/DockFocusController.cpp +++ b/src/DockFocusController.cpp @@ -38,6 +38,7 @@ struct DockFocusControllerPrivate CDockFocusController *_this; QPointer FocusedDockWidget = nullptr; QPointer FocusedArea = nullptr; + CDockWidget* OldFocusedDockWidget = nullptr; #ifdef Q_OS_LINUX QPointer FloatingWidget = nullptr; #endif @@ -159,14 +160,40 @@ void DockFocusControllerPrivate::updateDockWidgetFocus(CDockWidget* DockWidget) } #endif - if (old != DockWidget) + if (old == DockWidget) + { + return; + } + + if (DockWidget->isVisible()) { emit DockManager->focusedDockWidgetChanged(old, DockWidget); } + else + { + OldFocusedDockWidget = old; + QObject::connect(DockWidget, SIGNAL(visibilityChanged(bool)), _this, SLOT(onDockWidgetVisibilityChanged(bool))); + } } +//============================================================================ +void CDockFocusController::onDockWidgetVisibilityChanged(bool Visible) +{ + auto Sender = sender(); + auto DockWidget = qobject_cast(Sender); + /*qDebug() << "sender: " << Sender->metaObject()->className(); + qDebug() << "onDockWidgetVisibilityChanged " << Sender->objectName() << " Visible " << Visible;*/ + disconnect(Sender, SIGNAL(visibilityChanged(bool)), this, SLOT(onDockWidgetVisibilityChanged(bool))); + if (DockWidget && Visible) + { + //qDebug() << "emit d->DockManager->focusedDockWidgetChanged"; + emit d->DockManager->focusedDockWidgetChanged(d->OldFocusedDockWidget, DockWidget); + } +} + + //============================================================================ CDockFocusController::CDockFocusController(CDockManager* DockManager) : Super(DockManager), diff --git a/src/DockFocusController.h b/src/DockFocusController.h index 70abdab..8adfab5 100644 --- a/src/DockFocusController.h +++ b/src/DockFocusController.h @@ -34,6 +34,7 @@ private slots: void onApplicationFocusChanged(QWidget *old, QWidget *now); void onFocusedDockAreaViewToggled(bool Open); void onStateRestored(); + void onDockWidgetVisibilityChanged(bool Visible); public: using Super = QObject;