Improved emission of focusedDockWidgetChanged signal to ensure, that the application can restore the focus of the focused application dock widget content

This commit is contained in:
Uwe Kindler 2020-07-13 08:41:30 +02:00
parent 0459aff34f
commit aa25e1fd56
3 changed files with 22 additions and 11 deletions

View File

@ -138,6 +138,8 @@ CDockAreaTabBar::CDockAreaTabBar(CDockAreaWidget* parent) :
d->TabsLayout->addStretch(1);
d->TabsContainerWidget->setLayout(d->TabsLayout);
setWidget(d->TabsContainerWidget);
setFocusPolicy(Qt::NoFocus);
}

View File

@ -269,6 +269,8 @@ CDockAreaTitleBar::CDockAreaTitleBar(CDockAreaWidget* parent) :
d->createTabBar();
d->Layout->addWidget(new CSpacerWidget(this));
d->createButtons();
setFocusPolicy(Qt::NoFocus);
}
@ -606,7 +608,7 @@ CTitleBarButton::CTitleBarButton(bool visible, QWidget* parent)
Visible(visible),
HideWhenDisabled(CDockManager::testConfigFlag(CDockManager::DockAreaHideDisabledButtons))
{
setFocusPolicy(Qt::NoFocus);
}
//============================================================================

View File

@ -44,6 +44,7 @@ struct DockFocusControllerPrivate
QPointer<CFloatingDockContainer> FloatingWidget = nullptr;
#endif
CDockManager* DockManager;
bool ForceFocusChangedSignal = false;
/**
* Private data constructor
@ -161,11 +162,12 @@ void DockFocusControllerPrivate::updateDockWidgetFocus(CDockWidget* DockWidget)
}
#endif
if (old == DockWidget)
if (old == DockWidget && !ForceFocusChangedSignal)
{
return;
}
ForceFocusChangedSignal = false;
if (DockWidget->isVisible())
{
emit DockManager->focusedDockWidgetChanged(old, DockWidget);
@ -244,14 +246,17 @@ void CDockFocusController::onApplicationFocusChanged(QWidget* focusedOld, QWidge
if (DockWidgetTab)
{
DockWidget = DockWidgetTab->dockWidget();
// If the DockWidgetTab "steals" the focus from a widget in the same
// DockWidget, then we immediately give the focus back to the previous
// focused widget focusedOld
if (DockWidget == d->FocusedDockWidget && focusedOld && focusedOld != focusedNow)
{
focusedOld->setFocus();
return;
}
// If the DockWidgetTab "steals" the focus from a widget in the same
// DockWidget, then we immediately give the focus back to the previous
// focused widget focusedOld
if (focusedOld)
{
auto OldFocusedDockWidget = internal::findParent<CDockWidget*>(focusedOld);
if (OldFocusedDockWidget && OldFocusedDockWidget == DockWidget)
{
focusedOld->setFocus();
}
}
}
if (!DockWidget)
@ -322,6 +327,7 @@ void CDockFocusController::notifyWidgetOrAreaRelocation(QWidget* DroppedWidget)
CDockWidget* DockWidget = qobject_cast<CDockWidget*>(DroppedWidget);
if (DockWidget)
{
d->ForceFocusChangedSignal = true;
CDockManager::setWidgetFocus(DockWidget->tabWidget());
return;
}
@ -333,6 +339,7 @@ void CDockFocusController::notifyWidgetOrAreaRelocation(QWidget* DroppedWidget)
}
DockWidget = DockArea->currentDockWidget();
d->ForceFocusChangedSignal = true;
CDockManager::setWidgetFocus(DockWidget->tabWidget());
}