diff --git a/CMakeLists.txt b/CMakeLists.txt index 438ca9a7..e6344fff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,20 @@ option(FRAMELESSHELPER_EXAMPLES_STANDALONE "Build the demo projects as standalon cmake_dependent_option(FRAMELESSHELPER_ENABLE_UNIVERSAL_BUILD "macOS only: build universal library/example for Mac." ON APPLE OFF) option(FRAMELESSHELPER_FORCE_LTO "Force enable LTO/LTCG even when building static libraries." OFF) option(FRAMELESSHELPER_REPRODUCIBLE_OUTPUT "Don't update the build commit and date dynamically." ON) +option(FRAMELESSHELPER_NO_WINDOW "Disable the pre-defined FramelessWindow wrapper class." OFF) +option(FRAMELESSHELPER_NO_TITLEBAR "Disable the pre-defined StandardTitleBar control." OFF) +option(FRAMELESSHELPER_NO_TRANSLATION "Don't bundle the I18N translations into the library." OFF) +option(FRAMELESSHELPER_NO_MICA_MATERIAL "Disable the cross-platform homemade Mica Material." OFF) +option(FRAMELESSHELPER_NO_BORDER_PAINTER "Disable the cross-platform window frame border painter." OFF) +option(FRAMELESSHELPER_NO_SYSTEM_BUTTON "Disable the pre-defined StandardSystemButton control." OFF) + +set(PROJECT_VERSION_HEX "0x00000000") +math(EXPR PROJECT_VERSION_HEX "((${PROJECT_VERSION_MAJOR} & 0xff) << 24) | ((${PROJECT_VERSION_MINOR} & 0xff) << 16) | ((${PROJECT_VERSION_PATCH} & 0xff) << 8)" OUTPUT_FORMAT HEXADECIMAL) + +set(FRAMELESSHELPER_64BIT_POSTFIX "") +if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(FRAMELESSHELPER_64BIT_POSTFIX "64") +endif() find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Gui) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui) @@ -80,7 +94,7 @@ if(FRAMELESSHELPER_ENABLE_VCLTL AND NOT MSVC) message(WARNING "VC-LTL is only available for the MSVC toolchain.") endif() -set(__extra_flags) +set(__extra_flags "") if(NOT FRAMELESSHELPER_BUILD_STATIC) list(APPEND __extra_flags ENABLE_LTO) endif() @@ -130,7 +144,7 @@ if(MSVC) endif() endif() -set(__extra_flags) +set(__extra_flags "") if(FRAMELESSHELPER_NO_INSTALL) list(APPEND __extra_flags NO_INSTALL) endif() @@ -158,7 +172,7 @@ if(FRAMELESSHELPER_BUILD_EXAMPLES) add_subdirectory(examples) endif() -if(NOT FRAMELESSHELPER_NO_INSTALL) +if(WIN32 AND NOT FRAMELESSHELPER_NO_INSTALL) install(FILES "msbuild/FramelessHelper.props" DESTINATION ".") endif() @@ -234,5 +248,11 @@ if(NOT FRAMELESSHELPER_NO_SUMMARY) message("[macOS]: Build universal library/example: ${FRAMELESSHELPER_ENABLE_UNIVERSAL_BUILD}") message("Force enable LTO: ${FRAMELESSHELPER_FORCE_LTO}") message("Make output reproducible: ${FRAMELESSHELPER_REPRODUCIBLE_OUTPUT}") + message("Disable the FramelessWindow class (to reduce file size): ${FRAMELESSHELPER_NO_WINDOW}") + message("Disable the StandardTitleBar class (to reduce file size): ${FRAMELESSHELPER_NO_TITLEBAR}") + message("Don't embed the I18N resources (to reduce file size): ${FRAMELESSHELPER_NO_TRANSLATION}") + message("Disable the MicaMaterial class (to reduce file size): ${FRAMELESSHELPER_NO_MICA_MATERIAL}") + message("Disable the WindowBorderPainter class (to reduce file size): ${FRAMELESSHELPER_NO_BORDER_PAINTER}") + message("Disable the StandardSystemButton class (to reduce file size): ${FRAMELESSHELPER_NO_SYSTEM_BUTTON}") message("-----------------------------------------------------------------") endif() diff --git a/cmake b/cmake index 7215bd69..a0d72f17 160000 --- a/cmake +++ b/cmake @@ -1 +1 @@ -Subproject commit 7215bd692b7a62f307c7dffbe200554a12aabbf4 +Subproject commit a0d72f177e9a919c1f273b67d0456a052020781a diff --git a/include/FramelessHelper/Core/chromepalette.h b/include/FramelessHelper/Core/chromepalette.h index 9c568774..9e5d382f 100644 --- a/include/FramelessHelper/Core/chromepalette.h +++ b/include/FramelessHelper/Core/chromepalette.h @@ -26,6 +26,8 @@ #include +#if FRAMELESSHELPER_CONFIG(titlebar) + FRAMELESSHELPER_BEGIN_NAMESPACE class ChromePalettePrivate; @@ -33,6 +35,7 @@ class ChromePalettePrivate; class FRAMELESSHELPER_CORE_API ChromePalette : public QObject { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DECLARE_PRIVATE(ChromePalette) Q_DISABLE_COPY_MOVE(ChromePalette) @@ -123,3 +126,5 @@ public Q_SLOTS: }; FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/include/FramelessHelper/Core/framelesshelper_qt.h b/include/FramelessHelper/Core/framelesshelper_qt.h index bc5a5b3c..c9f506ec 100644 --- a/include/FramelessHelper/Core/framelesshelper_qt.h +++ b/include/FramelessHelper/Core/framelesshelper_qt.h @@ -33,6 +33,7 @@ struct SystemParameters; class FRAMELESSHELPER_CORE_API FramelessHelperQt : public QObject { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DISABLE_COPY_MOVE(FramelessHelperQt) public: diff --git a/include/FramelessHelper/Core/framelesshelper_win.h b/include/FramelessHelper/Core/framelesshelper_win.h index 8706ee42..51b76605 100644 --- a/include/FramelessHelper/Core/framelesshelper_win.h +++ b/include/FramelessHelper/Core/framelesshelper_win.h @@ -27,6 +27,8 @@ #include #include +#ifdef Q_OS_WINDOWS + FRAMELESSHELPER_BEGIN_NAMESPACE struct SystemParameters; @@ -46,3 +48,5 @@ class FRAMELESSHELPER_CORE_API FramelessHelperWin : public QAbstractNativeEventF }; FRAMELESSHELPER_END_NAMESPACE + +#endif // Q_OS_WINDOWS diff --git a/include/FramelessHelper/Core/framelesshelpercore_global.h b/include/FramelessHelper/Core/framelesshelpercore_global.h index 6cd445c9..74a2054a 100644 --- a/include/FramelessHelper/Core/framelesshelpercore_global.h +++ b/include/FramelessHelper/Core/framelesshelpercore_global.h @@ -24,6 +24,7 @@ #pragma once +#include "framelesshelper.config" #include #include #include @@ -165,6 +166,41 @@ QT_END_NAMESPACE } while (false) #endif +#ifndef FRAMELESSHELPER_QUOTE +# define FRAMELESSHELPER_QUOTE(x) #x +#endif + +#ifndef FRAMELESSHELPER_QUOTE2 +# define FRAMELESSHELPER_QUOTE2(x) FRAMELESSHELPER_QUOTE(x) +#endif + +#ifndef FRAMELESSHELPER_CONCAT +# define FRAMELESSHELPER_CONCAT(a, b) a##b +#endif + +#ifndef FRAMELESSHELPER_CONCAT2 +# define FRAMELESSHELPER_CONCAT2(a, b) FRAMELESSHELPER_CONCAT(a, b) +#endif + +/* + The FRAMELESSHELPER_CONFIG macro implements a safe compile time check for features of FramelessHelper. + Features can be in three states: + 0 or undefined: This will lead to a compile error when testing for it + -1: The feature is not available + 1: The feature is available +*/ +#ifndef FRAMELESSHELPER_CONFIG +# define FRAMELESSHELPER_CONFIG(feature) ((1 / FRAMELESSHELPER_FEATURE_##feature) == 1) +#endif + +#ifndef FRAMELESSHELPER_REQUIRE_CONFIG +# define FRAMELESSHELPER_REQUIRE_CONFIG(feature) static_assert(FRAMELESSHELPER_FEATURE_##feature == 1, "Required feature " #feature " for file " __FILE__ " is not available!") +#endif + +#ifndef FRAMELESSHELPER_CLASS_INFO +# define FRAMELESSHELPER_CLASS_INFO Q_CLASSINFO("__FRAMELESSHELPER__", FRAMELESSHELPER_QUOTE2(__FRAMELESSHELPER__)) +#endif + #ifndef FRAMELESSHELPER_BYTEARRAY_CONSTANT2 # define FRAMELESSHELPER_BYTEARRAY_CONSTANT2(name, ba) \ [[maybe_unused]] static constexpr const auto k##name = FRAMELESSHELPER_BYTEARRAY(ba); @@ -217,11 +253,12 @@ QT_END_NAMESPACE } #endif -#ifndef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE +#if FRAMELESSHELPER_CONFIG(bundle_resource) // Call this function in your main() function if you are using FramelessHelper as a static library, // it can make sure the resources bundled in the static library are correctly initialized. // NOTE: This function is intentionally not inside any namespaces. -FRAMELESSHELPER_CORE_API void framelesshelpercore_initResource(); +FRAMELESSHELPER_CORE_API void FramelessHelperCoreInitResource(); +inline void framelesshelpercore_initResource() { FramelessHelperCoreInitResource(); } #endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE FRAMELESSHELPER_BEGIN_NAMESPACE @@ -474,17 +511,43 @@ struct Dpi { return !operator==(lhs, rhs); } + + [[nodiscard]] friend constexpr bool operator>(const Dpi &lhs, const Dpi &rhs) noexcept + { + return ((lhs.x * lhs.y) > (rhs.x * rhs.y)); + } + + [[nodiscard]] friend constexpr bool operator>=(const Dpi &lhs, const Dpi &rhs) noexcept + { + return (operator>(lhs, rhs) || operator==(lhs, rhs)); + } + + [[nodiscard]] friend constexpr bool operator<(const Dpi &lhs, const Dpi &rhs) noexcept + { + return (operator!=(lhs, rhs) && !operator>(lhs, rhs)); + } + + [[nodiscard]] friend constexpr bool operator<=(const Dpi &lhs, const Dpi &rhs) noexcept + { + return (operator<(lhs, rhs) || operator==(lhs, rhs)); + } }; } // namespace Global +FRAMELESSHELPER_CORE_API void FramelessHelperCoreInitialize(); +FRAMELESSHELPER_CORE_API void FramelessHelperCoreUninitialize(); +[[nodiscard]] FRAMELESSHELPER_CORE_API Global::VersionInfo FramelessHelperVersion(); +FRAMELESSHELPER_CORE_API void FramelessHelperEnableThemeAware(); +FRAMELESSHELPER_CORE_API void FramelessHelperPrintLogo(); + namespace FramelessHelper::Core { -FRAMELESSHELPER_CORE_API void initialize(); -FRAMELESSHELPER_CORE_API void uninitialize(); -[[nodiscard]] FRAMELESSHELPER_CORE_API Global::VersionInfo version(); -FRAMELESSHELPER_CORE_API void setApplicationOSThemeAware(); -FRAMELESSHELPER_CORE_API void outputLogo(); +inline void initialize() { FramelessHelperCoreInitialize(); } +inline void uninitialize() { FramelessHelperCoreUninitialize(); } +[[nodiscard]] inline Global::VersionInfo version() { return FramelessHelperVersion(); } +inline void setApplicationOSThemeAware() { FramelessHelperEnableThemeAware(); } +inline void outputLogo() { FramelessHelperPrintLogo(); } } // namespace FramelessHelper::Core FRAMELESSHELPER_END_NAMESPACE diff --git a/include/FramelessHelper/Core/framelessmanager.h b/include/FramelessHelper/Core/framelessmanager.h index 5112ae2c..b6ed5bd5 100644 --- a/include/FramelessHelper/Core/framelessmanager.h +++ b/include/FramelessHelper/Core/framelessmanager.h @@ -34,6 +34,7 @@ class FramelessManagerPrivate; class FRAMELESSHELPER_CORE_API FramelessManager : public QObject { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DECLARE_PRIVATE(FramelessManager) Q_DISABLE_COPY_MOVE(FramelessManager) Q_PROPERTY(Global::SystemTheme systemTheme READ systemTheme WRITE setOverrideTheme NOTIFY systemThemeChanged FINAL) diff --git a/include/FramelessHelper/Core/micamaterial.h b/include/FramelessHelper/Core/micamaterial.h index 6cb8f802..b1920a79 100644 --- a/include/FramelessHelper/Core/micamaterial.h +++ b/include/FramelessHelper/Core/micamaterial.h @@ -26,6 +26,8 @@ #include +#if FRAMELESSHELPER_CONFIG(mica_material) + FRAMELESSHELPER_BEGIN_NAMESPACE class MicaMaterialPrivate; @@ -33,6 +35,7 @@ class MicaMaterialPrivate; class FRAMELESSHELPER_CORE_API MicaMaterial : public QObject { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DISABLE_COPY_MOVE(MicaMaterial) Q_DECLARE_PRIVATE(MicaMaterial) @@ -83,3 +86,5 @@ public Q_SLOTS: }; FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/include/FramelessHelper/Core/private/chromepalette_p.h b/include/FramelessHelper/Core/private/chromepalette_p.h index 0f6ff624..9610988e 100644 --- a/include/FramelessHelper/Core/private/chromepalette_p.h +++ b/include/FramelessHelper/Core/private/chromepalette_p.h @@ -27,6 +27,8 @@ #include #include +#if FRAMELESSHELPER_CONFIG(titlebar) + FRAMELESSHELPER_BEGIN_NAMESPACE class ChromePalette; @@ -34,6 +36,7 @@ class ChromePalette; class FRAMELESSHELPER_CORE_API ChromePalettePrivate : public QObject { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DECLARE_PUBLIC(ChromePalette) Q_DISABLE_COPY_MOVE(ChromePalettePrivate) @@ -72,3 +75,5 @@ class FRAMELESSHELPER_CORE_API ChromePalettePrivate : public QObject }; FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/include/FramelessHelper/Core/private/framelessconfig_p.h b/include/FramelessHelper/Core/private/framelessconfig_p.h index e97609ac..75ea209f 100644 --- a/include/FramelessHelper/Core/private/framelessconfig_p.h +++ b/include/FramelessHelper/Core/private/framelessconfig_p.h @@ -31,6 +31,7 @@ FRAMELESSHELPER_BEGIN_NAMESPACE class FRAMELESSHELPER_CORE_API FramelessConfig : public QObject { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DISABLE_COPY_MOVE(FramelessConfig) public: diff --git a/include/FramelessHelper/Core/private/framelesshelpercore_global_p.h b/include/FramelessHelper/Core/private/framelesshelpercore_global_p.h index 80071992..c0d2fa56 100644 --- a/include/FramelessHelper/Core/private/framelesshelpercore_global_p.h +++ b/include/FramelessHelper/Core/private/framelesshelpercore_global_p.h @@ -33,9 +33,6 @@ QT_END_NAMESPACE FRAMELESSHELPER_BEGIN_NAMESPACE -using InitializeHookCallback = std::function; -using UninitializeHookCallback = std::function; - using GetWindowFlagsCallback = std::function; using SetWindowFlagsCallback = std::function; using GetWindowSizeCallback = std::function; @@ -102,9 +99,6 @@ using FramelessParamsConst = const SystemParameters *; using FramelessParamsRef = SystemParameters &; using FramelessParamsConstRef = const SystemParameters &; -FRAMELESSHELPER_CORE_API void registerInitializeHook(const InitializeHookCallback &cb); -FRAMELESSHELPER_CORE_API void registerUninitializeHook(const UninitializeHookCallback &cb); - FRAMELESSHELPER_END_NAMESPACE #define DECLARE_SIZE_COMPARE_OPERATORS(Type1, Type2) \ diff --git a/include/FramelessHelper/Core/private/framelessmanager_p.h b/include/FramelessHelper/Core/private/framelessmanager_p.h index 73009542..5951a0bb 100644 --- a/include/FramelessHelper/Core/private/framelessmanager_p.h +++ b/include/FramelessHelper/Core/private/framelessmanager_p.h @@ -36,6 +36,7 @@ class FramelessManager; class FRAMELESSHELPER_CORE_API FramelessManagerPrivate : public QObject { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DECLARE_PUBLIC(FramelessManager) Q_DISABLE_COPY_MOVE(FramelessManagerPrivate) diff --git a/include/FramelessHelper/Core/private/micamaterial_p.h b/include/FramelessHelper/Core/private/micamaterial_p.h index 6014d2a8..e90da38c 100644 --- a/include/FramelessHelper/Core/private/micamaterial_p.h +++ b/include/FramelessHelper/Core/private/micamaterial_p.h @@ -27,6 +27,8 @@ #include #include +#if FRAMELESSHELPER_CONFIG(mica_material) + FRAMELESSHELPER_BEGIN_NAMESPACE class MicaMaterial; @@ -34,6 +36,7 @@ class MicaMaterial; class FRAMELESSHELPER_CORE_API MicaMaterialPrivate : public QObject { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DISABLE_COPY_MOVE(MicaMaterialPrivate) Q_DECLARE_PUBLIC(MicaMaterial) @@ -69,3 +72,5 @@ class FRAMELESSHELPER_CORE_API MicaMaterialPrivate : public QObject }; FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/include/FramelessHelper/Core/private/registrykey_p.h b/include/FramelessHelper/Core/private/registrykey_p.h index 32c22d07..114c80bb 100644 --- a/include/FramelessHelper/Core/private/registrykey_p.h +++ b/include/FramelessHelper/Core/private/registrykey_p.h @@ -28,6 +28,8 @@ #include #include +#ifdef Q_OS_WINDOWS + #ifndef REGISTRYKEY_FORCE_QSETTINGS # define REGISTRYKEY_FORCE_QSETTINGS (0) #endif // REGISTRYKEY_FORCE_QSETTINGS @@ -58,6 +60,7 @@ FRAMELESSHELPER_BEGIN_NAMESPACE class FRAMELESSHELPER_CORE_API RegistryKey : public QObject { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DISABLE_COPY_MOVE(RegistryKey) public: @@ -91,3 +94,5 @@ class FRAMELESSHELPER_CORE_API RegistryKey : public QObject }; FRAMELESSHELPER_END_NAMESPACE + +#endif // Q_OS_WINDOWS diff --git a/include/FramelessHelper/Core/private/sysapiloader_p.h b/include/FramelessHelper/Core/private/sysapiloader_p.h index fa69a4a8..da33d162 100644 --- a/include/FramelessHelper/Core/private/sysapiloader_p.h +++ b/include/FramelessHelper/Core/private/sysapiloader_p.h @@ -31,6 +31,7 @@ FRAMELESSHELPER_BEGIN_NAMESPACE class FRAMELESSHELPER_CORE_API SysApiLoader : public QObject { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DISABLE_COPY_MOVE(SysApiLoader) public: @@ -86,7 +87,7 @@ FRAMELESSHELPER_END_NAMESPACE # define API_NT_AVAILABLE(func) API_AVAILABLE(ntdll, func) #endif // Q_OS_WINDOWS -#ifdef Q_OS_LINUX +#if (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)) # define API_XLIB_AVAILABLE(func) API_AVAILABLE(libX11, func) # define API_XCB_AVAILABLE(func) API_AVAILABLE(libxcb, func) # define API_GTK_AVAILABLE(func) API_AVAILABLE(libgtk, func) diff --git a/include/FramelessHelper/Core/private/windowborderpainter_p.h b/include/FramelessHelper/Core/private/windowborderpainter_p.h index dfe63cad..5037cde5 100644 --- a/include/FramelessHelper/Core/private/windowborderpainter_p.h +++ b/include/FramelessHelper/Core/private/windowborderpainter_p.h @@ -27,6 +27,8 @@ #include #include +#if FRAMELESSHELPER_CONFIG(border_painter) + FRAMELESSHELPER_BEGIN_NAMESPACE class WindowBorderPainter; @@ -34,6 +36,7 @@ class WindowBorderPainter; class FRAMELESSHELPER_CORE_API WindowBorderPainterPrivate : public QObject { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DECLARE_PUBLIC(WindowBorderPainter) Q_DISABLE_COPY_MOVE(WindowBorderPainterPrivate) @@ -52,3 +55,5 @@ class FRAMELESSHELPER_CORE_API WindowBorderPainterPrivate : public QObject }; FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/include/FramelessHelper/Core/private/winverhelper_p.h b/include/FramelessHelper/Core/private/winverhelper_p.h index f2198dde..6986353c 100644 --- a/include/FramelessHelper/Core/private/winverhelper_p.h +++ b/include/FramelessHelper/Core/private/winverhelper_p.h @@ -26,6 +26,8 @@ #include +#ifdef Q_OS_WINDOWS + FRAMELESSHELPER_BEGIN_NAMESPACE namespace WindowsVersionHelper @@ -68,3 +70,5 @@ DECL(1122H2) } // namespace WindowsVersionHelper FRAMELESSHELPER_END_NAMESPACE + +#endif // Q_OS_WINDOWS diff --git a/include/FramelessHelper/Core/utils.h b/include/FramelessHelper/Core/utils.h index 8f5a18f2..e922eac1 100644 --- a/include/FramelessHelper/Core/utils.h +++ b/include/FramelessHelper/Core/utils.h @@ -25,11 +25,11 @@ #pragma once #include -#ifdef Q_OS_LINUX +#if (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)) # include #endif // Q_OS_LINUX -#ifdef Q_OS_LINUX +#if (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)) QT_BEGIN_NAMESPACE class QScreen; QT_END_NAMESPACE @@ -155,7 +155,7 @@ FRAMELESSHELPER_CORE_API void moveWindowToDesktopCenter( FRAMELESSHELPER_CORE_API void printWin32Message(void *msg); #endif // Q_OS_WINDOWS -#ifdef Q_OS_LINUX +#if (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)) [[nodiscard]] FRAMELESSHELPER_CORE_API QScreen *x11_findScreenForVirtualDesktop (const int virtualDesktopNumber); [[nodiscard]] FRAMELESSHELPER_CORE_API x11_return_type x11_appRootWindow(const int screen); diff --git a/include/FramelessHelper/Core/windowborderpainter.h b/include/FramelessHelper/Core/windowborderpainter.h index 648e62dc..8ce9fd47 100644 --- a/include/FramelessHelper/Core/windowborderpainter.h +++ b/include/FramelessHelper/Core/windowborderpainter.h @@ -26,6 +26,8 @@ #include +#if FRAMELESSHELPER_CONFIG(border_painter) + FRAMELESSHELPER_BEGIN_NAMESPACE class WindowBorderPainterPrivate; @@ -33,6 +35,7 @@ class WindowBorderPainterPrivate; class FRAMELESSHELPER_CORE_API WindowBorderPainter : public QObject { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DISABLE_COPY_MOVE(WindowBorderPainter) Q_DECLARE_PRIVATE(WindowBorderPainter) @@ -80,3 +83,5 @@ public Q_SLOTS: }; FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/include/FramelessHelper/Quick/QuickImageItem b/include/FramelessHelper/Quick/QuickImageItem deleted file mode 100644 index ce69bb15..00000000 --- a/include/FramelessHelper/Quick/QuickImageItem +++ /dev/null @@ -1 +0,0 @@ -#include "quickimageitem.h" diff --git a/include/FramelessHelper/Quick/framelesshelperquick_global.h b/include/FramelessHelper/Quick/framelesshelperquick_global.h index 93ca535d..4ed39ab3 100644 --- a/include/FramelessHelper/Quick/framelesshelperquick_global.h +++ b/include/FramelessHelper/Quick/framelesshelperquick_global.h @@ -77,9 +77,14 @@ FRAMELESSHELPER_BEGIN_NAMESPACE [[maybe_unused]] inline constexpr const int FRAMELESSHELPER_QUICK_VERSION_MAJOR = 1; [[maybe_unused]] inline constexpr const int FRAMELESSHELPER_QUICK_VERSION_MINOR = 0; +FRAMELESSHELPER_QUICK_API void FramelessHelperQuickInitialize(); +FRAMELESSHELPER_QUICK_API void FramelessHelperQuickUninitialize(); +FRAMELESSHELPER_QUICK_API void FramelessHelperQuickRegisterTypes(QQmlEngine *); + class FRAMELESSHELPER_QUICK_API QuickGlobal : public QObject { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DISABLE_COPY_MOVE(QuickGlobal) #ifdef QML_NAMED_ELEMENT QML_NAMED_ELEMENT(FramelessHelperConstants) @@ -148,8 +153,8 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QuickGlobal::WindowEdges) namespace FramelessHelper::Quick { -FRAMELESSHELPER_QUICK_API void initialize(); -FRAMELESSHELPER_QUICK_API void uninitialize(); +inline void initialize() { FramelessHelperQuickInitialize(); } +inline void uninitialize() { FramelessHelperQuickUninitialize(); } } // namespace FramelessHelper::Quick FRAMELESSHELPER_END_NAMESPACE diff --git a/include/FramelessHelper/Quick/framelessquickhelper.h b/include/FramelessHelper/Quick/framelessquickhelper.h index 8ee1b481..bf3ebc93 100644 --- a/include/FramelessHelper/Quick/framelessquickhelper.h +++ b/include/FramelessHelper/Quick/framelessquickhelper.h @@ -30,13 +30,18 @@ FRAMELESSHELPER_BEGIN_NAMESPACE -class FramelessQuickHelperPrivate; +#if FRAMELESSHELPER_CONFIG(mica_material) class QuickMicaMaterial; +#endif +#if FRAMELESSHELPER_CONFIG(border_painter) class QuickWindowBorder; +#endif +class FramelessQuickHelperPrivate; class FRAMELESSHELPER_QUICK_API FramelessQuickHelper : public QQuickItem { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO #ifdef QML_NAMED_ELEMENT QML_NAMED_ELEMENT(FramelessHelper) #endif @@ -63,8 +68,12 @@ class FRAMELESSHELPER_QUICK_API FramelessQuickHelper : public QQuickItem Q_NODISCARD bool isBlurBehindWindowEnabled() const; Q_NODISCARD bool isContentExtendedIntoTitleBar() const; +#if FRAMELESSHELPER_CONFIG(mica_material) Q_NODISCARD QuickMicaMaterial *micaMaterial() const; +#endif +#if FRAMELESSHELPER_CONFIG(border_painter) Q_NODISCARD QuickWindowBorder *windowBorder() const; +#endif Q_NODISCARD bool isReady() const; void waitForReady(); diff --git a/include/FramelessHelper/Quick/framelessquickmodule.h b/include/FramelessHelper/Quick/framelessquickmodule.h index deb3ca82..7703ed40 100644 --- a/include/FramelessHelper/Quick/framelessquickmodule.h +++ b/include/FramelessHelper/Quick/framelessquickmodule.h @@ -34,7 +34,7 @@ FRAMELESSHELPER_BEGIN_NAMESPACE namespace FramelessHelper::Quick { -FRAMELESSHELPER_QUICK_API void registerTypes(QQmlEngine *engine); +inline void registerTypes(QQmlEngine *engine) { FramelessHelperQuickRegisterTypes(engine); } } // namespace FramelessHelper::Quick FRAMELESSHELPER_END_NAMESPACE diff --git a/include/FramelessHelper/Quick/framelessquickutils.h b/include/FramelessHelper/Quick/framelessquickutils.h index 3ee81bae..ba463cf2 100644 --- a/include/FramelessHelper/Quick/framelessquickutils.h +++ b/include/FramelessHelper/Quick/framelessquickutils.h @@ -36,6 +36,7 @@ FRAMELESSHELPER_BEGIN_NAMESPACE class FRAMELESSHELPER_QUICK_API FramelessQuickUtils : public QObject, public QQmlParserStatus { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DISABLE_COPY_MOVE(FramelessQuickUtils) Q_INTERFACES(QQmlParserStatus) #ifdef QML_NAMED_ELEMENT diff --git a/include/FramelessHelper/Quick/private/framelessquickapplicationwindow_p.h b/include/FramelessHelper/Quick/private/framelessquickapplicationwindow_p.h index 01f61eaf..ae72529c 100644 --- a/include/FramelessHelper/Quick/private/framelessquickapplicationwindow_p.h +++ b/include/FramelessHelper/Quick/private/framelessquickapplicationwindow_p.h @@ -24,9 +24,10 @@ #pragma once -#ifndef FRAMELESSHELPER_QUICK_NO_PRIVATE - #include + +#if (FRAMELESSHELPER_CONFIG(private_qt) && FRAMELESSHELPER_CONFIG(window) && (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))) + #include FRAMELESSHELPER_BEGIN_NAMESPACE @@ -36,6 +37,7 @@ class FramelessQuickApplicationWindowPrivate; class FRAMELESSHELPER_QUICK_API FramelessQuickApplicationWindow : public QQuickApplicationWindow { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO #ifdef QML_NAMED_ELEMENT QML_NAMED_ELEMENT(FramelessApplicationWindow) #endif @@ -82,4 +84,4 @@ public Q_SLOTS: FRAMELESSHELPER_END_NAMESPACE -#endif // FRAMELESSHELPER_QUICK_NO_PRIVATE +#endif diff --git a/include/FramelessHelper/Quick/private/framelessquickapplicationwindow_p_p.h b/include/FramelessHelper/Quick/private/framelessquickapplicationwindow_p_p.h index 1bdb1960..51b6acec 100644 --- a/include/FramelessHelper/Quick/private/framelessquickapplicationwindow_p_p.h +++ b/include/FramelessHelper/Quick/private/framelessquickapplicationwindow_p_p.h @@ -24,19 +24,23 @@ #pragma once -#ifndef FRAMELESSHELPER_QUICK_NO_PRIVATE - #include + +#if (FRAMELESSHELPER_CONFIG(private_qt) && FRAMELESSHELPER_CONFIG(window) && (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))) + #include FRAMELESSHELPER_BEGIN_NAMESPACE -class FramelessQuickApplicationWindow; +#if FRAMELESSHELPER_CONFIG(border_painter) class QuickWindowBorder; +#endif +class FramelessQuickApplicationWindow; class FRAMELESSHELPER_QUICK_API FramelessQuickApplicationWindowPrivate : public QObject { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DECLARE_PUBLIC(FramelessQuickApplicationWindow) Q_DISABLE_COPY_MOVE(FramelessQuickApplicationWindowPrivate) @@ -48,10 +52,12 @@ class FRAMELESSHELPER_QUICK_API FramelessQuickApplicationWindowPrivate : public Q_NODISCARD static const FramelessQuickApplicationWindowPrivate *get(const FramelessQuickApplicationWindow *pub); FramelessQuickApplicationWindow *q_ptr = nullptr; - QuickWindowBorder *windowBorder = nullptr; QQuickWindow::Visibility savedVisibility = QQuickWindow::Windowed; +#if FRAMELESSHELPER_CONFIG(border_painter) + QuickWindowBorder *windowBorder = nullptr; +#endif }; FRAMELESSHELPER_END_NAMESPACE -#endif // FRAMELESSHELPER_QUICK_NO_PRIVATE +#endif diff --git a/include/FramelessHelper/Quick/private/framelessquickhelper_p.h b/include/FramelessHelper/Quick/private/framelessquickhelper_p.h index 0389912a..ce974035 100644 --- a/include/FramelessHelper/Quick/private/framelessquickhelper_p.h +++ b/include/FramelessHelper/Quick/private/framelessquickhelper_p.h @@ -33,14 +33,19 @@ QT_END_NAMESPACE FRAMELESSHELPER_BEGIN_NAMESPACE -class FramelessQuickHelper; +#if FRAMELESSHELPER_CONFIG(mica_material) class QuickMicaMaterial; +#endif +#if FRAMELESSHELPER_CONFIG(border_painter) class QuickWindowBorder; +#endif +class FramelessQuickHelper; struct FramelessQuickHelperData; class FRAMELESSHELPER_QUICK_API FramelessQuickHelperPrivate : public QObject { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DECLARE_PUBLIC(FramelessQuickHelper) Q_DISABLE_COPY_MOVE(FramelessQuickHelperPrivate) @@ -59,8 +64,12 @@ class FRAMELESSHELPER_QUICK_API FramelessQuickHelperPrivate : public QObject void setProperty(const char *name, const QVariant &value); Q_NODISCARD QVariant getProperty(const char *name, const QVariant &defaultValue = {}); +#if FRAMELESSHELPER_CONFIG(mica_material) Q_NODISCARD QuickMicaMaterial *findOrCreateMicaMaterial() const; +#endif +#if FRAMELESSHELPER_CONFIG(border_painter) Q_NODISCARD QuickWindowBorder *findOrCreateWindowBorder() const; +#endif Q_NODISCARD static FramelessQuickHelper *findOrCreateFramelessHelper(QObject *object); diff --git a/include/FramelessHelper/Quick/private/framelessquickwindow_p.h b/include/FramelessHelper/Quick/private/framelessquickwindow_p.h index 6b79833e..d0f8e64d 100644 --- a/include/FramelessHelper/Quick/private/framelessquickwindow_p.h +++ b/include/FramelessHelper/Quick/private/framelessquickwindow_p.h @@ -24,9 +24,10 @@ #pragma once -#ifndef FRAMELESSHELPER_QUICK_NO_PRIVATE - #include + +#if (FRAMELESSHELPER_CONFIG(private_qt) && FRAMELESSHELPER_CONFIG(window)) + #include FRAMELESSHELPER_BEGIN_NAMESPACE @@ -36,6 +37,7 @@ class FramelessQuickWindowPrivate; class FRAMELESSHELPER_QUICK_API FramelessQuickWindow : public QQuickWindowQmlImpl { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO #ifdef QML_NAMED_ELEMENT QML_NAMED_ELEMENT(FramelessWindow) #endif @@ -82,4 +84,4 @@ public Q_SLOTS: FRAMELESSHELPER_END_NAMESPACE -#endif // FRAMELESSHELPER_QUICK_NO_PRIVATE +#endif diff --git a/include/FramelessHelper/Quick/private/framelessquickwindow_p_p.h b/include/FramelessHelper/Quick/private/framelessquickwindow_p_p.h index 89797316..ef2ca71c 100644 --- a/include/FramelessHelper/Quick/private/framelessquickwindow_p_p.h +++ b/include/FramelessHelper/Quick/private/framelessquickwindow_p_p.h @@ -24,19 +24,23 @@ #pragma once -#ifndef FRAMELESSHELPER_QUICK_NO_PRIVATE - #include + +#if (FRAMELESSHELPER_CONFIG(private_qt) && FRAMELESSHELPER_CONFIG(window)) + #include FRAMELESSHELPER_BEGIN_NAMESPACE -class FramelessQuickWindow; +#if FRAMELESSHELPER_CONFIG(border_painter) class QuickWindowBorder; +#endif +class FramelessQuickWindow; class FRAMELESSHELPER_QUICK_API FramelessQuickWindowPrivate : public QObject { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DECLARE_PUBLIC(FramelessQuickWindow) Q_DISABLE_COPY_MOVE(FramelessQuickWindowPrivate) @@ -48,10 +52,12 @@ class FRAMELESSHELPER_QUICK_API FramelessQuickWindowPrivate : public QObject Q_NODISCARD static const FramelessQuickWindowPrivate *get(const FramelessQuickWindow *pub); FramelessQuickWindow *q_ptr = nullptr; - QuickWindowBorder *windowBorder = nullptr; QQuickWindow::Visibility savedVisibility = QQuickWindow::Windowed; +#if FRAMELESSHELPER_CONFIG(border_painter) + QuickWindowBorder *windowBorder = nullptr; +#endif }; FRAMELESSHELPER_END_NAMESPACE -#endif // FRAMELESSHELPER_QUICK_NO_PRIVATE +#endif diff --git a/include/FramelessHelper/Quick/private/quickimageitem_p.h b/include/FramelessHelper/Quick/private/quickimageitem_p.h index 5f3fcecb..2eec9d06 100644 --- a/include/FramelessHelper/Quick/private/quickimageitem_p.h +++ b/include/FramelessHelper/Quick/private/quickimageitem_p.h @@ -26,24 +26,38 @@ #include #include +#include FRAMELESSHELPER_BEGIN_NAMESPACE -class QuickImageItem; - -class FRAMELESSHELPER_QUICK_API QuickImageItemPrivate : public QObject +class FRAMELESSHELPER_QUICK_API QuickImageItem : public QQuickPaintedItem { Q_OBJECT - Q_DISABLE_COPY_MOVE(QuickImageItemPrivate) - Q_DECLARE_PUBLIC(QuickImageItem) + FRAMELESSHELPER_CLASS_INFO +#ifdef QML_NAMED_ELEMENT + QML_NAMED_ELEMENT(ImageItem) +#endif + Q_DISABLE_COPY_MOVE(QuickImageItem) + + Q_PROPERTY(QVariant source READ source WRITE setSource NOTIFY sourceChanged FINAL) public: - explicit QuickImageItemPrivate(QuickImageItem *q); - ~QuickImageItemPrivate() override; + explicit QuickImageItem(QQuickItem *parent = nullptr); + ~QuickImageItem() override; + + void paint(QPainter *painter) override; + + Q_NODISCARD QVariant source() const; + void setSource(const QVariant &value); + +Q_SIGNALS: + void sourceChanged(); - Q_NODISCARD static QuickImageItemPrivate *get(QuickImageItem *q); - Q_NODISCARD static const QuickImageItemPrivate *get(const QuickImageItem *q); +protected: + void classBegin() override; + void componentComplete() override; +private: void fromUrl(const QUrl &value, QPainter *painter) const; void fromString(const QString &value, QPainter *painter) const; void fromImage(const QImage &value, QPainter *painter) const; @@ -51,8 +65,8 @@ class FRAMELESSHELPER_QUICK_API QuickImageItemPrivate : public QObject void fromIcon(const QIcon &value, QPainter *painter) const; Q_NODISCARD QRectF paintArea() const; - QuickImageItem *q_ptr = nullptr; - QVariant source = {}; +private: + QVariant m_source = {}; }; FRAMELESSHELPER_END_NAMESPACE diff --git a/include/FramelessHelper/Quick/private/quickmicamaterial_p.h b/include/FramelessHelper/Quick/private/quickmicamaterial_p.h index f6464238..9fd66a34 100644 --- a/include/FramelessHelper/Quick/private/quickmicamaterial_p.h +++ b/include/FramelessHelper/Quick/private/quickmicamaterial_p.h @@ -26,6 +26,8 @@ #include +#if FRAMELESSHELPER_CONFIG(mica_material) + FRAMELESSHELPER_BEGIN_NAMESPACE class MicaMaterial; @@ -34,6 +36,7 @@ class QuickMicaMaterial; class FRAMELESSHELPER_QUICK_API QuickMicaMaterialPrivate : public QObject { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DISABLE_COPY_MOVE(QuickMicaMaterialPrivate) Q_DECLARE_PUBLIC(QuickMicaMaterial) @@ -56,3 +59,5 @@ class FRAMELESSHELPER_QUICK_API QuickMicaMaterialPrivate : public QObject }; FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/include/FramelessHelper/Quick/private/quickstandardsystembutton_p.h b/include/FramelessHelper/Quick/private/quickstandardsystembutton_p.h index 4b78b20b..8370a3fe 100644 --- a/include/FramelessHelper/Quick/private/quickstandardsystembutton_p.h +++ b/include/FramelessHelper/Quick/private/quickstandardsystembutton_p.h @@ -24,10 +24,10 @@ #pragma once -#ifndef FRAMELESSHELPER_QUICK_NO_PRIVATE - #include -#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + +#if (FRAMELESSHELPER_CONFIG(private_qt) && FRAMELESSHELPER_CONFIG(system_button) && (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))) + #include QT_BEGIN_NAMESPACE @@ -40,6 +40,7 @@ FRAMELESSHELPER_BEGIN_NAMESPACE class FRAMELESSHELPER_QUICK_API QuickStandardSystemButton : public QQuickButton { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO #ifdef QML_NAMED_ELEMENT QML_NAMED_ELEMENT(StandardSystemButton) #endif @@ -51,7 +52,7 @@ class FRAMELESSHELPER_QUICK_API QuickStandardSystemButton : public QQuickButton Q_PROPERTY(QColor normalColor READ normalColor WRITE setNormalColor NOTIFY normalColorChanged FINAL) Q_PROPERTY(QColor activeForegroundColor READ activeForegroundColor WRITE setActiveForegroundColor NOTIFY activeForegroundColorChanged FINAL) Q_PROPERTY(QColor inactiveForegroundColor READ inactiveForegroundColor WRITE setInactiveForegroundColor NOTIFY inactiveForegroundColorChanged FINAL) - Q_PROPERTY(qreal iconSize READ iconSize WRITE setIconSize NOTIFY iconSizeChanged FINAL) + Q_PROPERTY(qreal glyphSize READ glyphSize WRITE setGlyphSize NOTIFY glyphChanged FINAL) public: explicit QuickStandardSystemButton(QQuickItem *parent = nullptr); @@ -65,7 +66,7 @@ class FRAMELESSHELPER_QUICK_API QuickStandardSystemButton : public QQuickButton Q_NODISCARD QColor pressColor() const; Q_NODISCARD QColor activeForegroundColor() const; Q_NODISCARD QColor inactiveForegroundColor() const; - Q_NODISCARD qreal iconSize() const; + Q_NODISCARD qreal glyphSize() const; public Q_SLOTS: void updateColor(); @@ -76,7 +77,7 @@ public Q_SLOTS: void setPressColor(const QColor &value); void setActiveForegroundColor(const QColor &value); void setInactiveForegroundColor(const QColor &value); - void setIconSize(const qreal value); + void setGlyphSize(const qreal value); protected: void classBegin() override; @@ -93,7 +94,7 @@ public Q_SLOTS: void pressColorChanged(); void activeForegroundColorChanged(); void inactiveForegroundColorChanged(); - void iconSizeChanged(); + void glyphSizeChanged(); private: QQuickText *m_contentItem = nullptr; @@ -108,6 +109,5 @@ public Q_SLOTS: }; FRAMELESSHELPER_END_NAMESPACE -#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) -#endif // FRAMELESSHELPER_QUICK_NO_PRIVATE +#endif diff --git a/include/FramelessHelper/Quick/private/quickstandardtitlebar_p.h b/include/FramelessHelper/Quick/private/quickstandardtitlebar_p.h index d40f996c..9e243834 100644 --- a/include/FramelessHelper/Quick/private/quickstandardtitlebar_p.h +++ b/include/FramelessHelper/Quick/private/quickstandardtitlebar_p.h @@ -24,12 +24,14 @@ #pragma once -#ifndef FRAMELESSHELPER_QUICK_NO_PRIVATE - #include -#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + +#if (FRAMELESSHELPER_CONFIG(private_qt) && FRAMELESSHELPER_CONFIG(titlebar) && (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))) + #include -#include +#if FRAMELESSHELPER_CONFIG(system_button) +# include +#endif #include #include @@ -44,13 +46,14 @@ class QuickImageItem; class FRAMELESSHELPER_QUICK_API QuickStandardTitleBar : public QQuickRectangle { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO #ifdef QML_NAMED_ELEMENT QML_NAMED_ELEMENT(StandardTitleBar) #endif // QML_NAMED_ELEMENT 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) -#ifndef Q_OS_MACOS +#if (!defined(Q_OS_MACOS) && FRAMELESSHELPER_CONFIG(system_button)) Q_PROPERTY(QuickStandardSystemButton* minimizeButton READ minimizeButton CONSTANT FINAL) Q_PROPERTY(QuickStandardSystemButton* maximizeButton READ maximizeButton CONSTANT FINAL) Q_PROPERTY(QuickStandardSystemButton* closeButton READ closeButton CONSTANT FINAL) @@ -70,7 +73,7 @@ class FRAMELESSHELPER_QUICK_API QuickStandardTitleBar : public QQuickRectangle void setTitleLabelAlignment(const Qt::Alignment value); Q_NODISCARD QQuickLabel *titleLabel() const; -#ifndef Q_OS_MACOS +#if (!defined(Q_OS_MACOS) && FRAMELESSHELPER_CONFIG(system_button)) Q_NODISCARD QuickStandardSystemButton *minimizeButton() const; Q_NODISCARD QuickStandardSystemButton *maximizeButton() const; Q_NODISCARD QuickStandardSystemButton *closeButton() const; @@ -130,7 +133,7 @@ private Q_SLOTS: Qt::Alignment m_labelAlignment = {}; QuickImageItem *m_windowIcon = nullptr; QQuickLabel *m_windowTitleLabel = nullptr; -#ifndef Q_OS_MACOS +#if (!defined(Q_OS_MACOS) && FRAMELESSHELPER_CONFIG(system_button)) QQuickRow *m_systemButtonsRow = nullptr; QuickStandardSystemButton *m_minimizeButton = nullptr; QuickStandardSystemButton *m_maximizeButton = nullptr; @@ -146,6 +149,5 @@ private Q_SLOTS: }; FRAMELESSHELPER_END_NAMESPACE -#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) -#endif // FRAMELESSHELPER_QUICK_NO_PRIVATE +#endif diff --git a/include/FramelessHelper/Quick/private/quickwindowborder_p.h b/include/FramelessHelper/Quick/private/quickwindowborder_p.h index 94a89d35..48e659a5 100644 --- a/include/FramelessHelper/Quick/private/quickwindowborder_p.h +++ b/include/FramelessHelper/Quick/private/quickwindowborder_p.h @@ -26,6 +26,8 @@ #include +#if FRAMELESSHELPER_CONFIG(border_painter) + FRAMELESSHELPER_BEGIN_NAMESPACE class QuickWindowBorder; @@ -34,6 +36,7 @@ class WindowBorderPainter; class FRAMELESSHELPER_QUICK_API QuickWindowBorderPrivate : public QObject { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DISABLE_COPY_MOVE(QuickWindowBorderPrivate) Q_DECLARE_PUBLIC(QuickWindowBorder) @@ -56,3 +59,5 @@ class FRAMELESSHELPER_QUICK_API QuickWindowBorderPrivate : public QObject }; FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/include/FramelessHelper/Quick/quickchromepalette.h b/include/FramelessHelper/Quick/quickchromepalette.h index 85d2248a..9b481790 100644 --- a/include/FramelessHelper/Quick/quickchromepalette.h +++ b/include/FramelessHelper/Quick/quickchromepalette.h @@ -28,11 +28,14 @@ #include #include +#if FRAMELESSHELPER_CONFIG(titlebar) + FRAMELESSHELPER_BEGIN_NAMESPACE class FRAMELESSHELPER_QUICK_API QuickChromePalette : public ChromePalette, public QQmlParserStatus { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO #ifdef QML_ANONYMOUS QML_ANONYMOUS #endif @@ -49,3 +52,5 @@ class FRAMELESSHELPER_QUICK_API QuickChromePalette : public ChromePalette, publi }; FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/include/FramelessHelper/Quick/quickmicamaterial.h b/include/FramelessHelper/Quick/quickmicamaterial.h index 8a0c7e8c..f81d9fd4 100644 --- a/include/FramelessHelper/Quick/quickmicamaterial.h +++ b/include/FramelessHelper/Quick/quickmicamaterial.h @@ -27,6 +27,8 @@ #include #include +#if FRAMELESSHELPER_CONFIG(mica_material) + FRAMELESSHELPER_BEGIN_NAMESPACE class QuickMicaMaterialPrivate; @@ -34,6 +36,7 @@ class QuickMicaMaterialPrivate; class FRAMELESSHELPER_QUICK_API QuickMicaMaterial : public QQuickPaintedItem { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO #ifdef QML_NAMED_ELEMENT QML_NAMED_ELEMENT(MicaMaterial) #endif @@ -84,3 +87,5 @@ class FRAMELESSHELPER_QUICK_API QuickMicaMaterial : public QQuickPaintedItem }; FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/include/FramelessHelper/Quick/quickwindowborder.h b/include/FramelessHelper/Quick/quickwindowborder.h index 135481e3..edc7124f 100644 --- a/include/FramelessHelper/Quick/quickwindowborder.h +++ b/include/FramelessHelper/Quick/quickwindowborder.h @@ -27,6 +27,8 @@ #include #include +#if FRAMELESSHELPER_CONFIG(border_painter) + FRAMELESSHELPER_BEGIN_NAMESPACE class QuickWindowBorderPrivate; @@ -34,6 +36,7 @@ class QuickWindowBorderPrivate; class FRAMELESSHELPER_QUICK_API QuickWindowBorder : public QQuickPaintedItem { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO #ifdef QML_NAMED_ELEMENT QML_NAMED_ELEMENT(WindowBorder) #endif @@ -89,3 +92,5 @@ public Q_SLOTS: }; FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/include/FramelessHelper/Widgets/framelessdialog.h b/include/FramelessHelper/Widgets/framelessdialog.h index d08a184f..0c547b59 100644 --- a/include/FramelessHelper/Widgets/framelessdialog.h +++ b/include/FramelessHelper/Widgets/framelessdialog.h @@ -27,6 +27,8 @@ #include #include +#if FRAMELESSHELPER_CONFIG(window) + FRAMELESSHELPER_BEGIN_NAMESPACE class FramelessDialogPrivate; @@ -34,6 +36,7 @@ class FramelessDialogPrivate; class FRAMELESSHELPER_WIDGETS_API FramelessDialog : public QDialog { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DECLARE_PRIVATE(FramelessDialog) Q_DISABLE_COPY_MOVE(FramelessDialog) @@ -46,3 +49,5 @@ class FRAMELESSHELPER_WIDGETS_API FramelessDialog : public QDialog }; FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/include/FramelessHelper/Widgets/framelesshelperwidgets_global.h b/include/FramelessHelper/Widgets/framelesshelperwidgets_global.h index 8ba3a18b..be83981d 100644 --- a/include/FramelessHelper/Widgets/framelesshelperwidgets_global.h +++ b/include/FramelessHelper/Widgets/framelesshelperwidgets_global.h @@ -40,10 +40,13 @@ FRAMELESSHELPER_BEGIN_NAMESPACE +FRAMELESSHELPER_WIDGETS_API void FramelessHelperWidgetsInitialize(); +FRAMELESSHELPER_WIDGETS_API void FramelessHelperWidgetsUninitialize(); + namespace FramelessHelper::Widgets { -FRAMELESSHELPER_WIDGETS_API void initialize(); -FRAMELESSHELPER_WIDGETS_API void uninitialize(); +inline void initialize() { FramelessHelperWidgetsInitialize(); } +inline void uninitialize() { FramelessHelperWidgetsUninitialize(); } } // namespace FramelessHelper::Widgets FRAMELESSHELPER_END_NAMESPACE diff --git a/include/FramelessHelper/Widgets/framelessmainwindow.h b/include/FramelessHelper/Widgets/framelessmainwindow.h index d5cd3fb4..5e4a52f4 100644 --- a/include/FramelessHelper/Widgets/framelessmainwindow.h +++ b/include/FramelessHelper/Widgets/framelessmainwindow.h @@ -27,6 +27,8 @@ #include #include +#if FRAMELESSHELPER_CONFIG(window) + FRAMELESSHELPER_BEGIN_NAMESPACE class FramelessMainWindowPrivate; @@ -34,6 +36,7 @@ class FramelessMainWindowPrivate; class FRAMELESSHELPER_WIDGETS_API FramelessMainWindow : public QMainWindow { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DECLARE_PRIVATE(FramelessMainWindow) Q_DISABLE_COPY_MOVE(FramelessMainWindow) Q_PROPERTY(bool hidden READ isHidden NOTIFY hiddenChanged FINAL) @@ -61,3 +64,5 @@ public Q_SLOTS: }; FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/include/FramelessHelper/Widgets/framelesswidget.h b/include/FramelessHelper/Widgets/framelesswidget.h index 4f1ae731..f9fb997a 100644 --- a/include/FramelessHelper/Widgets/framelesswidget.h +++ b/include/FramelessHelper/Widgets/framelesswidget.h @@ -27,6 +27,8 @@ #include #include +#if FRAMELESSHELPER_CONFIG(window) + FRAMELESSHELPER_BEGIN_NAMESPACE class FramelessWidgetPrivate; @@ -34,6 +36,7 @@ class FramelessWidgetPrivate; class FRAMELESSHELPER_WIDGETS_API FramelessWidget : public QWidget { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DECLARE_PRIVATE(FramelessWidget) Q_DISABLE_COPY_MOVE(FramelessWidget) Q_PROPERTY(bool hidden READ isHidden NOTIFY hiddenChanged FINAL) @@ -61,3 +64,5 @@ public Q_SLOTS: }; FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/include/FramelessHelper/Widgets/framelesswidgetshelper.h b/include/FramelessHelper/Widgets/framelesswidgetshelper.h index aaa9bd84..58128af3 100644 --- a/include/FramelessHelper/Widgets/framelesswidgetshelper.h +++ b/include/FramelessHelper/Widgets/framelesswidgetshelper.h @@ -29,13 +29,18 @@ FRAMELESSHELPER_BEGIN_NAMESPACE -class FramelessWidgetsHelperPrivate; +#if FRAMELESSHELPER_CONFIG(mica_material) class MicaMaterial; +#endif +#if FRAMELESSHELPER_CONFIG(border_painter) class WindowBorderPainter; +#endif +class FramelessWidgetsHelperPrivate; class FRAMELESSHELPER_WIDGETS_API FramelessWidgetsHelper : public QObject { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DECLARE_PRIVATE(FramelessWidgetsHelper) Q_DISABLE_COPY_MOVE(FramelessWidgetsHelper) Q_PROPERTY(QWidget* titleBarWidget READ titleBarWidget WRITE setTitleBarWidget NOTIFY titleBarWidgetChanged FINAL) @@ -56,8 +61,12 @@ class FRAMELESSHELPER_WIDGETS_API FramelessWidgetsHelper : public QObject Q_NODISCARD QWidget *window() const; Q_NODISCARD bool isContentExtendedIntoTitleBar() const; +#if FRAMELESSHELPER_CONFIG(mica_material) Q_NODISCARD MicaMaterial *micaMaterial() const; +#endif +#if FRAMELESSHELPER_CONFIG(border_painter) Q_NODISCARD WindowBorderPainter *windowBorder() const; +#endif Q_NODISCARD bool isReady() const; void waitForReady(); diff --git a/include/FramelessHelper/Widgets/private/framelessdialog_p.h b/include/FramelessHelper/Widgets/private/framelessdialog_p.h index 66b0a964..89d28173 100644 --- a/include/FramelessHelper/Widgets/private/framelessdialog_p.h +++ b/include/FramelessHelper/Widgets/private/framelessdialog_p.h @@ -26,6 +26,8 @@ #include +#if FRAMELESSHELPER_CONFIG(window) + FRAMELESSHELPER_BEGIN_NAMESPACE class FramelessDialog; @@ -34,6 +36,7 @@ class WidgetsSharedHelper; class FRAMELESSHELPER_WIDGETS_API FramelessDialogPrivate : public QObject { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DECLARE_PUBLIC(FramelessDialog) Q_DISABLE_COPY_MOVE(FramelessDialogPrivate) @@ -49,3 +52,5 @@ class FRAMELESSHELPER_WIDGETS_API FramelessDialogPrivate : public QObject }; FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/include/FramelessHelper/Widgets/private/framelessmainwindow_p.h b/include/FramelessHelper/Widgets/private/framelessmainwindow_p.h index f15ca176..3608af52 100644 --- a/include/FramelessHelper/Widgets/private/framelessmainwindow_p.h +++ b/include/FramelessHelper/Widgets/private/framelessmainwindow_p.h @@ -26,6 +26,8 @@ #include +#if FRAMELESSHELPER_CONFIG(window) + FRAMELESSHELPER_BEGIN_NAMESPACE class FramelessMainWindow; @@ -34,6 +36,7 @@ class WidgetsSharedHelper; class FRAMELESSHELPER_WIDGETS_API FramelessMainWindowPrivate : public QObject { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DECLARE_PUBLIC(FramelessMainWindow) Q_DISABLE_COPY_MOVE(FramelessMainWindowPrivate) @@ -50,3 +53,5 @@ class FRAMELESSHELPER_WIDGETS_API FramelessMainWindowPrivate : public QObject }; FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/include/FramelessHelper/Widgets/private/framelesswidget_p.h b/include/FramelessHelper/Widgets/private/framelesswidget_p.h index 4146011e..5a15e1f9 100644 --- a/include/FramelessHelper/Widgets/private/framelesswidget_p.h +++ b/include/FramelessHelper/Widgets/private/framelesswidget_p.h @@ -26,6 +26,8 @@ #include +#if FRAMELESSHELPER_CONFIG(window) + FRAMELESSHELPER_BEGIN_NAMESPACE class FramelessWidget; @@ -34,6 +36,7 @@ class WidgetsSharedHelper; class FRAMELESSHELPER_WIDGETS_API FramelessWidgetPrivate : public QObject { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DECLARE_PUBLIC(FramelessWidget) Q_DISABLE_COPY_MOVE(FramelessWidgetPrivate) @@ -50,3 +53,5 @@ class FRAMELESSHELPER_WIDGETS_API FramelessWidgetPrivate : public QObject }; FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h b/include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h index 2f81b497..224192a0 100644 --- a/include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h +++ b/include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h @@ -30,15 +30,20 @@ FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(mica_material) +class MicaMaterial; +#endif +#if FRAMELESSHELPER_CONFIG(border_painter) +class WindowBorderPainter; +#endif class FramelessWidgetsHelper; struct FramelessWidgetsHelperData; class WidgetsSharedHelper; -class MicaMaterial; -class WindowBorderPainter; class FRAMELESSHELPER_WIDGETS_API FramelessWidgetsHelperPrivate : public QObject { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DECLARE_PUBLIC(FramelessWidgetsHelper) Q_DISABLE_COPY_MOVE(FramelessWidgetsHelperPrivate) @@ -57,8 +62,12 @@ class FRAMELESSHELPER_WIDGETS_API FramelessWidgetsHelperPrivate : public QObject void setProperty(const char *name, const QVariant &value); Q_NODISCARD QVariant getProperty(const char *name, const QVariant &defaultValue = {}); +#if FRAMELESSHELPER_CONFIG(mica_material) Q_NODISCARD MicaMaterial *getMicaMaterialIfAny() const; +#endif +#if FRAMELESSHELPER_CONFIG(border_painter) Q_NODISCARD WindowBorderPainter *getWindowBorderIfAny() const; +#endif Q_NODISCARD static WidgetsSharedHelper *findOrCreateSharedHelper(QWidget *window); Q_NODISCARD static FramelessWidgetsHelper *findOrCreateFramelessHelper(QObject *object); diff --git a/include/FramelessHelper/Widgets/private/standardsystembutton_p.h b/include/FramelessHelper/Widgets/private/standardsystembutton_p.h index 91742d96..060e9f5a 100644 --- a/include/FramelessHelper/Widgets/private/standardsystembutton_p.h +++ b/include/FramelessHelper/Widgets/private/standardsystembutton_p.h @@ -27,6 +27,8 @@ #include #include +#if FRAMELESSHELPER_CONFIG(system_button) + FRAMELESSHELPER_BEGIN_NAMESPACE class StandardSystemButton; @@ -34,6 +36,7 @@ class StandardSystemButton; class FRAMELESSHELPER_WIDGETS_API StandardSystemButtonPrivate : public QObject { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DECLARE_PUBLIC(StandardSystemButton) Q_DISABLE_COPY_MOVE(StandardSystemButtonPrivate) @@ -59,3 +62,5 @@ class FRAMELESSHELPER_WIDGETS_API StandardSystemButtonPrivate : public QObject }; FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/include/FramelessHelper/Widgets/private/standardtitlebar_p.h b/include/FramelessHelper/Widgets/private/standardtitlebar_p.h index b1fd794b..27837752 100644 --- a/include/FramelessHelper/Widgets/private/standardtitlebar_p.h +++ b/include/FramelessHelper/Widgets/private/standardtitlebar_p.h @@ -32,15 +32,20 @@ QT_BEGIN_NAMESPACE class QMouseEvent; QT_END_NAMESPACE +#if FRAMELESSHELPER_CONFIG(titlebar) + FRAMELESSHELPER_BEGIN_NAMESPACE -class StandardTitleBar; +#if FRAMELESSHELPER_CONFIG(system_button) class StandardSystemButton; +#endif class ChromePalette; +class StandardTitleBar; class FRAMELESSHELPER_WIDGETS_API StandardTitleBarPrivate : public QObject { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DECLARE_PUBLIC(StandardTitleBar) Q_DISABLE_COPY_MOVE(StandardTitleBarPrivate) @@ -75,11 +80,11 @@ class FRAMELESSHELPER_WIDGETS_API StandardTitleBarPrivate : public QObject void initialize(); StandardTitleBar *q_ptr = nullptr; -#ifndef Q_OS_MACOS +#if (!defined(Q_OS_MACOS) && FRAMELESSHELPER_CONFIG(system_button)) StandardSystemButton *minimizeButton = nullptr; StandardSystemButton *maximizeButton = nullptr; StandardSystemButton *closeButton = nullptr; -#endif // Q_OS_MACOS +#endif QPointer window = nullptr; bool extended = false; Qt::Alignment labelAlignment = {}; @@ -96,3 +101,5 @@ class FRAMELESSHELPER_WIDGETS_API StandardTitleBarPrivate : public QObject }; FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/include/FramelessHelper/Widgets/private/widgetssharedhelper_p.h b/include/FramelessHelper/Widgets/private/widgetssharedhelper_p.h index b34a3db2..497b7dfd 100644 --- a/include/FramelessHelper/Widgets/private/widgetssharedhelper_p.h +++ b/include/FramelessHelper/Widgets/private/widgetssharedhelper_p.h @@ -29,14 +29,21 @@ FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(mica_material) class MicaMaterial; +#endif +#if FRAMELESSHELPER_CONFIG(border_painter) class WindowBorderPainter; +#endif class FRAMELESSHELPER_WIDGETS_API WidgetsSharedHelper : public QObject { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DISABLE_COPY_MOVE(WidgetsSharedHelper) +#if FRAMELESSHELPER_CONFIG(mica_material) Q_PROPERTY(bool micaEnabled READ isMicaEnabled WRITE setMicaEnabled NOTIFY micaEnabledChanged FINAL) +#endif public: explicit WidgetsSharedHelper(QObject *parent = nullptr); @@ -44,11 +51,14 @@ class FRAMELESSHELPER_WIDGETS_API WidgetsSharedHelper : public QObject void setup(QWidget *widget); +#if FRAMELESSHELPER_CONFIG(mica_material) Q_NODISCARD bool isMicaEnabled() const; void setMicaEnabled(const bool value); - Q_NODISCARD MicaMaterial *rawMicaMaterial() const; +#endif +#if FRAMELESSHELPER_CONFIG(border_painter) Q_NODISCARD WindowBorderPainter *rawWindowBorder() const; +#endif protected: Q_NODISCARD bool eventFilter(QObject *object, QEvent *event) override; @@ -58,24 +68,34 @@ private Q_SLOTS: void handleScreenChanged(QScreen *screen); private: +#if FRAMELESSHELPER_CONFIG(mica_material) void repaintMica(); +#endif +#if FRAMELESSHELPER_CONFIG(border_painter) void repaintBorder(); +#endif void emitCustomWindowStateSignals(); Q_SIGNALS: +#if FRAMELESSHELPER_CONFIG(mica_material) void micaEnabledChanged(); +#endif private: QPointer m_targetWidget; QPointer m_screen; + qreal m_screenDpr = qreal(0); + QMetaObject::Connection m_screenDpiChangeConnection = {}; + QMetaObject::Connection m_screenChangeConnection = {}; +#if FRAMELESSHELPER_CONFIG(mica_material) bool m_micaEnabled = false; MicaMaterial *m_micaMaterial = nullptr; QMetaObject::Connection m_micaRedrawConnection = {}; - qreal m_screenDpr = 0.0; - QMetaObject::Connection m_screenDpiChangeConnection = {}; +#endif +#if FRAMELESSHELPER_CONFIG(border_painter) WindowBorderPainter *m_borderPainter = nullptr; QMetaObject::Connection m_borderRepaintConnection = {}; - QMetaObject::Connection m_screenChangeConnection = {}; +#endif }; FRAMELESSHELPER_END_NAMESPACE diff --git a/include/FramelessHelper/Widgets/standardsystembutton.h b/include/FramelessHelper/Widgets/standardsystembutton.h index 16cf3695..cdaacd7e 100644 --- a/include/FramelessHelper/Widgets/standardsystembutton.h +++ b/include/FramelessHelper/Widgets/standardsystembutton.h @@ -27,6 +27,8 @@ #include #include +#if FRAMELESSHELPER_CONFIG(system_button) + FRAMELESSHELPER_BEGIN_NAMESPACE class StandardSystemButtonPrivate; @@ -34,6 +36,7 @@ class StandardSystemButtonPrivate; class FRAMELESSHELPER_WIDGETS_API StandardSystemButton : public QPushButton { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DECLARE_PRIVATE(StandardSystemButton) Q_DISABLE_COPY_MOVE(StandardSystemButton) Q_PROPERTY(Global::SystemButtonType buttonType READ buttonType WRITE setButtonType NOTIFY buttonTypeChanged FINAL) @@ -92,3 +95,5 @@ public Q_SLOTS: }; FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/include/FramelessHelper/Widgets/standardtitlebar.h b/include/FramelessHelper/Widgets/standardtitlebar.h index 7a40dad3..4ea1f499 100644 --- a/include/FramelessHelper/Widgets/standardtitlebar.h +++ b/include/FramelessHelper/Widgets/standardtitlebar.h @@ -25,8 +25,13 @@ #pragma once #include -#include + +#if FRAMELESSHELPER_CONFIG(titlebar) + #include +#if FRAMELESSHELPER_CONFIG(system_button) +# include +#endif #include FRAMELESSHELPER_BEGIN_NAMESPACE @@ -36,14 +41,15 @@ class StandardTitleBarPrivate; class FRAMELESSHELPER_WIDGETS_API StandardTitleBar : public QWidget { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DECLARE_PRIVATE(StandardTitleBar) Q_DISABLE_COPY_MOVE(StandardTitleBar) Q_PROPERTY(Qt::Alignment titleLabelAlignment READ titleLabelAlignment WRITE setTitleLabelAlignment NOTIFY titleLabelAlignmentChanged FINAL) -#ifndef Q_OS_MACOS +#if (!defined(Q_OS_MACOS) && FRAMELESSHELPER_CONFIG(system_button)) Q_PROPERTY(StandardSystemButton* minimizeButton READ minimizeButton CONSTANT FINAL) Q_PROPERTY(StandardSystemButton* maximizeButton READ maximizeButton CONSTANT FINAL) Q_PROPERTY(StandardSystemButton* closeButton READ closeButton CONSTANT FINAL) -#endif // Q_OS_MACOS +#endif Q_PROPERTY(bool extended READ isExtended WRITE setExtended NOTIFY extendedChanged FINAL) Q_PROPERTY(bool hideWhenClose READ isHideWhenClose WRITE setHideWhenClose NOTIFY hideWhenCloseChanged FINAL) Q_PROPERTY(ChromePalette* chromePalette READ chromePalette CONSTANT FINAL) @@ -59,7 +65,7 @@ class FRAMELESSHELPER_WIDGETS_API StandardTitleBar : public QWidget Q_NODISCARD Qt::Alignment titleLabelAlignment() const; void setTitleLabelAlignment(const Qt::Alignment value); -#ifndef Q_OS_MACOS +#if (!defined(Q_OS_MACOS) && FRAMELESSHELPER_CONFIG(system_button)) Q_NODISCARD StandardSystemButton *minimizeButton() const; Q_NODISCARD StandardSystemButton *maximizeButton() const; Q_NODISCARD StandardSystemButton *closeButton() const; @@ -104,3 +110,5 @@ class FRAMELESSHELPER_WIDGETS_API StandardTitleBar : public QWidget }; FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/msbuild/FramelessHelper.props b/msbuild/FramelessHelper.props index 29c2db21..748aa3e5 100644 --- a/msbuild/FramelessHelper.props +++ b/msbuild/FramelessHelper.props @@ -1,18 +1,18 @@  - $(MSBuildThisFileDirectory)lib64;$(MSBuildThisFileDirectory)lib64\debug;$(MSBuildThisFileDirectory)lib64\release;$(LibraryPath) + $(MSBuildThisFileDirectory)lib;$(MSBuildThisFileDirectory)lib\debug;$(MSBuildThisFileDirectory)lib\release;$(LibraryPath) $(MSBuildThisFileDirectory)include;$(MSBuildThisFileDirectory)include\FramelessHelper;$(MSBuildThisFileDirectory)include\FramelessHelper\Core;$(MSBuildThisFileDirectory)include\FramelessHelper\Core\private;$(MSBuildThisFileDirectory)include\FramelessHelper\Widgets;$(MSBuildThisFileDirectory)include\FramelessHelper\Widgets\private;$(MSBuildThisFileDirectory)include\FramelessHelper\Quick;$(MSBuildThisFileDirectory)include\FramelessHelper\Quick\private;$(QtHeaderSearchPath) - FRAMELESSHELPER_CORE_STATIC;FRAMELESSHELPER_WIDGETS_STATIC;FRAMELESSHELPER_QUICK_STATIC;%(PreprocessorDefinitions) + %(PreprocessorDefinitions) - FramelessHelperCored.lib;FramelessHelperWidgetsd.lib;FramelessHelperQuickd.lib;%(AdditionalDependencies); - FramelessHelperCore.lib;FramelessHelperWidgets.lib;FramelessHelperQuick.lib;%(AdditionalDependencies); + FramelessHelperCore64d.lib;FramelessHelperWidgets64d.lib;FramelessHelperQuick64d.lib;%(AdditionalDependencies); + FramelessHelperCore64.lib;FramelessHelperWidgets64.lib;FramelessHelperQuick64.lib;%(AdditionalDependencies); diff --git a/qmake/core.pri b/qmake/core.pri index 34245dd6..dcefa4d0 100644 --- a/qmake/core.pri +++ b/qmake/core.pri @@ -26,6 +26,7 @@ DEPENDPATH += \ HEADERS += \ $$CORE_EXTRA_INC_DIR/framelesshelper.version \ + $$CORE_EXTRA_INC_DIR/framelesshelper.config \ $$CORE_PUB_INC_DIR/chromepalette.h \ $$CORE_PUB_INC_DIR/framelesshelper_qt.h \ $$CORE_PUB_INC_DIR/framelesshelpercore_global.h \ diff --git a/include/FramelessHelper/Quick/quickimageitem.h b/qmake/inc/core/framelesshelper.config similarity index 55% rename from include/FramelessHelper/Quick/quickimageitem.h rename to qmake/inc/core/framelesshelper.config index f2f08e19..f1dfdef5 100644 --- a/include/FramelessHelper/Quick/quickimageitem.h +++ b/qmake/inc/core/framelesshelper.config @@ -22,44 +22,28 @@ * SOFTWARE. */ -#pragma once - -#include -#include - -FRAMELESSHELPER_BEGIN_NAMESPACE - -class QuickImageItemPrivate; - -class FRAMELESSHELPER_QUICK_API QuickImageItem : public QQuickPaintedItem -{ - Q_OBJECT -#ifdef QML_NAMED_ELEMENT - QML_NAMED_ELEMENT(ImageItem) -#endif - Q_DISABLE_COPY_MOVE(QuickImageItem) - Q_DECLARE_PRIVATE(QuickImageItem) - - Q_PROPERTY(QVariant source READ source WRITE setSource NOTIFY sourceChanged FINAL) +// Generated automatically by CMake. +// WARNING! DO NOT EDIT THIS FILE MANUALLY! +// ALL CHANGES WILL BE LOST AFTER RE-CONFIGURING! +// Also please do not include this file directly, +// it's designed to be included by FramelessHelper's own headers. -public: - explicit QuickImageItem(QQuickItem *parent = nullptr); - ~QuickImageItem() override; - - void paint(QPainter *painter) override; - - Q_NODISCARD QVariant source() const; - void setSource(const QVariant &value); - -protected: - void classBegin() override; - void componentComplete() override; - -Q_SIGNALS: - void sourceChanged(); - -private: - QScopedPointer d_ptr; -}; +#pragma once -FRAMELESSHELPER_END_NAMESPACE +#ifndef _FRAMELESSHELPER_CONFIG_DEFINED_ +#define _FRAMELESSHELPER_CONFIG_DEFINED_ + +#define FRAMELESSHELPER_FEATURE_static_build 1 +#define FRAMELESSHELPER_FEATURE_widgets 1 +#define FRAMELESSHELPER_FEATURE_quick 1 +#define FRAMELESSHELPER_FEATURE_debug_output -1 +#define FRAMELESSHELPER_FEATURE_bundle_resource 1 +#define FRAMELESSHELPER_FEATURE_private_qt 1 +#define FRAMELESSHELPER_FEATURE_window 1 +#define FRAMELESSHELPER_FEATURE_titlebar 1 +#define FRAMELESSHELPER_FEATURE_translation 1 +#define FRAMELESSHELPER_FEATURE_mica_material 1 +#define FRAMELESSHELPER_FEATURE_border_painter 1 +#define FRAMELESSHELPER_FEATURE_system_button 1 + +#endif // _FRAMELESSHELPER_CONFIG_DEFINED_ diff --git a/qmake/inc/core/framelesshelper.version b/qmake/inc/core/framelesshelper.version index 494ba4e0..bc58718a 100644 --- a/qmake/inc/core/framelesshelper.version +++ b/qmake/inc/core/framelesshelper.version @@ -41,4 +41,11 @@ [[maybe_unused]] inline constexpr const char FRAMELESSHELPER_COMMIT_STR[] = "UNKNOWN"; [[maybe_unused]] inline constexpr const char FRAMELESSHELPER_COMPILE_DATETIME_STR[] = "UNKNOWN"; +#define __FRAMELESSHELPER_VERSION_MAJOR__ 2 +#define __FRAMELESSHELPER_VERSION_MINOR__ 5 +#define __FRAMELESSHELPER_VERSION_PATCH__ 0 +//#define __FRAMELESSHELPER_VERSION_TWEAK__ 0 +#define __FRAMELESSHELPER_VERSION__ 0x02050000 +#define __FRAMELESSHELPER__ 0x02050000 + #endif // _FRAMELESSHELPER_VERSION_DEFINED_ diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index e035a35d..f1ac6297 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -50,6 +50,55 @@ if(UNIX AND NOT APPLE) endif() endif() +set(FRAMELESSHELPER_FEATURE_static_build "-1") +if(FRAMELESSHELPER_BUILD_STATIC) + set(FRAMELESSHELPER_FEATURE_static_build "1") +endif() +set(FRAMELESSHELPER_FEATURE_widgets "-1") +if(FRAMELESSHELPER_BUILD_WIDGETS) + set(FRAMELESSHELPER_FEATURE_widgets "1") +endif() +set(FRAMELESSHELPER_FEATURE_quick "-1") +if(FRAMELESSHELPER_BUILD_QUICK) + set(FRAMELESSHELPER_FEATURE_quick "1") +endif() +set(FRAMELESSHELPER_FEATURE_debug_output "-1") +if(NOT FRAMELESSHELPER_NO_DEBUG_OUTPUT) + set(FRAMELESSHELPER_FEATURE_debug_output "1") +endif() +set(FRAMELESSHELPER_FEATURE_bundle_resource "-1") +if(NOT FRAMELESSHELPER_NO_BUNDLE_RESOURCE) + set(FRAMELESSHELPER_FEATURE_bundle_resource "1") +endif() +set(FRAMELESSHELPER_FEATURE_private_qt "-1") +if(NOT FRAMELESSHELPER_NO_PRIVATE) + set(FRAMELESSHELPER_FEATURE_private_qt "1") +endif() +set(FRAMELESSHELPER_FEATURE_window "-1") +if(NOT FRAMELESSHELPER_NO_WINDOW) + set(FRAMELESSHELPER_FEATURE_window "1") +endif() +set(FRAMELESSHELPER_FEATURE_titlebar "-1") +if(NOT FRAMELESSHELPER_NO_TITLEBAR) + set(FRAMELESSHELPER_FEATURE_titlebar "1") +endif() +set(FRAMELESSHELPER_FEATURE_translation "-1") +if(NOT FRAMELESSHELPER_NO_TRANSLATION) + set(FRAMELESSHELPER_FEATURE_translation "1") +endif() +set(FRAMELESSHELPER_FEATURE_mica_material "-1") +if(NOT FRAMELESSHELPER_NO_MICA_MATERIAL) + set(FRAMELESSHELPER_FEATURE_mica_material "1") +endif() +set(FRAMELESSHELPER_FEATURE_border_painter "-1") +if(NOT FRAMELESSHELPER_NO_BORDER_PAINTER) + set(FRAMELESSHELPER_FEATURE_border_painter "1") +endif() +set(FRAMELESSHELPER_FEATURE_system_button "-1") +if(NOT FRAMELESSHELPER_NO_SYSTEM_BUTTON) + set(FRAMELESSHELPER_FEATURE_system_button "1") +endif() + set(SUB_MODULE Core) set(SUB_MODULE_FULL_NAME ${PROJECT_NAME}${SUB_MODULE}) set(SUB_MODULE_TARGET ${SUB_MODULE_FULL_NAME}) @@ -59,16 +108,16 @@ set(INCLUDE_PREFIX ../../include/${SUB_MODULE_PATH}) configure_file(framelesshelper.version.in ${CMAKE_CURRENT_BINARY_DIR}/framelesshelper.version @ONLY) +configure_file(framelesshelper.config.in + ${CMAKE_CURRENT_BINARY_DIR}/framelesshelper.config @ONLY) set(PUBLIC_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/framelesshelper.version + ${CMAKE_CURRENT_BINARY_DIR}/framelesshelper.config ${INCLUDE_PREFIX}/framelesshelpercore_global.h ${INCLUDE_PREFIX}/framelesshelper_qt.h ${INCLUDE_PREFIX}/framelessmanager.h ${INCLUDE_PREFIX}/utils.h - ${INCLUDE_PREFIX}/chromepalette.h - ${INCLUDE_PREFIX}/micamaterial.h - ${INCLUDE_PREFIX}/windowborderpainter.h ) set(PUBLIC_HEADERS_ALIAS @@ -76,18 +125,12 @@ set(PUBLIC_HEADERS_ALIAS ${INCLUDE_PREFIX}/FramelessHelper_Qt ${INCLUDE_PREFIX}/FramelessManager ${INCLUDE_PREFIX}/Utils - ${INCLUDE_PREFIX}/ChromePalette - ${INCLUDE_PREFIX}/MicaMaterial - ${INCLUDE_PREFIX}/WindowBorderPainter ) set(PRIVATE_HEADERS ${INCLUDE_PREFIX}/private/framelessmanager_p.h ${INCLUDE_PREFIX}/private/framelessconfig_p.h ${INCLUDE_PREFIX}/private/sysapiloader_p.h - ${INCLUDE_PREFIX}/private/chromepalette_p.h - ${INCLUDE_PREFIX}/private/micamaterial_p.h - ${INCLUDE_PREFIX}/private/windowborderpainter_p.h ${INCLUDE_PREFIX}/private/framelesshelpercore_global_p.h ${INCLUDE_PREFIX}/private/versionnumber_p.h ${INCLUDE_PREFIX}/private/scopeguard_p.h @@ -99,10 +142,7 @@ set(SOURCES framelessmanager.cpp framelessconfig.cpp sysapiloader.cpp - chromepalette.cpp framelesshelpercore_global.cpp - micamaterial.cpp - windowborderpainter.cpp ) if(WIN32) @@ -140,6 +180,27 @@ elseif(UNIX) ) endif() +if(NOT FRAMELESSHELPER_NO_TITLEBAR) + list(APPEND PUBLIC_HEADERS ${INCLUDE_PREFIX}/chromepalette.h) + list(APPEND PUBLIC_HEADERS_ALIAS ${INCLUDE_PREFIX}/ChromePalette) + list(APPEND PRIVATE_HEADERS ${INCLUDE_PREFIX}/private/chromepalette_p.h) + list(APPEND SOURCES chromepalette.cpp) +endif() + +if(NOT FRAMELESSHELPER_NO_MICA_MATERIAL) + list(APPEND PUBLIC_HEADERS ${INCLUDE_PREFIX}/micamaterial.h) + list(APPEND PUBLIC_HEADERS_ALIAS ${INCLUDE_PREFIX}/MicaMaterial) + list(APPEND PRIVATE_HEADERS ${INCLUDE_PREFIX}/private/micamaterial_p.h) + list(APPEND SOURCES micamaterial.cpp) +endif() + +if(NOT FRAMELESSHELPER_NO_BORDER_PAINTER) + list(APPEND PUBLIC_HEADERS ${INCLUDE_PREFIX}/windowborderpainter.h) + list(APPEND PUBLIC_HEADERS_ALIAS ${INCLUDE_PREFIX}/WindowBorderPainter) + list(APPEND PRIVATE_HEADERS ${INCLUDE_PREFIX}/private/windowborderpainter_p.h) + list(APPEND SOURCES windowborderpainter.cpp) +endif() + if(WIN32 AND NOT FRAMELESSHELPER_BUILD_STATIC) set(__rc_path "${CMAKE_CURRENT_BINARY_DIR}/${SUB_MODULE_FULL_NAME}.rc") if(NOT EXISTS "${__rc_path}") @@ -172,6 +233,7 @@ add_library(${PROJECT_NAME}::${SUB_MODULE_FULL_NAME} ALIAS ${SUB_MODULE_TARGET}) set_target_properties(${SUB_MODULE_TARGET} PROPERTIES VERSION "${PROJECT_VERSION}" SOVERSION "${PROJECT_VERSION_MAJOR}" + OUTPUT_NAME "${SUB_MODULE_TARGET}${FRAMELESSHELPER_64BIT_POSTFIX}" ) set(__export_targets ${SUB_MODULE_TARGET}) @@ -203,24 +265,6 @@ if(NOT FRAMELESSHELPER_NO_BUNDLE_RESOURCE) endif() endif() -if(FRAMELESSHELPER_BUILD_STATIC) - target_compile_definitions(${SUB_MODULE_TARGET} PUBLIC FRAMELESSHELPER_CORE_STATIC) -endif() - -if(FRAMELESSHELPER_NO_DEBUG_OUTPUT) - target_compile_definitions(${SUB_MODULE_TARGET} PRIVATE - FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT - ) -endif() - -if(FRAMELESSHELPER_NO_BUNDLE_RESOURCE) - target_compile_definitions(${SUB_MODULE_TARGET} PUBLIC FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE) -endif() - -if(FRAMELESSHELPER_NO_PRIVATE) - target_compile_definitions(${SUB_MODULE_TARGET} PUBLIC FRAMELESSHELPER_CORE_NO_PRIVATE) -endif() - if(DEFINED FRAMELESSHELPER_NAMESPACE) if("x${FRAMELESSHELPER_NAMESPACE}" STREQUAL "x") message(FATAL_ERROR "FRAMELESSHELPER_NAMESPACE can't be empty!") diff --git a/src/core/chromepalette.cpp b/src/core/chromepalette.cpp index 45fd7fc7..bd191c94 100644 --- a/src/core/chromepalette.cpp +++ b/src/core/chromepalette.cpp @@ -24,24 +24,26 @@ #include "chromepalette.h" #include "chromepalette_p.h" + +#if FRAMELESSHELPER_CONFIG(titlebar) + #include "framelessmanager.h" #include "utils.h" #include FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcChromePalette, "wangwenx190.framelesshelper.core.chromepalette") - -#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcChromePalette) # define DEBUG qCDebug(lcChromePalette) # define WARNING qCWarning(lcChromePalette) # define CRITICAL qCCritical(lcChromePalette) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; @@ -428,3 +430,5 @@ void ChromePalette::resetCloseButtonPressColor() } FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/src/core/framelessconfig.cpp b/src/core/framelessconfig.cpp index bf7e704e..379788d4 100644 --- a/src/core/framelessconfig.cpp +++ b/src/core/framelessconfig.cpp @@ -33,18 +33,17 @@ FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcFramelessConfig, "wangwenx190.framelesshelper.core.framelessconfig") - -#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcFramelessConfig) # define DEBUG qCDebug(lcFramelessConfig) # define WARNING qCWarning(lcFramelessConfig) # define CRITICAL qCCritical(lcFramelessConfig) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; @@ -81,10 +80,15 @@ struct FramelessConfigData Q_GLOBAL_STATIC(FramelessConfigData, g_framelessConfigData) +#if FRAMELESSHELPER_CONFIG(debug_output) static inline void warnInappropriateOptions() { const FramelessConfig * const cfg = FramelessConfig::instance(); -#ifndef Q_OS_WINDOWS +#ifdef Q_OS_WINDOWS + if (cfg->isSet(Option::DisableWindowsSnapLayout)) { + WARNING << "Option::DisableWindowsSnapLayout is deprecated and will removed in a future version. It has not effect now."; + } +#else if (cfg->isSet(Option::UseCrossPlatformQtImplementation)) { WARNING << "Option::UseCrossPlatformQtImplementation is default on non-Windows platforms."; } @@ -108,6 +112,7 @@ static inline void warnInappropriateOptions() WARNING << "Option::WindowUseRoundCorners has not been implemented yet."; } } +#endif FramelessConfig::FramelessConfig(QObject *parent) : QObject(parent) { @@ -143,8 +148,9 @@ void FramelessConfig::reload(const bool force) g_framelessConfigData()->options.at(i) = (envVar || cfgFile); } g_framelessConfigData()->loaded = true; - +#if FRAMELESSHELPER_CONFIG(debug_output) QTimer::singleShot(0, this, [](){ warnInappropriateOptions(); }); +#endif } void FramelessConfig::set(const Option option, const bool on) diff --git a/src/core/framelesshelper.config.in b/src/core/framelesshelper.config.in new file mode 100644 index 00000000..e7ba7525 --- /dev/null +++ b/src/core/framelesshelper.config.in @@ -0,0 +1,49 @@ +/* + * MIT License + * + * Copyright (C) 2021-2023 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. + */ + +// Generated automatically by CMake. +// WARNING! DO NOT EDIT THIS FILE MANUALLY! +// ALL CHANGES WILL BE LOST AFTER RE-CONFIGURING! +// Also please do not include this file directly, +// it's designed to be included by FramelessHelper's own headers. + +#pragma once + +#ifndef _FRAMELESSHELPER_CONFIG_DEFINED_ +#define _FRAMELESSHELPER_CONFIG_DEFINED_ + +#define FRAMELESSHELPER_FEATURE_static_build @FRAMELESSHELPER_FEATURE_static_build@ +#define FRAMELESSHELPER_FEATURE_widgets @FRAMELESSHELPER_FEATURE_widgets@ +#define FRAMELESSHELPER_FEATURE_quick @FRAMELESSHELPER_FEATURE_quick@ +#define FRAMELESSHELPER_FEATURE_debug_output @FRAMELESSHELPER_FEATURE_debug_output@ +#define FRAMELESSHELPER_FEATURE_bundle_resource @FRAMELESSHELPER_FEATURE_bundle_resource@ +#define FRAMELESSHELPER_FEATURE_private_qt @FRAMELESSHELPER_FEATURE_private_qt@ +#define FRAMELESSHELPER_FEATURE_window @FRAMELESSHELPER_FEATURE_window@ +#define FRAMELESSHELPER_FEATURE_titlebar @FRAMELESSHELPER_FEATURE_titlebar@ +#define FRAMELESSHELPER_FEATURE_translation @FRAMELESSHELPER_FEATURE_translation@ +#define FRAMELESSHELPER_FEATURE_mica_material @FRAMELESSHELPER_FEATURE_mica_material@ +#define FRAMELESSHELPER_FEATURE_border_painter @FRAMELESSHELPER_FEATURE_border_painter@ +#define FRAMELESSHELPER_FEATURE_system_button @FRAMELESSHELPER_FEATURE_system_button@ + +#endif // _FRAMELESSHELPER_CONFIG_DEFINED_ diff --git a/src/core/framelesshelper.version.in b/src/core/framelesshelper.version.in index 061be9d1..a92d1715 100644 --- a/src/core/framelesshelper.version.in +++ b/src/core/framelesshelper.version.in @@ -41,4 +41,11 @@ [[maybe_unused]] inline constexpr const char FRAMELESSHELPER_COMMIT_STR[] = "@PROJECT_VERSION_COMMIT@"; [[maybe_unused]] inline constexpr const char FRAMELESSHELPER_COMPILE_DATETIME_STR[] = "@PROJECT_COMPILE_DATETIME@"; +#define __FRAMELESSHELPER_VERSION_MAJOR__ @PROJECT_VERSION_MAJOR@ +#define __FRAMELESSHELPER_VERSION_MINOR__ @PROJECT_VERSION_MINOR@ +#define __FRAMELESSHELPER_VERSION_PATCH__ @PROJECT_VERSION_PATCH@ +//#define __FRAMELESSHELPER_VERSION_TWEAK__ @PROJECT_VERSION_TWEAK@ +#define __FRAMELESSHELPER_VERSION__ @PROJECT_VERSION_HEX@ +#define __FRAMELESSHELPER__ @PROJECT_VERSION_HEX@ + #endif // _FRAMELESSHELPER_VERSION_DEFINED_ diff --git a/src/core/framelesshelper_qt.cpp b/src/core/framelesshelper_qt.cpp index e854f9b2..a5e663a5 100644 --- a/src/core/framelesshelper_qt.cpp +++ b/src/core/framelesshelper_qt.cpp @@ -34,18 +34,17 @@ FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcFramelessHelperQt, "wangwenx190.framelesshelper.core.impl.qt") - -#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcFramelessHelperQt) # define DEBUG qCDebug(lcFramelessHelperQt) # define WARNING qCWarning(lcFramelessHelperQt) # define CRITICAL qCCritical(lcFramelessHelperQt) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; @@ -86,9 +85,9 @@ void FramelessHelperQt::addWindow(FramelessParamsConst params) const auto shouldApplyFramelessFlag = []() -> bool { #ifdef Q_OS_MACOS return false; -#elif defined(Q_OS_LINUX) +#elif (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)) return !Utils::isCustomDecorationSupported(); -#else // Windows +#elif defined(Q_OS_WINDOWS) return true; #endif // Q_OS_MACOS }(); @@ -98,14 +97,14 @@ void FramelessHelperQt::addWindow(FramelessParamsConst params) if (shouldApplyFramelessFlag) { params->setWindowFlags(params->getWindowFlags() | Qt::FramelessWindowHint); } else { -#ifdef Q_OS_LINUX +#if (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)) std::ignore = Utils::tryHideSystemTitleBar(windowId, true); #elif defined(Q_OS_MACOS) Utils::setSystemTitleBarVisible(windowId, false); #endif // Q_OS_LINUX } window->installEventFilter(data.eventFilter); - FramelessHelper::Core::setApplicationOSThemeAware(); + FramelessHelperEnableThemeAware(); } void FramelessHelperQt::removeWindow(const WId windowId) diff --git a/src/core/framelesshelper_win.cpp b/src/core/framelesshelper_win.cpp index 3889717d..6802548a 100644 --- a/src/core/framelesshelper_win.cpp +++ b/src/core/framelesshelper_win.cpp @@ -23,6 +23,9 @@ */ #include "framelesshelper_win.h" + +#ifdef Q_OS_WINDOWS + #include "framelessmanager.h" #include "framelessmanager_p.h" #include "framelessconfig_p.h" @@ -42,18 +45,17 @@ FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcFramelessHelperWin, "wangwenx190.framelesshelper.core.impl.win") - -#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcFramelessHelperWin) # define DEBUG qCDebug(lcFramelessHelperWin) # define WARNING qCWarning(lcFramelessHelperWin) # define CRITICAL qCCritical(lcFramelessHelperWin) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; @@ -68,7 +70,7 @@ FRAMELESSHELPER_STRING_CONSTANT(GetClientRect) #ifdef Q_PROCESSOR_X86_64 FRAMELESSHELPER_STRING_CONSTANT(GetWindowLongPtrW) FRAMELESSHELPER_STRING_CONSTANT(SetWindowLongPtrW) -#else // Q_PROCESSOR_X86_64 +#else // !Q_PROCESSOR_X86_64 // WinUser.h defines G/SetClassLongPtr as G/SetClassLong due to the // "Ptr" suffixed APIs are not available on 32-bit platforms, so we // have to add the following workaround. Undefine the macros and then @@ -90,7 +92,7 @@ FRAMELESSHELPER_STRING_CONSTANT(SetWindowPlacement) enum class WindowPart : quint8 { - NotInterested, + Outside, ClientArea, ChromeButton, ResizeBorder, @@ -172,7 +174,7 @@ Q_GLOBAL_STATIC(FramelessWin32HelperInternal, g_framelessWin32HelperData) default: break; } - return WindowPart::NotInterested; + return WindowPart::Outside; } [[nodiscard]] static inline constexpr bool isTaggedMessage(const WPARAM wParam) @@ -180,7 +182,7 @@ Q_GLOBAL_STATIC(FramelessWin32HelperInternal, g_framelessWin32HelperData) return (wParam == kMessageTag); } -[[nodiscard]] static inline bool listenForMouseLeave(const HWND hWnd, const bool nonClient) +[[nodiscard]] static inline bool requestForMouseLeaveMessage(const HWND hWnd, const bool nonClient) { Q_ASSERT(hWnd); if (!hWnd) { @@ -251,7 +253,7 @@ void FramelessHelperWin::addWindow(FramelessParamsConst params) } if (WindowsVersionHelper::isWin10RS1OrGreater()) { // Tell DWM we may need dark theme non-client area (title bar & frame border). - FramelessHelper::Core::setApplicationOSThemeAware(); + FramelessHelperEnableThemeAware(); if (WindowsVersionHelper::isWin10RS5OrGreater()) { const bool dark = (FramelessManager::instance()->systemTheme() == SystemTheme::Dark); const auto isWidget = [params]() -> bool { @@ -312,14 +314,16 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me return false; } const UINT uMsg = msg->message; + + // We should skip these messages otherwise we will get crashes. // WM_QUIT won't be posted to the WindowProc function. switch (uMsg) { case WM_CLOSE: case WM_DESTROY: case WM_NCDESTROY: - // undocumented messages - case WM_UNREGISTER_WINDOW_SERVICES: + // Undocumented messages: case WM_UAHDESTROYWINDOW: + case WM_UNREGISTER_WINDOW_SERVICES: return false; default: break; @@ -353,8 +357,8 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me }; #endif // (QT_VERSION < QT_VERSION_CHECK(6, 5, 1)) - const auto emulateClientAreaMessage = [hWnd, uMsg, wParam, lParam](const std::optional overrideMessage = std::nullopt) -> void { - auto myMsg = overrideMessage.value_or(uMsg); + const auto emulateClientAreaMessage = [hWnd, uMsg, wParam, lParam](const std::optional &overrideMessage = std::nullopt) -> void { + const int myMsg = overrideMessage.value_or(uMsg); const auto wparam = [myMsg, wParam]() -> WPARAM { if (myMsg == WM_NCMOUSELEAVE) { return kMessageTag; @@ -824,9 +828,9 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me // Even if the mouse is inside the chrome button area now, we should still allow the user // to be able to resize the window with the top or right window border, this is also the // normal behavior of a native Win32 window. - static constexpr const int kTopBorderSize = 1; - const bool isTop = (nativeLocalPos.y <= kTopBorderSize); - const bool isRight = (nativeLocalPos.x >= (clientWidth - kTopBorderSize)); + static constexpr const int kBorderSize = 1; + const bool isTop = (nativeLocalPos.y <= kBorderSize); + const bool isRight = (nativeLocalPos.x >= (clientWidth - kBorderSize)); if (isTop || isRight) { if (isTop && isRight) { *result = HTTOPRIGHT; @@ -985,11 +989,10 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me case WM_MOUSEMOVE: { const WindowPart previousWindowPart = getHittedWindowPart(data.hitTestResult.first.value_or(HTNOWHERE)); const WindowPart currentWindowPart = getHittedWindowPart(data.hitTestResult.second.value_or(HTNOWHERE)); - if (previousWindowPart == WindowPart::ChromeButton && currentWindowPart == WindowPart::ClientArea) { - std::ignore = listenForMouseLeave(hWnd, false); + if ((previousWindowPart == WindowPart::ChromeButton) && (currentWindowPart == WindowPart::ClientArea)) { + std::ignore = requestForMouseLeaveMessage(hWnd, false); } - break; - } + } break; case WM_NCMOUSEMOVE: case WM_NCLBUTTONDOWN: case WM_NCLBUTTONUP: @@ -1010,30 +1013,25 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me #endif case WM_NCMOUSEHOVER: case WM_NCMOUSELEAVE: { - // For future code readers: - // The following code is not workaround anything, it's just try to emulate the original - // behavior of a native Win32 window. const WindowPart previousWindowPart = getHittedWindowPart(data.hitTestResult.first.value_or(HTNOWHERE)); const WindowPart currentWindowPart = getHittedWindowPart(data.hitTestResult.second.value_or(HTNOWHERE)); if (uMsg == WM_NCMOUSELEAVE) { - if (previousWindowPart == WindowPart::ChromeButton && currentWindowPart == WindowPart::NotInterested) { - // If current window part is chrome button, it indicates that we must have clicked + if ((previousWindowPart == WindowPart::ChromeButton) && (currentWindowPart == WindowPart::Outside)) { + // If current window part is chrome button, it indicates that we must have clicked // the minimize button or maximize button, we also should send the client leave // message to Qt. emulateClientAreaMessage(WM_NCMOUSELEAVE); } - if (currentWindowPart == WindowPart::NotInterested) { - // The mouse is leaving window from non-client area, clear window part caches - auto &hitTestResult = muData.hitTestResult; - hitTestResult.first.reset(); - hitTestResult.second.reset(); + if (currentWindowPart == WindowPart::Outside) { + // The mouse is leaving the window from the non-client area, clear window part cache. + muData.hitTestResult = {}; - // Notice: we're not going to clear window part caches when the mouse leaves window + // Notice: we're not going to clear window part cache when the mouse leaves window // from client area, which means we will get previous window part as HTCLIENT if // the mouse leaves window from client area and enters window from non-client area, // but it has no bad effect. - + std::ignore = data.params.resetQtGrabbedControl(); } } else { @@ -1047,7 +1045,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me || (currentWindowPart == WindowPart::FixedBorder))) { emulateClientAreaMessage(WM_NCMOUSELEAVE); } - + // We need to make sure we get the correct window part when a WM_NCMOUSELEAVE come, // so we reset current window part to null when we receive a WM_NCMOUSEMOVE. @@ -1064,9 +1062,9 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me if (currentWindowPart == WindowPart::ChromeButton) { emulateClientAreaMessage(); if (uMsg == WM_NCMOUSEMOVE) { - *result = ::DefWindowProcW(hWnd, uMsg, wParam, lParam); + *result = ::DefWindowProcW(hWnd, WM_NCMOUSEMOVE, wParam, lParam); } else { - *result = ((uMsg >= WM_NCXBUTTONDOWN) && (uMsg <= WM_NCXBUTTONDBLCLK)) ? TRUE : FALSE; + *result = (((uMsg >= WM_NCXBUTTONDOWN) && (uMsg <= WM_NCXBUTTONDBLCLK)) ? TRUE : FALSE); } return true; } @@ -1155,7 +1153,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me if (filteredWParam == WA_INACTIVE) { if (getHittedWindowPart(data.hitTestResult.second.value_or(HTNOWHERE)) == WindowPart::ChromeButton) { emulateClientAreaMessage(WM_NCMOUSELEAVE); - + // Clear window part cache auto &hitTestResult = muData.hitTestResult; hitTestResult.first.reset(); @@ -1167,7 +1165,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me case WM_INITMENU:{ if (getHittedWindowPart(data.hitTestResult.second.value_or(HTNOWHERE)) == WindowPart::ChromeButton) { emulateClientAreaMessage(WM_NCMOUSELEAVE); - + // Clear window part cache auto &hitTestResult = muData.hitTestResult; hitTestResult.first.reset(); @@ -1179,7 +1177,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me if (wParam == SIZE_MAXIMIZED || wParam == SIZE_MINIMIZED) { if (getHittedWindowPart(data.hitTestResult.second.value_or(HTNOWHERE)) == WindowPart::ChromeButton) { emulateClientAreaMessage(WM_NCMOUSELEAVE); - + // Clear window part cache auto &hitTestResult = muData.hitTestResult; hitTestResult.first.reset(); @@ -1349,3 +1347,5 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me } FRAMELESSHELPER_END_NAMESPACE + +#endif // Q_OS_WINDOWS diff --git a/src/core/framelesshelpercore_global.cpp b/src/core/framelesshelpercore_global.cpp index 014f9b8a..8a2d9175 100644 --- a/src/core/framelesshelpercore_global.cpp +++ b/src/core/framelesshelpercore_global.cpp @@ -96,31 +96,30 @@ QDebug operator<<(QDebug d, const FRAMELESSHELPER_PREPEND_NAMESPACE(Global)::Dpi QT_END_NAMESPACE #endif // QT_NO_DEBUG_STREAM -#ifndef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE +#if FRAMELESSHELPER_CONFIG(bundle_resource) // The "Q_INIT_RESOURCE()" macro can't be used within a namespace, // so we wrap it into a separate function outside of the namespace and // then call it instead inside the namespace, that's also the recommended // workaround provided by Qt's official documentation. -void framelesshelpercore_initResource() +void FramelessHelperCoreInitResource() { Q_INIT_RESOURCE(framelesshelpercore); } -#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE +#endif // FRAMELESSHELPER_CONFIG(bundle_resource) FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcCoreGlobal, "wangwenx190.framelesshelper.core.global") - -#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcCoreGlobal) # define DEBUG qCDebug(lcCoreGlobal) # define WARNING qCWarning(lcCoreGlobal) # define CRITICAL qCCritical(lcCoreGlobal) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; @@ -129,22 +128,7 @@ using namespace Global; static_assert(std::size(WindowsVersions) == (static_cast(WindowsVersion::Latest) + 1)); #endif -void registerInitializeHook(const InitializeHookCallback &cb) -{ - Q_UNUSED(cb); - WARNING << "registerInitializeHook: This function is deprecated and will be removed in a future version. Please consider using Qt's official Q_COREAPP_STARTUP_FUNCTION() macro instead."; -} - -void registerUninitializeHook(const UninitializeHookCallback &cb) -{ - Q_UNUSED(cb); - WARNING << "registerUninitializeHook: This function is deprecated and will be removed in a future version. Please consider using Qt's official qAddPostRoutine() function instead."; -} - -namespace FramelessHelper::Core -{ - -void initialize() +void FramelessHelperCoreInitialize() { static bool inited = false; if (inited) { @@ -152,9 +136,9 @@ void initialize() } inited = true; - outputLogo(); + FramelessHelperPrintLogo(); -#ifdef Q_OS_LINUX +#if (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)) // Qt's Wayland experience is not good, so we force the XCB backend here. // TODO: Remove this hack once Qt's Wayland implementation is good enough. // We are setting the preferred QPA backend, so we have to set it early @@ -199,7 +183,7 @@ void initialize() #endif } -void uninitialize() +void FramelessHelperCoreUninitialize() { static bool uninited = false; if (uninited) { @@ -208,7 +192,7 @@ void uninitialize() uninited = true; } -VersionInfo version() +VersionInfo FramelessHelperVersion() { static const auto result = []() -> VersionInfo { const auto _compiler = []() -> const char * { return COMPILER_STRING; }(); @@ -220,7 +204,7 @@ VersionInfo version() #endif }(); const auto _static = []() -> bool { -#ifdef FRAMELESSHELPER_CORE_STATIC +#if FRAMELESSHELPER_CONFIG(static_build) return true; #else return false; @@ -239,7 +223,7 @@ VersionInfo version() return result; } -void setApplicationOSThemeAware() +void FramelessHelperEnableThemeAware() { static bool set = false; if (set) { @@ -257,7 +241,7 @@ void setApplicationOSThemeAware() # endif #endif -#if ((defined(Q_OS_LINUX) && (QT_VERSION < QT_VERSION_CHECK(6, 4, 0))) || \ +#if ((defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) && (QT_VERSION < QT_VERSION_CHECK(6, 4, 0))) || \ (defined(Q_OS_MACOS) && (QT_VERSION < QT_VERSION_CHECK(5, 12, 0)))) // Linux: Qt 6.4 gained the ability to detect system theme change. // macOS: Qt 5.12. @@ -265,13 +249,13 @@ void setApplicationOSThemeAware() #endif } -void outputLogo() +void FramelessHelperPrintLogo() { static const bool noLogo = (qEnvironmentVariableIntValue("FRAMELESSHELPER_NO_LOGO") != 0); if (noLogo) { return; } - const VersionInfo &ver = version(); + const VersionInfo ver = FramelessHelperVersion(); QString message = {}; QTextStream stream(&message, QIODevice::WriteOnly); stream << "FramelessHelper (" << (ver.isStatic ? "static" : "shared") @@ -282,6 +266,4 @@ void outputLogo() INFO.nospace().noquote() << message; } -} - FRAMELESSHELPER_END_NAMESPACE diff --git a/src/core/framelessmanager.cpp b/src/core/framelessmanager.cpp index d2fbcd58..cf7bfdea 100644 --- a/src/core/framelessmanager.cpp +++ b/src/core/framelessmanager.cpp @@ -44,18 +44,17 @@ FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcFramelessManager, "wangwenx190.framelesshelper.core.framelessmanager") - -#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcFramelessManager) # define DEBUG qCDebug(lcFramelessManager) # define WARNING qCWarning(lcFramelessManager) # define CRITICAL qCCritical(lcFramelessManager) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; @@ -66,7 +65,7 @@ Q_GLOBAL_STATIC(FramelessManagerData, g_framelessManagerData) static constexpr const int kEventDelayInterval = 1000; -#ifndef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE +#if FRAMELESSHELPER_CONFIG(bundle_resource) [[nodiscard]] static inline QString iconFontFamilyName() { static const auto result = []() -> QString { @@ -82,7 +81,7 @@ static constexpr const int kEventDelayInterval = 1000; }(); return result; } -#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE +#endif [[nodiscard]] static inline bool usePureQtImplementation() { @@ -128,7 +127,7 @@ const FramelessManagerPrivate *FramelessManagerPrivate::get(const FramelessManag void FramelessManagerPrivate::initializeIconFont() { -#ifndef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE +#if FRAMELESSHELPER_CONFIG(bundle_resource) static bool inited = false; if (inited) { return; @@ -147,9 +146,7 @@ void FramelessManagerPrivate::initializeIconFont() QFont FramelessManagerPrivate::getIconFont() { -#ifdef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE - return {}; -#else // !FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE +#if FRAMELESSHELPER_CONFIG(bundle_resource) static const auto font = []() -> QFont { QFont f = {}; f.setFamily(iconFontFamilyName()); @@ -161,7 +158,9 @@ QFont FramelessManagerPrivate::getIconFont() return f; }(); return font; -#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE +#else // !FRAMELESSHELPER_CONFIG(bundle_resource) + return {}; +#endif // FRAMELESSHELPER_CONFIG(bundle_resource) } void FramelessManagerPrivate::notifySystemThemeHasChangedOrNot() @@ -281,7 +280,7 @@ void FramelessManagerPrivate::initialize() // Set a global flag so that people can check whether FramelessHelper is being // used without actually accessing the FramelessHelper interface. static constexpr const char flag[] = "__FRAMELESSHELPER__"; - const int ver = FramelessHelper::Core::version().version; + const int ver = FramelessHelperVersion().version; qputenv(flag, QByteArray::number(ver)); qApp->setProperty(flag, ver); } diff --git a/src/core/micamaterial.cpp b/src/core/micamaterial.cpp index 56e40e23..ad9c53c5 100644 --- a/src/core/micamaterial.cpp +++ b/src/core/micamaterial.cpp @@ -24,6 +24,9 @@ #include "micamaterial.h" #include "micamaterial_p.h" + +#if FRAMELESSHELPER_CONFIG(mica_material) + #include "framelessmanager.h" #include "utils.h" #include "framelessconfig_p.h" @@ -40,24 +43,23 @@ #include #include #include -#ifndef FRAMELESSHELPER_CORE_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) # include -#endif // FRAMELESSHELPER_CORE_NO_PRIVATE +#endif FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcMicaMaterial, "wangwenx190.framelesshelper.core.micamaterial") - -#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcMicaMaterial) # define DEBUG qCDebug(lcMicaMaterial) # define WARNING qCWarning(lcMicaMaterial) # define CRITICAL qCCritical(lcMicaMaterial) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif DECLARE_SIZE_COMPARE_OPERATORS(QSize, QSize) @@ -88,7 +90,7 @@ struct ImageData Q_GLOBAL_STATIC(ImageData, g_imageData) -#ifndef FRAMELESSHELPER_CORE_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) template [[nodiscard]] static inline constexpr int qt_static_shift(const int value) { @@ -429,7 +431,7 @@ static inline void expblur(QImage &img, qreal radius, const bool improvedQuality expblur<12, 10, false>(blurImage, radius, quality, transposed); } } -#endif // FRAMELESSHELPER_CORE_NO_PRIVATE +#endif /*! Transforms an \a alignment of Qt::AlignLeft or Qt::AlignRight @@ -485,6 +487,7 @@ static inline void expblur(QImage &img, qreal radius, const bool improvedQuality class WallpaperThread : public QThread { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DISABLE_COPY_MOVE(WallpaperThread) public: @@ -576,11 +579,11 @@ class WallpaperThread : public QThread painter.setRenderHint(QPainter::Antialiasing, false); painter.setRenderHint(QPainter::TextAntialiasing, false); painter.setRenderHint(QPainter::SmoothPixmapTransform, false); -#ifdef FRAMELESSHELPER_CORE_NO_PRIVATE - painter.drawImage(desktopOriginPoint, buffer); -#else // !FRAMELESSHELPER_CORE_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) qt_blurImage(&painter, buffer, kDefaultBlurRadius, false, false); -#endif // FRAMELESSHELPER_CORE_NO_PRIVATE +#else // !FRAMELESSHELPER_CONFIG(private_qt) + painter.drawImage(desktopOriginPoint, buffer); +#endif // FRAMELESSHELPER_CONFIG(private_qt) } Q_EMIT imageUpdated(); } @@ -653,7 +656,7 @@ void MicaMaterialPrivate::maybeGenerateBlurredWallpaper(const bool force) void MicaMaterialPrivate::updateMaterialBrush() { -#ifndef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE +#if FRAMELESSHELPER_CONFIG(bundle_resource) framelesshelpercore_initResource(); static const QImage noiseTexture = QImage(FRAMELESSHELPER_STRING_LITERAL(":/org.wangwenx190.FramelessHelper/resources/images/noise.png")); #endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE @@ -670,7 +673,7 @@ void MicaMaterialPrivate::updateMaterialBrush() const QRect rect = {QPoint(0, 0), micaTexture.size()}; painter.fillRect(rect, tintColor); painter.setOpacity(noiseOpacity); -#ifndef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE +#if FRAMELESSHELPER_CONFIG(bundle_resource) painter.fillRect(rect, QBrush(noiseTexture)); #endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE micaBrush = QBrush(micaTexture); @@ -964,3 +967,5 @@ void MicaMaterial::paint(QPainter *painter, const QRect &rect, const bool active FRAMELESSHELPER_END_NAMESPACE #include "micamaterial.moc" + +#endif diff --git a/src/core/platformsupport_linux.cpp b/src/core/platformsupport_linux.cpp index a236297e..300edbc2 100644 --- a/src/core/platformsupport_linux.cpp +++ b/src/core/platformsupport_linux.cpp @@ -22,6 +22,8 @@ * SOFTWARE. */ +#ifdef __linux__ + #include "framelesshelper_linux.h" #include "sysapiloader_p.h" @@ -509,3 +511,5 @@ QString gtkSettings(const gchar *property) return result; } FRAMELESSHELPER_END_NAMESPACE + +#endif // __linux__ diff --git a/src/core/platformsupport_win.cpp b/src/core/platformsupport_win.cpp index 615ba1df..479f8225 100644 --- a/src/core/platformsupport_win.cpp +++ b/src/core/platformsupport_win.cpp @@ -22,6 +22,8 @@ * SOFTWARE. */ +#if (defined(WIN32) || defined(_WIN32)) + #include "sysapiloader_p.h" #include "winverhelper_p.h" #include "framelesshelper_windows.h" @@ -499,3 +501,5 @@ _AdjustWindowRectExForDpi2(LPRECT lpRect, const DWORD dwStyle, } return pAdjustWindowRectExForDpi(lpRect, dwStyle, bMenu, dwExStyle, dpi); } + +#endif // Q_OS_WINDOWS diff --git a/src/core/registrykey.cpp b/src/core/registrykey.cpp index b4136f15..92f873cd 100644 --- a/src/core/registrykey.cpp +++ b/src/core/registrykey.cpp @@ -23,6 +23,9 @@ */ #include "registrykey_p.h" + +#ifdef Q_OS_WINDOWS + #include "framelesshelper_windows.h" #include #include @@ -34,18 +37,17 @@ FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcCoreRegistryKey, "wangwenx190.framelesshelper.core.registrykey") - -#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcCoreRegistryKey) # define DEBUG qCDebug(lcCoreRegistryKey) # define WARNING qCWarning(lcCoreRegistryKey) # define CRITICAL qCCritical(lcCoreRegistryKey) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; @@ -153,3 +155,5 @@ QVariant RegistryKey::value(const QString &name) const } FRAMELESSHELPER_END_NAMESPACE + +#endif // Q_OS_WINDOWS diff --git a/src/core/sysapiloader.cpp b/src/core/sysapiloader.cpp index 92f31762..c58dc640 100644 --- a/src/core/sysapiloader.cpp +++ b/src/core/sysapiloader.cpp @@ -57,29 +57,30 @@ FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcSysApiLoader, "wangwenx190.framelesshelper.core.sysapiloader") - -#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcSysApiLoader) # define DEBUG qCDebug(lcSysApiLoader) # define WARNING qCWarning(lcSysApiLoader) # define CRITICAL qCCritical(lcSysApiLoader) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using SysApiLoaderData = QHash; Q_GLOBAL_STATIC(SysApiLoaderData, g_sysApiLoaderData) +#if FRAMELESSHELPER_CONFIG(debug_output) [[nodiscard]] static inline bool isDebug() { - static const bool flag = qEnvironmentVariableIntValue("FRAMELESSHELPER_SYSAPILOADER_DEBUG"); + static const bool flag = (qEnvironmentVariableIntValue("FRAMELESSHELPER_SYSAPILOADER_DEBUG") != 0); return flag; } +#endif SysApiLoader::SysApiLoader(QObject *parent) : QObject(parent) { @@ -98,7 +99,7 @@ QString SysApiLoader::platformSharedLibrarySuffixName() static const auto result = []() -> QString { #ifdef Q_OS_WINDOWS return FRAMELESSHELPER_STRING_LITERAL(".dll"); -#elif defined(Q_OS_LINUX) +#elif (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)) return FRAMELESSHELPER_STRING_LITERAL(".so"); #elif defined(Q_OS_MACOS) return FRAMELESSHELPER_STRING_LITERAL(".dylib"); @@ -187,16 +188,20 @@ bool SysApiLoader::isAvailable(const QString &library, const QString &function) const QString key = generateUniqueKey(library, function); const auto it = g_sysApiLoaderData()->constFind(key); if (it != g_sysApiLoaderData()->constEnd()) { +#if FRAMELESSHELPER_CONFIG(debug_output) if (isDebug()) { DEBUG << Q_FUNC_INFO << "Function cache found:" << key; } +#endif return (it.value() != nullptr); } else { const QFunctionPointer symbol = SysApiLoader::resolve(library, function); g_sysApiLoaderData()->insert(key, symbol); +#if FRAMELESSHELPER_CONFIG(debug_output) if (isDebug()) { DEBUG << Q_FUNC_INFO << "New function cache:" << key << (symbol ? "[VALID]" : "[NULL]"); } +#endif if (symbol) { DEBUG << "Successfully loaded" << function << "from" << library; return true; @@ -217,14 +222,18 @@ QFunctionPointer SysApiLoader::get(const QString &library, const QString &functi const QString key = generateUniqueKey(library, function); const auto it = g_sysApiLoaderData()->constFind(key); if (it != g_sysApiLoaderData()->constEnd()) { +#if FRAMELESSHELPER_CONFIG(debug_output) if (isDebug()) { DEBUG << Q_FUNC_INFO << "Function cache found:" << key; } +#endif return it.value(); } else { +#if FRAMELESSHELPER_CONFIG(debug_output) if (isDebug()) { DEBUG << Q_FUNC_INFO << "Function cache not found:" << key; } +#endif return nullptr; } } diff --git a/src/core/utils.cpp b/src/core/utils.cpp index 7578be1a..00381e09 100644 --- a/src/core/utils.cpp +++ b/src/core/utils.cpp @@ -36,36 +36,35 @@ #include #include #include -#ifndef FRAMELESSHELPER_CORE_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) # include # include -#endif // FRAMELESSHELPER_CORE_NO_PRIVATE +#endif // FRAMELESSHELPER_CONFIG(private_qt) #if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)) # include -#elif ((QT_VERSION >= QT_VERSION_CHECK(6, 2, 1)) && !defined(FRAMELESSHELPER_CORE_NO_PRIVATE)) +#elif ((QT_VERSION >= QT_VERSION_CHECK(6, 2, 1)) && FRAMELESSHELPER_CONFIG(private_qt)) # include # include -#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)) +#endif // ((QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)) && FRAMELESSHELPER_CONFIG(private_qt)) FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcUtilsCommon, "wangwenx190.framelesshelper.core.utils.common") - -#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcUtilsCommon) # define DEBUG qCDebug(lcUtilsCommon) # define WARNING qCWarning(lcUtilsCommon) # define CRITICAL qCCritical(lcUtilsCommon) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; -#ifndef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE +#if FRAMELESSHELPER_CONFIG(bundle_resource) struct FONT_ICON { quint32 SegoeUI = 0; @@ -82,9 +81,9 @@ static constexpr const std::array(SystemButtonType:: FONT_ICON{ 0xE923, 0xE93D }, FONT_ICON{ 0xE8BB, 0xE93B } }; -#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE +#endif // FRAMELESSHELPER_CONFIG(bundle_resource) -#ifdef FRAMELESSHELPER_CORE_NO_PRIVATE +#if !FRAMELESSHELPER_CONFIG(private_qt) [[nodiscard]] static inline QPoint getScaleOrigin(const QWindow *window) { Q_ASSERT(window); @@ -100,7 +99,7 @@ static constexpr const std::array(SystemButtonType:: } return screen->geometry().topLeft(); } -#endif // FRAMELESSHELPER_CORE_NO_PRIVATE +#endif // !FRAMELESSHELPER_CONFIG(private_qt) Qt::CursorShape Utils::calculateCursorShape(const QWindow *window, const QPoint &pos) { @@ -173,9 +172,7 @@ Qt::Edges Utils::calculateWindowEdges(const QWindow *window, const QPoint &pos) QString Utils::getSystemButtonGlyph(const SystemButtonType button) { -#ifdef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE - return {}; -#else // !FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE +#if FRAMELESSHELPER_CONFIG(bundle_resource) const FONT_ICON &icon = g_fontIconsTable.at(static_cast(button)); # ifdef Q_OS_WINDOWS // Windows 11: Segoe Fluent Icons (https://docs.microsoft.com/en-us/windows/apps/design/style/segoe-fluent-icons-font) @@ -188,7 +185,9 @@ QString Utils::getSystemButtonGlyph(const SystemButtonType button) // We always use our own icons on UNIX platforms because Microsoft doesn't allow distributing // the Segoe icon font to other platforms than Windows. return QChar(icon.Fallback); -#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE +#else // !FRAMELESSHELPER_CONFIG(bundle_resource) + return {}; +#endif // FRAMELESSHELPER_CONFIG(bundle_resource) } QWindow *Utils::findWindow(const WId windowId) @@ -294,15 +293,15 @@ bool Utils::shouldAppsUseDarkMode() { #if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)) return (QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark); -#elif ((QT_VERSION >= QT_VERSION_CHECK(6, 2, 1)) && !defined(FRAMELESSHELPER_CORE_NO_PRIVATE)) +#elif ((QT_VERSION >= QT_VERSION_CHECK(6, 2, 1)) && FRAMELESSHELPER_CONFIG(private_qt)) if (const QPlatformTheme * const theme = QGuiApplicationPrivate::platformTheme()) { return (theme->appearance() == QPlatformTheme::Appearance::Dark); } return false; -#else // ((QT_VERSION < QT_VERSION_CHECK(6, 2, 1)) || FRAMELESSHELPER_CORE_NO_PRIVATE) +#else // ((QT_VERSION < QT_VERSION_CHECK(6, 2, 1)) || !FRAMELESSHELPER_CONFIG(private_qt)) # ifdef Q_OS_WINDOWS return shouldAppsUseDarkMode_windows(); -# elif defined(Q_OS_LINUX) +# elif (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)) return shouldAppsUseDarkMode_linux(); # elif defined(Q_OS_MACOS) return shouldAppsUseDarkMode_macos(); @@ -319,7 +318,7 @@ qreal Utils::roundScaleFactor(const qreal factor) if (factor < 1) { return 1; } -#if (defined(FRAMELESSHELPER_CORE_NO_PRIVATE) || (QT_VERSION < QT_VERSION_CHECK(6, 2, 1))) +#if (!FRAMELESSHELPER_CONFIG(private_qt) || (QT_VERSION < QT_VERSION_CHECK(6, 2, 1))) # if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) static const auto policy = QGuiApplication::highDpiScaleFactorRoundingPolicy(); switch (policy) { @@ -343,9 +342,9 @@ qreal Utils::roundScaleFactor(const qreal factor) # else // (QT_VERSION < QT_VERSION_CHECK(5, 14, 0)) return std::round(factor); # endif // (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) -#else // (!FRAMELESSHELPER_CORE_NO_PRIVATE && (QT_VERSION >= QT_VERSION_CHECK(6, 2, 1))) +#else // (FRAMELESSHELPER_CONFIG(private_qt) && (QT_VERSION >= QT_VERSION_CHECK(6, 2, 1))) return QHighDpiScaling::roundScaleFactor(factor); -#endif // FRAMELESSHELPER_CORE_NO_PRIVATE +#endif } int Utils::toNativePixels(const QWindow *window, const int value) @@ -354,11 +353,11 @@ int Utils::toNativePixels(const QWindow *window, const int value) if (!window) { return 0; } -#ifdef FRAMELESSHELPER_CORE_NO_PRIVATE - return std::round(qreal(value) * window->devicePixelRatio()); -#else // !FRAMELESSHELPER_CORE_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) return QHighDpi::toNativePixels(value, window); -#endif // FRAMELESSHELPER_CORE_NO_PRIVATE +#else + return std::round(qreal(value) * window->devicePixelRatio()); +#endif } QPoint Utils::toNativePixels(const QWindow *window, const QPoint &point) @@ -367,12 +366,12 @@ QPoint Utils::toNativePixels(const QWindow *window, const QPoint &point) if (!window) { return {}; } -#ifdef FRAMELESSHELPER_CORE_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) + return QHighDpi::toNativePixels(point, window); +#else const QPoint origin = getScaleOrigin(window); return QPointF(QPointF(point - origin) * window->devicePixelRatio()).toPoint() + origin; -#else // !FRAMELESSHELPER_CORE_NO_PRIVATE - return QHighDpi::toNativePixels(point, window); -#endif // FRAMELESSHELPER_CORE_NO_PRIVATE +#endif } QSize Utils::toNativePixels(const QWindow *window, const QSize &size) @@ -381,11 +380,11 @@ QSize Utils::toNativePixels(const QWindow *window, const QSize &size) if (!window) { return {}; } -#ifdef FRAMELESSHELPER_CORE_NO_PRIVATE - return QSizeF(QSizeF(size) * window->devicePixelRatio()).toSize(); -#else // !FRAMELESSHELPER_CORE_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) return QHighDpi::toNativePixels(size, window); -#endif // FRAMELESSHELPER_CORE_NO_PRIVATE +#else + return QSizeF(QSizeF(size) * window->devicePixelRatio()).toSize(); +#endif } QRect Utils::toNativePixels(const QWindow *window, const QRect &rect) @@ -394,11 +393,11 @@ QRect Utils::toNativePixels(const QWindow *window, const QRect &rect) if (!window) { return {}; } -#ifdef FRAMELESSHELPER_CORE_NO_PRIVATE - return QRect(toNativePixels(window, rect.topLeft()), toNativePixels(window, rect.size())); -#else // !FRAMELESSHELPER_CORE_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) return QHighDpi::toNativePixels(rect, window); -#endif // FRAMELESSHELPER_CORE_NO_PRIVATE +#else + return QRect(toNativePixels(window, rect.topLeft()), toNativePixels(window, rect.size())); +#endif } int Utils::fromNativePixels(const QWindow *window, const int value) @@ -407,11 +406,11 @@ int Utils::fromNativePixels(const QWindow *window, const int value) if (!window) { return 0; } -#ifdef FRAMELESSHELPER_CORE_NO_PRIVATE - return std::round(qreal(value) / window->devicePixelRatio()); -#else // !FRAMELESSHELPER_CORE_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) return QHighDpi::fromNativePixels(value, window); -#endif // FRAMELESSHELPER_CORE_NO_PRIVATE +#else + return std::round(qreal(value) / window->devicePixelRatio()); +#endif } QPoint Utils::fromNativePixels(const QWindow *window, const QPoint &point) @@ -420,12 +419,12 @@ QPoint Utils::fromNativePixels(const QWindow *window, const QPoint &point) if (!window) { return {}; } -#ifdef FRAMELESSHELPER_CORE_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) + return QHighDpi::fromNativePixels(point, window); +#else const QPoint origin = getScaleOrigin(window); return QPointF(QPointF(point - origin) / window->devicePixelRatio()).toPoint() + origin; -#else // !FRAMELESSHELPER_CORE_NO_PRIVATE - return QHighDpi::fromNativePixels(point, window); -#endif // FRAMELESSHELPER_CORE_NO_PRIVATE +#endif } QSize Utils::fromNativePixels(const QWindow *window, const QSize &size) @@ -434,11 +433,11 @@ QSize Utils::fromNativePixels(const QWindow *window, const QSize &size) if (!window) { return {}; } -#ifdef FRAMELESSHELPER_CORE_NO_PRIVATE - return QSizeF(QSizeF(size) / window->devicePixelRatio()).toSize(); -#else // !FRAMELESSHELPER_CORE_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) return QHighDpi::fromNativePixels(size, window); -#endif // FRAMELESSHELPER_CORE_NO_PRIVATE +#else + return QSizeF(QSizeF(size) / window->devicePixelRatio()).toSize(); +#endif } QRect Utils::fromNativePixels(const QWindow *window, const QRect &rect) @@ -447,11 +446,11 @@ QRect Utils::fromNativePixels(const QWindow *window, const QRect &rect) if (!window) { return {}; } -#ifdef FRAMELESSHELPER_CORE_NO_PRIVATE - return QRect(fromNativePixels(window, rect.topLeft()), fromNativePixels(window, rect.size())); -#else // !FRAMELESSHELPER_CORE_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) return QHighDpi::fromNativePixels(rect, window); -#endif // FRAMELESSHELPER_CORE_NO_PRIVATE +#else + return QRect(fromNativePixels(window, rect.topLeft()), fromNativePixels(window, rect.size())); +#endif } QPoint Utils::toNativeLocalPosition(const QWindow *window, const QPoint &point) @@ -460,11 +459,11 @@ QPoint Utils::toNativeLocalPosition(const QWindow *window, const QPoint &point) if (!window) { return {}; } -#ifdef FRAMELESSHELPER_CORE_NO_PRIVATE - return QPointF(QPointF(point) * window->devicePixelRatio()).toPoint(); -#else // !FRAMELESSHELPER_CORE_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) return QHighDpi::toNativeLocalPosition(point, window); -#endif // FRAMELESSHELPER_CORE_NO_PRIVATE +#else + return QPointF(QPointF(point) * window->devicePixelRatio()).toPoint(); +#endif } QPoint Utils::toNativeGlobalPosition(const QWindow *window, const QPoint &point) @@ -473,11 +472,11 @@ QPoint Utils::toNativeGlobalPosition(const QWindow *window, const QPoint &point) if (!window) { return {}; } -#if (defined(FRAMELESSHELPER_CORE_NO_PRIVATE) || (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))) +#if (!FRAMELESSHELPER_CONFIG(private_qt) || (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))) return toNativePixels(window, point); -#else // !FRAMELESSHELPER_CORE_NO_PRIVATE && QT_VERSION >= 6.0.0 +#else return QHighDpi::toNativeGlobalPosition(point, window); -#endif // FRAMELESSHELPER_CORE_NO_PRIVATE || QT_VERSION < 6.0.0 +#endif } QPoint Utils::fromNativeLocalPosition(const QWindow *window, const QPoint &point) @@ -486,11 +485,11 @@ QPoint Utils::fromNativeLocalPosition(const QWindow *window, const QPoint &point if (!window) { return {}; } -#ifdef FRAMELESSHELPER_CORE_NO_PRIVATE - return QPointF(QPointF(point) / window->devicePixelRatio()).toPoint(); -#else // !FRAMELESSHELPER_CORE_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) return QHighDpi::fromNativeLocalPosition(point, window); -#endif // FRAMELESSHELPER_CORE_NO_PRIVATE +#else + return QPointF(QPointF(point) / window->devicePixelRatio()).toPoint(); +#endif } QPoint Utils::fromNativeGlobalPosition(const QWindow *window, const QPoint &point) @@ -499,11 +498,11 @@ QPoint Utils::fromNativeGlobalPosition(const QWindow *window, const QPoint &poin if (!window) { return {}; } -#if (defined(FRAMELESSHELPER_CORE_NO_PRIVATE) || (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))) +#if (!FRAMELESSHELPER_CONFIG(private_qt) || (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))) return fromNativePixels(window, point); -#else // !FRAMELESSHELPER_CORE_NO_PRIVATE && QT_VERSION >= 6.0.0 +#else return QHighDpi::fromNativeGlobalPosition(point, window); -#endif // FRAMELESSHELPER_CORE_NO_PRIVATE || QT_VERSION < 6.0.0 +#endif } int Utils::horizontalAdvance(const QFontMetrics &fm, const QString &str) @@ -580,7 +579,7 @@ QColor Utils::getAccentColor() #else // (QT_VERSION < QT_VERSION_CHECK(6, 6, 0)) # ifdef Q_OS_WINDOWS return getAccentColor_windows(); -# elif defined(Q_OS_LINUX) +# elif (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)) return getAccentColor_linux(); # elif defined(Q_OS_MACOS) return getAccentColor_macos(); @@ -598,11 +597,11 @@ bool Utils::isWindowAccelerated(const QWindow *window) } switch (window->surfaceType()) { case QSurface::RasterGLSurface: -#ifdef FRAMELESSHELPER_CORE_NO_PRIVATE - return true; -#else // !FRAMELESSHELPER_CORE_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) return qt_window_private(const_cast(window))->compositing; -#endif // FRAMELESSHELPER_CORE_NO_PRIVATE +#else + return true; +#endif case QSurface::OpenGLSurface: case QSurface::VulkanSurface: case QSurface::MetalSurface: diff --git a/src/core/utils_linux.cpp b/src/core/utils_linux.cpp index 1f2dfe26..86797fe4 100644 --- a/src/core/utils_linux.cpp +++ b/src/core/utils_linux.cpp @@ -23,6 +23,9 @@ */ #include "utils.h" + +#if (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)) + #include "framelessconfig_p.h" #include "framelessmanager.h" #include "framelessmanager_p.h" @@ -33,12 +36,12 @@ #include #include #include -#ifdef FRAMELESSHELPER_CORE_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) # if __has_include() # include # define FRAMELESSHELPER_HAS_X11EXTRAS # endif // __has_include() -#else // !FRAMELESSHELPER_CORE_NO_PRIVATE +#else // !FRAMELESSHELPER_CONFIG(private_qt) # include # include # if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) @@ -51,22 +54,21 @@ # include # define FRAMELESSHELPER_HAS_X11EXTRAS # endif // (QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)) -#endif // FRAMELESSHELPER_CORE_NO_PRIVATE +#endif // FRAMELESSHELPER_CONFIG(private_qt) FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcUtilsLinux, "wangwenx190.framelesshelper.core.utils.linux") - -#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcUtilsLinux) # define DEBUG qCDebug(lcUtilsLinux) # define WARNING qCWarning(lcUtilsLinux) # define CRITICAL qCCritical(lcUtilsLinux) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; @@ -143,10 +145,7 @@ extern QString gtkSettings(const gchar *); QScreen *Utils::x11_findScreenForVirtualDesktop(const int virtualDesktopNumber) { -#ifdef FRAMELESSHELPER_CORE_NO_PRIVATE - Q_UNUSED(virtualDesktopNumber); - return QGuiApplication::primaryScreen(); -#else // !FRAMELESSHELPER_CORE_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) if (virtualDesktopNumber == -1) { return QGuiApplication::primaryScreen(); } @@ -167,7 +166,10 @@ QScreen *Utils::x11_findScreenForVirtualDesktop(const int virtualDesktopNumber) # endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) } return nullptr; -#endif // FRAMELESSHELPER_CORE_NO_PRIVATE +#else // !FRAMELESSHELPER_CONFIG(private_qt) + Q_UNUSED(virtualDesktopNumber); + return QGuiApplication::primaryScreen(); +#endif // FRAMELESSHELPER_CONFIG(private_qt) } x11_return_type Utils::x11_appRootWindow(const int screen) @@ -175,10 +177,7 @@ x11_return_type Utils::x11_appRootWindow(const int screen) #ifdef FRAMELESSHELPER_HAS_X11EXTRAS return QX11Info::appRootWindow(screen); #else // !FRAMELESSHELPER_HAS_X11EXTRAS -# ifdef FRAMELESSHELPER_CORE_NO_PRIVATE - Q_UNUSED(screen); - return 0; -# else // !FRAMELESSHELPER_CORE_NO_PRIVATE +# if FRAMELESSHELPER_CONFIG(private_qt) if (!qApp) { return 0; } @@ -191,7 +190,10 @@ x11_return_type Utils::x11_appRootWindow(const int screen) return 0; } return static_cast(reinterpret_cast(native->nativeResourceForScreen(krootwindow, scr))); -# endif // FRAMELESSHELPER_CORE_NO_PRIVATE +# else // !FRAMELESSHELPER_CONFIG(private_qt) + Q_UNUSED(screen); + return 0; +# endif // FRAMELESSHELPER_CONFIG(private_qt) #endif // FRAMELESSHELPER_HAS_X11EXTRAS } @@ -200,9 +202,7 @@ int Utils::x11_appScreen() #ifdef FRAMELESSHELPER_HAS_X11EXTRAS return QX11Info::appScreen(); #else // !FRAMELESSHELPER_HAS_X11EXTRAS -# ifdef FRAMELESSHELPER_CORE_NO_PRIVATE - return 0; -# else // !FRAMELESSHELPER_CORE_NO_PRIVATE +# if FRAMELESSHELPER_CONFIG(private_qt) if (!qApp) { return 0; } @@ -211,7 +211,9 @@ int Utils::x11_appScreen() return 0; } return reinterpret_cast(native->nativeResourceForIntegration(kx11screen)); -# endif // FRAMELESSHELPER_CORE_NO_PRIVATE +# else // !FRAMELESSHELPER_CONFIG(private_qt) + return 0; +# endif // FRAMELESSHELPER_CONFIG(private_qt) #endif // FRAMELESSHELPER_HAS_X11EXTRAS } @@ -220,9 +222,7 @@ x11_return_type Utils::x11_appTime() #ifdef FRAMELESSHELPER_HAS_X11EXTRAS return QX11Info::appTime(); #else // !FRAMELESSHELPER_HAS_X11EXTRAS -# ifdef FRAMELESSHELPER_CORE_NO_PRIVATE - return 0; -# else // !FRAMELESSHELPER_CORE_NO_PRIVATE +# if FRAMELESSHELPER_CONFIG(private_qt) if (!qApp) { return 0; } @@ -235,7 +235,9 @@ x11_return_type Utils::x11_appTime() return 0; } return static_cast(reinterpret_cast(native->nativeResourceForScreen(kapptime, screen))); -# endif // FRAMELESSHELPER_CORE_NO_PRIVATE +# else // !FRAMELESSHELPER_CONFIG(private_qt) + return 0; +# endif // FRAMELESSHELPER_CONFIG(private_qt) #endif // FRAMELESSHELPER_HAS_X11EXTRAS } @@ -244,9 +246,7 @@ x11_return_type Utils::x11_appUserTime() #ifdef FRAMELESSHELPER_HAS_X11EXTRAS return QX11Info::appUserTime(); #else // !FRAMELESSHELPER_HAS_X11EXTRAS -# ifdef FRAMELESSHELPER_CORE_NO_PRIVATE - return 0; -# else // !FRAMELESSHELPER_CORE_NO_PRIVATE +# if FRAMELESSHELPER_CONFIG(private_qt) if (!qApp) { return 0; } @@ -259,7 +259,9 @@ x11_return_type Utils::x11_appUserTime() return 0; } return static_cast(reinterpret_cast(native->nativeResourceForScreen(kappusertime, screen))); -# endif // FRAMELESSHELPER_CORE_NO_PRIVATE +# else // !FRAMELESSHELPER_CONFIG(private_qt) + return 0; +# endif // FRAMELESSHELPER_CONFIG(private_qt) #endif // FRAMELESSHELPER_HAS_X11EXTRAS } @@ -268,9 +270,7 @@ x11_return_type Utils::x11_getTimestamp() #ifdef FRAMELESSHELPER_HAS_X11EXTRAS return QX11Info::getTimestamp(); #else // !FRAMELESSHELPER_HAS_X11EXTRAS -# ifdef FRAMELESSHELPER_CORE_NO_PRIVATE - return 0; -# else // !FRAMELESSHELPER_CORE_NO_PRIVATE +# if FRAMELESSHELPER_CONFIG(private_qt) if (!qApp) { return 0; } @@ -283,7 +283,9 @@ x11_return_type Utils::x11_getTimestamp() return 0; } return static_cast(reinterpret_cast(native->nativeResourceForScreen(kgettimestamp, screen))); -# endif // FRAMELESSHELPER_CORE_NO_PRIVATE +# else // !FRAMELESSHELPER_CONFIG(private_qt) + return 0; +# endif // FRAMELESSHELPER_CONFIG(private_qt) #endif // FRAMELESSHELPER_HAS_X11EXTRAS } @@ -292,9 +294,7 @@ QByteArray Utils::x11_nextStartupId() #ifdef FRAMELESSHELPER_HAS_X11EXTRAS return QX11Info::nextStartupId(); #else // !FRAMELESSHELPER_HAS_X11EXTRAS -# ifdef FRAMELESSHELPER_CORE_NO_PRIVATE - return {}; -# else // !FRAMELESSHELPER_CORE_NO_PRIVATE +# if FRAMELESSHELPER_CONFIG(private_qt) if (!qApp) { return {}; } @@ -303,7 +303,9 @@ QByteArray Utils::x11_nextStartupId() return {}; } return static_cast(native->nativeResourceForIntegration(kstartupid)); -# endif // FRAMELESSHELPER_CORE_NO_PRIVATE +# else // !FRAMELESSHELPER_CONFIG(private_qt) + return {}; +# endif // FRAMELESSHELPER_CONFIG(private_qt) #endif // FRAMELESSHELPER_HAS_X11EXTRAS } @@ -312,9 +314,7 @@ Display *Utils::x11_display() #ifdef FRAMELESSHELPER_HAS_X11EXTRAS return QX11Info::display(); #else // !FRAMELESSHELPER_HAS_X11EXTRAS -# ifdef FRAMELESSHELPER_CORE_NO_PRIVATE - return nullptr; -# else // !FRAMELESSHELPER_CORE_NO_PRIVATE +# if FRAMELESSHELPER_CONFIG(private_qt) if (!qApp) { return nullptr; } @@ -332,7 +332,9 @@ Display *Utils::x11_display() # else // (QT_VERSION < QT_VERSION_CHECK(6, 2, 0)) return reinterpret_cast(native->nativeResourceForIntegration(kdisplay)); # endif // (QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)) -# endif // FRAMELESSHELPER_CORE_NO_PRIVATE +# else // !FRAMELESSHELPER_CONFIG(private_qt) + return nullptr; +# endif // FRAMELESSHELPER_CONFIG(private_qt) #endif // FRAMELESSHELPER_HAS_X11EXTRAS } @@ -341,9 +343,7 @@ xcb_connection_t *Utils::x11_connection() #ifdef FRAMELESSHELPER_HAS_X11EXTRAS return QX11Info::connection(); #else // !FRAMELESSHELPER_HAS_X11EXTRAS -# ifdef FRAMELESSHELPER_CORE_NO_PRIVATE - return nullptr; -# else // !FRAMELESSHELPER_CORE_NO_PRIVATE +# if FRAMELESSHELPER_CONFIG(private_qt) if (!qApp) { return nullptr; } @@ -361,7 +361,9 @@ xcb_connection_t *Utils::x11_connection() # else // (QT_VERSION < QT_VERSION_CHECK(6, 2, 0)) return reinterpret_cast(native->nativeResourceForIntegration(kconnection)); # endif // (QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)) -# endif // FRAMELESSHELPER_CORE_NO_PRIVATE +# else // !FRAMELESSHELPER_CONFIG(private_qt) + return nullptr; +# endif // FRAMELESSHELPER_CONFIG(private_qt) #endif // FRAMELESSHELPER_HAS_X11EXTRAS } @@ -993,3 +995,5 @@ bool Utils::setPlatformPropertiesForWindow(QWindow *window, const QVariantHash & } FRAMELESSHELPER_END_NAMESPACE + +#endif // Q_OS_LINUX diff --git a/src/core/utils_mac.mm b/src/core/utils_mac.mm index 205784ea..085c0512 100644 --- a/src/core/utils_mac.mm +++ b/src/core/utils_mac.mm @@ -23,6 +23,9 @@ */ #include "utils.h" + +#ifdef Q_OS_MACOS + #include "framelessmanager.h" #include "framelessmanager_p.h" #include "framelessconfig_p.h" @@ -67,18 +70,17 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcUtilsMac, "wangwenx190.framelesshelper.core.utils.mac") - -#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcUtilsMac) # define DEBUG qCDebug(lcUtilsMac) # define WARNING qCWarning(lcUtilsMac) # define CRITICAL qCCritical(lcUtilsMac) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; @@ -221,6 +223,7 @@ static void notifySystemThemeChange() class NSWindowProxy : public QObject { Q_OBJECT + FRAMELESSHELPER_CLASS_INFO Q_DISABLE_COPY_MOVE(NSWindowProxy) public: @@ -758,3 +761,5 @@ static inline void cleanupProxy() FRAMELESSHELPER_END_NAMESPACE #include "utils_mac.moc" + +#endif // Q_OS_MACOS diff --git a/src/core/utils_win.cpp b/src/core/utils_win.cpp index f07f62be..8cc7ba98 100644 --- a/src/core/utils_win.cpp +++ b/src/core/utils_win.cpp @@ -23,6 +23,9 @@ */ #include "utils.h" + +#ifdef Q_OS_WINDOWS + #include "framelesshelper_windows.h" #include "framelessmanager.h" #include "framelessconfig_p.h" @@ -39,7 +42,7 @@ #include #include #include -#ifndef FRAMELESSHELPER_CORE_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) # include # if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) # include @@ -50,7 +53,7 @@ # else // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) # include # endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) -#endif // FRAMELESSHELPER_CORE_NO_PRIVATE +#endif #include #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) @@ -59,18 +62,17 @@ Q_DECLARE_METATYPE(QMargins) FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcUtilsWin, "wangwenx190.framelesshelper.core.utils.win") - -#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcUtilsWin) # define DEBUG qCDebug(lcUtilsWin) # define WARNING qCWarning(lcUtilsWin) # define CRITICAL qCCritical(lcUtilsWin) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; @@ -108,7 +110,7 @@ FRAMELESSHELPER_STRING_CONSTANT(SystemParametersInfoW) FRAMELESSHELPER_STRING_CONSTANT(SetClassLongPtrW) FRAMELESSHELPER_STRING_CONSTANT(GetWindowLongPtrW) FRAMELESSHELPER_STRING_CONSTANT(SetWindowLongPtrW) -#else // Q_PROCESSOR_X86_64 +#else // !Q_PROCESSOR_X86_64 // WinUser.h defines G/SetClassLongPtr as G/SetClassLong due to the // "Ptr" suffixed APIs are not available on 32-bit platforms, so we // have to add the following workaround. Undefine the macros and then @@ -778,20 +780,20 @@ static constexpr const std::array g_win32MessageMap = if (code == ERROR_SUCCESS) { return kSuccessMessageText; } -#ifdef FRAMELESSHELPER_CORE_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) + const QString errorText = QSystemError::windowsString(code); + return kErrorMessageTemplate.arg(function, QString::number(code), errorText); +#else // !FRAMELESSHELPER_CONFIG(private_qt) LPWSTR buf = nullptr; if (::FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - nullptr, code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast(&buf), 0, nullptr) == 0) { + nullptr, code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast(&buf), 0, nullptr) == 0) { return FRAMELESSHELPER_STRING_LITERAL("FormatMessageW() returned empty string."); } const QString errorText = QString::fromWCharArray(buf).trimmed(); ::LocalFree(buf); buf = nullptr; return kErrorMessageTemplate.arg(function, QString::number(code), errorText); -#else // !FRAMELESSHELPER_CORE_NO_PRIVATE - const QString errorText = QSystemError::windowsString(code); - return kErrorMessageTemplate.arg(function, QString::number(code), errorText); -#endif // FRAMELESSHELPER_CORE_NO_PRIVATE +#endif // FRAMELESSHELPER_CONFIG(private_qt) } [[nodiscard]] static inline QString getSystemErrorMessageImpl(const QString &function, const HRESULT hr) @@ -907,11 +909,13 @@ static constexpr const std::array g_win32MessageMap = } } +#if FRAMELESSHELPER_CONFIG(debug_output) [[nodiscard]] static inline bool isWin32MessageDebuggingEnabled() { static const bool result = (qEnvironmentVariableIntValue("FRAMELESSHELPER_ENABLE_WIN32_MESSAGE_DEBUGGING") != 0); return result; } +#endif [[nodiscard]] static inline QByteArray qtNativeEventType() { @@ -965,6 +969,7 @@ static constexpr const std::array g_win32MessageMap = if (!hWnd) { return 0; } +#if FRAMELESSHELPER_CONFIG(debug_output) if (isWin32MessageDebuggingEnabled()) { MSG message; SecureZeroMemory(&message, sizeof(message)); @@ -975,6 +980,7 @@ static constexpr const std::array g_win32MessageMap = // The time and pt members are not used. Utils::printWin32Message(&message); } +#endif const auto windowId = reinterpret_cast(hWnd); const auto it = g_win32UtilsData()->data.constFind(windowId); if (it == g_win32UtilsData()->data.constEnd()) { @@ -1231,7 +1237,7 @@ bool Utils::updateInternalWindowFrameMargins(QWindow *window, const bool enable) }(); const QVariant marginsVar = QVariant::fromValue(margins); window->setProperty(kQtWindowCustomMarginsVar, marginsVar); -#ifndef FRAMELESSHELPER_CORE_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) # if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) if (QPlatformWindow *platformWindow = window->handle()) { if (const auto ni = QGuiApplication::platformNativeInterface()) { @@ -1252,7 +1258,7 @@ bool Utils::updateInternalWindowFrameMargins(QWindow *window, const bool enable) return false; } # endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) -#endif // FRAMELESSHELPER_CORE_NO_PRIVATE +#endif // FRAMELESSHELPER_CONFIG(private_qt) return triggerFrameChange(windowId); } @@ -2215,7 +2221,7 @@ bool Utils::shouldAppsUseDarkMode_windows() if (!WindowsVersionHelper::isWin10RS1OrGreater() || isHighContrastModeEnabled()) { return false; } -#ifndef FRAMELESSHELPER_CORE_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) # if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) if (const auto app = qApp->nativeInterface()) { return app->isDarkMode(); @@ -2232,7 +2238,7 @@ bool Utils::shouldAppsUseDarkMode_windows() // Qt gained the ability to detect the system dark mode setting only since 5.15. // We should detect it ourself on versions below that. # endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) -#endif // FRAMELESSHELPER_CORE_NO_PRIVATE +#endif // FRAMELESSHELPER_CONFIG(private_qt) // Starting from Windows 10 1903, "ShouldAppsUseDarkMode()" (exported by UXTHEME.DLL, // ordinal number 132) always return "TRUE" (actually, a random non-zero number at // runtime), so we can't use it due to this unreliability. In this case, we just simply @@ -2598,10 +2604,7 @@ bool Utils::hideOriginalTitleBarElements(const WId windowId, const bool disable) bool Utils::setQtDarkModeAwareEnabled(const bool enable) { -#ifdef FRAMELESSHELPER_CORE_NO_PRIVATE - Q_UNUSED(enable); - return true; -#else // !FRAMELESSHELPER_CORE_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) # if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) // We'll call QPA functions, so we have to ensure that the QGuiApplication // instance has already been created and initialized, because the platform @@ -2625,10 +2628,10 @@ bool Utils::setQtDarkModeAwareEnabled(const bool enable) // There's no global dark theme for Qt Quick applications, so setting this // flag has no effect for pure Qt Quick applications. return {App::DarkModeWindowFrames | App::DarkModeStyle}; -# else // (QT_VERSION < QT_VERSION_CHECK(6, 5, 0)) - // Don't try to use the broken dark theme for Qt Widgets applications. - // For Qt Quick applications this is also enough. There's no global dark - // theme for them anyway. +# else // (QT_VERSION < QT_VERSION_CHECK(6, 5, 0)) \ + // Don't try to use the broken dark theme for Qt Widgets applications. \ + // For Qt Quick applications this is also enough. There's no global dark \ + // theme for them anyway. return {App::DarkModeWindowFrames}; # endif // (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)) }()); @@ -2641,7 +2644,10 @@ bool Utils::setQtDarkModeAwareEnabled(const bool enable) Q_UNUSED(enable); return true; # endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) -#endif // FRAMELESSHELPER_CORE_NO_PRIVATE +#else // !FRAMELESSHELPER_CONFIG(private_qt) + Q_UNUSED(enable); + return true; +#endif // FRAMELESSHELPER_CONFIG(private_qt) } bool Utils::registerThemeChangeNotification() @@ -3071,6 +3077,12 @@ quint64 Utils::getKeyState() if (get(VK_RBUTTON)) { result |= (buttonSwapped ? MK_LBUTTON : MK_RBUTTON); } + if (get(VK_SHIFT)) { + result |= MK_SHIFT; + } + if (get(VK_CONTROL)) { + result |= MK_CONTROL; + } if (get(VK_MBUTTON)) { result |= MK_MBUTTON; } @@ -3192,7 +3204,7 @@ QMargins Utils::getWindowCustomFrameMargins(const QWindow *window) if (!window) { return {}; } -#ifndef FRAMELESSHELPER_CORE_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) # if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) if (QPlatformWindow *platformWindow = window->handle()) { if (const auto ni = QGuiApplication::platformNativeInterface()) { @@ -3213,7 +3225,7 @@ QMargins Utils::getWindowCustomFrameMargins(const QWindow *window) WARNING << "Failed to retrieve the platform window."; } # endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) -#endif // FRAMELESSHELPER_CORE_NO_PRIVATE +#endif // FRAMELESSHELPER_CONFIG(private_qt) const QVariant marginsVar = window->property(kQtWindowCustomMarginsVar); if (marginsVar.isValid() && !marginsVar.isNull()) { return qvariant_cast(marginsVar); @@ -3247,7 +3259,7 @@ void Utils::printWin32Message(void *msgPtr) const LPARAM lParam = msg->lParam; const QString messageCodeHex = FRAMELESSHELPER_STRING_LITERAL("0x") + QString::number(uMsg, 16).toUpper().rightJustified(4, u'0'); QString text = {}; - QTextStream stream(&text); + QTextStream stream(&text, QIODevice::WriteOnly); stream << "Windows message received: window handle: " << hwnd2str(hWnd) << ", message: "; if (uMsg >= WM_APP) { const UINT diff = (uMsg - WM_APP); @@ -3312,3 +3324,5 @@ void Utils::printWin32Message(void *msgPtr) } FRAMELESSHELPER_END_NAMESPACE + +#endif // Q_OS_WINDOWS diff --git a/src/core/windowborderpainter.cpp b/src/core/windowborderpainter.cpp index f8e8208a..255471b2 100644 --- a/src/core/windowborderpainter.cpp +++ b/src/core/windowborderpainter.cpp @@ -24,6 +24,9 @@ #include "windowborderpainter.h" #include "windowborderpainter_p.h" + +#if FRAMELESSHELPER_CONFIG(border_painter) + #include "utils.h" #include "framelessmanager.h" #ifdef Q_OS_WINDOWS @@ -34,18 +37,17 @@ FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcWindowBorderPainter, "wangwenx190.framelesshelper.core.windowborderpainter") - -#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcWindowBorderPainter) # define DEBUG qCDebug(lcWindowBorderPainter) # define WARNING qCWarning(lcWindowBorderPainter) # define CRITICAL qCCritical(lcWindowBorderPainter) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; @@ -116,9 +118,13 @@ QColor WindowBorderPainter::inactiveColor() const int WindowBorderPainter::nativeThickness() const { +#ifdef Q_OS_WINDOWS // Qt will scale it to the appropriate value for us automatically, // based on the current system DPI and scale factor rounding policy. return kDefaultWindowFrameBorderThickness; +#else + return 0; +#endif } WindowEdges WindowBorderPainter::nativeEdges() const @@ -254,3 +260,5 @@ void WindowBorderPainter::setInactiveColor(const QColor &value) } FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/src/core/winverhelper.cpp b/src/core/winverhelper.cpp index 528e4e1b..9ab7a470 100644 --- a/src/core/winverhelper.cpp +++ b/src/core/winverhelper.cpp @@ -23,6 +23,9 @@ */ #include "winverhelper_p.h" + +#ifdef Q_OS_WINDOWS + #include "utils.h" #include @@ -148,3 +151,5 @@ IMPL(1122H2, 11_22H2) #undef IMPL FRAMELESSHELPER_END_NAMESPACE + +#endif // Q_OS_WINDOWS diff --git a/src/quick/CMakeLists.txt b/src/quick/CMakeLists.txt index 533aa28a..ad39996e 100644 --- a/src/quick/CMakeLists.txt +++ b/src/quick/CMakeLists.txt @@ -41,10 +41,6 @@ set(PUBLIC_HEADERS ${INCLUDE_PREFIX}/framelessquickmodule.h ${INCLUDE_PREFIX}/framelessquickhelper.h ${INCLUDE_PREFIX}/framelessquickutils.h - ${INCLUDE_PREFIX}/quickchromepalette.h - ${INCLUDE_PREFIX}/quickmicamaterial.h - ${INCLUDE_PREFIX}/quickimageitem.h - ${INCLUDE_PREFIX}/quickwindowborder.h ) set(PUBLIC_HEADERS_ALIAS @@ -52,40 +48,56 @@ set(PUBLIC_HEADERS_ALIAS ${INCLUDE_PREFIX}/FramelessQuickModule ${INCLUDE_PREFIX}/FramelessQuickHelper ${INCLUDE_PREFIX}/FramelessQuickUtils - ${INCLUDE_PREFIX}/QuickChromePalette - ${INCLUDE_PREFIX}/QuickMicaMaterial - ${INCLUDE_PREFIX}/QuickImageItem - ${INCLUDE_PREFIX}/QuickWindowBorder ) set(PRIVATE_HEADERS - ${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 - ${INCLUDE_PREFIX}/private/framelessquickapplicationwindow_p.h - ${INCLUDE_PREFIX}/private/framelessquickapplicationwindow_p_p.h - ${INCLUDE_PREFIX}/private/quickmicamaterial_p.h ${INCLUDE_PREFIX}/private/quickimageitem_p.h - ${INCLUDE_PREFIX}/private/quickwindowborder_p.h ) set(SOURCES - quickstandardsystembutton.cpp - quickstandardtitlebar.cpp framelessquickutils.cpp - framelessquickmodule.cpp - framelessquickwindow.cpp - framelessquickapplicationwindow.cpp framelessquickhelper.cpp - quickchromepalette.cpp framelesshelperquick_global.cpp - quickmicamaterial.cpp quickimageitem.cpp - quickwindowborder.cpp ) +if(NOT FRAMELESSHELPER_NO_SYSTEM_BUTTON) + list(APPEND PRIVATE_HEADERS ${INCLUDE_PREFIX}/private/quickstandardsystembutton_p.h) + list(APPEND SOURCES quickstandardsystembutton.cpp) +endif() + +if(NOT FRAMELESSHELPER_NO_TITLEBAR) + list(APPEND PUBLIC_HEADERS ${INCLUDE_PREFIX}/quickchromepalette.h) + list(APPEND PUBLIC_HEADERS_ALIAS ${INCLUDE_PREFIX}/QuickChromePalette) + list(APPEND PRIVATE_HEADERS ${INCLUDE_PREFIX}/private/quickstandardtitlebar_p.h) + list(APPEND SOURCES quickchromepalette.cpp quickstandardtitlebar.cpp) +endif() + +if(NOT FRAMELESSHELPER_NO_WINDOW) + list(APPEND PRIVATE_HEADERS + ${INCLUDE_PREFIX}/private/framelessquickwindow_p.h + ${INCLUDE_PREFIX}/private/framelessquickwindow_p_p.h + ${INCLUDE_PREFIX}/private/framelessquickapplicationwindow_p.h + ${INCLUDE_PREFIX}/private/framelessquickapplicationwindow_p_p.h + ) + list(APPEND SOURCES framelessquickwindow.cpp framelessquickapplicationwindow.cpp) +endif() + +if(NOT FRAMELESSHELPER_NO_MICA_MATERIAL) + list(APPEND PUBLIC_HEADERS ${INCLUDE_PREFIX}/quickmicamaterial.h) + list(APPEND PUBLIC_HEADERS_ALIAS ${INCLUDE_PREFIX}/QuickMicaMaterial) + list(APPEND PRIVATE_HEADERS ${INCLUDE_PREFIX}/private/quickmicamaterial_p.h) + list(APPEND SOURCES quickmicamaterial.cpp) +endif() + +if(NOT FRAMELESSHELPER_NO_BORDER_PAINTER) + list(APPEND PUBLIC_HEADERS ${INCLUDE_PREFIX}/quickwindowborder.h) + list(APPEND PUBLIC_HEADERS_ALIAS ${INCLUDE_PREFIX}/QuickWindowBorder) + list(APPEND PRIVATE_HEADERS ${INCLUDE_PREFIX}/private/quickwindowborder_p.h) + list(APPEND SOURCES quickwindowborder.cpp) +endif() + if(WIN32 AND NOT FRAMELESSHELPER_BUILD_STATIC) set(__rc_path "${CMAKE_CURRENT_BINARY_DIR}/${SUB_MODULE_FULL_NAME}.rc") if(NOT EXISTS "${__rc_path}") @@ -118,6 +130,7 @@ add_library(${PROJECT_NAME}::${SUB_MODULE_FULL_NAME} ALIAS ${SUB_MODULE_TARGET}) set_target_properties(${SUB_MODULE_TARGET} PROPERTIES VERSION "${PROJECT_VERSION}" SOVERSION "${PROJECT_VERSION_MAJOR}" + OUTPUT_NAME "${SUB_MODULE_TARGET}${FRAMELESSHELPER_64BIT_POSTFIX}" ) set(__export_targets ${SUB_MODULE_TARGET}) @@ -138,8 +151,8 @@ if(QT_VERSION VERSION_GREATER_EQUAL "6.3") VERSION "1.0" OUTPUT_DIRECTORY "${__import_base_dir}/org/wangwenx190/${PROJECT_NAME}" RESOURCE_PREFIX "/" - TYPEINFO "plugins.qmltypes" # This is the type info file name since at least Qt5, some tools won't recognize other names. - #NO_RESOURCE_TARGET_PATH # Can't be used for non-executables. + TYPEINFO "plugins.qmltypes" # This is the default type info file name since at least Qt5, some tools won't recognize other names. + #NO_RESOURCE_TARGET_PATH # Can't be used for non-executable targets. OUTPUT_TARGETS __qml_targets IMPORTS QtQml/auto @@ -213,31 +226,6 @@ if(QT_VERSION VERSION_GREATER_EQUAL "6.3") endif() endif() -if(FRAMELESSHELPER_BUILD_STATIC) - target_compile_definitions(${SUB_MODULE_TARGET} PUBLIC FRAMELESSHELPER_QUICK_STATIC) -endif() - -if(FRAMELESSHELPER_NO_DEBUG_OUTPUT) - target_compile_definitions(${SUB_MODULE_TARGET} PRIVATE - FRAMELESSHELPER_QUICK_NO_DEBUG_OUTPUT - ) -endif() - -if(FRAMELESSHELPER_NO_BUNDLE_RESOURCE) - target_compile_definitions(${SUB_MODULE_TARGET} PUBLIC FRAMELESSHELPER_QUICK_NO_BUNDLE_RESOURCE) -endif() - -if(FRAMELESSHELPER_NO_PRIVATE) - target_compile_definitions(${SUB_MODULE_TARGET} PUBLIC FRAMELESSHELPER_QUICK_NO_PRIVATE) -endif() - -if(DEFINED FRAMELESSHELPER_NAMESPACE) - if("x${FRAMELESSHELPER_NAMESPACE}" STREQUAL "x") - message(FATAL_ERROR "FRAMELESSHELPER_NAMESPACE can't be empty!") - endif() - target_compile_definitions(${SUB_MODULE_TARGET} PUBLIC FRAMELESSHELPER_NAMESPACE=${FRAMELESSHELPER_NAMESPACE}) -endif() - target_compile_definitions(${SUB_MODULE_TARGET} PRIVATE FRAMELESSHELPER_QUICK_LIBRARY ) @@ -254,7 +242,7 @@ else() ) endif() -target_link_libraries(${SUB_MODULE_TARGET} PUBLIC +target_link_libraries(${SUB_MODULE_TARGET} PRIVATE ${PROJECT_NAME}::Core ) diff --git a/src/quick/framelesshelperquick_global.cpp b/src/quick/framelesshelperquick_global.cpp index 5db1f283..d565c259 100644 --- a/src/quick/framelesshelperquick_global.cpp +++ b/src/quick/framelesshelperquick_global.cpp @@ -23,24 +23,65 @@ */ #include "framelesshelperquick_global.h" +#include "framelessquickhelper.h" +#include "framelessquickutils.h" +#include "quickimageitem_p.h" +#if FRAMELESSHELPER_CONFIG(titlebar) +# include "quickchromepalette.h" +#endif +#if FRAMELESSHELPER_CONFIG(mica_material) +# include "quickmicamaterial.h" +#endif +#if FRAMELESSHELPER_CONFIG(border_painter) +# include "quickwindowborder.h" +#endif +#if FRAMELESSHELPER_CONFIG(private_qt) +# if FRAMELESSHELPER_CONFIG(window) +# include "framelessquickwindow_p.h" +# endif +# if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +# if FRAMELESSHELPER_CONFIG(window) +# include "framelessquickapplicationwindow_p.h" +# endif +# if FRAMELESSHELPER_CONFIG(system_button) +# include "quickstandardsystembutton_p.h" +# endif +# if FRAMELESSHELPER_CONFIG(titlebar) +# include "quickstandardtitlebar_p.h" +# endif +# endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +#endif #include -#define REG_META_TYPE(Type) qRegisterMetaType(#Type) +#ifndef QUICK_URI_SHORT +# define QUICK_URI_SHORT FRAMELESSHELPER_QUICK_URI, FRAMELESSHELPER_QUICK_VERSION_MAJOR +#endif + +#ifndef QUICK_URI_FULL +# define QUICK_URI_FULL QUICK_URI_SHORT, FRAMELESSHELPER_QUICK_VERSION_MINOR +#endif + +#ifndef QUICK_URI_EXPAND +# define QUICK_URI_EXPAND(name) QUICK_URI_FULL, name +#endif + +#ifndef REG_META_TYPE +# define REG_META_TYPE(Type) qRegisterMetaType(#Type) +#endif FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcQuickGlobal, "wangwenx190.framelesshelper.quick.global") - -#ifdef FRAMELESSHELPER_QUICK_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcQuickGlobal) # define DEBUG qCDebug(lcQuickGlobal) # define WARNING qCWarning(lcQuickGlobal) # define CRITICAL qCCritical(lcQuickGlobal) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif QuickGlobal::QuickGlobal(QObject *parent) : QObject(parent) @@ -49,10 +90,7 @@ QuickGlobal::QuickGlobal(QObject *parent) : QObject(parent) QuickGlobal::~QuickGlobal() = default; -namespace FramelessHelper::Quick -{ - -void initialize() +void FramelessHelperQuickInitialize() { static bool inited = false; if (inited) { @@ -60,7 +98,7 @@ void initialize() } inited = true; - FramelessHelper::Core::initialize(); + FramelessHelperCoreInitialize(); // Registering meta types only causes troubles in Qt6. #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) @@ -72,7 +110,7 @@ void initialize() #endif } -void uninitialize() +void FramelessHelperQuickUninitialize() { static bool uninited = false; if (uninited) { @@ -82,9 +120,80 @@ void uninitialize() // ### TODO: The Quick module-specific uninitialization. - FramelessHelper::Core::uninitialize(); + FramelessHelperCoreUninitialize(); } +void FramelessHelperQuickRegisterTypes(QQmlEngine *engine) +{ + Q_ASSERT(engine); + if (!engine) { + return; + } + + // In most cases we don't need to register the QML types for multiple times. + static bool reg = false; + if (reg) { + return; + } + reg = true; + + // @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; + }); + + qmlRegisterType(QUICK_URI_EXPAND("FramelessHelper")); + qmlRegisterType(QUICK_URI_EXPAND("ImageItem")); + +#if FRAMELESSHELPER_CONFIG(titlebar) + qmlRegisterAnonymousType(QUICK_URI_SHORT); +#endif +#if FRAMELESSHELPER_CONFIG(mica_material) + qmlRegisterType(QUICK_URI_EXPAND("MicaMaterial")); +#endif +#if FRAMELESSHELPER_CONFIG(border_painter) + qmlRegisterType(QUICK_URI_EXPAND("WindowBorder")); +#endif + +#if (FRAMELESSHELPER_CONFIG(private_qt) && FRAMELESSHELPER_CONFIG(window)) + qmlRegisterType(QUICK_URI_EXPAND("FramelessWindow")); +#else + qmlRegisterTypeNotAvailable(QUICK_URI_EXPAND("FramelessWindow"), + FRAMELESSHELPER_STRING_LITERAL("FramelessWindow is not available.")); +#endif + +#if ((QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) && FRAMELESSHELPER_CONFIG(private_qt)) +# if FRAMELESSHELPER_CONFIG(window) + qmlRegisterType(QUICK_URI_EXPAND("FramelessApplicationWindow")); +# endif +# if FRAMELESSHELPER_CONFIG(system_button) + qmlRegisterType(QUICK_URI_EXPAND("StandardSystemButton")); +# endif +# if FRAMELESSHELPER_CONFIG(titlebar) + qmlRegisterType(QUICK_URI_EXPAND("StandardTitleBar")); +# endif +#else +# if FRAMELESSHELPER_CONFIG(window) + qmlRegisterTypeNotAvailable(QUICK_URI_EXPAND("FramelessApplicationWindow"), + FRAMELESSHELPER_STRING_LITERAL("FramelessApplicationWindow is not available.")); +# endif +# if FRAMELESSHELPER_CONFIG(system_button) + qmlRegisterTypeNotAvailable(QUICK_URI_EXPAND("StandardSystemButton"), + FRAMELESSHELPER_STRING_LITERAL("StandardSystemButton is not available.")); +# endif +# if FRAMELESSHELPER_CONFIG(titlebar) + qmlRegisterTypeNotAvailable(QUICK_URI_EXPAND("StandardTitleBar"), + FRAMELESSHELPER_STRING_LITERAL("StandardTitleBar is not available.")); +# endif +#endif + + qmlRegisterModule(QUICK_URI_FULL); } FRAMELESSHELPER_END_NAMESPACE diff --git a/src/quick/framelessquickapplicationwindow.cpp b/src/quick/framelessquickapplicationwindow.cpp index ee600eff..1e06e559 100644 --- a/src/quick/framelessquickapplicationwindow.cpp +++ b/src/quick/framelessquickapplicationwindow.cpp @@ -22,12 +22,15 @@ * SOFTWARE. */ -#ifndef FRAMELESSHELPER_QUICK_NO_PRIVATE - #include "framelessquickapplicationwindow_p.h" #include "framelessquickapplicationwindow_p_p.h" + +#if (FRAMELESSHELPER_CONFIG(private_qt) && FRAMELESSHELPER_CONFIG(window) && (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))) + #include "framelessquickhelper.h" -#include "quickwindowborder.h" +#if FRAMELESSHELPER_CONFIG(border_painter) +# include "quickwindowborder.h" +#endif #ifdef Q_OS_WINDOWS # include #endif // Q_OS_WINDOWS @@ -36,18 +39,17 @@ FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcFramelessQuickApplicationWindow, "wangwenx190.framelesshelper.quick.framelessquickapplicationwindow") - -#ifdef FRAMELESSHELPER_QUICK_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcFramelessQuickApplicationWindow) # define DEBUG qCDebug(lcFramelessQuickApplicationWindow) # define WARNING qCWarning(lcFramelessQuickApplicationWindow) # define CRITICAL qCCritical(lcFramelessQuickApplicationWindow) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; @@ -86,12 +88,14 @@ FramelessQuickApplicationWindow::FramelessQuickApplicationWindow(QWindow *parent { QQuickItem * const rootItem = contentItem(); FramelessQuickHelper::get(rootItem)->extendsContentIntoTitleBar(); +#if FRAMELESSHELPER_CONFIG(border_painter) Q_D(FramelessQuickApplicationWindow); d->windowBorder = new QuickWindowBorder; d->windowBorder->setParent(rootItem); d->windowBorder->setParentItem(rootItem); d->windowBorder->setZ(999); // Make sure it always stays on the top. QQuickItemPrivate::get(d->windowBorder)->anchors()->setFill(rootItem); +#endif connect(this, &FramelessQuickApplicationWindow::visibilityChanged, this, [this](){ Q_EMIT hiddenChanged(); Q_EMIT normalChanged(); @@ -179,4 +183,4 @@ void FramelessQuickApplicationWindow::componentComplete() FRAMELESSHELPER_END_NAMESPACE -#endif // FRAMELESSHELPER_QUICK_NO_PRIVATE +#endif diff --git a/src/quick/framelessquickhelper.cpp b/src/quick/framelessquickhelper.cpp index caa84717..0b937227 100644 --- a/src/quick/framelessquickhelper.cpp +++ b/src/quick/framelessquickhelper.cpp @@ -24,8 +24,12 @@ #include "framelessquickhelper.h" #include "framelessquickhelper_p.h" -#include "quickmicamaterial.h" -#include "quickwindowborder.h" +#if FRAMELESSHELPER_CONFIG(mica_material) +# include "quickmicamaterial.h" +#endif +#if FRAMELESSHELPER_CONFIG(border_painter) +# include "quickwindowborder.h" +#endif #include #include #include @@ -38,14 +42,14 @@ #include #include #include -#ifndef FRAMELESSHELPER_QUICK_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) # if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) # include // For QWINDOWSIZE_MAX # else // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) # include // For QWINDOWSIZE_MAX # endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) # include -#endif // FRAMELESSHELPER_QUICK_NO_PRIVATE +#endif #ifndef QWINDOWSIZE_MAX # define QWINDOWSIZE_MAX ((1 << 24) - 1) @@ -53,18 +57,17 @@ FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcFramelessQuickHelper, "wangwenx190.framelesshelper.quick.framelessquickhelper") - -#ifdef FRAMELESSHELPER_QUICK_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcFramelessQuickHelper) # define DEBUG qCDebug(lcFramelessQuickHelper) # define WARNING qCWarning(lcFramelessQuickHelper) # define CRITICAL qCCritical(lcFramelessQuickHelper) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; @@ -265,6 +268,7 @@ QVariant FramelessQuickHelperPrivate::getProperty(const char *name, const QVaria return ((value.isValid() && !value.isNull()) ? value : defaultValue); } +#if FRAMELESSHELPER_CONFIG(mica_material) QuickMicaMaterial *FramelessQuickHelperPrivate::findOrCreateMicaMaterial() const { Q_Q(const FramelessQuickHelper); @@ -283,12 +287,14 @@ QuickMicaMaterial *FramelessQuickHelperPrivate::findOrCreateMicaMaterial() const item->setParent(rootItem); item->setParentItem(rootItem); item->setZ(-999); // Make sure it always stays on the bottom. -#ifndef FRAMELESSHELPER_QUICK_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) QQuickItemPrivate::get(item)->anchors()->setFill(rootItem); -#endif // FRAMELESSHELPER_QUICK_NO_PRIVATE +#endif return item; } +#endif +#if FRAMELESSHELPER_CONFIG(border_painter) QuickWindowBorder *FramelessQuickHelperPrivate::findOrCreateWindowBorder() const { Q_Q(const FramelessQuickHelper); @@ -307,11 +313,12 @@ QuickWindowBorder *FramelessQuickHelperPrivate::findOrCreateWindowBorder() const item->setParent(rootItem); item->setParentItem(rootItem); item->setZ(999); // Make sure it always stays on the top. -#ifndef FRAMELESSHELPER_QUICK_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) QQuickItemPrivate::get(item)->anchors()->setFill(rootItem); -#endif // FRAMELESSHELPER_QUICK_NO_PRIVATE +#endif return item; } +#endif FramelessQuickHelper *FramelessQuickHelperPrivate::findOrCreateFramelessHelper(QObject *object) { @@ -634,17 +641,21 @@ FramelessQuickHelper *FramelessQuickHelper::qmlAttachedProperties(QObject *paren return get(parentObject); } +#if FRAMELESSHELPER_CONFIG(mica_material) QuickMicaMaterial *FramelessQuickHelper::micaMaterial() const { Q_D(const FramelessQuickHelper); return d->findOrCreateMicaMaterial(); } +#endif +#if FRAMELESSHELPER_CONFIG(border_painter) QuickWindowBorder *FramelessQuickHelper::windowBorder() const { Q_D(const FramelessQuickHelper); return d->findOrCreateWindowBorder(); } +#endif void FramelessQuickHelper::setHitTestVisible(QQuickItem *item, const bool visible) { @@ -790,7 +801,7 @@ void FramelessQuickHelper::showSystemMenu(const QPoint &pos) #ifdef Q_OS_WINDOWS Q_D(FramelessQuickHelper); std::ignore = Utils::showSystemMenu(windowId, nativePos, false, &d->getWindowData()->params); -#elif defined(Q_OS_LINUX) +#elif (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)) Utils::openSystemMenu(windowId, nativePos); #else Q_UNUSED(windowId); @@ -932,7 +943,9 @@ void FramelessQuickHelper::setBlurBehindWindowEnabled(const bool value) } } else { d->blurBehindWindowEnabled = value; +#if FRAMELESSHELPER_CONFIG(mica_material) micaMaterial()->setVisible(d->blurBehindWindowEnabled); +#endif d->emitSignalForAllInstances("blurBehindWindowEnabledChanged"); } } diff --git a/src/quick/framelessquickmodule.cpp b/src/quick/framelessquickmodule.cpp deleted file mode 100644 index 8f6ed7bf..00000000 --- a/src/quick/framelessquickmodule.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - * MIT License - * - * Copyright (C) 2021-2023 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 "framelessquickmodule.h" -#include "framelessquickhelper.h" -#include "framelessquickutils.h" -#include "quickchromepalette.h" -#include "quickmicamaterial.h" -#include "quickimageitem.h" -#include "quickwindowborder.h" -#ifndef FRAMELESSHELPER_QUICK_NO_PRIVATE -# include "framelessquickwindow_p.h" -# if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) -# include "framelessquickapplicationwindow_p.h" -# include "quickstandardsystembutton_p.h" -# include "quickstandardtitlebar_p.h" -# endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) -#endif // FRAMELESSHELPER_QUICK_NO_PRIVATE -#include - -#ifndef QUICK_URI_SHORT -# define QUICK_URI_SHORT FRAMELESSHELPER_QUICK_URI, FRAMELESSHELPER_QUICK_VERSION_MAJOR -#endif - -#ifndef QUICK_URI_FULL -# define QUICK_URI_FULL QUICK_URI_SHORT, FRAMELESSHELPER_QUICK_VERSION_MINOR -#endif - -#ifndef QUICK_URI_EXPAND -# define QUICK_URI_EXPAND(name) QUICK_URI_FULL, name -#endif - -FRAMELESSHELPER_BEGIN_NAMESPACE - -[[maybe_unused]] static Q_LOGGING_CATEGORY(lcQuickModule, "wangwenx190.framelesshelper.quick.quickmodule") - -#ifdef FRAMELESSHELPER_QUICK_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else -# define INFO qCInfo(lcQuickModule) -# define DEBUG qCDebug(lcQuickModule) -# define WARNING qCWarning(lcQuickModule) -# define CRITICAL qCCritical(lcQuickModule) -#endif - -void FramelessHelper::Quick::registerTypes(QQmlEngine *engine) -{ - Q_ASSERT(engine); - if (!engine) { - return; - } - - // In most cases we don't need to register the QML types for multiple times. - static bool reg = false; - if (reg) { - return; - } - reg = true; - - // @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); - - qmlRegisterType(QUICK_URI_EXPAND("FramelessHelper")); - qmlRegisterType(QUICK_URI_EXPAND("MicaMaterial")); - qmlRegisterType(QUICK_URI_EXPAND("ImageItem")); - qmlRegisterType(QUICK_URI_EXPAND("WindowBorder")); - -#ifdef FRAMELESSHELPER_QUICK_NO_PRIVATE - qmlRegisterTypeNotAvailable(QUICK_URI_EXPAND("FramelessWindow"), - FRAMELESSHELPER_STRING_LITERAL("FramelessWindow is not available.")); -#else // !FRAMELESSHELPER_QUICK_NO_PRIVATE - qmlRegisterType(QUICK_URI_EXPAND("FramelessWindow")); -#endif // FRAMELESSHELPER_QUICK_NO_PRIVATE - -#if ((QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) && !defined(FRAMELESSHELPER_QUICK_NO_PRIVATE)) - qmlRegisterType(QUICK_URI_EXPAND("FramelessApplicationWindow")); - qmlRegisterType(QUICK_URI_EXPAND("StandardSystemButton")); - qmlRegisterType(QUICK_URI_EXPAND("StandardTitleBar")); -#else // ((QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) || FRAMELESSHELPER_QUICK_NO_PRIVATE) - qmlRegisterTypeNotAvailable(QUICK_URI_EXPAND("FramelessApplicationWindow"), - FRAMELESSHELPER_STRING_LITERAL("FramelessApplicationWindow is not available.")); - qmlRegisterTypeNotAvailable(QUICK_URI_EXPAND("StandardSystemButton"), - FRAMELESSHELPER_STRING_LITERAL("StandardSystemButton is not available.")); - qmlRegisterTypeNotAvailable(QUICK_URI_EXPAND("StandardTitleBar"), - FRAMELESSHELPER_STRING_LITERAL("StandardTitleBar is not available.")); -#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) - - qmlRegisterModule(QUICK_URI_FULL); -} - -FRAMELESSHELPER_END_NAMESPACE diff --git a/src/quick/framelessquickutils.cpp b/src/quick/framelessquickutils.cpp index 8bdbf309..06ba473a 100644 --- a/src/quick/framelessquickutils.cpp +++ b/src/quick/framelessquickutils.cpp @@ -32,18 +32,17 @@ FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcFramelessQuickUtils, "wangwenx190.framelesshelper.quick.framelessquickutils") - -#ifdef FRAMELESSHELPER_QUICK_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcFramelessQuickUtils) # define DEBUG qCDebug(lcFramelessQuickUtils) # define WARNING qCWarning(lcFramelessQuickUtils) # define CRITICAL qCCritical(lcFramelessQuickUtils) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; diff --git a/src/quick/framelessquickwindow.cpp b/src/quick/framelessquickwindow.cpp index 08567bbc..58f22fe3 100644 --- a/src/quick/framelessquickwindow.cpp +++ b/src/quick/framelessquickwindow.cpp @@ -22,12 +22,15 @@ * SOFTWARE. */ -#ifndef FRAMELESSHELPER_QUICK_NO_PRIVATE - #include "framelessquickwindow_p.h" #include "framelessquickwindow_p_p.h" + +#if (FRAMELESSHELPER_CONFIG(private_qt) && FRAMELESSHELPER_CONFIG(window)) + #include "framelessquickhelper.h" -#include "quickwindowborder.h" +#if FRAMELESSHELPER_CONFIG(border_painter) +# include "quickwindowborder.h" +#endif #ifdef Q_OS_WINDOWS # include #endif // Q_OS_WINDOWS @@ -36,18 +39,17 @@ FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcFramelessQuickWindow, "wangwenx190.framelesshelper.quick.framelessquickwindow") - -#ifdef FRAMELESSHELPER_QUICK_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcFramelessQuickWindow) # define DEBUG qCDebug(lcFramelessQuickWindow) # define WARNING qCWarning(lcFramelessQuickWindow) # define CRITICAL qCCritical(lcFramelessQuickWindow) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; @@ -86,12 +88,14 @@ FramelessQuickWindow::FramelessQuickWindow(QWindow *parent) { QQuickItem * const rootItem = contentItem(); FramelessQuickHelper::get(rootItem)->extendsContentIntoTitleBar(); +#if FRAMELESSHELPER_CONFIG(border_painter) Q_D(FramelessQuickWindow); d->windowBorder = new QuickWindowBorder; d->windowBorder->setParent(rootItem); d->windowBorder->setParentItem(rootItem); d->windowBorder->setZ(999); // Make sure it always stays on the top. QQuickItemPrivate::get(d->windowBorder)->anchors()->setFill(rootItem); +#endif connect(this, &FramelessQuickWindow::visibilityChanged, this, [this](){ Q_EMIT hiddenChanged(); Q_EMIT normalChanged(); @@ -179,4 +183,4 @@ void FramelessQuickWindow::componentComplete() FRAMELESSHELPER_END_NAMESPACE -#endif // FRAMELESSHELPER_QUICK_NO_PRIVATE +#endif diff --git a/src/quick/quickchromepalette.cpp b/src/quick/quickchromepalette.cpp index 5088ef46..3d7db306 100644 --- a/src/quick/quickchromepalette.cpp +++ b/src/quick/quickchromepalette.cpp @@ -23,22 +23,24 @@ */ #include "quickchromepalette.h" + +#if FRAMELESSHELPER_CONFIG(titlebar) + #include FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcQuickChromePalette, "wangwenx190.framelesshelper.quick.quickchromepalette") - -#ifdef FRAMELESSHELPER_QUICK_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcQuickChromePalette) # define DEBUG qCDebug(lcQuickChromePalette) # define WARNING qCWarning(lcQuickChromePalette) # define CRITICAL qCCritical(lcQuickChromePalette) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif QuickChromePalette::QuickChromePalette(QObject *parent) : ChromePalette(parent) @@ -56,3 +58,5 @@ void QuickChromePalette::componentComplete() } FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/src/quick/quickimageitem.cpp b/src/quick/quickimageitem.cpp index c4f2fa19..096389d7 100644 --- a/src/quick/quickimageitem.cpp +++ b/src/quick/quickimageitem.cpp @@ -22,7 +22,6 @@ * SOFTWARE. */ -#include "quickimageitem.h" #include "quickimageitem_p.h" #include #include @@ -32,18 +31,17 @@ FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcQuickImageItem, "wangwenx190.framelesshelper.quick.quickimageitem") - -#ifdef FRAMELESSHELPER_QUICK_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcQuickImageItem) # define DEBUG qCDebug(lcQuickImageItem) # define WARNING qCWarning(lcQuickImageItem) # define CRITICAL qCCritical(lcQuickImageItem) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; @@ -53,36 +51,72 @@ FRAMELESSHELPER_STRING_CONSTANT2(FileSystemPrefix, ":") FRAMELESSHELPER_STRING_CONSTANT2(UrlPrefix, ":///") FRAMELESSHELPER_STRING_CONSTANT2(FilePathPrefix, ":/") -QuickImageItemPrivate::QuickImageItemPrivate(QuickImageItem *q) : QObject(q) +QuickImageItem::QuickImageItem(QQuickItem *parent) : QQuickPaintedItem(parent) { - Q_ASSERT(q); - if (!q) { - return; - } - q_ptr = q; + setAntialiasing(true); + setSmooth(true); + setMipmap(true); + setClip(true); } -QuickImageItemPrivate::~QuickImageItemPrivate() = default; +QuickImageItem::~QuickImageItem() = default; -QuickImageItemPrivate *QuickImageItemPrivate::get(QuickImageItem *q) +void QuickImageItem::paint(QPainter *painter) { - Q_ASSERT(q); - if (!q) { - return nullptr; + Q_ASSERT(painter); + if (!painter) { + return; + } + if (!m_source.isValid() || m_source.isNull()) { + return; + } + painter->save(); + painter->setRenderHints(QPainter::Antialiasing | + QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); + switch (m_source.userType()) { + case QMetaType::QUrl: + fromUrl(m_source.toUrl(), painter); + break; + case QMetaType::QString: + fromString(m_source.toString(), painter); + break; + case QMetaType::QImage: + fromImage(qvariant_cast(m_source), painter); + break; + case QMetaType::QPixmap: + fromPixmap(qvariant_cast(m_source), painter); + break; + case QMetaType::QIcon: + fromIcon(qvariant_cast(m_source), painter); + break; + default: + WARNING << "Unsupported type:" << m_source.typeName(); + break; } - return q->d_func(); + painter->restore(); } -const QuickImageItemPrivate *QuickImageItemPrivate::get(const QuickImageItem *q) +QVariant QuickImageItem::source() const { - Q_ASSERT(q); - if (!q) { - return nullptr; + return m_source; +} + +void QuickImageItem::setSource(const QVariant &value) +{ + Q_ASSERT(value.isValid()); + Q_ASSERT(!value.isNull()); + if (!value.isValid() || value.isNull()) { + return; + } + if (m_source == value) { + return; } - return q->d_func(); + m_source = value; + update(); + Q_EMIT sourceChanged(); } -void QuickImageItemPrivate::fromUrl(const QUrl &value, QPainter *painter) const +void QuickImageItem::fromUrl(const QUrl &value, QPainter *painter) const { Q_ASSERT(value.isValid()); Q_ASSERT(painter); @@ -92,7 +126,7 @@ void QuickImageItemPrivate::fromUrl(const QUrl &value, QPainter *painter) const fromString((value.isLocalFile() ? value.toLocalFile() : value.toString()), painter); } -void QuickImageItemPrivate::fromString(const QString &value, QPainter *painter) const +void QuickImageItem::fromString(const QString &value, QPainter *painter) const { Q_ASSERT(!value.isEmpty()); Q_ASSERT(painter); @@ -100,21 +134,21 @@ void QuickImageItemPrivate::fromString(const QString &value, QPainter *painter) return; } return fromPixmap(QPixmap([&value]() -> QString { - // For most Qt classes, the "qrc:///" prefix won't be recognized as a valid - // file system path, unless it accepts a QUrl object. For QString constructors - // we can only use ":/" to represent the file system path. - QString path = value; - if (path.startsWith(kQrcPrefix, Qt::CaseInsensitive)) { - path.replace(kQrcPrefix, kFileSystemPrefix, Qt::CaseInsensitive); - } - if (path.startsWith(kUrlPrefix, Qt::CaseInsensitive)) { - path.replace(kUrlPrefix, kFilePathPrefix, Qt::CaseInsensitive); - } - return path; - }()), painter); + // For most Qt classes, the "qrc:///" prefix won't be recognized as a valid + // file system path, unless it accepts a QUrl object. For QString constructors + // we can only use ":/" to represent the file system path. + QString path = value; + if (path.startsWith(kQrcPrefix, Qt::CaseInsensitive)) { + path.replace(kQrcPrefix, kFileSystemPrefix, Qt::CaseInsensitive); + } + if (path.startsWith(kUrlPrefix, Qt::CaseInsensitive)) { + path.replace(kUrlPrefix, kFilePathPrefix, Qt::CaseInsensitive); + } + return path; + }()), painter); } -void QuickImageItemPrivate::fromImage(const QImage &value, QPainter *painter) const +void QuickImageItem::fromImage(const QImage &value, QPainter *painter) const { Q_ASSERT(!value.isNull()); Q_ASSERT(painter); @@ -124,7 +158,7 @@ void QuickImageItemPrivate::fromImage(const QImage &value, QPainter *painter) co fromPixmap(QPixmap::fromImage(value), painter); } -void QuickImageItemPrivate::fromPixmap(const QPixmap &value, QPainter *painter) const +void QuickImageItem::fromPixmap(const QPixmap &value, QPainter *painter) const { Q_ASSERT(!value.isNull()); Q_ASSERT(painter); @@ -136,7 +170,7 @@ void QuickImageItemPrivate::fromPixmap(const QPixmap &value, QPainter *painter) painter->drawPixmap(paintRect.topLeft(), (value.size() == paintSize ? value : value.scaled(paintSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation))); } -void QuickImageItemPrivate::fromIcon(const QIcon &value, QPainter *painter) const +void QuickImageItem::fromIcon(const QIcon &value, QPainter *painter) const { Q_ASSERT(!value.isNull()); Q_ASSERT(painter); @@ -146,84 +180,14 @@ void QuickImageItemPrivate::fromIcon(const QIcon &value, QPainter *painter) cons fromPixmap(value.pixmap(paintArea().size().toSize()), painter); } -QRectF QuickImageItemPrivate::paintArea() const +QRectF QuickImageItem::paintArea() const { - Q_Q(const QuickImageItem); #if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) - const QSizeF size = q->size(); + const QSizeF s = size(); #else - const QSizeF size = {q->width(), q->height()}; + const QSizeF s = {width(), height()}; #endif - return {QPointF(0, 0), size}; -} - -QuickImageItem::QuickImageItem(QQuickItem *parent) - : QQuickPaintedItem(parent), d_ptr(new QuickImageItemPrivate(this)) -{ - setAntialiasing(true); - setSmooth(true); - setMipmap(true); - setClip(true); -} - -QuickImageItem::~QuickImageItem() = default; - -void QuickImageItem::paint(QPainter *painter) -{ - Q_ASSERT(painter); - if (!painter) { - return; - } - Q_D(QuickImageItem); - if (!d->source.isValid() || d->source.isNull()) { - return; - } - painter->save(); - painter->setRenderHints(QPainter::Antialiasing | - QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); - switch (d->source.userType()) { - case QMetaType::QUrl: - d->fromUrl(d->source.toUrl(), painter); - break; - case QMetaType::QString: - d->fromString(d->source.toString(), painter); - break; - case QMetaType::QImage: - d->fromImage(qvariant_cast(d->source), painter); - break; - case QMetaType::QPixmap: - d->fromPixmap(qvariant_cast(d->source), painter); - break; - case QMetaType::QIcon: - d->fromIcon(qvariant_cast(d->source), painter); - break; - default: - WARNING << "Unsupported type:" << d->source.typeName(); - break; - } - painter->restore(); -} - -QVariant QuickImageItem::source() const -{ - Q_D(const QuickImageItem); - return d->source; -} - -void QuickImageItem::setSource(const QVariant &value) -{ - Q_ASSERT(value.isValid()); - Q_ASSERT(!value.isNull()); - if (!value.isValid() || value.isNull()) { - return; - } - Q_D(QuickImageItem); - if (d->source == value) { - return; - } - d->source = value; - update(); - Q_EMIT sourceChanged(); + return {QPointF(0, 0), s}; } void QuickImageItem::classBegin() diff --git a/src/quick/quickmicamaterial.cpp b/src/quick/quickmicamaterial.cpp index 5e610536..eb806cb9 100644 --- a/src/quick/quickmicamaterial.cpp +++ b/src/quick/quickmicamaterial.cpp @@ -24,28 +24,30 @@ #include "quickmicamaterial.h" #include "quickmicamaterial_p.h" + +#if FRAMELESSHELPER_CONFIG(mica_material) + #include #include #include -#ifndef FRAMELESSHELPER_QUICK_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) # include # include #endif // FRAMELESSHELPER_QUICK_NO_PRIVATE FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcQuickMicaMaterial, "wangwenx190.framelesshelper.quick.quickmicamaterial") - -#ifdef FRAMELESSHELPER_QUICK_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcQuickMicaMaterial) # define DEBUG qCDebug(lcQuickMicaMaterial) # define WARNING qCWarning(lcQuickMicaMaterial) # define CRITICAL qCCritical(lcQuickMicaMaterial) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; @@ -121,7 +123,7 @@ void QuickMicaMaterialPrivate::rebindWindow() QQuickItem * const rootItem = window->contentItem(); q->setParent(rootItem); q->setParentItem(rootItem); -#ifndef FRAMELESSHELPER_QUICK_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) QQuickItemPrivate::get(q)->anchors()->setFill(rootItem); #endif // FRAMELESSHELPER_QUICK_NO_PRIVATE q->setZ(-999); // Make sure we always stays on the bottom most place. @@ -255,3 +257,5 @@ void QuickMicaMaterial::componentComplete() } FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/src/quick/quickstandardsystembutton.cpp b/src/quick/quickstandardsystembutton.cpp index 790739f0..ef09aa22 100644 --- a/src/quick/quickstandardsystembutton.cpp +++ b/src/quick/quickstandardsystembutton.cpp @@ -22,10 +22,10 @@ * SOFTWARE. */ -#ifndef FRAMELESSHELPER_QUICK_NO_PRIVATE - #include "quickstandardsystembutton_p.h" -#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + +#if (FRAMELESSHELPER_CONFIG(private_qt) && FRAMELESSHELPER_CONFIG(system_button) && (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))) + #include #include #include @@ -38,18 +38,17 @@ FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcQuickStandardSystemButton, "wangwenx190.framelesshelper.quick.quickstandardsystembutton") - -#ifdef FRAMELESSHELPER_QUICK_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcQuickStandardSystemButton) # define DEBUG qCDebug(lcQuickStandardSystemButton) # define WARNING qCWarning(lcQuickStandardSystemButton) # define CRITICAL qCCritical(lcQuickStandardSystemButton) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; @@ -101,7 +100,7 @@ QColor QuickStandardSystemButton::inactiveForegroundColor() const return m_inactiveForegroundColor; } -qreal QuickStandardSystemButton::iconSize() const +qreal QuickStandardSystemButton::glyphSize() const { if (!m_contentItem) { return -1; @@ -217,19 +216,19 @@ void QuickStandardSystemButton::setInactiveForegroundColor(const QColor &value) Q_EMIT inactiveForegroundColorChanged(); } -void QuickStandardSystemButton::setIconSize(const qreal value) +void QuickStandardSystemButton::setGlyphSize(const qreal value) { Q_ASSERT(value > 0); if (qFuzzyIsNull(value) || (value < 0)) { return; } - if (qFuzzyCompare(iconSize(), value)) { + if (qFuzzyCompare(glyphSize(), value)) { return; } QFont font = m_contentItem->font(); font.setPointSizeF(value); m_contentItem->setFont(font); - Q_EMIT iconSizeChanged(); + Q_EMIT glyphSizeChanged(); } void QuickStandardSystemButton::updateColor() @@ -302,6 +301,5 @@ void QuickStandardSystemButton::componentComplete() } FRAMELESSHELPER_END_NAMESPACE -#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) -#endif // FRAMELESSHELPER_QUICK_NO_PRIVATE +#endif diff --git a/src/quick/quickstandardtitlebar.cpp b/src/quick/quickstandardtitlebar.cpp index 32d9724a..5f527a3d 100644 --- a/src/quick/quickstandardtitlebar.cpp +++ b/src/quick/quickstandardtitlebar.cpp @@ -22,14 +22,19 @@ * SOFTWARE. */ -#ifndef FRAMELESSHELPER_QUICK_NO_PRIVATE - #include "quickstandardtitlebar_p.h" -#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) -#include "quickimageitem.h" + +#if (FRAMELESSHELPER_CONFIG(private_qt) && FRAMELESSHELPER_CONFIG(titlebar) && (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))) + +#include "quickimageitem_p.h" #include "framelessquickhelper.h" -#include "quickstandardsystembutton_p.h" -#include "framelessquickwindow_p.h" +#if FRAMELESSHELPER_CONFIG(system_button) +# include "quickstandardsystembutton_p.h" +#endif +#if FRAMELESSHELPER_CONFIG(window) +# include "framelessquickwindow_p.h" +# include "framelessquickapplicationwindow_p.h" +#endif #include #include #include @@ -41,18 +46,17 @@ FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcQuickStandardTitleBar, "wangwenx190.framelesshelper.quick.quickstandardtitlebar") - -#ifdef FRAMELESSHELPER_QUICK_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcQuickStandardTitleBar) # define DEBUG qCDebug(lcQuickStandardTitleBar) # define WARNING qCWarning(lcQuickStandardTitleBar) # define CRITICAL qCCritical(lcQuickStandardTitleBar) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; @@ -120,7 +124,7 @@ QQuickLabel *QuickStandardTitleBar::titleLabel() const return m_windowTitleLabel; } -#ifndef Q_OS_MACOS +#if (!defined(Q_OS_MACOS) && FRAMELESSHELPER_CONFIG(system_button)) QuickStandardSystemButton *QuickStandardTitleBar::minimizeButton() const { return m_minimizeButton; @@ -135,7 +139,7 @@ QuickStandardSystemButton *QuickStandardTitleBar::closeButton() const { return m_closeButton; } -#endif // Q_OS_MACOS +#endif bool QuickStandardTitleBar::isExtended() const { @@ -240,7 +244,7 @@ void QuickStandardTitleBar::setWindowIcon(const QVariant &value) void QuickStandardTitleBar::updateMaximizeButton() { -#ifndef Q_OS_MACOS +#if (!defined(Q_OS_MACOS) && FRAMELESSHELPER_CONFIG(system_button)) const QQuickWindow * const w = window(); if (!w) { return; @@ -248,7 +252,7 @@ void QuickStandardTitleBar::updateMaximizeButton() const bool max = (w->visibility() == QQuickWindow::Maximized); m_maximizeButton->setButtonType(max ? QuickGlobal::SystemButtonType::Restore : QuickGlobal::SystemButtonType::Maximize); qobject_cast(qmlAttachedPropertiesObject(m_maximizeButton))->setText(max ? tr("Restore") : tr("Maximize")); -#endif // Q_OS_MACOS +#endif } void QuickStandardTitleBar::updateTitleLabelText() @@ -279,7 +283,7 @@ void QuickStandardTitleBar::updateTitleBarColor() void QuickStandardTitleBar::updateChromeButtonColor() { -#ifndef Q_OS_MACOS +#if (!defined(Q_OS_MACOS) && FRAMELESSHELPER_CONFIG(system_button)) const QQuickWindow * const w = window(); if (!w) { return; @@ -307,7 +311,7 @@ void QuickStandardTitleBar::updateChromeButtonColor() m_closeButton->setHoverColor(m_chromePalette->closeButtonHoverColor()); m_closeButton->setPressColor(m_chromePalette->closeButtonPressColor()); m_closeButton->updateColor(); -#endif // Q_OS_MACOS +#endif } void QuickStandardTitleBar::clickMinimizeButton() @@ -316,9 +320,14 @@ void QuickStandardTitleBar::clickMinimizeButton() if (!w) { return; } +#if FRAMELESSHELPER_CONFIG(window) if (const auto _w = qobject_cast(w)) { _w->showMinimized2(); - } else { + } else if (const auto _w2 = qobject_cast(w)) { + _w2->showMinimized2(); + } else +#endif + { w->setVisibility(QQuickWindow::Minimized); } } @@ -351,7 +360,7 @@ void QuickStandardTitleBar::clickCloseButton() void QuickStandardTitleBar::retranslateUi() { -#ifndef Q_OS_MACOS +#if (!defined(Q_OS_MACOS) && FRAMELESSHELPER_CONFIG(system_button)) qobject_cast(qmlAttachedPropertiesObject(m_minimizeButton))->setText(tr("Minimize")); qobject_cast(qmlAttachedPropertiesObject(m_maximizeButton))->setText([this]() -> QString { if (const QQuickWindow * const w = window()) { @@ -362,7 +371,7 @@ void QuickStandardTitleBar::retranslateUi() return tr("Maximize"); }()); qobject_cast(qmlAttachedPropertiesObject(m_closeButton))->setText(tr("Close")); -#endif // Q_OS_MACOS +#endif } void QuickStandardTitleBar::updateWindowIcon() @@ -516,7 +525,7 @@ void QuickStandardTitleBar::initialize() connect(m_windowIcon, &QuickImageItem::widthChanged, this, &QuickStandardTitleBar::windowIconSizeChanged); connect(m_windowIcon, &QuickImageItem::heightChanged, this, &QuickStandardTitleBar::windowIconSizeChanged); -#ifndef Q_OS_MACOS +#if (!defined(Q_OS_MACOS) && FRAMELESSHELPER_CONFIG(system_button)) m_systemButtonsRow = new QQuickRow(this); QQuickAnchors * const rowAnchors = QQuickItemPrivate::get(m_systemButtonsRow)->anchors(); rowAnchors->setTop(thisPriv->top()); @@ -527,7 +536,7 @@ void QuickStandardTitleBar::initialize() connect(m_maximizeButton, &QuickStandardSystemButton::clicked, this, &QuickStandardTitleBar::clickMaximizeButton); m_closeButton = new QuickStandardSystemButton(QuickGlobal::SystemButtonType::Close, m_systemButtonsRow); connect(m_closeButton, &QuickStandardSystemButton::clicked, this, &QuickStandardTitleBar::clickCloseButton); -#endif // Q_OS_MACOS +#endif setWindowIconSize(kDefaultWindowIconSize); setWindowIconVisible(false); @@ -619,6 +628,5 @@ void QuickStandardTitleBar::componentComplete() } FRAMELESSHELPER_END_NAMESPACE -#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) -#endif // FRAMELESSHELPER_QUICK_NO_PRIVATE +#endif diff --git a/src/quick/quickwindowborder.cpp b/src/quick/quickwindowborder.cpp index b6e90faa..828336d3 100644 --- a/src/quick/quickwindowborder.cpp +++ b/src/quick/quickwindowborder.cpp @@ -24,27 +24,29 @@ #include "quickwindowborder.h" #include "quickwindowborder_p.h" + +#if FRAMELESSHELPER_CONFIG(border_painter) + #include #include #include -#ifndef FRAMELESSHELPER_QUICK_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) # include -#endif // FRAMELESSHELPER_QUICK_NO_PRIVATE +#endif FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcQuickWindowBorder, "wangwenx190.framelesshelper.quick.quickwindowborder") - -#ifdef FRAMELESSHELPER_QUICK_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcQuickWindowBorder) # define DEBUG qCDebug(lcQuickWindowBorder) # define WARNING qCWarning(lcQuickWindowBorder) # define CRITICAL qCCritical(lcQuickWindowBorder) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; @@ -159,9 +161,9 @@ void QuickWindowBorderPrivate::rebindWindow() QQuickItem * const rootItem = window->contentItem(); q->setParent(rootItem); q->setParentItem(rootItem); -#ifndef FRAMELESSHELPER_QUICK_NO_PRIVATE +#if FRAMELESSHELPER_CONFIG(private_qt) QQuickItemPrivate::get(q)->anchors()->setFill(rootItem); -#endif // FRAMELESSHELPER_QUICK_NO_PRIVATE +#endif q->setZ(999); // Make sure we always stays on the top most place. if (activeChangeConnection) { disconnect(activeChangeConnection); @@ -202,59 +204,54 @@ void QuickWindowBorder::paint(QPainter *painter) qreal QuickWindowBorder::thickness() const { Q_D(const QuickWindowBorder); - return ((d->borderPainter == nullptr) ? 0 : d->borderPainter->thickness()); + return d->borderPainter->thickness(); } QuickGlobal::WindowEdges QuickWindowBorder::edges() const { Q_D(const QuickWindowBorder); - return ((d->borderPainter == nullptr) ? QuickGlobal::WindowEdges() - : edgesToQuickEdges(d->borderPainter->edges())); + return edgesToQuickEdges(d->borderPainter->edges()); } QColor QuickWindowBorder::activeColor() const { Q_D(const QuickWindowBorder); - return ((d->borderPainter == nullptr) ? QColor() : d->borderPainter->activeColor()); + return d->borderPainter->activeColor(); } QColor QuickWindowBorder::inactiveColor() const { Q_D(const QuickWindowBorder); - return ((d->borderPainter == nullptr) ? QColor() : d->borderPainter->inactiveColor()); + return d->borderPainter->inactiveColor(); } qreal QuickWindowBorder::nativeThickness() const { Q_D(const QuickWindowBorder); - return ((d->borderPainter == nullptr) ? 0 : d->borderPainter->nativeThickness()); + return d->borderPainter->nativeThickness(); } QuickGlobal::WindowEdges QuickWindowBorder::nativeEdges() const { Q_D(const QuickWindowBorder); - return ((d->borderPainter == nullptr) ? QuickGlobal::WindowEdges() - : edgesToQuickEdges(d->borderPainter->nativeEdges())); + return edgesToQuickEdges(d->borderPainter->nativeEdges()); } QColor QuickWindowBorder::nativeActiveColor() const { Q_D(const QuickWindowBorder); - return ((d->borderPainter == nullptr) ? QColor() : d->borderPainter->nativeActiveColor()); + return d->borderPainter->nativeActiveColor(); } QColor QuickWindowBorder::nativeInactiveColor() const { Q_D(const QuickWindowBorder); - return ((d->borderPainter == nullptr) ? QColor() : d->borderPainter->nativeInactiveColor()); + return d->borderPainter->nativeInactiveColor(); } void QuickWindowBorder::setThickness(const qreal value) { Q_D(QuickWindowBorder); - if (!d->borderPainter) { - return; - } if (qFuzzyCompare(thickness(), value)) { return; } @@ -264,9 +261,6 @@ void QuickWindowBorder::setThickness(const qreal value) void QuickWindowBorder::setEdges(const QuickGlobal::WindowEdges value) { Q_D(QuickWindowBorder); - if (!d->borderPainter) { - return; - } if (edges() == value) { return; } @@ -276,9 +270,6 @@ void QuickWindowBorder::setEdges(const QuickGlobal::WindowEdges value) void QuickWindowBorder::setActiveColor(const QColor &value) { Q_D(QuickWindowBorder); - if (!d->borderPainter) { - return; - } if (activeColor() == value) { return; } @@ -288,9 +279,6 @@ void QuickWindowBorder::setActiveColor(const QColor &value) void QuickWindowBorder::setInactiveColor(const QColor &value) { Q_D(QuickWindowBorder); - if (!d->borderPainter) { - return; - } if (inactiveColor() == value) { return; } @@ -317,3 +305,5 @@ void QuickWindowBorder::componentComplete() } FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt index 535765e6..7fa5b816 100644 --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -35,45 +35,62 @@ set(INCLUDE_PREFIX ../../include/${SUB_MODULE_PATH}) set(PUBLIC_HEADERS ${INCLUDE_PREFIX}/framelesshelperwidgets_global.h - ${INCLUDE_PREFIX}/framelesswidget.h - ${INCLUDE_PREFIX}/framelessmainwindow.h - ${INCLUDE_PREFIX}/standardsystembutton.h ${INCLUDE_PREFIX}/framelesswidgetshelper.h - ${INCLUDE_PREFIX}/standardtitlebar.h - ${INCLUDE_PREFIX}/framelessdialog.h ) set(PUBLIC_HEADERS_ALIAS ${INCLUDE_PREFIX}/Global - ${INCLUDE_PREFIX}/FramelessWidget - ${INCLUDE_PREFIX}/FramelessMainWindow - ${INCLUDE_PREFIX}/StandardSystemButton ${INCLUDE_PREFIX}/FramelessWidgetsHelper - ${INCLUDE_PREFIX}/StandardTitleBar - ${INCLUDE_PREFIX}/FramelessDialog ) set(PRIVATE_HEADERS ${INCLUDE_PREFIX}/private/framelesswidgetshelper_p.h - ${INCLUDE_PREFIX}/private/standardsystembutton_p.h - ${INCLUDE_PREFIX}/private/standardtitlebar_p.h - ${INCLUDE_PREFIX}/private/framelesswidget_p.h - ${INCLUDE_PREFIX}/private/framelessmainwindow_p.h ${INCLUDE_PREFIX}/private/widgetssharedhelper_p.h - ${INCLUDE_PREFIX}/private/framelessdialog_p.h ) set(SOURCES - framelessmainwindow.cpp framelesswidgetshelper.cpp - framelesswidget.cpp - standardsystembutton.cpp - standardtitlebar.cpp widgetssharedhelper.cpp framelesshelperwidgets_global.cpp - framelessdialog.cpp ) +if(NOT FRAMELESSHELPER_NO_SYSTEM_BUTTON) + list(APPEND PUBLIC_HEADERS ${INCLUDE_PREFIX}/standardsystembutton.h) + list(APPEND PUBLIC_HEADERS_ALIAS ${INCLUDE_PREFIX}/StandardSystemButton) + list(APPEND PRIVATE_HEADERS ${INCLUDE_PREFIX}/private/standardsystembutton_p.h) + list(APPEND SOURCES standardsystembutton.cpp) +endif() + +if(NOT FRAMELESSHELPER_NO_TITLEBAR) + list(APPEND PUBLIC_HEADERS ${INCLUDE_PREFIX}/standardtitlebar.h) + list(APPEND PUBLIC_HEADERS_ALIAS ${INCLUDE_PREFIX}/StandardTitleBar) + list(APPEND PRIVATE_HEADERS ${INCLUDE_PREFIX}/private/standardtitlebar_p.h) + list(APPEND SOURCES standardtitlebar.cpp) +endif() + +if(NOT FRAMELESSHELPER_NO_WINDOW) + list(APPEND PUBLIC_HEADERS + ${INCLUDE_PREFIX}/framelessdialog.h + ${INCLUDE_PREFIX}/framelesswidget.h + ${INCLUDE_PREFIX}/framelessmainwindow.h + ) + list(APPEND PUBLIC_HEADERS_ALIAS + ${INCLUDE_PREFIX}/FramelessDialog + ${INCLUDE_PREFIX}/FramelessWidget + ${INCLUDE_PREFIX}/FramelessMainWindow + ) + list(APPEND PRIVATE_HEADERS + ${INCLUDE_PREFIX}/private/framelessdialog_p.h + ${INCLUDE_PREFIX}/private/framelesswidget_p.h + ${INCLUDE_PREFIX}/private/framelessmainwindow_p.h + ) + list(APPEND SOURCES + framelessdialog.cpp + framelesswidget.cpp + framelessmainwindow.cpp + ) +endif() + if(WIN32 AND NOT FRAMELESSHELPER_BUILD_STATIC) set(__rc_path "${CMAKE_CURRENT_BINARY_DIR}/${SUB_MODULE_FULL_NAME}.rc") if(NOT EXISTS "${__rc_path}") @@ -106,33 +123,9 @@ add_library(${PROJECT_NAME}::${SUB_MODULE_FULL_NAME} ALIAS ${SUB_MODULE_TARGET}) set_target_properties(${SUB_MODULE_TARGET} PROPERTIES VERSION "${PROJECT_VERSION}" SOVERSION "${PROJECT_VERSION_MAJOR}" + OUTPUT_NAME "${SUB_MODULE_TARGET}${FRAMELESSHELPER_64BIT_POSTFIX}" ) -if(FRAMELESSHELPER_BUILD_STATIC) - target_compile_definitions(${SUB_MODULE_TARGET} PUBLIC FRAMELESSHELPER_WIDGETS_STATIC) -endif() - -if(FRAMELESSHELPER_NO_DEBUG_OUTPUT) - target_compile_definitions(${SUB_MODULE_TARGET} PRIVATE - FRAMELESSHELPER_WIDGETS_NO_DEBUG_OUTPUT - ) -endif() - -if(FRAMELESSHELPER_NO_BUNDLE_RESOURCE) - target_compile_definitions(${SUB_MODULE_TARGET} PUBLIC FRAMELESSHELPER_WIDGETS_NO_BUNDLE_RESOURCE) -endif() - -if(FRAMELESSHELPER_NO_PRIVATE) - target_compile_definitions(${SUB_MODULE_TARGET} PUBLIC FRAMELESSHELPER_WIDGETS_NO_PRIVATE) -endif() - -if(DEFINED FRAMELESSHELPER_NAMESPACE) - if("x${FRAMELESSHELPER_NAMESPACE}" STREQUAL "x") - message(FATAL_ERROR "FRAMELESSHELPER_NAMESPACE can't be empty!") - endif() - target_compile_definitions(${SUB_MODULE_TARGET} PUBLIC FRAMELESSHELPER_NAMESPACE=${FRAMELESSHELPER_NAMESPACE}) -endif() - target_compile_definitions(${SUB_MODULE_TARGET} PRIVATE FRAMELESSHELPER_WIDGETS_LIBRARY ) @@ -141,7 +134,7 @@ target_link_libraries(${SUB_MODULE_TARGET} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets ) -target_link_libraries(${SUB_MODULE_TARGET} PUBLIC +target_link_libraries(${SUB_MODULE_TARGET} PRIVATE ${PROJECT_NAME}::Core ) diff --git a/src/widgets/framelessdialog.cpp b/src/widgets/framelessdialog.cpp index a6a634d9..c36d591e 100644 --- a/src/widgets/framelessdialog.cpp +++ b/src/widgets/framelessdialog.cpp @@ -24,24 +24,26 @@ #include "framelessdialog.h" #include "framelessdialog_p.h" + +#if FRAMELESSHELPER_CONFIG(window) + #include "framelesswidgetshelper.h" #include "widgetssharedhelper_p.h" #include FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcFramelessDialog, "wangwenx190.framelesshelper.widgets.framelessdialog") - -#ifdef FRAMELESSHELPER_WIDGETS_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcFramelessDialog) # define DEBUG qCDebug(lcFramelessDialog) # define WARNING qCWarning(lcFramelessDialog) # define CRITICAL qCCritical(lcFramelessDialog) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; @@ -87,3 +89,5 @@ FramelessDialog::FramelessDialog(QWidget *parent) FramelessDialog::~FramelessDialog() = default; FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/src/widgets/framelesshelperwidgets_global.cpp b/src/widgets/framelesshelperwidgets_global.cpp index d209c84c..5224013b 100644 --- a/src/widgets/framelesshelperwidgets_global.cpp +++ b/src/widgets/framelesshelperwidgets_global.cpp @@ -27,24 +27,20 @@ FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcWidgetsGlobal, "wangwenx190.framelesshelper.widgets.global") - -#ifdef FRAMELESSHELPER_WIDGETS_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcWidgetsGlobal) # define DEBUG qCDebug(lcWidgetsGlobal) # define WARNING qCWarning(lcWidgetsGlobal) # define CRITICAL qCCritical(lcWidgetsGlobal) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif -namespace FramelessHelper::Widgets -{ - -void initialize() +void FramelessHelperWidgetsInitialize() { static bool inited = false; if (inited) { @@ -52,10 +48,10 @@ void initialize() } inited = true; - FramelessHelper::Core::initialize(); + FramelessHelperCoreInitialize(); } -void uninitialize() +void FramelessHelperWidgetsUninitialize() { static bool uninited = false; if (uninited) { @@ -65,9 +61,7 @@ void uninitialize() // ### TODO: The Widgets module-specific uninitialization. - FramelessHelper::Core::uninitialize(); -} - + FramelessHelperCoreUninitialize(); } FRAMELESSHELPER_END_NAMESPACE diff --git a/src/widgets/framelessmainwindow.cpp b/src/widgets/framelessmainwindow.cpp index 5131a764..de415f73 100644 --- a/src/widgets/framelessmainwindow.cpp +++ b/src/widgets/framelessmainwindow.cpp @@ -24,6 +24,9 @@ #include "framelessmainwindow.h" #include "framelessmainwindow_p.h" + +#if FRAMELESSHELPER_CONFIG(window) + #include "framelesswidgetshelper.h" #include "widgetssharedhelper_p.h" #include @@ -31,18 +34,17 @@ FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcFramelessMainWindow, "wangwenx190.framelesshelper.widgets.framelessmainwindow") - -#ifdef FRAMELESSHELPER_WIDGETS_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcFramelessMainWindow) # define DEBUG qCDebug(lcFramelessMainWindow) # define WARNING qCWarning(lcFramelessMainWindow) # define CRITICAL qCCritical(lcFramelessMainWindow) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; @@ -118,3 +120,5 @@ void FramelessMainWindow::toggleFullScreen() } FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/src/widgets/framelesswidget.cpp b/src/widgets/framelesswidget.cpp index 72e40a26..296d1b95 100644 --- a/src/widgets/framelesswidget.cpp +++ b/src/widgets/framelesswidget.cpp @@ -24,6 +24,9 @@ #include "framelesswidget.h" #include "framelesswidget_p.h" + +#if FRAMELESSHELPER_CONFIG(window) + #include "framelesswidgetshelper.h" #include "widgetssharedhelper_p.h" #include @@ -31,18 +34,17 @@ FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcFramelessWidget, "wangwenx190.framelesshelper.widgets.framelesswidget") - -#ifdef FRAMELESSHELPER_WIDGETS_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcFramelessWidget) # define DEBUG qCDebug(lcFramelessWidget) # define WARNING qCWarning(lcFramelessWidget) # define CRITICAL qCCritical(lcFramelessWidget) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; @@ -118,3 +120,5 @@ void FramelessWidget::toggleFullScreen() } FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/src/widgets/framelesswidgetshelper.cpp b/src/widgets/framelesswidgetshelper.cpp index 4b07a0f6..9208e951 100644 --- a/src/widgets/framelesswidgetshelper.cpp +++ b/src/widgets/framelesswidgetshelper.cpp @@ -24,12 +24,14 @@ #include "framelesswidgetshelper.h" #include "framelesswidgetshelper_p.h" -#include "framelesswidget.h" -#include "framelesswidget_p.h" -#include "framelessmainwindow.h" -#include "framelessmainwindow_p.h" -#include "framelessdialog.h" -#include "framelessdialog_p.h" +#if FRAMELESSHELPER_CONFIG(window) +# include "framelesswidget.h" +# include "framelesswidget_p.h" +# include "framelessmainwindow.h" +# include "framelessmainwindow_p.h" +# include "framelessdialog.h" +# include "framelessdialog_p.h" +#endif #include "widgetssharedhelper_p.h" #include #include @@ -54,18 +56,17 @@ extern Q_WIDGETS_EXPORT QWidget *qt_button_down; FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcFramelessWidgetsHelper, "wangwenx190.framelesshelper.widgets.framelesswidgetshelper") - -#ifdef FRAMELESSHELPER_WIDGETS_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcFramelessWidgetsHelper) # define DEBUG qCDebug(lcFramelessWidgetsHelper) # define WARNING qCWarning(lcFramelessWidgetsHelper) # define CRITICAL qCCritical(lcFramelessWidgetsHelper) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; @@ -241,6 +242,7 @@ QVariant FramelessWidgetsHelperPrivate::getProperty(const char *name, const QVar return ((value.isValid() && !value.isNull()) ? value : defaultValue); } +#if FRAMELESSHELPER_CONFIG(mica_material) MicaMaterial *FramelessWidgetsHelperPrivate::getMicaMaterialIfAny() const { if (!window) { @@ -251,7 +253,9 @@ MicaMaterial *FramelessWidgetsHelperPrivate::getMicaMaterialIfAny() const } return nullptr; } +#endif +#if FRAMELESSHELPER_CONFIG(border_painter) WindowBorderPainter *FramelessWidgetsHelperPrivate::getWindowBorderIfAny() const { if (!window) { @@ -262,6 +266,7 @@ WindowBorderPainter *FramelessWidgetsHelperPrivate::getWindowBorderIfAny() const } return nullptr; } +#endif WidgetsSharedHelper *FramelessWidgetsHelperPrivate::findOrCreateSharedHelper(QWidget *window) { @@ -269,6 +274,7 @@ WidgetsSharedHelper *FramelessWidgetsHelperPrivate::findOrCreateSharedHelper(QWi if (!window) { return nullptr; } +#if FRAMELESSHELPER_CONFIG(window) if (const auto widget = qobject_cast(window)) { if (const auto widgetPriv = FramelessWidgetPrivate::get(widget)) { return widgetPriv->sharedHelper; @@ -284,6 +290,7 @@ WidgetsSharedHelper *FramelessWidgetsHelperPrivate::findOrCreateSharedHelper(QWi return dialogPriv->sharedHelper; } } +#endif QWidget * const topLevelWindow = window->window(); WidgetsSharedHelper *helper = topLevelWindow->findChild(); if (!helper) { @@ -413,13 +420,16 @@ void FramelessWidgetsHelperPrivate::attach() params.forceChildrenRepaint = [this](const int delay) -> void { repaintAllChildren(delay); }; params.resetQtGrabbedControl = []() -> bool { if (qt_button_down) { - QMouseEvent e(QEvent::MouseButtonRelease, - {-999, -999}, - Qt::LeftButton, - Qt::NoButton, - QApplication::keyboardModifiers() - ); - QApplication::sendEvent(qt_button_down, &e); + static constexpr const auto invalidPos = QPoint{ -99999, -99999 }; + const auto event = std::make_unique( + QEvent::MouseButtonRelease, + invalidPos, + invalidPos, + invalidPos, + Qt::LeftButton, + QGuiApplication::mouseButtons() ^ Qt::LeftButton, + QGuiApplication::keyboardModifiers()); + QApplication::sendEvent(qt_button_down, event.get()); qt_button_down = nullptr; return true; } @@ -683,7 +693,7 @@ void FramelessWidgetsHelper::showSystemMenu(const QPoint &pos) const QPoint nativePos = Utils::toNativeGlobalPosition(d->window->windowHandle(), pos); #ifdef Q_OS_WINDOWS std::ignore = Utils::showSystemMenu(windowId, nativePos, false, &d->getWindowData()->params); -#elif defined(Q_OS_LINUX) +#elif (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)) Utils::openSystemMenu(windowId, nativePos); #else Q_UNUSED(windowId); @@ -768,17 +778,21 @@ QWidget *FramelessWidgetsHelper::window() const return d->window; } +#if FRAMELESSHELPER_CONFIG(mica_material) MicaMaterial *FramelessWidgetsHelper::micaMaterial() const { Q_D(const FramelessWidgetsHelper); return d->getMicaMaterialIfAny(); } +#endif +#if FRAMELESSHELPER_CONFIG(border_painter) WindowBorderPainter *FramelessWidgetsHelper::windowBorder() const { Q_D(const FramelessWidgetsHelper); return d->getWindowBorderIfAny(); } +#endif bool FramelessWidgetsHelper::isWindowFixedSize() const { @@ -844,7 +858,9 @@ void FramelessWidgetsHelper::setBlurBehindWindowEnabled(const bool enable) } else { if (WidgetsSharedHelper * const helper = d->findOrCreateSharedHelper(d->window)) { d->blurBehindWindowEnabled = enable; +#if FRAMELESSHELPER_CONFIG(mica_material) helper->setMicaEnabled(d->blurBehindWindowEnabled); +#endif d->emitSignalForAllInstances("blurBehindWindowEnabledChanged"); } else { DEBUG << "Blur behind window is not supported on current platform."; diff --git a/src/widgets/standardsystembutton.cpp b/src/widgets/standardsystembutton.cpp index a7d4991f..d6538697 100644 --- a/src/widgets/standardsystembutton.cpp +++ b/src/widgets/standardsystembutton.cpp @@ -24,6 +24,9 @@ #include "standardsystembutton.h" #include "standardsystembutton_p.h" + +#if FRAMELESSHELPER_CONFIG(system_button) + #include #include #include @@ -33,18 +36,17 @@ FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcStandardSystemButton, "wangwenx190.framelesshelper.widgets.standardsystembutton") - -#ifdef FRAMELESSHELPER_WIDGETS_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcStandardSystemButton) # define DEBUG qCDebug(lcStandardSystemButton) # define WARNING qCWarning(lcStandardSystemButton) # define CRITICAL qCCritical(lcStandardSystemButton) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; @@ -344,3 +346,5 @@ void StandardSystemButton::paintEvent(QPaintEvent *event) } FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/src/widgets/standardtitlebar.cpp b/src/widgets/standardtitlebar.cpp index 7df5b5f9..00c56633 100644 --- a/src/widgets/standardtitlebar.cpp +++ b/src/widgets/standardtitlebar.cpp @@ -24,7 +24,12 @@ #include "standardtitlebar.h" #include "standardtitlebar_p.h" -#include "standardsystembutton.h" + +#if FRAMELESSHELPER_CONFIG(titlebar) + +#if FRAMELESSHELPER_CONFIG(system_button) +# include "standardsystembutton.h" +#endif #include "framelesswidgetshelper.h" #include #include @@ -37,18 +42,17 @@ FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcStandardTitleBar, "wangwenx190.framelesshelper.widgets.standardtitlebar") - -#ifdef FRAMELESSHELPER_WIDGETS_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcStandardTitleBar) # define DEBUG qCDebug(lcStandardTitleBar) # define WARNING qCWarning(lcStandardTitleBar) # define CRITICAL qCCritical(lcStandardTitleBar) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; @@ -231,11 +235,11 @@ bool StandardTitleBarPrivate::isInTitleBarIconArea(const QPoint &pos) const void StandardTitleBarPrivate::updateMaximizeButton() { -#ifndef Q_OS_MACOS +#if (!defined(Q_OS_MACOS) && FRAMELESSHELPER_CONFIG(system_button)) const bool max = window->isMaximized(); maximizeButton->setButtonType(max ? SystemButtonType::Restore : SystemButtonType::Maximize); maximizeButton->setToolTip(max ? tr("Restore") : tr("Maximize")); -#endif // Q_OS_MACOS +#endif } void StandardTitleBarPrivate::updateTitleBarColor() @@ -246,7 +250,7 @@ void StandardTitleBarPrivate::updateTitleBarColor() void StandardTitleBarPrivate::updateChromeButtonColor() { -#ifndef Q_OS_MACOS +#if (!defined(Q_OS_MACOS) && FRAMELESSHELPER_CONFIG(system_button)) const bool active = window->isActiveWindow(); const QColor activeForeground = chromePalette->titleBarActiveForegroundColor(); const QColor inactiveForeground = chromePalette->titleBarInactiveForegroundColor(); @@ -271,16 +275,16 @@ void StandardTitleBarPrivate::updateChromeButtonColor() closeButton->setHoverColor(chromePalette->closeButtonHoverColor()); closeButton->setPressColor(chromePalette->closeButtonPressColor()); closeButton->setActive(active); -#endif // Q_OS_MACOS +#endif } void StandardTitleBarPrivate::retranslateUi() { -#ifndef Q_OS_MACOS +#if (!defined(Q_OS_MACOS) && FRAMELESSHELPER_CONFIG(system_button)) minimizeButton->setToolTip(tr("Minimize")); maximizeButton->setToolTip(window->isMaximized() ? tr("Restore") : tr("Maximize")); closeButton->setToolTip(tr("Close")); -#endif // Q_OS_MACOS +#endif } bool StandardTitleBarPrivate::eventFilter(QObject *object, QEvent *event) @@ -335,7 +339,7 @@ void StandardTitleBarPrivate::initialize() const auto titleBarLayout = new QHBoxLayout(q); titleBarLayout->setSpacing(0); titleBarLayout->setContentsMargins(0, 0, 0, 0); -#else // !Q_OS_MACOS +#elif FRAMELESSHELPER_CONFIG(system_button) minimizeButton = new StandardSystemButton(SystemButtonType::Minimize, q); connect(minimizeButton, &StandardSystemButton::clicked, window, &QWidget::showMinimized); maximizeButton = new StandardSystemButton(SystemButtonType::Maximize, q); @@ -374,7 +378,7 @@ void StandardTitleBarPrivate::initialize() titleBarLayout->setContentsMargins(0, 0, 0, 0); titleBarLayout->addStretch(); titleBarLayout->addLayout(systemButtonsOuterLayout); -#endif // Q_OS_MACOS +#endif retranslateUi(); updateTitleBarColor(); updateChromeButtonColor(); @@ -395,7 +399,7 @@ StandardTitleBar::StandardTitleBar(QWidget *parent) StandardTitleBar::~StandardTitleBar() = default; -#ifndef Q_OS_MACOS +#if (!defined(Q_OS_MACOS) && FRAMELESSHELPER_CONFIG(system_button)) StandardSystemButton *StandardTitleBar::minimizeButton() const { Q_D(const StandardTitleBar); @@ -413,7 +417,7 @@ StandardSystemButton *StandardTitleBar::closeButton() const Q_D(const StandardTitleBar); return d->closeButton; } -#endif // Q_OS_MACOS +#endif void StandardTitleBar::mouseReleaseEvent(QMouseEvent *event) { @@ -627,3 +631,5 @@ void StandardTitleBar::setTitleFont(const QFont &value) } FRAMELESSHELPER_END_NAMESPACE + +#endif diff --git a/src/widgets/widgetssharedhelper.cpp b/src/widgets/widgetssharedhelper.cpp index a5c48288..ff0f45c2 100644 --- a/src/widgets/widgetssharedhelper.cpp +++ b/src/widgets/widgetssharedhelper.cpp @@ -23,11 +23,15 @@ */ #include "widgetssharedhelper_p.h" -#include +#if FRAMELESSHELPER_CONFIG(mica_material) +# include +# include +#endif +#if FRAMELESSHELPER_CONFIG(border_painter) +# include +#endif #include -#include #include -#include #ifdef Q_OS_WINDOWS # include #endif // Q_OS_WINDOWS @@ -39,18 +43,17 @@ FRAMELESSHELPER_BEGIN_NAMESPACE +#if FRAMELESSHELPER_CONFIG(debug_output) [[maybe_unused]] static Q_LOGGING_CATEGORY(lcWidgetsSharedHelper, "wangwenx190.framelesshelper.widgets.widgetssharedhelper") - -#ifdef FRAMELESSHELPER_WIDGETS_NO_DEBUG_OUTPUT -# define INFO QT_NO_QDEBUG_MACRO() -# define DEBUG QT_NO_QDEBUG_MACRO() -# define WARNING QT_NO_QDEBUG_MACRO() -# define CRITICAL QT_NO_QDEBUG_MACRO() -#else # define INFO qCInfo(lcWidgetsSharedHelper) # define DEBUG qCDebug(lcWidgetsSharedHelper) # define WARNING qCWarning(lcWidgetsSharedHelper) # define CRITICAL qCCritical(lcWidgetsSharedHelper) +#else +# define INFO QT_NO_QDEBUG_MACRO() +# define DEBUG QT_NO_QDEBUG_MACRO() +# define WARNING QT_NO_QDEBUG_MACRO() +# define CRITICAL QT_NO_QDEBUG_MACRO() #endif using namespace Global; @@ -71,6 +74,7 @@ void WidgetsSharedHelper::setup(QWidget *widget) return; } m_targetWidget = widget; +#if FRAMELESSHELPER_CONFIG(border_painter) m_borderPainter = new WindowBorderPainter(this); if (m_borderRepaintConnection) { disconnect(m_borderRepaintConnection); @@ -82,6 +86,8 @@ void WidgetsSharedHelper::setup(QWidget *widget) m_targetWidget->update(); } }); +#endif +#if FRAMELESSHELPER_CONFIG(mica_material) m_micaMaterial = new MicaMaterial(this); if (m_micaRedrawConnection) { disconnect(m_micaRedrawConnection); @@ -93,6 +99,7 @@ void WidgetsSharedHelper::setup(QWidget *widget) m_targetWidget->update(); } }); +#endif m_targetWidget->installEventFilter(this); updateContentsMargins(); m_targetWidget->update(); @@ -110,6 +117,7 @@ void WidgetsSharedHelper::setup(QWidget *widget) &QWindow::screenChanged, this, &WidgetsSharedHelper::handleScreenChanged); } +#if FRAMELESSHELPER_CONFIG(mica_material) bool WidgetsSharedHelper::isMicaEnabled() const { return m_micaEnabled; @@ -131,11 +139,14 @@ MicaMaterial *WidgetsSharedHelper::rawMicaMaterial() const { return m_micaMaterial; } +#endif +#if FRAMELESSHELPER_CONFIG(border_painter) WindowBorderPainter *WidgetsSharedHelper::rawWindowBorder() const { return m_borderPainter; } +#endif bool WidgetsSharedHelper::eventFilter(QObject *object, QEvent *event) { @@ -162,8 +173,12 @@ bool WidgetsSharedHelper::eventFilter(QObject *object, QEvent *event) m_targetWidget->update(); break; case QEvent::Paint: { +#if FRAMELESSHELPER_CONFIG(mica_material) repaintMica(); +#endif +#if FRAMELESSHELPER_CONFIG(border_painter) repaintBorder(); +#endif } break; case QEvent::WindowStateChange: if (event->type() == QEvent::WindowStateChange) { @@ -173,7 +188,11 @@ bool WidgetsSharedHelper::eventFilter(QObject *object, QEvent *event) break; case QEvent::Move: case QEvent::Resize: - m_targetWidget->update(); +#if FRAMELESSHELPER_CONFIG(mica_material) + if (m_micaEnabled) { + m_targetWidget->update(); + } +#endif break; default: break; @@ -181,24 +200,28 @@ bool WidgetsSharedHelper::eventFilter(QObject *object, QEvent *event) return QObject::eventFilter(object, event); } +#if FRAMELESSHELPER_CONFIG(mica_material) void WidgetsSharedHelper::repaintMica() { - if (!m_micaEnabled || !m_micaMaterial) { + if (!m_micaEnabled) { return; } QPainter painter(m_targetWidget); const QRect rect = { m_targetWidget->mapToGlobal(QPoint(0, 0)), m_targetWidget->size() }; m_micaMaterial->paint(&painter, rect, m_targetWidget->isActiveWindow()); } +#endif +#if FRAMELESSHELPER_CONFIG(border_painter) void WidgetsSharedHelper::repaintBorder() { - if ((Utils::windowStatesToWindowState(m_targetWidget->windowState()) != Qt::WindowNoState) || !m_borderPainter) { + if (Utils::windowStatesToWindowState(m_targetWidget->windowState()) != Qt::WindowNoState) { return; } QPainter painter(m_targetWidget); m_borderPainter->paint(&painter, m_targetWidget->size(), m_targetWidget->isActiveWindow()); } +#endif void WidgetsSharedHelper::emitCustomWindowStateSignals() { @@ -244,9 +267,11 @@ void WidgetsSharedHelper::handleScreenChanged(QScreen *screen) return; } m_screenDpr = currentDpr; - if (m_micaEnabled && m_micaMaterial) { +#if FRAMELESSHELPER_CONFIG(mica_material) + if (m_micaEnabled) { MicaMaterialPrivate::get(m_micaMaterial)->maybeGenerateBlurredWallpaper(true); } +#endif }); }