Skip to content

Commit

Permalink
Gui: Restore previous width when closing task dialog
Browse files Browse the repository at this point in the history
This fixes FreeCAD#11016
  • Loading branch information
wwmayer committed May 18, 2024
1 parent e9c95b1 commit dd9e07e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
31 changes: 31 additions & 0 deletions src/Gui/TaskView/TaskView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
# include <QActionEvent>
# include <QApplication>
# include <QCursor>
# include <QDockWidget>
# include <QLineEdit>
# include <QPointer>
# include <QPushButton>
Expand Down Expand Up @@ -558,6 +559,7 @@ void TaskView::showDialog(TaskDialog *dlg)

ActiveDialog->open();

saveCurrentWidth();
getMainWindow()->updateActions();

triggerMinimumSizeHint();
Expand Down Expand Up @@ -602,6 +604,7 @@ void TaskView::removeDialog()
delete remove;
}

tryRestoreWidth();
triggerMinimumSizeHint();
}

Expand Down Expand Up @@ -713,6 +716,34 @@ void TaskView::addTaskWatcher()
taskPanel->setScheme(QSint::FreeCADPanelScheme::defaultScheme());
}

void TaskView::saveCurrentWidth()
{
if (shouldRestoreWidth()) {
if (auto parent = qobject_cast<QDockWidget*>(parentWidget())) {
currentWidth = parent->width();
}
}
}

void TaskView::tryRestoreWidth()
{
if (shouldRestoreWidth()) {
if (auto parent = qobject_cast<QDockWidget*>(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
Expand Down
8 changes: 8 additions & 0 deletions src/Gui/TaskView/TaskView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -175,6 +179,8 @@ protected Q_SLOTS:
private:
void triggerMinimumSizeHint();
void adjustMinimumSizeHint();
void saveCurrentWidth();
void tryRestoreWidth();

protected:
void keyPressEvent(QKeyEvent* event) override;
Expand All @@ -199,6 +205,8 @@ protected Q_SLOTS:
QSint::ActionPanel* taskPanel;
TaskDialog *ActiveDialog;
TaskEditControl *ActiveCtrl;
bool restoreWidth = false;
int currentWidth = 0;

Connection connectApplicationActiveDocument;
Connection connectApplicationDeleteDocument;
Expand Down

0 comments on commit dd9e07e

Please sign in to comment.