From: =?utf-8?b?5YiY6IGq?= <liucong1@kylinos.cn>
Date: Fri, 19 May 2023 09:16:59 +0000
Subject: =?utf-8?q?!15_kylin-video_Merge_pull_request_!15_from_=E6=88=8E?=
 =?utf-8?q?=E6=9C=89=E4=B8=BD/openkylin/yangtze?=

---
 src/widget/eventpasswidget.cpp | 37 +++++++++++++++++++++++++++++++++++++
 src/widget/eventpasswidget.h   |  5 ++++-
 src/widget/playglwidget.cpp    | 37 +++++++++++++++++++++++++++++++++++++
 src/widget/playglwidget.h      |  5 ++++-
 4 files changed, 82 insertions(+), 2 deletions(-)

diff --git a/src/widget/eventpasswidget.cpp b/src/widget/eventpasswidget.cpp
index ebe6f39..c74cc14 100644
--- a/src/widget/eventpasswidget.cpp
+++ b/src/widget/eventpasswidget.cpp
@@ -95,6 +95,7 @@ void EventPassWidget::mousePressEvent(QMouseEvent *e)
 
     // 右键点击触发显示菜单
     if (e->button() == Qt::LeftButton) {
+        m_isMousePressed = true;
         m_timePressStart = QDateTime::currentMSecsSinceEpoch();
     }
     return QWidget::mousePressEvent(e);
@@ -102,6 +103,7 @@ void EventPassWidget::mousePressEvent(QMouseEvent *e)
 
 void EventPassWidget::mouseReleaseEvent(QMouseEvent *e)
 {
+    m_isMousePressed = false;
     // 左键离开触发暂停，如果左键按得时间很长就不触发了，不然会和触摸屏长按冲突
     if (e->button() == Qt::LeftButton && (QDateTime::currentMSecsSinceEpoch() - m_timePressStart) < 500) {
         if (!m_mouseUsed)
@@ -115,6 +117,27 @@ void EventPassWidget::mouseReleaseEvent(QMouseEvent *e)
 
 void EventPassWidget::mouseMoveEvent(QMouseEvent *e)
 {
+    if (m_isMousePressed) {
+        m_posCurrent = e->pos();
+
+        int xc = abs(m_posCurrent.x() - m_posLast.x());
+        int yc = abs(m_posCurrent.y() - m_posLast.y());
+        if (xc < yc) {
+            m_volumeChange = yc * 200 / height();
+            //符合音量调节
+            if (m_volumeChange > 0) {
+                if (m_posCurrent.y() - m_posLast.y() > 2) {
+                    g_user_signal->setVolumeDown(m_volumeChange);
+                    m_posLast = m_posCurrent;
+                }
+                else {
+                    g_user_signal->setVolumeUp(m_volumeChange);
+                    m_posLast = m_posCurrent;
+                }
+            }
+        }
+    }
+
     m_isMouseEnter = true;
     m_checkMouseTimer->stop();
     setCursor(QCursor(Qt::ArrowCursor));
@@ -135,6 +158,19 @@ void EventPassWidget::mouseDoubleClickEvent(QMouseEvent *e)
     return QWidget::mouseDoubleClickEvent(e);
 }
 
+void EventPassWidget::wheelEvent(QWheelEvent *e)
+{
+    // 鼠标滚轮和触控板双指滑动调节音量
+    int wheel_distance = e->delta();
+    if (abs(wheel_distance) / 120 == 1) {
+        if (wheel_distance > 0)
+            g_user_signal->setVolumeUp(5);
+        else
+            g_user_signal->setVolumeDown(5);
+    }
+    return QWidget::wheelEvent(e);
+}
+
 void EventPassWidget::enterEvent(QEvent *e)
 {
     m_isMouseEnter = true;
@@ -144,6 +180,7 @@ void EventPassWidget::enterEvent(QEvent *e)
 void EventPassWidget::leaveEvent(QEvent *e)
 {
     m_isMouseEnter = false;
+    m_isMousePressed = false;
     if(g_playstate > 0)
         m_checkMouseTimer->start();
 
diff --git a/src/widget/eventpasswidget.h b/src/widget/eventpasswidget.h
index e1dfe6e..95bc7a2 100644
--- a/src/widget/eventpasswidget.h
+++ b/src/widget/eventpasswidget.h
@@ -27,7 +27,9 @@ private:
 
     bool m_mouseUsed,
          m_isMouseEnter,
-         m_hasVideo;
+         m_dbClicked,
+         m_hasVideo,
+         m_isMousePressed = false;
 
     int m_volumeChange;
 
@@ -46,6 +48,7 @@ protected:
     void mouseReleaseEvent(QMouseEvent *e) override;
     void mouseMoveEvent(QMouseEvent *e) override;
     void mouseDoubleClickEvent(QMouseEvent *e) override;
+    void wheelEvent(QWheelEvent *e) override;
     void enterEvent(QEvent *e) override;
     void leaveEvent(QEvent *e) override;
     bool event(QEvent *e) override;
diff --git a/src/widget/playglwidget.cpp b/src/widget/playglwidget.cpp
index d39a800..00533e0 100644
--- a/src/widget/playglwidget.cpp
+++ b/src/widget/playglwidget.cpp
@@ -159,6 +159,7 @@ void PlayGLWidget::videIdChange(int vid)
 
 void PlayGLWidget::mousePressEvent(QMouseEvent *e)
 {
+    m_isMousePressed = true;
     m_mousePosPressed = e->pos();
     m_posStart = e->pos();
     m_posLast = e->pos();
@@ -172,6 +173,7 @@ void PlayGLWidget::mousePressEvent(QMouseEvent *e)
 
 void PlayGLWidget::mouseReleaseEvent(QMouseEvent *e)
 {
+    m_isMousePressed = false;
     // 左键离开触发暂停，如果左键按得时间很长就不触发了，不然会和触摸屏长按冲突
     if (e->button() == Qt::LeftButton && (QDateTime::currentMSecsSinceEpoch() - m_timePressStart) < 500) {
         if (!m_mouseUsed)
@@ -185,6 +187,27 @@ void PlayGLWidget::mouseReleaseEvent(QMouseEvent *e)
 
 void PlayGLWidget::mouseMoveEvent(QMouseEvent *e)
 {
+    if (m_isMousePressed) {
+        m_posCurrent = e->pos();
+
+        int xc = abs(m_posCurrent.x() - m_posLast.x());
+        int yc = abs(m_posCurrent.y() - m_posLast.y());
+        if (xc < yc) {
+            m_volumeChange = yc * 200 / height();
+            //符合音量调节
+            if (m_volumeChange > 0) {
+                if (m_posCurrent.y() - m_posLast.y() > 2) {
+                    g_user_signal->setVolumeDown(m_volumeChange);
+                    m_posLast = m_posCurrent;
+                }
+                else {
+                    g_user_signal->setVolumeUp(m_volumeChange);
+                    m_posLast = m_posCurrent;
+                }
+            }
+        }
+    }
+
     m_isMouseEnter = true;
     m_checkMouseTimer->stop();
     setCursor(QCursor(Qt::ArrowCursor));
@@ -205,6 +228,19 @@ void PlayGLWidget::mouseDoubleClickEvent(QMouseEvent *e)
     return QOpenGLWidget::mouseDoubleClickEvent(e);
 }
 
+void PlayGLWidget::wheelEvent(QWheelEvent *e)
+{
+    // 鼠标滚轮和触控板双指滑动调节音量
+    int wheel_distance = e->delta();
+    if (abs(wheel_distance) / 120 == 1) {
+        if (wheel_distance > 0)
+            g_user_signal->setVolumeUp(5);
+        else
+            g_user_signal->setVolumeDown(5);
+    }
+    return QOpenGLWidget::wheelEvent(e);
+}
+
 void PlayGLWidget::enterEvent(QEvent *e)
 {
     m_isMouseEnter = true;
@@ -213,6 +249,7 @@ void PlayGLWidget::enterEvent(QEvent *e)
 
 void PlayGLWidget::leaveEvent(QEvent *e)
 {
+    m_isMousePressed = false;
     m_isMouseEnter = false;
     if(g_playstate > 0)
         m_checkMouseTimer->start();
diff --git a/src/widget/playglwidget.h b/src/widget/playglwidget.h
index a82fac7..72498e9 100644
--- a/src/widget/playglwidget.h
+++ b/src/widget/playglwidget.h
@@ -52,7 +52,9 @@ private:
 
     bool m_mouseUsed,
          m_isMouseEnter,
-         m_hasVideo;
+         m_dbClicked,
+         m_hasVideo,
+         m_isMousePressed = false;
 
     int m_volumeChange;
 
@@ -71,6 +73,7 @@ protected:
     void mouseReleaseEvent(QMouseEvent *e) override;
     void mouseMoveEvent(QMouseEvent *e) override;
     void mouseDoubleClickEvent(QMouseEvent *e) override;
+    void wheelEvent(QWheelEvent *e) override;
     void enterEvent(QEvent *e) override;
     void leaveEvent(QEvent *e) override;
     bool event(QEvent *e) override;
