Update the state of close button on titlebar and tabbar when CDockWidget::DockWidgetClosable changed. (#240)

This commit is contained in:
shelomentsev 2020-08-21 11:09:13 +05:00 committed by GitHub
parent 0eca1b0433
commit 703a9b3e12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 5 deletions

View File

@ -971,6 +971,16 @@ QSize CDockAreaWidget::minimumSizeHint() const
{
return d->MinSizeHint.isValid() ? d->MinSizeHint : Super::minimumSizeHint();
}
//============================================================================
void CDockAreaWidget::onDockWidgetFeaturesChanged()
{
if (d->TitleBar)
d->updateTitleBarButtonStates();
}
} // namespace ads
//---------------------------------------------------------------------------

View File

@ -65,6 +65,7 @@ private:
friend class CDockWidget;
friend struct DockManagerPrivate;
friend class CDockManager;
void onDockWidgetFeaturesChanged();
private slots:
void onTabCloseRequested(int Index);

View File

@ -340,6 +340,8 @@ void CDockWidget::setFeatures(DockWidgetFeatures features)
d->Features = features;
emit featuresChanged(d->Features);
d->TabWidget->onDockWidgetFeaturesChanged();
if(CDockAreaWidget* DockArea = dockAreaWidget())
DockArea->onDockWidgetFeaturesChanged();
}

View File

@ -134,6 +134,18 @@ struct DockWidgetTabPrivate
}
}
/**
* Update the close button visibility from current feature/config
*/
void updateCloseButtonVisibility(bool active)
{
bool DockWidgetClosable = DockWidget->features().testFlag(CDockWidget::DockWidgetClosable);
bool ActiveTabHasCloseButton = testConfigFlag(CDockManager::ActiveTabHasCloseButton);
bool AllTabsHaveCloseButton = testConfigFlag(CDockManager::AllTabsHaveCloseButton);
bool TabHasCloseButton = (ActiveTabHasCloseButton && active) | AllTabsHaveCloseButton;
CloseButton->setVisible(DockWidgetClosable && TabHasCloseButton);
}
template <typename T>
IFloatingWidget* createFloatingWidget(T* Widget, bool OpaqueUndocking)
{
@ -461,11 +473,7 @@ bool CDockWidgetTab::isActiveTab() const
//============================================================================
void CDockWidgetTab::setActiveTab(bool active)
{
bool DockWidgetClosable = d->DockWidget->features().testFlag(CDockWidget::DockWidgetClosable);
bool ActiveTabHasCloseButton = d->testConfigFlag(CDockManager::ActiveTabHasCloseButton);
bool AllTabsHaveCloseButton = d->testConfigFlag(CDockManager::AllTabsHaveCloseButton);
bool TabHasCloseButton = (ActiveTabHasCloseButton && active) | AllTabsHaveCloseButton;
d->CloseButton->setVisible(DockWidgetClosable && TabHasCloseButton);
d->updateCloseButtonVisibility(active);
// Focus related stuff
if (CDockManager::testConfigFlag(CDockManager::FocusHighlighting) && !d->DockWidget->dockManager()->isRestoringState())
@ -653,6 +661,7 @@ void CDockWidgetTab::onDockWidgetFeaturesChanged()
SizePolicy.setRetainSizeWhenHidden(Features.testFlag(CDockWidget::DockWidgetClosable)
&& d->testConfigFlag(CDockManager::RetainTabSizeWhenCloseButtonHidden));
d->CloseButton->setSizePolicy(SizePolicy);
d->updateCloseButtonVisibility(isActiveTab());
}