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->TabsLayout->addStretch(1);
d->TabsContainerWidget->setLayout(d->TabsLayout); d->TabsContainerWidget->setLayout(d->TabsLayout);
setWidget(d->TabsContainerWidget); setWidget(d->TabsContainerWidget);
setFocusPolicy(Qt::NoFocus);
} }

View File

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

View File

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