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(-)

--- 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
             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{
--- 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:
--- 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 QByteA
             }           
         }
     } 
-    
-#endif
  
     return QWidget::nativeEvent(eventType, message, result);
 }
+#endif
 
 } // namespace pv
--- 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 @@ protected:
     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);
 
