forked from github_mirror/framelesshelper
code simplification, minor re-structure
Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
b413d0b1e6
commit
2806cc811b
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -124,3 +124,5 @@ private:
|
|||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(ChromePalette))
|
||||
|
|
|
@ -45,3 +45,5 @@ protected:
|
|||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessHelperQt))
|
||||
|
|
|
@ -43,3 +43,5 @@ public:
|
|||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessHelperWin))
|
||||
|
|
|
@ -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)";
|
||||
|
|
|
@ -59,3 +59,5 @@ private:
|
|||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessManager))
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "framelesshelpercore_global.h"
|
||||
#include <QtCore/qobject.h>
|
||||
#include <QtCore/qpointer.h>
|
||||
#include <optional>
|
||||
|
||||
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<ChromePalette> 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<QColor> titleBarActiveBackgroundColor = std::nullopt;
|
||||
std::optional<QColor> titleBarInactiveBackgroundColor = std::nullopt;
|
||||
std::optional<QColor> titleBarActiveForegroundColor = std::nullopt;
|
||||
std::optional<QColor> titleBarInactiveForegroundColor = std::nullopt;
|
||||
std::optional<QColor> chromeButtonNormalColor = std::nullopt;
|
||||
std::optional<QColor> chromeButtonHoverColor = std::nullopt;
|
||||
std::optional<QColor> chromeButtonPressColor = std::nullopt;
|
||||
std::optional<QColor> closeButtonNormalColor = std::nullopt;
|
||||
std::optional<QColor> closeButtonHoverColor = std::nullopt;
|
||||
std::optional<QColor> closeButtonPressColor = std::nullopt;
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(ChromePalettePrivate::Mask)
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(ChromePalettePrivate))
|
||||
|
|
|
@ -50,3 +50,5 @@ public:
|
|||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessConfig))
|
||||
|
|
|
@ -66,3 +66,5 @@ private:
|
|||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessManagerPrivate))
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -86,4 +86,5 @@ Q_SIGNALS:
|
|||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickUtils))
|
||||
QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickUtils))
|
||||
|
|
|
@ -87,3 +87,5 @@ private:
|
|||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickHelperPrivate))
|
||||
|
|
|
@ -80,5 +80,6 @@ private:
|
|||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickWindow))
|
||||
QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickWindow))
|
||||
#endif
|
||||
|
|
|
@ -82,4 +82,6 @@ private:
|
|||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickWindowPrivate))
|
||||
#endif
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -45,4 +45,5 @@ public:
|
|||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickChromePalette))
|
||||
QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickChromePalette))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -61,3 +61,5 @@ private:
|
|||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessMainWindow))
|
||||
|
|
|
@ -61,3 +61,5 @@ private:
|
|||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessWidget))
|
||||
|
|
|
@ -77,3 +77,5 @@ private:
|
|||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessWidgetsHelper))
|
||||
|
|
|
@ -61,3 +61,5 @@ private:
|
|||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessMainWindowPrivate))
|
||||
|
|
|
@ -61,3 +61,5 @@ private:
|
|||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessWidgetPrivate))
|
||||
|
|
|
@ -84,3 +84,5 @@ private:
|
|||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessWidgetsHelperPrivate))
|
||||
|
|
|
@ -92,3 +92,5 @@ private:
|
|||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(StandardSystemButtonPrivate))
|
||||
|
|
|
@ -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<ChromePalette> m_chromePalette;
|
||||
bool m_titleLabelVisible = true;
|
||||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(StandardTitleBarPrivate))
|
||||
|
|
|
@ -61,3 +61,5 @@ private:
|
|||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(WidgetsSharedHelper))
|
||||
|
|
|
@ -90,3 +90,5 @@ private:
|
|||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(StandardSystemButton))
|
||||
|
|
|
@ -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<StandardTitleBarPrivate> d_ptr;
|
||||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(StandardTitleBar))
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#include "framelessmanager_p.h"
|
||||
#include <QtCore/qmutex.h>
|
||||
#include <QtCore/qdebug.h>
|
||||
#include <QtGui/qguiapplication.h>
|
||||
#include <QtGui/qscreen.h>
|
||||
#include <QtGui/qwindow.h>
|
||||
#include <QtGui/qfontdatabase.h>
|
||||
|
@ -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<Option>();
|
||||
qRegisterMetaType<SystemTheme>();
|
||||
qRegisterMetaType<SystemButtonType>();
|
||||
qRegisterMetaType<DwmColorizationArea>();
|
||||
qRegisterMetaType<Anchor>();
|
||||
qRegisterMetaType<ButtonState>();
|
||||
qRegisterMetaType<WindowsVersion>();
|
||||
qRegisterMetaType<ApplicationType>();
|
||||
qRegisterMetaType<BlurMode>();
|
||||
qRegisterMetaType<VersionNumber>();
|
||||
qRegisterMetaType<SystemParameters>();
|
||||
qRegisterMetaType<VersionInfo>();
|
||||
}
|
||||
|
||||
void FramelessHelper::Core::uninitialize()
|
||||
{
|
||||
// Currently nothing to do here.
|
||||
}
|
||||
|
||||
VersionInfo FramelessHelper::Core::version()
|
||||
{
|
||||
static const VersionInfo result = []() -> VersionInfo {
|
||||
VersionInfo ver = {};
|
||||
ver.version.major = FRAMELESSHELPER_VERSION_MAJOR;
|
||||
ver.version.minor = FRAMELESSHELPER_VERSION_MINOR;
|
||||
ver.version.patch = FRAMELESSHELPER_VERSION_PATCH;
|
||||
ver.version.tweak = FRAMELESSHELPER_VERSION_TWEAK;
|
||||
ver.commit = QUtf8String(FRAMELESSHELPER_COMMIT_STR);
|
||||
ver.compileDateTime = QUtf8String(FRAMELESSHELPER_COMPILE_DATETIME);
|
||||
ver.compiler = QUtf8String(COMPILER_STRING);
|
||||
return ver;
|
||||
}();
|
||||
return result;
|
||||
}
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
|
|
@ -0,0 +1,174 @@
|
|||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (C) 2022 by wangwenx190 (Yuhang Zhao)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "framelesshelpercore_global.h"
|
||||
#include "utils.h"
|
||||
#include "framelessmanager.h"
|
||||
#ifdef Q_OS_WINDOWS
|
||||
# include "framelesshelper_win.h"
|
||||
#endif
|
||||
#include "framelesshelper_qt.h"
|
||||
#include "chromepalette.h"
|
||||
#include <QtGui/qguiapplication.h>
|
||||
|
||||
#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
|
||||
|
||||
#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_BEGIN_NAMESPACE
|
||||
|
||||
using namespace Global;
|
||||
|
||||
namespace FramelessHelper::Core
|
||||
{
|
||||
|
||||
void 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<Option>();
|
||||
qRegisterMetaType<SystemTheme>();
|
||||
qRegisterMetaType<SystemButtonType>();
|
||||
qRegisterMetaType<DwmColorizationArea>();
|
||||
qRegisterMetaType<Anchor>();
|
||||
qRegisterMetaType<ButtonState>();
|
||||
qRegisterMetaType<WindowsVersion>();
|
||||
qRegisterMetaType<ApplicationType>();
|
||||
qRegisterMetaType<BlurMode>();
|
||||
qRegisterMetaType<VersionNumber>();
|
||||
qRegisterMetaType<SystemParameters>();
|
||||
qRegisterMetaType<VersionInfo>();
|
||||
qRegisterMetaType<FramelessManager>();
|
||||
#ifdef Q_OS_WINDOWS
|
||||
qRegisterMetaType<FramelessHelperWin>();
|
||||
#endif
|
||||
qRegisterMetaType<FramelessHelperQt>();
|
||||
qRegisterMetaType<ChromePalette>();
|
||||
}
|
||||
|
||||
void uninitialize()
|
||||
{
|
||||
// Currently nothing to do here.
|
||||
}
|
||||
|
||||
VersionInfo version()
|
||||
{
|
||||
static const VersionInfo result = []() -> VersionInfo {
|
||||
VersionInfo ver = {};
|
||||
ver.version.major = FRAMELESSHELPER_VERSION_MAJOR;
|
||||
ver.version.minor = FRAMELESSHELPER_VERSION_MINOR;
|
||||
ver.version.patch = FRAMELESSHELPER_VERSION_PATCH;
|
||||
ver.version.tweak = FRAMELESSHELPER_VERSION_TWEAK;
|
||||
ver.commit = QUtf8String(FRAMELESSHELPER_COMMIT_STR);
|
||||
ver.compileDateTime = QUtf8String(FRAMELESSHELPER_COMPILE_DATETIME);
|
||||
ver.compiler = QUtf8String(COMPILER_STRING);
|
||||
return ver;
|
||||
}();
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
|
@ -62,7 +62,7 @@ struct Win32UtilsHelper
|
|||
|
||||
Q_GLOBAL_STATIC(Win32UtilsHelper, g_utilsHelper)
|
||||
|
||||
static constexpr const wchar_t DUMMY_WINDOW_CLASS_NAME[] = L"FRAMELESSHELPER_DUMMY_WINDOW_CLASS";
|
||||
static constexpr const wchar_t kDummyWindowClassName[] = L"FRAMELESSHELPER_DUMMY_WINDOW_CLASS";
|
||||
static const QString qDwmRegistryKey = QString::fromWCharArray(kDwmRegistryKey);
|
||||
static const QString qPersonalizeRegistryKey = QString::fromWCharArray(kPersonalizeRegistryKey);
|
||||
static const QString qDwmColorKeyName = QString::fromWCharArray(kDwmColorKeyName);
|
||||
|
@ -210,13 +210,13 @@ private:
|
|||
wcex.cbSize = sizeof(wcex);
|
||||
wcex.lpfnWndProc = DefWindowProcW;
|
||||
wcex.hInstance = instance;
|
||||
wcex.lpszClassName = DUMMY_WINDOW_CLASS_NAME;
|
||||
wcex.lpszClassName = kDummyWindowClassName;
|
||||
const ATOM atom = RegisterClassExW(&wcex);
|
||||
if (!atom) {
|
||||
qWarning() << Utils::getSystemErrorMessage(kRegisterClassExW);
|
||||
return nullptr;
|
||||
}
|
||||
const HWND window = CreateWindowExW(0, DUMMY_WINDOW_CLASS_NAME, nullptr,
|
||||
const HWND window = CreateWindowExW(0, kDummyWindowClassName, nullptr,
|
||||
WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, nullptr, nullptr, instance, nullptr);
|
||||
if (!window) {
|
||||
qWarning() << Utils::getSystemErrorMessage(kCreateWindowExW);
|
||||
|
@ -1477,7 +1477,8 @@ bool Utils::setBlurBehindWindowEnabled(const WId windowId, const BlurMode mode,
|
|||
const auto pSetWindowCompositionAttribute =
|
||||
reinterpret_cast<SetWindowCompositionAttributePtr>(
|
||||
SysApiLoader::instance()->get(kSetWindowCompositionAttribute));
|
||||
static const bool isBuild22523OrGreater = doCompareWindowsVersion({10, 0, 22523});
|
||||
//static const bool isWin11Insider2OrGreater = doCompareWindowsVersion({10, 0, 22557});
|
||||
static const bool isWin11Insider1OrGreater = doCompareWindowsVersion({10, 0, 22523});
|
||||
static const bool isWin11OrGreater = isWindowsVersionOrGreater(WindowsVersion::_11_21H2);
|
||||
static const bool isWin10OrGreater = isWindowsVersionOrGreater(WindowsVersion::_10_1507);
|
||||
const BlurMode blurMode = [mode]() -> BlurMode {
|
||||
|
@ -1509,7 +1510,7 @@ bool Utils::setBlurBehindWindowEnabled(const WId windowId, const BlurMode mode,
|
|||
return mode;
|
||||
}();
|
||||
if (blurMode == BlurMode::Disable) {
|
||||
if (isBuild22523OrGreater) {
|
||||
if (isWin11Insider1OrGreater) {
|
||||
const _DWM_SYSTEMBACKDROP_TYPE dwmsbt = _DWMSBT_NONE;
|
||||
const HRESULT hr = API_CALL_FUNCTION(DwmSetWindowAttribute,
|
||||
hwnd, _DWMWA_SYSTEMBACKDROP_TYPE, &dwmsbt, sizeof(dwmsbt));
|
||||
|
@ -1547,7 +1548,7 @@ bool Utils::setBlurBehindWindowEnabled(const WId windowId, const BlurMode mode,
|
|||
const MARGINS margins = {-1, -1, -1, -1};
|
||||
HRESULT hr = API_CALL_FUNCTION(DwmExtendFrameIntoClientArea, hwnd, &margins);
|
||||
if (SUCCEEDED(hr)) {
|
||||
if (isBuild22523OrGreater) {
|
||||
if (isWin11Insider1OrGreater) {
|
||||
// ### FIXME: Is it necessary to enable the host backdrop brush in the first place? To be checked.
|
||||
const BOOL enable = TRUE;
|
||||
hr = API_CALL_FUNCTION(DwmSetWindowAttribute, hwnd,
|
||||
|
|
|
@ -48,6 +48,7 @@ set(SOURCES
|
|||
framelessquickwindow.cpp
|
||||
framelessquickhelper.cpp
|
||||
quickchromepalette.cpp
|
||||
global.cpp
|
||||
)
|
||||
|
||||
if(WIN32 AND NOT FRAMELESSHELPER_BUILD_STATIC)
|
||||
|
|
|
@ -181,7 +181,7 @@ void FramelessQuickHelperPrivate::attachToWindow()
|
|||
// we reach here, and all the modifications from the Qt side will be lost
|
||||
// due to QPA will reset the position and size of the window during it's
|
||||
// initialization process.
|
||||
QTimer::singleShot(200, this, [this](){
|
||||
QTimer::singleShot(0, this, [this](){
|
||||
if (FramelessConfig::instance()->isSet(Option::CenterWindowBeforeShow)) {
|
||||
moveWindowToDesktopCenter();
|
||||
}
|
||||
|
|
|
@ -54,6 +54,14 @@ void FramelessHelper::Quick::registerTypes(QQmlEngine *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;
|
||||
|
||||
qRegisterMetaType<QuickGlobal::SystemTheme>();
|
||||
qRegisterMetaType<QuickGlobal::SystemButtonType>();
|
||||
qRegisterMetaType<QuickGlobal::DwmColorizationArea>();
|
||||
|
@ -62,6 +70,17 @@ void FramelessHelper::Quick::registerTypes(QQmlEngine *engine)
|
|||
qRegisterMetaType<QuickGlobal::WindowsVersion>();
|
||||
qRegisterMetaType<QuickGlobal::ApplicationType>();
|
||||
qRegisterMetaType<QuickGlobal::BlurMode>();
|
||||
|
||||
qRegisterMetaType<QuickGlobal>();
|
||||
qRegisterMetaType<FramelessQuickUtils>();
|
||||
qRegisterMetaType<QuickChromePalette>();
|
||||
qRegisterMetaType<FramelessQuickHelper>();
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
qRegisterMetaType<QuickStandardSystemButton>();
|
||||
qRegisterMetaType<QuickStandardTitleBar>();
|
||||
qRegisterMetaType<FramelessQuickWindow>();
|
||||
#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
|
||||
qmlRegisterUncreatableType<QuickGlobal>(QUICK_URI_FULL, "FramelessHelperConstants",
|
||||
FRAMELESSHELPER_STRING_LITERAL("The FramelessHelperConstants namespace is not creatable, you can only use it to access it's enums."));
|
||||
qmlRegisterSingletonType<FramelessQuickUtils>(QUICK_URI_EXPAND("FramelessUtils"),
|
||||
|
@ -71,9 +90,11 @@ void FramelessHelper::Quick::registerTypes(QQmlEngine *engine)
|
|||
return new FramelessQuickUtils;
|
||||
});
|
||||
qmlRegisterAnonymousType<QuickChromePalette>(QUICK_URI_SHORT);
|
||||
|
||||
qmlRegisterRevision<QWindow, 254>(QUICK_URI_FULL);
|
||||
qmlRegisterRevision<QQuickWindow, 254>(QUICK_URI_FULL);
|
||||
qmlRegisterRevision<QQuickItem, 254>(QUICK_URI_FULL);
|
||||
|
||||
qmlRegisterType<FramelessQuickHelper>(QUICK_URI_EXPAND("FramelessHelper"));
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
qmlRegisterType<QuickStandardSystemButton>(QUICK_URI_EXPAND("StandardSystemButton"));
|
||||
|
@ -87,6 +108,7 @@ void FramelessHelper::Quick::registerTypes(QQmlEngine *engine)
|
|||
qmlRegisterTypeNotAvailable(QUICK_URI_EXPAND("FramelessWindow"),
|
||||
FRAMELESSHELPER_STRING_LITERAL("FramelessWindow is not available until Qt6."));
|
||||
#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
|
||||
qmlRegisterModule(QUICK_URI_FULL);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (C) 2022 by wangwenx190 (Yuhang Zhao)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "framelesshelperquick_global.h"
|
||||
|
||||
FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||
|
||||
namespace FramelessHelper::Quick
|
||||
{
|
||||
|
||||
void initialize()
|
||||
{
|
||||
static bool inited = false;
|
||||
if (inited) {
|
||||
return;
|
||||
}
|
||||
inited = true;
|
||||
|
||||
FramelessHelper::Core::initialize();
|
||||
|
||||
// ### TODO: The Quick module-specific initialization.
|
||||
}
|
||||
|
||||
void uninitialize()
|
||||
{
|
||||
// ### TODO: The Quick module-specific uninitialization.
|
||||
|
||||
FramelessHelper::Core::uninitialize();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
|
@ -46,6 +46,7 @@ set(SOURCES
|
|||
standardsystembutton.cpp
|
||||
standardtitlebar.cpp
|
||||
widgetssharedhelper.cpp
|
||||
global.cpp
|
||||
)
|
||||
|
||||
if(WIN32 AND NOT FRAMELESSHELPER_BUILD_STATIC)
|
||||
|
|
|
@ -304,7 +304,7 @@ void FramelessWidgetsHelperPrivate::attachToWindow()
|
|||
// we reach here, and all the modifications from the Qt side will be lost
|
||||
// due to QPA will reset the position and size of the window during it's
|
||||
// initialization process.
|
||||
QTimer::singleShot(200, this, [this](){
|
||||
QTimer::singleShot(0, this, [this](){
|
||||
if (FramelessConfig::instance()->isSet(Option::CenterWindowBeforeShow)) {
|
||||
moveWindowToDesktopCenter();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (C) 2022 by wangwenx190 (Yuhang Zhao)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "framelesshelperwidgets_global.h"
|
||||
#include "standardtitlebar.h"
|
||||
#include "standardsystembutton.h"
|
||||
#include "framelesswidgetshelper.h"
|
||||
#include "framelesswidget.h"
|
||||
#include "framelessmainwindow.h"
|
||||
|
||||
FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||
|
||||
namespace FramelessHelper::Widgets
|
||||
{
|
||||
|
||||
void initialize()
|
||||
{
|
||||
static bool inited = false;
|
||||
if (inited) {
|
||||
return;
|
||||
}
|
||||
inited = true;
|
||||
|
||||
FramelessHelper::Core::initialize();
|
||||
|
||||
qRegisterMetaType<StandardTitleBar>();
|
||||
qRegisterMetaType<StandardSystemButton>();
|
||||
qRegisterMetaType<FramelessWidgetsHelper>();
|
||||
qRegisterMetaType<FramelessWidget>();
|
||||
qRegisterMetaType<FramelessMainWindow>();
|
||||
}
|
||||
|
||||
void uninitialize()
|
||||
{
|
||||
// ### TODO: The Widgets module-specific uninitialization.
|
||||
|
||||
FramelessHelper::Core::uninitialize();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
|
@ -145,37 +145,55 @@ void StandardTitleBarPrivate::paintTitleBar(QPaintEvent *event)
|
|||
painter.setRenderHints(QPainter::Antialiasing |
|
||||
QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
|
||||
painter.fillRect(QRect(QPoint(0, 0), q->size()), backgroundColor);
|
||||
const QString text = m_window->windowTitle();
|
||||
if (!text.isEmpty()) {
|
||||
const QFont font = [q]() -> QFont {
|
||||
QFont f = q->font();
|
||||
f.setPointSize(kDefaultTitleBarFontPointSize);
|
||||
return f;
|
||||
}();
|
||||
painter.setPen(foregroundColor);
|
||||
painter.setFont(font);
|
||||
const QRect rect = [this, q]() -> QRect {
|
||||
const int w = q->width();
|
||||
int leftMargin = 0;
|
||||
int rightMargin = 0;
|
||||
if (m_labelAlignment & Qt::AlignLeft) {
|
||||
leftMargin = kDefaultTitleBarContentsMargin;
|
||||
}
|
||||
if (m_labelAlignment & Qt::AlignRight) {
|
||||
rightMargin = (w - m_minimizeButton->x() + kDefaultTitleBarContentsMargin);
|
||||
}
|
||||
const int x = leftMargin;
|
||||
const int y = 0;
|
||||
const int width = (w - leftMargin - rightMargin);
|
||||
const int height = q->height();
|
||||
return {QPoint(x, y), QSize(width, height)};
|
||||
}();
|
||||
painter.drawText(rect, m_labelAlignment, text);
|
||||
if (m_titleLabelVisible) {
|
||||
const QString text = m_window->windowTitle();
|
||||
if (!text.isEmpty()) {
|
||||
const QFont font = [q]() -> QFont {
|
||||
QFont f = q->font();
|
||||
f.setPointSize(kDefaultTitleBarFontPointSize);
|
||||
return f;
|
||||
}();
|
||||
painter.setPen(foregroundColor);
|
||||
painter.setFont(font);
|
||||
const QRect rect = [this, q]() -> QRect {
|
||||
const int w = q->width();
|
||||
int leftMargin = 0;
|
||||
int rightMargin = 0;
|
||||
if (m_labelAlignment & Qt::AlignLeft) {
|
||||
leftMargin = kDefaultTitleBarContentsMargin;
|
||||
}
|
||||
if (m_labelAlignment & Qt::AlignRight) {
|
||||
rightMargin = (w - m_minimizeButton->x() + kDefaultTitleBarContentsMargin);
|
||||
}
|
||||
const int x = leftMargin;
|
||||
const int y = 0;
|
||||
const int width = (w - leftMargin - rightMargin);
|
||||
const int height = q->height();
|
||||
return {QPoint(x, y), QSize(width, height)};
|
||||
}();
|
||||
painter.drawText(rect, m_labelAlignment, text);
|
||||
}
|
||||
}
|
||||
painter.restore();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool StandardTitleBarPrivate::titleLabelVisible() const
|
||||
{
|
||||
return m_titleLabelVisible;
|
||||
}
|
||||
|
||||
void StandardTitleBarPrivate::setTitleLabelVisible(const bool value)
|
||||
{
|
||||
if (m_titleLabelVisible == value) {
|
||||
return;
|
||||
}
|
||||
m_titleLabelVisible = value;
|
||||
Q_Q(StandardTitleBar);
|
||||
q->update();
|
||||
Q_EMIT q->titleLabelVisibleChanged();
|
||||
}
|
||||
|
||||
void StandardTitleBarPrivate::updateMaximizeButton()
|
||||
{
|
||||
const bool max = m_window->isMaximized();
|
||||
|
@ -379,6 +397,18 @@ ChromePalette *StandardTitleBar::chromePalette() const
|
|||
return d->chromePalette();
|
||||
}
|
||||
|
||||
bool StandardTitleBar::titleLabelVisible() const
|
||||
{
|
||||
Q_D(const StandardTitleBar);
|
||||
return d->titleLabelVisible();
|
||||
}
|
||||
|
||||
void StandardTitleBar::setTitleLabelVisible(const bool value)
|
||||
{
|
||||
Q_D(StandardTitleBar);
|
||||
d->setTitleLabelVisible(value);
|
||||
}
|
||||
|
||||
void StandardTitleBar::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
Q_D(StandardTitleBar);
|
||||
|
|
Loading…
Reference in New Issue