Properly implemented showing and hiding of TitleBarUndockButton

This commit is contained in:
Uwe Kindler 2018-11-05 09:07:18 +01:00
parent 188624440b
commit c973482b2b
8 changed files with 377 additions and 47 deletions

View File

@ -66,8 +66,8 @@ static const int APPEND = -1;
/**
* New dock area layout mimics stack layout but ony inserts the current
* widget
* New dock area layout mimics stack layout but only inserts the current
* widget into the internal QLayout object
*/
class CDockAreaLayout
{
@ -78,17 +78,27 @@ private:
QWidget* m_CurrentWidget = nullptr;
public:
/**
* Creates an instance with the given parent layout
*/
CDockAreaLayout(QBoxLayout* ParentLayout)
: m_ParentLayout(ParentLayout)
{
}
/**
* Returns the number of widgets in this layout
*/
int count() const
{
return m_Widgets.count();
}
/**
* Inserts the widget at the given index position into the internal widget
* list
*/
void insertWidget(int index, QWidget* Widget)
{
Widget->setParent(0);
@ -110,6 +120,9 @@ public:
}
}
/**
* Removes the given widget from the lyout
*/
void removeWidget(QWidget* Widget)
{
if (currentWidget() == Widget)
@ -125,11 +138,17 @@ public:
m_Widgets.removeOne(Widget);
}
/**
* Returns the current selected widget
*/
QWidget* currentWidget() const
{
return m_CurrentWidget;
}
/**
* Activates the widget with the give index.
*/
void setCurrentIndex(int index)
{
QWidget *prev = currentWidget();
@ -169,26 +188,41 @@ public:
}
}
/**
* Returns the index of the current active widget
*/
int currentIndex() const
{
return m_CurrentIndex;
}
/**
* Returns true if there are no widgets in the layout
*/
bool isEmpty() const
{
return m_Widgets.empty();
}
/**
* Returns the index of the given widget
*/
int indexOf(QWidget* w) const
{
return m_Widgets.indexOf(w);
}
/**
* Returns the widget for the given index
*/
QWidget* widget(int index) const
{
return (index < m_Widgets.size()) ? m_Widgets.at(index) : nullptr;
}
/**
* Returns the geometry of the current active widget
*/
QRect geometry() const
{
return m_Widgets.empty() ? QRect() : currentWidget()->geometry();
@ -254,12 +288,6 @@ struct DockAreaWidgetPrivate
return DockWidget->property(INDEX_PROPERTY).toInt();
}
/**
* Updates the tab bar visibility depending on the number of dock widgets
* in this area
*/
void updateTitleBarVisibility();
/**
* Convenience function for tabbar access
*/
@ -293,19 +321,6 @@ void DockAreaWidgetPrivate::createTitleBar()
}
//============================================================================
void DockAreaWidgetPrivate::updateTitleBarVisibility()
{
CDockContainerWidget* Container = _this->dockContainer();
if (!Container)
{
return;
}
TitleBar->setVisible(!Container->isFloating() || !Container->hasTopLevelDockWidget());
}
//============================================================================
CDockAreaWidget::CDockAreaWidget(CDockManager* DockManager, CDockContainerWidget* parent) :
QFrame(parent),
@ -402,7 +417,7 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
hideAreaWithNoVisibleContent();
}
d->updateTitleBarVisibility();
updateTitleBarVisibility();
auto TopLevelDockWidget = dockContainer()->topLevelDockWidget();
if (TopLevelDockWidget)
{
@ -440,7 +455,7 @@ void CDockAreaWidget::hideAreaWithNoVisibleContent()
return;
}
d->updateTitleBarVisibility();
updateTitleBarVisibility();
auto TopLevelWidget = Container->topLevelDockWidget();
auto FloatingWidget = Container->floatingWidget();
if (TopLevelWidget)
@ -626,14 +641,20 @@ void CDockAreaWidget::toggleDockWidgetView(CDockWidget* DockWidget, bool Open)
{
Q_UNUSED(DockWidget);
Q_UNUSED(Open);
updateTabBarVisibility();
updateTitleBarVisibility();
}
//============================================================================
void CDockAreaWidget::updateTabBarVisibility()
void CDockAreaWidget::updateTitleBarVisibility()
{
d->updateTitleBarVisibility();
CDockContainerWidget* Container = dockContainer();
if (!Container)
{
return;
}
d->TitleBar->setVisible(!Container->isFloating() || !Container->hasTopLevelDockWidget());
}

View File

@ -121,7 +121,7 @@ protected:
/**
* Updates the dock area layout and components visibility
*/
void updateTabBarVisibility();
void updateTitleBarVisibility();
/**
* This is the internal private function for setting the current widget.

View File

@ -37,6 +37,7 @@
#include <QVariant>
#include <QDebug>
#include <QXmlStreamWriter>
#include <QAbstractButton>
#include "DockManager.h"
#include "DockAreaWidget.h"
@ -105,6 +106,7 @@ public:
bool isFloating = false;
CDockAreaWidget* LastAddedAreaCache[5]{0, 0, 0, 0, 0};
int VisibleDockAreaCount = -1;
CDockAreaWidget* TopLevelDockArea = nullptr;
/**
* Private data constructor
@ -144,6 +146,12 @@ public:
*/
void addDockAreasToList(const QList<CDockAreaWidget*> NewDockAreas);
/**
* Wrapper function for DockAreas append, that ensures that dock area signals
* are properly connected to dock container slots
*/
void appendDockAreas(const QList<CDockAreaWidget*> NewDockAreas);
/**
* Save state of child nodes
*/
@ -208,11 +216,31 @@ public:
return VisibleDockAreaCount;
}
/**
* The visible dock area count changes, if dock areas are remove, added or
* when its view is toggled
*/
void onVisibleDockAreaCountChanged();
void emitDockAreasRemoved()
{
onVisibleDockAreaCountChanged();
emit _this->dockAreasRemoved();
}
void emitDockAreasAdded()
{
onVisibleDockAreaCountChanged();
emit _this->dockAreasAdded();
}
// private slots: ------------------------------------------------------------
void onDockAreaViewToggled(bool Visible)
{
std::cout << "onDockAreaViewToggled " << Visible << std::endl;
CDockAreaWidget* DockArea = qobject_cast<CDockAreaWidget*>(_this->sender());
VisibleDockAreaCount += Visible ? 1 : -1;
onVisibleDockAreaCountChanged();
emit _this->dockAreaViewToggled(DockArea, Visible);
}
}; // struct DockContainerWidgetPrivate
@ -225,6 +253,24 @@ DockContainerWidgetPrivate::DockContainerWidgetPrivate(CDockContainerWidget* _pu
}
//============================================================================
void DockContainerWidgetPrivate::onVisibleDockAreaCountChanged()
{
auto TopLevelDockArea = _this->topLevelDockArea();
if (TopLevelDockArea)
{
this->TopLevelDockArea = TopLevelDockArea;
TopLevelDockArea->titleBarButton(TitleBarButtonUndock)->setVisible(false || !_this->isFloating());
}
else if (this->TopLevelDockArea)
{
this->TopLevelDockArea->titleBarButton(TitleBarButtonUndock)->setVisible(true);
this->TopLevelDockArea = nullptr;
}
}
//============================================================================
void DockContainerWidgetPrivate::dropIntoContainer(CFloatingDockContainer* FloatingWidget,
DockWidgetArea area)
@ -299,7 +345,7 @@ void DockContainerWidgetPrivate::dropIntoSection(CFloatingDockContainer* Floatin
}
TargetArea->setCurrentIndex(0); // make the topmost widget active
FloatingWidget->deleteLater();
TargetArea->updateTabBarVisibility();
TargetArea->updateTitleBarVisibility();
return;
}
@ -364,21 +410,39 @@ void DockContainerWidgetPrivate::addDockAreasToList(const QList<CDockAreaWidget*
{
int CountBefore = DockAreas.count();
int NewAreaCount = NewDockAreas.count();
DockAreas.append(NewDockAreas);
appendDockAreas(NewDockAreas);
// If the user dropped a floating widget that contains only one single
// visible dock area, then its title bar button TitleBarButtonUndock is
// likely hidden. We need to ensure, that it is visible
for (auto DockArea : NewDockAreas)
{
DockArea->titleBarButton(TitleBarButtonUndock)->setVisible(true);
}
// We need to ensure, that the dock area title bar is visible. The title bar
// is invisible, if the dock are is a single dock area in a floating widget.
if (1 == CountBefore)
{
DockAreas.at(0)->updateTabBarVisibility();
DockAreas.at(0)->updateTitleBarVisibility();
}
if (1 == NewAreaCount)
{
DockAreas.last()->updateTabBarVisibility();
DockAreas.last()->updateTitleBarVisibility();
}
emit _this->dockAreasAdded();
emitDockAreasAdded();
}
//============================================================================
void DockContainerWidgetPrivate::appendDockAreas(const QList<CDockAreaWidget*> NewDockAreas)
{
DockAreas.append(NewDockAreas);
for (auto DockArea : NewDockAreas)
{
_this->connect(DockArea, SIGNAL(viewToggled(bool)), SLOT(onDockAreaViewToggled(bool)));
}
}
@ -588,7 +652,7 @@ bool DockContainerWidgetPrivate::restoreDockArea(QXmlStreamReader& s,
else
{
DockArea->setProperty("currentDockWidget", CurrentDockWidget);
DockAreas.append(DockArea);
appendDockAreas({DockArea});
}
CreatedWidget = DockArea;
@ -631,7 +695,7 @@ CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoContainer(DockWidgetA
CDockAreaWidget* NewDockArea = new CDockAreaWidget(DockManager, _this);
NewDockArea->addDockWidget(Dockwidget);
addDockArea(NewDockArea, area);
NewDockArea->updateTabBarVisibility();
NewDockArea->updateTitleBarVisibility();
LastAddedAreaCache[areaIdToIndex(area)] = NewDockArea;
return NewDockArea;
}
@ -673,9 +737,9 @@ void DockContainerWidgetPrivate::addDockArea(CDockAreaWidget* NewDockArea, DockW
RootSplitter = NewSplitter;
}
DockAreas.append(NewDockArea);
NewDockArea->updateTabBarVisibility();
emit _this->dockAreasAdded();
appendDockAreas({NewDockArea});
NewDockArea->updateTitleBarVisibility();
emitDockAreasAdded();
}
@ -744,8 +808,8 @@ CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoDockArea(DockWidgetAr
TargetAreaSplitter->insertWidget(index, NewSplitter);
}
DockAreas.append(NewDockArea);
emit _this->dockAreasAdded();
appendDockAreas({NewDockArea});
emitDockAreasAdded();
return NewDockArea;
}
@ -853,6 +917,7 @@ void CDockContainerWidget::addDockArea(CDockAreaWidget* DockAreaWidget,
void CDockContainerWidget::removeDockArea(CDockAreaWidget* area)
{
qDebug() << "CDockContainerWidget::removeDockArea";
area->disconnect(this);
d->DockAreas.removeAll(area);
CDockSplitter* Splitter = internal::findParent<CDockSplitter*>(area);
@ -913,7 +978,7 @@ emitAndExit:
// one single visible dock widget
CDockWidget::emitTopLevelEventForWidget(TopLevelWidget, true);
dumpLayout();
emit dockAreasRemoved();
d->emitDockAreasRemoved();
}

View File

@ -240,6 +240,12 @@ signals:
* This signal is emitted if one or multiple dock areas has been removed
*/
void dockAreasRemoved();
/**
* This signal is emitted if a dock area is opened or closed via
* toggleView() function
*/
void dockAreaViewToggled(CDockAreaWidget* DockArea, bool Open);
}; // class DockContainerWidget
} // namespace ads
//-----------------------------------------------------------------------------

View File

@ -643,7 +643,7 @@ void CDockWidget::emitTopLevelEventForWidget(CDockWidget* TopLevelDockWidget, bo
{
if (TopLevelDockWidget)
{
TopLevelDockWidget->dockAreaWidget()->updateTabBarVisibility();
TopLevelDockWidget->dockAreaWidget()->updateTitleBarVisibility();
TopLevelDockWidget->emitTopLevelChanged(Floating);
}
}

View File

@ -351,13 +351,13 @@ void CFloatingDockContainer::showEvent(QShowEvent *event)
{
std::cout << "CFloatingDockContainer showEvent" << std::endl;
QWidget::showEvent(event);
for (auto DockArea : d->DockContainer->openedDockAreas())
/*for (auto DockArea : d->DockContainer->openedDockAreas())
{
for (auto DockWidget : DockArea->openedDockWidgets())
{
DockWidget->setToggleViewActionChecked(true);
}
}
}*/
}
@ -467,12 +467,10 @@ bool CFloatingDockContainer::isClosable() const
void CFloatingDockContainer::onDockAreasAddedOrRemoved()
{
qDebug() << "CFloatingDockContainer::onDockAreasAddedOrRemoved()";
std::cout << "CFloatingDockContainer::onDockAreasAddedOrRemoved()" << std::endl;
auto TopLevelDockArea = d->DockContainer->topLevelDockArea();
if (TopLevelDockArea)
{
d->SingleDockArea = TopLevelDockArea;
d->SingleDockArea->titleBarButton(TitleBarButtonUndock)->setVisible(false);
this->setWindowTitle(d->SingleDockArea->currentDockWidget()->windowTitle());
connect(d->SingleDockArea, SIGNAL(currentChanged(int)), this,
SLOT(onDockAreaCurrentChanged(int)));
@ -481,7 +479,6 @@ void CFloatingDockContainer::onDockAreasAddedOrRemoved()
{
if (d->SingleDockArea)
{
d->SingleDockArea->titleBarButton(TitleBarButtonUndock)->setVisible(true);
disconnect(d->SingleDockArea, SIGNAL(currentChanged(int)), this,
SLOT(onDockAreaCurrentChanged(int)));
d->SingleDockArea = nullptr;

View File

@ -0,0 +1,122 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
id="Capa_1"
x="0px"
y="0px"
width="512"
height="512"
viewBox="0 0 512 512"
xml:space="preserve"
sodipodi:docname="close-button-disabled.svg"
inkscape:version="0.92.3 (2405546, 2018-03-11)"><metadata
id="metadata897"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
id="defs895" /><sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1017"
id="namedview893"
showgrid="false"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0"
inkscape:zoom="0.85862966"
inkscape:cx="345.29142"
inkscape:cy="32.731258"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="Capa_1" />
<g
id="g860"
transform="matrix(0.71708683,0,0,0.71708683,128,128)"
style="stroke:none;stroke-opacity:1;fill:#000000;fill-opacity:0.50196081">
<g
id="close"
style="stroke:none;stroke-opacity:1;fill:#000000;fill-opacity:0.50196081">
<polygon
points="357,321.3 214.2,178.5 357,35.7 321.3,0 178.5,142.8 35.7,0 0,35.7 142.8,178.5 0,321.3 35.7,357 178.5,214.2 321.3,357 "
id="polygon857"
style="stroke:none;stroke-opacity:1;fill:#000000;fill-opacity:0.50196081" />
</g>
</g>
<g
id="g862"
transform="translate(0,155)">
</g>
<g
id="g864"
transform="translate(0,155)">
</g>
<g
id="g866"
transform="translate(0,155)">
</g>
<g
id="g868"
transform="translate(0,155)">
</g>
<g
id="g870"
transform="translate(0,155)">
</g>
<g
id="g872"
transform="translate(0,155)">
</g>
<g
id="g874"
transform="translate(0,155)">
</g>
<g
id="g876"
transform="translate(0,155)">
</g>
<g
id="g878"
transform="translate(0,155)">
</g>
<g
id="g880"
transform="translate(0,155)">
</g>
<g
id="g882"
transform="translate(0,155)">
</g>
<g
id="g884"
transform="translate(0,155)">
</g>
<g
id="g886"
transform="translate(0,155)">
</g>
<g
id="g888"
transform="translate(0,155)">
</g>
<g
id="g890"
transform="translate(0,155)">
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.9 KiB

119
src/images/close-button.svg Normal file
View File

@ -0,0 +1,119 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
id="Capa_1"
x="0px"
y="0px"
width="512"
height="512"
viewBox="0 0 512 512"
xml:space="preserve"
sodipodi:docname="close-button.svg"
inkscape:version="0.92.3 (2405546, 2018-03-11)"><metadata
id="metadata897"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
id="defs895" /><sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1017"
id="namedview893"
showgrid="false"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0"
inkscape:zoom="0.85862966"
inkscape:cx="345.29142"
inkscape:cy="32.731258"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="Capa_1" />
<g
id="g860"
transform="matrix(0.71708683,0,0,0.71708683,128,128)">
<g
id="close">
<polygon
points="357,321.3 214.2,178.5 357,35.7 321.3,0 178.5,142.8 35.7,0 0,35.7 142.8,178.5 0,321.3 35.7,357 178.5,214.2 321.3,357 "
id="polygon857" />
</g>
</g>
<g
id="g862"
transform="translate(0,155)">
</g>
<g
id="g864"
transform="translate(0,155)">
</g>
<g
id="g866"
transform="translate(0,155)">
</g>
<g
id="g868"
transform="translate(0,155)">
</g>
<g
id="g870"
transform="translate(0,155)">
</g>
<g
id="g872"
transform="translate(0,155)">
</g>
<g
id="g874"
transform="translate(0,155)">
</g>
<g
id="g876"
transform="translate(0,155)">
</g>
<g
id="g878"
transform="translate(0,155)">
</g>
<g
id="g880"
transform="translate(0,155)">
</g>
<g
id="g882"
transform="translate(0,155)">
</g>
<g
id="g884"
transform="translate(0,155)">
</g>
<g
id="g886"
transform="translate(0,155)">
</g>
<g
id="g888"
transform="translate(0,155)">
</g>
<g
id="g890"
transform="translate(0,155)">
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.6 KiB