From 39ba3049f01b30c9a99ad8bb8cd94e117d1c3c65 Mon Sep 17 00:00:00 2001
From: SineStriker <trueful@163.com>
Date: 摹曛, 28 12月 2023 20:54:27 +0800
Subject: [PATCH] Fix mistakes of quick module

---
 src/quick/quickwindowagent_mac.cpp |   57 ++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/src/quick/quickwindowagent_mac.cpp b/src/quick/quickwindowagent_mac.cpp
index 3f6b3f8..0e19772 100644
--- a/src/quick/quickwindowagent_mac.cpp
+++ b/src/quick/quickwindowagent_mac.cpp
@@ -2,18 +2,43 @@
 
 namespace QWK {
 
-    /*!
-        Returns the item that acts as the system button area.
-    */
+    class SystemButtonAreaItemHandler : public QObject {
+    public:
+        SystemButtonAreaItemHandler(QQuickItem *item, AbstractWindowContext *ctx,
+                                    QObject *parent = nullptr);
+        ~SystemButtonAreaItemHandler() override = default;
+
+        void updateSystemButtonArea();
+
+    protected:
+        QQuickItem *item;
+        AbstractWindowContext *ctx;
+    };
+
+    SystemButtonAreaItemHandler::SystemButtonAreaItemHandler(QQuickItem *item,
+                                                             AbstractWindowContext *ctx,
+                                                             QObject *parent)
+        : QObject(parent), item(item), ctx(ctx) {
+        connect(item, &QQuickItem::xChanged, this,
+                &SystemButtonAreaItemHandler::updateSystemButtonArea);
+        connect(item, &QQuickItem::yChanged, this,
+                &SystemButtonAreaItemHandler::updateSystemButtonArea);
+        connect(item, &QQuickItem::widthChanged, this,
+                &SystemButtonAreaItemHandler::updateSystemButtonArea);
+        connect(item, &QQuickItem::heightChanged, this,
+                &SystemButtonAreaItemHandler::updateSystemButtonArea);
+        updateSystemButtonArea();
+    }
+
+    void SystemButtonAreaItemHandler::updateSystemButtonArea() {
+        ctx->setSystemButtonArea(QRectF(item->mapToScene(QPointF(0, 0)), item->size()).toRect());
+    }
+
     QQuickItem *QuickWindowAgent::systemButtonArea() const {
         Q_D(const QuickWindowAgent);
         return d->systemButtonAreaItem;
     }
 
-    /*!
-        Sets the item that acts as the system button area. The system button will be centered in
-        its area, it is recommended to place the item in a layout and set a fixed size policy.
-    */
     void QuickWindowAgent::setSystemButtonArea(QQuickItem *item) {
         Q_D(QuickWindowAgent);
         if (d->systemButtonAreaItem == item)
@@ -22,25 +47,11 @@
         auto ctx = d->context.get();
         d->systemButtonAreaItem = item;
         if (!item) {
-            disconnect(systemButtonAreaItemXChangedConnection);
-            disconnect(systemButtonAreaItemYChangedConnection);
-            disconnect(systemButtonAreaItemWidthChangedConnection);
-            disconnect(systemButtonAreaItemHeightChangedConnection);
-            systemButtonAreaItemXChangedConnection = {};
-            systemButtonAreaItemYChangedConnection = {};
-            systemButtonAreaItemWidthChangedConnection = {};
-            systemButtonAreaItemHeightChangedConnection = {};
+            d->systemButtonAreaItemHandler.reset();
             ctx->setSystemButtonArea({});
             return;
         }
-        const auto updateSystemButtonArea = [ctx, item]() -> void {
-            ctx->setSystemButtonArea(QRectF(item->mapToScene(QPointF(0, 0)), item->size()).toRect());
-        };
-        systemButtonAreaItemXChangedConnection = connect(item, &QQuickItem::xChanged, this, updateSystemButtonArea);
-        systemButtonAreaItemYChangedConnection = connect(item, &QQuickItem::yChanged, this, updateSystemButtonArea);
-        systemButtonAreaItemWidthChangedConnection = connect(item, &QQuickItem::widthChanged, this, updateSystemButtonArea);
-        systemButtonAreaItemHeightChangedConnection = connect(item, &QQuickItem::heightChanged, this, updateSystemButtonArea);
-        updateSystemButtonArea();
+        d->systemButtonAreaItemHandler = std::make_unique<SystemButtonAreaItemHandler>(item, ctx);
     }
 
 }

--
Gitblit v1.9.1