From 2d08f989b16dad059d42c94e3a2cdccdbd3c379e Mon Sep 17 00:00:00 2001
From: Sine Striker <trueful@163.com>
Date: 周一, 04 12月 2023 03:38:52 +0800
Subject: [PATCH] Add more comments

---
 src/core/contexts/abstractwindowcontext.cpp |   39 +++++++++++++++++++++++++++++++++++----
 1 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/src/core/contexts/abstractwindowcontext.cpp b/src/core/contexts/abstractwindowcontext.cpp
index 0cefb8b..5c75d28 100644
--- a/src/core/contexts/abstractwindowcontext.cpp
+++ b/src/core/contexts/abstractwindowcontext.cpp
@@ -2,11 +2,13 @@
 
 namespace QWK {
 
-    AbstractWindowContext::~AbstractWindowContext() {
-        delete m_delegate;
-    }
+    AbstractWindowContext::~AbstractWindowContext() = default;
 
     void AbstractWindowContext::setupWindow(QWindow *window) {
+        Q_ASSERT(window);
+        if (!window) {
+            return;
+        }
         m_windowHandle = window;
     }
 
@@ -35,11 +37,12 @@
         } else {
             m_hitTestVisibleRects.removeAll(rect);
         }
+        hitTestVisibleShapeDirty = true;
         return true;
     }
 
     bool AbstractWindowContext::setSystemButton(CoreWindowAgent::SystemButton button,
-                                                     QObject *obj) {
+                                                QObject *obj) {
         Q_ASSERT(obj);
         Q_ASSERT(button != CoreWindowAgent::Unknown);
         if (!obj || (button == CoreWindowAgent::Unknown)) {
@@ -70,4 +73,32 @@
         // ?
     }
 
+    QRegion AbstractWindowContext::hitTestShape() const {
+        if (hitTestVisibleShapeDirty) {
+            hitTestVisibleShape = {};
+            for (const auto &rect : m_hitTestVisibleRects) {
+                hitTestVisibleShape += rect;
+            }
+            hitTestVisibleShapeDirty = false;
+        }
+        return hitTestVisibleShape;
+    }
+
+    bool AbstractWindowContext::isInSystemButtons(const QPoint &pos,
+                                                  CoreWindowAgent::SystemButton *button) const {
+        *button = CoreWindowAgent::Unknown;
+        for (int i = CoreWindowAgent::WindowIcon; i <= CoreWindowAgent::Close; ++i) {
+            auto currentButton = m_systemButtons[i];
+            if (!currentButton || !m_delegate->isVisible(currentButton) ||
+                !m_delegate->isEnabled(currentButton)) {
+                continue;
+            }
+            if (m_delegate->mapGeometryToScene(currentButton).contains(pos)) {
+                *button = CoreWindowAgent::WindowIcon;
+                return true;
+            }
+        }
+        return false;
+    }
+
 }
\ No newline at end of file

--
Gitblit v1.9.1