From 27663fcb28c1c46f73bfc93d35712f636d4c5b70 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao Date: Sat, 15 Jul 2023 16:27:30 +0800 Subject: [PATCH] quick: minor code simplification --- src/quick/framelesshelperquick_global.cpp | 11 +++++++++++ src/quick/framelessquickmodule.cpp | 10 +++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/quick/framelesshelperquick_global.cpp b/src/quick/framelesshelperquick_global.cpp index a516b883..5db1f283 100644 --- a/src/quick/framelesshelperquick_global.cpp +++ b/src/quick/framelesshelperquick_global.cpp @@ -25,6 +25,8 @@ #include "framelesshelperquick_global.h" #include +#define REG_META_TYPE(Type) qRegisterMetaType(#Type) + FRAMELESSHELPER_BEGIN_NAMESPACE [[maybe_unused]] static Q_LOGGING_CATEGORY(lcQuickGlobal, "wangwenx190.framelesshelper.quick.global") @@ -59,6 +61,15 @@ void initialize() inited = true; FramelessHelper::Core::initialize(); + + // Registering meta types only causes troubles in Qt6. +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) + REG_META_TYPE(QuickGlobal::SystemTheme); + REG_META_TYPE(QuickGlobal::SystemButtonType); + REG_META_TYPE(QuickGlobal::ButtonState); + REG_META_TYPE(QuickGlobal::BlurMode); + REG_META_TYPE(QuickGlobal::WindowEdge); +#endif } void uninitialize() diff --git a/src/quick/framelessquickmodule.cpp b/src/quick/framelessquickmodule.cpp index 112b1b31..4cc60398 100644 --- a/src/quick/framelessquickmodule.cpp +++ b/src/quick/framelessquickmodule.cpp @@ -84,20 +84,16 @@ void FramelessHelper::Quick::registerTypes(QQmlEngine *engine) // @uri org.wangwenx190.FramelessHelper qmlRegisterUncreatableType(QUICK_URI_FULL, "FramelessHelperConstants", FRAMELESSHELPER_STRING_LITERAL("The FramelessHelperConstants namespace is not creatable, you can only use it to access it's enums.")); + qmlRegisterSingletonType(QUICK_URI_EXPAND("FramelessUtils"), [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { Q_UNUSED(engine); Q_UNUSED(scriptEngine); return new FramelessQuickUtils; }); + qmlRegisterAnonymousType(QUICK_URI_SHORT); -#if (QT_VERSION <= QT_VERSION_CHECK(5, 16, 0)) - qRegisterMetaType("QuickGlobal::SystemTheme"); - qRegisterMetaType("QuickGlobal::SystemButtonType"); - qRegisterMetaType("QuickGlobal::ButtonState"); - qRegisterMetaType("QuickGlobal::BlurMode"); - qRegisterMetaType("QuickGlobal::WindowEdge"); -#endif + qmlRegisterType(QUICK_URI_EXPAND("FramelessHelper")); qmlRegisterType(QUICK_URI_EXPAND("MicaMaterial")); qmlRegisterType(QUICK_URI_EXPAND("ImageItem"));