Properly implemented focusedDockWidgetChanged() signal

This commit is contained in:
Uwe Kindler 2020-06-05 12:14:26 +02:00
parent d360b4ced2
commit f90f0b0427
3 changed files with 56 additions and 2 deletions

View File

@ -504,6 +504,7 @@ void DockManagerPrivate::updateDockWidgetFocus(CDockWidget* DockWidget)
updateDockWidgetFocusStyle(FocusedDockWidget, false);
}
CDockWidget* old = FocusedDockWidget;
if (DockWidget != FocusedDockWidget)
{
std::cout << "!!!!!!!!!!!! focusedDockWidgetChanged " << (FocusedDockWidget ? FocusedDockWidget->objectName().toStdString() : "-")
@ -554,6 +555,11 @@ void DockManagerPrivate::updateDockWidgetFocus(CDockWidget* DockWidget)
updateFloatingWidgetFocusStyle(FloatingWidget, true);
}
#endif
if (old != DockWidget)
{
emit _this->focusedDockWidgetChanged(old, DockWidget);
}
}
@ -720,6 +726,10 @@ bool CDockManager::restoreState(const QByteArray &state, int version)
show();
}
if (d->FocusedDockWidget)
{
updateDockWidgetFocusStyle(d->FocusedDockWidget, false);
}
return Result;
}
@ -1019,6 +1029,10 @@ CIconProvider& CDockManager::iconProvider()
//===========================================================================
void CDockManager::onApplicationFocusChanged(QWidget* focusedOld, QWidget* focusedNow)
{
if (isRestoringState())
{
return;
}
std::cout << "CDockManager::onFocusChanged" << std::endl;
Q_UNUSED(focusedOld)
if (!focusedNow)
@ -1060,6 +1074,11 @@ void CDockManager::onApplicationFocusChanged(QWidget* focusedOld, QWidget* focus
//===========================================================================
void CDockManager::onFocusedDockAreaViewToggled(bool Open)
{
if (isRestoringState())
{
return;
}
CDockAreaWidget* DockArea = qobject_cast<CDockAreaWidget*>(sender());
if (!DockArea || Open)
{
@ -1079,6 +1098,10 @@ void CDockManager::onFocusedDockAreaViewToggled(bool Open)
//===========================================================================
void CDockManager::notifyWidgetOrAreaRelocation(QWidget* DroppedWidget)
{
if (isRestoringState())
{
return;
}
std::cout << "\n\nCDockManager::notifyWidgetDrop" << std::endl;
CDockWidget* DockWidget = qobject_cast<CDockWidget*>(DroppedWidget);
if (DockWidget)
@ -1104,7 +1127,7 @@ void CDockManager::notifyWidgetOrAreaRelocation(QWidget* DroppedWidget)
void CDockManager::notifyFloatingWidgetDrop(CFloatingDockContainer* FloatingWidget)
{
std::cout << "\n\nCDockManager::notifyFloatingWidgetDrop" << std::endl;
if (!FloatingWidget)
if (!FloatingWidget || isRestoringState())
{
return;
}

View File

@ -517,6 +517,13 @@ signals:
* docking system but it is not deleted yet.
*/
void dockWidgetRemoved(CDockWidget* DockWidget);
/**
* This signal is emitted if the focused dock widget changed.
* Both old and now can be nullptr.
* The focused dock widget is the one that is highlighted in the GUI
*/
void focusedDockWidgetChanged(CDockWidget* old, CDockWidget* now);
}; // class DockManager
} // namespace ads
//-----------------------------------------------------------------------------

View File

@ -466,7 +466,31 @@ void CDockWidgetTab::setActiveTab(bool active)
bool AllTabsHaveCloseButton = d->testConfigFlag(CDockManager::AllTabsHaveCloseButton);
bool TabHasCloseButton = (ActiveTabHasCloseButton && active) | AllTabsHaveCloseButton;
d->CloseButton->setVisible(DockWidgetClosable && TabHasCloseButton);
/*if (d->IsActiveTab == active)
{
return;
}*/
if (CDockManager::configFlags().testFlag(CDockManager::FocusStyling) && !d->DockWidget->dockManager()->isRestoringState())
{
bool UpdateFocusStyle = false;
if (active && !hasFocus())
{
setFocus(Qt::OtherFocusReason);
UpdateFocusStyle = true;
}
if (d->IsActiveTab == active)
{
if (UpdateFocusStyle)
{
updateStyle();
}
return;
}
}
else if (d->IsActiveTab == active)
{
return;
}