Skip to content

Commit ada3d6b

Browse files
author
Uwe Kindler
committed
Added minimumSizeHint function to DockWidget to prevent jumping of the height of a dock area when switching between dock widgets, fixed use of findParent function in DockWidget - non current dock widgets do not have a parent so this function will fail
1 parent 30bbd26 commit ada3d6b

10 files changed

+50
-9
lines changed

demo/MainWindow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ void MainWindowPrivate::createContent()
182182
ToolBar->addAction(ui.actionRestoreState);
183183
DockManager->addDockWidget(ads::BottomDockWidgetArea, FileSystemWidget);
184184

185-
/*FileSystemWidget = createFileSystemTreeDockWidget(ViewMenu);
185+
FileSystemWidget = createFileSystemTreeDockWidget(ViewMenu);
186186
ToolBar = FileSystemWidget->toolBar();
187187
ToolBar->addAction(ui.actionSaveState);
188188
ToolBar->addAction(ui.actionRestoreState);
@@ -197,7 +197,7 @@ void MainWindowPrivate::createContent()
197197
DockManager->addDockWidget(ads::TopDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
198198
auto BottomDockArea = DockManager->addDockWidget(ads::BottomDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
199199
DockManager->addDockWidget(ads::RightDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
200-
DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea);*/
200+
DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea);
201201
}
202202

203203

src/DockAreaTitleBar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <QScrollArea>
1818
#include <QMouseEvent>
1919
#include <QDebug>
20+
#include <QStyleOptionButton>
2021

2122
#include "FloatingDockContainer.h"
2223
#include "DockAreaWidget.h"
@@ -149,7 +150,6 @@ CDockAreaTabBar* CDockAreaTitleBar::tabBar() const
149150
//============================================================================
150151
void CDockAreaTitleBar::markTabsMenuOutdated()
151152
{
152-
qDebug() << "CDockAreaTitleBar::markTabsMenuOutdated()";
153153
d->MenuOutdated = true;
154154
}
155155

src/DockAreaWidget.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ void DockAreaWidgetPrivate::createTitleBar()
291291
SLOT(onTabCloseRequested(int)));
292292
_this->connect(tabBar(), SIGNAL(tabBarClicked(int)),
293293
SLOT(setCurrentIndex(int)));
294+
_this->connect(tabBar(), SIGNAL(tabMoved(int, int)),
295+
SLOT(reorderDockWidget(int, int)));
294296
}
295297

296298

@@ -480,7 +482,6 @@ void CDockAreaWidget::setCurrentDockWidget(CDockWidget* DockWidget)
480482
//============================================================================
481483
void CDockAreaWidget::setCurrentIndex(int index)
482484
{
483-
std::cout << "CDockAreaWidget::setCurrentIndex " << index << std::endl;
484485
auto TabBar = d->tabBar();
485486
if (index < 0 || index > (TabBar->count() - 1))
486487
{
@@ -583,6 +584,7 @@ CDockWidget* CDockAreaWidget::dockWidget(int Index) const
583584
//============================================================================
584585
void CDockAreaWidget::reorderDockWidget(int fromIndex, int toIndex)
585586
{
587+
qDebug() << "CDockAreaWidget::reorderDockWidget";
586588
if (fromIndex >= d->ContentsLayout->count() || fromIndex < 0
587589
|| toIndex >= d->ContentsLayout->count() || toIndex < 0 || fromIndex == toIndex)
588590
{
@@ -658,7 +660,7 @@ CDockWidget* CDockAreaWidget::nextOpenDockWidget(CDockWidget* DockWidget) const
658660
//============================================================================
659661
CDockWidget::DockWidgetFeatures CDockAreaWidget::features() const
660662
{
661-
CDockWidget::DockWidgetFeatures Features;
663+
CDockWidget::DockWidgetFeatures Features(CDockWidget::AllDockWidgetFeatures);
662664
for (const auto DockWidget : dockWidgets())
663665
{
664666
Features &= DockWidget->features();
@@ -667,6 +669,20 @@ CDockWidget::DockWidgetFeatures CDockAreaWidget::features() const
667669
return Features;
668670
}
669671

672+
673+
//============================================================================
674+
void CDockAreaWidget::setVisible(bool visible)
675+
{
676+
Super::setVisible(visible);
677+
QString FirstDockWidgetLabel;
678+
if (dockWidgetsCount())
679+
{
680+
FirstDockWidgetLabel = dockWidget(0)->windowTitle();
681+
}
682+
qDebug() << "CDockAreaWidget::setVisible " << visible << " " << FirstDockWidgetLabel
683+
<< " count: " << dockWidgetsCount() << " open count: " << openDockWidgetsCount();
684+
}
685+
670686
} // namespace ads
671687

672688
//---------------------------------------------------------------------------

src/DockAreaWidget.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ private slots:
129129
void updateTabBarVisibility();
130130

131131
public:
132+
using Super = QFrame;
133+
132134
/**
133135
* Default Constructor
134136
*/
@@ -223,6 +225,11 @@ public slots:
223225
*/
224226
void setCurrentIndex(int index);
225227

228+
/**
229+
* This function is required for debugging purposes
230+
*/
231+
virtual void setVisible(bool visible) override;
232+
226233
signals:
227234
/**
228235
* This signal is emitted when user clicks on a tab at an index.

src/DockContainerWidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,7 @@ QList<CDockWidget*> CDockContainerWidget::dockWidgets() const
11561156
//============================================================================
11571157
CDockWidget::DockWidgetFeatures CDockContainerWidget::features() const
11581158
{
1159-
CDockWidget::DockWidgetFeatures Features;
1159+
CDockWidget::DockWidgetFeatures Features(CDockWidget::AllDockWidgetFeatures);
11601160
for (const auto DockArea : d->DockAreas)
11611161
{
11621162
Features &= DockArea->features();

src/DockManager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ bool DockManagerPrivate::restoreState(const QByteArray &state, int version)
252252
}
253253
}
254254

255+
255256
// Now all dock areas are properly restored and we setup the index of
256257
// The dock areas because the previous toggleView() action has changed
257258
// the dock area index
@@ -278,6 +279,7 @@ bool DockManagerPrivate::restoreState(const QByteArray &state, int version)
278279
}
279280
}
280281

282+
281283
// Finally we need to send the topLevelChanged() signals for all dock
282284
// widgets if top level changed
283285
for (auto DockContainer : Containers)

src/DockWidget.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ void DockWidgetPrivate::showDockWidget()
133133
DockArea->show();
134134
DockArea->setCurrentDockWidget(_this);
135135
TabWidget->show();
136-
QSplitter* Splitter = internal::findParent<QSplitter*>(_this);
136+
QSplitter* Splitter = internal::findParent<QSplitter*>(DockArea);
137137
while (Splitter && !Splitter->isVisible())
138138
{
139139
Splitter->show();
@@ -666,6 +666,13 @@ void CDockWidget::setClosedState(bool Closed)
666666
d->Closed = Closed;
667667
}
668668

669+
670+
//============================================================================
671+
QSize CDockWidget::minimumSizeHint() const
672+
{
673+
return QSize(60, 40);
674+
}
675+
669676
} // namespace ads
670677

671678
//---------------------------------------------------------------------------

src/DockWidget.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ private slots:
209209
*/
210210
virtual ~CDockWidget();
211211

212+
/**
213+
* We return a fixed minimum size hint for all dock widgets
214+
*/
215+
virtual QSize minimumSizeHint() const override;
216+
212217
/**
213218
* Sets the widget for the dock widget to widget.
214219
*/

src/DockWidgetTab.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,10 @@ void CDockWidgetTab::mouseDoubleClickEvent(QMouseEvent *event)
398398
//============================================================================
399399
void CDockWidgetTab::setVisible(bool visible)
400400
{
401-
if (!visible)
401+
/*if (!visible)
402402
{
403403
qDebug() << "CDockWidgetTab::setVisible " << visible;
404-
}
404+
}*/
405405
Super::setVisible(visible);
406406
}
407407

src/ads_globals.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ CDockInsertParam dockAreaInsertParameters(DockWidgetArea Area);
9797
* Searches for the parent widget of the given type.
9898
* Returns the parent widget of the given widget or 0 if the widget is not
9999
* child of any widget of type T
100+
*
101+
* It is not safe to use this function in in CDockWidget because only
102+
* the current dock widget has a parent. All dock widgets that are not the
103+
* current dock widget in a dock area have no parent.
100104
*/
101105
template <class T>
102106
T findParent(const QWidget* w)

0 commit comments

Comments
 (0)