Fix coordinate bug for FramelessHelper too

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2021-03-08 15:17:01 +08:00
parent 70b257adb6
commit 07290f9aeb
1 changed files with 12 additions and 6 deletions

View File

@ -1,7 +1,7 @@
/* /*
* MIT License * MIT License
* *
* Copyright (C) 2020 by wangwenx190 (Yuhang Zhao) * Copyright (C) 2021 by wangwenx190 (Yuhang Zhao)
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -25,11 +25,10 @@
#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 <QDebug> #include <QtCore/qdebug.h>
#include <QEvent> #include <QtCore/qcoreevent.h>
#include <QMouseEvent> #include <QtGui/qevent.h>
#include <QTouchEvent> #include <QtGui/qwindow.h>
#include <QWindow>
FramelessHelper::FramelessHelper(QObject *parent) : QObject(parent) {} FramelessHelper::FramelessHelper(QObject *parent) : QObject(parent) {}
@ -101,6 +100,7 @@ void FramelessHelper::setResizable(const QWindow *window, const bool val)
void FramelessHelper::removeWindowFrame(QWindow *window) void FramelessHelper::removeWindowFrame(QWindow *window)
{ {
Q_ASSERT(window); Q_ASSERT(window);
// TODO: check whether these flags are correct for Linux and macOS.
window->setFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint window->setFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint
| Qt::WindowMinMaxButtonsHint | Qt::WindowTitleHint); | Qt::WindowMinMaxButtonsHint | Qt::WindowTitleHint);
// MouseTracking is always enabled for QWindow. // MouseTracking is always enabled for QWindow.
@ -183,9 +183,15 @@ bool FramelessHelper::eventFilter(QObject *object, QEvent *event)
} }
const auto mapOriginPointToWindow = [](const QObject *obj) -> QPointF { const auto mapOriginPointToWindow = [](const QObject *obj) -> QPointF {
Q_ASSERT(obj); Q_ASSERT(obj);
if (!obj) {
return {};
}
QPointF point = {obj->property("x").toReal(), obj->property("y").toReal()}; QPointF point = {obj->property("x").toReal(), obj->property("y").toReal()};
for (QObject *parent = obj->parent(); parent; parent = parent->parent()) { for (QObject *parent = obj->parent(); parent; parent = parent->parent()) {
point += {parent->property("x").toReal(), parent->property("y").toReal()}; point += {parent->property("x").toReal(), parent->property("y").toReal()};
if (parent->isWindowType()) {
break;
}
} }
return point; return point;
}; };