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
No related branches found
No related tags found
No related merge requests found
......@@ -197,12 +197,12 @@ main(int argc, char *argv[])
delete sem;
});
#endif
auto ret = a.exec();
QCoreApplication::exit();
GlobalSystemTray::instance().deleteLater();
GlobalSystemTray::instance().hide();
auto ret = a.exec();
QCoreApplication::exit();
GlobalSystemTray::instance().deleteLater();
GlobalSystemTray::instance().hide();
return ret;
}
......@@ -83,17 +83,7 @@ MainWindow::MainWindow(QWidget* parent) :
}
#endif
QSettings settings;
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);
readSettingsFromRegistry();
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());
......@@ -111,9 +101,6 @@ MainWindow::MainWindow(QWidget* parent) :
setContextMenuPolicy(Qt::NoContextMenu);
if (not settings.contains(SettingsKey::enableNotifications)) {
settings.setValue(SettingsKey::enableNotifications, true);
}
connect(&GlobalSystemTray::instance(), SIGNAL(messageClicked()), this, SLOT(notificationClicked()));
connect(&netManager_, &QNetworkConfigurationManager::onlineStateChanged, [=](bool online) {
......@@ -227,7 +214,19 @@ MainWindow::closeEvent(QCloseEvent* event)
this->hide();
event->ignore();
} else {
settings.setValue(SettingsKey::savedSize, size());
settings.setValue(SettingsKey::savedPos, pos());
settings.setValue(SettingsKey::geometry, saveGeometry());
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
......@@ -62,7 +62,10 @@ private slots:
private:
explicit MainWindow(QWidget* parent = 0);
~MainWindow();
~MainWindow();
void readSettingsFromRegistry();
Ui::MainWindow* ui;
QNetworkConfigurationManager netManager_;
};
......@@ -22,8 +22,8 @@ namespace SettingsKey {
constexpr static char closeOrMinimized[] = "closeOrMin";
constexpr static char autoAnswer[] = "autoAnswer";
constexpr static char savedSize[] = "savedSize";
constexpr static char savedPos[] = "savedPos";
constexpr static char geometry[] = "geometry";
constexpr static char windowState[] = "windowState";
constexpr static char imShowAuthor[] = "imShowAuthor";
constexpr static char imShowDate[] = "imShowDate";
constexpr static char enableNotifications[] = "enableNotifications";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment