From 82719573b55d210d7ab908722f011e9cfaa33a77 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Tue, 28 May 2019 15:57:06 +0300 Subject: [PATCH] Reader: store geometry instead of pos&size in Configuration Qt documentation recommends calling saveGeometry() in closeEvent(). This commit fixes the following bug on my GNU/Linux with Xfce system: 1. Move the top of the YACReader window to the top of the screen. 2. Restart YACReader (exit and run again). 2. Enter full screen mode. 4. Restart YACReader. 5. Exit full screen mode. At this point YACReader's title bar is hidden beyond the top of the screen, i.e. the window has moved up. --- YACReader/configuration.cpp | 2 -- YACReader/configuration.h | 8 +++----- YACReader/main_window_viewer.cpp | 13 +++---------- common/yacreader_global_gui.h | 3 +-- 4 files changed, 7 insertions(+), 19 deletions(-) diff --git a/YACReader/configuration.cpp b/YACReader/configuration.cpp index 5f2ecd39..a5208e87 100644 --- a/YACReader/configuration.cpp +++ b/YACReader/configuration.cpp @@ -35,8 +35,6 @@ void Configuration::load(QSettings *settings) settings->setValue(FLOW_TYPE, 0); if (!settings->contains(FULLSCREEN)) settings->setValue(FULLSCREEN, false); - if (!settings->contains(Y_WINDOW_SIZE)) - settings->setValue(Y_WINDOW_SIZE, QSize(0, 0)); if (!settings->contains(MAXIMIZED)) settings->setValue(MAXIMIZED, false); if (!settings->contains(DOUBLE_PAGE)) diff --git a/YACReader/configuration.h b/YACReader/configuration.h index 1662fb51..652aff40 100644 --- a/YACReader/configuration.h +++ b/YACReader/configuration.h @@ -1,9 +1,9 @@ #ifndef __CONFIGURATION_H #define __CONFIGURATION_H +#include #include #include #include -#include #include #include #include @@ -66,10 +66,8 @@ public: bool getFullScreen() { return settings->value(FULLSCREEN).toBool(); } void setFullScreen(bool f) { settings->setValue(FULLSCREEN, f); } - QPoint getPos() { return settings->value(Y_WINDOW_POS).toPoint(); } - void setPos(QPoint p) { settings->setValue(Y_WINDOW_POS, p); } - QSize getSize() { return settings->value(Y_WINDOW_SIZE).toSize(); } - void setSize(QSize s) { settings->setValue(Y_WINDOW_SIZE, s); } + QByteArray getGeometry() const { return settings->value(Y_WINDOW_GEOMETRY).toByteArray(); } + void setGeometry(const QByteArray &g) { settings->setValue(Y_WINDOW_GEOMETRY, g); } bool getMaximized() { return settings->value(MAXIMIZED).toBool(); } void setMaximized(bool b) { settings->setValue(MAXIMIZED, b); } bool getDoublePage() { return settings->value(DOUBLE_PAGE).toBool(); } diff --git a/YACReader/main_window_viewer.cpp b/YACReader/main_window_viewer.cpp index fc8295f6..32bd6479 100644 --- a/YACReader/main_window_viewer.cpp +++ b/YACReader/main_window_viewer.cpp @@ -142,12 +142,7 @@ void MainWindowViewer::setupUI() height = static_cast(heightDesktopResolution * 0.84); width = static_cast(height * 0.70); Configuration &conf = Configuration::getConfiguration(); - QPoint p = conf.getPos(); - QSize s = conf.getSize(); - if (s.width() != 0) { - move(p); - resize(s); - } else { + if (!restoreGeometry(conf.getGeometry())) { move(QPoint((widthDesktopResolution - width) / 2, ((heightDesktopResolution - height) - 40) / 2)); resize(QSize(width, height)); } @@ -1438,10 +1433,8 @@ void MainWindowViewer::closeEvent(QCloseEvent *event) viewer->save(); Configuration &conf = Configuration::getConfiguration(); - if (!fullscreen && !isMaximized()) { - conf.setPos(pos()); - conf.setSize(size()); - } + if (!fullscreen && !isMaximized()) + conf.setGeometry(saveGeometry()); conf.setMaximized(isMaximized()); event->accept(); diff --git a/common/yacreader_global_gui.h b/common/yacreader_global_gui.h index 417cab8d..0ec4ab1b 100644 --- a/common/yacreader_global_gui.h +++ b/common/yacreader_global_gui.h @@ -15,8 +15,7 @@ #define FITMODE "FITMODE" #define FLOW_TYPE "FLOW_TYPE" #define FULLSCREEN "FULLSCREEN" -#define Y_WINDOW_POS "POS" -#define Y_WINDOW_SIZE "SIZE" +#define Y_WINDOW_GEOMETRY "GEOMETRY" #define MAXIMIZED "MAXIMIZED" #define DOUBLE_PAGE "DOUBLE_PAGE" #define DOUBLE_MANGA_PAGE "DOUBLE_MANGA_PAGE"