Skip to content
Snippets Groups Projects
Commit d063d5a2 authored by Andreas Traczyk's avatar Andreas Traczyk Committed by Adrien Béraud
Browse files

mainwindow: save/load complete window geometry and state

- Replaces the use of position and size 2d vectors when saving qt
  application settings to the registry with geometry and state
  byte arrays which includes information about the window's screen
  number and fixes a bug which prevents the main window from ever
  starting correctly maximized due to the disregarded taskbar
  offset.

Change-Id: Iaa15f075970675e85ffcdb26da962a19a1914252
parent ca320d87
Branches
Tags
No related merge requests found
...@@ -83,17 +83,7 @@ MainWindow::MainWindow(QWidget* parent) : ...@@ -83,17 +83,7 @@ MainWindow::MainWindow(QWidget* parent) :
} }
#endif #endif
QSettings settings; readSettingsFromRegistry();
QVariant size = settings.value(SettingsKey::savedSize);
QVariant posV = settings.value(SettingsKey::savedPos);
if (size.isValid() && posV.isValid()) {
resize(size.toSize());
auto screenSize = QApplication::desktop()->screenGeometry();
auto pos = posV.toPoint();
if (pos.rx() < screenSize.width() && pos.ry() < screenSize.height())
move(pos);
} else
resize(800, 600);
win_sparkle_set_appcast_url("http://dl.ring.cx/windows/winsparkle-ring.xml"); win_sparkle_set_appcast_url("http://dl.ring.cx/windows/winsparkle-ring.xml");
win_sparkle_set_app_details(L"Savoir-faire Linux", L"Ring", QString(NIGHTLY_VERSION).toStdWString().c_str()); win_sparkle_set_app_details(L"Savoir-faire Linux", L"Ring", QString(NIGHTLY_VERSION).toStdWString().c_str());
...@@ -111,9 +101,6 @@ MainWindow::MainWindow(QWidget* parent) : ...@@ -111,9 +101,6 @@ MainWindow::MainWindow(QWidget* parent) :
setContextMenuPolicy(Qt::NoContextMenu); setContextMenuPolicy(Qt::NoContextMenu);
if (not settings.contains(SettingsKey::enableNotifications)) {
settings.setValue(SettingsKey::enableNotifications, true);
}
connect(&GlobalSystemTray::instance(), SIGNAL(messageClicked()), this, SLOT(notificationClicked())); connect(&GlobalSystemTray::instance(), SIGNAL(messageClicked()), this, SLOT(notificationClicked()));
connect(&netManager_, &QNetworkConfigurationManager::onlineStateChanged, [=](bool online) { connect(&netManager_, &QNetworkConfigurationManager::onlineStateChanged, [=](bool online) {
...@@ -227,7 +214,19 @@ MainWindow::closeEvent(QCloseEvent* event) ...@@ -227,7 +214,19 @@ MainWindow::closeEvent(QCloseEvent* event)
this->hide(); this->hide();
event->ignore(); event->ignore();
} else { } else {
settings.setValue(SettingsKey::savedSize, size()); settings.setValue(SettingsKey::geometry, saveGeometry());
settings.setValue(SettingsKey::savedPos, pos()); settings.setValue(SettingsKey::windowState, saveState());
}
QMainWindow::closeEvent(event);
}
void
MainWindow::readSettingsFromRegistry()
{
QSettings settings;
restoreGeometry(settings.value(SettingsKey::geometry).toByteArray());
restoreState(settings.value(SettingsKey::windowState).toByteArray());
if (not settings.contains(SettingsKey::enableNotifications)) {
settings.setValue(SettingsKey::enableNotifications, true);
} }
} }
\ No newline at end of file
...@@ -63,6 +63,9 @@ private slots: ...@@ -63,6 +63,9 @@ private slots:
private: private:
explicit MainWindow(QWidget* parent = 0); explicit MainWindow(QWidget* parent = 0);
~MainWindow(); ~MainWindow();
void readSettingsFromRegistry();
Ui::MainWindow* ui; Ui::MainWindow* ui;
QNetworkConfigurationManager netManager_; QNetworkConfigurationManager netManager_;
}; };
...@@ -22,8 +22,8 @@ namespace SettingsKey { ...@@ -22,8 +22,8 @@ namespace SettingsKey {
constexpr static char closeOrMinimized[] = "closeOrMin"; constexpr static char closeOrMinimized[] = "closeOrMin";
constexpr static char autoAnswer[] = "autoAnswer"; constexpr static char autoAnswer[] = "autoAnswer";
constexpr static char savedSize[] = "savedSize"; constexpr static char geometry[] = "geometry";
constexpr static char savedPos[] = "savedPos"; constexpr static char windowState[] = "windowState";
constexpr static char imShowAuthor[] = "imShowAuthor"; constexpr static char imShowAuthor[] = "imShowAuthor";
constexpr static char imShowDate[] = "imShowDate"; constexpr static char imShowDate[] = "imShowDate";
constexpr static char enableNotifications[] = "enableNotifications"; constexpr static char enableNotifications[] = "enableNotifications";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment