Fix the application closing and saved size to be restored on startup.
Leonardo Robol [2011-10-25 17:25]
Fix the application closing and saved size to be restored on startup.
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 @@
<rect>
<x>0</x>
<y>0</y>
- <width>720</width>
- <height>480</height>
+ <width>420</width>
+ <height>320</height>
</rect>
</property>
<property name="windowTitle">
@@ -105,7 +105,7 @@
<rect>
<x>0</x>
<y>0</y>
- <width>720</width>
+ <width>420</width>
<height>24</height>
</rect>
</property>