From: Soeren Apel <[email protected]> This patch fixes bug #326 [1] by saving the main window state when closing and restoring it on startup. I set the default window size to 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.
[1] http://sigrok.org/bugzilla/show_bug.cgi?id=326 --- pv/mainwindow.cpp | 35 +++++++++++++++++++++++++++++++++-- pv/mainwindow.h | 7 ++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 50cab69..719d608 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -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( diff --git a/pv/mainwindow.h b/pv/mainwindow.h index 41c55ba..1b2135d 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); -- 1.7.8.6 ------------------------------------------------------------------------------ Want excitement? Manually upgrade your production database. When you want reliability, choose Perforce Perforce version control. Predictably reliable. http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk _______________________________________________ sigrok-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sigrok-devel

