Minor tweaks
Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
6698033a1a
commit
2b6d0fccb6
|
@ -26,6 +26,8 @@
|
||||||
#include <QtGui/qpainter.h>
|
#include <QtGui/qpainter.h>
|
||||||
#include "../../framelesswindowsmanager.h"
|
#include "../../framelesswindowsmanager.h"
|
||||||
|
|
||||||
|
FRAMELESSHELPER_USE_NAMESPACE
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, flags)
|
MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, flags)
|
||||||
{
|
{
|
||||||
setAttribute(Qt::WA_DontCreateNativeAncestors);
|
setAttribute(Qt::WA_DontCreateNativeAncestors);
|
||||||
|
|
|
@ -60,7 +60,7 @@ int main(int argc, char *argv[])
|
||||||
QQuickStyle::setStyle(QStringLiteral("Default"));
|
QQuickStyle::setStyle(QStringLiteral("Default"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
qmlRegisterType<FramelessQuickHelper>("wangwenx190.Utils", 1, 0, "FramelessHelper");
|
qmlRegisterType<FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickHelper)>("wangwenx190.Utils", 1, 0, "FramelessHelper");
|
||||||
|
|
||||||
const QUrl mainQmlUrl(QStringLiteral("qrc:///qml/main.qml"));
|
const QUrl mainQmlUrl(QStringLiteral("qrc:///qml/main.qml"));
|
||||||
const QMetaObject::Connection connection = QObject::connect(
|
const QMetaObject::Connection connection = QObject::connect(
|
||||||
|
|
|
@ -32,6 +32,8 @@
|
||||||
#include "../../utilities.h"
|
#include "../../utilities.h"
|
||||||
#include "../../framelesswindowsmanager.h"
|
#include "../../framelesswindowsmanager.h"
|
||||||
|
|
||||||
|
FRAMELESSHELPER_USE_NAMESPACE
|
||||||
|
|
||||||
Widget::Widget(QWidget *parent) : QWidget(parent)
|
Widget::Widget(QWidget *parent) : QWidget(parent)
|
||||||
{
|
{
|
||||||
setAttribute(Qt::WA_DontCreateNativeAncestors);
|
setAttribute(Qt::WA_DontCreateNativeAncestors);
|
||||||
|
@ -112,8 +114,8 @@ void Widget::paintEvent(QPaintEvent *event)
|
||||||
void Widget::setupUi()
|
void Widget::setupUi()
|
||||||
{
|
{
|
||||||
const QWindow *win = windowHandle();
|
const QWindow *win = windowHandle();
|
||||||
const int resizeBorderHeight = Utilities::getSystemMetric(win, Utilities::SystemMetric::ResizeBorderHeight, false);
|
const int resizeBorderHeight = Utilities::getSystemMetric(win, SystemMetric::ResizeBorderHeight, false);
|
||||||
const int titleBarHeight = Utilities::getSystemMetric(win, Utilities::SystemMetric::TitleBarHeight, false);
|
const int titleBarHeight = Utilities::getSystemMetric(win, SystemMetric::TitleBarHeight, false);
|
||||||
const int systemButtonHeight = titleBarHeight + resizeBorderHeight;
|
const int systemButtonHeight = titleBarHeight + resizeBorderHeight;
|
||||||
const QSize systemButtonSize = {qRound(static_cast<qreal>(systemButtonHeight) * 1.5), systemButtonHeight};
|
const QSize systemButtonSize = {qRound(static_cast<qreal>(systemButtonHeight) * 1.5), systemButtonHeight};
|
||||||
m_minimizeButton = new QPushButton(this);
|
m_minimizeButton = new QPushButton(this);
|
||||||
|
|
|
@ -25,12 +25,15 @@
|
||||||
#include "framelesshelper.h"
|
#include "framelesshelper.h"
|
||||||
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
|
||||||
|
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
#include "framelesswindowsmanager.h"
|
#include "framelesswindowsmanager.h"
|
||||||
#include <QtCore/qdebug.h>
|
#include <QtCore/qdebug.h>
|
||||||
#include <QtGui/qevent.h>
|
#include <QtGui/qevent.h>
|
||||||
#include <QtGui/qwindow.h>
|
#include <QtGui/qwindow.h>
|
||||||
|
|
||||||
|
FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||||
|
|
||||||
FramelessHelper::FramelessHelper(QObject *parent) : QObject(parent) {}
|
FramelessHelper::FramelessHelper(QObject *parent) : QObject(parent) {}
|
||||||
|
|
||||||
void FramelessHelper::removeWindowFrame(QWindow *window)
|
void FramelessHelper::removeWindowFrame(QWindow *window)
|
||||||
|
@ -41,7 +44,7 @@ void FramelessHelper::removeWindowFrame(QWindow *window)
|
||||||
}
|
}
|
||||||
window->setFlags(window->flags() | Qt::FramelessWindowHint);
|
window->setFlags(window->flags() | Qt::FramelessWindowHint);
|
||||||
window->installEventFilter(this);
|
window->installEventFilter(this);
|
||||||
window->setProperty(_flh_global::_flh_framelessEnabled_flag, true);
|
window->setProperty(Constants::framelessMode_flag, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FramelessHelper::bringBackWindowFrame(QWindow *window)
|
void FramelessHelper::bringBackWindowFrame(QWindow *window)
|
||||||
|
@ -52,7 +55,7 @@ void FramelessHelper::bringBackWindowFrame(QWindow *window)
|
||||||
}
|
}
|
||||||
window->removeEventFilter(this);
|
window->removeEventFilter(this);
|
||||||
window->setFlags(window->flags() & ~Qt::FramelessWindowHint);
|
window->setFlags(window->flags() & ~Qt::FramelessWindowHint);
|
||||||
window->setProperty(_flh_global::_flh_framelessEnabled_flag, false);
|
window->setProperty(Constants::framelessMode_flag, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FramelessHelper::eventFilter(QObject *object, QEvent *event)
|
bool FramelessHelper::eventFilter(QObject *object, QEvent *event)
|
||||||
|
@ -166,4 +169,7 @@ bool FramelessHelper::eventFilter(QObject *object, QEvent *event)
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FRAMELESSHELPER_END_NAMESPACE
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -27,12 +27,15 @@
|
||||||
#include "framelesshelper_global.h"
|
#include "framelesshelper_global.h"
|
||||||
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
|
||||||
|
|
||||||
#include <QtCore/qobject.h>
|
#include <QtCore/qobject.h>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
QT_FORWARD_DECLARE_CLASS(QWindow)
|
QT_FORWARD_DECLARE_CLASS(QWindow)
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||||
|
|
||||||
class FRAMELESSHELPER_API FramelessHelper : public QObject
|
class FRAMELESSHELPER_API FramelessHelper : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -48,4 +51,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
bool eventFilter(QObject *object, QEvent *event) override;
|
bool eventFilter(QObject *object, QEvent *event) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
FRAMELESSHELPER_END_NAMESPACE
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -63,17 +63,41 @@
|
||||||
#define Q_NODISCARD
|
#define Q_NODISCARD
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace _flh_global
|
#ifndef FRAMELESSHELPER_NAMESPACE
|
||||||
|
#define FRAMELESSHELPER_NAMESPACE __flh_ns
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||||
|
#define FRAMELESSHELPER_BEGIN_NAMESPACE namespace FRAMELESSHELPER_NAMESPACE {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FRAMELESSHELPER_END_NAMESPACE
|
||||||
|
#define FRAMELESSHELPER_END_NAMESPACE }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FRAMELESSHELPER_USE_NAMESPACE
|
||||||
|
#define FRAMELESSHELPER_USE_NAMESPACE using namespace FRAMELESSHELPER_NAMESPACE;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FRAMELESSHELPER_PREPEND_NAMESPACE
|
||||||
|
#define FRAMELESSHELPER_PREPEND_NAMESPACE(X) ::FRAMELESSHELPER_NAMESPACE::X
|
||||||
|
#endif
|
||||||
|
|
||||||
|
FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
namespace Constants
|
||||||
{
|
{
|
||||||
|
|
||||||
[[maybe_unused]] const char _flh_framelessEnabled_flag[] = "_FRAMELESSHELPER_FRAMELESS_MODE_ENABLED";
|
[[maybe_unused]] const char framelessMode_flag[] = "_FRAMELESSHELPER_FRAMELESS_MODE";
|
||||||
[[maybe_unused]] const char _flh_resizeBorderWidth_flag[] = "_FRAMELESSHELPER_WINDOW_RESIZE_BORDER_WIDTH";
|
[[maybe_unused]] const char resizeBorderWidth_flag[] = "_FRAMELESSHELPER_RESIZE_BORDER_WIDTH";
|
||||||
[[maybe_unused]] const char _flh_resizeBorderHeight_flag[] = "_FRAMELESSHELPER_WINDOW_RESIZE_BORDER_HEIGHT";
|
[[maybe_unused]] const char resizeBorderHeight_flag[] = "_FRAMELESSHELPER_RESIZE_BORDER_HEIGHT";
|
||||||
[[maybe_unused]] const char _flh_titleBarHeight_flag[] = "_FRAMELESSHELPER_WINDOW_TITLE_BAR_HEIGHT";
|
[[maybe_unused]] const char titleBarHeight_flag[] = "_FRAMELESSHELPER_TITLE_BAR_HEIGHT";
|
||||||
[[maybe_unused]] const char _flh_hitTestVisibleInChrome_flag[] = "_FRAMELESSHELPER_HIT_TEST_VISIBLE_IN_CHROME";
|
[[maybe_unused]] const char hitTestVisibleInChrome_flag[] = "_FRAMELESSHELPER_HIT_TEST_VISIBLE_IN_CHROME";
|
||||||
[[maybe_unused]] const char _flh_useNativeTitleBar_flag[] = "_FRAMELESSHELPER_USE_NATIVE_TITLE_BAR";
|
[[maybe_unused]] const char useNativeTitleBar_flag[] = "_FRAMELESSHELPER_USE_NATIVE_TITLE_BAR";
|
||||||
[[maybe_unused]] const char _flh_preserveNativeFrame_flag[] = "_FRAMELESSHELPER_PRESERVE_NATIVE_WINDOW_FRAME";
|
[[maybe_unused]] const char preserveNativeFrame_flag[] = "_FRAMELESSHELPER_PRESERVE_NATIVE_WINDOW_FRAME";
|
||||||
[[maybe_unused]] const char _flh_forcePreserveNativeFrame_flag[] = "_FRAMELESSHELPER_FORCE_PRESERVE_NATIVE_WINDOW_FRAME";
|
[[maybe_unused]] const char forcePreserveNativeFrame_flag[] = "_FRAMELESSHELPER_FORCE_PRESERVE_NATIVE_WINDOW_FRAME";
|
||||||
[[maybe_unused]] const char _flh_windowFixedSize_flag[] = "_FRAMELESSHELPER_WINDOW_FIXED_SIZE";
|
[[maybe_unused]] const char windowFixedSize_flag[] = "_FRAMELESSHELPER_WINDOW_FIXED_SIZE";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FRAMELESSHELPER_END_NAMESPACE
|
||||||
|
|
|
@ -48,24 +48,26 @@
|
||||||
|
|
||||||
#ifndef IsMinimized
|
#ifndef IsMinimized
|
||||||
// Only available since Windows 2000
|
// Only available since Windows 2000
|
||||||
#define IsMinimized(h) IsIconic(h)
|
#define IsMinimized(window) IsIconic(window)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef IsMaximized
|
#ifndef IsMaximized
|
||||||
// Only available since Windows 2000
|
// Only available since Windows 2000
|
||||||
#define IsMaximized(h) IsZoomed(h)
|
#define IsMaximized(window) IsZoomed(window)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef GET_X_LPARAM
|
#ifndef GET_X_LPARAM
|
||||||
// Only available since Windows 2000
|
// Only available since Windows 2000
|
||||||
#define GET_X_LPARAM(lp) ((int) (short) LOWORD(lp))
|
#define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef GET_Y_LPARAM
|
#ifndef GET_Y_LPARAM
|
||||||
// Only available since Windows 2000
|
// Only available since Windows 2000
|
||||||
#define GET_Y_LPARAM(lp) ((int) (short) HIWORD(lp))
|
#define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||||
|
|
||||||
[[nodiscard]] static inline bool shouldHaveWindowFrame()
|
[[nodiscard]] static inline bool shouldHaveWindowFrame()
|
||||||
{
|
{
|
||||||
if (Utilities::shouldUseNativeTitleBar()) {
|
if (Utilities::shouldUseNativeTitleBar()) {
|
||||||
|
@ -73,8 +75,8 @@
|
||||||
// want to use the native title bar.
|
// want to use the native title bar.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const bool should = qEnvironmentVariableIsSet(_flh_global::_flh_preserveNativeFrame_flag);
|
const bool should = qEnvironmentVariableIsSet(Constants::preserveNativeFrame_flag);
|
||||||
const bool force = qEnvironmentVariableIsSet(_flh_global::_flh_forcePreserveNativeFrame_flag);
|
const bool force = qEnvironmentVariableIsSet(Constants::forcePreserveNativeFrame_flag);
|
||||||
if (should || force) {
|
if (should || force) {
|
||||||
if (force) {
|
if (force) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -112,7 +114,7 @@ static inline void installHelper(QWindow *window, const bool enable)
|
||||||
const WId winId = window->winId();
|
const WId winId = window->winId();
|
||||||
Utilities::updateFrameMargins(winId, !enable);
|
Utilities::updateFrameMargins(winId, !enable);
|
||||||
Utilities::triggerFrameChange(winId);
|
Utilities::triggerFrameChange(winId);
|
||||||
window->setProperty(_flh_global::_flh_framelessEnabled_flag, enable);
|
window->setProperty(Constants::framelessMode_flag, enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
FramelessHelperWin::FramelessHelperWin() = default;
|
FramelessHelperWin::FramelessHelperWin() = default;
|
||||||
|
@ -164,7 +166,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const QWindow *window = Utilities::findWindow(reinterpret_cast<WId>(msg->hwnd));
|
const QWindow *window = Utilities::findWindow(reinterpret_cast<WId>(msg->hwnd));
|
||||||
if (!window || !window->property(_flh_global::_flh_framelessEnabled_flag).toBool()) {
|
if (!window || !window->property(Constants::framelessMode_flag).toBool()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
switch (msg->message) {
|
switch (msg->message) {
|
||||||
|
@ -254,7 +256,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
|
||||||
// applies the default frame.
|
// applies the default frame.
|
||||||
const LONG originalTop = clientRect->top;
|
const LONG originalTop = clientRect->top;
|
||||||
// Apply the default frame
|
// Apply the default frame
|
||||||
const LRESULT ret = DefWindowProcW(msg->hwnd, WM_NCCALCSIZE, msg->wParam, msg->lParam);
|
const LRESULT ret = DefWindowProcW(msg->hwnd, msg->message, msg->wParam, msg->lParam);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
*result = ret;
|
*result = ret;
|
||||||
return true;
|
return true;
|
||||||
|
@ -274,11 +276,11 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
|
||||||
// The value of border width and border height should be
|
// The value of border width and border height should be
|
||||||
// identical in most cases, when the scale factor is 1.0, it
|
// identical in most cases, when the scale factor is 1.0, it
|
||||||
// should be eight pixels.
|
// should be eight pixels.
|
||||||
const int rbh = getSystemMetric(window, Utilities::SystemMetric::ResizeBorderHeight, true);
|
const int rbh = Utilities::getSystemMetric(window, SystemMetric::ResizeBorderHeight, true);
|
||||||
clientRect->top += rbh;
|
clientRect->top += rbh;
|
||||||
if (!shouldHaveWindowFrame()) {
|
if (!shouldHaveWindowFrame()) {
|
||||||
clientRect->bottom -= rbh;
|
clientRect->bottom -= rbh;
|
||||||
const int rbw = getSystemMetric(window, Utilities::SystemMetric::ResizeBorderWidth, true);
|
const int rbw = Utilities::getSystemMetric(window, SystemMetric::ResizeBorderWidth, true);
|
||||||
clientRect->left += rbw;
|
clientRect->left += rbw;
|
||||||
clientRect->right -= rbw;
|
clientRect->right -= rbw;
|
||||||
}
|
}
|
||||||
|
@ -522,9 +524,9 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
|
||||||
RECT clientRect = {0, 0, 0, 0};
|
RECT clientRect = {0, 0, 0, 0};
|
||||||
GetClientRect(msg->hwnd, &clientRect);
|
GetClientRect(msg->hwnd, &clientRect);
|
||||||
const LONG ww = clientRect.right;
|
const LONG ww = clientRect.right;
|
||||||
const int rbw = getSystemMetric(window, Utilities::SystemMetric::ResizeBorderWidth, true);
|
const int rbw = Utilities::getSystemMetric(window, SystemMetric::ResizeBorderWidth, true);
|
||||||
const int rbh = getSystemMetric(window, Utilities::SystemMetric::ResizeBorderHeight, true);
|
const int rbh = Utilities::getSystemMetric(window, SystemMetric::ResizeBorderHeight, true);
|
||||||
const int tbh = getSystemMetric(window, Utilities::SystemMetric::TitleBarHeight, true);
|
const int tbh = Utilities::getSystemMetric(window, SystemMetric::TitleBarHeight, true);
|
||||||
const bool isTitleBar = (localMouse.y() > rbh) && (localMouse.y() <= (rbh + tbh))
|
const bool isTitleBar = (localMouse.y() > rbh) && (localMouse.y() <= (rbh + tbh))
|
||||||
&& (localMouse.x() > rbw) && (localMouse.y() < (ww - rbw))
|
&& (localMouse.x() > rbw) && (localMouse.y() < (ww - rbw))
|
||||||
&& !Utilities::isHitTestVisibleInChrome(window);
|
&& !Utilities::isHitTestVisibleInChrome(window);
|
||||||
|
@ -532,7 +534,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
|
||||||
if (shouldHaveWindowFrame()) {
|
if (shouldHaveWindowFrame()) {
|
||||||
// This will handle the left, right and bottom parts of the frame
|
// This will handle the left, right and bottom parts of the frame
|
||||||
// because we didn't change them.
|
// because we didn't change them.
|
||||||
const LRESULT originalRet = DefWindowProcW(msg->hwnd, WM_NCHITTEST, msg->wParam, msg->lParam);
|
const LRESULT originalRet = DefWindowProcW(msg->hwnd, msg->message, msg->wParam, msg->lParam);
|
||||||
if (originalRet != HTCLIENT) {
|
if (originalRet != HTCLIENT) {
|
||||||
*result = originalRet;
|
*result = originalRet;
|
||||||
return true;
|
return true;
|
||||||
|
@ -615,10 +617,11 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
|
||||||
// Prevent Windows from drawing the default title bar by temporarily
|
// Prevent Windows from drawing the default title bar by temporarily
|
||||||
// toggling the WS_VISIBLE style.
|
// toggling the WS_VISIBLE style.
|
||||||
SetWindowLongPtrW(msg->hwnd, GWL_STYLE, oldStyle & ~WS_VISIBLE);
|
SetWindowLongPtrW(msg->hwnd, GWL_STYLE, oldStyle & ~WS_VISIBLE);
|
||||||
Utilities::triggerFrameChange(reinterpret_cast<WId>(msg->hwnd));
|
const WId winId = window->winId();
|
||||||
|
Utilities::triggerFrameChange(winId);
|
||||||
const LRESULT ret = DefWindowProcW(msg->hwnd, msg->message, msg->wParam, msg->lParam);
|
const LRESULT ret = DefWindowProcW(msg->hwnd, msg->message, msg->wParam, msg->lParam);
|
||||||
SetWindowLongPtrW(msg->hwnd, GWL_STYLE, oldStyle);
|
SetWindowLongPtrW(msg->hwnd, GWL_STYLE, oldStyle);
|
||||||
Utilities::triggerFrameChange(reinterpret_cast<WId>(msg->hwnd));
|
Utilities::triggerFrameChange(winId);
|
||||||
*result = ret;
|
*result = ret;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -627,3 +630,5 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FRAMELESSHELPER_END_NAMESPACE
|
||||||
|
|
|
@ -32,6 +32,8 @@ QT_BEGIN_NAMESPACE
|
||||||
QT_FORWARD_DECLARE_CLASS(QWindow)
|
QT_FORWARD_DECLARE_CLASS(QWindow)
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||||
|
|
||||||
class FRAMELESSHELPER_API FramelessHelperWin : public QAbstractNativeEventFilter
|
class FRAMELESSHELPER_API FramelessHelperWin : public QAbstractNativeEventFilter
|
||||||
{
|
{
|
||||||
Q_DISABLE_COPY_MOVE(FramelessHelperWin)
|
Q_DISABLE_COPY_MOVE(FramelessHelperWin)
|
||||||
|
@ -49,3 +51,5 @@ public:
|
||||||
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override;
|
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
FRAMELESSHELPER_END_NAMESPACE
|
||||||
|
|
|
@ -26,6 +26,8 @@
|
||||||
#include "framelesswindowsmanager.h"
|
#include "framelesswindowsmanager.h"
|
||||||
#include <QtQuick/qquickwindow.h>
|
#include <QtQuick/qquickwindow.h>
|
||||||
|
|
||||||
|
FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||||
|
|
||||||
FramelessQuickHelper::FramelessQuickHelper(QQuickItem *parent) : QQuickItem(parent)
|
FramelessQuickHelper::FramelessQuickHelper(QQuickItem *parent) : QQuickItem(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -97,3 +99,5 @@ void FramelessQuickHelper::setHitTestVisibleInChrome(QQuickItem *item, const boo
|
||||||
}
|
}
|
||||||
FramelessWindowsManager::setHitTestVisibleInChrome(window(), item, visible);
|
FramelessWindowsManager::setHitTestVisibleInChrome(window(), item, visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FRAMELESSHELPER_END_NAMESPACE
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
#include "framelesshelper_global.h"
|
#include "framelesshelper_global.h"
|
||||||
#include <QtQuick/qquickitem.h>
|
#include <QtQuick/qquickitem.h>
|
||||||
|
|
||||||
|
FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||||
|
|
||||||
class FRAMELESSHELPER_API FramelessQuickHelper : public QQuickItem
|
class FRAMELESSHELPER_API FramelessQuickHelper : public QQuickItem
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -67,3 +69,5 @@ Q_SIGNALS:
|
||||||
void titleBarHeightChanged(qreal);
|
void titleBarHeightChanged(qreal);
|
||||||
void resizableChanged(bool);
|
void resizableChanged(bool);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
FRAMELESSHELPER_END_NAMESPACE
|
||||||
|
|
|
@ -35,6 +35,8 @@
|
||||||
#include "framelesshelper_win32.h"
|
#include "framelesshelper_win32.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||||
|
|
||||||
#ifdef FRAMELESSHELPER_USE_UNIX_VERSION
|
#ifdef FRAMELESSHELPER_USE_UNIX_VERSION
|
||||||
Q_GLOBAL_STATIC(FramelessHelper, framelessHelperUnix)
|
Q_GLOBAL_STATIC(FramelessHelper, framelessHelperUnix)
|
||||||
#endif
|
#endif
|
||||||
|
@ -71,7 +73,7 @@ void FramelessWindowsManager::setHitTestVisibleInChrome(QWindow *window, QObject
|
||||||
qWarning() << object << "is not a QWidget or QQuickItem.";
|
qWarning() << object << "is not a QWidget or QQuickItem.";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto objList = qvariant_cast<QObjectList>(window->property(_flh_global::_flh_hitTestVisibleInChrome_flag));
|
auto objList = qvariant_cast<QObjectList>(window->property(Constants::hitTestVisibleInChrome_flag));
|
||||||
if (value) {
|
if (value) {
|
||||||
if (objList.isEmpty() || !objList.contains(object)) {
|
if (objList.isEmpty() || !objList.contains(object)) {
|
||||||
objList.append(object);
|
objList.append(object);
|
||||||
|
@ -81,7 +83,7 @@ void FramelessWindowsManager::setHitTestVisibleInChrome(QWindow *window, QObject
|
||||||
objList.removeAll(object);
|
objList.removeAll(object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
window->setProperty(_flh_global::_flh_hitTestVisibleInChrome_flag, QVariant::fromValue(objList));
|
window->setProperty(Constants::hitTestVisibleInChrome_flag, QVariant::fromValue(objList));
|
||||||
}
|
}
|
||||||
|
|
||||||
int FramelessWindowsManager::getResizeBorderWidth(const QWindow *window)
|
int FramelessWindowsManager::getResizeBorderWidth(const QWindow *window)
|
||||||
|
@ -91,10 +93,10 @@ int FramelessWindowsManager::getResizeBorderWidth(const QWindow *window)
|
||||||
return 8;
|
return 8;
|
||||||
}
|
}
|
||||||
#ifdef FRAMELESSHELPER_USE_UNIX_VERSION
|
#ifdef FRAMELESSHELPER_USE_UNIX_VERSION
|
||||||
const int value = window->property(_flh_global::_flh_resizeBorderWidth_flag).toInt();
|
const int value = window->property(Constants::resizeBorderWidth_flag).toInt();
|
||||||
return value <= 0 ? 8 : value;
|
return value <= 0 ? 8 : value;
|
||||||
#else
|
#else
|
||||||
return Utilities::getSystemMetric(window, Utilities::SystemMetric::ResizeBorderWidth, false);
|
return Utilities::getSystemMetric(window, SystemMetric::ResizeBorderWidth, false);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +106,7 @@ void FramelessWindowsManager::setResizeBorderWidth(QWindow *window, const int va
|
||||||
if (!window || (value <= 0)) {
|
if (!window || (value <= 0)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
window->setProperty(_flh_global::_flh_resizeBorderWidth_flag, value);
|
window->setProperty(Constants::resizeBorderWidth_flag, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
int FramelessWindowsManager::getResizeBorderHeight(const QWindow *window)
|
int FramelessWindowsManager::getResizeBorderHeight(const QWindow *window)
|
||||||
|
@ -114,10 +116,10 @@ int FramelessWindowsManager::getResizeBorderHeight(const QWindow *window)
|
||||||
return 8;
|
return 8;
|
||||||
}
|
}
|
||||||
#ifdef FRAMELESSHELPER_USE_UNIX_VERSION
|
#ifdef FRAMELESSHELPER_USE_UNIX_VERSION
|
||||||
const int value = window->property(_flh_global::_flh_resizeBorderHeight_flag).toInt();
|
const int value = window->property(Constants::resizeBorderHeight_flag).toInt();
|
||||||
return value <= 0 ? 8 : value;
|
return value <= 0 ? 8 : value;
|
||||||
#else
|
#else
|
||||||
return Utilities::getSystemMetric(window, Utilities::SystemMetric::ResizeBorderHeight, false);
|
return Utilities::getSystemMetric(window, SystemMetric::ResizeBorderHeight, false);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +129,7 @@ void FramelessWindowsManager::setResizeBorderHeight(QWindow *window, const int v
|
||||||
if (!window || (value <= 0)) {
|
if (!window || (value <= 0)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
window->setProperty(_flh_global::_flh_resizeBorderHeight_flag, value);
|
window->setProperty(Constants::resizeBorderHeight_flag, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
int FramelessWindowsManager::getTitleBarHeight(const QWindow *window)
|
int FramelessWindowsManager::getTitleBarHeight(const QWindow *window)
|
||||||
|
@ -137,10 +139,10 @@ int FramelessWindowsManager::getTitleBarHeight(const QWindow *window)
|
||||||
return 23;
|
return 23;
|
||||||
}
|
}
|
||||||
#ifdef FRAMELESSHELPER_USE_UNIX_VERSION
|
#ifdef FRAMELESSHELPER_USE_UNIX_VERSION
|
||||||
const int value = window->property(_flh_global::_flh_titleBarHeight_flag).toInt();
|
const int value = window->property(Constants::titleBarHeight_flag).toInt();
|
||||||
return value <= 0 ? 23 : value;
|
return value <= 0 ? 23 : value;
|
||||||
#else
|
#else
|
||||||
return Utilities::getSystemMetric(window, Utilities::SystemMetric::TitleBarHeight, false);
|
return Utilities::getSystemMetric(window, SystemMetric::TitleBarHeight, false);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +152,7 @@ void FramelessWindowsManager::setTitleBarHeight(QWindow *window, const int value
|
||||||
if (!window || (value <= 0)) {
|
if (!window || (value <= 0)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
window->setProperty(_flh_global::_flh_titleBarHeight_flag, value);
|
window->setProperty(Constants::titleBarHeight_flag, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FramelessWindowsManager::getResizable(const QWindow *window)
|
bool FramelessWindowsManager::getResizable(const QWindow *window)
|
||||||
|
@ -160,7 +162,7 @@ bool FramelessWindowsManager::getResizable(const QWindow *window)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#ifdef FRAMELESSHELPER_USE_UNIX_VERSION
|
#ifdef FRAMELESSHELPER_USE_UNIX_VERSION
|
||||||
return !window->property(_flh_global::_flh_windowFixedSize_flag).toBool();
|
return !window->property(Constants::windowFixedSize_flag).toBool();
|
||||||
#else
|
#else
|
||||||
return !Utilities::isWindowFixedSize(window);
|
return !Utilities::isWindowFixedSize(window);
|
||||||
#endif
|
#endif
|
||||||
|
@ -173,7 +175,7 @@ void FramelessWindowsManager::setResizable(QWindow *window, const bool value)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#ifdef FRAMELESSHELPER_USE_UNIX_VERSION
|
#ifdef FRAMELESSHELPER_USE_UNIX_VERSION
|
||||||
window->setProperty(_flh_global::_flh_windowFixedSize_flag, !value);
|
window->setProperty(Constants::windowFixedSize_flag, !value);
|
||||||
#else
|
#else
|
||||||
window->setFlag(Qt::MSWindowsFixedSizeDialogHint, !value);
|
window->setFlag(Qt::MSWindowsFixedSizeDialogHint, !value);
|
||||||
#endif
|
#endif
|
||||||
|
@ -198,5 +200,7 @@ bool FramelessWindowsManager::isWindowFrameless(const QWindow *window)
|
||||||
if (!window) {
|
if (!window) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return window->property(_flh_global::_flh_framelessEnabled_flag).toBool();
|
return window->property(Constants::framelessMode_flag).toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FRAMELESSHELPER_END_NAMESPACE
|
||||||
|
|
|
@ -31,6 +31,8 @@ QT_FORWARD_DECLARE_CLASS(QObject)
|
||||||
QT_FORWARD_DECLARE_CLASS(QWindow)
|
QT_FORWARD_DECLARE_CLASS(QWindow)
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||||
|
|
||||||
namespace FramelessWindowsManager
|
namespace FramelessWindowsManager
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -48,3 +50,5 @@ FRAMELESSHELPER_API void setTitleBarHeight(QWindow *window, const int value);
|
||||||
FRAMELESSHELPER_API void setResizable(QWindow *window, const bool value = true);
|
FRAMELESSHELPER_API void setResizable(QWindow *window, const bool value = true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FRAMELESSHELPER_END_NAMESPACE
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
#include <QtGui/qguiapplication.h>
|
#include <QtGui/qguiapplication.h>
|
||||||
#include <QtGui/qscreen.h>
|
#include <QtGui/qscreen.h>
|
||||||
|
|
||||||
|
FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||||
|
|
||||||
QWindow *Utilities::findWindow(const WId winId)
|
QWindow *Utilities::findWindow(const WId winId)
|
||||||
{
|
{
|
||||||
Q_ASSERT(winId);
|
Q_ASSERT(winId);
|
||||||
|
@ -47,7 +49,7 @@ QWindow *Utilities::findWindow(const WId winId)
|
||||||
|
|
||||||
bool Utilities::shouldUseNativeTitleBar()
|
bool Utilities::shouldUseNativeTitleBar()
|
||||||
{
|
{
|
||||||
return qEnvironmentVariableIsSet(_flh_global::_flh_useNativeTitleBar_flag);
|
return qEnvironmentVariableIsSet(Constants::useNativeTitleBar_flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Utilities::isWindowFixedSize(const QWindow *window)
|
bool Utilities::isWindowFixedSize(const QWindow *window)
|
||||||
|
@ -84,7 +86,7 @@ bool Utilities::isHitTestVisibleInChrome(const QWindow *window)
|
||||||
if (!window) {
|
if (!window) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const auto objs = qvariant_cast<QObjectList>(window->property(_flh_global::_flh_hitTestVisibleInChrome_flag));
|
const auto objs = qvariant_cast<QObjectList>(window->property(Constants::hitTestVisibleInChrome_flag));
|
||||||
if (objs.isEmpty()) {
|
if (objs.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -126,3 +128,5 @@ QPointF Utilities::mapOriginPointToWindow(const QObject *object)
|
||||||
}
|
}
|
||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FRAMELESSHELPER_END_NAMESPACE
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#include "framelesshelper_global.h"
|
#include "framelesshelper_global.h"
|
||||||
#include <QtGui/qwindow.h>
|
#include <QtGui/qwindow.h>
|
||||||
|
|
||||||
namespace Utilities {
|
FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||||
|
|
||||||
enum class SystemMetric
|
enum class SystemMetric
|
||||||
{
|
{
|
||||||
|
@ -36,6 +36,9 @@ enum class SystemMetric
|
||||||
TitleBarHeight
|
TitleBarHeight
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace Utilities
|
||||||
|
{
|
||||||
|
|
||||||
[[nodiscard]] FRAMELESSHELPER_API int getSystemMetric(const QWindow *window, const SystemMetric metric, const bool dpiScale, const bool forceSystemValue = false);
|
[[nodiscard]] FRAMELESSHELPER_API int getSystemMetric(const QWindow *window, const SystemMetric metric, const bool dpiScale, const bool forceSystemValue = false);
|
||||||
[[nodiscard]] FRAMELESSHELPER_API QWindow *findWindow(const WId winId);
|
[[nodiscard]] FRAMELESSHELPER_API QWindow *findWindow(const WId winId);
|
||||||
[[nodiscard]] FRAMELESSHELPER_API bool shouldUseNativeTitleBar();
|
[[nodiscard]] FRAMELESSHELPER_API bool shouldUseNativeTitleBar();
|
||||||
|
@ -55,3 +58,5 @@ FRAMELESSHELPER_API void updateQtFrameMargins(QWindow *window, const bool enable
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FRAMELESSHELPER_END_NAMESPACE
|
||||||
|
|
|
@ -46,6 +46,8 @@ Q_DECLARE_METATYPE(QMargins)
|
||||||
#define SM_CXPADDEDBORDER 92
|
#define SM_CXPADDEDBORDER 92
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||||
|
|
||||||
// The standard values of resize border width, resize border height and title bar height when DPI is 96.
|
// The standard values of resize border width, resize border height and title bar height when DPI is 96.
|
||||||
static const int g_defaultResizeBorderWidth = 8, g_defaultResizeBorderHeight = 8, g_defaultTitleBarHeight = 23;
|
static const int g_defaultResizeBorderWidth = 8, g_defaultResizeBorderHeight = 8, g_defaultTitleBarHeight = 23;
|
||||||
|
|
||||||
|
@ -71,7 +73,7 @@ int Utilities::getSystemMetric(const QWindow *window, const SystemMetric metric,
|
||||||
}
|
}
|
||||||
switch (metric) {
|
switch (metric) {
|
||||||
case SystemMetric::ResizeBorderWidth: {
|
case SystemMetric::ResizeBorderWidth: {
|
||||||
const int rbw = window->property(_flh_global::_flh_resizeBorderWidth_flag).toInt();
|
const int rbw = window->property(Constants::resizeBorderWidth_flag).toInt();
|
||||||
if ((rbw > 0) && !forceSystemValue) {
|
if ((rbw > 0) && !forceSystemValue) {
|
||||||
return qRound(static_cast<qreal>(rbw) * (dpiScale ? window->devicePixelRatio() : 1.0));
|
return qRound(static_cast<qreal>(rbw) * (dpiScale ? window->devicePixelRatio() : 1.0));
|
||||||
} else {
|
} else {
|
||||||
|
@ -92,7 +94,7 @@ int Utilities::getSystemMetric(const QWindow *window, const SystemMetric metric,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case SystemMetric::ResizeBorderHeight: {
|
case SystemMetric::ResizeBorderHeight: {
|
||||||
const int rbh = window->property(_flh_global::_flh_resizeBorderHeight_flag).toInt();
|
const int rbh = window->property(Constants::resizeBorderHeight_flag).toInt();
|
||||||
if ((rbh > 0) && !forceSystemValue) {
|
if ((rbh > 0) && !forceSystemValue) {
|
||||||
return qRound(static_cast<qreal>(rbh) * (dpiScale ? window->devicePixelRatio() : 1.0));
|
return qRound(static_cast<qreal>(rbh) * (dpiScale ? window->devicePixelRatio() : 1.0));
|
||||||
} else {
|
} else {
|
||||||
|
@ -114,7 +116,7 @@ int Utilities::getSystemMetric(const QWindow *window, const SystemMetric metric,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case SystemMetric::TitleBarHeight: {
|
case SystemMetric::TitleBarHeight: {
|
||||||
const int tbh = window->property(_flh_global::_flh_titleBarHeight_flag).toInt();
|
const int tbh = window->property(Constants::titleBarHeight_flag).toInt();
|
||||||
if ((tbh > 0) && !forceSystemValue) {
|
if ((tbh > 0) && !forceSystemValue) {
|
||||||
return qRound(static_cast<qreal>(tbh) * (dpiScale ? window->devicePixelRatio() : 1.0));
|
return qRound(static_cast<qreal>(tbh) * (dpiScale ? window->devicePixelRatio() : 1.0));
|
||||||
} else {
|
} else {
|
||||||
|
@ -174,9 +176,9 @@ void Utilities::updateQtFrameMargins(QWindow *window, const bool enable)
|
||||||
if (!window) {
|
if (!window) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const int tbh = enable ? Utilities::getSystemMetric(window, Utilities::SystemMetric::TitleBarHeight, true, true) : 0;
|
const int tbh = enable ? Utilities::getSystemMetric(window, SystemMetric::TitleBarHeight, true, true) : 0;
|
||||||
const int rbw = enable ? Utilities::getSystemMetric(window, Utilities::SystemMetric::ResizeBorderWidth, true, true) : 0;
|
const int rbw = enable ? Utilities::getSystemMetric(window, SystemMetric::ResizeBorderWidth, true, true) : 0;
|
||||||
const int rbh = enable ? Utilities::getSystemMetric(window, Utilities::SystemMetric::ResizeBorderHeight, true, true) : 0;
|
const int rbh = enable ? Utilities::getSystemMetric(window, SystemMetric::ResizeBorderHeight, true, true) : 0;
|
||||||
const QMargins margins = {-rbw, -(rbh + tbh), -rbw, -rbh}; // left, top, right, bottom
|
const QMargins margins = {-rbw, -(rbh + tbh), -rbw, -rbh}; // left, top, right, bottom
|
||||||
const QVariant marginsVar = QVariant::fromValue(margins);
|
const QVariant marginsVar = QVariant::fromValue(margins);
|
||||||
window->setProperty("_q_windowsCustomMargins", marginsVar);
|
window->setProperty("_q_windowsCustomMargins", marginsVar);
|
||||||
|
@ -220,3 +222,5 @@ bool Utilities::isWin10OrGreater()
|
||||||
return QSysInfo::WindowsVersion >= QSysInfo::WV_WINDOWS10;
|
return QSysInfo::WindowsVersion >= QSysInfo::WV_WINDOWS10;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FRAMELESSHELPER_END_NAMESPACE
|
||||||
|
|
Loading…
Reference in New Issue