From c5aad9feed6e2766aa1f6bbd51be535f822b1ab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A=5Czhuzi?= Date: Fri, 15 Dec 2023 22:41:11 +0800 Subject: [PATCH] update --- example/qml-Qt6/window/MainWindow.qml | 1 - example/qml/window/MainWindow.qml | 1 - src/FluFrameless.cpp | 20 ++- src/FluFrameless.h | 1 + .../imports/FluentUI/Controls/FluWindow.qml | 137 ++++++++++-------- .../imports/FluentUI/Controls/FluWindow.qml | 135 +++++++++-------- 6 files changed, 162 insertions(+), 133 deletions(-) diff --git a/example/qml-Qt6/window/MainWindow.qml b/example/qml-Qt6/window/MainWindow.qml index d6a710a8..56de8c1b 100644 --- a/example/qml-Qt6/window/MainWindow.qml +++ b/example/qml-Qt6/window/MainWindow.qml @@ -20,7 +20,6 @@ FluWindow { launchMode: FluWindowType.SingleTask fitsAppBarWindows: true appBar: FluAppBar { - width: window.width height: 30 darkText: Lang.dark_mode showDark: true diff --git a/example/qml/window/MainWindow.qml b/example/qml/window/MainWindow.qml index 2f4c08b8..616dd461 100644 --- a/example/qml/window/MainWindow.qml +++ b/example/qml/window/MainWindow.qml @@ -23,7 +23,6 @@ FluWindow { launchMode: FluWindowType.SingleTask fitsAppBarWindows: true appBar: FluAppBar { - width: window.width height: 30 darkText: Lang.dark_mode showDark: true diff --git a/src/FluFrameless.cpp b/src/FluFrameless.cpp index b0e90297..13d5068e 100644 --- a/src/FluFrameless.cpp +++ b/src/FluFrameless.cpp @@ -46,12 +46,10 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void * } return false; }else if(uMsg == WM_NCCALCSIZE){ -#if QT_VERSION < QT_VERSION_CHECK(6,0,0) - NCCALCSIZE_PARAMS& sz = *reinterpret_cast(msg->lParam); + NCCALCSIZE_PARAMS* sz = reinterpret_cast(msg->lParam); *result = WVR_REDRAW; - sz.rgrc[0].top -= 1; + sz->rgrc[0].top -= 1; return true; -#endif } return false; #endif @@ -161,10 +159,16 @@ void FluFrameless::componentComplete(){ #ifdef Q_OS_WIN _nativeEvent =new FramelessEventFilter(_window); qApp->installNativeEventFilter(_nativeEvent); - HWND hWnd = reinterpret_cast(_window->winId()); - ULONG_PTR cNewStyle = GetClassLongPtr(hWnd, GCL_STYLE) | CS_DROPSHADOW; - SetClassLongPtr(hWnd, GCL_STYLE, cNewStyle); - SetWindowPos(hWnd,nullptr,0,0,0,0,SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE |SWP_FRAMECHANGED); + HWND hwnd = reinterpret_cast(_window->winId()); + ULONG_PTR cNewStyle = GetClassLongPtr(hwnd, GCL_STYLE) | CS_DROPSHADOW; + SetClassLongPtr(hwnd, GCL_STYLE, cNewStyle); + DWORD style = ::GetWindowLong(hwnd, GWL_STYLE); + SetWindowPos(hwnd,nullptr,0,0,0,0,SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE |SWP_FRAMECHANGED); + SetWindowLong(hwnd, GWL_STYLE, style | WS_THICKFRAME | WS_CAPTION); + connect(this,&FluFrameless::stayTopChanged,this,[this,hwnd](){ + DWORD style = ::GetWindowLong(hwnd, GWL_STYLE); + SetWindowLong(hwnd, GWL_STYLE, style | WS_THICKFRAME | WS_CAPTION); + }); #endif } } diff --git a/src/FluFrameless.h b/src/FluFrameless.h index b5c7ae6b..3f013190 100644 --- a/src/FluFrameless.h +++ b/src/FluFrameless.h @@ -28,6 +28,7 @@ public: class FluFrameless : public QObject, public QQmlParserStatus { Q_OBJECT + Q_PROPERTY_AUTO(bool,stayTop) QML_NAMED_ELEMENT(FluFrameless) public: explicit FluFrameless(QObject *parent = nullptr); diff --git a/src/Qt5/imports/FluentUI/Controls/FluWindow.qml b/src/Qt5/imports/FluentUI/Controls/FluWindow.qml index 1e28f079..d7c19bd0 100644 --- a/src/Qt5/imports/FluentUI/Controls/FluWindow.qml +++ b/src/Qt5/imports/FluentUI/Controls/FluWindow.qml @@ -16,7 +16,6 @@ Window { property bool fitsAppBarWindows: false property Item appBar: FluAppBar { title: window.title - width: window.width height: 30 showDark: window.showDark showClose: window.showClose @@ -87,14 +86,6 @@ Window { } lifecycle.onVisible(visible) } - Component{ - id:com_frameless - FluFrameless{ - } - } - FluLoader{ - id:loader_frameless - } QtObject{ id:d property bool isFirstVisible: true @@ -119,53 +110,24 @@ Window { target: window function onClosing(event){closeListener(event)} } + Component{ + id:com_frameless + FluFrameless{ + stayTop: window.stayTop + } + } Component{ id:com_background Rectangle{ color: window.backgroundColor } } - FluLoader{ - anchors.fill: parent - sourceComponent: background - } - FluLoader{ - id:loader_app_bar - anchors { - top: parent.top - left: parent.left - right: parent.right - } - height: { - if(window.useSystemAppBar){ - return 0 - } - return window.fitsAppBarWindows ? 0 : window.appBar.height - } - sourceComponent: window.useSystemAppBar ? undefined : com_app_bar - } Component{ id:com_app_bar Item{ data: window.appBar } } - Item{ - id:container - anchors{ - top: loader_app_bar.bottom - left: parent.left - right: parent.right - bottom: parent.bottom - } - clip: true - } - FluLoader{ - property string loadingText: "加载中..." - property bool cancel: false - id:loader_loading - anchors.fill: container - } Component{ id:com_loading Popup{ @@ -228,27 +190,78 @@ Window { } } } - FluInfoBar{ - id:infoBar - root: window - } - WindowLifecycle{ - id:lifecycle - } - Rectangle{ + FluLoader{ anchors.fill: parent - anchors.topMargin: FluTools.isWin() ? 1/Screen.devicePixelRatio : 0 - color:"transparent" - border.width: window.resizeBorderWidth - border.color: window.resizeBorderColor - visible: { - if(window.useSystemAppBar){ - return false + sourceComponent: background + } + FluLoader{ + id:loader_frameless + } + Item{ + id:layout_content + anchors.fill: parent + anchors.margins: { + if(FluTools.isWin()){ + return window.visibility === Window.Maximized ? 8 : 0 } - if(window.visibility == Window.Maximized || window.visibility == Window.FullScreen){ - return false + return 0 + } + onWidthChanged: { + window.appBar.width = width + } + FluLoader{ + id:loader_app_bar + anchors { + top: parent.top + left: parent.left + right: parent.right + } + height: { + if(window.useSystemAppBar){ + return 0 + } + return window.fitsAppBarWindows ? 0 : window.appBar.height + } + sourceComponent: window.useSystemAppBar ? undefined : com_app_bar + } + Item{ + id:container + anchors{ + top: loader_app_bar.bottom + left: parent.left + right: parent.right + bottom: parent.bottom + } + clip: true + } + FluLoader{ + property string loadingText: "加载中..." + property bool cancel: false + id:loader_loading + anchors.fill: container + } + FluInfoBar{ + id:infoBar + root: window + } + WindowLifecycle{ + id:lifecycle + } + Rectangle{ + anchors.fill: parent + color:"transparent" + anchors.topMargin: FluTools.isWin() ? 1/Screen.devicePixelRatio : 0 + border.width: window.resizeBorderWidth + border.color: window.resizeBorderColor + visible: { + if(window.useSystemAppBar){ + return false + } + if(window.visibility == Window.Maximized || window.visibility == Window.FullScreen){ + return false + } + return true } - return true } } function destoryOnClose(){ diff --git a/src/Qt6/imports/FluentUI/Controls/FluWindow.qml b/src/Qt6/imports/FluentUI/Controls/FluWindow.qml index 57c20e8e..15d72689 100644 --- a/src/Qt6/imports/FluentUI/Controls/FluWindow.qml +++ b/src/Qt6/imports/FluentUI/Controls/FluWindow.qml @@ -15,7 +15,6 @@ Window { property bool fitsAppBarWindows: false property Item appBar: FluAppBar { title: window.title - width: window.width height: 30 showDark: window.showDark showClose: window.showClose @@ -86,14 +85,6 @@ Window { } lifecycle.onVisible(visible) } - Component{ - id:com_frameless - FluFrameless{ - } - } - FluLoader{ - id:loader_frameless - } QtObject{ id:d property bool isFirstVisible: true @@ -118,53 +109,24 @@ Window { target: window function onClosing(event){closeListener(event)} } + Component{ + id:com_frameless + FluFrameless{ + stayTop: window.stayTop + } + } Component{ id:com_background Rectangle{ color: window.backgroundColor } } - FluLoader{ - anchors.fill: parent - sourceComponent: background - } - FluLoader{ - id:loader_app_bar - anchors { - top: parent.top - left: parent.left - right: parent.right - } - height: { - if(window.useSystemAppBar){ - return 0 - } - return window.fitsAppBarWindows ? 0 : window.appBar.height - } - sourceComponent: window.useSystemAppBar ? undefined : com_app_bar - } Component{ id:com_app_bar Item{ data: window.appBar } } - Item{ - id:container - anchors{ - top: loader_app_bar.bottom - left: parent.left - right: parent.right - bottom: parent.bottom - } - clip: true - } - FluLoader{ - property string loadingText: "加载中..." - property bool cancel: false - id:loader_loading - anchors.fill: container - } Component{ id:com_loading Popup{ @@ -227,26 +189,77 @@ Window { } } } - FluInfoBar{ - id:infoBar - root: window - } - WindowLifecycle{ - id:lifecycle - } - Rectangle{ + FluLoader{ anchors.fill: parent - color:"transparent" - border.width: window.resizeBorderWidth - border.color: window.resizeBorderColor - visible: { - if(window.useSystemAppBar){ - return false + sourceComponent: background + } + FluLoader{ + id:loader_frameless + } + Item{ + id:layout_content + anchors.fill: parent + anchors.margins: { + if(FluTools.isWin()){ + return window.visibility === Window.Maximized ? 8 : 0 } - if(window.visibility == Window.Maximized || window.visibility == Window.FullScreen){ - return false + return 0 + } + onWidthChanged: { + window.appBar.width = width + } + FluLoader{ + id:loader_app_bar + anchors { + top: parent.top + left: parent.left + right: parent.right + } + height: { + if(window.useSystemAppBar){ + return 0 + } + return window.fitsAppBarWindows ? 0 : window.appBar.height + } + sourceComponent: window.useSystemAppBar ? undefined : com_app_bar + } + Item{ + id:container + anchors{ + top: loader_app_bar.bottom + left: parent.left + right: parent.right + bottom: parent.bottom + } + clip: true + } + FluLoader{ + property string loadingText: "加载中..." + property bool cancel: false + id:loader_loading + anchors.fill: container + } + FluInfoBar{ + id:infoBar + root: window + } + WindowLifecycle{ + id:lifecycle + } + Rectangle{ + anchors.fill: parent + color:"transparent" + border.width: window.resizeBorderWidth + border.color: window.resizeBorderColor + visible: { + if(window.useSystemAppBar){ + return false + } + if(window.visibility == Window.Maximized || window.visibility == Window.FullScreen){ + return false + } + return true } - return true } } function destoryOnClose(){