From 0d13901cbb5891781b258dfa666fdef7bffe179a Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Tue, 16 Jan 2024 14:48:56 +0800 Subject: [PATCH] fix: the window can't restore form the second screen well --- DSView/pv/config/appconfig.cpp | 5 +++++ DSView/pv/config/appconfig.h | 2 ++ DSView/pv/mainframe.cpp | 38 +++++++++++++++++++++++++++------- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/DSView/pv/config/appconfig.cpp b/DSView/pv/config/appconfig.cpp index 1d6ebc1c..2cabb2b4 100644 --- a/DSView/pv/config/appconfig.cpp +++ b/DSView/pv/config/appconfig.cpp @@ -188,6 +188,8 @@ static void _loadFrame(FrameOptions &o, QSettings &st) getFiled("top", st, o.top, 0); getFiled("right", st, o.right, 0); getFiled("bottom", st, o.bottom, 0); + getFiled("x", st, o.x, -10000); + getFiled("y", st, o.y, -10000); _loadDockOptions(o._logicDock, st, "LOGIC_DOCK"); _loadDockOptions(o._analogDock, st, "ANALOG_DOCK"); @@ -217,6 +219,9 @@ static void _saveFrame(FrameOptions &o, QSettings &st) setFiled("top", st, o.top); setFiled("right", st, o.right); setFiled("bottom", st, o.bottom); + setFiled("x", st, o.x); + setFiled("y", st, o.y); + st.setValue("windowState", o.windowState); _saveDockOptions(o._logicDock, st, "LOGIC_DOCK"); diff --git a/DSView/pv/config/appconfig.h b/DSView/pv/config/appconfig.h index 2c02bb60..aba12640 100644 --- a/DSView/pv/config/appconfig.h +++ b/DSView/pv/config/appconfig.h @@ -88,6 +88,8 @@ struct FrameOptions int top; int right; int bottom; + int x; + int y; bool isMax; QByteArray windowState; diff --git a/DSView/pv/mainframe.cpp b/DSView/pv/mainframe.cpp index fb849b11..a32d8fc3 100644 --- a/DSView/pv/mainframe.cpp +++ b/DSView/pv/mainframe.cpp @@ -432,12 +432,16 @@ bool MainFrame::eventFilter(QObject *object, QEvent *event) void MainFrame::saveWindowRegion() { - AppConfig &app = AppConfig::Instance(); - QRect rc = geometry(); - app.frameOptions.left = rc.left(); - app.frameOptions.top = rc.top(); - app.frameOptions.right = rc.right(); - app.frameOptions.bottom = rc.bottom(); + AppConfig &app = AppConfig::Instance(); + QRect rc = geometry(); + app.frameOptions.left = rc.left(); + app.frameOptions.top = rc.top(); + app.frameOptions.right = rc.right(); + app.frameOptions.bottom = rc.bottom(); + + QRect frc = frameGeometry(); + app.frameOptions.x = frc.x(); + app.frameOptions.y = frc.y(); } void MainFrame::writeSettings() @@ -460,13 +464,15 @@ void MainFrame::readSettings() AppConfig &app = AppConfig::Instance(); if (app.frameOptions.language > 0){ - _mainWindow->switchLanguage(app.frameOptions.language); + _mainWindow->switchLanguage(app.frameOptions.language); } int left = app.frameOptions.left; int top = app.frameOptions.top; int right = app.frameOptions.right; int bottom = app.frameOptions.bottom; + int x = app.frameOptions.x; + int y = app.frameOptions.y; bool bReset = false; int scrIndex = -1; @@ -499,7 +505,10 @@ void MainFrame::readSettings() if (app.frameOptions.isMax) { + QRect rc = QGuiApplication::screens().at(scrIndex)->availableGeometry(); + move(rc.left(), rc.top()); showMaximized(); // show max by system api + dsv_info("show as max, screens:%s", QGuiApplication::screens().at(scrIndex)->name().toStdString().c_str()); } else if (bReset) { @@ -508,11 +517,24 @@ void MainFrame::readSettings() const int origX = std::max(0, (trc.width() - width()) / 2); const int origY = std::max(0, (trc.height() - height()) / 2); move(origX, origY); + dsv_info("reset, screens:%s", QGuiApplication::screens().at(scrIndex)->name().toStdString().c_str()); } else - { + { resize(right - left, bottom - top); + +#ifdef _WIN32 + if (y != -10000){ + move(x, y); + } + else{ + move(left, top); + } +#else move(left, top); +#endif + + dsv_info("restore, screens:%s", QGuiApplication::screens().at(scrIndex)->name().toStdString().c_str()); } // restore dockwidgets