From dd9e07e7583d81f264d48c63755e2cbf41795ace Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 18 May 2024 15:59:54 +0200 Subject: [PATCH] Gui: Restore previous width when closing task dialog This fixes #11016 --- src/Gui/MainWindow.cpp | 12 ++++++++++-- src/Gui/TaskView/TaskView.cpp | 31 +++++++++++++++++++++++++++++++ src/Gui/TaskView/TaskView.h | 8 ++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp index 1f454358abb4..9d7d991fe141 100644 --- a/src/Gui/MainWindow.cpp +++ b/src/Gui/MainWindow.cpp @@ -599,9 +599,17 @@ bool MainWindow::setupTaskView() { // Task view if (d->hiddenDockWindows.find("Std_TaskView") == std::string::npos) { + // clang-format off + auto group = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp") + ->GetGroup("Preferences") + ->GetGroup("DockWindows") + ->GetGroup("TaskView"); + // clang-format on auto taskView = new Gui::TaskView::TaskView(this); - taskView->setObjectName - (QString::fromLatin1(QT_TRANSLATE_NOOP("QDockWidget","Tasks"))); + bool restore = group->GetBool("RestoreWidth", taskView->shouldRestoreWidth()); + taskView->setRestoreWidth(restore); + taskView->setObjectName(QString::fromLatin1(QT_TRANSLATE_NOOP("QDockWidget","Tasks"))); taskView->setMinimumWidth(210); DockWindowManager* pDockMgr = DockWindowManager::instance(); diff --git a/src/Gui/TaskView/TaskView.cpp b/src/Gui/TaskView/TaskView.cpp index 0dbb9fccc9c8..ae231262bc9b 100644 --- a/src/Gui/TaskView/TaskView.cpp +++ b/src/Gui/TaskView/TaskView.cpp @@ -27,6 +27,7 @@ # include # include # include +# include # include # include # include @@ -558,6 +559,7 @@ void TaskView::showDialog(TaskDialog *dlg) ActiveDialog->open(); + saveCurrentWidth(); getMainWindow()->updateActions(); triggerMinimumSizeHint(); @@ -602,6 +604,7 @@ void TaskView::removeDialog() delete remove; } + tryRestoreWidth(); triggerMinimumSizeHint(); } @@ -713,6 +716,34 @@ void TaskView::addTaskWatcher() taskPanel->setScheme(QSint::FreeCADPanelScheme::defaultScheme()); } +void TaskView::saveCurrentWidth() +{ + if (shouldRestoreWidth()) { + if (auto parent = qobject_cast(parentWidget())) { + currentWidth = parent->width(); + } + } +} + +void TaskView::tryRestoreWidth() +{ + if (shouldRestoreWidth()) { + if (auto parent = qobject_cast(parentWidget())) { + Gui::getMainWindow()->resizeDocks({parent}, {currentWidth}, Qt::Horizontal); + } + } +} + +void TaskView::setRestoreWidth(bool on) +{ + restoreWidth = on; +} + +bool TaskView::shouldRestoreWidth() const +{ + return restoreWidth; +} + void TaskView::removeTaskWatcher() { // In case a child of the TaskView has the focus and get hidden we have diff --git a/src/Gui/TaskView/TaskView.h b/src/Gui/TaskView/TaskView.h index 3504cb1c9991..7b58e76aa33e 100644 --- a/src/Gui/TaskView/TaskView.h +++ b/src/Gui/TaskView/TaskView.h @@ -163,6 +163,10 @@ class GuiExport TaskView : public QScrollArea, public Gui::SelectionSingleton::O QSize minimumSizeHint() const override; + // Restore width before opening a task panel + void setRestoreWidth(bool on); + bool shouldRestoreWidth() const; + Q_SIGNALS: void taskUpdate(); @@ -175,6 +179,8 @@ protected Q_SLOTS: private: void triggerMinimumSizeHint(); void adjustMinimumSizeHint(); + void saveCurrentWidth(); + void tryRestoreWidth(); protected: void keyPressEvent(QKeyEvent* event) override; @@ -199,6 +205,8 @@ protected Q_SLOTS: QSint::ActionPanel* taskPanel; TaskDialog *ActiveDialog; TaskEditControl *ActiveCtrl; + bool restoreWidth = false; + int currentWidth = 0; Connection connectApplicationActiveDocument; Connection connectApplicationDeleteDocument;