From 7d747f3bb139d2c01aee61b809d0929e8e908a2d Mon Sep 17 00:00:00 2001 From: Zhao Yuhang <2546789017@qq.com> Date: 周六, 23 12月 2023 17:41:00 +0800 Subject: [PATCH] update qmsetup --- src/core/contexts/qtwindowcontext.cpp | 55 +++++++++++++++++++++++++++++-------------------------- 1 files changed, 29 insertions(+), 26 deletions(-) diff --git a/src/core/contexts/qtwindowcontext.cpp b/src/core/contexts/qtwindowcontext.cpp index ad982c6..9c05fa4 100644 --- a/src/core/contexts/qtwindowcontext.cpp +++ b/src/core/contexts/qtwindowcontext.cpp @@ -2,6 +2,9 @@ #include <QtCore/QDebug> +#include "qwkglobal_p.h" +#include "systemwindow_p.h" + namespace QWK { static constexpr const quint8 kDefaultResizeBorderThickness = 8; @@ -103,23 +106,21 @@ QtWindowEventFilter::~QtWindowEventFilter() = default; - bool QtWindowEventFilter::eventFilter(QObject *object, QEvent *event) { + bool QtWindowEventFilter::eventFilter(QObject *obj, QEvent *event) { + Q_UNUSED(obj) auto type = event->type(); if (type < QEvent::MouseButtonPress || type > QEvent::MouseMove) { return false; } - QObject *host = m_context->host(); - QWindow *window = m_context->window(); - WindowItemDelegate *delegate = m_context->delegate(); - bool fixedSize = delegate->isHostSizeFixed(host); + auto host = m_context->host(); + auto window = m_context->window(); + auto delegate = m_context->delegate(); auto me = static_cast<const QMouseEvent *>(event); -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - QPoint scenePos = me->scenePosition().toPoint(); - QPoint globalPos = me->globalPosition().toPoint(); -#else - QPoint scenePos = me->windowPos().toPoint(); - QPoint globalPos = me->screenPos().toPoint(); -#endif + bool fixedSize = delegate->isHostSizeFixed(host); + + QPoint scenePos = getMouseEventScenePos(me); + QPoint globalPos = getMouseEventGlobalPos(me); + bool inTitleBar = m_context->isInTitleBarDraggableArea(scenePos); switch (type) { case QEvent::MouseButtonPress: { @@ -129,7 +130,7 @@ Qt::Edges edges = calculateWindowEdges(window, scenePos); if (edges != Qt::Edges()) { m_windowStatus = Resizing; - window->startSystemResize(edges); + startSystemResize(window, edges); event->accept(); return true; } @@ -142,7 +143,6 @@ event->accept(); return true; } - m_windowStatus = WaitingRelease; break; } case Qt::RightButton: { @@ -152,6 +152,7 @@ default: break; } + m_windowStatus = WaitingRelease; break; } @@ -186,7 +187,7 @@ } case PreparingMove: { m_windowStatus = Moving; - window->startSystemMove(); + startSystemMove(window); event->accept(); return true; } @@ -243,19 +244,21 @@ } void QtWindowContext::virtual_hook(int id, void *data) { - switch (id) { - case ShowSystemMenuHook: - return; - default: - break; - } AbstractWindowContext::virtual_hook(id, data); } - bool QtWindowContext::setupHost() { - m_delegate->setWindowFlags(m_host, Qt::FramelessWindowHint); - std::ignore = new QtWindowEventFilter(this, this); - return true; + void QtWindowContext::winIdChanged() { + if (!m_windowHandle) { + m_delegate->setWindowFlags(m_host, m_delegate->getWindowFlags(m_host) & + ~Qt::FramelessWindowHint); + qtWindowEventFilter.reset(); + return; + } + + // Allocate new resources + m_delegate->setWindowFlags(m_host, + m_delegate->getWindowFlags(m_host) | Qt::FramelessWindowHint); + qtWindowEventFilter = std::make_unique<QtWindowEventFilter>(this); } -} \ No newline at end of file +} -- Gitblit v1.9.1