forked from github_mirror/framelesshelper
misc: improve old Qt version support
Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
701d8d0927
commit
130d174dc2
|
@ -48,6 +48,7 @@
|
|||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QDebug>
|
||||
#include <QApplication>
|
||||
#include <QSurfaceFormat>
|
||||
#include <QOpenGLContext>
|
||||
|
|
|
@ -192,9 +192,8 @@ FRAMELESSHELPER_STRING_CONSTANT2(UsePureQtImplKeyPath, "Options/UsePureQtImpleme
|
|||
FRAMELESSHELPER_STRING_CONSTANT2(ForceHideFrameBorderKeyPath, "Options/ForceHideFrameBorder")
|
||||
FRAMELESSHELPER_STRING_CONSTANT2(ForceShowFrameBorderKeyPath, "Options/ForceShowFrameBorder")
|
||||
|
||||
enum class Option : int
|
||||
enum class Option
|
||||
{
|
||||
Default = 0x00000000, // Default placeholder, have no effect.
|
||||
ForceHideWindowFrameBorder = 0x00000001, // Windows only, force hide the window frame border even on Windows 10 and onwards.
|
||||
ForceShowWindowFrameBorder = 0x00000002, // Windows only, force show the window frame border even on Windows 7 (~ 8.1).
|
||||
DontDrawTopWindowFrameBorder = 0x00000004, // Windows only, don't draw the top window frame border even if the window frame border is visible.
|
||||
|
@ -224,7 +223,7 @@ Q_DECLARE_FLAGS(Options, Option)
|
|||
Q_FLAG_NS(Options)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(Options)
|
||||
|
||||
enum class SystemTheme : int
|
||||
enum class SystemTheme
|
||||
{
|
||||
Unknown = -1,
|
||||
Light = 0,
|
||||
|
@ -233,7 +232,7 @@ enum class SystemTheme : int
|
|||
};
|
||||
Q_ENUM_NS(SystemTheme)
|
||||
|
||||
enum class SystemButtonType : int
|
||||
enum class SystemButtonType
|
||||
{
|
||||
Unknown = -1,
|
||||
WindowIcon = 0,
|
||||
|
@ -245,7 +244,7 @@ enum class SystemButtonType : int
|
|||
};
|
||||
Q_ENUM_NS(SystemButtonType)
|
||||
|
||||
enum class ResourceType : int
|
||||
enum class ResourceType
|
||||
{
|
||||
Image = 0,
|
||||
Pixmap = 1,
|
||||
|
@ -253,7 +252,7 @@ enum class ResourceType : int
|
|||
};
|
||||
Q_ENUM_NS(ResourceType)
|
||||
|
||||
enum class DwmColorizationArea : int
|
||||
enum class DwmColorizationArea
|
||||
{
|
||||
None_ = 0, // Avoid name conflicts with X11 headers.
|
||||
StartMenu_TaskBar_ActionCenter = 1,
|
||||
|
@ -262,7 +261,7 @@ enum class DwmColorizationArea : int
|
|||
};
|
||||
Q_ENUM_NS(DwmColorizationArea)
|
||||
|
||||
enum class Anchor : int
|
||||
enum class Anchor
|
||||
{
|
||||
Top = 0,
|
||||
Bottom = 1,
|
||||
|
@ -274,7 +273,7 @@ enum class Anchor : int
|
|||
};
|
||||
Q_ENUM_NS(Anchor)
|
||||
|
||||
enum class ButtonState : int
|
||||
enum class ButtonState
|
||||
{
|
||||
Unspecified = -1,
|
||||
Hovered = 0,
|
||||
|
|
|
@ -25,6 +25,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <framelesshelpercore_global.h>
|
||||
#if __has_include(<QtQml/qqmlregistration.h>)
|
||||
#include <QtQml/qqmlregistration.h>
|
||||
#endif
|
||||
|
||||
#ifndef FRAMELESSHELPER_QUICK_API
|
||||
# ifdef FRAMELESSHELPER_QUICK_STATIC
|
||||
|
@ -38,6 +41,94 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef FRAMELESSHELPER_QUICK_ENUM_VALUE
|
||||
# define FRAMELESSHELPER_QUICK_ENUM_VALUE(Enum, Value) \
|
||||
Value = static_cast<int>(FRAMELESSHELPER_PREPEND_NAMESPACE(Global)::Enum::Value),
|
||||
#endif
|
||||
|
||||
#ifndef FRAMELESSHELPER_ENUM_CORE_TO_QUICK
|
||||
# define FRAMELESSHELPER_ENUM_CORE_TO_QUICK(Enum, Value) \
|
||||
static_cast<FRAMELESSHELPER_PREPEND_NAMESPACE(QuickGlobal)::Enum>(static_cast<int>(Value))
|
||||
#endif
|
||||
|
||||
#ifndef FRAMELESSHELPER_ENUM_QUICK_TO_CORE
|
||||
# define FRAMELESSHELPER_ENUM_QUICK_TO_CORE(Enum, Value) \
|
||||
static_cast<FRAMELESSHELPER_PREPEND_NAMESPACE(Global)::Enum>(static_cast<int>(Value))
|
||||
#endif
|
||||
|
||||
FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||
|
||||
[[maybe_unused]] static constexpr const char FRAMELESSHELPER_QUICK_URI[] = "org.wangwenx190.FramelessHelper";
|
||||
|
||||
struct FRAMELESSHELPER_QUICK_API QuickGlobal
|
||||
{
|
||||
enum class SystemTheme
|
||||
{
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(SystemTheme, Unknown)
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(SystemTheme, Light)
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(SystemTheme, Dark)
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(SystemTheme, HighContrast)
|
||||
};
|
||||
Q_ENUM(SystemTheme)
|
||||
|
||||
enum class SystemButtonType
|
||||
{
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(SystemButtonType, Unknown)
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(SystemButtonType, WindowIcon)
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(SystemButtonType, Help)
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(SystemButtonType, Minimize)
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(SystemButtonType, Maximize)
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(SystemButtonType, Restore)
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(SystemButtonType, Close)
|
||||
};
|
||||
Q_ENUM(SystemButtonType)
|
||||
|
||||
enum class ResourceType
|
||||
{
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(ResourceType, Image)
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(ResourceType, Pixmap)
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(ResourceType, Icon)
|
||||
};
|
||||
Q_ENUM(ResourceType)
|
||||
|
||||
enum class DwmColorizationArea
|
||||
{
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(DwmColorizationArea, None_) // Avoid name conflicts with X11 headers.
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(DwmColorizationArea, StartMenu_TaskBar_ActionCenter)
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(DwmColorizationArea, TitleBar_WindowBorder)
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(DwmColorizationArea, All)
|
||||
};
|
||||
Q_ENUM(DwmColorizationArea)
|
||||
|
||||
enum class Anchor
|
||||
{
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(Anchor, Top)
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(Anchor, Bottom)
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(Anchor, Left)
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(Anchor, Right)
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(Anchor, HorizontalCenter)
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(Anchor, VerticalCenter)
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(Anchor, Center)
|
||||
};
|
||||
Q_ENUM(Anchor)
|
||||
|
||||
enum class ButtonState
|
||||
{
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(ButtonState, Unspecified)
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(ButtonState, Hovered)
|
||||
FRAMELESSHELPER_QUICK_ENUM_VALUE(ButtonState, Pressed)
|
||||
};
|
||||
Q_ENUM(ButtonState)
|
||||
|
||||
private:
|
||||
Q_GADGET
|
||||
#ifdef QML_NAMED_ELEMENT
|
||||
QML_NAMED_ELEMENT(FramelessHelper)
|
||||
#endif
|
||||
#ifdef QML_UNCREATABLE
|
||||
QML_UNCREATABLE("The FramelessHelper namespace is not creatable, you can only use it to access it's enums.")
|
||||
#endif
|
||||
Q_DISABLE_COPY_MOVE(QuickGlobal)
|
||||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
|
|
@ -78,7 +78,7 @@ public:
|
|||
Q_NODISCARD static QColor defaultSystemCloseButtonBackgroundColor();
|
||||
|
||||
Q_NODISCARD Q_INVOKABLE static QColor getSystemButtonBackgroundColor(
|
||||
const Global::SystemButtonType button, const Global::ButtonState state);
|
||||
const QuickGlobal::SystemButtonType button, const QuickGlobal::ButtonState state);
|
||||
|
||||
Q_SIGNALS:
|
||||
void darkModeEnabledChanged();
|
||||
|
|
|
@ -74,7 +74,7 @@ public Q_SLOTS:
|
|||
void setHitTestVisible(QQuickItem *item);
|
||||
void moveToDesktopCenter();
|
||||
void bringToFront();
|
||||
void snapToTopBorder(QQuickItem *item, const Global::Anchor itemAnchor, const Global::Anchor topBorderAnchor);
|
||||
void snapToTopBorder(QQuickItem *item, const QuickGlobal::Anchor itemAnchor, const QuickGlobal::Anchor topBorderAnchor);
|
||||
|
||||
Q_SIGNALS:
|
||||
void hiddenChanged();
|
||||
|
@ -84,7 +84,7 @@ Q_SIGNALS:
|
|||
void fullScreenChanged();
|
||||
void fixedSizeChanged();
|
||||
void frameBorderColorChanged();
|
||||
void systemButtonStateChanged(const Global::SystemButtonType, const Global::ButtonState);
|
||||
void systemButtonStateChanged(const QuickGlobal::SystemButtonType, const QuickGlobal::ButtonState);
|
||||
|
||||
private:
|
||||
QScopedPointer<FramelessQuickWindowPrivate> d_ptr;
|
||||
|
|
|
@ -39,6 +39,7 @@ struct QtHelperData
|
|||
UserSettings settings = {};
|
||||
SystemParameters params = {};
|
||||
FramelessHelperQt *eventFilter = nullptr;
|
||||
bool cursorShapeChanged = false;
|
||||
};
|
||||
|
||||
struct QtHelper
|
||||
|
@ -133,9 +134,17 @@ bool FramelessHelperQt::eventFilter(QObject *object, QEvent *event)
|
|||
}
|
||||
const Qt::CursorShape cs = Utils::calculateCursorShape(window, scenePos);
|
||||
if (cs == Qt::ArrowCursor) {
|
||||
window->unsetCursor();
|
||||
if (data.cursorShapeChanged) {
|
||||
window->unsetCursor();
|
||||
QMutexLocker locker(&g_qtHelper()->mutex);
|
||||
g_qtHelper()->data[windowId].cursorShapeChanged = false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
window->setCursor(cs);
|
||||
QMutexLocker locker(&g_qtHelper()->mutex);
|
||||
g_qtHelper()->data[windowId].cursorShapeChanged = true;
|
||||
}
|
||||
} break;
|
||||
case QEvent::MouseButtonPress: {
|
||||
|
|
|
@ -97,7 +97,7 @@ bool FramelessWindowsManagerPrivate::usePureQtImplementation()
|
|||
if (qEnvironmentVariableIntValue(kUsePureQtImplFlag) != 0) {
|
||||
return true;
|
||||
}
|
||||
const QString iniFilePath = QCoreApplication::applicationDirPath() + u'/' + kConfigFileName;
|
||||
const QString iniFilePath = QCoreApplication::applicationDirPath() + QChar(u'/') + kConfigFileName;
|
||||
QSettings settings(iniFilePath, QSettings::IniFormat);
|
||||
return settings.value(kUsePureQtImplKeyPath, false).toBool();
|
||||
}();
|
||||
|
@ -300,8 +300,6 @@ void FramelessHelper::Core::initialize(const Options options)
|
|||
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Round);
|
||||
}
|
||||
#endif
|
||||
// Mainly for Qt Quick applications, but won't bring any harm to Qt Widgets
|
||||
// applications either.
|
||||
qRegisterMetaType<Option>();
|
||||
qRegisterMetaType<SystemTheme>();
|
||||
qRegisterMetaType<SystemButtonType>();
|
||||
|
@ -311,20 +309,6 @@ void FramelessHelper::Core::initialize(const Options options)
|
|||
qRegisterMetaType<ButtonState>();
|
||||
qRegisterMetaType<UserSettings>();
|
||||
qRegisterMetaType<SystemParameters>();
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
// Only needed by Qt5 Quick applications, it's hard to say whether it's a
|
||||
// bug or a lack of features. The QML engine is having a hard time to find
|
||||
// the correct type if the type has a long namespace with a deep hierarchy.
|
||||
qRegisterMetaType<Option>("Global::Option");
|
||||
qRegisterMetaType<SystemTheme>("Global::SystemTheme");
|
||||
qRegisterMetaType<SystemButtonType>("Global::SystemButtonType");
|
||||
qRegisterMetaType<ResourceType>("Global::ResourceType");
|
||||
qRegisterMetaType<DwmColorizationArea>("Global::DwmColorizationArea");
|
||||
qRegisterMetaType<Anchor>("Global::Anchor");
|
||||
qRegisterMetaType<ButtonState>("Global::ButtonState");
|
||||
qRegisterMetaType<UserSettings>("Global::UserSettings");
|
||||
qRegisterMetaType<SystemParameters>("Global::SystemParameters");
|
||||
#endif
|
||||
}
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
|
|
@ -38,17 +38,13 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "qwinregistry_p.h"
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0))
|
||||
|
||||
#include <QtCore/qvarlengtharray.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
QWinRegistryKey::QWinRegistryKey() :
|
||||
m_key(nullptr)
|
||||
QWinRegistryKey::QWinRegistryKey()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -57,8 +53,8 @@ QWinRegistryKey::QWinRegistryKey() :
|
|||
QWinRegistryKey::QWinRegistryKey(HKEY parentHandle, QStringView subKey,
|
||||
REGSAM permissions, REGSAM access)
|
||||
{
|
||||
if (RegOpenKeyEx(parentHandle, reinterpret_cast<const wchar_t *>(subKey.utf16()),
|
||||
0, permissions | access, &m_key) != ERROR_SUCCESS) {
|
||||
if (RegOpenKeyExW(parentHandle, qUtf16Printable(subKey), 0,
|
||||
permissions | access, &m_key) != ERROR_SUCCESS) {
|
||||
m_key = nullptr;
|
||||
}
|
||||
}
|
||||
|
@ -78,14 +74,14 @@ void QWinRegistryKey::close()
|
|||
|
||||
QString QWinRegistryKey::stringValue(QStringView subKey) const
|
||||
{
|
||||
QString result;
|
||||
if (!isValid())
|
||||
QString result = {};
|
||||
if (!isValid()) {
|
||||
return result;
|
||||
DWORD type;
|
||||
DWORD size;
|
||||
auto subKeyC = reinterpret_cast<const wchar_t *>(subKey.utf16());
|
||||
if (RegQueryValueEx(m_key, subKeyC, nullptr, &type, nullptr, &size) != ERROR_SUCCESS
|
||||
|| (type != REG_SZ && type != REG_EXPAND_SZ) || size <= 2) {
|
||||
}
|
||||
DWORD type = 0;
|
||||
DWORD size = 0;
|
||||
if ((RegQueryValueExW(m_key, qUtf16Printable(subKey), nullptr, &type, nullptr, &size) != ERROR_SUCCESS)
|
||||
|| ((type != REG_SZ) && (type != REG_EXPAND_SZ)) || (size <= 2)) {
|
||||
return result;
|
||||
}
|
||||
// Reserve more for rare cases where trailing '\0' are missing in registry.
|
||||
|
@ -94,25 +90,26 @@ QString QWinRegistryKey::stringValue(QStringView subKey) const
|
|||
size += 2;
|
||||
QVarLengthArray<unsigned char> buffer(static_cast<int>(size));
|
||||
std::fill(buffer.data(), buffer.data() + size, 0u);
|
||||
if (RegQueryValueEx(m_key, subKeyC, nullptr, &type, buffer.data(), &size) == ERROR_SUCCESS)
|
||||
result = QString::fromWCharArray(reinterpret_cast<const wchar_t *>(buffer.constData()));
|
||||
if (RegQueryValueExW(m_key, qUtf16Printable(subKey), nullptr, &type, buffer.data(), &size) == ERROR_SUCCESS) {
|
||||
result = QString::fromWCharArray(reinterpret_cast<const wchar_t *>(buffer.constData()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QPair<DWORD, bool> QWinRegistryKey::dwordValue(QStringView subKey) const
|
||||
{
|
||||
if (!isValid())
|
||||
if (!isValid()) {
|
||||
return qMakePair(0, false);
|
||||
DWORD type;
|
||||
auto subKeyC = reinterpret_cast<const wchar_t *>(subKey.utf16());
|
||||
if (RegQueryValueEx(m_key, subKeyC, nullptr, &type, nullptr, nullptr) != ERROR_SUCCESS
|
||||
|| type != REG_DWORD) {
|
||||
}
|
||||
DWORD type = 0;
|
||||
if ((RegQueryValueExW(m_key, qUtf16Printable(subKey), nullptr, &type, nullptr, nullptr) != ERROR_SUCCESS)
|
||||
|| (type != REG_DWORD)) {
|
||||
return qMakePair(0, false);
|
||||
}
|
||||
DWORD value = 0;
|
||||
DWORD size = sizeof(value);
|
||||
const bool ok =
|
||||
RegQueryValueEx(m_key, subKeyC, nullptr, nullptr,
|
||||
RegQueryValueExW(m_key, qUtf16Printable(subKey), nullptr, nullptr,
|
||||
reinterpret_cast<unsigned char *>(&value), &size) == ERROR_SUCCESS;
|
||||
return qMakePair(value, ok);
|
||||
}
|
||||
|
|
|
@ -62,9 +62,9 @@ QT_BEGIN_NAMESPACE
|
|||
|
||||
class FRAMELESSHELPER_CORE_API QWinRegistryKey
|
||||
{
|
||||
public:
|
||||
Q_DISABLE_COPY(QWinRegistryKey)
|
||||
|
||||
public:
|
||||
QWinRegistryKey();
|
||||
explicit QWinRegistryKey(HKEY parentHandle, QStringView subKey,
|
||||
REGSAM permissions = KEY_READ, REGSAM access = 0);
|
||||
|
@ -79,15 +79,15 @@ public:
|
|||
}
|
||||
void swap(QWinRegistryKey &other) noexcept { std::swap(m_key, other.m_key); }
|
||||
|
||||
bool isValid() const { return m_key != nullptr; }
|
||||
operator HKEY() const { return m_key; }
|
||||
[[nodiscard]] bool isValid() const { return m_key != nullptr; }
|
||||
[[nodiscard]] operator HKEY() const { return m_key; }
|
||||
void close();
|
||||
|
||||
QString stringValue(QStringView subKey) const;
|
||||
QPair<DWORD, bool> dwordValue(QStringView subKey) const;
|
||||
[[nodiscard]] QString stringValue(QStringView subKey) const;
|
||||
[[nodiscard]] QPair<DWORD, bool> dwordValue(QStringView subKey) const;
|
||||
|
||||
private:
|
||||
HKEY m_key;
|
||||
HKEY m_key = nullptr;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
@ -1029,7 +1029,7 @@ bool Utils::isWindowFrameBorderVisible()
|
|||
if (qEnvironmentVariableIntValue(kForceHideFrameBorderFlag) != 0) {
|
||||
return false;
|
||||
}
|
||||
const QString iniFilePath = QCoreApplication::applicationDirPath() + u'/' + kConfigFileName;
|
||||
const QString iniFilePath = QCoreApplication::applicationDirPath() + QChar(u'/') + kConfigFileName;
|
||||
QSettings settings(iniFilePath, QSettings::IniFormat);
|
||||
if (settings.value(kForceShowFrameBorderKeyPath, false).toBool()) {
|
||||
return true;
|
||||
|
|
|
@ -22,8 +22,10 @@
|
|||
SOFTWARE.
|
||||
]]
|
||||
|
||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS QuickTemplates2)
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS QuickTemplates2)
|
||||
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS QuickTemplates2)
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS QuickTemplates2)
|
||||
endif()
|
||||
|
||||
set(SUB_PROJ_NAME FramelessHelperQuick)
|
||||
|
||||
|
@ -101,9 +103,14 @@ endif()
|
|||
|
||||
target_link_libraries(${SUB_PROJ_NAME} PRIVATE
|
||||
Qt${QT_VERSION_MAJOR}::QuickPrivate
|
||||
Qt${QT_VERSION_MAJOR}::QuickTemplates2Private
|
||||
)
|
||||
|
||||
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
||||
target_link_libraries(${SUB_PROJ_NAME} PRIVATE
|
||||
Qt${QT_VERSION_MAJOR}::QuickTemplates2Private
|
||||
)
|
||||
endif()
|
||||
|
||||
target_link_libraries(${SUB_PROJ_NAME} PUBLIC
|
||||
FramelessHelperCore
|
||||
)
|
||||
|
|
|
@ -52,10 +52,19 @@ void FramelessHelper::Quick::registerTypes(QQmlEngine *engine)
|
|||
if (!engine) {
|
||||
return;
|
||||
}
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
qmlRegisterUncreatableMetaObject(Global::staticMetaObject, QUICK_URI_EXPAND("FramelessHelper"),
|
||||
FRAMELESSHELPER_STRING_LITERAL("The FramelessHelper namespace is not creatable, you can only use it to access its enums."));
|
||||
#endif
|
||||
static bool inited = false;
|
||||
if (inited) {
|
||||
return;
|
||||
}
|
||||
inited = true;
|
||||
qRegisterMetaType<QuickGlobal::SystemTheme>();
|
||||
qRegisterMetaType<QuickGlobal::SystemButtonType>();
|
||||
qRegisterMetaType<QuickGlobal::ResourceType>();
|
||||
qRegisterMetaType<QuickGlobal::DwmColorizationArea>();
|
||||
qRegisterMetaType<QuickGlobal::Anchor>();
|
||||
qRegisterMetaType<QuickGlobal::ButtonState>();
|
||||
qmlRegisterUncreatableType<QuickGlobal>(QUICK_URI_FULL, "FramelessHelper",
|
||||
FRAMELESSHELPER_STRING_LITERAL("The FramelessHelper namespace is not creatable, you can only use it to access it's enums."));
|
||||
qmlRegisterSingletonType<FramelessQuickUtils>(QUICK_URI_EXPAND("FramelessUtils"),
|
||||
[](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
|
||||
Q_UNUSED(engine);
|
||||
|
@ -71,6 +80,15 @@ void FramelessHelper::Quick::registerTypes(QQmlEngine *engine)
|
|||
qmlRegisterType<QuickStandardMaximizeButton>(QUICK_URI_EXPAND("StandardMaximizeButton"));
|
||||
qmlRegisterType<QuickStandardCloseButton>(QUICK_URI_EXPAND("StandardCloseButton"));
|
||||
qmlRegisterType<QuickStandardTitleBar>(QUICK_URI_EXPAND("StandardTitleBar"));
|
||||
#else // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
qmlRegisterTypeNotAvailable(QUICK_URI_EXPAND("StandardMinimizeButton"),
|
||||
FRAMELESSHELPER_STRING_LITERAL("StandardMinimizeButton is not available until Qt6."));
|
||||
qmlRegisterTypeNotAvailable(QUICK_URI_EXPAND("StandardMaximizeButton"),
|
||||
FRAMELESSHELPER_STRING_LITERAL("StandardMaximizeButton is not available until Qt6."));
|
||||
qmlRegisterTypeNotAvailable(QUICK_URI_EXPAND("StandardCloseButton"),
|
||||
FRAMELESSHELPER_STRING_LITERAL("StandardCloseButton is not available until Qt6."));
|
||||
qmlRegisterTypeNotAvailable(QUICK_URI_EXPAND("StandardTitleBar"),
|
||||
FRAMELESSHELPER_STRING_LITERAL("StandardTitleBar is not available until Qt6."));
|
||||
#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
qmlRegisterModule(QUICK_URI_FULL);
|
||||
}
|
||||
|
|
|
@ -124,9 +124,11 @@ QColor FramelessQuickUtils::defaultSystemCloseButtonBackgroundColor()
|
|||
return kDefaultSystemCloseButtonBackgroundColor;
|
||||
}
|
||||
|
||||
QColor FramelessQuickUtils::getSystemButtonBackgroundColor(const SystemButtonType button, const ButtonState state)
|
||||
QColor FramelessQuickUtils::getSystemButtonBackgroundColor(const QuickGlobal::SystemButtonType button,
|
||||
const QuickGlobal::ButtonState state)
|
||||
{
|
||||
return Utils::calculateSystemButtonBackgroundColor(button, state);
|
||||
return Utils::calculateSystemButtonBackgroundColor(FRAMELESSHELPER_ENUM_QUICK_TO_CORE(SystemButtonType, button),
|
||||
FRAMELESSHELPER_ENUM_QUICK_TO_CORE(ButtonState, state));
|
||||
}
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
|
|
@ -226,7 +226,7 @@ void FramelessQuickWindowPrivate::bringToFront()
|
|||
q->requestActivate();
|
||||
}
|
||||
|
||||
void FramelessQuickWindowPrivate::snapToTopBorder(QQuickItem *item, const Anchor itemAnchor, const Anchor topBorderAnchor)
|
||||
void FramelessQuickWindowPrivate::snapToTopBorder(QQuickItem *item, const QuickGlobal::Anchor itemAnchor, const QuickGlobal::Anchor topBorderAnchor)
|
||||
{
|
||||
Q_ASSERT(item);
|
||||
if (!item) {
|
||||
|
@ -234,17 +234,17 @@ void FramelessQuickWindowPrivate::snapToTopBorder(QQuickItem *item, const Anchor
|
|||
}
|
||||
const QQuickAnchorLine targetAnchorLine = [this, topBorderAnchor]() -> QQuickAnchorLine {
|
||||
switch (topBorderAnchor) {
|
||||
case Anchor::Top:
|
||||
case QuickGlobal::Anchor::Top:
|
||||
return getTopBorderTop();
|
||||
case Anchor::Bottom:
|
||||
case QuickGlobal::Anchor::Bottom:
|
||||
return getTopBorderBottom();
|
||||
case Anchor::Left:
|
||||
case QuickGlobal::Anchor::Left:
|
||||
return getTopBorderLeft();
|
||||
case Anchor::Right:
|
||||
case QuickGlobal::Anchor::Right:
|
||||
return getTopBorderRight();
|
||||
case Anchor::HorizontalCenter:
|
||||
case QuickGlobal::Anchor::HorizontalCenter:
|
||||
return getTopBorderHorizontalCenter();
|
||||
case Anchor::VerticalCenter:
|
||||
case QuickGlobal::Anchor::VerticalCenter:
|
||||
return getTopBorderVerticalCenter();
|
||||
default:
|
||||
break;
|
||||
|
@ -254,25 +254,25 @@ void FramelessQuickWindowPrivate::snapToTopBorder(QQuickItem *item, const Anchor
|
|||
const QQuickItemPrivate * const itemPrivate = QQuickItemPrivate::get(item);
|
||||
QQuickAnchors * const anchors = itemPrivate->anchors();
|
||||
switch (itemAnchor) {
|
||||
case Anchor::Top:
|
||||
case QuickGlobal::Anchor::Top:
|
||||
anchors->setTop(targetAnchorLine);
|
||||
break;
|
||||
case Anchor::Bottom:
|
||||
case QuickGlobal::Anchor::Bottom:
|
||||
anchors->setBottom(targetAnchorLine);
|
||||
break;
|
||||
case Anchor::Left:
|
||||
case QuickGlobal::Anchor::Left:
|
||||
anchors->setLeft(targetAnchorLine);
|
||||
break;
|
||||
case Anchor::Right:
|
||||
case QuickGlobal::Anchor::Right:
|
||||
anchors->setRight(targetAnchorLine);
|
||||
break;
|
||||
case Anchor::HorizontalCenter:
|
||||
case QuickGlobal::Anchor::HorizontalCenter:
|
||||
anchors->setHorizontalCenter(targetAnchorLine);
|
||||
break;
|
||||
case Anchor::VerticalCenter:
|
||||
case QuickGlobal::Anchor::VerticalCenter:
|
||||
anchors->setVerticalCenter(targetAnchorLine);
|
||||
break;
|
||||
case Anchor::Center:
|
||||
case QuickGlobal::Anchor::Center:
|
||||
anchors->setCenterIn(m_topBorderRectangle.data());
|
||||
break;
|
||||
}
|
||||
|
@ -417,7 +417,12 @@ void FramelessQuickWindowPrivate::initialize()
|
|||
m_params.getWindowHandle = [q]() -> QWindow * { return q; };
|
||||
m_params.windowToScreen = [q](const QPoint &pos) -> QPoint { return q->mapToGlobal(pos); };
|
||||
m_params.screenToWindow = [q](const QPoint &pos) -> QPoint { return q->mapFromGlobal(pos); };
|
||||
m_params.isInsideSystemButtons = [this](const QPoint &pos, SystemButtonType *button) -> bool { return isInSystemButtons(pos, button); };
|
||||
m_params.isInsideSystemButtons = [this](const QPoint &pos, SystemButtonType *button) -> bool {
|
||||
QuickGlobal::SystemButtonType button2 = QuickGlobal::SystemButtonType::Unknown;
|
||||
const bool result = isInSystemButtons(pos, &button2);
|
||||
*button = FRAMELESSHELPER_ENUM_QUICK_TO_CORE(SystemButtonType, button2);
|
||||
return result;
|
||||
};
|
||||
m_params.isInsideTitleBarDraggableArea = [this](const QPoint &pos) -> bool { return isInTitleBarDraggableArea(pos); };
|
||||
m_params.getWindowDevicePixelRatio = [q]() -> qreal { return q->effectiveDevicePixelRatio(); };
|
||||
m_params.setSystemButtonState = [q](const SystemButtonType button, const ButtonState state) -> void {
|
||||
|
@ -425,7 +430,8 @@ void FramelessQuickWindowPrivate::initialize()
|
|||
if (button == SystemButtonType::Unknown) {
|
||||
return;
|
||||
}
|
||||
Q_EMIT q->systemButtonStateChanged(button, state);
|
||||
Q_EMIT q->systemButtonStateChanged(FRAMELESSHELPER_ENUM_CORE_TO_QUICK(SystemButtonType, button),
|
||||
FRAMELESSHELPER_ENUM_CORE_TO_QUICK(ButtonState, state));
|
||||
};
|
||||
if (m_settings.options & Option::DisableResizing) {
|
||||
setFixedSize(true, true);
|
||||
|
@ -493,13 +499,13 @@ QRect FramelessQuickWindowPrivate::mapItemGeometryToScene(const QQuickItem * con
|
|||
return QRectF(originPoint, size).toRect();
|
||||
}
|
||||
|
||||
bool FramelessQuickWindowPrivate::isInSystemButtons(const QPoint &pos, SystemButtonType *button) const
|
||||
bool FramelessQuickWindowPrivate::isInSystemButtons(const QPoint &pos, QuickGlobal::SystemButtonType *button) const
|
||||
{
|
||||
Q_ASSERT(button);
|
||||
if (!button) {
|
||||
return false;
|
||||
}
|
||||
*button = SystemButtonType::Unknown;
|
||||
*button = QuickGlobal::SystemButtonType::Unknown;
|
||||
if (!m_settings.windowIconButton && !m_settings.contextHelpButton
|
||||
&& !m_settings.minimizeButton && !m_settings.maximizeButton && !m_settings.closeButton) {
|
||||
return false;
|
||||
|
@ -507,35 +513,35 @@ bool FramelessQuickWindowPrivate::isInSystemButtons(const QPoint &pos, SystemBut
|
|||
if (m_settings.windowIconButton && m_settings.windowIconButton->inherits(QT_QUICKITEM_CLASS_NAME)) {
|
||||
const auto iconBtn = qobject_cast<QQuickItem *>(m_settings.windowIconButton);
|
||||
if (mapItemGeometryToScene(iconBtn).contains(pos)) {
|
||||
*button = SystemButtonType::WindowIcon;
|
||||
*button = QuickGlobal::SystemButtonType::WindowIcon;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (m_settings.contextHelpButton && m_settings.contextHelpButton->inherits(QT_QUICKITEM_CLASS_NAME)) {
|
||||
const auto helpBtn = qobject_cast<QQuickItem *>(m_settings.contextHelpButton);
|
||||
if (mapItemGeometryToScene(helpBtn).contains(pos)) {
|
||||
*button = SystemButtonType::Help;
|
||||
*button = QuickGlobal::SystemButtonType::Help;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (m_settings.minimizeButton && m_settings.minimizeButton->inherits(QT_QUICKITEM_CLASS_NAME)) {
|
||||
const auto minBtn = qobject_cast<QQuickItem *>(m_settings.minimizeButton);
|
||||
if (mapItemGeometryToScene(minBtn).contains(pos)) {
|
||||
*button = SystemButtonType::Minimize;
|
||||
*button = QuickGlobal::SystemButtonType::Minimize;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (m_settings.maximizeButton && m_settings.maximizeButton->inherits(QT_QUICKITEM_CLASS_NAME)) {
|
||||
const auto maxBtn = qobject_cast<QQuickItem *>(m_settings.maximizeButton);
|
||||
if (mapItemGeometryToScene(maxBtn).contains(pos)) {
|
||||
*button = SystemButtonType::Maximize;
|
||||
*button = QuickGlobal::SystemButtonType::Maximize;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (m_settings.closeButton && m_settings.closeButton->inherits(QT_QUICKITEM_CLASS_NAME)) {
|
||||
const auto closeBtn = qobject_cast<QQuickItem *>(m_settings.closeButton);
|
||||
if (mapItemGeometryToScene(closeBtn).contains(pos)) {
|
||||
*button = SystemButtonType::Close;
|
||||
*button = QuickGlobal::SystemButtonType::Close;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -807,7 +813,7 @@ void FramelessQuickWindow::bringToFront()
|
|||
d->bringToFront();
|
||||
}
|
||||
|
||||
void FramelessQuickWindow::snapToTopBorder(QQuickItem *item, const Anchor itemAnchor, const Anchor topBorderAnchor)
|
||||
void FramelessQuickWindow::snapToTopBorder(QQuickItem *item, const QuickGlobal::Anchor itemAnchor, const QuickGlobal::Anchor topBorderAnchor)
|
||||
{
|
||||
Q_ASSERT(item);
|
||||
if (!item) {
|
||||
|
|
|
@ -83,7 +83,7 @@ public Q_SLOTS:
|
|||
void moveToDesktopCenter();
|
||||
void setFixedSize(const bool value, const bool force = false);
|
||||
void bringToFront();
|
||||
void snapToTopBorder(QQuickItem *item, const Global::Anchor itemAnchor, const Global::Anchor topBorderAnchor);
|
||||
void snapToTopBorder(QQuickItem *item, const QuickGlobal::Anchor itemAnchor, const QuickGlobal::Anchor topBorderAnchor);
|
||||
|
||||
protected:
|
||||
Q_NODISCARD bool eventFilter(QObject *object, QEvent *event) override;
|
||||
|
@ -91,7 +91,7 @@ protected:
|
|||
private:
|
||||
void initialize();
|
||||
Q_NODISCARD QRect mapItemGeometryToScene(const QQuickItem * const item) const;
|
||||
Q_NODISCARD bool isInSystemButtons(const QPoint &pos, Global::SystemButtonType *button) const;
|
||||
Q_NODISCARD bool isInSystemButtons(const QPoint &pos, QuickGlobal::SystemButtonType *button) const;
|
||||
Q_NODISCARD bool isInTitleBarDraggableArea(const QPoint &pos) const;
|
||||
Q_NODISCARD bool shouldIgnoreMouseEvents(const QPoint &pos) const;
|
||||
void doStartSystemMove2(QMouseEvent *event);
|
||||
|
|
|
@ -26,8 +26,6 @@
|
|||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
#include <framelesswindowsmanager.h>
|
||||
#include <utils.h>
|
||||
#include <QtGui/qguiapplication.h>
|
||||
#include <QtGui/qstylehints.h>
|
||||
#include <QtQuick/private/qquickimage_p.h>
|
||||
#include <QtQuick/private/qquickrectangle_p.h>
|
||||
#include <QtQuick/private/qquickanchors_p.h>
|
||||
|
@ -70,10 +68,7 @@ void QuickStandardCloseButton::updateBackground()
|
|||
|
||||
void QuickStandardCloseButton::updateToolTip()
|
||||
{
|
||||
const bool visible = (isHovered() && !isPressed());
|
||||
const int delay = QGuiApplication::styleHints()->mousePressAndHoldInterval();
|
||||
m_tooltip->setVisible(visible);
|
||||
m_tooltip->setDelay(delay);
|
||||
m_tooltip->setVisible(isHovered() && !isPressed());
|
||||
}
|
||||
|
||||
void QuickStandardCloseButton::initialize()
|
||||
|
@ -100,10 +95,7 @@ void QuickStandardCloseButton::initialize()
|
|||
|
||||
m_tooltip = qobject_cast<QQuickToolTipAttached *>(qmlAttachedPropertiesObject<QQuickToolTip>(this));
|
||||
m_tooltip->setText(tr("Close"));
|
||||
connect(QGuiApplication::styleHints(), &QStyleHints::mousePressAndHoldIntervalChanged, this, [this](const int interval){
|
||||
Q_UNUSED(interval);
|
||||
updateToolTip();
|
||||
});
|
||||
m_tooltip->setDelay(0);
|
||||
connect(this, &QuickStandardCloseButton::hoveredChanged, this, &QuickStandardCloseButton::updateToolTip);
|
||||
connect(this, &QuickStandardCloseButton::pressedChanged, this, &QuickStandardCloseButton::updateToolTip);
|
||||
|
||||
|
|
|
@ -26,8 +26,6 @@
|
|||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
#include <framelesswindowsmanager.h>
|
||||
#include <utils.h>
|
||||
#include <QtGui/qguiapplication.h>
|
||||
#include <QtGui/qstylehints.h>
|
||||
#include <QtQuick/private/qquickimage_p.h>
|
||||
#include <QtQuick/private/qquickrectangle_p.h>
|
||||
#include <QtQuick/private/qquickanchors_p.h>
|
||||
|
@ -86,12 +84,8 @@ void QuickStandardMaximizeButton::updateBackground()
|
|||
|
||||
void QuickStandardMaximizeButton::updateToolTip()
|
||||
{
|
||||
const bool visible = (isHovered() && !isPressed());
|
||||
const int delay = QGuiApplication::styleHints()->mousePressAndHoldInterval();
|
||||
const QString text = (m_max ? tr("Restore") : tr("Maximize"));
|
||||
m_tooltip->setVisible(visible);
|
||||
m_tooltip->setDelay(delay);
|
||||
m_tooltip->setText(text);
|
||||
m_tooltip->setVisible(isHovered() && !isPressed());
|
||||
m_tooltip->setText(m_max ? tr("Restore") : tr("Maximize"));
|
||||
}
|
||||
|
||||
void QuickStandardMaximizeButton::initialize()
|
||||
|
@ -116,10 +110,7 @@ void QuickStandardMaximizeButton::initialize()
|
|||
connect(this, &QuickStandardMaximizeButton::pressedChanged, this, &QuickStandardMaximizeButton::updateBackground);
|
||||
|
||||
m_tooltip = qobject_cast<QQuickToolTipAttached *>(qmlAttachedPropertiesObject<QQuickToolTip>(this));
|
||||
connect(QGuiApplication::styleHints(), &QStyleHints::mousePressAndHoldIntervalChanged, this, [this](const int interval){
|
||||
Q_UNUSED(interval);
|
||||
updateToolTip();
|
||||
});
|
||||
m_tooltip->setDelay(0);
|
||||
connect(this, &QuickStandardMaximizeButton::hoveredChanged, this, &QuickStandardMaximizeButton::updateToolTip);
|
||||
connect(this, &QuickStandardMaximizeButton::pressedChanged, this, &QuickStandardMaximizeButton::updateToolTip);
|
||||
connect(this, &QuickStandardMaximizeButton::maximizedChanged, this, &QuickStandardMaximizeButton::updateToolTip);
|
||||
|
|
|
@ -26,8 +26,6 @@
|
|||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
#include <framelesswindowsmanager.h>
|
||||
#include <utils.h>
|
||||
#include <QtGui/qguiapplication.h>
|
||||
#include <QtGui/qstylehints.h>
|
||||
#include <QtQuick/private/qquickimage_p.h>
|
||||
#include <QtQuick/private/qquickrectangle_p.h>
|
||||
#include <QtQuick/private/qquickanchors_p.h>
|
||||
|
@ -70,10 +68,7 @@ void QuickStandardMinimizeButton::updateBackground()
|
|||
|
||||
void QuickStandardMinimizeButton::updateToolTip()
|
||||
{
|
||||
const bool visible = (isHovered() && !isPressed());
|
||||
const int delay = QGuiApplication::styleHints()->mousePressAndHoldInterval();
|
||||
m_tooltip->setVisible(visible);
|
||||
m_tooltip->setDelay(delay);
|
||||
m_tooltip->setVisible(isHovered() && !isPressed());
|
||||
}
|
||||
|
||||
void QuickStandardMinimizeButton::initialize()
|
||||
|
@ -98,10 +93,7 @@ void QuickStandardMinimizeButton::initialize()
|
|||
|
||||
m_tooltip = qobject_cast<QQuickToolTipAttached *>(qmlAttachedPropertiesObject<QQuickToolTip>(this));
|
||||
m_tooltip->setText(tr("Minimize"));
|
||||
connect(QGuiApplication::styleHints(), &QStyleHints::mousePressAndHoldIntervalChanged, this, [this](const int interval){
|
||||
Q_UNUSED(interval);
|
||||
updateToolTip();
|
||||
});
|
||||
m_tooltip->setDelay(0);
|
||||
connect(this, &QuickStandardMinimizeButton::hoveredChanged, this, &QuickStandardMinimizeButton::updateToolTip);
|
||||
connect(this, &QuickStandardMinimizeButton::pressedChanged, this, &QuickStandardMinimizeButton::updateToolTip);
|
||||
|
||||
|
|
Loading…
Reference in New Issue