From 65e15782f5a346c69f09ee1455317ef8c2784e11 Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Tue, 25 Oct 2011 19:25:36 +0200 Subject: [PATCH] Fix the application closing and saved size to be restored on startup. --- include/mainwindow.h | 1 + larss/mainwindow.cpp | 21 +++++++++++++++++++++ ui/mainwindow.ui | 6 +++--- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/include/mainwindow.h b/include/mainwindow.h index b2ee79c..5faff7f 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -47,6 +47,7 @@ public slots: protected: bool eventFilter (QObject *object, QEvent *event); + void closeEvent(QCloseEvent *event); private: Ui::MainWindow *ui; diff --git a/larss/mainwindow.cpp b/larss/mainwindow.cpp index 38d3e0f..9c2ee14 100644 --- a/larss/mainwindow.cpp +++ b/larss/mainwindow.cpp @@ -53,6 +53,15 @@ MainWindow::MainWindow(QWidget *parent) : // Install event filter to handle particular events. ui->webViewTitleLabel->installEventFilter(this); loadedNews = ""; + + // Give the window the right size, if present in the + // settings. + QSettings settings; + if (settings.contains("width") && settings.contains("height")) + { + resize (settings.value("width").toInt(), + settings.value("height").toInt()); + } } MainWindow::~MainWindow() @@ -67,10 +76,22 @@ MainWindow::loadingFeedStart(QString feedName) ui->statusBar->showMessage(tr("Updating feed '%1'...").arg(feedName), 2000); } +void MainWindow::closeEvent(QCloseEvent *event) +{ + do_exit(); +} + void MainWindow::do_exit() { + // Kill the poller poller->stopPolling(); poller->wait(); + + // Save window size + QSettings settings; + settings.setValue("width", width()); + settings.setValue("height", height()); + QApplication::exit(); } diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index 1eab07f..b75b12d 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 720 - 480 + 420 + 320 @@ -105,7 +105,7 @@ 0 0 - 720 + 420 24 -- 2.1.4