Properly implemented setting enable state of dock area close button

This commit is contained in:
Uwe Kindler 2018-11-08 12:22:15 +01:00
parent b3a272110a
commit b9265fccec
4 changed files with 61 additions and 2 deletions

View File

@ -54,6 +54,8 @@
#include "DockSplitter.h"
#include "DockAreaTitleBar.h"
#include <iostream>
namespace ads
{
@ -242,6 +244,7 @@ struct DockAreaWidgetPrivate
DockAreaLayout* ContentsLayout;
CDockAreaTitleBar* TitleBar;
CDockManager* DockManager = nullptr;
bool UpdateCloseButton = false;
/**
* Private data constructor
@ -293,6 +296,11 @@ struct DockAreaWidgetPrivate
{
return TitleBar->tabBar();
}
/**
* Udpates the enable state of the close button
*/
void updateCloseButtonState();
};
// struct DockAreaWidgetPrivate
@ -319,6 +327,25 @@ void DockAreaWidgetPrivate::createTitleBar()
}
//============================================================================
void DockAreaWidgetPrivate::updateCloseButtonState()
{
if (_this->isHidden())
{
UpdateCloseButton = true;
return;
}
if (!UpdateCloseButton)
{
return;
}
TitleBar->button(TitleBarButtonClose)->setEnabled(
_this->features().testFlag(CDockWidget::DockWidgetClosable));
UpdateCloseButton = false;
}
//============================================================================
CDockAreaWidget::CDockAreaWidget(CDockManager* DockManager, CDockContainerWidget* parent) :
QFrame(parent),
@ -383,6 +410,7 @@ void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget,
setCurrentIndex(index);
}
DockWidget->setDockArea(this);
d->updateCloseButtonState();
}
@ -414,6 +442,7 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
hideAreaWithNoVisibleContent();
}
d->updateCloseButtonState();
updateTitleBarVisibility();
auto TopLevelDockWidget = dockContainer()->topLevelDockWidget();
if (TopLevelDockWidget)
@ -730,10 +759,19 @@ CDockWidget::DockWidgetFeatures CDockAreaWidget::features() const
void CDockAreaWidget::toggleView(bool Open)
{
setVisible(Open);
emit viewToggled(Open);
}
//============================================================================
void CDockAreaWidget::setVisible(bool Visible)
{
Super::setVisible(Visible);
d->updateCloseButtonState();
}
//============================================================================
QAbstractButton* CDockAreaWidget::titleBarButton(TitleBarButton which) const
{

View File

@ -241,6 +241,11 @@ public:
*/
QAbstractButton* titleBarButton(TitleBarButton which) const;
/**
* Update the close button if visibility changed
*/
virtual void setVisible(bool Visible) override;
public slots:
/**
* This activates the tab for the given tab index.

View File

@ -627,11 +627,10 @@ bool DockContainerWidgetPrivate::restoreDockArea(QXmlStreamReader& s,
}
qDebug() << "Dock Widget found - parent " << DockWidget->parent();
DockArea->addDockWidget(DockWidget);
// We hide the DockArea here to prevent the short display (the flashing)
// of the dock areas during application startup
DockArea->hide();
DockArea->addDockWidget(DockWidget);
DockWidget->setToggleViewActionChecked(!Closed);
DockWidget->setClosedState(Closed);
DockWidget->setProperty("closed", Closed);

View File

@ -152,6 +152,23 @@ public:
StateFloating
};
/**
* Sets the widget for the dock widget to widget.
* The InsertMode defines how the widget is inserted into the dock widget.
* The content of a dock widget should be resizable do a very small size to
* prevent the dock widget from blocking the resizing. To ensure, that a
* dock widget can be resized very well, it is better to insert the content+
* widget into a scroll area or to provide a widget that is already a scroll
* area or that contains a scroll area.
* If the InsertMode is AutoScrollArea, the DockWidget tries to automatically
* detect how to insert the given widget. If the widget is derived from
* QScrollArea (i.e. an QAbstractItemView), then the widget is inserted
* directly. If the given widget is not a scroll area, the widget will be
* inserted into a scroll area.
* To force insertion into a scroll area, you can also provide the InsertMode
* ForceScrollArea. To prevent insertion into a scroll area, you can
* provide the InsertMode ForceNoScrollArea
*/
enum eInsertMode
{
AutoScrollArea,