Skip to content

Commit 8637c89

Browse files
author
Uwe Kindler
committed
Added proper support for closable feature, now the close button is disabled for floating widgets
1 parent 11e5f9c commit 8637c89

File tree

5 files changed

+69
-2
lines changed

5 files changed

+69
-2
lines changed

src/DockAreaWidget.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,19 @@ CDockWidget* CDockAreaWidget::nextOpenDockWidget(CDockWidget* DockWidget) const
654654
}
655655
}
656656

657+
658+
//============================================================================
659+
CDockWidget::DockWidgetFeatures CDockAreaWidget::features() const
660+
{
661+
CDockWidget::DockWidgetFeatures Features;
662+
for (const auto DockWidget : dockWidgets())
663+
{
664+
Features &= DockWidget->features();
665+
}
666+
667+
return Features;
668+
}
669+
657670
} // namespace ads
658671

659672
//---------------------------------------------------------------------------

src/DockAreaWidget.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <QFrame>
3434

3535
#include "ads_globals.h"
36+
#include "DockWidget.h"
3637

3738
class QXmlStreamWriter;
3839

@@ -42,7 +43,6 @@ struct DockAreaWidgetPrivate;
4243
class CDockManager;
4344
class CDockContainerWidget;
4445
struct DockContainerWidgetPrivate;
45-
class CDockWidget;
4646

4747

4848
/**
@@ -206,6 +206,15 @@ private slots:
206206
*/
207207
void saveState(QXmlStreamWriter& Stream) const;
208208

209+
/**
210+
* This functions returns the dock widget features of all dock widget in
211+
* this area.
212+
* A bitwise and is used to combine the flags of all dock widgets. That
213+
* means, if only dock widget does not support a certain flag, the whole
214+
* dock are does not support the flag.
215+
*/
216+
CDockWidget::DockWidgetFeatures features() const;
217+
209218
public slots:
210219
/**
211220
* This activates the tab for the given tab index.

src/DockContainerWidget.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,19 @@ QList<CDockWidget*> CDockContainerWidget::dockWidgets() const
11531153
}
11541154

11551155

1156+
//============================================================================
1157+
CDockWidget::DockWidgetFeatures CDockContainerWidget::features() const
1158+
{
1159+
CDockWidget::DockWidgetFeatures Features;
1160+
for (const auto DockArea : d->DockAreas)
1161+
{
1162+
Features &= DockArea->features();
1163+
}
1164+
1165+
return Features;
1166+
}
1167+
1168+
11561169

11571170
} // namespace ads
11581171

src/DockContainerWidget.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include <QFrame>
3434

3535
#include "ads_globals.h"
36-
36+
#include "DockWidget.h"
3737

3838
class QXmlStreamWriter;
3939
class QXmlStreamReader;
@@ -206,6 +206,15 @@ class ADS_EXPORT CDockContainerWidget : public QFrame
206206
*/
207207
void dumpLayout();
208208

209+
/**
210+
* This functions returns the dock widget features of all dock widget in
211+
* this container.
212+
* A bitwise and is used to combine the flags of all dock widgets. That
213+
* means, if only dock widget does not support a certain flag, the whole
214+
* dock are does not support the flag.
215+
*/
216+
CDockWidget::DockWidgetFeatures features() const;
217+
209218
signals:
210219
/**
211220
* This signal is emitted if one or multiple dock areas has been added to

src/FloatingDockContainer.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ struct FloatingDockContainerPrivate
9191
{
9292
DraggingState = StateId;
9393
}
94+
95+
/**
96+
* Disables the window close button if the content is not closable
97+
*/
98+
void disableCloseButton()
99+
{
100+
auto Flags = _this->windowFlags();
101+
Flags |= Qt::CustomizeWindowHint;
102+
Flags &= ~Qt::WindowCloseButtonHint;
103+
_this->setWindowFlags(Flags);
104+
}
94105
};
95106
// struct FloatingDockContainerPrivate
96107

@@ -250,6 +261,10 @@ CFloatingDockContainer::CFloatingDockContainer(CDockAreaWidget* DockArea) :
250261
CFloatingDockContainer(DockArea->dockManager())
251262
{
252263
d->DockContainer->addDockArea(DockArea);
264+
if (!DockArea->features().testFlag(CDockWidget::DockWidgetClosable))
265+
{
266+
d->disableCloseButton();
267+
}
253268
}
254269

255270

@@ -258,6 +273,10 @@ CFloatingDockContainer::CFloatingDockContainer(CDockWidget* DockWidget) :
258273
CFloatingDockContainer(DockWidget->dockManager())
259274
{
260275
d->DockContainer->addDockWidget(CenterDockWidgetArea, DockWidget);
276+
if (!DockWidget->features().testFlag(CDockWidget::DockWidgetClosable))
277+
{
278+
d->disableCloseButton();
279+
}
261280
}
262281

263282
//============================================================================
@@ -515,6 +534,10 @@ bool CFloatingDockContainer::restoreState(QXmlStreamReader& Stream, bool Testing
515534
{
516535
return false;
517536
}
537+
if (!d->DockContainer->features().testFlag(CDockWidget::DockWidgetClosable))
538+
{
539+
d->disableCloseButton();
540+
}
518541
onDockAreasAddedOrRemoved();
519542
return true;
520543
}

0 commit comments

Comments
 (0)