Skip to content

Commit b9265fc

Browse files
author
Uwe Kindler
committed
Properly implemented setting enable state of dock area close button
1 parent b3a2721 commit b9265fc

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

src/DockAreaWidget.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
#include "DockSplitter.h"
5555
#include "DockAreaTitleBar.h"
5656

57+
#include <iostream>
58+
5759

5860
namespace ads
5961
{
@@ -242,6 +244,7 @@ struct DockAreaWidgetPrivate
242244
DockAreaLayout* ContentsLayout;
243245
CDockAreaTitleBar* TitleBar;
244246
CDockManager* DockManager = nullptr;
247+
bool UpdateCloseButton = false;
245248

246249
/**
247250
* Private data constructor
@@ -293,6 +296,11 @@ struct DockAreaWidgetPrivate
293296
{
294297
return TitleBar->tabBar();
295298
}
299+
300+
/**
301+
* Udpates the enable state of the close button
302+
*/
303+
void updateCloseButtonState();
296304
};
297305
// struct DockAreaWidgetPrivate
298306

@@ -319,6 +327,25 @@ void DockAreaWidgetPrivate::createTitleBar()
319327
}
320328

321329

330+
//============================================================================
331+
void DockAreaWidgetPrivate::updateCloseButtonState()
332+
{
333+
if (_this->isHidden())
334+
{
335+
UpdateCloseButton = true;
336+
return;
337+
}
338+
339+
if (!UpdateCloseButton)
340+
{
341+
return;
342+
}
343+
TitleBar->button(TitleBarButtonClose)->setEnabled(
344+
_this->features().testFlag(CDockWidget::DockWidgetClosable));
345+
UpdateCloseButton = false;
346+
}
347+
348+
322349
//============================================================================
323350
CDockAreaWidget::CDockAreaWidget(CDockManager* DockManager, CDockContainerWidget* parent) :
324351
QFrame(parent),
@@ -383,6 +410,7 @@ void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget,
383410
setCurrentIndex(index);
384411
}
385412
DockWidget->setDockArea(this);
413+
d->updateCloseButtonState();
386414
}
387415

388416

@@ -414,6 +442,7 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
414442
hideAreaWithNoVisibleContent();
415443
}
416444

445+
d->updateCloseButtonState();
417446
updateTitleBarVisibility();
418447
auto TopLevelDockWidget = dockContainer()->topLevelDockWidget();
419448
if (TopLevelDockWidget)
@@ -730,10 +759,19 @@ CDockWidget::DockWidgetFeatures CDockAreaWidget::features() const
730759
void CDockAreaWidget::toggleView(bool Open)
731760
{
732761
setVisible(Open);
762+
733763
emit viewToggled(Open);
734764
}
735765

736766

767+
//============================================================================
768+
void CDockAreaWidget::setVisible(bool Visible)
769+
{
770+
Super::setVisible(Visible);
771+
d->updateCloseButtonState();
772+
}
773+
774+
737775
//============================================================================
738776
QAbstractButton* CDockAreaWidget::titleBarButton(TitleBarButton which) const
739777
{

src/DockAreaWidget.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ protected slots:
241241
*/
242242
QAbstractButton* titleBarButton(TitleBarButton which) const;
243243

244+
/**
245+
* Update the close button if visibility changed
246+
*/
247+
virtual void setVisible(bool Visible) override;
248+
244249
public slots:
245250
/**
246251
* This activates the tab for the given tab index.

src/DockContainerWidget.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,11 +627,10 @@ bool DockContainerWidgetPrivate::restoreDockArea(QXmlStreamReader& s,
627627
}
628628

629629
qDebug() << "Dock Widget found - parent " << DockWidget->parent();
630-
DockArea->addDockWidget(DockWidget);
631-
632630
// We hide the DockArea here to prevent the short display (the flashing)
633631
// of the dock areas during application startup
634632
DockArea->hide();
633+
DockArea->addDockWidget(DockWidget);
635634
DockWidget->setToggleViewActionChecked(!Closed);
636635
DockWidget->setClosedState(Closed);
637636
DockWidget->setProperty("closed", Closed);

src/DockWidget.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,23 @@ private slots:
152152
StateFloating
153153
};
154154

155+
/**
156+
* Sets the widget for the dock widget to widget.
157+
* The InsertMode defines how the widget is inserted into the dock widget.
158+
* The content of a dock widget should be resizable do a very small size to
159+
* prevent the dock widget from blocking the resizing. To ensure, that a
160+
* dock widget can be resized very well, it is better to insert the content+
161+
* widget into a scroll area or to provide a widget that is already a scroll
162+
* area or that contains a scroll area.
163+
* If the InsertMode is AutoScrollArea, the DockWidget tries to automatically
164+
* detect how to insert the given widget. If the widget is derived from
165+
* QScrollArea (i.e. an QAbstractItemView), then the widget is inserted
166+
* directly. If the given widget is not a scroll area, the widget will be
167+
* inserted into a scroll area.
168+
* To force insertion into a scroll area, you can also provide the InsertMode
169+
* ForceScrollArea. To prevent insertion into a scroll area, you can
170+
* provide the InsertMode ForceNoScrollArea
171+
*/
155172
enum eInsertMode
156173
{
157174
AutoScrollArea,

0 commit comments

Comments
 (0)