Fixed saving of size/position.

This commit is contained in:
Martin Rotter 2013-12-21 15:07:09 +01:00
parent 8ad3bb94f3
commit a5d6b23f89
6 changed files with 67 additions and 41 deletions

View File

@ -27,12 +27,10 @@ FeedMessageViewer::FeedMessageViewer(QWidget *parent)
initialize(); initialize();
initializeViews(); initializeViews();
createConnections(); createConnections();
loadSize();
} }
FeedMessageViewer::~FeedMessageViewer() { FeedMessageViewer::~FeedMessageViewer() {
qDebug("Destroying FeedMessageViewer instance."); qDebug("Destroying FeedMessageViewer instance.");
saveSize();
} }
void FeedMessageViewer::saveSize() { void FeedMessageViewer::saveSize() {

View File

@ -13,6 +13,7 @@
#include "gui/tabbar.h" #include "gui/tabbar.h"
#include "gui/statusbar.h" #include "gui/statusbar.h"
#include "core/settings.h" #include "core/settings.h"
#include "gui/feedmessageviewer.h"
#include "core/defs.h" #include "core/defs.h"
#include "qtsingleapplication/qtsingleapplication.h" #include "qtsingleapplication/qtsingleapplication.h"
@ -37,7 +38,7 @@ FormMain::FormMain(QWidget *parent) : QMainWindow(parent), m_ui(new Ui::FormMain
m_ui->m_tabWidget->initializeTabs(); m_ui->m_tabWidget->initializeTabs();
setupIcons(); setupIcons();
setupSize(); loadSize();
} }
FormMain::~FormMain() { FormMain::~FormMain() {
@ -163,10 +164,19 @@ void FormMain::display() {
void FormMain::onCommitData(QSessionManager &manager) { void FormMain::onCommitData(QSessionManager &manager) {
Q_UNUSED(manager) Q_UNUSED(manager)
qDebug("OS asked application to commit its data."); qDebug("OS asked application to commit its data.");
onAboutToQuit();
}
void FormMain::onSaveState(QSessionManager &manager) {
Q_UNUSED(manager)
qDebug("OS asked application to save its state.");
onAboutToQuit();
} }
void FormMain::onAboutToQuit() { void FormMain::onAboutToQuit() {
qDebug("Cleaning up resources and saving application state before it exits."); qDebug("Cleaning up resources and saving application state.");
saveSize(); saveSize();
} }
@ -219,7 +229,7 @@ void FormMain::setupIcons() {
m_ui->m_tabWidget->setupIcons(); m_ui->m_tabWidget->setupIcons();
} }
void FormMain::setupSize() { void FormMain::loadSize() {
QRect screen = qApp->desktop()->screenGeometry(); QRect screen = qApp->desktop()->screenGeometry();
resize(Settings::getInstance()->value(APP_CFG_GUI, resize(Settings::getInstance()->value(APP_CFG_GUI,
@ -228,17 +238,21 @@ void FormMain::setupSize() {
move(Settings::getInstance()->value(APP_CFG_GUI, move(Settings::getInstance()->value(APP_CFG_GUI,
"window_position", "window_position",
screen.center() - rect().center()).toPoint()); screen.center() - rect().center()).toPoint());
m_ui->m_tabWidget->feedMessageViewer()->loadSize();
} }
void FormMain::saveSize() { void FormMain::saveSize() {
Settings::getInstance()->setValue(APP_CFG_GUI, "window_position", pos()); Settings::getInstance()->setValue(APP_CFG_GUI, "window_position", pos());
Settings::getInstance()->setValue(APP_CFG_GUI, "window_size", size()); Settings::getInstance()->setValue(APP_CFG_GUI, "window_size", size());
m_ui->m_tabWidget->feedMessageViewer()->saveSize();
} }
void FormMain::createConnections() { void FormMain::createConnections() {
// Core connections. // Core connections.
connect(qApp, SIGNAL(commitDataRequest(QSessionManager&)), connect(qApp, SIGNAL(commitDataRequest(QSessionManager&)),
this, SLOT(onCommitData(QSessionManager&))); this, SLOT(onCommitData(QSessionManager&)));
connect(qApp, SIGNAL(saveStateRequest(QSessionManager&)),
this, SLOT(onSaveState(QSessionManager&)));
// Menu "File" connections. // Menu "File" connections.
connect(m_ui->m_actionQuit, SIGNAL(triggered()), this, SLOT(quit())); connect(m_ui->m_actionQuit, SIGNAL(triggered()), this, SLOT(quit()));

View File

@ -48,8 +48,8 @@ class FormMain : public QMainWindow {
// kind of method and catch ThemeFactoryEvent::type() in its event handler. // kind of method and catch ThemeFactoryEvent::type() in its event handler.
void setupIcons(); void setupIcons();
// Loads saves visual state of the application. // Loads/saves visual state of the application.
void setupSize(); void loadSize();
void saveSize(); void saveSize();
public slots: public slots:
@ -70,6 +70,7 @@ class FormMain : public QMainWindow {
protected slots: protected slots:
void onCommitData(QSessionManager &manager); void onCommitData(QSessionManager &manager);
void onSaveState(QSessionManager &manager);
// Used for last-minute actions. // Used for last-minute actions.
void onAboutToQuit(); void onAboutToQuit();

View File

@ -48,9 +48,12 @@ void MessagesView::setSortingEnabled(bool enable) {
void MessagesView::setupAppearance() { void MessagesView::setupAppearance() {
// FIXME: Sometimes ASSERT occurs if model provides less columns // FIXME: Sometimes ASSERT occurs if model provides less columns
// than we set resize mode for. // than we set resize mode for.
qDebug("Loading MessagesView with %d columns.", int column_count = header()->count();
header()->count());
qDebug("Loading MessagesView with %d columns.",
column_count);
if (column_count > 0) {
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
// Setup column resize strategies. // Setup column resize strategies.
header()->setSectionResizeMode(MSG_DB_ID_INDEX, QHeaderView::Interactive); header()->setSectionResizeMode(MSG_DB_ID_INDEX, QHeaderView::Interactive);
@ -85,6 +88,7 @@ void MessagesView::setupAppearance() {
hideColumn(MSG_DB_FEED_INDEX); hideColumn(MSG_DB_FEED_INDEX);
hideColumn(MSG_DB_URL_INDEX); hideColumn(MSG_DB_URL_INDEX);
hideColumn(MSG_DB_CONTENTS_INDEX); hideColumn(MSG_DB_CONTENTS_INDEX);
}
header()->setStretchLastSection(false); header()->setStretchLastSection(false);
setUniformRowHeights(true); setUniformRowHeights(true);

View File

@ -57,8 +57,8 @@ TabBar *TabWidget::tabBar() {
void TabWidget::initializeTabs() { void TabWidget::initializeTabs() {
// Create widget for "Feeds" page and add it. // Create widget for "Feeds" page and add it.
FeedMessageViewer *browser = new FeedMessageViewer(this); m_feedMessageViewer = new FeedMessageViewer(this);
int index_of_browser = addTab(static_cast<TabContent*>(browser), int index_of_browser = addTab(static_cast<TabContent*>(m_feedMessageViewer),
QIcon(), QIcon(),
tr("Feeds"), tr("Feeds"),
TabBar::FeedReader); TabBar::FeedReader);
@ -244,6 +244,10 @@ int TabWidget::addBrowser(bool move_after_current,
return final_index; return final_index;
} }
FeedMessageViewer *TabWidget::feedMessageViewer() const {
return m_feedMessageViewer;
}
void TabWidget::changeIcon(int index, const QIcon &new_icon) { void TabWidget::changeIcon(int index, const QIcon &new_icon) {
setTabIcon(index, new_icon); setTabIcon(index, new_icon);
} }

View File

@ -10,6 +10,7 @@
class CornerButton; class CornerButton;
class Message; class Message;
class FeedMessageViewer;
class TabWidget : public QTabWidget { class TabWidget : public QTabWidget {
Q_OBJECT Q_OBJECT
@ -41,6 +42,9 @@ class TabWidget : public QTabWidget {
// Sets up icons for this TabWidget. // Sets up icons for this TabWidget.
void setupIcons(); void setupIcons();
// Accessor to feed/message viewer.
FeedMessageViewer *feedMessageViewer() const;
protected: protected:
// Creates necesary connections. // Creates necesary connections.
void createConnections(); void createConnections();
@ -90,6 +94,7 @@ class TabWidget : public QTabWidget {
private: private:
CornerButton *m_cornerButton; CornerButton *m_cornerButton;
FeedMessageViewer *m_feedMessageViewer;
}; };
#endif // TABWIDGET_H #endif // TABWIDGET_H