]> sigrok.org Git - pulseview.git/commitdiff
Automatically save/restore main window state
authorSoeren Apel <redacted>
Fri, 12 Sep 2014 22:43:26 +0000 (00:43 +0200)
committerUwe Hermann <redacted>
Mon, 15 Sep 2014 19:24:51 +0000 (21:24 +0200)
Fix bug #326 by saving the main window state when closing and
restoring it on startup. The default window size is 1000x720 so
that the window can still be seen entirely when on a 1024x768 screen.
This wouldn't be the case with a default size of 1024x768.

pv/mainwindow.cpp
pv/mainwindow.h

index 50cab695a8a87d850f4f2fda04f6b8f233ed8ee8..719d608989a82b92a8d42f1be66b04ef9264a1ce 100644 (file)
@@ -30,6 +30,7 @@
 #include <QAction>
 #include <QApplication>
 #include <QButtonGroup>
+#include <QCloseEvent>
 #include <QFileDialog>
 #include <QMessageBox>
 #include <QMenu>
@@ -81,6 +82,7 @@ MainWindow::MainWindow(DeviceManager &device_manager,
        _session(device_manager)
 {
        setup_ui();
+       restore_ui_settings();
        if (open_file_name) {
                const QString s(QString::fromUtf8(open_file_name));
                QMetaObject::invokeMethod(this, "load_file",
@@ -93,8 +95,6 @@ void MainWindow::setup_ui()
 {
        setObjectName(QString::fromUtf8("MainWindow"));
 
-       resize(1024, 768);
-
        // Set the window icon
        QIcon icon;
        icon.addFile(QString::fromUtf8(":/icons/sigrok-logo-notext.png"),
@@ -268,6 +268,31 @@ void MainWindow::setup_ui()
 
 }
 
+void MainWindow::save_ui_settings()
+{
+       QSettings settings("sigrok", "PulseView");
+
+       settings.beginGroup("MainWindow");
+       settings.setValue("state", saveState());
+       settings.setValue("geometry", saveGeometry());
+       settings.endGroup();
+}
+
+void MainWindow::restore_ui_settings()
+{
+       QSettings settings("sigrok", "PulseView");
+
+       settings.beginGroup("MainWindow");
+
+       if (settings.contains("geometry")) {
+               restoreGeometry(settings.value("geometry").toByteArray());
+               restoreState(settings.value("state").toByteArray());
+       } else
+               resize(1000, 720);
+
+       settings.endGroup();
+}
+
 void MainWindow::session_error(
        const QString text, const QString info_text)
 {
@@ -297,6 +322,12 @@ void MainWindow::update_device_list()
        _sampling_bar->set_device_list(devices, selected_device);
 }
 
+void MainWindow::closeEvent(QCloseEvent *event)
+{
+       save_ui_settings();
+       event->accept();
+}
+
 void MainWindow::load_file(QString file_name)
 {
        const QString errorMessage(
index 41c55ba5ca9c11f2d6282c497831c9ad83985d4f..1b2135df1f8d47d53ee75a9fd9b1dff1dc49e935 100644 (file)
@@ -65,6 +65,10 @@ public:
 private:
        void setup_ui();
 
+       void save_ui_settings();
+
+       void restore_ui_settings();
+
        void session_error(const QString text, const QString info_text);
 
        /**
@@ -72,10 +76,11 @@ private:
         */
        void update_device_list();
 
+       void closeEvent(QCloseEvent *event);
+
 private Q_SLOTS:
        void load_file(QString file_name);
 
-
        void show_session_error(
                const QString text, const QString info_text);