From 38a277801d9be7ea72668cef73badeff1f3c8594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A=5Czhuzi?= Date: Mon, 11 Mar 2024 12:36:20 +0800 Subject: [PATCH] fix bug #455 --- src/FluFramelessHelper.cpp | 39 +++++++------------ src/FluFramelessHelper.h | 2 +- .../imports/FluentUI/Controls/FluAppBar.qml | 10 ++--- .../imports/FluentUI/Controls/FluWindow.qml | 25 +++++------- .../imports/FluentUI/Controls/FluAppBar.qml | 10 ++--- .../imports/FluentUI/Controls/FluWindow.qml | 25 +++++------- 6 files changed, 44 insertions(+), 67 deletions(-) diff --git a/src/FluFramelessHelper.cpp b/src/FluFramelessHelper.cpp index ed3be788..910eaa8d 100644 --- a/src/FluFramelessHelper.cpp +++ b/src/FluFramelessHelper.cpp @@ -72,10 +72,8 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void * const auto clientRect = ((wParam == FALSE) ? reinterpret_cast(lParam) : &(reinterpret_cast(lParam))->rgrc[0]); const LONG originalTop = clientRect->top; const LONG originalLeft = clientRect->left; -#if QT_VERSION < QT_VERSION_CHECK(6,0,0) const LONG originalRight = clientRect->right; const LONG originalBottom = clientRect->bottom; -#endif const LRESULT hitTestResult = ::DefWindowProcW(hwnd, WM_NCCALCSIZE, wParam, lParam); if ((hitTestResult != HTERROR) && (hitTestResult != HTNOWHERE)) { *result = hitTestResult; @@ -85,23 +83,19 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void * bool isMaximum = ::IsZoomed(hwnd); offsetXY = QPoint(abs(clientRect->left - originalLeft),abs(clientRect->top - originalTop)); if(isMaximum || _helper->fullScreen()){ - _helper->setOriginalPos(QPoint(originalLeft,originalTop)); offsetSize = 0; }else{ - _helper->setOriginalPos({}); offsetSize = 1; } if(!isCompositionEnabled()){ offsetSize = 0; } - clientRect->top = originalTop+offsetSize; -#if QT_VERSION < QT_VERSION_CHECK(6,0,0) - if(!isMaximum){ - clientRect->bottom = originalBottom-offsetSize; - clientRect->left = originalLeft+offsetSize; - clientRect->right = originalRight-offsetSize; + if (!isMaximum || QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) { + clientRect->top = originalTop + offsetSize; + clientRect->bottom = originalBottom - offsetSize; + clientRect->left = originalLeft + offsetSize; + clientRect->right = originalRight - offsetSize; } -#endif *result = WVR_REDRAW; return true; }if(uMsg == WM_NCHITTEST){ @@ -172,13 +166,11 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void * *result = ::DefWindowProcW(hwnd, WM_NCACTIVATE, wParam, -1); return true; }else if(uMsg == WM_GETMINMAXINFO){ -#if QT_VERSION < QT_VERSION_CHECK(6,2,4) MINMAXINFO* minmaxInfo = reinterpret_cast(lParam); auto pixelRatio = _helper->window->devicePixelRatio(); auto geometry = _helper->window->screen()->availableGeometry(); - minmaxInfo->ptMaxSize.x = geometry.width()*pixelRatio + offsetXY.x()*2; - minmaxInfo->ptMaxSize.y = geometry.height()*pixelRatio + offsetXY.y()*2; -#endif + minmaxInfo->ptMaxSize.x = geometry.width()*pixelRatio + offsetXY.x() * 2; + minmaxInfo->ptMaxSize.y = geometry.height()*pixelRatio + offsetXY.y() * 2; return false; }else if(uMsg == WM_NCRBUTTONDOWN){ if (wParam == HTCAPTION) { @@ -302,7 +294,6 @@ void FluFramelessHelper::componentComplete(){ _stayTop = QQmlProperty(window,"stayTop"); _screen = QQmlProperty(window,"screen"); _fixSize = QQmlProperty(window,"fixSize"); - _originalPos = QQmlProperty(window,"_originalPos"); _realHeight = QQmlProperty(window,"_realHeight"); _realWidth = QQmlProperty(window,"_realWidth"); _appBarHeight = QQmlProperty(window,"_appBarHeight"); @@ -311,7 +302,7 @@ void FluFramelessHelper::componentComplete(){ if(!_appBar.isNull()){ _appBar.value()->setProperty("systemMoveEnable",false); } - window->setFlags((window->flags()) | Qt::CustomizeWindowHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint); + window->setFlags((window->flags()) | Qt::CustomizeWindowHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint | Qt::FramelessWindowHint); if(resizeable()){ window->setFlag(Qt::WindowMaximizeButtonHint); } @@ -324,9 +315,6 @@ void FluFramelessHelper::componentComplete(){ }else{ ::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME); } - LONG exstyle = ::GetWindowLong(hwnd, GWL_EXSTYLE); - exstyle = exstyle | 0x02000000; - ::SetWindowLongPtr(hwnd, GWL_EXSTYLE, exstyle); #else window->setFlags((window->flags() & (~Qt::WindowMinMaxButtonsHint) & (~Qt::Dialog)) | Qt::FramelessWindowHint | Qt::Window); window->installEventFilter(this); @@ -382,6 +370,13 @@ void FluFramelessHelper::showSystemMenu(QPoint point){ #endif } +void FluFramelessHelper::showMaximized(){ +#ifdef Q_OS_WIN + HWND hwnd = reinterpret_cast(window->winId()); + ::ShowWindow(hwnd,3); +#endif +} + void FluFramelessHelper::_onStayTopChange(){ bool isStayTop = _stayTop.read().toBool(); #ifdef Q_OS_WIN @@ -457,10 +452,6 @@ QObject* FluFramelessHelper::maximizeButton(){ return var.value(); } -void FluFramelessHelper::setOriginalPos(QVariant pos){ - _originalPos.write(pos); -} - bool FluFramelessHelper::resizeable(){ return !_fixSize.read().toBool(); } diff --git a/src/FluFramelessHelper.h b/src/FluFramelessHelper.h index dbe16480..9250a47c 100644 --- a/src/FluFramelessHelper.h +++ b/src/FluFramelessHelper.h @@ -54,6 +54,7 @@ public: QObject* maximizeButton(); void setOriginalPos(QVariant pos); Q_INVOKABLE void showSystemMenu(QPoint point); + Q_INVOKABLE void showMaximized(); Q_SIGNAL void loadCompleted(); protected: bool eventFilter(QObject *obj, QEvent *event) override; @@ -67,7 +68,6 @@ private: FramelessEventFilter* _nativeEvent = nullptr; QQmlProperty _stayTop; QQmlProperty _screen; - QQmlProperty _originalPos; QQmlProperty _fixSize; QQmlProperty _realHeight; QQmlProperty _realWidth; diff --git a/src/Qt5/imports/FluentUI/Controls/FluAppBar.qml b/src/Qt5/imports/FluentUI/Controls/FluAppBar.qml index 30b8686d..6ca7665e 100644 --- a/src/Qt5/imports/FluentUI/Controls/FluAppBar.qml +++ b/src/Qt5/imports/FluentUI/Controls/FluAppBar.qml @@ -37,19 +37,19 @@ Rectangle{ property var maxClickListener : function(){ if(FluTools.isMacos()){ if (d.win.visibility === Window.FullScreen) - d.win.visibility = Window.Windowed + d.win.showNormal() else - d.win.visibility = Window.FullScreen + d.win.showFullScreen() }else{ if (d.win.visibility === Window.Maximized) - d.win.visibility = Window.Windowed + d.win.showNormal() else - d.win.visibility = Window.Maximized + d.win.showMaximized() d.hoverMaxBtn = false } } property var minClickListener: function(){ - d.win.visibility = Window.Minimized + d.win.showMinimized() } property var closeClickListener : function(){ d.win.close() diff --git a/src/Qt5/imports/FluentUI/Controls/FluWindow.qml b/src/Qt5/imports/FluentUI/Controls/FluWindow.qml index 51635539..b0acb40c 100644 --- a/src/Qt5/imports/FluentUI/Controls/FluWindow.qml +++ b/src/Qt5/imports/FluentUI/Controls/FluWindow.qml @@ -58,8 +58,6 @@ Window { signal showSystemMenu signal initArgument(var argument) signal firstVisible() - property point _offsetXY : Qt.point(0,0) - property var _originalPos property int _realHeight property int _realWidth property int _appBarHeight: appBar.height @@ -91,19 +89,6 @@ Window { Component.onDestruction: { lifecycle.onDestruction() } - on_OriginalPosChanged: { - if(_originalPos){ - var dx = (_originalPos.x - screen.virtualX)/screen.devicePixelRatio - var dy = (_originalPos.y - screen.virtualY)/screen.devicePixelRatio - if(dx<0 && dy<0){ - _offsetXY = Qt.point(Math.abs(dx)-1,Math.abs(dy)-1) - }else{ - _offsetXY = Qt.point(0,0) - } - }else{ - _offsetXY = Qt.point(0,0) - } - } onShowSystemMenu: { if(loader_frameless_helper.item){ loader_frameless_helper.item.showSystemMenu() @@ -223,7 +208,6 @@ Window { id:layout_container anchors{ fill:parent - topMargin: _offsetXY.y } onWidthChanged: { window.appBar.width = width @@ -337,4 +321,13 @@ Window { function layoutContent(){ return layout_content } + function showMaximized(){ + if(FluTools.isWin()){ + if(loader_frameless_helper.item){ + loader_frameless_helper.item.showMaximized() + } + }else{ + window.visibility = Qt.WindowMaximized + } + } } diff --git a/src/Qt6/imports/FluentUI/Controls/FluAppBar.qml b/src/Qt6/imports/FluentUI/Controls/FluAppBar.qml index 67436197..b4352ee4 100644 --- a/src/Qt6/imports/FluentUI/Controls/FluAppBar.qml +++ b/src/Qt6/imports/FluentUI/Controls/FluAppBar.qml @@ -37,19 +37,19 @@ Rectangle{ property var maxClickListener : function(){ if(FluTools.isMacos()){ if (d.win.visibility === Window.FullScreen) - d.win.visibility = Window.Windowed + d.win.showNormal() else - d.win.visibility = Window.FullScreen + d.win.showFullScreen() }else{ if (d.win.visibility === Window.Maximized) - d.win.visibility = Window.Windowed + d.win.showNormal() else - d.win.visibility = Window.Maximized + d.win.showMaximized() d.hoverMaxBtn = false } } property var minClickListener: function(){ - d.win.visibility = Window.Minimized + d.win.showMinimized() } property var closeClickListener : function(){ d.win.close() diff --git a/src/Qt6/imports/FluentUI/Controls/FluWindow.qml b/src/Qt6/imports/FluentUI/Controls/FluWindow.qml index e5fe38d4..0ad01a96 100644 --- a/src/Qt6/imports/FluentUI/Controls/FluWindow.qml +++ b/src/Qt6/imports/FluentUI/Controls/FluWindow.qml @@ -57,8 +57,6 @@ Window { signal showSystemMenu signal initArgument(var argument) signal firstVisible() - property point _offsetXY : Qt.point(0,0) - property var _originalPos property int _realHeight property int _realWidth property int _appBarHeight: appBar.height @@ -90,19 +88,6 @@ Window { Component.onDestruction: { lifecycle.onDestruction() } - on_OriginalPosChanged: { - if(_originalPos){ - var dx = (_originalPos.x - screen.virtualX)/screen.devicePixelRatio - var dy = (_originalPos.y - screen.virtualY)/screen.devicePixelRatio - if(dx<0 && dy<0){ - _offsetXY = Qt.point(Math.abs(dx)-1,Math.abs(dy)-1) - }else{ - _offsetXY = Qt.point(0,0) - } - }else{ - _offsetXY = Qt.point(0,0) - } - } onShowSystemMenu: { if(loader_frameless_helper.item){ loader_frameless_helper.item.showSystemMenu() @@ -222,7 +207,6 @@ Window { id:layout_container anchors{ fill:parent - topMargin: _offsetXY.y } onWidthChanged: { window.appBar.width = width @@ -336,4 +320,13 @@ Window { function layoutContent(){ return layout_content } + function showMaximized(){ + if(FluTools.isWin()){ + if(loader_frameless_helper.item){ + loader_frameless_helper.item.showMaximized() + } + }else{ + window.visibility = Qt.WindowMaximized + } + } }