mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-25 07:31:33 +08:00
Properly implemented setting enable state of dock area close button
This commit is contained in:
parent
b3a272110a
commit
b9265fccec
@ -54,6 +54,8 @@
|
|||||||
#include "DockSplitter.h"
|
#include "DockSplitter.h"
|
||||||
#include "DockAreaTitleBar.h"
|
#include "DockAreaTitleBar.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
namespace ads
|
namespace ads
|
||||||
{
|
{
|
||||||
@ -242,6 +244,7 @@ struct DockAreaWidgetPrivate
|
|||||||
DockAreaLayout* ContentsLayout;
|
DockAreaLayout* ContentsLayout;
|
||||||
CDockAreaTitleBar* TitleBar;
|
CDockAreaTitleBar* TitleBar;
|
||||||
CDockManager* DockManager = nullptr;
|
CDockManager* DockManager = nullptr;
|
||||||
|
bool UpdateCloseButton = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private data constructor
|
* Private data constructor
|
||||||
@ -293,6 +296,11 @@ struct DockAreaWidgetPrivate
|
|||||||
{
|
{
|
||||||
return TitleBar->tabBar();
|
return TitleBar->tabBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Udpates the enable state of the close button
|
||||||
|
*/
|
||||||
|
void updateCloseButtonState();
|
||||||
};
|
};
|
||||||
// struct DockAreaWidgetPrivate
|
// 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) :
|
CDockAreaWidget::CDockAreaWidget(CDockManager* DockManager, CDockContainerWidget* parent) :
|
||||||
QFrame(parent),
|
QFrame(parent),
|
||||||
@ -383,6 +410,7 @@ void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget,
|
|||||||
setCurrentIndex(index);
|
setCurrentIndex(index);
|
||||||
}
|
}
|
||||||
DockWidget->setDockArea(this);
|
DockWidget->setDockArea(this);
|
||||||
|
d->updateCloseButtonState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -414,6 +442,7 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
|
|||||||
hideAreaWithNoVisibleContent();
|
hideAreaWithNoVisibleContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d->updateCloseButtonState();
|
||||||
updateTitleBarVisibility();
|
updateTitleBarVisibility();
|
||||||
auto TopLevelDockWidget = dockContainer()->topLevelDockWidget();
|
auto TopLevelDockWidget = dockContainer()->topLevelDockWidget();
|
||||||
if (TopLevelDockWidget)
|
if (TopLevelDockWidget)
|
||||||
@ -730,10 +759,19 @@ CDockWidget::DockWidgetFeatures CDockAreaWidget::features() const
|
|||||||
void CDockAreaWidget::toggleView(bool Open)
|
void CDockAreaWidget::toggleView(bool Open)
|
||||||
{
|
{
|
||||||
setVisible(Open);
|
setVisible(Open);
|
||||||
|
|
||||||
emit viewToggled(Open);
|
emit viewToggled(Open);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
void CDockAreaWidget::setVisible(bool Visible)
|
||||||
|
{
|
||||||
|
Super::setVisible(Visible);
|
||||||
|
d->updateCloseButtonState();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
QAbstractButton* CDockAreaWidget::titleBarButton(TitleBarButton which) const
|
QAbstractButton* CDockAreaWidget::titleBarButton(TitleBarButton which) const
|
||||||
{
|
{
|
||||||
|
@ -241,6 +241,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
QAbstractButton* titleBarButton(TitleBarButton which) const;
|
QAbstractButton* titleBarButton(TitleBarButton which) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the close button if visibility changed
|
||||||
|
*/
|
||||||
|
virtual void setVisible(bool Visible) override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
/**
|
/**
|
||||||
* This activates the tab for the given tab index.
|
* This activates the tab for the given tab index.
|
||||||
|
@ -627,11 +627,10 @@ bool DockContainerWidgetPrivate::restoreDockArea(QXmlStreamReader& s,
|
|||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Dock Widget found - parent " << DockWidget->parent();
|
qDebug() << "Dock Widget found - parent " << DockWidget->parent();
|
||||||
DockArea->addDockWidget(DockWidget);
|
|
||||||
|
|
||||||
// We hide the DockArea here to prevent the short display (the flashing)
|
// We hide the DockArea here to prevent the short display (the flashing)
|
||||||
// of the dock areas during application startup
|
// of the dock areas during application startup
|
||||||
DockArea->hide();
|
DockArea->hide();
|
||||||
|
DockArea->addDockWidget(DockWidget);
|
||||||
DockWidget->setToggleViewActionChecked(!Closed);
|
DockWidget->setToggleViewActionChecked(!Closed);
|
||||||
DockWidget->setClosedState(Closed);
|
DockWidget->setClosedState(Closed);
|
||||||
DockWidget->setProperty("closed", Closed);
|
DockWidget->setProperty("closed", Closed);
|
||||||
|
@ -152,6 +152,23 @@ public:
|
|||||||
StateFloating
|
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
|
enum eInsertMode
|
||||||
{
|
{
|
||||||
AutoScrollArea,
|
AutoScrollArea,
|
||||||
|
Loading…
Reference in New Issue
Block a user