wip: quick: start migrating to modern usage

Still wip, but doesn't left much.

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2022-04-14 17:33:09 +08:00
parent d353c81c5e
commit 4f5044a58c
24 changed files with 602 additions and 305 deletions

View File

@ -25,22 +25,28 @@
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS QuickControls2) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS QuickControls2)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS QuickControls2) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS QuickControls2)
set(SOURCES qt_add_executable(Quick main.cpp)
qml.qrc
main.cpp qt_add_qml_module(Quick
URI Demo
VERSION 1.0
DEPENDENCIES
org.wangwenx190.FramelessHelper
QML_FILES
MainWindow.qml
) )
if(WIN32) if(WIN32)
enable_language(RC) enable_language(RC)
list(APPEND SOURCES ../example.rc ../example.manifest) target_sources(Quick PRIVATE
../example.rc ../example.manifest
)
endif() endif()
add_executable(Quick WIN32 ${SOURCES})
target_link_libraries(Quick PRIVATE target_link_libraries(Quick PRIVATE
Qt${QT_VERSION_MAJOR}::Quick Qt${QT_VERSION_MAJOR}::Quick
Qt${QT_VERSION_MAJOR}::QuickControls2 Qt${QT_VERSION_MAJOR}::QuickControls2
FramelessHelperQuick FramelessHelperCore
) )
target_compile_definitions(Quick PRIVATE target_compile_definitions(Quick PRIVATE
@ -51,4 +57,13 @@ target_compile_definitions(Quick PRIVATE
QT_DEPRECATED_WARNINGS QT_DEPRECATED_WARNINGS
QT_DISABLE_DEPRECATED_BEFORE=0x060400 QT_DISABLE_DEPRECATED_BEFORE=0x060400
$<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG> $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>: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
) )

View File

@ -26,7 +26,7 @@
#include <QtQml/qqmlapplicationengine.h> #include <QtQml/qqmlapplicationengine.h>
#include <QtQuick/qquickwindow.h> #include <QtQuick/qquickwindow.h>
#include <QtQuickControls2/qquickstyle.h> #include <QtQuickControls2/qquickstyle.h>
#include <FramelessQuickHelper> #include <framelesshelpercore_global.h>
FRAMELESSHELPER_USE_NAMESPACE FRAMELESSHELPER_USE_NAMESPACE
@ -54,6 +54,7 @@ int main(int argc, char *argv[])
} }
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
engine.addImportPath(QUtf8String(DEMO_IMPORT_DIR));
// This line is not relevant to FramelessHelper, we change the default // This line is not relevant to FramelessHelper, we change the default
// Qt Quick Controls theme to "Basic" (Qt6) or "Default" (Qt5) just // 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")); QQuickStyle::setStyle(FRAMELESSHELPER_STRING_LITERAL("Default"));
#endif #endif
// VERY IMPORTANT! Don't forget to register the QML types! const QUrl homepageUrl(FRAMELESSHELPER_STRING_LITERAL("qrc:///Demo/MainWindow.qml"));
FramelessHelper::Quick::registerTypes(&engine);
const QUrl homepageUrl(FRAMELESSHELPER_STRING_LITERAL("qrc:///qml/MainWindow.qml"));
const QMetaObject::Connection connection = QObject::connect( const QMetaObject::Connection connection = QObject::connect(
&engine, &QQmlApplicationEngine::objectCreated, &application, &engine, &QQmlApplicationEngine::objectCreated, &application,
[&homepageUrl, &connection](QObject *object, const QUrl &url) { [&homepageUrl, &connection](QObject *object, const QUrl &url) {

View File

@ -1,5 +0,0 @@
<RCC>
<qresource prefix="/">
<file>qml/MainWindow.qml</file>
</qresource>
</RCC>

View File

@ -1 +0,0 @@
#include <framelessquickhelper.h>

View File

@ -61,6 +61,8 @@ public:
explicit FramelessQuickUtils(QObject *parent = nullptr); explicit FramelessQuickUtils(QObject *parent = nullptr);
~FramelessQuickUtils() override; ~FramelessQuickUtils() override;
Q_NODISCARD static FramelessQuickUtils *instance();
Q_NODISCARD static qreal titleBarHeight(); Q_NODISCARD static qreal titleBarHeight();
Q_NODISCARD static bool frameBorderVisible(); Q_NODISCARD static bool frameBorderVisible();
Q_NODISCARD static qreal frameBorderThickness(); Q_NODISCARD static qreal frameBorderThickness();

View File

@ -22,47 +22,63 @@
SOFTWARE. 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(INCLUDE_PREFIX ../../include/FramelessHelper/Quick)
set(SOURCES find_package(Qt6 REQUIRED COMPONENTS QuickTemplates2)
${INCLUDE_PREFIX}/framelesshelperquick_global.h
${INCLUDE_PREFIX}/framelessquickutils.h qt_add_qml_module(${PROJ_TARGET}
${INCLUDE_PREFIX}/framelesshelperimageprovider.h URI ${PROJ_URI}
${INCLUDE_PREFIX}/framelessquickhelper.h VERSION ${PROJ_VERSION}
${INCLUDE_PREFIX}/framelessquickwindow.h PLUGIN_TARGET ${PROJ_TARGET}
framelessquickwindow_p.h CLASS_NAME ${PROJ_CLASS}
framelesshelperquick.qrc OUTPUT_DIRECTORY ${PROJ_IMPORTS_DIR}
framelessquickhelper.cpp NO_PLUGIN_OPTIONAL
framelessquickutils.cpp NO_GENERATE_PLUGIN_SOURCE
framelesshelperimageprovider.cpp SOURCES
framelessquickwindow.cpp ${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) if(WIN32 AND NOT FRAMELESSHELPER_BUILD_STATIC)
enable_language(RC) enable_language(RC)
list(APPEND SOURCES framelesshelperquick.rc) target_sources(${PROJ_TARGET} PRIVATE
framelesshelperquick.rc
)
endif() endif()
if(FRAMELESSHELPER_BUILD_STATIC) if(FRAMELESSHELPER_BUILD_STATIC)
add_library(${SUB_PROJ_NAME} STATIC ${SOURCES}) target_compile_definitions(${PROJ_TARGET} PUBLIC
else()
add_library(${SUB_PROJ_NAME} SHARED ${SOURCES})
endif()
if(FRAMELESSHELPER_BUILD_STATIC)
target_compile_definitions(${SUB_PROJ_NAME} PUBLIC
FRAMELESSHELPER_QUICK_STATIC FRAMELESSHELPER_QUICK_STATIC
) )
endif() endif()
target_compile_definitions(${SUB_PROJ_NAME} PRIVATE target_compile_definitions(${PROJ_TARGET} PRIVATE
QT_NO_CAST_FROM_ASCII QT_NO_CAST_FROM_ASCII
QT_NO_CAST_TO_ASCII QT_NO_CAST_TO_ASCII
QT_NO_URL_CAST_FROM_STRING QT_NO_URL_CAST_FROM_STRING
QT_NO_CAST_FROM_BYTEARRAY QT_NO_CAST_FROM_BYTEARRAY
QT_NO_KEYWORDS #QT_NO_KEYWORDS
QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
QT_NO_FOREACH QT_NO_FOREACH
QT_USE_QSTRINGBUILDER QT_USE_QSTRINGBUILDER
@ -74,30 +90,31 @@ target_compile_definitions(${SUB_PROJ_NAME} PRIVATE
if(MSVC) if(MSVC)
set(_WIN32_WINNT_WIN10 0x0A00) set(_WIN32_WINNT_WIN10 0x0A00)
set(NTDDI_WIN10_CO 0x0A00000B) 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 _CRT_NON_CONFORMING_SWPRINTFS _CRT_SECURE_NO_WARNINGS
_ENABLE_EXTENDED_ALIGNED_STORAGE NOMINMAX UNICODE _ENABLE_EXTENDED_ALIGNED_STORAGE NOMINMAX UNICODE
_UNICODE WIN32_LEAN_AND_MEAN WINRT_LEAN_AND_MEAN _UNICODE WIN32_LEAN_AND_MEAN WINRT_LEAN_AND_MEAN
WINVER=${_WIN32_WINNT_WIN10} _WIN32_WINNT=${_WIN32_WINNT_WIN10} WINVER=${_WIN32_WINNT_WIN10} _WIN32_WINNT=${_WIN32_WINNT_WIN10}
_WIN32_IE=${_WIN32_WINNT_WIN10} NTDDI_VERSION=${NTDDI_WIN10_CO} _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 /utf-8 /W4 /WX
) )
else() else()
target_compile_options(${SUB_PROJ_NAME} PRIVATE target_compile_options(${PROJ_TARGET} PRIVATE
-Wall -Wextra -Werror -Wall -Wextra -Werror
) )
endif() endif()
target_link_libraries(${SUB_PROJ_NAME} PRIVATE target_link_libraries(${PROJ_TARGET} PRIVATE
Qt${QT_VERSION_MAJOR}::QuickPrivate Qt${QT_VERSION_MAJOR}::QuickPrivate
Qt${QT_VERSION_MAJOR}::QuickTemplates2Private
) )
target_link_libraries(${SUB_PROJ_NAME} PUBLIC target_link_libraries(${PROJ_TARGET} PUBLIC
FramelessHelperCore FramelessHelperCore
) )
target_include_directories(${SUB_PROJ_NAME} PUBLIC target_include_directories(${PROJ_TARGET} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/${INCLUDE_PREFIX}" "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/${INCLUDE_PREFIX}"
) )

View File

@ -1,8 +0,0 @@
<RCC>
<qresource prefix="/org.wangwenx190.FramelessHelper">
<file>qml/StandardCloseButton.qml</file>
<file>qml/StandardMaximizeButton.qml</file>
<file>qml/StandardMinimizeButton.qml</file>
<file>qml/StandardTitleBar.qml</file>
</qresource>
</RCC>

View File

@ -34,6 +34,8 @@ FRAMELESSHELPER_BEGIN_NAMESPACE
using namespace Global; using namespace Global;
Q_GLOBAL_STATIC(FramelessQuickUtils, g_quickUtils)
FramelessQuickUtils::FramelessQuickUtils(QObject *parent) : QObject(parent) FramelessQuickUtils::FramelessQuickUtils(QObject *parent) : QObject(parent)
{ {
connect(FramelessWindowsManager::instance(), &FramelessWindowsManager::systemThemeChanged, this, [this](){ connect(FramelessWindowsManager::instance(), &FramelessWindowsManager::systemThemeChanged, this, [this](){
@ -45,6 +47,11 @@ FramelessQuickUtils::FramelessQuickUtils(QObject *parent) : QObject(parent)
FramelessQuickUtils::~FramelessQuickUtils() = default; FramelessQuickUtils::~FramelessQuickUtils() = default;
FramelessQuickUtils *FramelessQuickUtils::instance()
{
return g_quickUtils();
}
qreal FramelessQuickUtils::titleBarHeight() qreal FramelessQuickUtils::titleBarHeight()
{ {
return 30.0; return 30.0;

View File

@ -49,6 +49,24 @@ FramelessQuickWindowPrivate::FramelessQuickWindowPrivate(FramelessQuickWindow *q
FramelessQuickWindowPrivate::~FramelessQuickWindowPrivate() = default; 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 bool FramelessQuickWindowPrivate::isHidden() const
{ {
Q_Q(const FramelessQuickWindow); Q_Q(const FramelessQuickWindow);

View File

@ -47,6 +47,9 @@ public:
explicit FramelessQuickWindowPrivate(FramelessQuickWindow *q, const Global::UserSettings &settings = {}); explicit FramelessQuickWindowPrivate(FramelessQuickWindow *q, const Global::UserSettings &settings = {});
~FramelessQuickWindowPrivate() override; ~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 isHidden() const;
Q_INVOKABLE Q_NODISCARD bool isNormal() const; Q_INVOKABLE Q_NODISCARD bool isNormal() const;
Q_INVOKABLE Q_NODISCARD bool isMinimized() const; Q_INVOKABLE Q_NODISCARD bool isMinimized() const;

View File

@ -22,17 +22,15 @@
* SOFTWARE. * SOFTWARE.
*/ */
#include "framelessquickhelper.h" #include "framelesshelperquick_global.h"
#include <QtQml/qqmlextensionplugin.h> #include <QtQml/qqmlextensionplugin.h>
#include "framelesshelperimageprovider.h" #include "framelesshelperimageprovider.h"
#include "framelessquickutils.h" #include "framelessquickutils.h"
#include "framelessquickwindow.h" #include "framelessquickwindow.h"
#include "quickstandardminimizebutton_p.h"
#ifndef QML_URL_EXPAND #include "quickstandardmaximizebutton_p.h"
# define QML_URL_EXPAND(fileName) \ #include "quickstandardclosebutton_p.h"
QUrl(FRAMELESSHELPER_STRING_LITERAL("qrc:///org.wangwenx190.FramelessHelper/qml/%1.qml") \ #include "quickstandardtitlebar_p.h"
.arg(FRAMELESSHELPER_STRING_LITERAL(fileName)))
#endif
#ifndef QUICK_URI_SHORT #ifndef QUICK_URI_SHORT
# define QUICK_URI_SHORT FRAMELESSHELPER_QUICK_URI, 1 # define QUICK_URI_SHORT FRAMELESSHELPER_QUICK_URI, 1
@ -54,57 +52,17 @@
# endif # endif
#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 FRAMELESSHELPER_BEGIN_NAMESPACE
void FramelessHelper::Quick::registerTypes(QQmlEngine *engine) class FramelessHelperPlugin : public QQmlEngineExtensionPlugin
{
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<FramelessQuickUtils>(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<FramelessQuickWindow>(QUICK_URI_EXPAND("FramelessWindow"));
initResource();
qmlRegisterFile("StandardMinimizeButton");
qmlRegisterFile("StandardMaximizeButton");
qmlRegisterFile("StandardCloseButton");
qmlRegisterFile("StandardTitleBar");
}
class FRAMELESSHELPER_QUICK_API FramelessHelperExtensionPlugin : public QQmlEngineExtensionPlugin
{ {
Q_OBJECT Q_OBJECT
Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid) Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid)
public: public:
explicit FramelessHelperPlugin(QObject *parent = nullptr) : QQmlEngineExtensionPlugin(parent) {}
~FramelessHelperPlugin() override = default;
void initializeEngine(QQmlEngine *engine, const char *uri) override void initializeEngine(QQmlEngine *engine, const char *uri) override
{ {
Q_ASSERT(engine); Q_ASSERT(engine);
@ -112,13 +70,30 @@ public:
if (!engine || !uri) { if (!engine || !uri) {
return; return;
} }
Q_ASSERT(qstrcmp(uri, FRAMELESSHELPER_QUICK_URI) == 0);
if (qstrcmp(uri, FRAMELESSHELPER_QUICK_URI) != 0) { if (qstrcmp(uri, FRAMELESSHELPER_QUICK_URI) != 0) {
return; 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<FramelessQuickUtils>(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<FramelessQuickWindow>(QUICK_URI_EXPAND("FramelessWindow"));
qmlRegisterType<QuickStandardMinimizeButton>(QUICK_URI_EXPAND("StandardMinimizeButton"));
qmlRegisterType<QuickStandardMaximizeButton>(QUICK_URI_EXPAND("StandardMaximizeButton"));
qmlRegisterType<QuickStandardCloseButton>(QUICK_URI_EXPAND("StandardCloseButton"));
qmlRegisterType<QuickStandardTitleBar>(QUICK_URI_EXPAND("StandardTitleBar"));
} }
}; };
FRAMELESSHELPER_END_NAMESPACE FRAMELESSHELPER_END_NAMESPACE
#include "framelessquickhelper.moc" #include "plugin.moc"

View File

@ -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")
}
}

View File

@ -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
}
}
}

View File

@ -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 <QtQuick/private/qquickimage_p.h>
#include <QtQuick/private/qquickrectangle_p.h>
#include <QtQuick/private/qquickanchors_p.h>
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

View File

@ -22,4 +22,38 @@
* SOFTWARE. * SOFTWARE.
*/ */
#include "../../include/FramelessHelper/Quick/framelessquickhelper.h" #pragma once
#include <QtQuickTemplates2/private/qquickbutton_p.h>
#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<QQuickItem> m_contentItem;
QScopedPointer<QQuickImage> m_image;
QScopedPointer<QQuickRectangle> m_backgroundItem;
};
FRAMELESSHELPER_END_NAMESPACE

View File

@ -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 <QtQuick/private/qquickimage_p.h>
#include <QtQuick/private/qquickrectangle_p.h>
#include <QtQuick/private/qquickanchors_p.h>
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

View File

@ -22,33 +22,46 @@
* SOFTWARE. * SOFTWARE.
*/ */
import QtQuick 2.0 #pragma once
import QtQuick.Controls 2.0
import org.wangwenx190.FramelessHelper 1.0
Button { #include <QtQuickTemplates2/private/qquickbutton_p.h>
id: button #include "framelesshelperquick_global.h"
objectName: "MinimizeButtonObject"
implicitWidth: FramelessUtils.defaultSystemButtonSize.width
implicitHeight: FramelessUtils.defaultSystemButtonSize.height
contentItem: Item {
implicitWidth: FramelessUtils.defaultSystemButtonIconSize.width
implicitHeight: FramelessUtils.defaultSystemButtonIconSize.height
Image { QT_BEGIN_NAMESPACE
anchors.centerIn: parent class QQuickImage;
source: (FramelessUtils.darkModeEnabled || FramelessUtils.titleBarColorized) class QQuickRectangle;
? "image://framelesshelper/dark/minimize" : "image://framelesshelper/light/minimize" QT_END_NAMESPACE
}
}
background: Rectangle {
visible: button.hovered || button.pressed
color: FramelessUtils.getSystemButtonBackgroundColor(FramelessHelper.Minimize, (button.pressed ? FramelessHelper.Pressed : FramelessHelper.Hovered))
}
ToolTip { FRAMELESSHELPER_BEGIN_NAMESPACE
visible: button.hovered && !button.pressed
delay: Qt.styleHints.mousePressAndHoldInterval class FRAMELESSHELPER_QUICK_API QuickStandardMaximizeButton : public QQuickButton
text: qsTr("Minimize") {
} 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<QQuickItem> m_contentItem;
QScopedPointer<QQuickImage> m_image;
QScopedPointer<QQuickRectangle> m_backgroundItem;
};
FRAMELESSHELPER_END_NAMESPACE

View File

@ -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 <QtQuick/private/qquickimage_p.h>
#include <QtQuick/private/qquickrectangle_p.h>
#include <QtQuick/private/qquickanchors_p.h>
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

View File

@ -22,33 +22,38 @@
* SOFTWARE. * SOFTWARE.
*/ */
import QtQuick 2.0 #pragma once
import QtQuick.Controls 2.0
import org.wangwenx190.FramelessHelper 1.0
Button { #include <QtQuickTemplates2/private/qquickbutton_p.h>
id: button #include "framelesshelperquick_global.h"
objectName: "CloseButtonObject"
implicitWidth: FramelessUtils.defaultSystemButtonSize.width
implicitHeight: FramelessUtils.defaultSystemButtonSize.height
contentItem: Item {
implicitWidth: FramelessUtils.defaultSystemButtonIconSize.width
implicitHeight: FramelessUtils.defaultSystemButtonIconSize.height
Image { QT_BEGIN_NAMESPACE
anchors.centerIn: parent class QQuickImage;
source: (button.hovered || FramelessUtils.darkModeEnabled || FramelessUtils.titleBarColorized) class QQuickRectangle;
? "image://framelesshelper/dark/close" : "image://framelesshelper/light/close" QT_END_NAMESPACE
}
}
background: Rectangle {
visible: button.hovered || button.pressed
color: FramelessUtils.getSystemButtonBackgroundColor(FramelessHelper.Close, (button.pressed ? FramelessHelper.Pressed : FramelessHelper.Hovered))
}
ToolTip { FRAMELESSHELPER_BEGIN_NAMESPACE
visible: button.hovered && !button.pressed
delay: Qt.styleHints.mousePressAndHoldInterval class FRAMELESSHELPER_QUICK_API QuickStandardMinimizeButton : public QQuickButton
text: qsTr("Close") {
} 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<QQuickItem> m_contentItem;
QScopedPointer<QQuickImage> m_image;
QScopedPointer<QQuickRectangle> m_backgroundItem;
};
FRAMELESSHELPER_END_NAMESPACE

View File

@ -22,20 +22,19 @@
* SOFTWARE. * SOFTWARE.
*/ */
#pragma once #include "quickstandardtitlebar_p.h"
#include "framelesshelperquick_global.h"
QT_BEGIN_NAMESPACE
class QQmlEngine;
QT_END_NAMESPACE
FRAMELESSHELPER_BEGIN_NAMESPACE 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()
{
} }

View File

@ -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 <QtQuick/private/qquickrectangle_p.h>
#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<QQuickLabel> m_label;
QScopedPointer<QuickStandardMinimizeButton> m_minBtn;
QScopedPointer<QuickStandardMaximizeButton> m_maxBtn;
QScopedPointer<QuickStandardCloseButton> m_closeBtn;
};
FRAMELESSHELPER_END_NAMESPACE

View File

@ -49,6 +49,24 @@ StandardSystemButtonPrivate::StandardSystemButtonPrivate(StandardSystemButton *q
StandardSystemButtonPrivate::~StandardSystemButtonPrivate() = default; 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) void StandardSystemButtonPrivate::refreshButtonTheme(const bool force)
{ {
if (m_buttonType == SystemButtonType::Unknown) { if (m_buttonType == SystemButtonType::Unknown) {

View File

@ -47,6 +47,9 @@ public:
explicit StandardSystemButtonPrivate(StandardSystemButton *q); explicit StandardSystemButtonPrivate(StandardSystemButton *q);
~StandardSystemButtonPrivate() override; ~StandardSystemButtonPrivate() override;
Q_NODISCARD static StandardSystemButtonPrivate *get(StandardSystemButton *pub);
Q_NODISCARD static const StandardSystemButtonPrivate *get(const StandardSystemButton *pub);
void refreshButtonTheme(const bool force); void refreshButtonTheme(const bool force);
Q_NODISCARD Global::SystemButtonType getButtonType() const; Q_NODISCARD Global::SystemButtonType getButtonType() const;