[vlc-commits] [Git][videolan/vlc][master] qt, qml: flickable scroll always handle pixel delta

Hugo Beauzée-Luyssen (@chouquette) gitlab at videolan.org
Thu Jan 13 17:55:04 UTC 2022



Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC


Commits:
02fbb3b1 by Fatih Uzunoglu at 2022-01-13T17:41:35+00:00
qt, qml: flickable scroll always handle pixel delta

- - - - -


5 changed files:

- modules/gui/qt/maininterface/mainctx.hpp
- modules/gui/qt/util/flickable_scroll_handler.cpp
- modules/gui/qt/util/flickable_scroll_handler.hpp
- modules/gui/qt/util/qml/FlickableScrollHandler.qml
- modules/gui/qt/util/qml/MultipleBinding.qml


Changes:

=====================================
modules/gui/qt/maininterface/mainctx.hpp
=====================================
@@ -261,6 +261,12 @@ public:
     Q_INVOKABLE static inline void setCursor(Qt::CursorShape cursor) { QApplication::setOverrideCursor(QCursor(cursor)); };
     Q_INVOKABLE static inline void restoreCursor(void) { QApplication::restoreOverrideCursor(); };
 
+    Q_INVOKABLE static /*constexpr*/ inline unsigned int qtVersion() { return QT_VERSION; };
+    Q_INVOKABLE static /*constexpr*/ inline unsigned int qtVersionCheck(unsigned char major,
+                                                                        unsigned char minor,
+                                                                        unsigned char patch)
+                                                                       { return QT_VERSION_CHECK(major, minor, patch); };
+
     void dropEventPlay( QDropEvent* event, bool b_play );
     /**
      * @brief ask for the application to terminate


=====================================
modules/gui/qt/util/flickable_scroll_handler.cpp
=====================================
@@ -104,7 +104,7 @@ bool FlickableScrollHandler::eventFilter(QObject *watched, QEvent *event)
         ev.delta = wheel->pixelDelta();
         ev.type = Type::Pixel;
     }
-    else if (!wheel->angleDelta().isNull())
+    else if (!m_handleOnlyPixelDelta && !wheel->angleDelta().isNull())
     {
         ev.delta = wheel->angleDelta() / 8 / 15;
         ev.type = Type::Degree;


=====================================
modules/gui/qt/util/flickable_scroll_handler.hpp
=====================================
@@ -33,6 +33,7 @@ class FlickableScrollHandler : public QObject
     Q_PROPERTY(qreal effectiveScaleFactor READ effectiveScaleFactor NOTIFY effectiveScaleFactorChanged FINAL)
     Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged FINAL)
     Q_PROPERTY(bool fallbackScroll MEMBER m_fallbackScroll NOTIFY fallbackScrollChanged FINAL)
+    Q_PROPERTY(bool handleOnlyPixelDelta MEMBER m_handleOnlyPixelDelta NOTIFY handleOnlyPixelDeltaChanged FINAL)
 
 public:
     explicit FlickableScrollHandler(QObject *parent = nullptr);
@@ -53,6 +54,8 @@ signals:
     void effectiveScaleFactorChanged();
     void fallbackScrollChanged();
 
+    void handleOnlyPixelDeltaChanged();
+
 private slots:
     void init();
 
@@ -86,6 +89,7 @@ private:
     } m_scrollBarV, m_scrollBarH;
 
     void adjustScrollBar(ScrollBar& scrollBar);
+    bool m_handleOnlyPixelDelta = false;
 };
 
 #endif // FLICKABLE_SCROLL_HANDLER_HPP


=====================================
modules/gui/qt/util/qml/FlickableScrollHandler.qml
=====================================
@@ -17,6 +17,7 @@
  *****************************************************************************/
 
 import QtQml 2.11
+import QtQml.Models 2.11
 
 import org.videolan.vlc 0.1 as VLC
 
@@ -24,16 +25,29 @@ VLC.FlickableScrollHandler {
     id: handler
 
     scaleFactor: VLC.MainCtx.intfScaleFactor
+
     enabled: !VLC.MainCtx.smoothScroll
 
-    readonly property QtObject _behaviorAdjuster: MultipleBinding {
+    Component.onCompleted: {
+        // QTBUG-56075
+        var qtVersion = VLC.MainCtx.qtVersion()
+        if ((qtVersion >= VLC.MainCtx.qtVersionCheck(6, 0, 0) && qtVersion < VLC.MainCtx.qtVersionCheck(6, 2, 0)) ||
+            (qtVersion < VLC.MainCtx.qtVersionCheck(5, 15, 8))) {
+            handler.enabled = true
+            var smoothScroll = Qt.binding(function() { return VLC.MainCtx.smoothScroll })
+            handler.handleOnlyPixelDelta = smoothScroll
+            _behaviorAdjuster.when = smoothScroll
+            _behaviorAdjuster.model.append( {property: "flickDeceleration", value: 3500} )
+        }
+    }
+
+    readonly property MultipleBinding _behaviorAdjuster: MultipleBinding {
         target: handler.parent
         when: !handler.enabled
 
-        model: [
-            {property: "flickDeceleration", value: 3500} /* TODO: Workaround Qt <6.2 */,
-            {property: "boundsBehavior", value: 0 /* Flickable.StopAtBounds */},
-            {property: "boundsMovement", value: 0 /* Flickable.StopAtBounds */}
-        ]
+        model: ListModel {
+            ListElement {property: "boundsBehavior"; value: 0 /* Flickable.StopAtBounds */}
+            ListElement {property: "boundsMovement"; value: 0 /* Flickable.StopAtBounds */}
+        }
     }
 }


=====================================
modules/gui/qt/util/qml/MultipleBinding.qml
=====================================
@@ -17,11 +17,12 @@
  *****************************************************************************/
 
 import QtQml 2.11
+import QtQml.Models 2.11
 
 QtObject {
     id: root
 
-    property alias model: instantiator.model
+    property ListModel model
     property alias enabled: instantiator.active
     property alias asynchronous: instantiator.asynchronous
 
@@ -32,15 +33,17 @@ QtObject {
     readonly property QtObject _instantiator: Instantiator {
         id: instantiator
 
+        model: root.model
+
         delegate: Binding {
-            target: modelData.target ? modelData.target
-                                     : root.target
-            when: modelData.when !== undefined ? modelData.when
-                                               : root.when
-            property: modelData.property
-            value: modelData.value
-            delayed: modelData.delayed !== undefined ? modelData.delayed
-                                                     : root.delayed
+            target: model.target ? model.target
+                                 : root.target
+            when: model.when !== undefined ? model.when
+                                           : root.when
+            property: model.property
+            value: model.value
+            delayed: model.delayed !== undefined ? model.delayed
+                                                 : root.delayed
         }
     }
 }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/02fbb3b1de156ab079a6bd19d7a5dfc47fbabc78

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/02fbb3b1de156ab079a6bd19d7a5dfc47fbabc78
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list