From c428bd66e313aaf64bfe5b96c687858a72fa6ddd Mon Sep 17 00:00:00 2001
From: dreamsource-tai <tzz@dreamsourcelab.com>
Date: Thu, 11 Jul 2024 15:14:28 +0800
Subject: [PATCH] fix: unable to complie with qt6

---
 DSView/pv/dock/keywordlineedit.cpp | 16 +++++++++++++++-
 DSView/pv/dock/keywordlineedit.h   |  1 +
 DSView/pv/mainframe.cpp            |  8 +++-----
 DSView/pv/mainframe.h              | 11 +++++++++--
 libsigrok4DSL/lib_main.c           |  2 +-
 5 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/DSView/pv/dock/keywordlineedit.cpp b/DSView/pv/dock/keywordlineedit.cpp
index a74c8c15..aef003ec 100644
--- a/DSView/pv/dock/keywordlineedit.cpp
+++ b/DSView/pv/dock/keywordlineedit.cpp
@@ -25,6 +25,7 @@
 #include "../config/appconfig.h"
 #include "../ui/langresource.h"
 #include "../log.h"
+#include "../dsvdef.h"
 
 namespace{
     QTimer *move_timer = NULL;
@@ -120,7 +121,20 @@ void KeyLineEdit::wheelEvent(QWheelEvent *event)
             int v = new_text.toInt();
             int old_v = v;
 
-            if (event->delta() > 0){
+            int delta = 0;
+
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+            int anglex = event->angleDelta().x();
+            int angley = event->angleDelta().y();
+
+            if (anglex == 0 || ABS_VAL(angley) >= ABS_VAL(anglex)){
+                delta = angley;
+            }
+#else
+            delta = event->delta();
+#endif
+
+            if (delta > 0){
                 v++;
             }
             else{
diff --git a/DSView/pv/dock/keywordlineedit.h b/DSView/pv/dock/keywordlineedit.h
index 5a32ec51..93b50cb8 100644
--- a/DSView/pv/dock/keywordlineedit.h
+++ b/DSView/pv/dock/keywordlineedit.h
@@ -28,6 +28,7 @@
 #include <QWidget>
 #include <QDialog>
 #include <QSpinBox>
+#include <QWheelEvent>
 
 class IKeywordActive{
 public:
diff --git a/DSView/pv/mainframe.cpp b/DSView/pv/mainframe.cpp
index f9e91588..9f92d42b 100644
--- a/DSView/pv/mainframe.cpp
+++ b/DSView/pv/mainframe.cpp
@@ -1106,10 +1106,9 @@ QWidget* MainFrame::GetBodyView()
     return _mainWindow->GetBodyView();
 }
 
-bool MainFrame::nativeEvent(const QByteArray &eventType, void *message, long *result)
-{
 #ifdef _WIN32
-
+bool MainFrame::nativeEvent(const QByteArray &eventType, void *message, MESSAGE_RESULT_PTR result)
+{
     if (_parentNativeWidget != NULL)
     { 
         MSG *msg = static_cast<MSG*>(message);
@@ -1129,10 +1128,9 @@ bool MainFrame::nativeEvent(const QByteArray &eventType, void *message, long *re
             }           
         }
     } 
-    
-#endif
  
     return QWidget::nativeEvent(eventType, message, result);
 }
+#endif
 
 } // namespace pv
diff --git a/DSView/pv/mainframe.h b/DSView/pv/mainframe.h
index 36674801..0c2ec3ee 100644
--- a/DSView/pv/mainframe.h
+++ b/DSView/pv/mainframe.h
@@ -37,6 +37,13 @@
 
 #include "toolbars/titlebar.h"
 
+
+#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
+typedef qintptr *MESSAGE_RESULT_PTR;
+#else
+typedef long *MESSAGE_RESULT_PTR;
+#endif
+
 namespace pv {
  
 class MainWindow;
@@ -108,14 +115,14 @@ class MainFrame :
     void resizeEvent(QResizeEvent *event);
     void closeEvent(QCloseEvent *event);
     bool eventFilter(QObject *object, QEvent *event) override;
+
 #ifdef _WIN32
     void showEvent(QShowEvent *event);
+    bool nativeEvent(const QByteArray &eventType, void *message, MESSAGE_RESULT_PTR result) override;
 #endif
 
     void changeEvent(QEvent *event) override; 
 
-    bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
- 
 signals:
     void sig_ParentNativeEvent(int msg);
 
