From 1c67f2a41b86b13464e5eb24dc86a2578c776c06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A=5Czhuzi?= Date: Wed, 20 Dec 2023 21:58:59 +0800 Subject: [PATCH] update --- src/FluTools.cpp | 15 +++++++++++++++ src/FluTools.h | 2 ++ src/Qt5/imports/FluentUI/Controls/FluWindow.qml | 11 ++++++----- src/Qt6/imports/FluentUI/Controls/FluWindow.qml | 11 ++++++----- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/FluTools.cpp b/src/FluTools.cpp index 2d89b81a..99786219 100644 --- a/src/FluTools.cpp +++ b/src/FluTools.cpp @@ -179,3 +179,18 @@ qint64 FluTools::currentTimestamp(){ QIcon FluTools::windowIcon(){ return QGuiApplication::windowIcon(); } + +int FluTools::cursorScreenIndex(){ + int screenIndex = 0; + int screenCount = qApp->screens().count(); + if (screenCount > 1) { + QPoint pos = QCursor::pos(); + for (int i = 0; i < screenCount; ++i) { + if (qApp->screens().at(i)->geometry().contains(pos)) { + screenIndex = i; + break; + } + } + } + return screenIndex; +} diff --git a/src/FluTools.h b/src/FluTools.h index 09882b81..72e57e89 100644 --- a/src/FluTools.h +++ b/src/FluTools.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "singleton.h" /** @@ -50,6 +51,7 @@ public: Q_INVOKABLE qint64 currentTimestamp(); Q_INVOKABLE QPoint cursorPos(); Q_INVOKABLE QIcon windowIcon(); + Q_INVOKABLE int cursorScreenIndex(); }; #endif // FLUTOOLS_H diff --git a/src/Qt5/imports/FluentUI/Controls/FluWindow.qml b/src/Qt5/imports/FluentUI/Controls/FluWindow.qml index 72d2ec8f..cf5a15da 100644 --- a/src/Qt5/imports/FluentUI/Controls/FluWindow.qml +++ b/src/Qt5/imports/FluentUI/Controls/FluWindow.qml @@ -53,19 +53,15 @@ Window { signal initArgument(var argument) signal firstVisible() id:window - maximumWidth: fixSize ? width : 16777215 - maximumHeight: fixSize ? height : 16777215 - minimumWidth: fixSize ? width : 0 - minimumHeight: fixSize ? height : 0 color:"transparent" Component.onCompleted: { + moveWindowToDesktopCenter() useSystemAppBar = FluApp.useSystemAppBar if(!useSystemAppBar){ loader_frameless.sourceComponent = com_frameless } lifecycle.onCompleted(window) initArgument(argument) - moveWindowToDesktopCenter() if(window.autoMaximize){ window.showMaximized() }else{ @@ -286,7 +282,12 @@ Window { return lifecycle.createRegister(window,path) } function moveWindowToDesktopCenter(){ + screen = Qt.application.screens[FluTools.cursorScreenIndex()] window.setGeometry((Screen.width-window.width)/2+Screen.virtualX,(Screen.height-window.height)/2+Screen.virtualY,window.width,window.height) + maximumWidth = fixSize ? width : 16777215 + maximumHeight = fixSize ? height : 16777215 + minimumWidth = fixSize ? width : 0 + minimumHeight = fixSize ? height : 0 } function onResult(data){ if(_pageRegister){ diff --git a/src/Qt6/imports/FluentUI/Controls/FluWindow.qml b/src/Qt6/imports/FluentUI/Controls/FluWindow.qml index 0442323b..c28b7955 100644 --- a/src/Qt6/imports/FluentUI/Controls/FluWindow.qml +++ b/src/Qt6/imports/FluentUI/Controls/FluWindow.qml @@ -52,19 +52,15 @@ Window { signal initArgument(var argument) signal firstVisible() id:window - maximumWidth: fixSize ? width : 16777215 - maximumHeight: fixSize ? height : 16777215 - minimumWidth: fixSize ? width : 0 - minimumHeight: fixSize ? height : 0 color:"transparent" Component.onCompleted: { + moveWindowToDesktopCenter() useSystemAppBar = FluApp.useSystemAppBar if(!useSystemAppBar){ loader_frameless.sourceComponent = com_frameless } lifecycle.onCompleted(window) initArgument(argument) - moveWindowToDesktopCenter() if(window.autoMaximize){ window.showMaximized() }else{ @@ -285,7 +281,12 @@ Window { return lifecycle.createRegister(window,path) } function moveWindowToDesktopCenter(){ + screen = Qt.application.screens[FluTools.cursorScreenIndex()] window.setGeometry((Screen.width-window.width)/2+Screen.virtualX,(Screen.height-window.height)/2+Screen.virtualY,window.width,window.height) + maximumWidth = fixSize ? width : 16777215 + maximumHeight = fixSize ? height : 16777215 + minimumWidth = fixSize ? width : 0 + minimumHeight = fixSize ? height : 0 } function onResult(data){ if(_pageRegister){