diff --git a/examples/quick/CMakeLists.txt b/examples/quick/CMakeLists.txt index b406ea5..afaf54a 100644 --- a/examples/quick/CMakeLists.txt +++ b/examples/quick/CMakeLists.txt @@ -25,22 +25,28 @@ find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS QuickControls2) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS QuickControls2) -set(SOURCES - qml.qrc - main.cpp +qt_add_executable(Quick main.cpp) + +qt_add_qml_module(Quick + URI Demo + VERSION 1.0 + DEPENDENCIES + org.wangwenx190.FramelessHelper + QML_FILES + MainWindow.qml ) if(WIN32) enable_language(RC) - list(APPEND SOURCES ../example.rc ../example.manifest) + target_sources(Quick PRIVATE + ../example.rc ../example.manifest + ) endif() -add_executable(Quick WIN32 ${SOURCES}) - target_link_libraries(Quick PRIVATE Qt${QT_VERSION_MAJOR}::Quick Qt${QT_VERSION_MAJOR}::QuickControls2 - FramelessHelperQuick + FramelessHelperCore ) target_compile_definitions(Quick PRIVATE @@ -51,4 +57,13 @@ target_compile_definitions(Quick PRIVATE QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060400 $<$,$>:QT_QML_DEBUG> + DEMO_IMPORT_DIR="${PROJECT_BINARY_DIR}/imports" +) + +set_target_properties(Quick PROPERTIES + MACOSX_BUNDLE_GUI_IDENTIFIER org.wangwenx190.framelesshelper.quick + MACOSX_BUNDLE_BUNDLE_VERSION 1.0.0.0 + MACOSX_BUNDLE_SHORT_VERSION_STRING 1.0 + MACOSX_BUNDLE TRUE + WIN32_EXECUTABLE TRUE ) diff --git a/examples/quick/qml/MainWindow.qml b/examples/quick/MainWindow.qml similarity index 100% rename from examples/quick/qml/MainWindow.qml rename to examples/quick/MainWindow.qml diff --git a/examples/quick/main.cpp b/examples/quick/main.cpp index bb98578..4b189e0 100644 --- a/examples/quick/main.cpp +++ b/examples/quick/main.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include FRAMELESSHELPER_USE_NAMESPACE @@ -54,6 +54,7 @@ int main(int argc, char *argv[]) } QQmlApplicationEngine engine; + engine.addImportPath(QUtf8String(DEMO_IMPORT_DIR)); // This line is not relevant to FramelessHelper, we change the default // Qt Quick Controls theme to "Basic" (Qt6) or "Default" (Qt5) just @@ -65,10 +66,7 @@ int main(int argc, char *argv[]) QQuickStyle::setStyle(FRAMELESSHELPER_STRING_LITERAL("Default")); #endif - // VERY IMPORTANT! Don't forget to register the QML types! - FramelessHelper::Quick::registerTypes(&engine); - - const QUrl homepageUrl(FRAMELESSHELPER_STRING_LITERAL("qrc:///qml/MainWindow.qml")); + const QUrl homepageUrl(FRAMELESSHELPER_STRING_LITERAL("qrc:///Demo/MainWindow.qml")); const QMetaObject::Connection connection = QObject::connect( &engine, &QQmlApplicationEngine::objectCreated, &application, [&homepageUrl, &connection](QObject *object, const QUrl &url) { diff --git a/examples/quick/qml.qrc b/examples/quick/qml.qrc deleted file mode 100644 index 5c3ce85..0000000 --- a/examples/quick/qml.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - qml/MainWindow.qml - - diff --git a/include/FramelessHelper/Quick/FramelessQuickHelper b/include/FramelessHelper/Quick/FramelessQuickHelper deleted file mode 100644 index 1cbb62f..0000000 --- a/include/FramelessHelper/Quick/FramelessQuickHelper +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/include/FramelessHelper/Quick/framelessquickutils.h b/include/FramelessHelper/Quick/framelessquickutils.h index f761ffb..adc6760 100644 --- a/include/FramelessHelper/Quick/framelessquickutils.h +++ b/include/FramelessHelper/Quick/framelessquickutils.h @@ -61,6 +61,8 @@ public: explicit FramelessQuickUtils(QObject *parent = nullptr); ~FramelessQuickUtils() override; + Q_NODISCARD static FramelessQuickUtils *instance(); + Q_NODISCARD static qreal titleBarHeight(); Q_NODISCARD static bool frameBorderVisible(); Q_NODISCARD static qreal frameBorderThickness(); diff --git a/src/quick/CMakeLists.txt b/src/quick/CMakeLists.txt index 1b061f9..be8f2ec 100644 --- a/src/quick/CMakeLists.txt +++ b/src/quick/CMakeLists.txt @@ -22,47 +22,63 @@ SOFTWARE. ]] -set(SUB_PROJ_NAME FramelessHelperQuick) +set(PROJ_TARGET framelesshelperplugin) +set(PROJ_CLASS FramelessHelperPlugin) +set(PROJ_URI org.wangwenx190.FramelessHelper) +set(PROJ_VERSION 1.0) +set(PROJ_IMPORTS_DIR ${PROJECT_BINARY_DIR}/imports/org/wangwenx190/FramelessHelper) set(INCLUDE_PREFIX ../../include/FramelessHelper/Quick) -set(SOURCES - ${INCLUDE_PREFIX}/framelesshelperquick_global.h - ${INCLUDE_PREFIX}/framelessquickutils.h - ${INCLUDE_PREFIX}/framelesshelperimageprovider.h - ${INCLUDE_PREFIX}/framelessquickhelper.h - ${INCLUDE_PREFIX}/framelessquickwindow.h - framelessquickwindow_p.h - framelesshelperquick.qrc - framelessquickhelper.cpp - framelessquickutils.cpp - framelesshelperimageprovider.cpp - framelessquickwindow.cpp +find_package(Qt6 REQUIRED COMPONENTS QuickTemplates2) + +qt_add_qml_module(${PROJ_TARGET} + URI ${PROJ_URI} + VERSION ${PROJ_VERSION} + PLUGIN_TARGET ${PROJ_TARGET} + CLASS_NAME ${PROJ_CLASS} + OUTPUT_DIRECTORY ${PROJ_IMPORTS_DIR} + NO_PLUGIN_OPTIONAL + NO_GENERATE_PLUGIN_SOURCE + SOURCES + ${INCLUDE_PREFIX}/framelesshelperquick_global.h + ${INCLUDE_PREFIX}/framelessquickutils.h + ${INCLUDE_PREFIX}/framelesshelperimageprovider.h + ${INCLUDE_PREFIX}/framelessquickwindow.h + quickstandardminimizebutton_p.h + quickstandardminimizebutton.cpp + quickstandardmaximizebutton_p.h + quickstandardmaximizebutton.cpp + quickstandardclosebutton_p.h + quickstandardclosebutton.cpp + quickstandardtitlebar_p.h + quickstandardtitlebar.cpp + framelessquickwindow_p.h + framelessquickutils.cpp + framelesshelperimageprovider.cpp + framelessquickwindow.cpp + plugin.cpp ) if(WIN32 AND NOT FRAMELESSHELPER_BUILD_STATIC) enable_language(RC) - list(APPEND SOURCES framelesshelperquick.rc) + target_sources(${PROJ_TARGET} PRIVATE + framelesshelperquick.rc + ) endif() if(FRAMELESSHELPER_BUILD_STATIC) - add_library(${SUB_PROJ_NAME} STATIC ${SOURCES}) -else() - add_library(${SUB_PROJ_NAME} SHARED ${SOURCES}) -endif() - -if(FRAMELESSHELPER_BUILD_STATIC) - target_compile_definitions(${SUB_PROJ_NAME} PUBLIC + target_compile_definitions(${PROJ_TARGET} PUBLIC FRAMELESSHELPER_QUICK_STATIC ) endif() -target_compile_definitions(${SUB_PROJ_NAME} PRIVATE +target_compile_definitions(${PROJ_TARGET} PRIVATE QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII QT_NO_URL_CAST_FROM_STRING QT_NO_CAST_FROM_BYTEARRAY - QT_NO_KEYWORDS + #QT_NO_KEYWORDS QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_FOREACH QT_USE_QSTRINGBUILDER @@ -74,30 +90,31 @@ target_compile_definitions(${SUB_PROJ_NAME} PRIVATE if(MSVC) set(_WIN32_WINNT_WIN10 0x0A00) set(NTDDI_WIN10_CO 0x0A00000B) - target_compile_definitions(${SUB_PROJ_NAME} PRIVATE + target_compile_definitions(${PROJ_TARGET} PRIVATE _CRT_NON_CONFORMING_SWPRINTFS _CRT_SECURE_NO_WARNINGS _ENABLE_EXTENDED_ALIGNED_STORAGE NOMINMAX UNICODE _UNICODE WIN32_LEAN_AND_MEAN WINRT_LEAN_AND_MEAN WINVER=${_WIN32_WINNT_WIN10} _WIN32_WINNT=${_WIN32_WINNT_WIN10} _WIN32_IE=${_WIN32_WINNT_WIN10} NTDDI_VERSION=${NTDDI_WIN10_CO} ) - target_compile_options(${SUB_PROJ_NAME} PRIVATE + target_compile_options(${PROJ_TARGET} PRIVATE /utf-8 /W4 /WX ) else() - target_compile_options(${SUB_PROJ_NAME} PRIVATE + target_compile_options(${PROJ_TARGET} PRIVATE -Wall -Wextra -Werror ) endif() -target_link_libraries(${SUB_PROJ_NAME} PRIVATE +target_link_libraries(${PROJ_TARGET} PRIVATE Qt${QT_VERSION_MAJOR}::QuickPrivate + Qt${QT_VERSION_MAJOR}::QuickTemplates2Private ) -target_link_libraries(${SUB_PROJ_NAME} PUBLIC +target_link_libraries(${PROJ_TARGET} PUBLIC FramelessHelperCore ) -target_include_directories(${SUB_PROJ_NAME} PUBLIC +target_include_directories(${PROJ_TARGET} PUBLIC "$/${INCLUDE_PREFIX}" ) diff --git a/src/quick/framelesshelperquick.qrc b/src/quick/framelesshelperquick.qrc deleted file mode 100644 index cca4488..0000000 --- a/src/quick/framelesshelperquick.qrc +++ /dev/null @@ -1,8 +0,0 @@ - - - qml/StandardCloseButton.qml - qml/StandardMaximizeButton.qml - qml/StandardMinimizeButton.qml - qml/StandardTitleBar.qml - - diff --git a/src/quick/framelessquickutils.cpp b/src/quick/framelessquickutils.cpp index eddb328..9dfb393 100644 --- a/src/quick/framelessquickutils.cpp +++ b/src/quick/framelessquickutils.cpp @@ -34,6 +34,8 @@ FRAMELESSHELPER_BEGIN_NAMESPACE using namespace Global; +Q_GLOBAL_STATIC(FramelessQuickUtils, g_quickUtils) + FramelessQuickUtils::FramelessQuickUtils(QObject *parent) : QObject(parent) { connect(FramelessWindowsManager::instance(), &FramelessWindowsManager::systemThemeChanged, this, [this](){ @@ -45,6 +47,11 @@ FramelessQuickUtils::FramelessQuickUtils(QObject *parent) : QObject(parent) FramelessQuickUtils::~FramelessQuickUtils() = default; +FramelessQuickUtils *FramelessQuickUtils::instance() +{ + return g_quickUtils(); +} + qreal FramelessQuickUtils::titleBarHeight() { return 30.0; diff --git a/src/quick/framelessquickwindow.cpp b/src/quick/framelessquickwindow.cpp index 09490d0..504c376 100644 --- a/src/quick/framelessquickwindow.cpp +++ b/src/quick/framelessquickwindow.cpp @@ -49,6 +49,24 @@ FramelessQuickWindowPrivate::FramelessQuickWindowPrivate(FramelessQuickWindow *q FramelessQuickWindowPrivate::~FramelessQuickWindowPrivate() = default; +FramelessQuickWindowPrivate *FramelessQuickWindowPrivate::get(FramelessQuickWindow *pub) +{ + Q_ASSERT(pub); + if (!pub) { + return nullptr; + } + return pub->d_func(); +} + +const FramelessQuickWindowPrivate *FramelessQuickWindowPrivate::get(const FramelessQuickWindow *pub) +{ + Q_ASSERT(pub); + if (!pub) { + return nullptr; + } + return pub->d_func(); +} + bool FramelessQuickWindowPrivate::isHidden() const { Q_Q(const FramelessQuickWindow); diff --git a/src/quick/framelessquickwindow_p.h b/src/quick/framelessquickwindow_p.h index a4deadd..26c9548 100644 --- a/src/quick/framelessquickwindow_p.h +++ b/src/quick/framelessquickwindow_p.h @@ -47,6 +47,9 @@ public: explicit FramelessQuickWindowPrivate(FramelessQuickWindow *q, const Global::UserSettings &settings = {}); ~FramelessQuickWindowPrivate() override; + Q_NODISCARD static FramelessQuickWindowPrivate *get(FramelessQuickWindow *pub); + Q_NODISCARD static const FramelessQuickWindowPrivate *get(const FramelessQuickWindow *pub); + Q_INVOKABLE Q_NODISCARD bool isHidden() const; Q_INVOKABLE Q_NODISCARD bool isNormal() const; Q_INVOKABLE Q_NODISCARD bool isMinimized() const; diff --git a/src/quick/framelessquickhelper.cpp b/src/quick/plugin.cpp similarity index 52% rename from src/quick/framelessquickhelper.cpp rename to src/quick/plugin.cpp index eff1fe1..9dfa72d 100644 --- a/src/quick/framelessquickhelper.cpp +++ b/src/quick/plugin.cpp @@ -22,17 +22,15 @@ * SOFTWARE. */ -#include "framelessquickhelper.h" +#include "framelesshelperquick_global.h" #include #include "framelesshelperimageprovider.h" #include "framelessquickutils.h" #include "framelessquickwindow.h" - -#ifndef QML_URL_EXPAND -# define QML_URL_EXPAND(fileName) \ - QUrl(FRAMELESSHELPER_STRING_LITERAL("qrc:///org.wangwenx190.FramelessHelper/qml/%1.qml") \ - .arg(FRAMELESSHELPER_STRING_LITERAL(fileName))) -#endif +#include "quickstandardminimizebutton_p.h" +#include "quickstandardmaximizebutton_p.h" +#include "quickstandardclosebutton_p.h" +#include "quickstandardtitlebar_p.h" #ifndef QUICK_URI_SHORT # define QUICK_URI_SHORT FRAMELESSHELPER_QUICK_URI, 1 @@ -54,57 +52,17 @@ # endif #endif -#ifndef qmlRegisgerFile -# define qmlRegisterFile(Name) qmlRegisterType(QML_URL_EXPAND(Name), QUICK_URI_EXPAND(Name)) -#endif - -// The "Q_INIT_RESOURCE()" macro can't be used inside a namespace, -// the official workaround is to wrap it into a global function -// and call the wrapper function inside the namespace. -static inline void initResource() -{ - Q_INIT_RESOURCE(framelesshelperquick); -} - FRAMELESSHELPER_BEGIN_NAMESPACE -void FramelessHelper::Quick::registerTypes(QQmlEngine *engine) -{ - Q_ASSERT(engine); - if (!engine) { - return; - } - static bool inited = false; - if (inited) { - return; - } - inited = true; - engine->addImageProvider(FRAMELESSHELPER_STRING_LITERAL("framelesshelper"), new FramelessHelperImageProvider); - qmlRegisterModule(QUICK_URI_FULL); - qmlRegisterUncreatableMetaObject(Global::staticMetaObject, QUICK_URI_EXPAND("FramelessHelper"), - FRAMELESSHELPER_STRING_LITERAL("The FramelessHelper namespace is not creatable, you can only use it to access its enums.")); - qmlRegisterSingletonType(QUICK_URI_EXPAND("FramelessUtils"), - [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { - Q_UNUSED(engine); - Q_UNUSED(scriptEngine); - return new FramelessQuickUtils; - }); - qmlRegisterAnonymousType2(QWindow, QUICK_URI_SHORT); - qmlRegisterAnonymousType2(QQuickWindow, QUICK_URI_SHORT); - qmlRegisterType(QUICK_URI_EXPAND("FramelessWindow")); - initResource(); - qmlRegisterFile("StandardMinimizeButton"); - qmlRegisterFile("StandardMaximizeButton"); - qmlRegisterFile("StandardCloseButton"); - qmlRegisterFile("StandardTitleBar"); -} - -class FRAMELESSHELPER_QUICK_API FramelessHelperExtensionPlugin : public QQmlEngineExtensionPlugin +class FramelessHelperPlugin : public QQmlEngineExtensionPlugin { Q_OBJECT Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid) public: + explicit FramelessHelperPlugin(QObject *parent = nullptr) : QQmlEngineExtensionPlugin(parent) {} + ~FramelessHelperPlugin() override = default; + void initializeEngine(QQmlEngine *engine, const char *uri) override { Q_ASSERT(engine); @@ -112,13 +70,30 @@ public: if (!engine || !uri) { return; } + Q_ASSERT(qstrcmp(uri, FRAMELESSHELPER_QUICK_URI) == 0); if (qstrcmp(uri, FRAMELESSHELPER_QUICK_URI) != 0) { return; } - FramelessHelper::Quick::registerTypes(engine); + engine->addImageProvider(FRAMELESSHELPER_STRING_LITERAL("framelesshelper"), new FramelessHelperImageProvider); + qmlRegisterModule(QUICK_URI_FULL); + qmlRegisterUncreatableMetaObject(Global::staticMetaObject, QUICK_URI_EXPAND("FramelessHelper"), + FRAMELESSHELPER_STRING_LITERAL("The FramelessHelper namespace is not creatable, you can only use it to access its enums.")); + qmlRegisterSingletonType(QUICK_URI_EXPAND("FramelessUtils"), + [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { + Q_UNUSED(engine); + Q_UNUSED(scriptEngine); + return new FramelessQuickUtils; + }); + qmlRegisterAnonymousType2(QWindow, QUICK_URI_SHORT); + qmlRegisterAnonymousType2(QQuickWindow, QUICK_URI_SHORT); + qmlRegisterType(QUICK_URI_EXPAND("FramelessWindow")); + qmlRegisterType(QUICK_URI_EXPAND("StandardMinimizeButton")); + qmlRegisterType(QUICK_URI_EXPAND("StandardMaximizeButton")); + qmlRegisterType(QUICK_URI_EXPAND("StandardCloseButton")); + qmlRegisterType(QUICK_URI_EXPAND("StandardTitleBar")); } }; FRAMELESSHELPER_END_NAMESPACE -#include "framelessquickhelper.moc" +#include "plugin.moc" diff --git a/src/quick/qml/StandardMaximizeButton.qml b/src/quick/qml/StandardMaximizeButton.qml deleted file mode 100644 index 9eae9b2..0000000 --- a/src/quick/qml/StandardMaximizeButton.qml +++ /dev/null @@ -1,59 +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. - */ - -import QtQuick 2.0 -import QtQuick.Controls 2.0 -import org.wangwenx190.FramelessHelper 1.0 - -Button { - property bool maximized: false - - id: button - objectName: "MaximizeButtonObject" - implicitWidth: FramelessUtils.defaultSystemButtonSize.width - implicitHeight: FramelessUtils.defaultSystemButtonSize.height - contentItem: Item { - implicitWidth: FramelessUtils.defaultSystemButtonIconSize.width - implicitHeight: FramelessUtils.defaultSystemButtonIconSize.height - - Image { - anchors.centerIn: parent - source: button.maximized ? - ((FramelessUtils.darkModeEnabled || FramelessUtils.titleBarColorized) - ? "image://framelesshelper/dark/restore" : "image://framelesshelper/light/restore") : - ((FramelessUtils.darkModeEnabled || FramelessUtils.titleBarColorized) - ? "image://framelesshelper/dark/maximize" : "image://framelesshelper/light/maximize") - } - } - background: Rectangle { - visible: button.hovered || button.pressed - color: FramelessUtils.getSystemButtonBackgroundColor(FramelessHelper.Maximize, (button.pressed ? FramelessHelper.Pressed : FramelessHelper.Hovered)) - } - - ToolTip { - visible: button.hovered && !button.pressed - delay: Qt.styleHints.mousePressAndHoldInterval - text: button.maximized ? qsTr("Restore") : qsTr("Maximize") - } -} diff --git a/src/quick/qml/StandardTitleBar.qml b/src/quick/qml/StandardTitleBar.qml deleted file mode 100644 index 815a2e1..0000000 --- a/src/quick/qml/StandardTitleBar.qml +++ /dev/null @@ -1,74 +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. - */ - -import QtQuick 2.0 -import QtQuick.Controls 2.0 -import org.wangwenx190.FramelessHelper 1.0 - -Rectangle { - property bool active: true - property bool maximized: false - property alias title: windowTitleLabel.text - property alias minimizeButton: minimizeButton - property alias maximizeButton: maximizeButton - property alias closeButton: closeButton - - id: titleBar - height: FramelessUtils.titleBarHeight - color: titleBar.active ? (FramelessUtils.titleBarColorized ? FramelessUtils.systemAccentColor - : (FramelessUtils.darkModeEnabled ? "black" : "white")) - : (FramelessUtils.darkModeEnabled ? FramelessUtils.defaultSystemDarkColor : "white") - - Text { - id: windowTitleLabel - font.pointSize: 11 - color: titleBar.active ? ((FramelessUtils.darkModeEnabled - || FramelessUtils.titleBarColorized) ? "white" : "black") : "darkGray" - anchors { - left: parent.left - leftMargin: 10 - verticalCenter: parent.verticalCenter - } - } - - Row { - anchors { - top: parent.top - right: parent.right - } - - StandardMinimizeButton { - id: minimizeButton - } - - StandardMaximizeButton { - id: maximizeButton - maximized: titleBar.maximized - } - - StandardCloseButton { - id: closeButton - } - } -} diff --git a/src/quick/quickstandardclosebutton.cpp b/src/quick/quickstandardclosebutton.cpp new file mode 100644 index 0000000..e46526c --- /dev/null +++ b/src/quick/quickstandardclosebutton.cpp @@ -0,0 +1,87 @@ +/* + * 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" +#include "framelessquickutils.h" +#include +#include +#include + +FRAMELESSHELPER_BEGIN_NAMESPACE + +using namespace Global; + +FRAMELESSHELPER_STRING_CONSTANT2(DarkUrl, "image://framelesshelper/dark/close") +FRAMELESSHELPER_STRING_CONSTANT2(LightUrl, "image://framelesshelper/light/close") + +QuickStandardCloseButton::QuickStandardCloseButton(QQuickItem *parent) : QQuickButton(parent) +{ + initialize(); +} + +QuickStandardCloseButton::~QuickStandardCloseButton() = default; + +void QuickStandardCloseButton::updateForeground() +{ + const bool dark = (FramelessQuickUtils::darkModeEnabled() || FramelessQuickUtils::titleBarColorized()); + const auto url = QUrl(dark ? kDarkUrl : kLightUrl); + m_image->setSource(url); +} + +void QuickStandardCloseButton::updateBackground() +{ + static constexpr const auto button = SystemButtonType::Close; + const ButtonState state = (isPressed() ? ButtonState::Pressed : ButtonState::Hovered); + const bool visible = (isHovered() || isPressed()); + m_backgroundItem->setColor(FramelessQuickUtils::getSystemButtonBackgroundColor(button, state)); + m_backgroundItem->setVisible(visible); +} + +void QuickStandardCloseButton::initialize() +{ + m_contentItem.reset(new QQuickItem(this)); + m_contentItem->setImplicitWidth(kDefaultSystemButtonSize.width()); + m_contentItem->setImplicitHeight(kDefaultSystemButtonSize.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()); + const FramelessQuickUtils * const utils = FramelessQuickUtils::instance(); + connect(utils, &FramelessQuickUtils::darkModeEnabledChanged, this, &QuickStandardCloseButton::updateForeground); + connect(utils, &FramelessQuickUtils::titleBarColorizedChanged, 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 diff --git a/src/quick/framelessquickhelper.h b/src/quick/quickstandardclosebutton_p.h similarity index 59% rename from src/quick/framelessquickhelper.h rename to src/quick/quickstandardclosebutton_p.h index 4f4e9b3..c7a97df 100644 --- a/src/quick/framelessquickhelper.h +++ b/src/quick/quickstandardclosebutton_p.h @@ -22,4 +22,38 @@ * SOFTWARE. */ -#include "../../include/FramelessHelper/Quick/framelessquickhelper.h" +#pragma once + +#include +#include "framelesshelperquick_global.h" + +QT_BEGIN_NAMESPACE +class QQuickImage; +class QQuickRectangle; +QT_END_NAMESPACE + +FRAMELESSHELPER_BEGIN_NAMESPACE + +class FRAMELESSHELPER_QUICK_API QuickStandardCloseButton : public QQuickButton +{ + Q_OBJECT + Q_DISABLE_COPY_MOVE(QuickStandardCloseButton) + +public: + explicit QuickStandardCloseButton(QQuickItem *parent = nullptr); + ~QuickStandardCloseButton() override; + +public Q_SLOTS: + void updateForeground(); + void updateBackground(); + +private: + void initialize(); + +private: + QScopedPointer m_contentItem; + QScopedPointer m_image; + QScopedPointer m_backgroundItem; +}; + +FRAMELESSHELPER_END_NAMESPACE diff --git a/src/quick/quickstandardmaximizebutton.cpp b/src/quick/quickstandardmaximizebutton.cpp new file mode 100644 index 0000000..c6c0871 --- /dev/null +++ b/src/quick/quickstandardmaximizebutton.cpp @@ -0,0 +1,104 @@ +/* + * 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" +#include "framelessquickutils.h" +#include +#include +#include + +FRAMELESSHELPER_BEGIN_NAMESPACE + +using namespace Global; + +FRAMELESSHELPER_STRING_CONSTANT2(DarkMaxUrl, "image://framelesshelper/dark/maximize") +FRAMELESSHELPER_STRING_CONSTANT2(LightMaxUrl, "image://framelesshelper/light/maximize") +FRAMELESSHELPER_STRING_CONSTANT2(DarkRestoreUrl, "image://framelesshelper/dark/restore") +FRAMELESSHELPER_STRING_CONSTANT2(LightRestoreUrl, "image://framelesshelper/light/restore") + +QuickStandardMaximizeButton::QuickStandardMaximizeButton(QQuickItem *parent) : QQuickButton(parent) +{ + initialize(); +} + +QuickStandardMaximizeButton::~QuickStandardMaximizeButton() = default; + +bool QuickStandardMaximizeButton::maximized() 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 = (FramelessQuickUtils::darkModeEnabled() || FramelessQuickUtils::titleBarColorized()); + const auto url = QUrl(dark ? (m_max ? kDarkMaxUrl : kDarkRestoreUrl) : (m_max ? kLightMaxUrl : kLightRestoreUrl)); + m_image->setSource(url); +} + +void QuickStandardMaximizeButton::updateBackground() +{ + const SystemButtonType button = (m_max ? SystemButtonType::Maximize : SystemButtonType::Restore); + const ButtonState state = (isPressed() ? ButtonState::Pressed : ButtonState::Hovered); + const bool visible = (isHovered() || isPressed()); + m_backgroundItem->setColor(FramelessQuickUtils::getSystemButtonBackgroundColor(button, state)); + m_backgroundItem->setVisible(visible); +} + +void QuickStandardMaximizeButton::initialize() +{ + m_contentItem.reset(new QQuickItem(this)); + m_contentItem->setImplicitWidth(kDefaultSystemButtonSize.width()); + m_contentItem->setImplicitHeight(kDefaultSystemButtonSize.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()); + const FramelessQuickUtils * const utils = FramelessQuickUtils::instance(); + connect(utils, &FramelessQuickUtils::darkModeEnabledChanged, this, &QuickStandardMaximizeButton::updateForeground); + connect(utils, &FramelessQuickUtils::titleBarColorizedChanged, 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 diff --git a/src/quick/qml/StandardMinimizeButton.qml b/src/quick/quickstandardmaximizebutton_p.h similarity index 50% rename from src/quick/qml/StandardMinimizeButton.qml rename to src/quick/quickstandardmaximizebutton_p.h index 89bf9a3..e661d70 100644 --- a/src/quick/qml/StandardMinimizeButton.qml +++ b/src/quick/quickstandardmaximizebutton_p.h @@ -22,33 +22,46 @@ * SOFTWARE. */ -import QtQuick 2.0 -import QtQuick.Controls 2.0 -import org.wangwenx190.FramelessHelper 1.0 +#pragma once -Button { - id: button - objectName: "MinimizeButtonObject" - implicitWidth: FramelessUtils.defaultSystemButtonSize.width - implicitHeight: FramelessUtils.defaultSystemButtonSize.height - contentItem: Item { - implicitWidth: FramelessUtils.defaultSystemButtonIconSize.width - implicitHeight: FramelessUtils.defaultSystemButtonIconSize.height +#include +#include "framelesshelperquick_global.h" - Image { - anchors.centerIn: parent - source: (FramelessUtils.darkModeEnabled || FramelessUtils.titleBarColorized) - ? "image://framelesshelper/dark/minimize" : "image://framelesshelper/light/minimize" - } - } - background: Rectangle { - visible: button.hovered || button.pressed - color: FramelessUtils.getSystemButtonBackgroundColor(FramelessHelper.Minimize, (button.pressed ? FramelessHelper.Pressed : FramelessHelper.Hovered)) - } +QT_BEGIN_NAMESPACE +class QQuickImage; +class QQuickRectangle; +QT_END_NAMESPACE - ToolTip { - visible: button.hovered && !button.pressed - delay: Qt.styleHints.mousePressAndHoldInterval - text: qsTr("Minimize") - } -} +FRAMELESSHELPER_BEGIN_NAMESPACE + +class FRAMELESSHELPER_QUICK_API QuickStandardMaximizeButton : public QQuickButton +{ + Q_OBJECT + Q_DISABLE_COPY_MOVE(QuickStandardMaximizeButton) + Q_PROPERTY(bool maximized READ maximized WRITE setMaximized NOTIFY maximizedChanged FINAL) + +public: + explicit QuickStandardMaximizeButton(QQuickItem *parent = nullptr); + ~QuickStandardMaximizeButton() override; + + Q_NODISCARD bool maximized() const; + void setMaximized(const bool max); + +public Q_SLOTS: + void updateForeground(); + void updateBackground(); + +Q_SIGNALS: + void maximizedChanged(); + +private: + void initialize(); + +private: + bool m_max = false; + QScopedPointer m_contentItem; + QScopedPointer m_image; + QScopedPointer m_backgroundItem; +}; + +FRAMELESSHELPER_END_NAMESPACE diff --git a/src/quick/quickstandardminimizebutton.cpp b/src/quick/quickstandardminimizebutton.cpp new file mode 100644 index 0000000..e781531 --- /dev/null +++ b/src/quick/quickstandardminimizebutton.cpp @@ -0,0 +1,87 @@ +/* + * 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" +#include "framelessquickutils.h" +#include +#include +#include + +FRAMELESSHELPER_BEGIN_NAMESPACE + +using namespace Global; + +FRAMELESSHELPER_STRING_CONSTANT2(DarkUrl, "image://framelesshelper/dark/minimize") +FRAMELESSHELPER_STRING_CONSTANT2(LightUrl, "image://framelesshelper/light/minimize") + +QuickStandardMinimizeButton::QuickStandardMinimizeButton(QQuickItem *parent) : QQuickButton(parent) +{ + initialize(); +} + +QuickStandardMinimizeButton::~QuickStandardMinimizeButton() = default; + +void QuickStandardMinimizeButton::updateForeground() +{ + const bool dark = (FramelessQuickUtils::darkModeEnabled() || FramelessQuickUtils::titleBarColorized()); + const auto url = QUrl(dark ? kDarkUrl : kLightUrl); + m_image->setSource(url); +} + +void QuickStandardMinimizeButton::updateBackground() +{ + static constexpr const auto button = SystemButtonType::Minimize; + const ButtonState state = (isPressed() ? ButtonState::Pressed : ButtonState::Hovered); + const bool visible = (isHovered() || isPressed()); + m_backgroundItem->setColor(FramelessQuickUtils::getSystemButtonBackgroundColor(button, state)); + m_backgroundItem->setVisible(visible); +} + +void QuickStandardMinimizeButton::initialize() +{ + m_contentItem.reset(new QQuickItem(this)); + m_contentItem->setImplicitWidth(kDefaultSystemButtonSize.width()); + m_contentItem->setImplicitHeight(kDefaultSystemButtonSize.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()); + const FramelessQuickUtils * const utils = FramelessQuickUtils::instance(); + connect(utils, &FramelessQuickUtils::darkModeEnabledChanged, this, &QuickStandardMinimizeButton::updateForeground); + connect(utils, &FramelessQuickUtils::titleBarColorizedChanged, 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 diff --git a/src/quick/qml/StandardCloseButton.qml b/src/quick/quickstandardminimizebutton_p.h similarity index 50% rename from src/quick/qml/StandardCloseButton.qml rename to src/quick/quickstandardminimizebutton_p.h index b2b3dc2..5a32b60 100644 --- a/src/quick/qml/StandardCloseButton.qml +++ b/src/quick/quickstandardminimizebutton_p.h @@ -22,33 +22,38 @@ * SOFTWARE. */ -import QtQuick 2.0 -import QtQuick.Controls 2.0 -import org.wangwenx190.FramelessHelper 1.0 +#pragma once -Button { - id: button - objectName: "CloseButtonObject" - implicitWidth: FramelessUtils.defaultSystemButtonSize.width - implicitHeight: FramelessUtils.defaultSystemButtonSize.height - contentItem: Item { - implicitWidth: FramelessUtils.defaultSystemButtonIconSize.width - implicitHeight: FramelessUtils.defaultSystemButtonIconSize.height +#include +#include "framelesshelperquick_global.h" - Image { - anchors.centerIn: parent - source: (button.hovered || FramelessUtils.darkModeEnabled || FramelessUtils.titleBarColorized) - ? "image://framelesshelper/dark/close" : "image://framelesshelper/light/close" - } - } - background: Rectangle { - visible: button.hovered || button.pressed - color: FramelessUtils.getSystemButtonBackgroundColor(FramelessHelper.Close, (button.pressed ? FramelessHelper.Pressed : FramelessHelper.Hovered)) - } +QT_BEGIN_NAMESPACE +class QQuickImage; +class QQuickRectangle; +QT_END_NAMESPACE - ToolTip { - visible: button.hovered && !button.pressed - delay: Qt.styleHints.mousePressAndHoldInterval - text: qsTr("Close") - } -} +FRAMELESSHELPER_BEGIN_NAMESPACE + +class FRAMELESSHELPER_QUICK_API QuickStandardMinimizeButton : public QQuickButton +{ + Q_OBJECT + Q_DISABLE_COPY_MOVE(QuickStandardMinimizeButton) + +public: + explicit QuickStandardMinimizeButton(QQuickItem *parent = nullptr); + ~QuickStandardMinimizeButton() override; + +public Q_SLOTS: + void updateForeground(); + void updateBackground(); + +private: + void initialize(); + +private: + QScopedPointer m_contentItem; + QScopedPointer m_image; + QScopedPointer m_backgroundItem; +}; + +FRAMELESSHELPER_END_NAMESPACE diff --git a/include/FramelessHelper/Quick/framelessquickhelper.h b/src/quick/quickstandardtitlebar.cpp similarity index 83% rename from include/FramelessHelper/Quick/framelessquickhelper.h rename to src/quick/quickstandardtitlebar.cpp index 9b7bf2a..f6ec16f 100644 --- a/include/FramelessHelper/Quick/framelessquickhelper.h +++ b/src/quick/quickstandardtitlebar.cpp @@ -22,20 +22,19 @@ * SOFTWARE. */ -#pragma once - -#include "framelesshelperquick_global.h" - -QT_BEGIN_NAMESPACE -class QQmlEngine; -QT_END_NAMESPACE +#include "quickstandardtitlebar_p.h" FRAMELESSHELPER_BEGIN_NAMESPACE -namespace FramelessHelper::Quick +QuickStandardTitleBar::QuickStandardTitleBar(QQuickItem *parent) : QQuickRectangle(parent) { + initialize(); +} -FRAMELESSHELPER_QUICK_API void registerTypes(QQmlEngine *engine); +QuickStandardTitleBar::~QuickStandardTitleBar() = default; + +void QuickStandardTitleBar::initialize() +{ } diff --git a/src/quick/quickstandardtitlebar_p.h b/src/quick/quickstandardtitlebar_p.h new file mode 100644 index 0000000..dacde4d --- /dev/null +++ b/src/quick/quickstandardtitlebar_p.h @@ -0,0 +1,59 @@ +/* + * 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 +#include "framelesshelperquick_global.h" + +QT_BEGIN_NAMESPACE +class QQuickLabel; +QT_END_NAMESPACE + +FRAMELESSHELPER_BEGIN_NAMESPACE + +class QuickStandardMinimizeButton; +class QuickStandardMaximizeButton; +class QuickStandardCloseButton; + +class QuickStandardTitleBar : public QQuickRectangle +{ + Q_OBJECT + Q_DISABLE_COPY_MOVE(QuickStandardTitleBar) + +public: + explicit QuickStandardTitleBar(QQuickItem *parent = nullptr); + ~QuickStandardTitleBar() override; + +private: + void initialize(); + +private: + QScopedPointer m_label; + QScopedPointer m_minBtn; + QScopedPointer m_maxBtn; + QScopedPointer m_closeBtn; +}; + +FRAMELESSHELPER_END_NAMESPACE diff --git a/src/widgets/standardsystembutton.cpp b/src/widgets/standardsystembutton.cpp index 2cec533..92a7e94 100644 --- a/src/widgets/standardsystembutton.cpp +++ b/src/widgets/standardsystembutton.cpp @@ -49,6 +49,24 @@ StandardSystemButtonPrivate::StandardSystemButtonPrivate(StandardSystemButton *q StandardSystemButtonPrivate::~StandardSystemButtonPrivate() = default; +StandardSystemButtonPrivate *StandardSystemButtonPrivate::get(StandardSystemButton *pub) +{ + Q_ASSERT(pub); + if (!pub) { + return nullptr; + } + return pub->d_func(); +} + +const StandardSystemButtonPrivate *StandardSystemButtonPrivate::get(const StandardSystemButton *pub) +{ + Q_ASSERT(pub); + if (!pub) { + return nullptr; + } + return pub->d_func(); +} + void StandardSystemButtonPrivate::refreshButtonTheme(const bool force) { if (m_buttonType == SystemButtonType::Unknown) { diff --git a/src/widgets/standardsystembutton_p.h b/src/widgets/standardsystembutton_p.h index f58a874..2680aec 100644 --- a/src/widgets/standardsystembutton_p.h +++ b/src/widgets/standardsystembutton_p.h @@ -47,6 +47,9 @@ public: explicit StandardSystemButtonPrivate(StandardSystemButton *q); ~StandardSystemButtonPrivate() override; + Q_NODISCARD static StandardSystemButtonPrivate *get(StandardSystemButton *pub); + Q_NODISCARD static const StandardSystemButtonPrivate *get(const StandardSystemButton *pub); + void refreshButtonTheme(const bool force); Q_NODISCARD Global::SystemButtonType getButtonType() const;