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();
initializeViews();
createConnections();
loadSize();
}
FeedMessageViewer::~FeedMessageViewer() {
qDebug("Destroying FeedMessageViewer instance.");
saveSize();
}
void FeedMessageViewer::saveSize() {

View File

@ -13,6 +13,7 @@
#include "gui/tabbar.h"
#include "gui/statusbar.h"
#include "core/settings.h"
#include "gui/feedmessageviewer.h"
#include "core/defs.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();
setupIcons();
setupSize();
loadSize();
}
FormMain::~FormMain() {
@ -163,10 +164,19 @@ void FormMain::display() {
void FormMain::onCommitData(QSessionManager &manager) {
Q_UNUSED(manager)
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() {
qDebug("Cleaning up resources and saving application state before it exits.");
qDebug("Cleaning up resources and saving application state.");
saveSize();
}
@ -219,7 +229,7 @@ void FormMain::setupIcons() {
m_ui->m_tabWidget->setupIcons();
}
void FormMain::setupSize() {
void FormMain::loadSize() {
QRect screen = qApp->desktop()->screenGeometry();
resize(Settings::getInstance()->value(APP_CFG_GUI,
@ -228,17 +238,21 @@ void FormMain::setupSize() {
move(Settings::getInstance()->value(APP_CFG_GUI,
"window_position",
screen.center() - rect().center()).toPoint());
m_ui->m_tabWidget->feedMessageViewer()->loadSize();
}
void FormMain::saveSize() {
Settings::getInstance()->setValue(APP_CFG_GUI, "window_position", pos());
Settings::getInstance()->setValue(APP_CFG_GUI, "window_size", size());
m_ui->m_tabWidget->feedMessageViewer()->saveSize();
}
void FormMain::createConnections() {
// Core connections.
connect(qApp, SIGNAL(commitDataRequest(QSessionManager&)),
this, SLOT(onCommitData(QSessionManager&)));
connect(qApp, SIGNAL(saveStateRequest(QSessionManager&)),
this, SLOT(onSaveState(QSessionManager&)));
// Menu "File" connections.
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.
void setupIcons();
// Loads saves visual state of the application.
void setupSize();
// Loads/saves visual state of the application.
void loadSize();
void saveSize();
public slots:
@ -70,6 +70,7 @@ class FormMain : public QMainWindow {
protected slots:
void onCommitData(QSessionManager &manager);
void onSaveState(QSessionManager &manager);
// Used for last-minute actions.
void onAboutToQuit();

View File

@ -48,43 +48,47 @@ void MessagesView::setSortingEnabled(bool enable) {
void MessagesView::setupAppearance() {
// FIXME: Sometimes ASSERT occurs if model provides less columns
// than we set resize mode for.
qDebug("Loading MessagesView with %d columns.",
header()->count());
int column_count = header()->count();
qDebug("Loading MessagesView with %d columns.",
column_count);
if (column_count > 0) {
#if QT_VERSION >= 0x050000
// Setup column resize strategies.
header()->setSectionResizeMode(MSG_DB_ID_INDEX, QHeaderView::Interactive);
header()->setSectionResizeMode(MSG_DB_READ_INDEX, QHeaderView::ResizeToContents);
header()->setSectionResizeMode(MSG_DB_DELETED_INDEX, QHeaderView::Interactive);
header()->setSectionResizeMode(MSG_DB_IMPORTANT_INDEX, QHeaderView::ResizeToContents);
header()->setSectionResizeMode(MSG_DB_FEED_INDEX, QHeaderView::Interactive);
header()->setSectionResizeMode(MSG_DB_TITLE_INDEX, QHeaderView::Stretch);
header()->setSectionResizeMode(MSG_DB_URL_INDEX, QHeaderView::Interactive);
header()->setSectionResizeMode(MSG_DB_AUTHOR_INDEX, QHeaderView::Interactive);
header()->setSectionResizeMode(MSG_DB_DCREATED_INDEX, QHeaderView::Interactive);
header()->setSectionResizeMode(MSG_DB_DUPDATED_INDEX, QHeaderView::Interactive);
header()->setSectionResizeMode(MSG_DB_CONTENTS_INDEX, QHeaderView::Interactive);
// Setup column resize strategies.
header()->setSectionResizeMode(MSG_DB_ID_INDEX, QHeaderView::Interactive);
header()->setSectionResizeMode(MSG_DB_READ_INDEX, QHeaderView::ResizeToContents);
header()->setSectionResizeMode(MSG_DB_DELETED_INDEX, QHeaderView::Interactive);
header()->setSectionResizeMode(MSG_DB_IMPORTANT_INDEX, QHeaderView::ResizeToContents);
header()->setSectionResizeMode(MSG_DB_FEED_INDEX, QHeaderView::Interactive);
header()->setSectionResizeMode(MSG_DB_TITLE_INDEX, QHeaderView::Stretch);
header()->setSectionResizeMode(MSG_DB_URL_INDEX, QHeaderView::Interactive);
header()->setSectionResizeMode(MSG_DB_AUTHOR_INDEX, QHeaderView::Interactive);
header()->setSectionResizeMode(MSG_DB_DCREATED_INDEX, QHeaderView::Interactive);
header()->setSectionResizeMode(MSG_DB_DUPDATED_INDEX, QHeaderView::Interactive);
header()->setSectionResizeMode(MSG_DB_CONTENTS_INDEX, QHeaderView::Interactive);
#else
// Setup column resize strategies.
header()->setResizeMode(MSG_DB_ID_INDEX, QHeaderView::Interactive);
header()->setResizeMode(MSG_DB_READ_INDEX, QHeaderView::ResizeToContents);
header()->setResizeMode(MSG_DB_DELETED_INDEX, QHeaderView::Interactive);
header()->setResizeMode(MSG_DB_IMPORTANT_INDEX, QHeaderView::ResizeToContents);
header()->setResizeMode(MSG_DB_FEED_INDEX, QHeaderView::Interactive);
header()->setResizeMode(MSG_DB_TITLE_INDEX, QHeaderView::Stretch);
header()->setResizeMode(MSG_DB_URL_INDEX, QHeaderView::Interactive);
header()->setResizeMode(MSG_DB_AUTHOR_INDEX, QHeaderView::Interactive);
header()->setResizeMode(MSG_DB_DCREATED_INDEX, QHeaderView::Interactive);
header()->setResizeMode(MSG_DB_DUPDATED_INDEX, QHeaderView::Interactive);
header()->setResizeMode(MSG_DB_CONTENTS_INDEX, QHeaderView::Interactive);
// Setup column resize strategies.
header()->setResizeMode(MSG_DB_ID_INDEX, QHeaderView::Interactive);
header()->setResizeMode(MSG_DB_READ_INDEX, QHeaderView::ResizeToContents);
header()->setResizeMode(MSG_DB_DELETED_INDEX, QHeaderView::Interactive);
header()->setResizeMode(MSG_DB_IMPORTANT_INDEX, QHeaderView::ResizeToContents);
header()->setResizeMode(MSG_DB_FEED_INDEX, QHeaderView::Interactive);
header()->setResizeMode(MSG_DB_TITLE_INDEX, QHeaderView::Stretch);
header()->setResizeMode(MSG_DB_URL_INDEX, QHeaderView::Interactive);
header()->setResizeMode(MSG_DB_AUTHOR_INDEX, QHeaderView::Interactive);
header()->setResizeMode(MSG_DB_DCREATED_INDEX, QHeaderView::Interactive);
header()->setResizeMode(MSG_DB_DUPDATED_INDEX, QHeaderView::Interactive);
header()->setResizeMode(MSG_DB_CONTENTS_INDEX, QHeaderView::Interactive);
#endif
// Hide columns.
hideColumn(MSG_DB_ID_INDEX);
hideColumn(MSG_DB_DELETED_INDEX);
hideColumn(MSG_DB_FEED_INDEX);
hideColumn(MSG_DB_URL_INDEX);
hideColumn(MSG_DB_CONTENTS_INDEX);
// Hide columns.
hideColumn(MSG_DB_ID_INDEX);
hideColumn(MSG_DB_DELETED_INDEX);
hideColumn(MSG_DB_FEED_INDEX);
hideColumn(MSG_DB_URL_INDEX);
hideColumn(MSG_DB_CONTENTS_INDEX);
}
header()->setStretchLastSection(false);
setUniformRowHeights(true);

View File

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

View File

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