Skip to content

Commit aa25e1f

Browse files
Improved emission of focusedDockWidgetChanged signal to ensure, that the application can restore the focus of the focused application dock widget content
1 parent 0459aff commit aa25e1f

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

src/DockAreaTabBar.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ CDockAreaTabBar::CDockAreaTabBar(CDockAreaWidget* parent) :
138138
d->TabsLayout->addStretch(1);
139139
d->TabsContainerWidget->setLayout(d->TabsLayout);
140140
setWidget(d->TabsContainerWidget);
141+
142+
setFocusPolicy(Qt::NoFocus);
141143
}
142144

143145

src/DockAreaTitleBar.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ CDockAreaTitleBar::CDockAreaTitleBar(CDockAreaWidget* parent) :
269269
d->createTabBar();
270270
d->Layout->addWidget(new CSpacerWidget(this));
271271
d->createButtons();
272+
273+
setFocusPolicy(Qt::NoFocus);
272274
}
273275

274276

@@ -606,7 +608,7 @@ CTitleBarButton::CTitleBarButton(bool visible, QWidget* parent)
606608
Visible(visible),
607609
HideWhenDisabled(CDockManager::testConfigFlag(CDockManager::DockAreaHideDisabledButtons))
608610
{
609-
611+
setFocusPolicy(Qt::NoFocus);
610612
}
611613

612614
//============================================================================

src/DockFocusController.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct DockFocusControllerPrivate
4444
QPointer<CFloatingDockContainer> FloatingWidget = nullptr;
4545
#endif
4646
CDockManager* DockManager;
47+
bool ForceFocusChangedSignal = false;
4748

4849
/**
4950
* Private data constructor
@@ -161,11 +162,12 @@ void DockFocusControllerPrivate::updateDockWidgetFocus(CDockWidget* DockWidget)
161162
}
162163
#endif
163164

164-
if (old == DockWidget)
165+
if (old == DockWidget && !ForceFocusChangedSignal)
165166
{
166167
return;
167168
}
168169

170+
ForceFocusChangedSignal = false;
169171
if (DockWidget->isVisible())
170172
{
171173
emit DockManager->focusedDockWidgetChanged(old, DockWidget);
@@ -243,15 +245,18 @@ void CDockFocusController::onApplicationFocusChanged(QWidget* focusedOld, QWidge
243245
auto DockWidgetTab = qobject_cast<CDockWidgetTab*>(focusedNow);
244246
if (DockWidgetTab)
245247
{
246-
DockWidget = DockWidgetTab->dockWidget();
247-
// If the DockWidgetTab "steals" the focus from a widget in the same
248-
// DockWidget, then we immediately give the focus back to the previous
249-
// focused widget focusedOld
250-
if (DockWidget == d->FocusedDockWidget && focusedOld && focusedOld != focusedNow)
251-
{
252-
focusedOld->setFocus();
253-
return;
254-
}
248+
DockWidget = DockWidgetTab->dockWidget();
249+
// If the DockWidgetTab "steals" the focus from a widget in the same
250+
// DockWidget, then we immediately give the focus back to the previous
251+
// focused widget focusedOld
252+
if (focusedOld)
253+
{
254+
auto OldFocusedDockWidget = internal::findParent<CDockWidget*>(focusedOld);
255+
if (OldFocusedDockWidget && OldFocusedDockWidget == DockWidget)
256+
{
257+
focusedOld->setFocus();
258+
}
259+
}
255260
}
256261

257262
if (!DockWidget)
@@ -322,6 +327,7 @@ void CDockFocusController::notifyWidgetOrAreaRelocation(QWidget* DroppedWidget)
322327
CDockWidget* DockWidget = qobject_cast<CDockWidget*>(DroppedWidget);
323328
if (DockWidget)
324329
{
330+
d->ForceFocusChangedSignal = true;
325331
CDockManager::setWidgetFocus(DockWidget->tabWidget());
326332
return;
327333
}
@@ -333,6 +339,7 @@ void CDockFocusController::notifyWidgetOrAreaRelocation(QWidget* DroppedWidget)
333339
}
334340

335341
DockWidget = DockArea->currentDockWidget();
342+
d->ForceFocusChangedSignal = true;
336343
CDockManager::setWidgetFocus(DockWidget->tabWidget());
337344
}
338345

0 commit comments

Comments
 (0)