From ada3d6b3b5c7fcf71095231a9a62447ad4557507 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Mon, 15 Oct 2018 08:29:30 +0200 Subject: [PATCH] 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 --- demo/MainWindow.cpp | 4 ++-- src/DockAreaTitleBar.cpp | 2 +- src/DockAreaWidget.cpp | 20 ++++++++++++++++++-- src/DockAreaWidget.h | 7 +++++++ src/DockContainerWidget.cpp | 2 +- src/DockManager.cpp | 2 ++ src/DockWidget.cpp | 9 ++++++++- src/DockWidget.h | 5 +++++ src/DockWidgetTab.cpp | 4 ++-- src/ads_globals.h | 4 ++++ 10 files changed, 50 insertions(+), 9 deletions(-) diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index 6425be8..b0ee5b2 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -182,7 +182,7 @@ void MainWindowPrivate::createContent() ToolBar->addAction(ui.actionRestoreState); DockManager->addDockWidget(ads::BottomDockWidgetArea, FileSystemWidget); - /*FileSystemWidget = createFileSystemTreeDockWidget(ViewMenu); + FileSystemWidget = createFileSystemTreeDockWidget(ViewMenu); ToolBar = FileSystemWidget->toolBar(); ToolBar->addAction(ui.actionSaveState); ToolBar->addAction(ui.actionRestoreState); @@ -197,7 +197,7 @@ void MainWindowPrivate::createContent() DockManager->addDockWidget(ads::TopDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea); auto BottomDockArea = DockManager->addDockWidget(ads::BottomDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea); DockManager->addDockWidget(ads::RightDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea); - DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea);*/ + DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea); } diff --git a/src/DockAreaTitleBar.cpp b/src/DockAreaTitleBar.cpp index 92b4a0e..59cc688 100644 --- a/src/DockAreaTitleBar.cpp +++ b/src/DockAreaTitleBar.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include "FloatingDockContainer.h" #include "DockAreaWidget.h" @@ -149,7 +150,6 @@ CDockAreaTabBar* CDockAreaTitleBar::tabBar() const //============================================================================ void CDockAreaTitleBar::markTabsMenuOutdated() { - qDebug() << "CDockAreaTitleBar::markTabsMenuOutdated()"; d->MenuOutdated = true; } diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index a75e6de..209d647 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -291,6 +291,8 @@ void DockAreaWidgetPrivate::createTitleBar() SLOT(onTabCloseRequested(int))); _this->connect(tabBar(), SIGNAL(tabBarClicked(int)), SLOT(setCurrentIndex(int))); + _this->connect(tabBar(), SIGNAL(tabMoved(int, int)), + SLOT(reorderDockWidget(int, int))); } @@ -480,7 +482,6 @@ void CDockAreaWidget::setCurrentDockWidget(CDockWidget* DockWidget) //============================================================================ void CDockAreaWidget::setCurrentIndex(int index) { - std::cout << "CDockAreaWidget::setCurrentIndex " << index << std::endl; auto TabBar = d->tabBar(); if (index < 0 || index > (TabBar->count() - 1)) { @@ -583,6 +584,7 @@ CDockWidget* CDockAreaWidget::dockWidget(int Index) const //============================================================================ void CDockAreaWidget::reorderDockWidget(int fromIndex, int toIndex) { + qDebug() << "CDockAreaWidget::reorderDockWidget"; if (fromIndex >= d->ContentsLayout->count() || fromIndex < 0 || toIndex >= d->ContentsLayout->count() || toIndex < 0 || fromIndex == toIndex) { @@ -658,7 +660,7 @@ CDockWidget* CDockAreaWidget::nextOpenDockWidget(CDockWidget* DockWidget) const //============================================================================ CDockWidget::DockWidgetFeatures CDockAreaWidget::features() const { - CDockWidget::DockWidgetFeatures Features; + CDockWidget::DockWidgetFeatures Features(CDockWidget::AllDockWidgetFeatures); for (const auto DockWidget : dockWidgets()) { Features &= DockWidget->features(); @@ -667,6 +669,20 @@ CDockWidget::DockWidgetFeatures CDockAreaWidget::features() const return Features; } + +//============================================================================ +void CDockAreaWidget::setVisible(bool visible) +{ + Super::setVisible(visible); + QString FirstDockWidgetLabel; + if (dockWidgetsCount()) + { + FirstDockWidgetLabel = dockWidget(0)->windowTitle(); + } + qDebug() << "CDockAreaWidget::setVisible " << visible << " " << FirstDockWidgetLabel + << " count: " << dockWidgetsCount() << " open count: " << openDockWidgetsCount(); +} + } // namespace ads //--------------------------------------------------------------------------- diff --git a/src/DockAreaWidget.h b/src/DockAreaWidget.h index c76c135..d07f202 100644 --- a/src/DockAreaWidget.h +++ b/src/DockAreaWidget.h @@ -129,6 +129,8 @@ protected: void updateTabBarVisibility(); public: + using Super = QFrame; + /** * Default Constructor */ @@ -223,6 +225,11 @@ public slots: */ void setCurrentIndex(int index); + /** + * This function is required for debugging purposes + */ + virtual void setVisible(bool visible) override; + signals: /** * This signal is emitted when user clicks on a tab at an index. diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index 0daecdc..6b10a84 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -1156,7 +1156,7 @@ QList CDockContainerWidget::dockWidgets() const //============================================================================ CDockWidget::DockWidgetFeatures CDockContainerWidget::features() const { - CDockWidget::DockWidgetFeatures Features; + CDockWidget::DockWidgetFeatures Features(CDockWidget::AllDockWidgetFeatures); for (const auto DockArea : d->DockAreas) { Features &= DockArea->features(); diff --git a/src/DockManager.cpp b/src/DockManager.cpp index 1fe7824..5ab722f 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -252,6 +252,7 @@ bool DockManagerPrivate::restoreState(const QByteArray &state, int version) } } + // Now all dock areas are properly restored and we setup the index of // The dock areas because the previous toggleView() action has changed // the dock area index @@ -278,6 +279,7 @@ bool DockManagerPrivate::restoreState(const QByteArray &state, int version) } } + // Finally we need to send the topLevelChanged() signals for all dock // widgets if top level changed for (auto DockContainer : Containers) diff --git a/src/DockWidget.cpp b/src/DockWidget.cpp index b1faf27..56d6f49 100644 --- a/src/DockWidget.cpp +++ b/src/DockWidget.cpp @@ -133,7 +133,7 @@ void DockWidgetPrivate::showDockWidget() DockArea->show(); DockArea->setCurrentDockWidget(_this); TabWidget->show(); - QSplitter* Splitter = internal::findParent(_this); + QSplitter* Splitter = internal::findParent(DockArea); while (Splitter && !Splitter->isVisible()) { Splitter->show(); @@ -666,6 +666,13 @@ void CDockWidget::setClosedState(bool Closed) d->Closed = Closed; } + +//============================================================================ +QSize CDockWidget::minimumSizeHint() const +{ + return QSize(60, 40); +} + } // namespace ads //--------------------------------------------------------------------------- diff --git a/src/DockWidget.h b/src/DockWidget.h index 73da7c9..9341140 100644 --- a/src/DockWidget.h +++ b/src/DockWidget.h @@ -209,6 +209,11 @@ public: */ virtual ~CDockWidget(); + /** + * We return a fixed minimum size hint for all dock widgets + */ + virtual QSize minimumSizeHint() const override; + /** * Sets the widget for the dock widget to widget. */ diff --git a/src/DockWidgetTab.cpp b/src/DockWidgetTab.cpp index eb1fd23..cb41a78 100644 --- a/src/DockWidgetTab.cpp +++ b/src/DockWidgetTab.cpp @@ -398,10 +398,10 @@ void CDockWidgetTab::mouseDoubleClickEvent(QMouseEvent *event) //============================================================================ void CDockWidgetTab::setVisible(bool visible) { - if (!visible) + /*if (!visible) { qDebug() << "CDockWidgetTab::setVisible " << visible; - } + }*/ Super::setVisible(visible); } diff --git a/src/ads_globals.h b/src/ads_globals.h index 128fdb7..a32fad6 100644 --- a/src/ads_globals.h +++ b/src/ads_globals.h @@ -97,6 +97,10 @@ CDockInsertParam dockAreaInsertParameters(DockWidgetArea Area); * Searches for the parent widget of the given type. * Returns the parent widget of the given widget or 0 if the widget is not * child of any widget of type T + * + * It is not safe to use this function in in CDockWidget because only + * the current dock widget has a parent. All dock widgets that are not the + * current dock widget in a dock area have no parent. */ template T findParent(const QWidget* w)