From: Soeren Apel Date: Fri, 12 Sep 2014 22:43:26 +0000 (+0200) Subject: Automatically save/restore main window state X-Git-Tag: pulseview-0.3.0~540 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=93f683adaed4345f815293f0193bbbc09d8fc42c;p=pulseview.git Automatically save/restore main window state 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. --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 50cab695..719d6089 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -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( diff --git a/pv/mainwindow.h b/pv/mainwindow.h index 41c55ba5..1b2135df 100644 --- a/pv/mainwindow.h +++ b/pv/mainwindow.h @@ -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);