From ebb7dde012e6409a617e9c8765bf932bcb6d9aa5 Mon Sep 17 00:00:00 2001 From: Torsten Paul Date: Mon, 20 Oct 2014 00:21:06 +0200 Subject: [PATCH 1/2] Fix status handling for docked windows. Especially for the case where the windows are docked as tabs in the same position, the "visibility-changed" signal does not work as close indicator. The window is also treated as invisible when just the tab is invisible, not only in case the window is closed. --- openscad.pro | 2 ++ src/Dock.cc | 32 ++++++++++++++++++++++++++++++++ src/Dock.h | 23 +++++++++++++++++++++++ src/MainWindow.h | 1 - src/MainWindow.ui | 12 ++++++++++-- src/mainwin.cc | 22 ++++++---------------- 6 files changed, 73 insertions(+), 19 deletions(-) create mode 100644 src/Dock.cc create mode 100644 src/Dock.h diff --git a/openscad.pro b/openscad.pro index 067576f1..a2692b66 100644 --- a/openscad.pro +++ b/openscad.pro @@ -307,6 +307,7 @@ src/FontCache.h \ src/system-gl.h \ src/CsgInfo.h \ \ + src/Dock.h \ src/AutoUpdater.h \ src/launchingscreen.h \ src/legacyeditor.h \ @@ -397,6 +398,7 @@ SOURCES += src/version_check.cc \ src/openscad.cc \ src/mainwin.cc \ src/UIUtils.cc \ + src/Dock.cc \ src/FontListDialog.cc \ src/launchingscreen.cc \ src/legacyeditor.cc \ diff --git a/src/Dock.cc b/src/Dock.cc new file mode 100644 index 00000000..17ba9e20 --- /dev/null +++ b/src/Dock.cc @@ -0,0 +1,32 @@ +#include +#include + +#include "Dock.h" + +Dock::Dock(QWidget *parent) : QDockWidget(parent), action(NULL) +{ +} + +Dock::~Dock() +{ +} + +void Dock::setVisible(bool visible) +{ + QSettings settings; + settings.setValue(configKey, !visible); + if (action != NULL) { + action->setChecked(!visible); + } + QDockWidget::setVisible(visible); +} + +void Dock::setConfigKey(const QString configKey) +{ + this->configKey = configKey; +} + +void Dock::setAction(QAction *action) +{ + this->action = action; +} \ No newline at end of file diff --git a/src/Dock.h b/src/Dock.h new file mode 100644 index 00000000..58334b3d --- /dev/null +++ b/src/Dock.h @@ -0,0 +1,23 @@ +#pragma once + +#include +#include +#include + +class Dock : public QDockWidget +{ + Q_OBJECT + +public: + Dock(QWidget *parent = NULL); + virtual ~Dock(); + void setConfigKey(const QString configKey); + void setAction(QAction *action); + +public slots: + void setVisible(bool visible); + +private: + QString configKey; + QAction *action; +}; diff --git a/src/MainWindow.h b/src/MainWindow.h index 482cb205..7b976f82 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -239,7 +239,6 @@ private: char const * afterCompileSlot; bool procevents; - bool isClosing; class QTemporaryFile *tempFile; class ProgressWidget *progresswidget; class CGALWorker *cgalworker; diff --git a/src/MainWindow.ui b/src/MainWindow.ui index 22b80e3d..8553e8e4 100644 --- a/src/MainWindow.ui +++ b/src/MainWindow.ui @@ -142,6 +142,8 @@ 0 0 + 1397 + 33 @@ -287,7 +289,7 @@ - + 1 @@ -410,7 +412,7 @@ - + 8 @@ -1092,6 +1094,12 @@
QGLView.h
1 + + Dock + QDockWidget +
Dock.h
+ 1 +
diff --git a/src/mainwin.cc b/src/mainwin.cc index 23651190..c94d370b 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -225,7 +225,6 @@ MainWindow::MainWindow(const QString &filename) tval = 0; fps = 0; fsteps = 1; - isClosing = false; const QString importStatement = "import(\"%1\");\n"; const QString surfaceStatement = "surface(\"%1\");\n"; @@ -532,6 +531,10 @@ MainWindow::MainWindow(const QString &filename) editor->setInitialSizeHint(QSize((5 * this->width() / 11), 100)); } + this->editorDock->setConfigKey("view/hideEditor"); + this->editorDock->setAction(this->viewActionHideEditor); + this->consoleDock->setConfigKey("view/hideConsole"); + this->consoleDock->setAction(this->viewActionHideConsole); connect(this->editorDock, SIGNAL(topLevelChanged(bool)), this, SLOT(editorTopLevelChanged(bool))); connect(this->consoleDock, SIGNAL(topLevelChanged(bool)), this, SLOT(consoleTopLevelChanged(bool))); @@ -2265,25 +2268,13 @@ void MainWindow::viewAll() this->qglview->updateGL(); } -void MainWindow::on_editorDock_visibilityChanged(bool visible) +void MainWindow::on_editorDock_visibilityChanged(bool) { - if (isClosing) { - return; - } - QSettings settings; - settings.setValue("view/hideEditor", !visible); - viewActionHideEditor->setChecked(!visible); editorTopLevelChanged(editorDock->isFloating()); } -void MainWindow::on_consoleDock_visibilityChanged(bool visible) +void MainWindow::on_consoleDock_visibilityChanged(bool) { - if (isClosing) { - return; - } - QSettings settings; - settings.setValue("view/hideConsole", !visible); - viewActionHideConsole->setChecked(!visible); consoleTopLevelChanged(consoleDock->isFloating()); } @@ -2453,7 +2444,6 @@ void MainWindow::closeEvent(QCloseEvent *event) delete this->tempFile; this->tempFile = NULL; } - isClosing = true; event->accept(); } else { event->ignore(); From ea39c70471c1547dc52e4a348635ba6f2460cc13 Mon Sep 17 00:00:00 2001 From: Torsten Paul Date: Mon, 20 Oct 2014 00:22:22 +0200 Subject: [PATCH 2/2] Ensure window is visible after restoring the window state (fixes #976). --- src/mainwin.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/mainwin.cc b/src/mainwin.cc index c94d370b..e5069f98 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -86,6 +86,7 @@ #include #include #include +#include #include @@ -529,6 +530,24 @@ MainWindow::MainWindow(const QString &filename) * fill the available space. */ editor->setInitialSizeHint(QSize((5 * this->width() / 11), 100)); + } else { +#ifdef Q_OS_WIN + // Try moving the main window into the display range, this + // can occur when closing OpenSCAD on a second monitor which + // is not available at the time the application is started + // again. + // On Windows that causes the main window to open in a not + // easily reachable place. + QDesktopWidget *desktop = QApplication::desktop(); + QRect desktopRect = desktop->frameGeometry().adjusted(250, 150, -250, -150).normalized(); + QRect windowRect = frameGeometry(); + if (!desktopRect.intersects(windowRect)) { + windowRect.moveCenter(desktopRect.center()); + windowRect = windowRect.intersected(desktopRect); + move(windowRect.topLeft()); + resize(windowRect.size()); + } +#endif } this->editorDock->setConfigKey("view/hideEditor");