1
0
mirror of https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git synced 2025-03-31 10:22:39 +08:00

Deferred focusedDockWidgetChanged signal until dock widget becomes visible

This commit is contained in:
Uwe Kindler 2020-07-03 23:24:20 +02:00
parent 0d242297ff
commit 2de3e7e3be
4 changed files with 34 additions and 2 deletions

View File

@ -590,7 +590,7 @@ CMainWindow::CMainWindow(QWidget *parent) :
// uncomment the following line to enable focus highlighting of the dock // uncomment the following line to enable focus highlighting of the dock
// widget that has the focus // 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 // uncomment if you would like to enable an equal distribution of the
// available size of a splitter to all contained dock widgets // available size of a splitter to all contained dock widgets

View File

@ -13,6 +13,10 @@ int main(int argc, char *argv[])
ads::CDockManager::setConfigFlag(ads::CDockManager::FocusHighlighting, true); ads::CDockManager::setConfigFlag(ads::CDockManager::FocusHighlighting, true);
ads::CDockManager::setConfigFlag(ads::CDockManager::AllTabsHaveCloseButton, true); ads::CDockManager::setConfigFlag(ads::CDockManager::AllTabsHaveCloseButton, true);
auto dockManager = new ads::CDockManager(&w); 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); QAction *action = new QAction("New Delete On Close", &w);
w.menuBar()->addAction(action); w.menuBar()->addAction(action);

View File

@ -38,6 +38,7 @@ struct DockFocusControllerPrivate
CDockFocusController *_this; CDockFocusController *_this;
QPointer<CDockWidget> FocusedDockWidget = nullptr; QPointer<CDockWidget> FocusedDockWidget = nullptr;
QPointer<CDockAreaWidget> FocusedArea = nullptr; QPointer<CDockAreaWidget> FocusedArea = nullptr;
CDockWidget* OldFocusedDockWidget = nullptr;
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
QPointer<CFloatingDockContainer> FloatingWidget = nullptr; QPointer<CFloatingDockContainer> FloatingWidget = nullptr;
#endif #endif
@ -159,14 +160,40 @@ void DockFocusControllerPrivate::updateDockWidgetFocus(CDockWidget* DockWidget)
} }
#endif #endif
if (old != DockWidget) if (old == DockWidget)
{
return;
}
if (DockWidget->isVisible())
{ {
emit DockManager->focusedDockWidgetChanged(old, DockWidget); 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<ads::CDockWidget*>(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) : CDockFocusController::CDockFocusController(CDockManager* DockManager) :
Super(DockManager), Super(DockManager),

View File

@ -34,6 +34,7 @@ private slots:
void onApplicationFocusChanged(QWidget *old, QWidget *now); void onApplicationFocusChanged(QWidget *old, QWidget *now);
void onFocusedDockAreaViewToggled(bool Open); void onFocusedDockAreaViewToggled(bool Open);
void onStateRestored(); void onStateRestored();
void onDockWidgetVisibilityChanged(bool Visible);
public: public:
using Super = QObject; using Super = QObject;