From 2f629a9e5be1d377b34912816969cd081f8b7709 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Mon, 25 Apr 2022 14:50:41 +0800 Subject: [PATCH] Quick: make the titleBarItem become a property By making it a Q_PROPERTY we can use it more conveniently. Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- README.md | 1 + examples/quick/MainWindow.qml | 2 +- .../FramelessHelper/Quick/framelessquickwindow.h | 10 +++++++--- src/core/utils_win.cpp | 8 ++++---- src/quick/framelessquickwindow.cpp | 15 ++++++++++++++- src/quick/framelessquickwindow_p.h | 2 ++ 6 files changed, 29 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 5e6960d..4bbf46b 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,7 @@ Please refer to the demo applications to see more detailed usages: [examples](./ - Force your application use the ANGLE backend instead of the Desktop OpenGL. - Force your application use pure software rendering instead of rendering through OpenGL. - Or just don't use OpenGL at all, try to use Direct3D/Vulkan/Metal instead. +- Due to there are many sub-versions of Windows 10, it's highly recommended to use the latest version of Windows 10, at least no older than Windows 10 1809. If you try to use this framework on some very old Windows 10 versions such as 1507 or 1607, there may be some compatibility issues. Using this framework on Windows 7 is also supported but not recommended. To get the most stable behavior and the best appearance, you should use it on the latest version of Windows 10 or Windows 11. ### Linux diff --git a/examples/quick/MainWindow.qml b/examples/quick/MainWindow.qml index ab412b1..c025dbb 100644 --- a/examples/quick/MainWindow.qml +++ b/examples/quick/MainWindow.qml @@ -78,7 +78,7 @@ FramelessWindow { window.snapToTopBorder(titleBar, FramelessHelper.Top, FramelessHelper.Bottom); // Make our homemade title bar draggable, and on Windows, open the system menu // when the user right clicks on the title bar area. - window.setTitleBarItem(titleBar); + window.titleBarItem = titleBar; // Make our homemade system buttons visible to hit test. // The call to "setHitTestVisible()" is necessary, don't forget to do it. window.setHitTestVisible(minimizeButton); diff --git a/include/FramelessHelper/Quick/framelessquickwindow.h b/include/FramelessHelper/Quick/framelessquickwindow.h index 083f7aa..b3d2ed6 100644 --- a/include/FramelessHelper/Quick/framelessquickwindow.h +++ b/include/FramelessHelper/Quick/framelessquickwindow.h @@ -45,9 +45,10 @@ class FRAMELESSHELPER_QUICK_API FramelessQuickWindow : public QQuickWindow Q_PROPERTY(bool minimized READ isMinimized NOTIFY minimizedChanged FINAL) Q_PROPERTY(bool zoomed READ isZoomed NOTIFY zoomedChanged FINAL) Q_PROPERTY(bool fullScreen READ isFullScreen NOTIFY fullScreenChanged FINAL) - Q_PROPERTY(bool fixedSize READ fixedSize WRITE setFixedSize NOTIFY fixedSizeChanged FINAL) + Q_PROPERTY(bool fixedSize READ isFixedSize WRITE setFixedSize NOTIFY fixedSizeChanged FINAL) Q_PROPERTY(QColor frameBorderColor READ frameBorderColor NOTIFY frameBorderColorChanged FINAL) Q_PROPERTY(QuickGlobal::Options options READ options WRITE setOptions NOTIFY optionsChanged FINAL) + Q_PROPERTY(QQuickItem* titleBarItem READ titleBarItem WRITE setTitleBarItem NOTIFY titleBarItemChanged FINAL) public: explicit FramelessQuickWindow(QWindow *parent = nullptr, const Global::UserSettings &settings = {}); @@ -59,7 +60,7 @@ public: Q_NODISCARD bool isZoomed() const; Q_NODISCARD bool isFullScreen() const; - Q_NODISCARD bool fixedSize() const; + Q_NODISCARD bool isFixedSize() const; void setFixedSize(const bool value); Q_NODISCARD QColor frameBorderColor() const; @@ -67,6 +68,9 @@ public: Q_NODISCARD QuickGlobal::Options options() const; void setOptions(const QuickGlobal::Options value); + Q_NODISCARD QQuickItem *titleBarItem() const; + void setTitleBarItem(QQuickItem *item); + public Q_SLOTS: void showMinimized2(); void toggleMaximized(); @@ -74,7 +78,6 @@ public Q_SLOTS: void showSystemMenu(const QPoint &pos); void startSystemMove2(const QPoint &pos); void startSystemResize2(const Qt::Edges edges, const QPoint &pos); - void setTitleBarItem(QQuickItem *item); void setHitTestVisible(QQuickItem *item); void moveToDesktopCenter(); void bringToFront(); @@ -90,6 +93,7 @@ Q_SIGNALS: void frameBorderColorChanged(); void systemButtonStateChanged(const QuickGlobal::SystemButtonType, const QuickGlobal::ButtonState); void optionsChanged(); + void titleBarItemChanged(); private: QScopedPointer d_ptr; diff --git a/src/core/utils_win.cpp b/src/core/utils_win.cpp index 76d73c7..113501a 100644 --- a/src/core/utils_win.cpp +++ b/src/core/utils_win.cpp @@ -1178,8 +1178,8 @@ void Utils::tryToEnableHighestDpiAwarenessLevel() // Any attempt to change the DPI awareness level through API will always fail, // so we treat this situation as succeeded. if (dwError == ERROR_ACCESS_DENIED) { - qDebug() << "FramelessHelper doesn't have access to change this process's DPI awareness level," - " most likely due to it has been setted externally."; + qDebug() << "FramelessHelper doesn't have access to change the current process's DPI awareness level," + " most likely due to it has been set externally already."; return true; } qWarning() << __getSystemErrorMessage(kSetProcessDpiAwarenessContext, dwError); @@ -1211,8 +1211,8 @@ void Utils::tryToEnableHighestDpiAwarenessLevel() // Any attempt to change the DPI awareness level through API will always fail, // so we treat this situation as succeeded. if (hr == E_ACCESSDENIED) { - qDebug() << "FramelessHelper doesn't have access to change this process's DPI awareness level," - " most likely due to it has been setted externally."; + qDebug() << "FramelessHelper doesn't have access to change the current process's DPI awareness level," + " most likely due to it has been set externally already."; return true; } qWarning() << __getSystemErrorMessage(kSetProcessDpiAwareness, hr); diff --git a/src/quick/framelessquickwindow.cpp b/src/quick/framelessquickwindow.cpp index b3ad12f..ef82940 100644 --- a/src/quick/framelessquickwindow.cpp +++ b/src/quick/framelessquickwindow.cpp @@ -225,6 +225,8 @@ void FramelessQuickWindowPrivate::setTitleBarItem(QQuickItem *item) return; } m_titleBarItem = item; + Q_Q(FramelessQuickWindow); + Q_EMIT q->titleBarItemChanged(); } void FramelessQuickWindowPrivate::setHitTestVisible(QQuickItem *item) @@ -773,6 +775,11 @@ QuickGlobal::Options FramelessQuickWindowPrivate::getOptions() const return m_quickOptions; } +QQuickItem *FramelessQuickWindowPrivate::getTitleBarItem() const +{ + return m_titleBarItem; +} + void FramelessQuickWindowPrivate::updateTopBorderColor() { #ifdef Q_OS_WINDOWS @@ -831,7 +838,7 @@ bool FramelessQuickWindow::isFullScreen() const return d->isFullScreen(); } -bool FramelessQuickWindow::fixedSize() const +bool FramelessQuickWindow::isFixedSize() const { Q_D(const FramelessQuickWindow); return d->isFixedSize(); @@ -861,6 +868,12 @@ void FramelessQuickWindow::setOptions(const QuickGlobal::Options value) d->setOptions(value); } +QQuickItem *FramelessQuickWindow::titleBarItem() const +{ + Q_D(const FramelessQuickWindow); + return d->getTitleBarItem(); +} + void FramelessQuickWindow::setTitleBarItem(QQuickItem *item) { Q_ASSERT(item); diff --git a/src/quick/framelessquickwindow_p.h b/src/quick/framelessquickwindow_p.h index daad340..e3daf07 100644 --- a/src/quick/framelessquickwindow_p.h +++ b/src/quick/framelessquickwindow_p.h @@ -73,6 +73,8 @@ public: Q_INVOKABLE Q_NODISCARD QuickGlobal::Options getOptions() const; + Q_INVOKABLE Q_NODISCARD QQuickItem *getTitleBarItem() const; + public Q_SLOTS: void showMinimized2(); void toggleMaximized();