forked from github_mirror/framelesshelper
Minor tweaks.
Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
c783bc1fe2
commit
f35407ce5c
|
@ -180,30 +180,30 @@ void FramelessHelper::setTitleBarHeight(const int val)
|
||||||
m_titleBarHeight = val;
|
m_titleBarHeight = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QRect> FramelessHelper::getIgnoreAreas(QObject *obj) const
|
QList<QRectF> FramelessHelper::getIgnoreAreas(QObject *obj) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(obj);
|
Q_ASSERT(obj);
|
||||||
return m_ignoreAreas.value(obj);
|
return m_ignoreAreas.value(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FramelessHelper::addIgnoreArea(QObject *obj, const QRect &val)
|
void FramelessHelper::addIgnoreArea(QObject *obj, const QRectF &val)
|
||||||
{
|
{
|
||||||
Q_ASSERT(obj);
|
Q_ASSERT(obj);
|
||||||
QList<QRect> areas = m_ignoreAreas[obj];
|
QList<QRectF> areas = m_ignoreAreas[obj];
|
||||||
areas.append(val);
|
areas.append(val);
|
||||||
m_ignoreAreas[obj] = areas;
|
m_ignoreAreas[obj] = areas;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QRect> FramelessHelper::getDraggableAreas(QObject *obj) const
|
QList<QRectF> FramelessHelper::getDraggableAreas(QObject *obj) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(obj);
|
Q_ASSERT(obj);
|
||||||
return m_draggableAreas.value(obj);
|
return m_draggableAreas.value(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FramelessHelper::addDraggableArea(QObject *obj, const QRect &val)
|
void FramelessHelper::addDraggableArea(QObject *obj, const QRectF &val)
|
||||||
{
|
{
|
||||||
Q_ASSERT(obj);
|
Q_ASSERT(obj);
|
||||||
QList<QRect> areas = m_draggableAreas[obj];
|
QList<QRectF> areas = m_draggableAreas[obj];
|
||||||
areas.append(val);
|
areas.append(val);
|
||||||
m_draggableAreas[obj] = areas;
|
m_draggableAreas[obj] = areas;
|
||||||
}
|
}
|
||||||
|
@ -387,60 +387,62 @@ bool FramelessHelper::eventFilter(QObject *object, QEvent *event)
|
||||||
}
|
}
|
||||||
return Qt::CursorShape::ArrowCursor;
|
return Qt::CursorShape::ArrowCursor;
|
||||||
};
|
};
|
||||||
const auto isInSpecificAreas = [](const int x, const int y, const QList<QRect> &areas) -> bool {
|
const auto isInSpecificAreas = [](const QPointF &mousePos, const QList<QRectF> &areas) -> bool {
|
||||||
if (!areas.isEmpty()) {
|
if (areas.isEmpty()) {
|
||||||
for (auto &&area : qAsConst(areas)) {
|
return false;
|
||||||
if (area.contains(x, y)) {
|
}
|
||||||
return true;
|
for (auto &&area : qAsConst(areas)) {
|
||||||
}
|
if (area.contains(mousePos)) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
const auto isInSpecificObjects =
|
const auto isInSpecificObjects = [](const QPointF &mousePos,
|
||||||
[](const int x, const int y, const QList<QObject *> &objects) -> bool {
|
const QList<QObject *> &objects) -> bool {
|
||||||
if (!objects.isEmpty()) {
|
if (objects.isEmpty()) {
|
||||||
for (auto &&obj : qAsConst(objects)) {
|
return false;
|
||||||
if (!obj) {
|
}
|
||||||
continue;
|
for (auto &&obj : qAsConst(objects)) {
|
||||||
}
|
if (!obj) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
#ifdef QT_WIDGETS_LIB
|
#ifdef QT_WIDGETS_LIB
|
||||||
const auto widget = qobject_cast<QWidget *>(obj);
|
const auto widget = qobject_cast<QWidget *>(obj);
|
||||||
if (widget) {
|
if (widget) {
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||||
const QPointF pos = widget->mapToGlobal(QPointF{0, 0});
|
const QPointF pos = widget->mapToGlobal(QPointF{0, 0});
|
||||||
#else
|
#else
|
||||||
const QPoint pos = widget->mapToGlobal(QPoint{0, 0});
|
const QPoint pos = widget->mapToGlobal(QPoint{0, 0});
|
||||||
#endif
|
#endif
|
||||||
if (QRect(pos.x(), pos.y(), widget->width(), widget->height()).contains(x, y)) {
|
if (QRectF(pos.x(), pos.y(), widget->width(), widget->height()).contains(mousePos)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef QT_QUICK_LIB
|
#ifdef QT_QUICK_LIB
|
||||||
const auto quickItem = qobject_cast<QQuickItem *>(obj);
|
const auto quickItem = qobject_cast<QQuickItem *>(obj);
|
||||||
if (quickItem) {
|
if (quickItem) {
|
||||||
const QPointF pos = quickItem->mapToGlobal({0, 0});
|
const QPointF pos = quickItem->mapToGlobal({0, 0});
|
||||||
if (QRectF(pos.x(), pos.y(), quickItem->width(), quickItem->height())
|
if (QRectF(pos.x(), pos.y(), quickItem->width(), quickItem->height())
|
||||||
.contains(x, y)) {
|
.contains(mousePos)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
const auto isInIgnoreAreas = [this, &isInSpecificAreas](const QPointF &point,
|
const auto isInIgnoreAreas = [this, &isInSpecificAreas](const QPointF &point,
|
||||||
QObject *window) -> bool {
|
QObject *window) -> bool {
|
||||||
Q_ASSERT(window);
|
Q_ASSERT(window);
|
||||||
return isInSpecificAreas(point.x(), point.y(), getIgnoreAreas(window));
|
return isInSpecificAreas(point, getIgnoreAreas(window));
|
||||||
};
|
};
|
||||||
const auto isInIgnoreObjects = [this, &isInSpecificObjects](const QPointF &point,
|
const auto isInIgnoreObjects = [this, &isInSpecificObjects](const QPointF &point,
|
||||||
QObject *window) -> bool {
|
QObject *window) -> bool {
|
||||||
Q_ASSERT(window);
|
Q_ASSERT(window);
|
||||||
#if defined(QT_WIDGETS_LIB) || defined(QT_QUICK_LIB)
|
#if defined(QT_WIDGETS_LIB) || defined(QT_QUICK_LIB)
|
||||||
return isInSpecificObjects(point.x(), point.y(), getIgnoreObjects(window));
|
return isInSpecificObjects(point, getIgnoreObjects(window));
|
||||||
#else
|
#else
|
||||||
Q_UNUSED(point)
|
Q_UNUSED(point)
|
||||||
Q_UNUSED(window)
|
Q_UNUSED(window)
|
||||||
|
@ -451,14 +453,14 @@ bool FramelessHelper::eventFilter(QObject *object, QEvent *event)
|
||||||
QObject *window) -> bool {
|
QObject *window) -> bool {
|
||||||
Q_ASSERT(window);
|
Q_ASSERT(window);
|
||||||
const auto areas = getDraggableAreas(window);
|
const auto areas = getDraggableAreas(window);
|
||||||
return (areas.isEmpty() ? true : isInSpecificAreas(point.x(), point.y(), areas));
|
return (areas.isEmpty() ? true : isInSpecificAreas(point, areas));
|
||||||
};
|
};
|
||||||
const auto isInDraggableObjects = [this, &isInSpecificObjects](const QPointF &point,
|
const auto isInDraggableObjects = [this, &isInSpecificObjects](const QPointF &point,
|
||||||
QObject *window) -> bool {
|
QObject *window) -> bool {
|
||||||
Q_ASSERT(window);
|
Q_ASSERT(window);
|
||||||
#if defined(QT_WIDGETS_LIB) || defined(QT_QUICK_LIB)
|
#if defined(QT_WIDGETS_LIB) || defined(QT_QUICK_LIB)
|
||||||
const auto objs = getDraggableObjects(window);
|
const auto objs = getDraggableObjects(window);
|
||||||
return (objs.isEmpty() ? true : isInSpecificObjects(point.x(), point.y(), objs));
|
return (objs.isEmpty() ? true : isInSpecificObjects(point, objs));
|
||||||
#else
|
#else
|
||||||
Q_UNUSED(point)
|
Q_UNUSED(point)
|
||||||
Q_UNUSED(window)
|
Q_UNUSED(window)
|
||||||
|
@ -498,7 +500,7 @@ bool FramelessHelper::eventFilter(QObject *object, QEvent *event)
|
||||||
Q_ASSERT(object);
|
Q_ASSERT(object);
|
||||||
QWindow *window = getWindowHandle(object);
|
QWindow *window = getWindowHandle(object);
|
||||||
if (window) {
|
if (window) {
|
||||||
const QPointF deltaPoint = globalPoint - m_pOldMousePos;
|
//const QPointF deltaPoint = globalPoint - m_pOldMousePos;
|
||||||
const Qt::Edges edges = getWindowEdges(point, window->width(), window->height());
|
const Qt::Edges edges = getWindowEdges(point, window->width(), window->height());
|
||||||
if (edges == Qt::Edges{}) {
|
if (edges == Qt::Edges{}) {
|
||||||
if (isInTitlebarArea(globalPoint, point, object)) {
|
if (isInTitlebarArea(globalPoint, point, object)) {
|
||||||
|
@ -605,8 +607,14 @@ bool FramelessHelper::eventFilter(QObject *object, QEvent *event)
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case QEvent::MouseButtonRelease: {
|
case QEvent::MouseButtonRelease: {
|
||||||
m_bIsMRBPressed = false;
|
const auto mouseEvent = static_cast<QMouseEvent *>(event);
|
||||||
m_pOldMousePos = {};
|
if (mouseEvent) {
|
||||||
|
if (mouseEvent->button() != Qt::MouseButton::LeftButton) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
m_bIsMRBPressed = false;
|
||||||
|
m_pOldMousePos = {};
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
case QEvent::TouchBegin:
|
case QEvent::TouchBegin:
|
||||||
case QEvent::TouchUpdate: {
|
case QEvent::TouchUpdate: {
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QRect>
|
#include <QRectF>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
QT_FORWARD_DECLARE_CLASS(QWindow)
|
QT_FORWARD_DECLARE_CLASS(QWindow)
|
||||||
|
@ -58,11 +58,11 @@ public:
|
||||||
int getTitleBarHeight() const;
|
int getTitleBarHeight() const;
|
||||||
void setTitleBarHeight(const int val);
|
void setTitleBarHeight(const int val);
|
||||||
|
|
||||||
void addIgnoreArea(QObject *obj, const QRect &val);
|
void addIgnoreArea(QObject *obj, const QRectF &val);
|
||||||
QList<QRect> getIgnoreAreas(QObject *obj) const;
|
QList<QRectF> getIgnoreAreas(QObject *obj) const;
|
||||||
|
|
||||||
void addDraggableArea(QObject *obj, const QRect &val);
|
void addDraggableArea(QObject *obj, const QRectF &val);
|
||||||
QList<QRect> getDraggableAreas(QObject *obj) const;
|
QList<QRectF> getDraggableAreas(QObject *obj) const;
|
||||||
|
|
||||||
void addIgnoreObject(QObject *obj, QObject *val);
|
void addIgnoreObject(QObject *obj, QObject *val);
|
||||||
QList<QObject *> getIgnoreObjects(QObject *obj) const;
|
QList<QObject *> getIgnoreObjects(QObject *obj) const;
|
||||||
|
@ -84,7 +84,7 @@ private:
|
||||||
// the scale factor is 1.0. Don't know how to acquire these values on UNIX
|
// the scale factor is 1.0. Don't know how to acquire these values on UNIX
|
||||||
// platforms through native API.
|
// platforms through native API.
|
||||||
int m_borderWidth = 8, m_borderHeight = 8, m_titleBarHeight = 30;
|
int m_borderWidth = 8, m_borderHeight = 8, m_titleBarHeight = 30;
|
||||||
QHash<QObject *, QList<QRect>> m_ignoreAreas = {}, m_draggableAreas = {};
|
QHash<QObject *, QList<QRectF>> m_ignoreAreas = {}, m_draggableAreas = {};
|
||||||
QHash<QObject *, QList<QObject *>> m_ignoreObjects = {}, m_draggableObjects = {};
|
QHash<QObject *, QList<QObject *>> m_ignoreObjects = {}, m_draggableObjects = {};
|
||||||
QHash<QObject *, bool> m_fixedSize = {}, m_disableTitleBar = {};
|
QHash<QObject *, bool> m_fixedSize = {}, m_disableTitleBar = {};
|
||||||
};
|
};
|
||||||
|
|
|
@ -814,7 +814,7 @@ BOOL IsFullScreen(const HWND handle)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL IsTopLevel(const HWND handle)
|
[[maybe_unused]] BOOL IsTopLevel(const HWND handle)
|
||||||
{
|
{
|
||||||
Q_ASSERT(handle);
|
Q_ASSERT(handle);
|
||||||
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, handle)) {
|
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, handle)) {
|
||||||
|
@ -971,7 +971,7 @@ qreal GetDevicePixelRatioForWindow(const HWND handle)
|
||||||
return GetPreferedNumber(result);
|
return GetPreferedNumber(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
RECT GetFrameSizeForWindow(const HWND handle, const BOOL includingTitleBar = FALSE)
|
[[maybe_unused]] RECT GetFrameSizeForWindow(const HWND handle, const BOOL includingTitleBar = FALSE)
|
||||||
{
|
{
|
||||||
Q_ASSERT(handle);
|
Q_ASSERT(handle);
|
||||||
RECT rect = {0, 0, 0, 0};
|
RECT rect = {0, 0, 0, 0};
|
||||||
|
@ -1161,13 +1161,9 @@ bool displaySystemMenu_internal(const HWND handle, const bool isRtl, const LPARA
|
||||||
const POINT globalMouse{GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
|
const POINT globalMouse{GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
|
||||||
POINT localMouse = globalMouse;
|
POINT localMouse = globalMouse;
|
||||||
WNEF_EXECUTE_WINAPI(ScreenToClient, handle, &localMouse)
|
WNEF_EXECUTE_WINAPI(ScreenToClient, handle, &localMouse)
|
||||||
const int bh
|
|
||||||
= WinNativeEventFilter::getSystemMetric(handle,
|
|
||||||
WinNativeEventFilter::SystemMetric::BorderHeight,
|
|
||||||
true);
|
|
||||||
const int tbh = WinNativeEventFilter::getSystemMetric(
|
const int tbh = WinNativeEventFilter::getSystemMetric(
|
||||||
handle, WinNativeEventFilter::SystemMetric::TitleBarHeight, true);
|
handle, WinNativeEventFilter::SystemMetric::TitleBarHeight, true);
|
||||||
const bool isTitleBar = localMouse.y <= (tbh + bh);
|
const bool isTitleBar = localMouse.y <= tbh;
|
||||||
if (isTitleBar && !IsFullScreen(handle)) {
|
if (isTitleBar && !IsFullScreen(handle)) {
|
||||||
return WinNativeEventFilter::displaySystemMenu(handle,
|
return WinNativeEventFilter::displaySystemMenu(handle,
|
||||||
isRtl,
|
isRtl,
|
||||||
|
@ -1895,7 +1891,7 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
||||||
const int bh = getSystemMetric(msg->hwnd, SystemMetric::BorderHeight, true);
|
const int bh = getSystemMetric(msg->hwnd, SystemMetric::BorderHeight, true);
|
||||||
const int tbh = getSystemMetric(msg->hwnd, SystemMetric::TitleBarHeight, true);
|
const int tbh = getSystemMetric(msg->hwnd, SystemMetric::TitleBarHeight, true);
|
||||||
const bool isTitleBar = (customDrag ? (isInDraggableAreas && isInDraggableObjects)
|
const bool isTitleBar = (customDrag ? (isInDraggableAreas && isInDraggableObjects)
|
||||||
: (localMouse.y() <= (tbh + bh)))
|
: (localMouse.y() <= tbh))
|
||||||
&& isResizePermitted && !data->disableTitleBar;
|
&& isResizePermitted && !data->disableTitleBar;
|
||||||
const bool isTop = (localMouse.y() <= bh) && isResizePermitted;
|
const bool isTop = (localMouse.y() <= bh) && isResizePermitted;
|
||||||
if (shouldHaveWindowFrame()) {
|
if (shouldHaveWindowFrame()) {
|
||||||
|
@ -1948,7 +1944,7 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
||||||
const bool isRight = (localMouse.x() >= (ww - (bw * factor)));
|
const bool isRight = (localMouse.x() >= (ww - (bw * factor)));
|
||||||
const bool fixedSize = data->fixedSize;
|
const bool fixedSize = data->fixedSize;
|
||||||
const auto getBorderValue = [fixedSize](int value) -> int {
|
const auto getBorderValue = [fixedSize](int value) -> int {
|
||||||
// HTBORDER: non-resizeable window border.
|
// HTBORDER: non-resizable window border.
|
||||||
return fixedSize ? HTBORDER : value;
|
return fixedSize ? HTBORDER : value;
|
||||||
};
|
};
|
||||||
if (isTop) {
|
if (isTop) {
|
||||||
|
|
Loading…
Reference in New Issue