From e5370435a9d4297d0ba227f2237d7ed16bba7e82 Mon Sep 17 00:00:00 2001
From: Yuhang Zhao <zhaoyuhang@rankyee.com>
Date: 周三, 27 12月 2023 17:15:52 +0800
Subject: [PATCH] fix some win32 issues

---
 src/widgets/widgetitemdelegate.cpp |   49 ++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 38 insertions(+), 11 deletions(-)

diff --git a/src/widgets/widgetitemdelegate.cpp b/src/widgets/widgetitemdelegate.cpp
index ca8bb99..91e02ae 100644
--- a/src/widgets/widgetitemdelegate.cpp
+++ b/src/widgets/widgetitemdelegate.cpp
@@ -4,7 +4,7 @@
 #include <QtWidgets/QWidget>
 #include <QtWidgets/QApplication>
 
-extern Q_WIDGETS_EXPORT QWidget *qt_button_down;
+extern Q_DECL_IMPORT QWidget *qt_button_down;
 
 namespace QWK {
 
@@ -12,7 +12,7 @@
 
     WidgetItemDelegate::~WidgetItemDelegate() = default;
 
-    QWindow *WidgetItemDelegate::window(QObject *obj) const {
+    QWindow *WidgetItemDelegate::window(const QObject *obj) const {
         return static_cast<const QWidget *>(obj)->windowHandle();
     }
 
@@ -31,7 +31,7 @@
         return {originPoint, size};
     }
 
-    QWindow *WidgetItemDelegate::hostWindow(QObject *host) const {
+    QWindow *WidgetItemDelegate::hostWindow(const QObject *host) const {
         return static_cast<const QWidget *>(host)->windowHandle();
     }
 
@@ -47,12 +47,6 @@
         if (!minSize.isEmpty() && !maxSize.isEmpty() && (minSize == maxSize)) {
             return true;
         }
-        // Usually set by the user.
-        const QSizePolicy sizePolicy = widget->sizePolicy();
-        if ((sizePolicy.horizontalPolicy() == QSizePolicy::Fixed) &&
-            (sizePolicy.verticalPolicy() == QSizePolicy::Fixed)) {
-            return true;
-        }
         return false;
     }
 
@@ -60,7 +54,8 @@
         return static_cast<const QWidget *>(host)->isActiveWindow();
     }
 
-    void WidgetItemDelegate::resetQtGrabbedControl() const {
+    void WidgetItemDelegate::resetQtGrabbedControl(QObject *host) const {
+        Q_UNUSED(host);
         if (!qt_button_down) {
             return;
         }
@@ -69,8 +64,40 @@
         const auto event = new QMouseEvent(
             QEvent::MouseButtonRelease, invalidPos, invalidPos, invalidPos, Qt::LeftButton,
             QGuiApplication::mouseButtons() ^ Qt::LeftButton, QGuiApplication::keyboardModifiers());
-        QApplication::postEvent(qt_button_down, event);
+        QCoreApplication::postEvent(qt_button_down, event);
         qt_button_down = nullptr;
     }
 
+    Qt::WindowStates WidgetItemDelegate::getWindowState(const QObject *host) const {
+        return static_cast<const QWidget *>(host)->windowState();
+    }
+
+    void WidgetItemDelegate::setWindowState(QObject *host, Qt::WindowStates state) const {
+        static_cast<QWidget *>(host)->setWindowState(state);
+    }
+
+    void WidgetItemDelegate::setCursorShape(QObject *host, Qt::CursorShape shape) const {
+        static_cast<QWidget *>(host)->setCursor(QCursor(shape));
+    }
+
+    void WidgetItemDelegate::restoreCursorShape(QObject *host) const {
+        static_cast<QWidget *>(host)->unsetCursor();
+    }
+
+    Qt::WindowFlags WidgetItemDelegate::getWindowFlags(const QObject *host) const {
+        return static_cast<const QWidget *>(host)->windowFlags();
+    }
+
+    void WidgetItemDelegate::setWindowFlags(QObject *host, Qt::WindowFlags flags) const {
+        static_cast<QWidget *>(host)->setWindowFlags(flags);
+    }
+
+    void WidgetItemDelegate::setWindowVisible(QObject *host, bool visible) const {
+        static_cast<QWidget *>(host)->setVisible(visible);
+    }
+
+    void WidgetItemDelegate::bringWindowToTop(QObject *host) const {
+        static_cast<QWidget *>(host)->raise();
+    }
+
 }
\ No newline at end of file

--
Gitblit v1.9.1