From ef7c04cd9ac06b64c516db47bda6f4d9c12db3b9 Mon Sep 17 00:00:00 2001
From: Dylan Liu <312902918@qq.com>
Date: 摹曛, 30 5月 2024 19:45:07 +0800
Subject: [PATCH] quickwindowagent: Remove const for HitTestVisible API.

---
 src/quick/quickwindowagent.cpp |  125 +++++++++++------------------------------
 1 files changed, 35 insertions(+), 90 deletions(-)

diff --git a/src/quick/quickwindowagent.cpp b/src/quick/quickwindowagent.cpp
index 74a032b..a9bfd84 100644
--- a/src/quick/quickwindowagent.cpp
+++ b/src/quick/quickwindowagent.cpp
@@ -1,100 +1,37 @@
+// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware)
+// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao)
+// SPDX-License-Identifier: Apache-2.0
+
 #include "quickwindowagent.h"
 #include "quickwindowagent_p.h"
-#include "quickitemdelegate_p.h"
 
 #include <QtQuick/QQuickWindow>
-#include <QtQuick/QQuickPaintedItem>
-#include <QtQuick/private/qquickitem_p.h>
 #include <QtQuick/private/qquickanchors_p.h>
+
+#include "quickitemdelegate_p.h"
 
 namespace QWK {
 
-    class BorderItem : public QQuickPaintedItem {
-        Q_OBJECT
+    /*!
+        \class QuickWindowAgent
+        \brief QuickWindowAgent is the window agent for QtQuick.
 
-    public:
-        explicit BorderItem(AbstractWindowContext *ctx, QQuickItem *parent = nullptr);
-        ~BorderItem() override;
+        It provides interfaces for QtQuick and processes some Qt events related to the QQuickItem
+        instance. The usage of all APIs is consistent with the \a Widgets module.
+    */
 
-        void updateHeight();
+    QuickWindowAgentPrivate::QuickWindowAgentPrivate() = default;
 
-        void paint(QPainter *painter) override;
-
-        void itemChange(ItemChange change, const ItemChangeData &data) override;
-
-    private:
-        AbstractWindowContext *context;
-    };
-
-    BorderItem::BorderItem(AbstractWindowContext *ctx, QQuickItem *parent) : QQuickPaintedItem(parent), context(ctx) {
-        setAntialiasing(true); // ### FIXME: do we need to enable or disable this?
-        setMipmap(true); // ### FIXME: do we need to enable or disable this?
-        setFillColor({}); // Will improve the performance a little bit.
-        setOpaquePainting(true); // Will also improve the performance, we don't draw semi-transparent borders of course.
-
-        auto parentPri = QQuickItemPrivate::get(parent);
-        auto anchors = QQuickItemPrivate::get(this)->anchors();
-        anchors->setTop(parentPri->top());
-        anchors->setLeft(parentPri->left());
-        anchors->setRight(parentPri->right());
-
-        setZ(std::numeric_limits<qreal>::max());
-    }
-
-    BorderItem::~BorderItem() = default;
-
-    void BorderItem::updateHeight() {
-        bool native = false;
-        quint32 thickness = 0;
-        void *args[] = { &native, &thickness };
-        context->virtual_hook(AbstractWindowContext::QueryBorderThicknessHook, &args);
-        setHeight(thickness);
-    }
-
-    void BorderItem::paint(QPainter *painter) {
-        auto rect = QRect{ QPoint{ 0, 0}, size().toSize() };
-        auto region = QRegion{ rect };
-        void *args[] = {
-            painter,
-            &rect,
-            &region
-        };
-        context->virtual_hook(AbstractWindowContext::DrawBordersHook, args);
-    }
-
-    void BorderItem::itemChange(ItemChange change, const ItemChangeData &data) {
-        QQuickPaintedItem::itemChange(change, data);
-        switch (change) {
-            case ItemSceneChange:
-                if (data.window) {
-                    connect(data.window, &QQuickWindow::activeChanged, this, [this](){ update(); });
-                }
-                Q_FALLTHROUGH();
-            case ItemVisibleHasChanged:
-            case ItemDevicePixelRatioHasChanged:
-                updateHeight();
-                break;
-            default:
-                break;
-        }
-    }
-
-    QuickWindowAgentPrivate::QuickWindowAgentPrivate() {
-    }
-
-    QuickWindowAgentPrivate::~QuickWindowAgentPrivate() {
-    }
+    QuickWindowAgentPrivate::~QuickWindowAgentPrivate() = default;
 
     void QuickWindowAgentPrivate::init() {
-        borderItem = std::make_unique<BorderItem>(context.get(), hostWindow->contentItem());
     }
 
     QuickWindowAgent::QuickWindowAgent(QObject *parent)
         : QuickWindowAgent(*new QuickWindowAgentPrivate(), parent) {
     }
 
-    QuickWindowAgent::~QuickWindowAgent() {
-    }
+    QuickWindowAgent::~QuickWindowAgent() = default;
 
     bool QuickWindowAgent::setup(QQuickWindow *window) {
         Q_ASSERT(window);
@@ -107,10 +44,12 @@
             return false;
         }
 
-        if (!d->setup(window, new QuickItemDelegate())) {
-            return false;
-        }
+        d->setup(window, new QuickItemDelegate());
         d->hostWindow = window;
+
+#if defined(Q_OS_WINDOWS) && QWINDOWKIT_CONFIG(ENABLE_WINDOWS_SYSTEM_BORDERS)
+        d->setupWindows10BorderWorkaround();
+#endif
         return true;
     }
 
@@ -124,6 +63,9 @@
         if (!d->context->setTitleBar(item)) {
             return;
         }
+#ifdef Q_OS_MAC
+        setSystemButtonArea(nullptr);
+#endif
         Q_EMIT titleBarWidgetChanged(item);
     }
 
@@ -140,26 +82,29 @@
         Q_EMIT systemButtonChanged(button, item);
     }
 
+#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
+    bool QuickWindowAgent::isHitTestVisible(QQuickItem *item) const {
+#else
     bool QuickWindowAgent::isHitTestVisible(const QQuickItem *item) const {
+#endif
         Q_D(const QuickWindowAgent);
         return d->context->isHitTestVisible(item);
     }
-
-    void QuickWindowAgent::setHitTestVisible_item(const QQuickItem *item, bool visible) {
+#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
+    void QuickWindowAgent::setHitTestVisible(QQuickItem *item, bool visible) {
+#else
+    void QuickWindowAgent::setHitTestVisible(const QQuickItem *item, bool visible) {
+#endif
         Q_D(QuickWindowAgent);
         d->context->setHitTestVisible(item, visible);
     }
 
-    void QuickWindowAgent::setHitTestVisible_rect(const QRect &rect, bool visible) {
-        Q_D(QuickWindowAgent);
-        d->context->setHitTestVisible(rect, visible);
-    }
-
+    /*!
+        \internal
+    */
     QuickWindowAgent::QuickWindowAgent(QuickWindowAgentPrivate &d, QObject *parent)
         : WindowAgentBase(d, parent) {
         d.init();
     }
 
 }
-
-#include "quickwindowagent.moc"
\ No newline at end of file

--
Gitblit v1.9.1