From 2806cc811b687f8cd50e7aad3898ca6b5f69a815 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Thu, 7 Jul 2022 13:43:09 +0800 Subject: [PATCH] code simplification, minor re-structure Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- examples/mainwindow/main.cpp | 2 +- examples/openglwidget/main.cpp | 2 +- examples/quick-blur/main.cpp | 2 +- examples/quick/main.cpp | 2 +- examples/widget-blur/main.cpp | 2 +- examples/widget/main.cpp | 2 +- include/FramelessHelper/Core/chromepalette.h | 2 + .../FramelessHelper/Core/framelesshelper_qt.h | 2 + .../Core/framelesshelper_win.h | 2 + .../Core/framelesshelper_windows.h | 12 +- .../FramelessHelper/Core/framelessmanager.h | 2 + .../Core/private/chromepalette_p.h | 43 ++--- .../Core/private/framelessconfig_p.h | 2 + .../Core/private/framelessmanager_p.h | 2 + .../Core/private/sysapiloader_p.h | 2 + .../Quick/framelesshelperquick_global.h | 8 + .../Quick/framelessquickhelper.h | 1 + .../Quick/framelessquickutils.h | 1 + .../Quick/private/framelessquickhelper_p.h | 2 + .../Quick/private/framelessquickwindow_p.h | 1 + .../Quick/private/framelessquickwindow_p_p.h | 2 + .../private/quickstandardsystembutton_p.h | 1 + .../Quick/private/quickstandardtitlebar_p.h | 1 + .../Quick/quickchromepalette.h | 1 + .../Widgets/framelesshelperwidgets_global.h | 10 + .../Widgets/framelessmainwindow.h | 2 + .../FramelessHelper/Widgets/framelesswidget.h | 2 + .../Widgets/framelesswidgetshelper.h | 2 + .../Widgets/private/framelessmainwindow_p.h | 2 + .../Widgets/private/framelesswidget_p.h | 2 + .../private/framelesswidgetshelper_p.h | 2 + .../Widgets/private/standardsystembutton_p.h | 2 + .../Widgets/private/standardtitlebar_p.h | 6 + .../Widgets/private/widgetssharedhelper_p.h | 2 + .../Widgets/standardsystembutton.h | 2 + .../Widgets/standardtitlebar.h | 7 + src/core/CMakeLists.txt | 5 +- src/core/chromepalette.cpp | 110 +++++------ src/core/framelessmanager.cpp | 118 ------------ src/core/global.cpp | 174 ++++++++++++++++++ src/core/utils_win.cpp | 13 +- src/quick/CMakeLists.txt | 1 + src/quick/framelessquickhelper.cpp | 2 +- src/quick/framelessquickmodule.cpp | 22 +++ src/quick/global.cpp | 54 ++++++ src/widgets/CMakeLists.txt | 1 + src/widgets/framelesswidgetshelper.cpp | 2 +- src/widgets/global.cpp | 63 +++++++ src/widgets/standardtitlebar.cpp | 82 ++++++--- 49 files changed, 532 insertions(+), 255 deletions(-) create mode 100644 src/core/global.cpp create mode 100644 src/quick/global.cpp create mode 100644 src/widgets/global.cpp diff --git a/examples/mainwindow/main.cpp b/examples/mainwindow/main.cpp index c9d397a..136ae47 100644 --- a/examples/mainwindow/main.cpp +++ b/examples/mainwindow/main.cpp @@ -32,7 +32,7 @@ int main(int argc, char *argv[]) { // Not necessary, but better call this function, before the construction // of any Q(Core|Gui)Application instances. - FramelessHelper::Core::initialize(); + FramelessHelper::Widgets::initialize(); QApplication application(argc, argv); diff --git a/examples/openglwidget/main.cpp b/examples/openglwidget/main.cpp index dffaa2a..007291a 100644 --- a/examples/openglwidget/main.cpp +++ b/examples/openglwidget/main.cpp @@ -69,7 +69,7 @@ int main(int argc, char *argv[]) { // Not necessary, but better call this function, before the construction // of any Q(Core|Gui)Application instances. - FramelessHelper::Core::initialize(); + FramelessHelper::Widgets::initialize(); QApplication application(argc, argv); diff --git a/examples/quick-blur/main.cpp b/examples/quick-blur/main.cpp index 59eb380..0d46e98 100644 --- a/examples/quick-blur/main.cpp +++ b/examples/quick-blur/main.cpp @@ -44,7 +44,7 @@ int main(int argc, char *argv[]) { // Not necessary, but better call this function, before the construction // of any Q(Core|Gui)Application instances. - FramelessHelper::Core::initialize(); + FramelessHelper::Quick::initialize(); QGuiApplication application(argc, argv); diff --git a/examples/quick/main.cpp b/examples/quick/main.cpp index 59eb380..0d46e98 100644 --- a/examples/quick/main.cpp +++ b/examples/quick/main.cpp @@ -44,7 +44,7 @@ int main(int argc, char *argv[]) { // Not necessary, but better call this function, before the construction // of any Q(Core|Gui)Application instances. - FramelessHelper::Core::initialize(); + FramelessHelper::Quick::initialize(); QGuiApplication application(argc, argv); diff --git a/examples/widget-blur/main.cpp b/examples/widget-blur/main.cpp index 80990a7..5079187 100644 --- a/examples/widget-blur/main.cpp +++ b/examples/widget-blur/main.cpp @@ -32,7 +32,7 @@ int main(int argc, char *argv[]) { // Not necessary, but better call this function, before the construction // of any Q(Core|Gui)Application instances. - FramelessHelper::Core::initialize(); + FramelessHelper::Widgets::initialize(); QApplication application(argc, argv); diff --git a/examples/widget/main.cpp b/examples/widget/main.cpp index 80990a7..5079187 100644 --- a/examples/widget/main.cpp +++ b/examples/widget/main.cpp @@ -32,7 +32,7 @@ int main(int argc, char *argv[]) { // Not necessary, but better call this function, before the construction // of any Q(Core|Gui)Application instances. - FramelessHelper::Core::initialize(); + FramelessHelper::Widgets::initialize(); QApplication application(argc, argv); diff --git a/include/FramelessHelper/Core/chromepalette.h b/include/FramelessHelper/Core/chromepalette.h index e88ba6f..ed5b127 100644 --- a/include/FramelessHelper/Core/chromepalette.h +++ b/include/FramelessHelper/Core/chromepalette.h @@ -124,3 +124,5 @@ private: }; FRAMELESSHELPER_END_NAMESPACE + +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(ChromePalette)) diff --git a/include/FramelessHelper/Core/framelesshelper_qt.h b/include/FramelessHelper/Core/framelesshelper_qt.h index e892bf5..0f984bc 100644 --- a/include/FramelessHelper/Core/framelesshelper_qt.h +++ b/include/FramelessHelper/Core/framelesshelper_qt.h @@ -45,3 +45,5 @@ protected: }; FRAMELESSHELPER_END_NAMESPACE + +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessHelperQt)) diff --git a/include/FramelessHelper/Core/framelesshelper_win.h b/include/FramelessHelper/Core/framelesshelper_win.h index 75afe71..6d90b20 100644 --- a/include/FramelessHelper/Core/framelesshelper_win.h +++ b/include/FramelessHelper/Core/framelesshelper_win.h @@ -43,3 +43,5 @@ public: }; FRAMELESSHELPER_END_NAMESPACE + +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessHelperWin)) diff --git a/include/FramelessHelper/Core/framelesshelper_windows.h b/include/FramelessHelper/Core/framelesshelper_windows.h index 09c1b52..4237c54 100644 --- a/include/FramelessHelper/Core/framelesshelper_windows.h +++ b/include/FramelessHelper/Core/framelesshelper_windows.h @@ -160,8 +160,7 @@ using NTSTATUS = LONG; #ifndef WINMMAPI - -#define WINMMAPI EXTERN_C DECLSPEC_IMPORT +# define WINMMAPI DECLSPEC_IMPORT using MMRESULT = UINT; @@ -173,7 +172,6 @@ using TIMECAPS = struct TIMECAPS using PTIMECAPS = TIMECAPS *; using NPTIMECAPS = TIMECAPS NEAR *; using LPTIMECAPS = TIMECAPS FAR *; - #endif using PROCESS_DPI_AWARENESS = enum PROCESS_DPI_AWARENESS @@ -290,6 +288,8 @@ using LPWINDOWCOMPOSITIONATTRIBDATA = WINDOWCOMPOSITIONATTRIBDATA FAR *; using GetWindowCompositionAttributePtr = BOOL(WINAPI *)(HWND, PWINDOWCOMPOSITIONATTRIBDATA); using SetWindowCompositionAttributePtr = BOOL(WINAPI *)(HWND, PWINDOWCOMPOSITIONATTRIBDATA); +EXTERN_C_START + WINMMAPI MMRESULT WINAPI timeGetDevCaps( _Out_writes_bytes_(cbtc) LPTIMECAPS ptc, @@ -306,12 +306,12 @@ timeEndPeriod( _In_ UINT uPeriod ); -EXTERN_C HRESULT WINAPI +DECLSPEC_IMPORT HRESULT WINAPI SetProcessDpiAwareness( _In_ PROCESS_DPI_AWARENESS value ); -EXTERN_C HRESULT WINAPI +DECLSPEC_IMPORT HRESULT WINAPI GetDpiForMonitor( _In_ HMONITOR hMonitor, _In_ MONITOR_DPI_TYPE dpiType, @@ -350,6 +350,8 @@ SetProcessDPIAware( VOID ); +EXTERN_C_END + [[maybe_unused]] static constexpr const int kAutoHideTaskBarThickness = 2; // The thickness of an auto-hide taskbar in pixels. [[maybe_unused]] static constexpr const wchar_t kDwmRegistryKey[] = LR"(Software\Microsoft\Windows\DWM)"; diff --git a/include/FramelessHelper/Core/framelessmanager.h b/include/FramelessHelper/Core/framelessmanager.h index e63ced4..bd3d540 100644 --- a/include/FramelessHelper/Core/framelessmanager.h +++ b/include/FramelessHelper/Core/framelessmanager.h @@ -59,3 +59,5 @@ private: }; FRAMELESSHELPER_END_NAMESPACE + +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessManager)) diff --git a/include/FramelessHelper/Core/private/chromepalette_p.h b/include/FramelessHelper/Core/private/chromepalette_p.h index 439c0ab..193a99d 100644 --- a/include/FramelessHelper/Core/private/chromepalette_p.h +++ b/include/FramelessHelper/Core/private/chromepalette_p.h @@ -27,6 +27,7 @@ #include "framelesshelpercore_global.h" #include #include +#include FRAMELESSHELPER_BEGIN_NAMESPACE @@ -39,23 +40,6 @@ class FRAMELESSHELPER_CORE_API ChromePalettePrivate : public QObject Q_DISABLE_COPY_MOVE(ChromePalettePrivate) public: - enum class MaskFlag - { - TitleBarActiveBackgroundColor = 0x00000001, - TitleBarInactiveBackgroundColor = 0x00000002, - TitleBarActiveForegroundColor = 0x00000004, - TitleBarInactiveForegroundColor = 0x00000008, - ChromeButtonNormalColor = 0x00000010, - ChromeButtonHoverColor = 0x00000020, - ChromeButtonPressColor = 0x00000040, - CloseButtonNormalColor = 0x00000080, - CloseButtonHoverColor = 0x00000100, - CloseButtonPressColor = 0x00000200 - }; - Q_ENUM(MaskFlag) - Q_DECLARE_FLAGS(Mask, MaskFlag) - Q_FLAG(Mask) - explicit ChromePalettePrivate(ChromePalette *q); ~ChromePalettePrivate() override; @@ -67,7 +51,6 @@ public Q_SLOTS: private: QPointer q_ptr = nullptr; - Mask mask = {}; // System-defined ones: QColor titleBarActiveBackgroundColor_sys = {}; QColor titleBarInactiveBackgroundColor_sys = {}; @@ -80,18 +63,18 @@ private: QColor closeButtonHoverColor_sys = {}; QColor closeButtonPressColor_sys = {}; // User-defined ones: - QColor titleBarActiveBackgroundColor = {}; - QColor titleBarInactiveBackgroundColor = {}; - QColor titleBarActiveForegroundColor = {}; - QColor titleBarInactiveForegroundColor = {}; - QColor chromeButtonNormalColor = {}; - QColor chromeButtonHoverColor = {}; - QColor chromeButtonPressColor = {}; - QColor closeButtonNormalColor = {}; - QColor closeButtonHoverColor = {}; - QColor closeButtonPressColor = {}; + std::optional titleBarActiveBackgroundColor = std::nullopt; + std::optional titleBarInactiveBackgroundColor = std::nullopt; + std::optional titleBarActiveForegroundColor = std::nullopt; + std::optional titleBarInactiveForegroundColor = std::nullopt; + std::optional chromeButtonNormalColor = std::nullopt; + std::optional chromeButtonHoverColor = std::nullopt; + std::optional chromeButtonPressColor = std::nullopt; + std::optional closeButtonNormalColor = std::nullopt; + std::optional closeButtonHoverColor = std::nullopt; + std::optional closeButtonPressColor = std::nullopt; }; -Q_DECLARE_OPERATORS_FOR_FLAGS(ChromePalettePrivate::Mask) - FRAMELESSHELPER_END_NAMESPACE + +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(ChromePalettePrivate)) diff --git a/include/FramelessHelper/Core/private/framelessconfig_p.h b/include/FramelessHelper/Core/private/framelessconfig_p.h index ff44783..bfda0c9 100644 --- a/include/FramelessHelper/Core/private/framelessconfig_p.h +++ b/include/FramelessHelper/Core/private/framelessconfig_p.h @@ -50,3 +50,5 @@ public: }; FRAMELESSHELPER_END_NAMESPACE + +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessConfig)) diff --git a/include/FramelessHelper/Core/private/framelessmanager_p.h b/include/FramelessHelper/Core/private/framelessmanager_p.h index d4c0dda..41dc5cc 100644 --- a/include/FramelessHelper/Core/private/framelessmanager_p.h +++ b/include/FramelessHelper/Core/private/framelessmanager_p.h @@ -66,3 +66,5 @@ private: }; FRAMELESSHELPER_END_NAMESPACE + +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessManagerPrivate)) diff --git a/include/FramelessHelper/Core/private/sysapiloader_p.h b/include/FramelessHelper/Core/private/sysapiloader_p.h index ee096b9..b0470a8 100644 --- a/include/FramelessHelper/Core/private/sysapiloader_p.h +++ b/include/FramelessHelper/Core/private/sysapiloader_p.h @@ -63,6 +63,8 @@ private: FRAMELESSHELPER_END_NAMESPACE +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(SysApiLoader)) + #ifdef Q_OS_WINDOWS # define API_WIN_AVAILABLE(lib, func) (SysApiLoader::instance()->isAvailable(k##lib, k##func)) # define API_USER_AVAILABLE(func) API_WIN_AVAILABLE(user32, func) diff --git a/include/FramelessHelper/Quick/framelesshelperquick_global.h b/include/FramelessHelper/Quick/framelesshelperquick_global.h index d1ef98f..e074e07 100644 --- a/include/FramelessHelper/Quick/framelesshelperquick_global.h +++ b/include/FramelessHelper/Quick/framelesshelperquick_global.h @@ -190,4 +190,12 @@ private: #endif }; +namespace FramelessHelper::Quick +{ +FRAMELESSHELPER_QUICK_API void initialize(); +FRAMELESSHELPER_QUICK_API void uninitialize(); +} // namespace FramelessHelper::Quick + FRAMELESSHELPER_END_NAMESPACE + +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickGlobal)) diff --git a/include/FramelessHelper/Quick/framelessquickhelper.h b/include/FramelessHelper/Quick/framelessquickhelper.h index 3491b53..4c17edc 100644 --- a/include/FramelessHelper/Quick/framelessquickhelper.h +++ b/include/FramelessHelper/Quick/framelessquickhelper.h @@ -88,5 +88,6 @@ private: FRAMELESSHELPER_END_NAMESPACE +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickHelper)) QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickHelper)) QML_DECLARE_TYPEINFO(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickHelper), QML_HAS_ATTACHED_PROPERTIES) diff --git a/include/FramelessHelper/Quick/framelessquickutils.h b/include/FramelessHelper/Quick/framelessquickutils.h index b7f96b4..0c1a743 100644 --- a/include/FramelessHelper/Quick/framelessquickutils.h +++ b/include/FramelessHelper/Quick/framelessquickutils.h @@ -86,4 +86,5 @@ Q_SIGNALS: FRAMELESSHELPER_END_NAMESPACE +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickUtils)) QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickUtils)) diff --git a/include/FramelessHelper/Quick/private/framelessquickhelper_p.h b/include/FramelessHelper/Quick/private/framelessquickhelper_p.h index 6fb1ce4..e86a301 100644 --- a/include/FramelessHelper/Quick/private/framelessquickhelper_p.h +++ b/include/FramelessHelper/Quick/private/framelessquickhelper_p.h @@ -87,3 +87,5 @@ private: }; FRAMELESSHELPER_END_NAMESPACE + +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickHelperPrivate)) diff --git a/include/FramelessHelper/Quick/private/framelessquickwindow_p.h b/include/FramelessHelper/Quick/private/framelessquickwindow_p.h index 028b47e..e4b1426 100644 --- a/include/FramelessHelper/Quick/private/framelessquickwindow_p.h +++ b/include/FramelessHelper/Quick/private/framelessquickwindow_p.h @@ -80,5 +80,6 @@ private: FRAMELESSHELPER_END_NAMESPACE +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickWindow)) QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickWindow)) #endif diff --git a/include/FramelessHelper/Quick/private/framelessquickwindow_p_p.h b/include/FramelessHelper/Quick/private/framelessquickwindow_p_p.h index 7b54cb2..a715102 100644 --- a/include/FramelessHelper/Quick/private/framelessquickwindow_p_p.h +++ b/include/FramelessHelper/Quick/private/framelessquickwindow_p_p.h @@ -82,4 +82,6 @@ private: }; FRAMELESSHELPER_END_NAMESPACE + +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickWindowPrivate)) #endif diff --git a/include/FramelessHelper/Quick/private/quickstandardsystembutton_p.h b/include/FramelessHelper/Quick/private/quickstandardsystembutton_p.h index b57e364..07eae62 100644 --- a/include/FramelessHelper/Quick/private/quickstandardsystembutton_p.h +++ b/include/FramelessHelper/Quick/private/quickstandardsystembutton_p.h @@ -95,5 +95,6 @@ private: FRAMELESSHELPER_END_NAMESPACE +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickStandardSystemButton)) QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickStandardSystemButton)) #endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) diff --git a/include/FramelessHelper/Quick/private/quickstandardtitlebar_p.h b/include/FramelessHelper/Quick/private/quickstandardtitlebar_p.h index bc97372..1fd0787 100644 --- a/include/FramelessHelper/Quick/private/quickstandardtitlebar_p.h +++ b/include/FramelessHelper/Quick/private/quickstandardtitlebar_p.h @@ -114,5 +114,6 @@ private: FRAMELESSHELPER_END_NAMESPACE +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickStandardTitleBar)) QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickStandardTitleBar)) #endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) diff --git a/include/FramelessHelper/Quick/quickchromepalette.h b/include/FramelessHelper/Quick/quickchromepalette.h index f34e8b6..903d30d 100644 --- a/include/FramelessHelper/Quick/quickchromepalette.h +++ b/include/FramelessHelper/Quick/quickchromepalette.h @@ -45,4 +45,5 @@ public: FRAMELESSHELPER_END_NAMESPACE +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickChromePalette)) QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickChromePalette)) diff --git a/include/FramelessHelper/Widgets/framelesshelperwidgets_global.h b/include/FramelessHelper/Widgets/framelesshelperwidgets_global.h index 51a4d65..8492d87 100644 --- a/include/FramelessHelper/Widgets/framelesshelperwidgets_global.h +++ b/include/FramelessHelper/Widgets/framelesshelperwidgets_global.h @@ -37,3 +37,13 @@ # endif # endif #endif + +FRAMELESSHELPER_BEGIN_NAMESPACE + +namespace FramelessHelper::Widgets +{ +FRAMELESSHELPER_WIDGETS_API void initialize(); +FRAMELESSHELPER_WIDGETS_API void uninitialize(); +} // namespace FramelessHelper::Widgets + +FRAMELESSHELPER_END_NAMESPACE diff --git a/include/FramelessHelper/Widgets/framelessmainwindow.h b/include/FramelessHelper/Widgets/framelessmainwindow.h index fd922c4..a58ef90 100644 --- a/include/FramelessHelper/Widgets/framelessmainwindow.h +++ b/include/FramelessHelper/Widgets/framelessmainwindow.h @@ -61,3 +61,5 @@ private: }; FRAMELESSHELPER_END_NAMESPACE + +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessMainWindow)) diff --git a/include/FramelessHelper/Widgets/framelesswidget.h b/include/FramelessHelper/Widgets/framelesswidget.h index f43a1f2..c398104 100644 --- a/include/FramelessHelper/Widgets/framelesswidget.h +++ b/include/FramelessHelper/Widgets/framelesswidget.h @@ -61,3 +61,5 @@ private: }; FRAMELESSHELPER_END_NAMESPACE + +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessWidget)) diff --git a/include/FramelessHelper/Widgets/framelesswidgetshelper.h b/include/FramelessHelper/Widgets/framelesswidgetshelper.h index 78ed8fc..f54498a 100644 --- a/include/FramelessHelper/Widgets/framelesswidgetshelper.h +++ b/include/FramelessHelper/Widgets/framelesswidgetshelper.h @@ -77,3 +77,5 @@ private: }; FRAMELESSHELPER_END_NAMESPACE + +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessWidgetsHelper)) diff --git a/include/FramelessHelper/Widgets/private/framelessmainwindow_p.h b/include/FramelessHelper/Widgets/private/framelessmainwindow_p.h index 55b3284..ff54be0 100644 --- a/include/FramelessHelper/Widgets/private/framelessmainwindow_p.h +++ b/include/FramelessHelper/Widgets/private/framelessmainwindow_p.h @@ -61,3 +61,5 @@ private: }; FRAMELESSHELPER_END_NAMESPACE + +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessMainWindowPrivate)) diff --git a/include/FramelessHelper/Widgets/private/framelesswidget_p.h b/include/FramelessHelper/Widgets/private/framelesswidget_p.h index eea7791..9e96c7a 100644 --- a/include/FramelessHelper/Widgets/private/framelesswidget_p.h +++ b/include/FramelessHelper/Widgets/private/framelesswidget_p.h @@ -61,3 +61,5 @@ private: }; FRAMELESSHELPER_END_NAMESPACE + +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessWidgetPrivate)) diff --git a/include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h b/include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h index c7658c7..7d14cce 100644 --- a/include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h +++ b/include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h @@ -84,3 +84,5 @@ private: }; FRAMELESSHELPER_END_NAMESPACE + +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessWidgetsHelperPrivate)) diff --git a/include/FramelessHelper/Widgets/private/standardsystembutton_p.h b/include/FramelessHelper/Widgets/private/standardsystembutton_p.h index cfd5522..b258e31 100644 --- a/include/FramelessHelper/Widgets/private/standardsystembutton_p.h +++ b/include/FramelessHelper/Widgets/private/standardsystembutton_p.h @@ -92,3 +92,5 @@ private: }; FRAMELESSHELPER_END_NAMESPACE + +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(StandardSystemButtonPrivate)) diff --git a/include/FramelessHelper/Widgets/private/standardtitlebar_p.h b/include/FramelessHelper/Widgets/private/standardtitlebar_p.h index f753432..63ec321 100644 --- a/include/FramelessHelper/Widgets/private/standardtitlebar_p.h +++ b/include/FramelessHelper/Widgets/private/standardtitlebar_p.h @@ -64,6 +64,9 @@ public: void paintTitleBar(QPaintEvent *event); + Q_NODISCARD bool titleLabelVisible() const; + void setTitleLabelVisible(const bool value); + public Q_SLOTS: void updateMaximizeButton(); void updateTitleBarColor(); @@ -86,6 +89,9 @@ private: Qt::Alignment m_labelAlignment = {}; bool m_hideWhenClose = false; QScopedPointer m_chromePalette; + bool m_titleLabelVisible = true; }; FRAMELESSHELPER_END_NAMESPACE + +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(StandardTitleBarPrivate)) diff --git a/include/FramelessHelper/Widgets/private/widgetssharedhelper_p.h b/include/FramelessHelper/Widgets/private/widgetssharedhelper_p.h index 7f24955..cf4caef 100644 --- a/include/FramelessHelper/Widgets/private/widgetssharedhelper_p.h +++ b/include/FramelessHelper/Widgets/private/widgetssharedhelper_p.h @@ -61,3 +61,5 @@ private: }; FRAMELESSHELPER_END_NAMESPACE + +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(WidgetsSharedHelper)) diff --git a/include/FramelessHelper/Widgets/standardsystembutton.h b/include/FramelessHelper/Widgets/standardsystembutton.h index c9cc4e1..89c87ae 100644 --- a/include/FramelessHelper/Widgets/standardsystembutton.h +++ b/include/FramelessHelper/Widgets/standardsystembutton.h @@ -90,3 +90,5 @@ private: }; FRAMELESSHELPER_END_NAMESPACE + +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(StandardSystemButton)) diff --git a/include/FramelessHelper/Widgets/standardtitlebar.h b/include/FramelessHelper/Widgets/standardtitlebar.h index 48b4750..62f64a8 100644 --- a/include/FramelessHelper/Widgets/standardtitlebar.h +++ b/include/FramelessHelper/Widgets/standardtitlebar.h @@ -45,6 +45,7 @@ class FRAMELESSHELPER_WIDGETS_API StandardTitleBar : public QWidget 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) + Q_PROPERTY(bool titleLabelVisible READ titleLabelVisible WRITE setTitleLabelVisible NOTIFY titleLabelVisibleChanged FINAL) public: explicit StandardTitleBar(QWidget *parent = nullptr); @@ -65,6 +66,9 @@ public: Q_NODISCARD ChromePalette *chromePalette() const; + Q_NODISCARD bool titleLabelVisible() const; + void setTitleLabelVisible(const bool value); + protected: void paintEvent(QPaintEvent *event) override; @@ -72,9 +76,12 @@ Q_SIGNALS: void extendedChanged(); void titleLabelAlignmentChanged(); void hideWhenCloseChanged(); + void titleLabelVisibleChanged(); private: QScopedPointer d_ptr; }; FRAMELESSHELPER_END_NAMESPACE + +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(StandardTitleBar)) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index d43dd98..1fc4d34 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -54,6 +54,7 @@ set(SOURCES framelessconfig.cpp sysapiloader.cpp chromepalette.cpp + global.cpp ) if(WIN32) @@ -125,12 +126,12 @@ else() ) endif() -if (APPLE) +if(APPLE) target_link_libraries(${SUB_PROJ_NAME} PRIVATE "-framework Foundation" "-framework Cocoa" ) -elseif (UNIX) +elseif(UNIX) target_compile_definitions(${SUB_PROJ_NAME} PRIVATE GDK_VERSION_MIN_REQUIRED=GDK_VERSION_3_6 ) diff --git a/src/core/chromepalette.cpp b/src/core/chromepalette.cpp index 226f0fc..d8e84f3 100644 --- a/src/core/chromepalette.cpp +++ b/src/core/chromepalette.cpp @@ -133,8 +133,8 @@ ChromePalette::~ChromePalette() = default; QColor ChromePalette::titleBarActiveBackgroundColor() const { Q_D(const ChromePalette); - if (d->mask & ChromePalettePrivate::MaskFlag::TitleBarActiveBackgroundColor) { - return d->titleBarActiveBackgroundColor; + if (d->titleBarActiveBackgroundColor.has_value()) { + return d->titleBarActiveBackgroundColor.value(); } return d->titleBarActiveBackgroundColor_sys; } @@ -142,8 +142,8 @@ QColor ChromePalette::titleBarActiveBackgroundColor() const QColor ChromePalette::titleBarInactiveBackgroundColor() const { Q_D(const ChromePalette); - if (d->mask & ChromePalettePrivate::MaskFlag::TitleBarInactiveBackgroundColor) { - return d->titleBarInactiveBackgroundColor; + if (d->titleBarInactiveBackgroundColor.has_value()) { + return d->titleBarInactiveBackgroundColor.value(); } return d->titleBarInactiveBackgroundColor_sys; } @@ -151,8 +151,8 @@ QColor ChromePalette::titleBarInactiveBackgroundColor() const QColor ChromePalette::titleBarActiveForegroundColor() const { Q_D(const ChromePalette); - if (d->mask & ChromePalettePrivate::MaskFlag::TitleBarActiveForegroundColor) { - return d->titleBarActiveForegroundColor; + if (d->titleBarActiveForegroundColor.has_value()) { + return d->titleBarActiveForegroundColor.value(); } return d->titleBarActiveForegroundColor_sys; } @@ -160,8 +160,8 @@ QColor ChromePalette::titleBarActiveForegroundColor() const QColor ChromePalette::titleBarInactiveForegroundColor() const { Q_D(const ChromePalette); - if (d->mask & ChromePalettePrivate::MaskFlag::TitleBarInactiveForegroundColor) { - return d->titleBarInactiveForegroundColor; + if (d->titleBarInactiveForegroundColor.has_value()) { + return d->titleBarInactiveForegroundColor.value(); } return d->titleBarInactiveForegroundColor_sys; } @@ -169,8 +169,8 @@ QColor ChromePalette::titleBarInactiveForegroundColor() const QColor ChromePalette::chromeButtonNormalColor() const { Q_D(const ChromePalette); - if (d->mask & ChromePalettePrivate::MaskFlag::ChromeButtonNormalColor) { - return d->chromeButtonNormalColor; + if (d->chromeButtonNormalColor.has_value()) { + return d->chromeButtonNormalColor.value(); } return d->chromeButtonNormalColor_sys; } @@ -178,8 +178,8 @@ QColor ChromePalette::chromeButtonNormalColor() const QColor ChromePalette::chromeButtonHoverColor() const { Q_D(const ChromePalette); - if (d->mask & ChromePalettePrivate::MaskFlag::ChromeButtonHoverColor) { - return d->chromeButtonHoverColor; + if (d->chromeButtonHoverColor.has_value()) { + return d->chromeButtonHoverColor.value(); } return d->chromeButtonHoverColor_sys; } @@ -187,8 +187,8 @@ QColor ChromePalette::chromeButtonHoverColor() const QColor ChromePalette::chromeButtonPressColor() const { Q_D(const ChromePalette); - if (d->mask & ChromePalettePrivate::MaskFlag::ChromeButtonPressColor) { - return d->chromeButtonPressColor; + if (d->chromeButtonPressColor.has_value()) { + return d->chromeButtonPressColor.value(); } return d->chromeButtonPressColor_sys; } @@ -196,8 +196,8 @@ QColor ChromePalette::chromeButtonPressColor() const QColor ChromePalette::closeButtonNormalColor() const { Q_D(const ChromePalette); - if (d->mask & ChromePalettePrivate::MaskFlag::CloseButtonNormalColor) { - return d->closeButtonNormalColor; + if (d->closeButtonNormalColor.has_value()) { + return d->closeButtonNormalColor.value(); } return d->closeButtonNormalColor_sys; } @@ -205,8 +205,8 @@ QColor ChromePalette::closeButtonNormalColor() const QColor ChromePalette::closeButtonHoverColor() const { Q_D(const ChromePalette); - if (d->mask & ChromePalettePrivate::MaskFlag::CloseButtonHoverColor) { - return d->closeButtonHoverColor; + if (d->closeButtonHoverColor.has_value()) { + return d->closeButtonHoverColor.value(); } return d->closeButtonHoverColor_sys; } @@ -214,8 +214,8 @@ QColor ChromePalette::closeButtonHoverColor() const QColor ChromePalette::closeButtonPressColor() const { Q_D(const ChromePalette); - if (d->mask & ChromePalettePrivate::MaskFlag::CloseButtonPressColor) { - return d->closeButtonPressColor; + if (d->closeButtonPressColor.has_value()) { + return d->closeButtonPressColor.value(); } return d->closeButtonPressColor_sys; } @@ -227,11 +227,11 @@ void ChromePalette::setTitleBarActiveBackgroundColor(const QColor &value) return; } Q_D(ChromePalette); - if (d->titleBarActiveBackgroundColor == value) { + if (d->titleBarActiveBackgroundColor.has_value() + && (d->titleBarActiveBackgroundColor.value() == value)) { return; } d->titleBarActiveBackgroundColor = value; - d->mask |= ChromePalettePrivate::MaskFlag::TitleBarActiveBackgroundColor; Q_EMIT titleBarActiveBackgroundColorChanged(); Q_EMIT titleBarColorChanged(); } @@ -239,8 +239,7 @@ void ChromePalette::setTitleBarActiveBackgroundColor(const QColor &value) void ChromePalette::resetTitleBarActiveBackgroundColor() { Q_D(ChromePalette); - d->titleBarActiveBackgroundColor = {}; - d->mask &= ~ChromePalettePrivate::Mask(ChromePalettePrivate::MaskFlag::TitleBarActiveBackgroundColor); + d->titleBarActiveBackgroundColor = std::nullopt; Q_EMIT titleBarActiveBackgroundColorChanged(); Q_EMIT titleBarColorChanged(); } @@ -252,11 +251,11 @@ void ChromePalette::setTitleBarInactiveBackgroundColor(const QColor &value) return; } Q_D(ChromePalette); - if (d->titleBarInactiveBackgroundColor == value) { + if (d->titleBarInactiveBackgroundColor.has_value() + && (d->titleBarInactiveBackgroundColor.value() == value)) { return; } d->titleBarInactiveBackgroundColor = value; - d->mask |= ChromePalettePrivate::MaskFlag::TitleBarInactiveBackgroundColor; Q_EMIT titleBarInactiveBackgroundColorChanged(); Q_EMIT titleBarColorChanged(); } @@ -264,8 +263,7 @@ void ChromePalette::setTitleBarInactiveBackgroundColor(const QColor &value) void ChromePalette::resetTitleBarInactiveBackgroundColor() { Q_D(ChromePalette); - d->titleBarInactiveBackgroundColor = {}; - d->mask &= ~ChromePalettePrivate::Mask(ChromePalettePrivate::MaskFlag::TitleBarInactiveBackgroundColor); + d->titleBarInactiveBackgroundColor = std::nullopt; Q_EMIT titleBarInactiveBackgroundColorChanged(); Q_EMIT titleBarColorChanged(); } @@ -277,11 +275,11 @@ void ChromePalette::setTitleBarActiveForegroundColor(const QColor &value) return; } Q_D(ChromePalette); - if (d->titleBarActiveForegroundColor == value) { + if (d->titleBarActiveForegroundColor.has_value() + && (d->titleBarActiveForegroundColor.value() == value)) { return; } d->titleBarActiveForegroundColor = value; - d->mask |= ChromePalettePrivate::MaskFlag::TitleBarActiveForegroundColor; Q_EMIT titleBarActiveForegroundColorChanged(); Q_EMIT titleBarColorChanged(); } @@ -289,8 +287,7 @@ void ChromePalette::setTitleBarActiveForegroundColor(const QColor &value) void ChromePalette::resetTitleBarActiveForegroundColor() { Q_D(ChromePalette); - d->titleBarActiveForegroundColor = {}; - d->mask &= ~ChromePalettePrivate::Mask(ChromePalettePrivate::MaskFlag::TitleBarActiveForegroundColor); + d->titleBarActiveForegroundColor = std::nullopt; Q_EMIT titleBarActiveForegroundColorChanged(); Q_EMIT titleBarColorChanged(); } @@ -302,11 +299,11 @@ void ChromePalette::setTitleBarInactiveForegroundColor(const QColor &value) return; } Q_D(ChromePalette); - if (d->titleBarInactiveForegroundColor == value) { + if (d->titleBarInactiveForegroundColor.has_value() + && (d->titleBarInactiveForegroundColor.value() == value)) { return; } d->titleBarInactiveForegroundColor = value; - d->mask |= ChromePalettePrivate::MaskFlag::TitleBarInactiveForegroundColor; Q_EMIT titleBarInactiveForegroundColorChanged(); Q_EMIT titleBarColorChanged(); } @@ -314,8 +311,7 @@ void ChromePalette::setTitleBarInactiveForegroundColor(const QColor &value) void ChromePalette::resetTitleBarInactiveForegroundColor() { Q_D(ChromePalette); - d->titleBarInactiveForegroundColor = {}; - d->mask &= ~ChromePalettePrivate::Mask(ChromePalettePrivate::MaskFlag::TitleBarInactiveForegroundColor); + d->titleBarInactiveForegroundColor = std::nullopt; Q_EMIT titleBarInactiveForegroundColorChanged(); Q_EMIT titleBarColorChanged(); } @@ -327,11 +323,11 @@ void ChromePalette::setChromeButtonNormalColor(const QColor &value) return; } Q_D(ChromePalette); - if (d->chromeButtonNormalColor == value) { + if (d->chromeButtonNormalColor.has_value() + && (d->chromeButtonNormalColor.value() == value)) { return; } d->chromeButtonNormalColor = value; - d->mask |= ChromePalettePrivate::MaskFlag::ChromeButtonNormalColor; Q_EMIT chromeButtonNormalColorChanged(); Q_EMIT chromeButtonColorChanged(); } @@ -339,8 +335,7 @@ void ChromePalette::setChromeButtonNormalColor(const QColor &value) void ChromePalette::resetChromeButtonNormalColor() { Q_D(ChromePalette); - d->chromeButtonNormalColor = {}; - d->mask &= ~ChromePalettePrivate::Mask(ChromePalettePrivate::MaskFlag::ChromeButtonNormalColor); + d->chromeButtonNormalColor = std::nullopt; Q_EMIT chromeButtonNormalColorChanged(); Q_EMIT chromeButtonColorChanged(); } @@ -352,11 +347,11 @@ void ChromePalette::setChromeButtonHoverColor(const QColor &value) return; } Q_D(ChromePalette); - if (d->chromeButtonHoverColor == value) { + if (d->chromeButtonHoverColor.has_value() + && (d->chromeButtonHoverColor.value() == value)) { return; } d->chromeButtonHoverColor = value; - d->mask |= ChromePalettePrivate::MaskFlag::ChromeButtonHoverColor; Q_EMIT chromeButtonHoverColorChanged(); Q_EMIT chromeButtonColorChanged(); } @@ -364,8 +359,7 @@ void ChromePalette::setChromeButtonHoverColor(const QColor &value) void ChromePalette::resetChromeButtonHoverColor() { Q_D(ChromePalette); - d->chromeButtonHoverColor = {}; - d->mask &= ~ChromePalettePrivate::Mask(ChromePalettePrivate::MaskFlag::ChromeButtonHoverColor); + d->chromeButtonHoverColor = std::nullopt; Q_EMIT chromeButtonHoverColorChanged(); Q_EMIT chromeButtonColorChanged(); } @@ -377,11 +371,11 @@ void ChromePalette::setChromeButtonPressColor(const QColor &value) return; } Q_D(ChromePalette); - if (d->chromeButtonPressColor == value) { + if (d->chromeButtonPressColor.has_value() + && (d->chromeButtonPressColor.value() == value)) { return; } d->chromeButtonPressColor = value; - d->mask |= ChromePalettePrivate::MaskFlag::ChromeButtonPressColor; Q_EMIT chromeButtonPressColorChanged(); Q_EMIT chromeButtonColorChanged(); } @@ -389,8 +383,7 @@ void ChromePalette::setChromeButtonPressColor(const QColor &value) void ChromePalette::resetChromeButtonPressColor() { Q_D(ChromePalette); - d->chromeButtonPressColor = {}; - d->mask &= ~ChromePalettePrivate::Mask(ChromePalettePrivate::MaskFlag::ChromeButtonPressColor); + d->chromeButtonPressColor = std::nullopt; Q_EMIT chromeButtonPressColorChanged(); Q_EMIT chromeButtonColorChanged(); } @@ -402,11 +395,11 @@ void ChromePalette::setCloseButtonNormalColor(const QColor &value) return; } Q_D(ChromePalette); - if (d->closeButtonNormalColor == value) { + if (d->closeButtonNormalColor.has_value() + && (d->closeButtonNormalColor.value() == value)) { return; } d->closeButtonNormalColor = value; - d->mask |= ChromePalettePrivate::MaskFlag::CloseButtonNormalColor; Q_EMIT closeButtonNormalColorChanged(); Q_EMIT chromeButtonColorChanged(); } @@ -414,8 +407,7 @@ void ChromePalette::setCloseButtonNormalColor(const QColor &value) void ChromePalette::resetCloseButtonNormalColor() { Q_D(ChromePalette); - d->closeButtonNormalColor = {}; - d->mask &= ~ChromePalettePrivate::Mask(ChromePalettePrivate::MaskFlag::CloseButtonNormalColor); + d->closeButtonNormalColor = std::nullopt; Q_EMIT closeButtonNormalColorChanged(); Q_EMIT chromeButtonColorChanged(); } @@ -427,11 +419,11 @@ void ChromePalette::setCloseButtonHoverColor(const QColor &value) return; } Q_D(ChromePalette); - if (d->closeButtonHoverColor == value) { + if (d->closeButtonHoverColor.has_value() + && (d->closeButtonHoverColor.value() == value)) { return; } d->closeButtonHoverColor = value; - d->mask |= ChromePalettePrivate::MaskFlag::CloseButtonHoverColor; Q_EMIT closeButtonHoverColorChanged(); Q_EMIT chromeButtonColorChanged(); } @@ -439,8 +431,7 @@ void ChromePalette::setCloseButtonHoverColor(const QColor &value) void ChromePalette::resetCloseButtonHoverColor() { Q_D(ChromePalette); - d->closeButtonHoverColor = {}; - d->mask &= ~ChromePalettePrivate::Mask(ChromePalettePrivate::MaskFlag::CloseButtonHoverColor); + d->closeButtonHoverColor = std::nullopt; Q_EMIT closeButtonHoverColorChanged(); Q_EMIT chromeButtonColorChanged(); } @@ -452,11 +443,11 @@ void ChromePalette::setCloseButtonPressColor(const QColor &value) return; } Q_D(ChromePalette); - if (d->closeButtonPressColor == value) { + if (d->closeButtonPressColor.has_value() + && (d->closeButtonPressColor.value() == value)) { return; } d->closeButtonPressColor = value; - d->mask |= ChromePalettePrivate::MaskFlag::CloseButtonPressColor; Q_EMIT closeButtonPressColorChanged(); Q_EMIT chromeButtonColorChanged(); } @@ -464,8 +455,7 @@ void ChromePalette::setCloseButtonPressColor(const QColor &value) void ChromePalette::resetCloseButtonPressColor() { Q_D(ChromePalette); - d->closeButtonPressColor = {}; - d->mask &= ~ChromePalettePrivate::Mask(ChromePalettePrivate::MaskFlag::CloseButtonPressColor); + d->closeButtonPressColor = std::nullopt; Q_EMIT closeButtonPressColorChanged(); Q_EMIT chromeButtonColorChanged(); } diff --git a/src/core/framelessmanager.cpp b/src/core/framelessmanager.cpp index 51ed17b..d7a803c 100644 --- a/src/core/framelessmanager.cpp +++ b/src/core/framelessmanager.cpp @@ -26,7 +26,6 @@ #include "framelessmanager_p.h" #include #include -#include #include #include #include @@ -37,30 +36,6 @@ # include "framelesshelper_win.h" #endif -#ifndef COMPILER_STRING -# ifdef Q_CC_CLANG // Must be before GNU, because Clang claims to be GNU too. -# define COMPILER_STRING __VERSION__ // Already includes the compiler's name. -# elif defined(Q_CC_GHS) -# define COMPILER_STRING "GHS " QT_STRINGIFY(__GHS_VERSION_NUMBER) -# elif defined(Q_CC_GNU) -# define COMPILER_STRING "GCC " __VERSION__ -# elif defined(Q_CC_MSVC) -# if (_MSC_VER < 1910) -# define COMPILER_STRING "MSVC 2015" -# elif (_MSC_VER < 1917) -# define COMPILER_STRING "MSVC 2017" -# elif (_MSC_VER < 1930) -# define COMPILER_STRING "MSVC 2019" -# elif (_MSC_VER < 2000) -# define COMPILER_STRING "MSVC 2022" -# else -# define COMPILER_STRING "MSVC version " QT_STRINGIFY(_MSC_VER) -# endif -# else -# define COMPILER_STRING "UNKNOWN" -# endif -#endif - // 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 @@ -84,16 +59,6 @@ Q_GLOBAL_STATIC(FramelessManagerHelper, g_helper) Q_GLOBAL_STATIC(FramelessManager, g_manager) -#ifdef Q_OS_LINUX -static constexpr const char QT_QPA_ENV_VAR[] = "QT_QPA_PLATFORM"; -FRAMELESSHELPER_BYTEARRAY_CONSTANT(xcb) -#endif - -#ifdef Q_OS_MACOS -static constexpr const char MAC_LAYER_ENV_VAR[] = "QT_MAC_WANTS_LAYER"; -FRAMELESSHELPER_BYTEARRAY_CONSTANT2(ValueOne, "1") -#endif - FRAMELESSHELPER_STRING_CONSTANT2(IconFontFilePath, ":/org.wangwenx190.FramelessHelper/resources/fonts/Segoe Fluent Icons.ttf") FRAMELESSHELPER_STRING_CONSTANT2(IconFontName, "Segoe Fluent Icons") static constexpr const int kIconFontPointSize = 8; @@ -291,87 +256,4 @@ void FramelessManager::addWindow(const SystemParameters ¶ms) d->addWindow(params); } -void FramelessHelper::Core::initialize() -{ - static bool inited = false; - if (inited) { - return; - } - inited = true; -#ifdef Q_OS_LINUX - // 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 - // enough, that is, before the construction of any Q(Gui)Application - // instances. QCoreApplication won't instantiate the platform plugin. - qputenv(QT_QPA_ENV_VAR, kxcb); -#endif -#ifdef Q_OS_MACOS - // This has become the default setting since some unknown Qt version, - // check whether we can remove this hack safely or not. - qputenv(MAC_LAYER_ENV_VAR, kValueOne); -#endif -#ifdef Q_OS_WINDOWS - // This is equivalent to set the "dpiAware" and "dpiAwareness" field in - // your manifest file. It works through out Windows Vista to Windows 11. - // It's highly recommended to enable the highest DPI awareness level - // (currently it's PerMonitor Version 2, or PMv2 for short) for any GUI - // applications, to allow your user interface scale to an appropriate - // size and still stay sharp, though you will have to do the calculation - // and resize by yourself. - Utils::tryToEnableHighestDpiAwarenessLevel(); -#endif - // This attribute is known to be __NOT__ compatible with QGLWidget. - // Please consider migrating to the recommended QOpenGLWidget instead. - QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); -#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) - // Enable high DPI scaling by default, but only for Qt5 applications, - // because this has become the default setting since Qt6 and it can't - // be changed from outside anymore (except for internal testing purposes). - QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); -#endif -#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) - // Non-integer scale factors will cause Qt have some painting defects - // for both Qt Widgets and Qt Quick applications, and it's still not - // totally fixed till now (Qt 6.5), so we round the scale factors to - // get a better looking. Non-integer scale factors will also cause - // flicker and jitter during window resizing. - QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Round); -#endif - qRegisterMetaType