From 245ddfa1f01b4c9fa10337246b8045755e5bcce5 Mon Sep 17 00:00:00 2001
From: Sine Striker <trueful@163.com>
Date: 周二, 19 12月 2023 21:03:58 +0800
Subject: [PATCH] Change back to qScopeGuard

---
 src/core/contexts/qtwindowcontext.cpp |   48 ++++++++++++++++++++++--------------------------
 1 files changed, 22 insertions(+), 26 deletions(-)

diff --git a/src/core/contexts/qtwindowcontext.cpp b/src/core/contexts/qtwindowcontext.cpp
index 78b0de1..4bbb0e6 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 = mouseEvent->scenePosition().toPoint();
-        QPoint globalPos = mouseEvent->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,14 @@
     }
 
     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(QWindow *oldWindow) {
+        Q_UNUSED(oldWindow)
+        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