Skip to content

Commit 2de3e7e

Browse files
Deferred focusedDockWidgetChanged signal until dock widget becomes visible
1 parent 0d24229 commit 2de3e7e

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

demo/MainWindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ CMainWindow::CMainWindow(QWidget *parent) :
590590

591591
// uncomment the following line to enable focus highlighting of the dock
592592
// widget that has the focus
593-
// CDockManager::setConfigFlag(CDockManager::FocusHighlighting, true);
593+
CDockManager::setConfigFlag(CDockManager::FocusHighlighting, true);
594594

595595
// uncomment if you would like to enable an equal distribution of the
596596
// available size of a splitter to all contained dock widgets

examples/deleteonclose/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ int main(int argc, char *argv[])
1313
ads::CDockManager::setConfigFlag(ads::CDockManager::FocusHighlighting, true);
1414
ads::CDockManager::setConfigFlag(ads::CDockManager::AllTabsHaveCloseButton, true);
1515
auto dockManager = new ads::CDockManager(&w);
16+
QObject::connect(dockManager, &ads::CDockManager::focusedDockWidgetChanged, [] (ads::CDockWidget* old, ads::CDockWidget* now) {
17+
qDebug() << "CDockManager::focusedDockWidgetChanged: " << now->objectName() << " visible: " << now->isVisible();
18+
now->widget()->setFocus();
19+
});
1620

1721
QAction *action = new QAction("New Delete On Close", &w);
1822
w.menuBar()->addAction(action);

src/DockFocusController.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct DockFocusControllerPrivate
3838
CDockFocusController *_this;
3939
QPointer<CDockWidget> FocusedDockWidget = nullptr;
4040
QPointer<CDockAreaWidget> FocusedArea = nullptr;
41+
CDockWidget* OldFocusedDockWidget = nullptr;
4142
#ifdef Q_OS_LINUX
4243
QPointer<CFloatingDockContainer> FloatingWidget = nullptr;
4344
#endif
@@ -159,14 +160,40 @@ void DockFocusControllerPrivate::updateDockWidgetFocus(CDockWidget* DockWidget)
159160
}
160161
#endif
161162

162-
if (old != DockWidget)
163+
if (old == DockWidget)
164+
{
165+
return;
166+
}
167+
168+
if (DockWidget->isVisible())
163169
{
164170
emit DockManager->focusedDockWidgetChanged(old, DockWidget);
165171
}
172+
else
173+
{
174+
OldFocusedDockWidget = old;
175+
QObject::connect(DockWidget, SIGNAL(visibilityChanged(bool)), _this, SLOT(onDockWidgetVisibilityChanged(bool)));
176+
}
166177
}
167178

168179

169180

181+
//============================================================================
182+
void CDockFocusController::onDockWidgetVisibilityChanged(bool Visible)
183+
{
184+
auto Sender = sender();
185+
auto DockWidget = qobject_cast<ads::CDockWidget*>(Sender);
186+
/*qDebug() << "sender: " << Sender->metaObject()->className();
187+
qDebug() << "onDockWidgetVisibilityChanged " << Sender->objectName() << " Visible " << Visible;*/
188+
disconnect(Sender, SIGNAL(visibilityChanged(bool)), this, SLOT(onDockWidgetVisibilityChanged(bool)));
189+
if (DockWidget && Visible)
190+
{
191+
//qDebug() << "emit d->DockManager->focusedDockWidgetChanged";
192+
emit d->DockManager->focusedDockWidgetChanged(d->OldFocusedDockWidget, DockWidget);
193+
}
194+
}
195+
196+
170197
//============================================================================
171198
CDockFocusController::CDockFocusController(CDockManager* DockManager) :
172199
Super(DockManager),

src/DockFocusController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ private slots:
3434
void onApplicationFocusChanged(QWidget *old, QWidget *now);
3535
void onFocusedDockAreaViewToggled(bool Open);
3636
void onStateRestored();
37+
void onDockWidgetVisibilityChanged(bool Visible);
3738

3839
public:
3940
using Super = QObject;

0 commit comments

Comments
 (0)