From 9dcea027f16c4ce5852da3dfc8aca284c582bd7d Mon Sep 17 00:00:00 2001
From: sola.lu <sola.lu.greentest.com.cn>
Date: 周五, 06 6月 2025 18:19:18 +0800
Subject: [PATCH] 1.注释掉custom margin,解决程序放大后,遮盖窗口底部内容的问题。

---
 src/core/contexts/qtwindowcontext.cpp |   69 +++++++++++++++++++---------------
 1 files changed, 38 insertions(+), 31 deletions(-)

diff --git a/src/core/contexts/qtwindowcontext.cpp b/src/core/contexts/qtwindowcontext.cpp
index 35fc2d1..a476211 100644
--- a/src/core/contexts/qtwindowcontext.cpp
+++ b/src/core/contexts/qtwindowcontext.cpp
@@ -1,6 +1,13 @@
+// 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 "qtwindowcontext_p.h"
 
 #include <QtCore/QDebug>
+
+#include "qwkglobal_p.h"
+#include "systemwindow_p.h"
 
 namespace QWK {
 
@@ -74,9 +81,9 @@
 #endif
     }
 
-    class QtWindowEventFilter : public QObject {
+    class QtWindowEventFilter : public SharedEventFilter {
     public:
-        explicit QtWindowEventFilter(AbstractWindowContext *context, QObject *parent = nullptr);
+        explicit QtWindowEventFilter(AbstractWindowContext *context);
         ~QtWindowEventFilter() override;
 
         enum WindowStatus {
@@ -88,7 +95,7 @@
         };
 
     protected:
-        bool eventFilter(QObject *object, QEvent *event) override;
+        bool sharedEventFilter(QObject *object, QEvent *event) override;
 
     private:
         AbstractWindowContext *m_context;
@@ -96,31 +103,29 @@
         WindowStatus m_windowStatus;
     };
 
-    QtWindowEventFilter::QtWindowEventFilter(AbstractWindowContext *context, QObject *parent)
-        : QObject(parent), m_context(context), m_cursorShapeChanged(false), m_windowStatus(Idle) {
-        m_context->window()->installEventFilter(this);
+    QtWindowEventFilter::QtWindowEventFilter(AbstractWindowContext *context)
+        : m_context(context), m_cursorShapeChanged(false), m_windowStatus(Idle) {
+        m_context->installSharedEventFilter(this);
     }
 
     QtWindowEventFilter::~QtWindowEventFilter() = default;
 
-    bool QtWindowEventFilter::eventFilter(QObject *obj, QEvent *event) {
+    bool QtWindowEventFilter::sharedEventFilter(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 = m_context->isHostSizeFixed();
+
+        QPoint scenePos = getMouseEventScenePos(me);
+        QPoint globalPos = getMouseEventGlobalPos(me);
+
         bool inTitleBar = m_context->isInTitleBarDraggableArea(scenePos);
         switch (type) {
             case QEvent::MouseButtonPress: {
@@ -130,7 +135,7 @@
                             Qt::Edges edges = calculateWindowEdges(window, scenePos);
                             if (edges != Qt::Edges()) {
                                 m_windowStatus = Resizing;
-                                window->startSystemResize(edges);
+                                startSystemResize(window, edges);
                                 event->accept();
                                 return true;
                             }
@@ -143,7 +148,6 @@
                             event->accept();
                             return true;
                         }
-                        m_windowStatus = WaitingRelease;
                         break;
                     }
                     case Qt::RightButton: {
@@ -153,6 +157,7 @@
                     default:
                         break;
                 }
+                m_windowStatus = WaitingRelease;
                 break;
             }
 
@@ -187,7 +192,7 @@
                     }
                     case PreparingMove: {
                         m_windowStatus = Moving;
-                        window->startSystemMove();
+                        startSystemMove(window);
                         event->accept();
                         return true;
                     }
@@ -214,8 +219,10 @@
 
             case QEvent::MouseButtonDblClick: {
                 if (me->button() == Qt::LeftButton && inTitleBar && !fixedSize) {
+                    Qt::WindowFlags windowFlags = delegate->getWindowFlags(host);
                     Qt::WindowStates windowState = delegate->getWindowState(host);
-                    if (!(windowState & Qt::WindowFullScreen)) {
+                    if ((windowFlags & Qt::WindowMaximizeButtonHint) &&
+                        !(windowState & Qt::WindowFullScreen)) {
                         if (windowState & Qt::WindowMaximized) {
                             delegate->setWindowState(host, windowState & ~Qt::WindowMaximized);
                         } else {
@@ -235,6 +242,7 @@
     }
 
     QtWindowContext::QtWindowContext() : AbstractWindowContext() {
+        qtWindowEventFilter = std::make_unique<QtWindowEventFilter>(this);
     }
 
     QtWindowContext::~QtWindowContext() = default;
@@ -244,20 +252,19 @@
     }
 
     void QtWindowContext::virtual_hook(int id, void *data) {
-        switch (id) {
-            case ShowSystemMenuHook:
-                return;
-            default:
-                break;
-        }
         AbstractWindowContext::virtual_hook(id, data);
     }
 
-    void QtWindowContext::winIdChanged(QWindow *oldWindow) {
-        Q_UNUSED(oldWindow)
+    void QtWindowContext::winIdChanged(WId winId, WId oldWinId) {
+        if (!m_windowHandle) {
+            m_delegate->setWindowFlags(m_host, m_delegate->getWindowFlags(m_host) &
+                                                   ~Qt::FramelessWindowHint);
+            return;
+        }
+
+        // Allocate new resources
         m_delegate->setWindowFlags(m_host,
                                    m_delegate->getWindowFlags(m_host) | Qt::FramelessWindowHint);
-        qtWindowEventFilter = std::make_unique<QtWindowEventFilter>(this);
     }
 
 }

--
Gitblit v1.9.1