2
0
forked from Ivasoft/DSView

fix: the window can't restore form the second screen well

This commit is contained in:
dreamsourcelabTAI
2024-01-16 14:48:56 +08:00
parent 6990a3aa07
commit 0d13901cbb
3 changed files with 37 additions and 8 deletions

View File

@@ -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");

View File

@@ -88,6 +88,8 @@ struct FrameOptions
int top;
int right;
int bottom;
int x;
int y;
bool isMax;
QByteArray windowState;

View File

@@ -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