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;
|
||||
}
|
||||
|
||||
QList<QRect> FramelessHelper::getIgnoreAreas(QObject *obj) const
|
||||
QList<QRectF> FramelessHelper::getIgnoreAreas(QObject *obj) const
|
||||
{
|
||||
Q_ASSERT(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);
|
||||
QList<QRect> areas = m_ignoreAreas[obj];
|
||||
QList<QRectF> areas = m_ignoreAreas[obj];
|
||||
areas.append(val);
|
||||
m_ignoreAreas[obj] = areas;
|
||||
}
|
||||
|
||||
QList<QRect> FramelessHelper::getDraggableAreas(QObject *obj) const
|
||||
QList<QRectF> FramelessHelper::getDraggableAreas(QObject *obj) const
|
||||
{
|
||||
Q_ASSERT(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);
|
||||
QList<QRect> areas = m_draggableAreas[obj];
|
||||
QList<QRectF> areas = m_draggableAreas[obj];
|
||||
areas.append(val);
|
||||
m_draggableAreas[obj] = areas;
|
||||
}
|
||||
|
@ -387,60 +387,62 @@ bool FramelessHelper::eventFilter(QObject *object, QEvent *event)
|
|||
}
|
||||
return Qt::CursorShape::ArrowCursor;
|
||||
};
|
||||
const auto isInSpecificAreas = [](const int x, const int y, const QList<QRect> &areas) -> bool {
|
||||
if (!areas.isEmpty()) {
|
||||
for (auto &&area : qAsConst(areas)) {
|
||||
if (area.contains(x, y)) {
|
||||
return true;
|
||||
}
|
||||
const auto isInSpecificAreas = [](const QPointF &mousePos, const QList<QRectF> &areas) -> bool {
|
||||
if (areas.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
for (auto &&area : qAsConst(areas)) {
|
||||
if (area.contains(mousePos)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
const auto isInSpecificObjects =
|
||||
[](const int x, const int y, const QList<QObject *> &objects) -> bool {
|
||||
if (!objects.isEmpty()) {
|
||||
for (auto &&obj : qAsConst(objects)) {
|
||||
if (!obj) {
|
||||
continue;
|
||||
}
|
||||
const auto isInSpecificObjects = [](const QPointF &mousePos,
|
||||
const QList<QObject *> &objects) -> bool {
|
||||
if (objects.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
for (auto &&obj : qAsConst(objects)) {
|
||||
if (!obj) {
|
||||
continue;
|
||||
}
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
const auto widget = qobject_cast<QWidget *>(obj);
|
||||
if (widget) {
|
||||
const auto widget = qobject_cast<QWidget *>(obj);
|
||||
if (widget) {
|
||||
#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
|
||||
const QPoint pos = widget->mapToGlobal(QPoint{0, 0});
|
||||
const QPoint pos = widget->mapToGlobal(QPoint{0, 0});
|
||||
#endif
|
||||
if (QRect(pos.x(), pos.y(), widget->width(), widget->height()).contains(x, y)) {
|
||||
return true;
|
||||
}
|
||||
if (QRectF(pos.x(), pos.y(), widget->width(), widget->height()).contains(mousePos)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef QT_QUICK_LIB
|
||||
const auto quickItem = qobject_cast<QQuickItem *>(obj);
|
||||
if (quickItem) {
|
||||
const QPointF pos = quickItem->mapToGlobal({0, 0});
|
||||
if (QRectF(pos.x(), pos.y(), quickItem->width(), quickItem->height())
|
||||
.contains(x, y)) {
|
||||
return true;
|
||||
}
|
||||
const auto quickItem = qobject_cast<QQuickItem *>(obj);
|
||||
if (quickItem) {
|
||||
const QPointF pos = quickItem->mapToGlobal({0, 0});
|
||||
if (QRectF(pos.x(), pos.y(), quickItem->width(), quickItem->height())
|
||||
.contains(mousePos)) {
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
};
|
||||
const auto isInIgnoreAreas = [this, &isInSpecificAreas](const QPointF &point,
|
||||
QObject *window) -> bool {
|
||||
Q_ASSERT(window);
|
||||
return isInSpecificAreas(point.x(), point.y(), getIgnoreAreas(window));
|
||||
return isInSpecificAreas(point, getIgnoreAreas(window));
|
||||
};
|
||||
const auto isInIgnoreObjects = [this, &isInSpecificObjects](const QPointF &point,
|
||||
QObject *window) -> bool {
|
||||
Q_ASSERT(window);
|
||||
#if defined(QT_WIDGETS_LIB) || defined(QT_QUICK_LIB)
|
||||
return isInSpecificObjects(point.x(), point.y(), getIgnoreObjects(window));
|
||||
return isInSpecificObjects(point, getIgnoreObjects(window));
|
||||
#else
|
||||
Q_UNUSED(point)
|
||||
Q_UNUSED(window)
|
||||
|
@ -451,14 +453,14 @@ bool FramelessHelper::eventFilter(QObject *object, QEvent *event)
|
|||
QObject *window) -> bool {
|
||||
Q_ASSERT(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,
|
||||
QObject *window) -> bool {
|
||||
Q_ASSERT(window);
|
||||
#if defined(QT_WIDGETS_LIB) || defined(QT_QUICK_LIB)
|
||||
const auto objs = getDraggableObjects(window);
|
||||
return (objs.isEmpty() ? true : isInSpecificObjects(point.x(), point.y(), objs));
|
||||
return (objs.isEmpty() ? true : isInSpecificObjects(point, objs));
|
||||
#else
|
||||
Q_UNUSED(point)
|
||||
Q_UNUSED(window)
|
||||
|
@ -498,7 +500,7 @@ bool FramelessHelper::eventFilter(QObject *object, QEvent *event)
|
|||
Q_ASSERT(object);
|
||||
QWindow *window = getWindowHandle(object);
|
||||
if (window) {
|
||||
const QPointF deltaPoint = globalPoint - m_pOldMousePos;
|
||||
//const QPointF deltaPoint = globalPoint - m_pOldMousePos;
|
||||
const Qt::Edges edges = getWindowEdges(point, window->width(), window->height());
|
||||
if (edges == Qt::Edges{}) {
|
||||
if (isInTitlebarArea(globalPoint, point, object)) {
|
||||
|
@ -605,8 +607,14 @@ bool FramelessHelper::eventFilter(QObject *object, QEvent *event)
|
|||
}
|
||||
} break;
|
||||
case QEvent::MouseButtonRelease: {
|
||||
m_bIsMRBPressed = false;
|
||||
m_pOldMousePos = {};
|
||||
const auto mouseEvent = static_cast<QMouseEvent *>(event);
|
||||
if (mouseEvent) {
|
||||
if (mouseEvent->button() != Qt::MouseButton::LeftButton) {
|
||||
break;
|
||||
}
|
||||
m_bIsMRBPressed = false;
|
||||
m_pOldMousePos = {};
|
||||
}
|
||||
} break;
|
||||
case QEvent::TouchBegin:
|
||||
case QEvent::TouchUpdate: {
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
|
||||
#include <QHash>
|
||||
#include <QObject>
|
||||
#include <QRect>
|
||||
#include <QRectF>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
QT_FORWARD_DECLARE_CLASS(QWindow)
|
||||
|
@ -58,11 +58,11 @@ public:
|
|||
int getTitleBarHeight() const;
|
||||
void setTitleBarHeight(const int val);
|
||||
|
||||
void addIgnoreArea(QObject *obj, const QRect &val);
|
||||
QList<QRect> getIgnoreAreas(QObject *obj) const;
|
||||
void addIgnoreArea(QObject *obj, const QRectF &val);
|
||||
QList<QRectF> getIgnoreAreas(QObject *obj) const;
|
||||
|
||||
void addDraggableArea(QObject *obj, const QRect &val);
|
||||
QList<QRect> getDraggableAreas(QObject *obj) const;
|
||||
void addDraggableArea(QObject *obj, const QRectF &val);
|
||||
QList<QRectF> getDraggableAreas(QObject *obj) const;
|
||||
|
||||
void addIgnoreObject(QObject *obj, QObject *val);
|
||||
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
|
||||
// platforms through native API.
|
||||
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 *, bool> m_fixedSize = {}, m_disableTitleBar = {};
|
||||
};
|
||||
|
|
|
@ -814,7 +814,7 @@ BOOL IsFullScreen(const HWND handle)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL IsTopLevel(const HWND handle)
|
||||
[[maybe_unused]] BOOL IsTopLevel(const HWND handle)
|
||||
{
|
||||
Q_ASSERT(handle);
|
||||
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, handle)) {
|
||||
|
@ -971,7 +971,7 @@ qreal GetDevicePixelRatioForWindow(const HWND handle)
|
|||
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);
|
||||
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)};
|
||||
POINT localMouse = globalMouse;
|
||||
WNEF_EXECUTE_WINAPI(ScreenToClient, handle, &localMouse)
|
||||
const int bh
|
||||
= WinNativeEventFilter::getSystemMetric(handle,
|
||||
WinNativeEventFilter::SystemMetric::BorderHeight,
|
||||
true);
|
||||
const int tbh = WinNativeEventFilter::getSystemMetric(
|
||||
handle, WinNativeEventFilter::SystemMetric::TitleBarHeight, true);
|
||||
const bool isTitleBar = localMouse.y <= (tbh + bh);
|
||||
const bool isTitleBar = localMouse.y <= tbh;
|
||||
if (isTitleBar && !IsFullScreen(handle)) {
|
||||
return WinNativeEventFilter::displaySystemMenu(handle,
|
||||
isRtl,
|
||||
|
@ -1895,7 +1891,7 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
|||
const int bh = getSystemMetric(msg->hwnd, SystemMetric::BorderHeight, true);
|
||||
const int tbh = getSystemMetric(msg->hwnd, SystemMetric::TitleBarHeight, true);
|
||||
const bool isTitleBar = (customDrag ? (isInDraggableAreas && isInDraggableObjects)
|
||||
: (localMouse.y() <= (tbh + bh)))
|
||||
: (localMouse.y() <= tbh))
|
||||
&& isResizePermitted && !data->disableTitleBar;
|
||||
const bool isTop = (localMouse.y() <= bh) && isResizePermitted;
|
||||
if (shouldHaveWindowFrame()) {
|
||||
|
@ -1948,7 +1944,7 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
|||
const bool isRight = (localMouse.x() >= (ww - (bw * factor)));
|
||||
const bool fixedSize = data->fixedSize;
|
||||
const auto getBorderValue = [fixedSize](int value) -> int {
|
||||
// HTBORDER: non-resizeable window border.
|
||||
// HTBORDER: non-resizable window border.
|
||||
return fixedSize ? HTBORDER : value;
|
||||
};
|
||||
if (isTop) {
|
||||
|
|
Loading…
Reference in New Issue