diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ae58c5f..4a67e1cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,7 @@ cmake_minimum_required(VERSION 3.20) project(FramelessHelper - VERSION 2.1.0.0 + VERSION 2.1.1.0 DESCRIPTION "Cross-platform window customization framework for Qt Widgets and Qt Quick." HOMEPAGE_URL "https://github.com/wangwenx190/framelesshelper/" LANGUAGES CXX diff --git a/README.md b/README.md index 6b1d5d1a..85a65192 100644 --- a/README.md +++ b/README.md @@ -143,6 +143,8 @@ void MyWidget::myFunction2() } ``` +**IMPORTANT NOTE**: Some functionalities may only be available when `FramelessHelper` has finished the window customization process, such as changing window geometry/flags/state. In this case you can connect to the public `void ready()` signal of `FramelessHelper` to get the accurate time point and do your rest initialization process afterwards. + ### Qt Quick #### Code snippet @@ -223,6 +225,26 @@ If you find any of `FramelessHelper` functions have no effect after calling, the There's also a QML type called `FramelessWindow`, it's only a simple wrapper of `FramelessHelper`, you can absolutely use plain `Window` instead. +**IMPORTANT NOTE**: Some functionalities may only be available when `FramelessHelper` has finished the window customization process, such as changing window geometry/flags/state. In this case you can connect to the public `void ready()` signal of `FramelessHelper` to get the accurate time point and do your rest initialization process afterwards. + +```qml +Window { + FramelessHelper.onReady: { + // do something here ... + } +} +``` + +```qml +Window { + FramelessHelper { + onReady: { + // do something here ... + } + } +} +``` + ### More Please refer to the demo projects to see more detailed usages: [examples](./examples/) diff --git a/include/FramelessHelper/Core/framelesshelpercore_global.h b/include/FramelessHelper/Core/framelesshelpercore_global.h index 33647b2b..ef14e224 100644 --- a/include/FramelessHelper/Core/framelesshelpercore_global.h +++ b/include/FramelessHelper/Core/framelesshelpercore_global.h @@ -152,8 +152,31 @@ QT_END_NAMESPACE # define FRAMELESSHELPER_PREPEND_NAMESPACE(X) ::FRAMELESSHELPER_NAMESPACE::X #endif +#ifndef FRAMELESSHELPER_MAKE_VERSION +# define FRAMELESSHELPER_MAKE_VERSION(Major, Minor, Patch, Tweak) \ + (((Major & 0xff) << 24) | ((Minor & 0xff) << 16) | ((Patch & 0xff) << 8) | (Tweak & 0xff)) +#endif + +#ifndef FRAMELESSHELPER_EXTRACT_VERSION +# define FRAMELESSHELPER_EXTRACT_VERSION(Version, Major, Minor, Patch, Tweak) \ + { \ + Major = ((Version & 0xff) >> 24); \ + Minor = ((Version & 0xff) >> 16); \ + Patch = ((Version & 0xff) >> 8); \ + Tweak = (Version & 0xff); \ + } +#endif + FRAMELESSHELPER_BEGIN_NAMESPACE +[[maybe_unused]] static constexpr const int FRAMELESSHELPER_VERSION_MAJOR = 2; +[[maybe_unused]] static constexpr const int FRAMELESSHELPER_VERSION_MINOR = 1; +[[maybe_unused]] static constexpr const int FRAMELESSHELPER_VERSION_PATCH = 1; +[[maybe_unused]] static constexpr const int FRAMELESSHELPER_VERSION_TWEAK = 0; +[[maybe_unused]] static constexpr const int FRAMELESSHELPER_VERSION = + FRAMELESSHELPER_MAKE_VERSION(FRAMELESSHELPER_VERSION_MAJOR, FRAMELESSHELPER_VERSION_MINOR, + FRAMELESSHELPER_VERSION_PATCH, FRAMELESSHELPER_VERSION_TWEAK); + namespace Global { @@ -471,6 +494,7 @@ static_assert(std::size(WindowsVersions) == (static_cast(WindowsVersion::_1 namespace FramelessHelper::Core { FRAMELESSHELPER_CORE_API void initialize(); +[[nodiscard]] FRAMELESSHELPER_CORE_API int version(); } // namespace FramelessHelper::Core FRAMELESSHELPER_END_NAMESPACE diff --git a/include/FramelessHelper/Quick/private/quickstandardmaximizebutton_p.h b/include/FramelessHelper/Quick/private/quickstandardmaximizebutton_p.h deleted file mode 100644 index e72fca10..00000000 --- a/include/FramelessHelper/Quick/private/quickstandardmaximizebutton_p.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#pragma once - -#include "framelesshelperquick_global.h" -#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) -#include - -QT_BEGIN_NAMESPACE -class QQuickImage; -class QQuickRectangle; -QT_END_NAMESPACE - -FRAMELESSHELPER_BEGIN_NAMESPACE - -class FRAMELESSHELPER_QUICK_API QuickStandardMaximizeButton : public QQuickButton -{ - Q_OBJECT -#ifdef QML_NAMED_ELEMENT - QML_NAMED_ELEMENT(StandardMaximizeButton) -#endif - Q_DISABLE_COPY_MOVE(QuickStandardMaximizeButton) - Q_PROPERTY(bool maximized READ isMaximized WRITE setMaximized NOTIFY maximizedChanged FINAL) - -public: - explicit QuickStandardMaximizeButton(QQuickItem *parent = nullptr); - ~QuickStandardMaximizeButton() override; - - Q_NODISCARD bool isMaximized() const; - void setMaximized(const bool max); - -public Q_SLOTS: - void updateForeground(); - void updateBackground(); - void setInactive(const bool value); - -Q_SIGNALS: - void maximizedChanged(); - -private: - void initialize(); - void checkInactive(); - -private: - bool m_max = false; - QScopedPointer m_contentItem; - QScopedPointer m_image; - QScopedPointer m_backgroundItem; - bool m_forceLightTheme = false; - bool m_shouldCheck = false; - bool m_checkFlag = false; -}; - -FRAMELESSHELPER_END_NAMESPACE - -QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickStandardMaximizeButton)) -#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) diff --git a/include/FramelessHelper/Quick/private/quickstandardminimizebutton_p.h b/include/FramelessHelper/Quick/private/quickstandardminimizebutton_p.h deleted file mode 100644 index d2e9355b..00000000 --- a/include/FramelessHelper/Quick/private/quickstandardminimizebutton_p.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#pragma once - -#include "framelesshelperquick_global.h" -#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) -#include - -QT_BEGIN_NAMESPACE -class QQuickImage; -class QQuickRectangle; -QT_END_NAMESPACE - -FRAMELESSHELPER_BEGIN_NAMESPACE - -class FRAMELESSHELPER_QUICK_API QuickStandardMinimizeButton : public QQuickButton -{ - Q_OBJECT -#ifdef QML_NAMED_ELEMENT - QML_NAMED_ELEMENT(StandardMinimizeButton) -#endif - Q_DISABLE_COPY_MOVE(QuickStandardMinimizeButton) - -public: - explicit QuickStandardMinimizeButton(QQuickItem *parent = nullptr); - ~QuickStandardMinimizeButton() override; - -public Q_SLOTS: - void updateForeground(); - void updateBackground(); - void setInactive(const bool value); - -private: - void initialize(); - void checkInactive(); - -private: - QScopedPointer m_contentItem; - QScopedPointer m_image; - QScopedPointer m_backgroundItem; - bool m_forceLightTheme = false; - bool m_shouldCheck = false; - bool m_checkFlag = false; -}; - -FRAMELESSHELPER_END_NAMESPACE - -QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickStandardMinimizeButton)) -#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) diff --git a/include/FramelessHelper/Quick/private/quickstandardclosebutton_p.h b/include/FramelessHelper/Quick/private/quickstandardsystembutton_p.h similarity index 76% rename from include/FramelessHelper/Quick/private/quickstandardclosebutton_p.h rename to include/FramelessHelper/Quick/private/quickstandardsystembutton_p.h index fa1c2a4e..04f039ee 100644 --- a/include/FramelessHelper/Quick/private/quickstandardclosebutton_p.h +++ b/include/FramelessHelper/Quick/private/quickstandardsystembutton_p.h @@ -35,37 +35,39 @@ QT_END_NAMESPACE FRAMELESSHELPER_BEGIN_NAMESPACE -class FRAMELESSHELPER_QUICK_API QuickStandardCloseButton : public QQuickButton +class FRAMELESSHELPER_QUICK_API QuickStandardSystemButton : public QQuickButton { Q_OBJECT #ifdef QML_NAMED_ELEMENT - QML_NAMED_ELEMENT(StandardCloseButton) + QML_NAMED_ELEMENT(StandardSystemButton) #endif - Q_DISABLE_COPY_MOVE(QuickStandardCloseButton) + Q_DISABLE_COPY_MOVE(QuickStandardSystemButton) public: - explicit QuickStandardCloseButton(QQuickItem *parent = nullptr); - ~QuickStandardCloseButton() override; + explicit QuickStandardSystemButton(QQuickItem *parent = nullptr); + explicit QuickStandardSystemButton(const QuickGlobal::SystemButtonType type, QQuickItem *parent = nullptr); + ~QuickStandardSystemButton() override; public Q_SLOTS: void updateForeground(); void updateBackground(); void setInactive(const bool value); + void setButtonType(const QuickGlobal::SystemButtonType type); private: void initialize(); void checkInactive(); private: - QScopedPointer m_contentItem; - QScopedPointer m_image; + QScopedPointer m_contentItem; QScopedPointer m_backgroundItem; bool m_forceLightTheme = false; bool m_shouldCheck = false; bool m_checkFlag = false; + QuickGlobal::SystemButtonType m_buttonType = QuickGlobal::SystemButtonType::Unknown; }; FRAMELESSHELPER_END_NAMESPACE -QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickStandardCloseButton)) +QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickStandardSystemButton)) #endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) diff --git a/include/FramelessHelper/Quick/private/quickstandardtitlebar_p.h b/include/FramelessHelper/Quick/private/quickstandardtitlebar_p.h index 53b83970..4d3002c3 100644 --- a/include/FramelessHelper/Quick/private/quickstandardtitlebar_p.h +++ b/include/FramelessHelper/Quick/private/quickstandardtitlebar_p.h @@ -35,9 +35,7 @@ QT_END_NAMESPACE FRAMELESSHELPER_BEGIN_NAMESPACE -class QuickStandardMinimizeButton; -class QuickStandardMaximizeButton; -class QuickStandardCloseButton; +class QuickStandardSystemButton; class FRAMELESSHELPER_QUICK_API QuickStandardTitleBar : public QQuickRectangle { @@ -48,9 +46,9 @@ class FRAMELESSHELPER_QUICK_API QuickStandardTitleBar : public QQuickRectangle Q_DISABLE_COPY_MOVE(QuickStandardTitleBar) Q_PROPERTY(Qt::Alignment titleLabelAlignment READ titleLabelAlignment WRITE setTitleLabelAlignment NOTIFY titleLabelAlignmentChanged FINAL) Q_PROPERTY(QQuickLabel* titleLabel READ titleLabel CONSTANT FINAL) - Q_PROPERTY(QuickStandardMinimizeButton* minimizeButton READ minimizeButton CONSTANT FINAL) - Q_PROPERTY(QuickStandardMaximizeButton* maximizeButton READ maximizeButton CONSTANT FINAL) - Q_PROPERTY(QuickStandardCloseButton* closeButton READ closeButton CONSTANT FINAL) + Q_PROPERTY(QuickStandardSystemButton* minimizeButton READ minimizeButton CONSTANT FINAL) + Q_PROPERTY(QuickStandardSystemButton* maximizeButton READ maximizeButton CONSTANT FINAL) + Q_PROPERTY(QuickStandardSystemButton* closeButton READ closeButton CONSTANT FINAL) Q_PROPERTY(bool extended READ isExtended WRITE setExtended NOTIFY extendedChanged FINAL) public: @@ -61,9 +59,9 @@ class FRAMELESSHELPER_QUICK_API QuickStandardTitleBar : public QQuickRectangle void setTitleLabelAlignment(const Qt::Alignment value); Q_NODISCARD QQuickLabel *titleLabel() const; - Q_NODISCARD QuickStandardMinimizeButton *minimizeButton() const; - Q_NODISCARD QuickStandardMaximizeButton *maximizeButton() const; - Q_NODISCARD QuickStandardCloseButton *closeButton() const; + Q_NODISCARD QuickStandardSystemButton *minimizeButton() const; + Q_NODISCARD QuickStandardSystemButton *maximizeButton() const; + Q_NODISCARD QuickStandardSystemButton *closeButton() const; Q_NODISCARD bool isExtended() const; void setExtended(const bool value); @@ -93,9 +91,9 @@ private Q_SLOTS: Qt::Alignment m_labelAlignment = {}; QScopedPointer m_windowTitleLabel; QScopedPointer m_systemButtonsRow; - QScopedPointer m_minimizeButton; - QScopedPointer m_maximizeButton; - QScopedPointer m_closeButton; + QScopedPointer m_minimizeButton; + QScopedPointer m_maximizeButton; + QScopedPointer m_closeButton; QMetaObject::Connection m_windowStateChangeConnection = {}; QMetaObject::Connection m_windowActiveChangeConnection = {}; QMetaObject::Connection m_windowTitleChangeConnection = {}; diff --git a/src/core/framelesshelpercore.rc b/src/core/framelesshelpercore.rc index db97854a..802a8ae8 100644 --- a/src/core/framelesshelpercore.rc +++ b/src/core/framelesshelpercore.rc @@ -26,7 +26,7 @@ VS_VERSION_INFO VERSIONINFO FILEVERSION 0,0,0,0 -PRODUCTVERSION 2,1,0,0 +PRODUCTVERSION 2,1,1,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS VS_FF_DEBUG @@ -51,7 +51,7 @@ BEGIN VALUE "OriginalFilename", "FramelessHelperCore.dll" #endif VALUE "ProductName", "FramelessHelper" - VALUE "ProductVersion", "2.1.0.0" + VALUE "ProductVersion", "2.1.1.0" VALUE "InternalName", "FramelessHelperCore" END END diff --git a/src/core/framelessmanager.cpp b/src/core/framelessmanager.cpp index 9e2061c6..92900458 100644 --- a/src/core/framelessmanager.cpp +++ b/src/core/framelessmanager.cpp @@ -289,4 +289,9 @@ void FramelessHelper::Core::initialize() qRegisterMetaType(); } +int FramelessHelper::Core::version() +{ + return FRAMELESSHELPER_VERSION; +} + FRAMELESSHELPER_END_NAMESPACE diff --git a/src/quick/CMakeLists.txt b/src/quick/CMakeLists.txt index 1f03fbd0..0a4aa660 100644 --- a/src/quick/CMakeLists.txt +++ b/src/quick/CMakeLists.txt @@ -35,16 +35,12 @@ set(SOURCES ${INCLUDE_PREFIX}/framelessquickmodule.h ${INCLUDE_PREFIX}/framelessquickhelper.h ${INCLUDE_PREFIX}/framelessquickutils.h - ${INCLUDE_PREFIX}/private/quickstandardminimizebutton_p.h - ${INCLUDE_PREFIX}/private/quickstandardmaximizebutton_p.h - ${INCLUDE_PREFIX}/private/quickstandardclosebutton_p.h + ${INCLUDE_PREFIX}/private/quickstandardsystembutton_p.h ${INCLUDE_PREFIX}/private/quickstandardtitlebar_p.h ${INCLUDE_PREFIX}/private/framelessquickhelper_p.h ${INCLUDE_PREFIX}/private/framelessquickwindow_p.h ${INCLUDE_PREFIX}/private/framelessquickwindow_p_p.h - quickstandardminimizebutton.cpp - quickstandardmaximizebutton.cpp - quickstandardclosebutton.cpp + quickstandardsystembutton.cpp quickstandardtitlebar.cpp framelessquickutils.cpp framelessquickmodule.cpp diff --git a/src/quick/framelesshelperquick.qrc b/src/quick/framelesshelperquick.qrc index fb787fc9..08ce3abd 100644 --- a/src/quick/framelesshelperquick.qrc +++ b/src/quick/framelesshelperquick.qrc @@ -1,7 +1,4 @@ - - module/qmldir - ../core/images/dark/chrome-close.svg ../core/images/dark/chrome-maximize.svg diff --git a/src/quick/framelesshelperquick.rc b/src/quick/framelesshelperquick.rc index 5ba07154..4e61b877 100644 --- a/src/quick/framelesshelperquick.rc +++ b/src/quick/framelesshelperquick.rc @@ -26,7 +26,7 @@ VS_VERSION_INFO VERSIONINFO FILEVERSION 0,0,0,0 -PRODUCTVERSION 2,1,0,0 +PRODUCTVERSION 2,1,1,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS VS_FF_DEBUG @@ -51,7 +51,7 @@ BEGIN VALUE "OriginalFilename", "FramelessHelperQuick.dll" #endif VALUE "ProductName", "FramelessHelper" - VALUE "ProductVersion", "2.1.0.0" + VALUE "ProductVersion", "2.1.1.0" VALUE "InternalName", "FramelessHelperQuick" END END diff --git a/src/quick/framelessquickmodule.cpp b/src/quick/framelessquickmodule.cpp index c49e6764..90cf6978 100644 --- a/src/quick/framelessquickmodule.cpp +++ b/src/quick/framelessquickmodule.cpp @@ -26,9 +26,7 @@ #include "framelessquickhelper.h" #include "framelessquickutils.h" #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) -# include "quickstandardminimizebutton_p.h" -# include "quickstandardmaximizebutton_p.h" -# include "quickstandardclosebutton_p.h" +# include "quickstandardsystembutton_p.h" # include "quickstandardtitlebar_p.h" # include "framelessquickwindow_p.h" #else // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) @@ -75,18 +73,12 @@ void FramelessHelper::Quick::registerTypes(QQmlEngine *engine) qmlRegisterRevision(QUICK_URI_FULL); qmlRegisterType(QUICK_URI_EXPAND("FramelessHelper")); #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) - qmlRegisterType(QUICK_URI_EXPAND("StandardMinimizeButton")); - qmlRegisterType(QUICK_URI_EXPAND("StandardMaximizeButton")); - qmlRegisterType(QUICK_URI_EXPAND("StandardCloseButton")); + qmlRegisterType(QUICK_URI_EXPAND("StandardSystemButton")); qmlRegisterType(QUICK_URI_EXPAND("StandardTitleBar")); qmlRegisterType(QUICK_URI_EXPAND("FramelessWindow")); #else // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) - qmlRegisterTypeNotAvailable(QUICK_URI_EXPAND("StandardMinimizeButton"), - FRAMELESSHELPER_STRING_LITERAL("StandardMinimizeButton is not available until Qt6.")); - qmlRegisterTypeNotAvailable(QUICK_URI_EXPAND("StandardMaximizeButton"), - FRAMELESSHELPER_STRING_LITERAL("StandardMaximizeButton is not available until Qt6.")); - qmlRegisterTypeNotAvailable(QUICK_URI_EXPAND("StandardCloseButton"), - FRAMELESSHELPER_STRING_LITERAL("StandardCloseButton is not available until Qt6.")); + qmlRegisterTypeNotAvailable(QUICK_URI_EXPAND("StandardSystemButton"), + FRAMELESSHELPER_STRING_LITERAL("StandardSystemButton is not available until Qt6.")); qmlRegisterTypeNotAvailable(QUICK_URI_EXPAND("StandardTitleBar"), FRAMELESSHELPER_STRING_LITERAL("StandardTitleBar is not available until Qt6.")); qmlRegisterTypeNotAvailable(QUICK_URI_EXPAND("FramelessWindow"), diff --git a/src/quick/module/qmldir b/src/quick/module/qmldir deleted file mode 100644 index 659d2dc0..00000000 --- a/src/quick/module/qmldir +++ /dev/null @@ -1,6 +0,0 @@ -module org.wangwenx190.FramelessHelper -linktarget FramelessHelperQuick -plugin FramelessHelperQuick -classname FramelessHelperQuickPlugin -typeinfo FramelessHelperQuick.qmltypes -prefer :/org/wangwenx190/FramelessHelper/ diff --git a/src/quick/quickstandardclosebutton.cpp b/src/quick/quickstandardclosebutton.cpp deleted file mode 100644 index 60b8bfe7..00000000 --- a/src/quick/quickstandardclosebutton.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "quickstandardclosebutton_p.h" -#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) -#include -#include -#include -#include -#include -#include - -static inline void initResource() -{ - Q_INIT_RESOURCE(framelesshelperquick); -} - -FRAMELESSHELPER_BEGIN_NAMESPACE - -using namespace Global; - -FRAMELESSHELPER_STRING_CONSTANT2(DarkUrl, "qrc:///org.wangwenx190.FramelessHelper/images/dark/chrome-close.svg") -FRAMELESSHELPER_STRING_CONSTANT2(LightUrl, "qrc:///org.wangwenx190.FramelessHelper/images/light/chrome-close.svg") - -QuickStandardCloseButton::QuickStandardCloseButton(QQuickItem *parent) : QQuickButton(parent) -{ - initialize(); -} - -QuickStandardCloseButton::~QuickStandardCloseButton() = default; - -void QuickStandardCloseButton::updateForeground() -{ - const bool dark = ((Utils::shouldAppsUseDarkMode() || Utils::isTitleBarColorized()) && !m_forceLightTheme); - const auto url = QUrl((dark || isHovered() || isPressed()) ? kDarkUrl : kLightUrl); - initResource(); - m_image->setSource(url); -} - -void QuickStandardCloseButton::updateBackground() -{ - static constexpr const auto button = SystemButtonType::Close; - const bool hover = isHovered(); - const bool press = isPressed(); - m_backgroundItem->setColor(Utils::calculateSystemButtonBackgroundColor(button, (press ? ButtonState::Pressed : ButtonState::Hovered))); - m_backgroundItem->setVisible(hover || press); - checkInactive(); - qobject_cast(qmlAttachedPropertiesObject(this))->setVisible(hover); -} - -void QuickStandardCloseButton::setInactive(const bool value) -{ - const bool force = (value && Utils::isTitleBarColorized() && !Utils::shouldAppsUseDarkMode()); - if (m_forceLightTheme == force) { - return; - } - m_forceLightTheme = force; - m_shouldCheck = m_forceLightTheme; - updateForeground(); -} - -void QuickStandardCloseButton::checkInactive() -{ - if (!m_shouldCheck) { - return; - } - m_forceLightTheme = m_checkFlag; - m_checkFlag = !m_checkFlag; - updateForeground(); -} - -void QuickStandardCloseButton::initialize() -{ - setImplicitWidth(kDefaultSystemButtonSize.width()); - setImplicitHeight(kDefaultSystemButtonSize.height()); - - m_contentItem.reset(new QQuickItem(this)); - m_contentItem->setImplicitWidth(kDefaultSystemButtonIconSize.width()); - m_contentItem->setImplicitHeight(kDefaultSystemButtonIconSize.height()); - m_image.reset(new QQuickImage(m_contentItem.data())); - const auto imageAnchors = new QQuickAnchors(m_image.data(), m_image.data()); - imageAnchors->setCenterIn(m_contentItem.data()); - connect(this, &QuickStandardCloseButton::hoveredChanged, this, &QuickStandardCloseButton::updateForeground); - connect(this, &QuickStandardCloseButton::pressedChanged, this, &QuickStandardCloseButton::updateForeground); - connect(FramelessManager::instance(), &FramelessManager::systemThemeChanged, this, &QuickStandardCloseButton::updateForeground); - - m_backgroundItem.reset(new QQuickRectangle(this)); - QQuickPen * const border = m_backgroundItem->border(); - border->setWidth(0.0); - border->setColor(kDefaultTransparentColor); - connect(this, &QuickStandardCloseButton::hoveredChanged, this, &QuickStandardCloseButton::updateBackground); - connect(this, &QuickStandardCloseButton::pressedChanged, this, &QuickStandardCloseButton::updateBackground); - - updateBackground(); - updateForeground(); - - setContentItem(m_contentItem.data()); - setBackground(m_backgroundItem.data()); -} - -FRAMELESSHELPER_END_NAMESPACE -#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) diff --git a/src/quick/quickstandardmaximizebutton.cpp b/src/quick/quickstandardmaximizebutton.cpp deleted file mode 100644 index 7d30e6e9..00000000 --- a/src/quick/quickstandardmaximizebutton.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "quickstandardmaximizebutton_p.h" -#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) -#include -#include -#include -#include -#include -#include - -static inline void initResource() -{ - Q_INIT_RESOURCE(framelesshelperquick); -} - -FRAMELESSHELPER_BEGIN_NAMESPACE - -using namespace Global; - -FRAMELESSHELPER_STRING_CONSTANT2(DarkMaxUrl, "qrc:///org.wangwenx190.FramelessHelper/images/dark/chrome-maximize.svg") -FRAMELESSHELPER_STRING_CONSTANT2(LightMaxUrl, "qrc:///org.wangwenx190.FramelessHelper/images/light/chrome-maximize.svg") -FRAMELESSHELPER_STRING_CONSTANT2(DarkRestoreUrl, "qrc:///org.wangwenx190.FramelessHelper/images/dark/chrome-restore.svg") -FRAMELESSHELPER_STRING_CONSTANT2(LightRestoreUrl, "qrc:///org.wangwenx190.FramelessHelper/images/light/chrome-restore.svg") - -QuickStandardMaximizeButton::QuickStandardMaximizeButton(QQuickItem *parent) : QQuickButton(parent) -{ - initialize(); -} - -QuickStandardMaximizeButton::~QuickStandardMaximizeButton() = default; - -bool QuickStandardMaximizeButton::isMaximized() const -{ - return m_max; -} - -void QuickStandardMaximizeButton::setMaximized(const bool max) -{ - if (m_max == max) { - return; - } - m_max = max; - Q_EMIT maximizedChanged(); -} - -void QuickStandardMaximizeButton::updateForeground() -{ - const bool dark = ((Utils::shouldAppsUseDarkMode() || Utils::isTitleBarColorized()) && !m_forceLightTheme); - const auto url = QUrl(dark ? (m_max ? kDarkRestoreUrl : kDarkMaxUrl) : (m_max ? kLightRestoreUrl : kLightMaxUrl)); - initResource(); - m_image->setSource(url); -} - -void QuickStandardMaximizeButton::updateBackground() -{ - const SystemButtonType button = (m_max ? SystemButtonType::Restore : SystemButtonType::Maximize); - const bool hover = isHovered(); - const bool press = isPressed(); - m_backgroundItem->setColor(Utils::calculateSystemButtonBackgroundColor(button, (press ? ButtonState::Pressed : ButtonState::Hovered))); - m_backgroundItem->setVisible(hover || press); - checkInactive(); - qobject_cast(qmlAttachedPropertiesObject(this))->setVisible(hover); -} - -void QuickStandardMaximizeButton::setInactive(const bool value) -{ - const bool force = (value && Utils::isTitleBarColorized() && !Utils::shouldAppsUseDarkMode()); - if (m_forceLightTheme == force) { - return; - } - m_forceLightTheme = force; - m_shouldCheck = m_forceLightTheme; - updateForeground(); -} - -void QuickStandardMaximizeButton::checkInactive() -{ - if (!m_shouldCheck) { - return; - } - m_forceLightTheme = m_checkFlag; - m_checkFlag = !m_checkFlag; - updateForeground(); -} - -void QuickStandardMaximizeButton::initialize() -{ - setImplicitWidth(kDefaultSystemButtonSize.width()); - setImplicitHeight(kDefaultSystemButtonSize.height()); - - m_contentItem.reset(new QQuickItem(this)); - m_contentItem->setImplicitWidth(kDefaultSystemButtonIconSize.width()); - m_contentItem->setImplicitHeight(kDefaultSystemButtonIconSize.height()); - m_image.reset(new QQuickImage(m_contentItem.data())); - const auto imageAnchors = new QQuickAnchors(m_image.data(), m_image.data()); - imageAnchors->setCenterIn(m_contentItem.data()); - connect(FramelessManager::instance(), &FramelessManager::systemThemeChanged, this, &QuickStandardMaximizeButton::updateForeground); - connect(this, &QuickStandardMaximizeButton::maximizedChanged, this, &QuickStandardMaximizeButton::updateForeground); - - m_backgroundItem.reset(new QQuickRectangle(this)); - QQuickPen * const border = m_backgroundItem->border(); - border->setWidth(0.0); - border->setColor(kDefaultTransparentColor); - connect(this, &QuickStandardMaximizeButton::hoveredChanged, this, &QuickStandardMaximizeButton::updateBackground); - connect(this, &QuickStandardMaximizeButton::pressedChanged, this, &QuickStandardMaximizeButton::updateBackground); - - updateBackground(); - updateForeground(); - - setContentItem(m_contentItem.data()); - setBackground(m_backgroundItem.data()); -} - -FRAMELESSHELPER_END_NAMESPACE -#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) diff --git a/src/quick/quickstandardmaximizebutton_p.h b/src/quick/quickstandardmaximizebutton_p.h deleted file mode 100644 index 40a6d003..00000000 --- a/src/quick/quickstandardmaximizebutton_p.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../include/FramelessHelper/Quick/private/quickstandardmaximizebutton_p.h" diff --git a/src/quick/quickstandardminimizebutton.cpp b/src/quick/quickstandardminimizebutton.cpp deleted file mode 100644 index 982d8b16..00000000 --- a/src/quick/quickstandardminimizebutton.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "quickstandardminimizebutton_p.h" -#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) -#include -#include -#include -#include -#include -#include - -static inline void initResource() -{ - Q_INIT_RESOURCE(framelesshelperquick); -} - -FRAMELESSHELPER_BEGIN_NAMESPACE - -using namespace Global; - -FRAMELESSHELPER_STRING_CONSTANT2(DarkUrl, "qrc:///org.wangwenx190.FramelessHelper/images/dark/chrome-minimize.svg") -FRAMELESSHELPER_STRING_CONSTANT2(LightUrl, "qrc:///org.wangwenx190.FramelessHelper/images/light/chrome-minimize.svg") - -QuickStandardMinimizeButton::QuickStandardMinimizeButton(QQuickItem *parent) : QQuickButton(parent) -{ - initialize(); -} - -QuickStandardMinimizeButton::~QuickStandardMinimizeButton() = default; - -void QuickStandardMinimizeButton::updateForeground() -{ - const bool dark = ((Utils::shouldAppsUseDarkMode() || Utils::isTitleBarColorized()) && !m_forceLightTheme); - const auto url = QUrl(dark ? kDarkUrl : kLightUrl); - initResource(); - m_image->setSource(url); -} - -void QuickStandardMinimizeButton::updateBackground() -{ - static constexpr const auto button = SystemButtonType::Minimize; - const bool hover = isHovered(); - const bool press = isPressed(); - m_backgroundItem->setColor(Utils::calculateSystemButtonBackgroundColor(button, (press ? ButtonState::Pressed : ButtonState::Hovered))); - m_backgroundItem->setVisible(hover || press); - checkInactive(); - qobject_cast(qmlAttachedPropertiesObject(this))->setVisible(hover); -} - -void QuickStandardMinimizeButton::setInactive(const bool value) -{ - const bool force = (value && Utils::isTitleBarColorized() && !Utils::shouldAppsUseDarkMode()); - if (m_forceLightTheme == force) { - return; - } - m_forceLightTheme = force; - m_shouldCheck = m_forceLightTheme; - updateForeground(); -} - -void QuickStandardMinimizeButton::checkInactive() -{ - if (!m_shouldCheck) { - return; - } - m_forceLightTheme = m_checkFlag; - m_checkFlag = !m_checkFlag; - updateForeground(); -} - -void QuickStandardMinimizeButton::initialize() -{ - setImplicitWidth(kDefaultSystemButtonSize.width()); - setImplicitHeight(kDefaultSystemButtonSize.height()); - - m_contentItem.reset(new QQuickItem(this)); - m_contentItem->setImplicitWidth(kDefaultSystemButtonIconSize.width()); - m_contentItem->setImplicitHeight(kDefaultSystemButtonIconSize.height()); - m_image.reset(new QQuickImage(m_contentItem.data())); - const auto imageAnchors = new QQuickAnchors(m_image.data(), m_image.data()); - imageAnchors->setCenterIn(m_contentItem.data()); - connect(FramelessManager::instance(), &FramelessManager::systemThemeChanged, this, &QuickStandardMinimizeButton::updateForeground); - - m_backgroundItem.reset(new QQuickRectangle(this)); - QQuickPen * const border = m_backgroundItem->border(); - border->setWidth(0.0); - border->setColor(kDefaultTransparentColor); - connect(this, &QuickStandardMinimizeButton::hoveredChanged, this, &QuickStandardMinimizeButton::updateBackground); - connect(this, &QuickStandardMinimizeButton::pressedChanged, this, &QuickStandardMinimizeButton::updateBackground); - - updateBackground(); - updateForeground(); - - setContentItem(m_contentItem.data()); - setBackground(m_backgroundItem.data()); -} - -FRAMELESSHELPER_END_NAMESPACE -#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) diff --git a/src/quick/quickstandardminimizebutton_p.h b/src/quick/quickstandardminimizebutton_p.h deleted file mode 100644 index 818986ed..00000000 --- a/src/quick/quickstandardminimizebutton_p.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../include/FramelessHelper/Quick/private/quickstandardminimizebutton_p.h" diff --git a/src/quick/quickstandardsystembutton.cpp b/src/quick/quickstandardsystembutton.cpp new file mode 100644 index 00000000..32a3085f --- /dev/null +++ b/src/quick/quickstandardsystembutton.cpp @@ -0,0 +1,170 @@ +/* + * MIT License + * + * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "quickstandardsystembutton_p.h" +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +#include +#include +#include +#include +#include + +static inline void initResource() +{ + Q_INIT_RESOURCE(framelesshelperquick); +} + +FRAMELESSHELPER_BEGIN_NAMESPACE + +using namespace Global; + +FRAMELESSHELPER_STRING_CONSTANT2(DarkMinimizeUrl, "qrc:///org.wangwenx190.FramelessHelper/images/dark/chrome-minimize.svg") +FRAMELESSHELPER_STRING_CONSTANT2(LightMinimizeUrl, "qrc:///org.wangwenx190.FramelessHelper/images/light/chrome-minimize.svg") +FRAMELESSHELPER_STRING_CONSTANT2(DarkMaximizeUrl, "qrc:///org.wangwenx190.FramelessHelper/images/dark/chrome-maximize.svg") +FRAMELESSHELPER_STRING_CONSTANT2(LightMaximizeUrl, "qrc:///org.wangwenx190.FramelessHelper/images/light/chrome-maximize.svg") +FRAMELESSHELPER_STRING_CONSTANT2(DarkRestoreUrl, "qrc:///org.wangwenx190.FramelessHelper/images/dark/chrome-restore.svg") +FRAMELESSHELPER_STRING_CONSTANT2(LightRestoreUrl, "qrc:///org.wangwenx190.FramelessHelper/images/light/chrome-restore.svg") +FRAMELESSHELPER_STRING_CONSTANT2(DarkCloseUrl, "qrc:///org.wangwenx190.FramelessHelper/images/dark/chrome-close.svg") +FRAMELESSHELPER_STRING_CONSTANT2(LightCloseUrl, "qrc:///org.wangwenx190.FramelessHelper/images/light/chrome-close.svg") + +QuickStandardSystemButton::QuickStandardSystemButton(QQuickItem *parent) : QQuickButton(parent) +{ + initialize(); +} + +QuickStandardSystemButton::QuickStandardSystemButton(const QuickGlobal::SystemButtonType type, QQuickItem *parent) : QuickStandardSystemButton(parent) +{ + setButtonType(type); +} + +QuickStandardSystemButton::~QuickStandardSystemButton() = default; + +void QuickStandardSystemButton::setButtonType(const QuickGlobal::SystemButtonType type) +{ + Q_ASSERT(type != QuickGlobal::SystemButtonType::Unknown); + if (type == QuickGlobal::SystemButtonType::Unknown) { + return; + } + if (m_buttonType == type) { + return; + } + m_buttonType = type; + updateForeground(); +} + +void QuickStandardSystemButton::updateForeground() +{ + if (m_buttonType == QuickGlobal::SystemButtonType::Unknown) { + return; + } + const QUrl url = [this]() -> QUrl { + const bool dark = ((Utils::shouldAppsUseDarkMode() || Utils::isTitleBarColorized() || ((m_buttonType == QuickGlobal::SystemButtonType::Close) && isHovered())) && !m_forceLightTheme); + switch (m_buttonType) { + case QuickGlobal::SystemButtonType::Minimize: + return QUrl(dark ? kDarkMinimizeUrl : kLightMinimizeUrl); + case QuickGlobal::SystemButtonType::Maximize: + return QUrl(dark ? kDarkMaximizeUrl : kLightMaximizeUrl); + case QuickGlobal::SystemButtonType::Restore: + return QUrl(dark ? kDarkRestoreUrl : kLightRestoreUrl); + case QuickGlobal::SystemButtonType::Close: + return QUrl(dark ? kDarkCloseUrl : kLightCloseUrl); + case QuickGlobal::SystemButtonType::WindowIcon: + Q_FALLTHROUGH(); + case QuickGlobal::SystemButtonType::Help: + Q_FALLTHROUGH(); + case QuickGlobal::SystemButtonType::Unknown: + Q_ASSERT(false); + return {}; + } + Q_UNREACHABLE(); + return {}; + }(); + if (m_contentItem->source() == url) { + return; + } + initResource(); + m_contentItem->setSource(url); +} + +void QuickStandardSystemButton::updateBackground() +{ + const bool hover = isHovered(); + const bool press = isPressed(); + m_backgroundItem->setColor(Utils::calculateSystemButtonBackgroundColor( + FRAMELESSHELPER_ENUM_QUICK_TO_CORE(SystemButtonType, m_buttonType), + (press ? ButtonState::Pressed : ButtonState::Hovered))); + m_backgroundItem->setVisible(hover || press); + checkInactive(); + qobject_cast(qmlAttachedPropertiesObject(this))->setVisible(hover); +} + +void QuickStandardSystemButton::setInactive(const bool value) +{ + const bool force = (value && Utils::isTitleBarColorized() && !Utils::shouldAppsUseDarkMode()); + if (m_forceLightTheme == force) { + return; + } + m_forceLightTheme = force; + m_shouldCheck = m_forceLightTheme; + updateForeground(); +} + +void QuickStandardSystemButton::checkInactive() +{ + if (!m_shouldCheck) { + return; + } + m_forceLightTheme = m_checkFlag; + m_checkFlag = !m_checkFlag; + updateForeground(); +} + +void QuickStandardSystemButton::initialize() +{ + setImplicitWidth(kDefaultSystemButtonSize.width()); + setImplicitHeight(kDefaultSystemButtonSize.height()); + + m_contentItem.reset(new QQuickImage(this)); + m_contentItem->setFillMode(QQuickImage::Pad); + m_contentItem->setWidth(kDefaultSystemButtonIconSize.width()); + m_contentItem->setHeight(kDefaultSystemButtonIconSize.height()); + connect(FramelessManager::instance(), &FramelessManager::systemThemeChanged, this, &QuickStandardSystemButton::updateForeground); + + m_backgroundItem.reset(new QQuickRectangle(this)); + QQuickPen * const border = m_backgroundItem->border(); + border->setWidth(0.0); + border->setColor(kDefaultTransparentColor); + connect(this, &QuickStandardSystemButton::hoveredChanged, this, &QuickStandardSystemButton::updateBackground); + connect(this, &QuickStandardSystemButton::hoveredChanged, this, &QuickStandardSystemButton::updateForeground); + connect(this, &QuickStandardSystemButton::pressedChanged, this, &QuickStandardSystemButton::updateBackground); + + updateBackground(); + updateForeground(); + + setContentItem(m_contentItem.data()); + setBackground(m_backgroundItem.data()); +} + +FRAMELESSHELPER_END_NAMESPACE +#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) diff --git a/src/quick/quickstandardclosebutton_p.h b/src/quick/quickstandardsystembutton_p.h similarity index 75% rename from src/quick/quickstandardclosebutton_p.h rename to src/quick/quickstandardsystembutton_p.h index dc4adcb3..d5450a09 100644 --- a/src/quick/quickstandardclosebutton_p.h +++ b/src/quick/quickstandardsystembutton_p.h @@ -1 +1 @@ -#include "../../include/FramelessHelper/Quick/private/quickstandardclosebutton_p.h" +#include "../../include/FramelessHelper/Quick/private/quickstandardsystembutton_p.h" diff --git a/src/quick/quickstandardtitlebar.cpp b/src/quick/quickstandardtitlebar.cpp index 7cabce26..58ab0447 100644 --- a/src/quick/quickstandardtitlebar.cpp +++ b/src/quick/quickstandardtitlebar.cpp @@ -24,9 +24,7 @@ #include "quickstandardtitlebar_p.h" #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) -#include "quickstandardminimizebutton_p.h" -#include "quickstandardmaximizebutton_p.h" -#include "quickstandardclosebutton_p.h" +#include "quickstandardsystembutton_p.h" #include #include #include @@ -93,17 +91,17 @@ QQuickLabel *QuickStandardTitleBar::titleLabel() const return m_windowTitleLabel.data(); } -QuickStandardMinimizeButton *QuickStandardTitleBar::minimizeButton() const +QuickStandardSystemButton *QuickStandardTitleBar::minimizeButton() const { return m_minimizeButton.data(); } -QuickStandardMaximizeButton *QuickStandardTitleBar::maximizeButton() const +QuickStandardSystemButton *QuickStandardTitleBar::maximizeButton() const { return m_maximizeButton.data(); } -QuickStandardCloseButton *QuickStandardTitleBar::closeButton() const +QuickStandardSystemButton *QuickStandardTitleBar::closeButton() const { return m_closeButton.data(); } @@ -129,15 +127,9 @@ void QuickStandardTitleBar::updateMaximizeButton() if (!w) { return; } - m_maximizeButton->setMaximized(w->visibility() == QQuickWindow::Maximized); - qobject_cast(qmlAttachedPropertiesObject(m_maximizeButton.data()))->setText([this]() -> QString { - if (const QQuickWindow * const w = window()) { - if (w->visibility() == QQuickWindow::Maximized) { - return tr("Restore"); - } - } - return tr("Maximize"); - }()); + const bool max = (w->visibility() == QQuickWindow::Maximized); + m_maximizeButton->setButtonType(max ? QuickGlobal::SystemButtonType::Restore : QuickGlobal::SystemButtonType::Maximize); + qobject_cast(qmlAttachedPropertiesObject(m_maximizeButton.data()))->setText(max ? tr("Restore") : tr("Maximize")); } void QuickStandardTitleBar::updateTitleLabelText() @@ -256,12 +248,12 @@ void QuickStandardTitleBar::initialize() const QQuickItemPrivate * const thisPriv = QQuickItemPrivate::get(this); rowAnchors->setTop(thisPriv->top()); rowAnchors->setRight(thisPriv->right()); - m_minimizeButton.reset(new QuickStandardMinimizeButton(m_systemButtonsRow.data())); - connect(m_minimizeButton.data(), &QuickStandardMinimizeButton::clicked, this, &QuickStandardTitleBar::clickMinimizeButton); - m_maximizeButton.reset(new QuickStandardMaximizeButton(m_systemButtonsRow.data())); - connect(m_maximizeButton.data(), &QuickStandardMaximizeButton::clicked, this, &QuickStandardTitleBar::clickMaximizeButton); - m_closeButton.reset(new QuickStandardCloseButton(m_systemButtonsRow.data())); - connect(m_closeButton.data(), &QuickStandardCloseButton::clicked, this, &QuickStandardTitleBar::clickCloseButton); + m_minimizeButton.reset(new QuickStandardSystemButton(QuickGlobal::SystemButtonType::Minimize, m_systemButtonsRow.data())); + connect(m_minimizeButton.data(), &QuickStandardSystemButton::clicked, this, &QuickStandardTitleBar::clickMinimizeButton); + m_maximizeButton.reset(new QuickStandardSystemButton(m_systemButtonsRow.data())); + connect(m_maximizeButton.data(), &QuickStandardSystemButton::clicked, this, &QuickStandardTitleBar::clickMaximizeButton); + m_closeButton.reset(new QuickStandardSystemButton(QuickGlobal::SystemButtonType::Close, m_systemButtonsRow.data())); + connect(m_closeButton.data(), &QuickStandardSystemButton::clicked, this, &QuickStandardTitleBar::clickCloseButton); connect(FramelessManager::instance(), &FramelessManager::systemThemeChanged, this, &QuickStandardTitleBar::updateTitleBarColor); diff --git a/src/widgets/framelesshelperwidgets.rc b/src/widgets/framelesshelperwidgets.rc index 3c5adf1f..abc1ae97 100644 --- a/src/widgets/framelesshelperwidgets.rc +++ b/src/widgets/framelesshelperwidgets.rc @@ -26,7 +26,7 @@ VS_VERSION_INFO VERSIONINFO FILEVERSION 0,0,0,0 -PRODUCTVERSION 2,1,0,0 +PRODUCTVERSION 2,1,1,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS VS_FF_DEBUG @@ -51,7 +51,7 @@ BEGIN VALUE "OriginalFilename", "FramelessHelperWidgets.dll" #endif VALUE "ProductName", "FramelessHelper" - VALUE "ProductVersion", "2.1.0.0" + VALUE "ProductVersion", "2.1.1.0" VALUE "InternalName", "FramelessHelperWidgets" END END diff --git a/src/widgets/standardsystembutton.cpp b/src/widgets/standardsystembutton.cpp index f2883e44..d89454b9 100644 --- a/src/widgets/standardsystembutton.cpp +++ b/src/widgets/standardsystembutton.cpp @@ -98,6 +98,8 @@ void StandardSystemButtonPrivate::refreshButtonTheme(const bool force) // https://doc.qt.io/qt-6/qpixmap.html#reading-and-writing-image-files setImage(qvariant_cast(Utils::getSystemButtonIconResource(m_buttonType, m_buttonTheme, ResourceType::Image)), false); setImage(qvariant_cast(Utils::getSystemButtonIconResource(m_buttonType, reversedTheme, ResourceType::Image)), true); + setHoverColor(Utils::calculateSystemButtonBackgroundColor(m_buttonType, ButtonState::Hovered)); + setPressColor(Utils::calculateSystemButtonBackgroundColor(m_buttonType, ButtonState::Pressed)); } SystemButtonType StandardSystemButtonPrivate::getButtonType() const @@ -115,8 +117,6 @@ void StandardSystemButtonPrivate::setButtonType(const SystemButtonType type) return; } m_buttonType = type; - setHoverColor(Utils::calculateSystemButtonBackgroundColor(type, ButtonState::Hovered)); - setPressColor(Utils::calculateSystemButtonBackgroundColor(type, ButtonState::Pressed)); refreshButtonTheme(true); } @@ -315,7 +315,8 @@ void StandardSystemButtonPrivate::paintEventHandler(QPaintEvent *event) if (m_reversedIcon.isNull()) { return m_icon; } - if (m_hovered && m_forceLightTheme) { + if (m_hovered && (((m_buttonType == SystemButtonType::Close) + && (m_buttonTheme == SystemTheme::Light)) || m_forceLightTheme)) { return m_reversedIcon; } return m_icon;