[vlc-commits] [Git][videolan/vlc][master] 7 commits: qt: move Qt key to VLC translation to its own file

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Sat Dec 21 17:24:04 UTC 2024



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
eb312d52 by Pierre Lamot at 2024-12-21T17:10:25+00:00
qt: move Qt key to VLC translation to its own file

these functions don't belong in widgets

- - - - -
7498ac55 by Pierre Lamot at 2024-12-21T17:10:25+00:00
qt: introduce WheelToVLCConverter to aggregate wheel events as VLC keys

this class aggregates wheel events until a full step (120 angle units) is
reached in a direction and emits a synthesized event usable by VLC hotkeys

- - - - -
07d69422 by Pierre Lamot at 2024-12-21T17:10:25+00:00
qt: register WheelToVLCConverter to be usable in QML

- - - - -
390d6536 by Pierre Lamot at 2024-12-21T17:10:25+00:00
qml: use WheelToVLCConverter to handle volume changes from wheel events

- - - - -
f93ceb4b by Pierre Lamot at 2024-12-21T17:10:25+00:00
qt: allow MainCtx to send directly raw VLC hotkeys

- - - - -
69afc34f by Pierre Lamot at 2024-12-21T17:10:25+00:00
qml: send scroll events as hotkeys to VLC rather than volume change in the Player

this way the player in audio mode behaves similarly to the video window

- - - - -
529bd47c by Pierre Lamot at 2024-12-21T17:10:25+00:00
qml: remove applyVolume helper function

- - - - -


17 changed files:

- modules/gui/qt/Makefile.am
- modules/gui/qt/dialogs/dialogs_provider.cpp
- modules/gui/qt/dialogs/preferences/preferences_widgets.cpp
- modules/gui/qt/dialogs/preferences/preferences_widgets.hpp
- modules/gui/qt/maininterface/mainctx.cpp
- modules/gui/qt/maininterface/mainctx.hpp
- modules/gui/qt/maininterface/mainui.cpp
- modules/gui/qt/maininterface/videosurface.cpp
- modules/gui/qt/maininterface/videosurface.hpp
- modules/gui/qt/meson.build
- modules/gui/qt/player/qml/Player.qml
- modules/gui/qt/player/qml/controlbarcontrols/VolumeWidget.qml
- modules/gui/qt/util/qml/Helpers.qml
- + modules/gui/qt/util/vlchotkeyconverter.cpp
- + modules/gui/qt/util/vlchotkeyconverter.hpp
- modules/gui/qt/widgets/native/customwidgets.cpp
- modules/gui/qt/widgets/native/customwidgets.hpp


Changes:

=====================================
modules/gui/qt/Makefile.am
=====================================
@@ -326,6 +326,7 @@ libqt_plugin_la_SOURCES = \
 	util/varcommon_p.hpp \
 	util/varchoicemodel.cpp  util/varchoicemodel.hpp \
 	util/variables.cpp util/variables.hpp \
+	util/vlchotkeyconverter.cpp util/vlchotkeyconverter.hpp \
 	util/vlctick.cpp \
 	util/vlctick.hpp \
 	util/shared_input_item.hpp \
@@ -497,6 +498,7 @@ nodist_libqt_plugin_la_SOURCES = \
 	util/vlctick.moc.cpp \
 	util/dismiss_popup_event_filter.moc.cpp \
 	util/list_selection_model.moc.cpp \
+	util/vlchotkeyconverter.moc.cpp \
 	widgets/native/animators.moc.cpp \
 	widgets/native/csdthemeimage.moc.cpp \
 	widgets/native/customwidgets.moc.cpp \


=====================================
modules/gui/qt/dialogs/dialogs_provider.cpp
=====================================
@@ -36,7 +36,7 @@
 #include "playlist/playlist_controller.hpp"
 #include "menus/menus.hpp"
 #include "util/qt_dirs.hpp"
-#include "widgets/native/customwidgets.hpp" /* VLCKeyToString() */
+#include "util/vlchotkeyconverter.hpp"
 #include "maininterface/mainctx.hpp"
 
 /* The dialogs */


=====================================
modules/gui/qt/dialogs/preferences/preferences_widgets.cpp
=====================================
@@ -31,8 +31,8 @@
 #endif
 
 #include "dialogs/preferences/preferences_widgets.hpp"
-#include "widgets/native/customwidgets.hpp"
 #include "widgets/native/searchlineedit.hpp"
+#include "util/vlchotkeyconverter.hpp"
 #include "util/qt_dirs.hpp"
 #include <vlc_intf_strings.h>
 #include <vlc_modules.h>
@@ -64,6 +64,7 @@
 #include <QGuiApplication>
 #include <QClipboard>
 #include <QFont>
+#include <QToolButton>
 
 #define MINWIDTH_BOX 90
 #define LAST_COLUMN 10
@@ -1765,6 +1766,14 @@ KeyInputDialog::KeyInputDialog( QTreeWidget *table_,
     conflicts = false;
     existingkeys = NULL;
 
+    wheelConverter = new WheelToVLCConverter(this);
+    connect(wheelConverter, &WheelToVLCConverter::vlcWheelKey, this, [this](int i_vlck){
+        vlckey = VLCKeyToString( i_vlck, false );
+        vlckey_tr = VLCKeyToString( i_vlck, true );
+        selected->setText( qtr( "Key: <b>%1</b>" ).arg( vlckey_tr ) );
+        checkForConflicts( QString() );
+    });
+
     bool global = ( column == KeySelectorControl::GLOBAL_HOTKEY_COL );
 
     setWindowTitle( global ? qtr( "Global Hotkey change" )
@@ -1864,11 +1873,7 @@ void KeyInputDialog::keyPressEvent( QKeyEvent *e )
 
 void KeyInputDialog::wheelEvent( QWheelEvent *e )
 {
-    int i_vlck = qtWheelEventToVLCKey( *e );
-    vlckey = VLCKeyToString( i_vlck, false );
-    vlckey_tr = VLCKeyToString( i_vlck, true );
-    selected->setText( qtr( "Key: <b>%1</b>" ).arg( vlckey_tr ) );
-    checkForConflicts( QString() );
+    wheelConverter->wheelEvent(e);
 }
 
 void KeyInputDialog::unsetAction() { done( 2 ); }


=====================================
modules/gui/qt/dialogs/preferences/preferences_widgets.hpp
=====================================
@@ -53,6 +53,7 @@ class QPushButton;
 class QFontComboBox;
 class QSlider;
 class QAbstractButton;
+class WheelToVLCConverter;
 
 /*******************************************************
  * Simple widgets
@@ -505,6 +506,7 @@ private:
     QPushButton *ok, *unset;
     KeyTableItem *keyItem;
     enum KeySelectorControl::ColumnIndex column;
+    WheelToVLCConverter* wheelConverter;
 
     void checkForConflicts( const QString &sequence );
     void keyPressEvent( QKeyEvent *);


=====================================
modules/gui/qt/maininterface/mainctx.cpp
=====================================
@@ -36,7 +36,7 @@
 #include "util/renderer_manager.hpp"
 #include "util/csdbuttonmodel.hpp"
 
-#include "widgets/native/customwidgets.hpp"               // qtEventToVLCKey, QVLCStackedWidget
+#include "util/vlchotkeyconverter.hpp"
 #include "util/qt_dirs.hpp"                     // toNativeSeparators
 
 #include "util/color_scheme_model.hpp"
@@ -510,6 +510,11 @@ void MainCtx::sendHotkey(Qt::Key key , Qt::KeyboardModifiers modifiers)
     var_SetInteger(vlc_object_instance(p_intf), "key-pressed", vlckey);
 }
 
+void MainCtx::sendVLCHotkey(int vlcHotkey)
+{
+    var_SetInteger(vlc_object_instance(p_intf), "key-pressed", vlcHotkey);
+}
+
 void MainCtx::updateIntfScaleFactor()
 {
     m_intfScaleFactor = m_intfUserScaleFactor;


=====================================
modules/gui/qt/maininterface/mainctx.hpp
=====================================
@@ -431,6 +431,7 @@ public slots:
     void setMinimalView(bool);
 
     void sendHotkey(Qt::Key key, Qt::KeyboardModifiers modifiers );
+    void sendVLCHotkey(int vlcHotkey);
 
     void emitBoss();
     void emitRaise();


=====================================
modules/gui/qt/maininterface/mainui.cpp
=====================================
@@ -50,6 +50,7 @@
 #include "dialogs/help/aboutmodel.hpp"
 #include "dialogs/dialogs_provider.hpp"
 #include "dialogs/dialogs/dialogmodel.hpp"
+#include "util/vlchotkeyconverter.hpp"
 
 #include "network/networkmediamodel.hpp"
 #include "network/networkdevicemodel.hpp"
@@ -328,6 +329,7 @@ void MainUI::registerQMLTypes()
         qmlRegisterSingletonInstance<SVGColorImage>(uri, versionMajor, versionMinor, "SVGColorImage", new SVGColorImage(this));
         qmlRegisterSingletonInstance<VLCAccessImage>(uri, versionMajor, versionMinor, "VLCAccessImage", new VLCAccessImage(this));
         qmlRegisterType<DelayEstimator>( uri, versionMajor, versionMinor, "DelayEstimator" );
+        qmlRegisterTypesAndRevisions<WheelToVLCConverter>( uri, versionMajor );
 
         qmlRegisterType<ImageLuminanceExtractor>( uri, versionMajor, versionMinor, "ImageLuminanceExtractor");
 


=====================================
modules/gui/qt/maininterface/videosurface.cpp
=====================================
@@ -17,7 +17,7 @@
  *****************************************************************************/
 #include "videosurface.hpp"
 #include "maininterface/mainctx.hpp"
-#include "widgets/native/customwidgets.hpp" //for qtEventToVLCKey
+#include "util/vlchotkeyconverter.hpp"
 #include <QSGRectangleNode>
 #include <QThreadPool>
 #include <vlc_window.h>
@@ -174,12 +174,11 @@ void VideoSurfaceProvider::onMouseMoved(float x, float y)
         vlc_window_ReportMouseMoved(m_voutWindow, x, y);
 }
 
-void VideoSurfaceProvider::onMouseWheeled(const QWheelEvent& event)
+void VideoSurfaceProvider::onMouseWheeled(int vlcButton)
 {
-    int vlckey = qtWheelEventToVLCKey(event);
     QMutexLocker lock(&m_voutlock);
     if (m_voutWindow)
-        vlc_window_ReportKeyPress(m_voutWindow, vlckey);
+        vlc_window_ReportKeyPress(m_voutWindow, vlcButton);
 }
 
 void VideoSurfaceProvider::onKeyPressed(int key, Qt::KeyboardModifiers modifiers)
@@ -210,6 +209,8 @@ VideoSurface::VideoSurface(QQuickItem* parent)
     setAcceptedMouseButtons(Qt::AllButtons);
     setFlag(ItemAcceptsInputMethod, true);
 
+    m_wheelEventConverter = new WheelToVLCConverter(this);
+
     {
         connect(this, &QQuickItem::widthChanged, this, &VideoSurface::updateSurfaceSize);
         connect(this, &QQuickItem::heightChanged, this, &VideoSurface::updateSurfaceSize);
@@ -307,7 +308,7 @@ void VideoSurface::keyPressEvent(QKeyEvent* event)
 #if QT_CONFIG(wheelevent)
 void VideoSurface::wheelEvent(QWheelEvent *event)
 {
-    emit mouseWheeled(*event);
+    m_wheelEventConverter->wheelEvent(event);
     event->accept();
 }
 #endif
@@ -377,11 +378,11 @@ void VideoSurface::setVideoSurfaceProvider(VideoSurfaceProvider *newVideoSurface
         connect(this, &VideoSurface::mousePressed, m_provider, &VideoSurfaceProvider::onMousePressed);
         connect(this, &VideoSurface::mouseDblClicked, m_provider, &VideoSurfaceProvider::onMouseDoubleClick);
         connect(this, &VideoSurface::mouseReleased, m_provider, &VideoSurfaceProvider::onMouseReleased);
-        connect(this, &VideoSurface::mouseWheeled, m_provider, &VideoSurfaceProvider::onMouseWheeled);
         connect(this, &VideoSurface::keyPressed, m_provider, &VideoSurfaceProvider::onKeyPressed);
         connect(this, &VideoSurface::surfaceSizeChanged, m_provider, &VideoSurfaceProvider::onSurfaceSizeChanged);
         connect(this, &VideoSurface::surfacePositionChanged, m_provider, &VideoSurfaceProvider::surfacePositionChanged);
 
+        connect(m_wheelEventConverter, &WheelToVLCConverter::vlcWheelKey, m_provider, &VideoSurfaceProvider::onMouseWheeled);
         connect(m_provider, &VideoSurfaceProvider::videoEnabledChanged, this, &VideoSurface::updateSurfacePositionAndSize);
 
         setFlag(ItemHasContents, true);


=====================================
modules/gui/qt/maininterface/videosurface.hpp
=====================================
@@ -33,6 +33,7 @@ extern "C" {
 Q_MOC_INCLUDE( "maininterface/mainctx.hpp")
 
 class MainCtx;
+class WheelToVLCConverter;
 
 class WindowResizer :
     public QRunnable
@@ -83,7 +84,7 @@ public slots:
     void onMouseReleased( int vlcButton );
     void onMouseDoubleClick( int vlcButton );
     void onMouseMoved( float x, float y );
-    void onMouseWheeled(const QWheelEvent& event);
+    void onMouseWheeled(int vlcButton);
     void onKeyPressed(int key, Qt::KeyboardModifiers modifiers);
     void onSurfaceSizeChanged(QSizeF size);
 
@@ -134,7 +135,6 @@ signals:
     void mouseDblClicked( int vlcButton );
     void mouseMoved( float x, float y );
     void keyPressed(int key, Qt::KeyboardModifiers modifier);
-    void mouseWheeled(const QWheelEvent& event);
 
     void videoSurfaceProviderChanged();
 
@@ -148,6 +148,8 @@ protected slots:
 private:
     QPointF m_oldHoverPos;
 
+    WheelToVLCConverter* m_wheelEventConverter = nullptr;
+
     QPointer<VideoSurfaceProvider> m_provider;
 
     std::vector<QPointer<QQuickItem>> m_parentList;


=====================================
modules/gui/qt/meson.build
=====================================
@@ -140,6 +140,7 @@ moc_headers = files(
     'util/validators.hpp',
     'util/varchoicemodel.hpp',
     'util/variables.hpp',
+    'util/vlchotkeyconverter.hpp',
     'util/vlctick.hpp',
     'util/dismiss_popup_event_filter.hpp',
     'util/list_selection_model.hpp',
@@ -462,6 +463,8 @@ some_sources = files(
     'util/variables.hpp',
     'util/vlctick.cpp',
     'util/vlctick.hpp',
+    'util/vlchotkeyconverter.cpp',
+    'util/vlchotkeyconverter.hpp',
     'util/shared_input_item.hpp',
     'util/fast_gaussian_blur_template.h',
     'util/effects_image_provider.cpp',


=====================================
modules/gui/qt/player/qml/Player.qml
=====================================
@@ -307,13 +307,13 @@ FocusScope {
 
                     onWheel: (wheel) => {
                         wheel.accepted = true
+                        wheelToVlc.qmlWheelEvent(wheel)
+                    }
 
-                        var delta = wheel.angleDelta.y
-
-                        if (delta === 0)
-                            return
+                    WheelToVLCConverter {
+                        id: wheelToVlc
 
-                        Helpers.applyVolume(Player, delta)
+                        onVlcWheelKey: (key) => MainCtx.sendVLCHotkey(key)
                     }
 
                     ColumnLayout {


=====================================
modules/gui/qt/player/qml/controlbarcontrols/VolumeWidget.qml
=====================================
@@ -286,30 +286,20 @@ T.Pane {
                 }
 
                 onWheel: (wheel) => {
-                    let delta = 0, fineControl = false
 
                     if ((Math.abs(wheel.pixelDelta.x) % 120 > 0) || (Math.abs(wheel.pixelDelta.y) % 120 > 0)) {
+                        let delta = 0
                         if (Math.abs(wheel.pixelDelta.x) > Math.abs(wheel.pixelDelta.y))
                             delta = wheel.pixelDelta.x
                         else
                             delta = wheel.pixelDelta.y
-                        fineControl = true
-                    }
-                    else if (wheel.angleDelta.x)
-                        delta = wheel.angleDelta.x
-                    else if (wheel.angleDelta.y)
-                        delta = wheel.angleDelta.y
-
-                    if (delta === 0)
-                        return
 
-                    if (wheel.inverted)
-                        delta = -delta
-
-                    if (fineControl)
+                        if (wheel.inverted)
+                            delta = -delta
                         volControl.value += 0.001 * delta
+                    }
                     else
-                        Helpers.applyVolume(Player, delta)
+                        wheelToVLC.qmlWheelEvent(wheel)
 
                     wheel.accepted = true
                 }
@@ -328,6 +318,17 @@ T.Pane {
                     else
                         volControl.value = 1.25
                 }
+
+                WheelToVLCConverter {
+                    id: wheelToVLC
+
+                    onWheelUpDown: (steps, modifiers) => {
+                        if (steps > 0)
+                            Player.setVolumeUp(steps)
+                        else
+                            Player.setVolumeDown(-steps)
+                    }
+                }
             }
         }
     }


=====================================
modules/gui/qt/util/qml/Helpers.qml
=====================================
@@ -40,20 +40,6 @@ QtObject {
         item.forceActiveFocus(reason);
     }
 
-    function applyVolume(player, delta) {
-        // Degrees to steps for standard mouse
-        delta = delta / 8 / 15
-
-        const steps = Math.ceil(Math.abs(delta))
-
-        player.muted = false
-
-        if (delta > 0)
-            player.setVolumeUp(steps)
-        else
-            player.setVolumeDown(steps)
-    }
-
     function pointInRadius(x, y, radius) {
          return (x * x + y * y < radius * radius)
     }


=====================================
modules/gui/qt/util/vlchotkeyconverter.cpp
=====================================
@@ -0,0 +1,334 @@
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "vlchotkeyconverter.hpp"
+#include "qt.hpp"
+
+#include <QKeyEvent>
+#include <QWheelEvent>
+#include <QApplication>
+#include <vlc_actions.h>
+
+/***************************************************************************
+ * Hotkeys converters
+ ***************************************************************************/
+int qtKeyModifiersToVLC( const QInputEvent& e )
+{
+    int i_keyModifiers = 0;
+    if( e.modifiers() & Qt::ShiftModifier ) i_keyModifiers |= KEY_MODIFIER_SHIFT;
+    if( e.modifiers() & Qt::AltModifier ) i_keyModifiers |= KEY_MODIFIER_ALT;
+    if( e.modifiers() & Qt::ControlModifier ) i_keyModifiers |= KEY_MODIFIER_CTRL;
+    if( e.modifiers() & Qt::MetaModifier ) i_keyModifiers |= KEY_MODIFIER_META;
+    return i_keyModifiers;
+}
+
+typedef struct
+{
+    int      qt;
+    uint32_t vlc;
+} vlc_qt_key_t;
+
+static const vlc_qt_key_t keys[] =
+    {
+        { Qt::Key_Escape,                KEY_ESC },
+        { Qt::Key_Tab,                   '\t', },
+        // Qt::Key_Backtab
+        { Qt::Key_Backspace,             '\b' },
+        { Qt::Key_Return,                '\r' },
+        { Qt::Key_Enter,                 '\r' }, // numeric pad
+        { Qt::Key_Insert,                KEY_INSERT },
+        { Qt::Key_Delete,                KEY_DELETE },
+        { Qt::Key_Pause,                 KEY_PAUSE },
+        { Qt::Key_Print,                 KEY_PRINT },
+        // Qt::Key_SysReq
+        // Qt::Key_Clear
+        { Qt::Key_Home,                  KEY_HOME },
+        { Qt::Key_End,                   KEY_END },
+        { Qt::Key_Left,                  KEY_LEFT },
+        { Qt::Key_Up,                    KEY_UP },
+        { Qt::Key_Right,                 KEY_RIGHT },
+        { Qt::Key_Down,                  KEY_DOWN },
+        { Qt::Key_PageUp,                KEY_PAGEUP },
+        { Qt::Key_PageDown,              KEY_PAGEDOWN },
+        // Qt::Key_Shift
+        // Qt::Key_Control
+        // Qt::Key_Meta
+        // Qt::Key_Alt
+        // Qt::Key_CapsLock
+        // Qt::Key_NumLock
+        // Qt::Key_ScrollLock
+        /* F1 - F35 - Qt goes to F35, VLC stops at F12 */
+        { Qt::Key_F1,                    KEY_F1 },
+        { Qt::Key_F2,                    KEY_F2 },
+        { Qt::Key_F3,                    KEY_F3 },
+        { Qt::Key_F4,                    KEY_F4 },
+        { Qt::Key_F5,                    KEY_F5 },
+        { Qt::Key_F6,                    KEY_F6 },
+        { Qt::Key_F7,                    KEY_F7 },
+        { Qt::Key_F8,                    KEY_F8 },
+        { Qt::Key_F9,                    KEY_F9 },
+        { Qt::Key_F10,                   KEY_F10 },
+        { Qt::Key_F11,                   KEY_F11 },
+        { Qt::Key_F12,                   KEY_F12 },
+        { Qt::Key_F13,                   KEY_F(13) },
+        { Qt::Key_F14,                   KEY_F(14) },
+        { Qt::Key_F15,                   KEY_F(15) },
+        { Qt::Key_F16,                   KEY_F(16) },
+        { Qt::Key_F17,                   KEY_F(17) },
+        { Qt::Key_F18,                   KEY_F(18) },
+        { Qt::Key_F19,                   KEY_F(19) },
+        { Qt::Key_F20,                   KEY_F(20) },
+        { Qt::Key_F21,                   KEY_F(21) },
+        { Qt::Key_F22,                   KEY_F(22) },
+        { Qt::Key_F23,                   KEY_F(23) },
+        { Qt::Key_F24,                   KEY_F(24) },
+        { Qt::Key_F25,                   KEY_F(25) },
+        { Qt::Key_F26,                   KEY_F(26) },
+        { Qt::Key_F27,                   KEY_F(27) },
+        { Qt::Key_F28,                   KEY_F(28) },
+        { Qt::Key_F29,                   KEY_F(29) },
+        { Qt::Key_F30,                   KEY_F(30) },
+        { Qt::Key_F31,                   KEY_F(31) },
+        { Qt::Key_F32,                   KEY_F(32) },
+        { Qt::Key_F33,                   KEY_F(33) },
+        { Qt::Key_F34,                   KEY_F(34) },
+        { Qt::Key_F35,                   KEY_F(35) },
+
+        // Qt::Key_Super_L
+        // Qt::Key_Super_R
+        { Qt::Key_Menu,                  KEY_MENU },
+        // Qt::Key_Hyper_L
+        // Qt::Key_Hyper_R
+        // Qt::Key_Help
+        // Qt::Key_Direction_L
+        // Qt::Key_Direction_R
+
+        // Qt::Key_Multi_key
+        // Qt::Key_Codeinput
+        // Qt::Key_SingleCandidate
+        // Qt::Key_MultipleCandidate
+        // Qt::Key_PreviousCandidate
+        // Qt::Key_Mode_switch
+        // Qt::Key_Kanji
+        // Qt::Key_Muhenkan
+        // Qt::Key_Henkan
+        // Qt::Key_Romaji
+        // Qt::Key_Hiragana
+        // Qt::Key_Katakana
+        // Qt::Key_Hiragana_Katakana
+        // Qt::Key_Zenkaku
+        // Qt::Key_Hankaku
+        // Qt::Key_Zenkaku_Hankaku
+        // Qt::Key_Touroku
+        // Qt::Key_Massyo
+        // Qt::Key_Kana_Lock
+        // Qt::Key_Kana_Shift
+        // Qt::Key_Eisu_Shift
+        // Qt::Key_Eisu_toggle
+        // Qt::Key_Hangul
+        // Qt::Key_Hangul_Start
+        // Qt::Key_Hangul_End
+        // Qt::Key_Hangul_Hanja
+        // Qt::Key_Hangul_Jamo
+        // Qt::Key_Hangul_Romaja
+        // Qt::Key_Hangul_Jeonja
+        // Qt::Key_Hangul_Banja
+        // Qt::Key_Hangul_PreHanja
+        // Qt::Key_Hangul_PostHanja
+        // Qt::Key_Hangul_Special
+        // Qt::Key_Dead_Grave
+        // Qt::Key_Dead_Acute
+        // Qt::Key_Dead_Circumflex
+        // Qt::Key_Dead_Tilde
+        // Qt::Key_Dead_Macron
+        // Qt::Key_Dead_Breve
+        // Qt::Key_Dead_Abovedot
+        // Qt::Key_Dead_Diaeresis
+        // Qt::Key_Dead_Abovering
+        // Qt::Key_Dead_Doubleacute
+        // Qt::Key_Dead_Caron
+        // Qt::Key_Dead_Cedilla
+        // Qt::Key_Dead_Ogonek
+        // Qt::Key_Dead_Iota
+        // Qt::Key_Dead_Voiced_Sound
+        // Qt::Key_Dead_Semivoiced_Sound
+        // Qt::Key_Dead_Belowdot
+        // Qt::Key_Dead_Hook
+        // Qt::Key_Dead_Horn
+        { Qt::Key_Back,                  KEY_BROWSER_BACK },
+        { Qt::Key_Forward,               KEY_BROWSER_FORWARD },
+        { Qt::Key_Stop,                  KEY_BROWSER_STOP },
+        { Qt::Key_Refresh,               KEY_BROWSER_REFRESH },
+        { Qt::Key_VolumeDown,            KEY_VOLUME_DOWN },
+        { Qt::Key_VolumeMute,            KEY_VOLUME_MUTE },
+        { Qt::Key_VolumeUp,              KEY_VOLUME_UP },
+        // Qt::Key_BassBoost
+        // Qt::Key_BassUp
+        // Qt::Key_BassDown
+        // Qt::Key_TrebleUp
+        // Qt::Key_TrebleDown
+        { Qt::Key_MediaPlay,             KEY_MEDIA_PLAY_PAUSE },
+        { Qt::Key_MediaStop,             KEY_MEDIA_STOP },
+        { Qt::Key_MediaPrevious,         KEY_MEDIA_PREV_TRACK },
+        { Qt::Key_MediaNext,             KEY_MEDIA_NEXT_TRACK },
+        // Qt::Key_MediaRecord
+        { Qt::Key_HomePage,              KEY_BROWSER_HOME },
+        { Qt::Key_Favorites,             KEY_BROWSER_FAVORITES },
+        { Qt::Key_Search,                KEY_BROWSER_SEARCH },
+        // Qt::Key_Standby
+        // Qt::Key_OpenUrl
+        // Qt::Key_LaunchMail
+        // Qt::Key_LaunchMedia
+        /* Qt::Key_Launch0 through Qt::Key_LaunchF */
+        /* ... */
+        { Qt::Key_Reload,                KEY_BROWSER_REFRESH },
+        };
+
+static int keycmp( const void *a, const void *b )
+{
+    const int *q = (const int *)a;
+    const vlc_qt_key_t *m = (const vlc_qt_key_t *)b;
+
+    return *q - m->qt;
+}
+
+int qtEventToVLCKey( QKeyEvent *e )
+{
+    int qtk = e->key();
+    uint32_t i_vlck = 0;
+
+    if( qtk <= 0xff )
+    {
+        /* VLC and X11 use lowercase whereas Qt uses uppercase, this
+         * method should be equal to towlower in case of latin1 */
+        if( qtk >= 'A' && qtk <= 'Z' ) i_vlck = qtk+32;
+        else if( qtk >= 0xC0 && qtk <= 0xDE && qtk != 0xD7) i_vlck = qtk+32;
+        else i_vlck = qtk;
+    }
+    else
+    {
+        const vlc_qt_key_t *map;
+
+        map = (const vlc_qt_key_t *)
+            bsearch( &qtk, (const void *)keys, sizeof(keys)/sizeof(keys[0]),
+                    sizeof(*keys), keycmp );
+        if( map != NULL )
+            i_vlck = map->vlc;
+    }
+
+    /* Handle modifiers */
+    i_vlck |= qtKeyModifiersToVLC( *e );
+    return i_vlck;
+}
+
+Qt::Orientations WheelToVLCConverter::getWheelOrientation(int x, int y)
+{
+    const qreal v_cos_deadzone = 0.45; // ~63 degrees
+    const qreal h_cos_deadzone = 0.95; // ~15 degrees
+
+    if (x == 0 && y == 0)
+        return Qt::Orientations{};
+
+    qreal cos = qFabs(x)/qSqrt(x*x + y*y);
+    if (cos < v_cos_deadzone)
+        return Qt::Vertical;
+    else if (cos > h_cos_deadzone)
+        return Qt::Horizontal;
+    return Qt::Orientations{};
+}
+
+void WheelToVLCConverter::wheelEvent( const QWheelEvent* e )
+{
+    if (!e)
+        return;
+
+    const int deltaPerStep = QWheelEvent::DefaultDeltasPerStep;
+
+    if (e->modifiers() != m_modifiers)
+    {
+        m_scrollAmount = {};
+        m_modifiers = e->modifiers();
+    }
+    if (e->buttons() != m_buttons)
+    {
+        m_scrollAmount = {};
+        m_buttons = e->buttons();
+    }
+
+    QPoint p = e->angleDelta();
+    p += m_scrollAmount;
+
+    if (p.isNull())
+        return;
+
+    int i_vlck = qtKeyModifiersToVLC(*e);  // Handle modifiers
+    Qt::Orientations orientation = getWheelOrientation(p.x(), p.y());
+    if (orientation == Qt::Vertical && qAbs(p.y()) >= deltaPerStep)
+    {
+        if (p.y() > 0)
+            i_vlck |= KEY_MOUSEWHEELUP;
+        else
+            i_vlck |= KEY_MOUSEWHEELDOWN;
+
+        const int steps = p.y() / deltaPerStep;
+
+        emit wheelUpDown(steps, e->modifiers());
+        //in practice this will emit once
+        for (int i = 0; i < qAbs(steps); i++)
+            emit vlcWheelKey(i_vlck);
+
+        m_scrollAmount.setX(0);
+        m_scrollAmount.setY(p.y() % deltaPerStep);
+
+    }
+    else if (orientation == Qt::Horizontal && qAbs(p.x()) >= deltaPerStep)
+    {
+        if (p.x() > 0)
+            i_vlck |= KEY_MOUSEWHEELLEFT;
+        else
+            i_vlck |= KEY_MOUSEWHEELRIGHT;
+
+        const int steps = p.x() / deltaPerStep;
+
+        emit wheelLeftRight(steps, e->modifiers());
+        //in practice this will emit once
+        for (int i = 0; i < qAbs(steps); i++)
+            emit vlcWheelKey(i_vlck);
+
+        m_scrollAmount.setY(0);
+        m_scrollAmount.setX(p.x() % deltaPerStep);
+    }
+    else
+    {
+        m_scrollAmount = p;
+    }
+}
+
+void WheelToVLCConverter::qmlWheelEvent( const QObject* e )
+{
+    assert(e);
+    assert(e->inherits("QQuickWheelEvent"));
+
+    QPoint pixelDelta = e->property("pixelDelta").toPoint();
+    QPoint angleDelta = e->property("angleDelta").toPoint();
+    auto buttons = Qt::MouseButtons::fromInt(e->property("buttons").toInt());
+    auto modifiers = Qt::KeyboardModifiers::fromInt(e->property("modifiers").toInt());
+    bool inverted = e->property("inverted").toBool();
+
+    QWheelEvent event({}, {}, pixelDelta, angleDelta, buttons, modifiers, Qt::ScrollPhase::NoScrollPhase, inverted);
+    wheelEvent(&event);
+}
+
+QString VLCKeyToString( unsigned val, bool locale )
+{
+    char *base = vlc_keycode2str (val, locale);
+    if (base == NULL)
+        return qfu( "" );
+
+    QString r = qfu( base );
+
+    free( base );
+    return r;
+}


=====================================
modules/gui/qt/util/vlchotkeyconverter.hpp
=====================================
@@ -0,0 +1,73 @@
+#ifndef VLC_HOTKEY_CONVERTER_HPP
+#define VLC_HOTKEY_CONVERTER_HPP
+
+#include <QObject>
+#include <QPoint>
+#include <QQmlEngine>
+
+/* VLC Key/Wheel hotkeys interactions */
+
+Q_MOC_INCLUDE("QKeyEvent")
+Q_MOC_INCLUDE("QWheelEvent")
+
+class QKeyEvent;
+class QWheelEvent;
+class QInputEvent;
+
+int qtKeyModifiersToVLC( const QInputEvent& e );
+int qtEventToVLCKey( QKeyEvent *e );
+int qtWheelEventToVLCKey( const QWheelEvent& e );
+QString VLCKeyToString( unsigned val, bool );
+
+/**
+ * @brief The WheelToVLCConverter class aggregates wheel events and
+ * emit a signal once it gathers a full scroll step, as VLC doesn't handle
+ * fractionnal scroll events
+ */
+class WheelToVLCConverter : public QObject
+{
+    Q_OBJECT
+    QML_ELEMENT
+
+public:
+    using QObject::QObject;
+
+public:
+    Q_INVOKABLE Qt::Orientations getWheelOrientation(int x, int y);
+
+signals:
+    /**
+     * @param vlcKey the VLC hotkey representation
+     */
+    void vlcWheelKey(int vlcKey);
+    /**
+     * @param steps: positive value indicated UP wheel events, negative DOWN wheel event
+     * @param modifiers are keyboard pressed modifiers
+     */
+    void wheelUpDown(int steps, Qt::KeyboardModifiers modifiers);
+    /**
+     * @param steps: positive value indicated UP wheel events, negative DOWN wheel event
+     * @param modifiers are keyboard pressed modifiers
+     */
+    void wheelLeftRight(int steps, Qt::KeyboardModifiers modifiers);
+
+public slots:
+    /**
+     * @brief qmlWheelEvent handles wheel events as emitted by QWidget
+     * @param e the wheel event
+     */
+    void wheelEvent(const QWheelEvent* e);
+
+    /**
+     * @brief qmlWheelEvent handles wheel events as emitted by QML
+     * @param wheelEvent qml wheel event
+     */
+    void qmlWheelEvent(const QObject* wheelEvent);
+
+private:
+    QPoint m_scrollAmount = {};
+    Qt::KeyboardModifiers m_modifiers = {};
+    Qt::MouseButtons m_buttons = {};
+};
+
+#endif // VLC_HOTKEY_CONVERTER_HPP


=====================================
modules/gui/qt/widgets/native/customwidgets.cpp
=====================================
@@ -32,7 +32,6 @@
 #include <QKeyEvent>
 #include <QWheelEvent>
 #include <QApplication>
-#include <vlc_actions.h>
 
 #define SPINNER_SIZE 32
 
@@ -84,257 +83,6 @@ void VLCQDial::paintEvent( QPaintEvent *event )
     painter.end();
 }
 
-/***************************************************************************
- * Hotkeys converters
- ***************************************************************************/
-int qtKeyModifiersToVLC( const QInputEvent& e )
-{
-    int i_keyModifiers = 0;
-    if( e.modifiers() & Qt::ShiftModifier ) i_keyModifiers |= KEY_MODIFIER_SHIFT;
-    if( e.modifiers() & Qt::AltModifier ) i_keyModifiers |= KEY_MODIFIER_ALT;
-    if( e.modifiers() & Qt::ControlModifier ) i_keyModifiers |= KEY_MODIFIER_CTRL;
-    if( e.modifiers() & Qt::MetaModifier ) i_keyModifiers |= KEY_MODIFIER_META;
-    return i_keyModifiers;
-}
-
-typedef struct
-{
-    int      qt;
-    uint32_t vlc;
-} vlc_qt_key_t;
-
-static const vlc_qt_key_t keys[] =
-{
-    { Qt::Key_Escape,                KEY_ESC },
-    { Qt::Key_Tab,                   '\t', },
-    // Qt::Key_Backtab
-    { Qt::Key_Backspace,             '\b' },
-    { Qt::Key_Return,                '\r' },
-    { Qt::Key_Enter,                 '\r' }, // numeric pad
-    { Qt::Key_Insert,                KEY_INSERT },
-    { Qt::Key_Delete,                KEY_DELETE },
-    { Qt::Key_Pause,                 KEY_PAUSE },
-    { Qt::Key_Print,                 KEY_PRINT },
-    // Qt::Key_SysReq
-    // Qt::Key_Clear
-    { Qt::Key_Home,                  KEY_HOME },
-    { Qt::Key_End,                   KEY_END },
-    { Qt::Key_Left,                  KEY_LEFT },
-    { Qt::Key_Up,                    KEY_UP },
-    { Qt::Key_Right,                 KEY_RIGHT },
-    { Qt::Key_Down,                  KEY_DOWN },
-    { Qt::Key_PageUp,                KEY_PAGEUP },
-    { Qt::Key_PageDown,              KEY_PAGEDOWN },
-    // Qt::Key_Shift
-    // Qt::Key_Control
-    // Qt::Key_Meta
-    // Qt::Key_Alt
-    // Qt::Key_CapsLock
-    // Qt::Key_NumLock
-    // Qt::Key_ScrollLock
-    /* F1 - F35 - Qt goes to F35, VLC stops at F12 */
-    { Qt::Key_F1,                    KEY_F1 },
-    { Qt::Key_F2,                    KEY_F2 },
-    { Qt::Key_F3,                    KEY_F3 },
-    { Qt::Key_F4,                    KEY_F4 },
-    { Qt::Key_F5,                    KEY_F5 },
-    { Qt::Key_F6,                    KEY_F6 },
-    { Qt::Key_F7,                    KEY_F7 },
-    { Qt::Key_F8,                    KEY_F8 },
-    { Qt::Key_F9,                    KEY_F9 },
-    { Qt::Key_F10,                   KEY_F10 },
-    { Qt::Key_F11,                   KEY_F11 },
-    { Qt::Key_F12,                   KEY_F12 },
-    { Qt::Key_F13,                   KEY_F(13) },
-    { Qt::Key_F14,                   KEY_F(14) },
-    { Qt::Key_F15,                   KEY_F(15) },
-    { Qt::Key_F16,                   KEY_F(16) },
-    { Qt::Key_F17,                   KEY_F(17) },
-    { Qt::Key_F18,                   KEY_F(18) },
-    { Qt::Key_F19,                   KEY_F(19) },
-    { Qt::Key_F20,                   KEY_F(20) },
-    { Qt::Key_F21,                   KEY_F(21) },
-    { Qt::Key_F22,                   KEY_F(22) },
-    { Qt::Key_F23,                   KEY_F(23) },
-    { Qt::Key_F24,                   KEY_F(24) },
-    { Qt::Key_F25,                   KEY_F(25) },
-    { Qt::Key_F26,                   KEY_F(26) },
-    { Qt::Key_F27,                   KEY_F(27) },
-    { Qt::Key_F28,                   KEY_F(28) },
-    { Qt::Key_F29,                   KEY_F(29) },
-    { Qt::Key_F30,                   KEY_F(30) },
-    { Qt::Key_F31,                   KEY_F(31) },
-    { Qt::Key_F32,                   KEY_F(32) },
-    { Qt::Key_F33,                   KEY_F(33) },
-    { Qt::Key_F34,                   KEY_F(34) },
-    { Qt::Key_F35,                   KEY_F(35) },
-
-    // Qt::Key_Super_L
-    // Qt::Key_Super_R
-    { Qt::Key_Menu,                  KEY_MENU },
-    // Qt::Key_Hyper_L
-    // Qt::Key_Hyper_R
-    // Qt::Key_Help
-    // Qt::Key_Direction_L
-    // Qt::Key_Direction_R
-
-    // Qt::Key_Multi_key
-    // Qt::Key_Codeinput
-    // Qt::Key_SingleCandidate
-    // Qt::Key_MultipleCandidate
-    // Qt::Key_PreviousCandidate
-    // Qt::Key_Mode_switch
-    // Qt::Key_Kanji
-    // Qt::Key_Muhenkan
-    // Qt::Key_Henkan
-    // Qt::Key_Romaji
-    // Qt::Key_Hiragana
-    // Qt::Key_Katakana
-    // Qt::Key_Hiragana_Katakana
-    // Qt::Key_Zenkaku
-    // Qt::Key_Hankaku
-    // Qt::Key_Zenkaku_Hankaku
-    // Qt::Key_Touroku
-    // Qt::Key_Massyo
-    // Qt::Key_Kana_Lock
-    // Qt::Key_Kana_Shift
-    // Qt::Key_Eisu_Shift
-    // Qt::Key_Eisu_toggle
-    // Qt::Key_Hangul
-    // Qt::Key_Hangul_Start
-    // Qt::Key_Hangul_End
-    // Qt::Key_Hangul_Hanja
-    // Qt::Key_Hangul_Jamo
-    // Qt::Key_Hangul_Romaja
-    // Qt::Key_Hangul_Jeonja
-    // Qt::Key_Hangul_Banja
-    // Qt::Key_Hangul_PreHanja
-    // Qt::Key_Hangul_PostHanja
-    // Qt::Key_Hangul_Special
-    // Qt::Key_Dead_Grave
-    // Qt::Key_Dead_Acute
-    // Qt::Key_Dead_Circumflex
-    // Qt::Key_Dead_Tilde
-    // Qt::Key_Dead_Macron
-    // Qt::Key_Dead_Breve
-    // Qt::Key_Dead_Abovedot
-    // Qt::Key_Dead_Diaeresis
-    // Qt::Key_Dead_Abovering
-    // Qt::Key_Dead_Doubleacute
-    // Qt::Key_Dead_Caron
-    // Qt::Key_Dead_Cedilla
-    // Qt::Key_Dead_Ogonek
-    // Qt::Key_Dead_Iota
-    // Qt::Key_Dead_Voiced_Sound
-    // Qt::Key_Dead_Semivoiced_Sound
-    // Qt::Key_Dead_Belowdot
-    // Qt::Key_Dead_Hook
-    // Qt::Key_Dead_Horn
-    { Qt::Key_Back,                  KEY_BROWSER_BACK },
-    { Qt::Key_Forward,               KEY_BROWSER_FORWARD },
-    { Qt::Key_Stop,                  KEY_BROWSER_STOP },
-    { Qt::Key_Refresh,               KEY_BROWSER_REFRESH },
-    { Qt::Key_VolumeDown,            KEY_VOLUME_DOWN },
-    { Qt::Key_VolumeMute,            KEY_VOLUME_MUTE },
-    { Qt::Key_VolumeUp,              KEY_VOLUME_UP },
-    // Qt::Key_BassBoost
-    // Qt::Key_BassUp
-    // Qt::Key_BassDown
-    // Qt::Key_TrebleUp
-    // Qt::Key_TrebleDown
-    { Qt::Key_MediaPlay,             KEY_MEDIA_PLAY_PAUSE },
-    { Qt::Key_MediaStop,             KEY_MEDIA_STOP },
-    { Qt::Key_MediaPrevious,         KEY_MEDIA_PREV_TRACK },
-    { Qt::Key_MediaNext,             KEY_MEDIA_NEXT_TRACK },
-    // Qt::Key_MediaRecord
-    { Qt::Key_HomePage,              KEY_BROWSER_HOME },
-    { Qt::Key_Favorites,             KEY_BROWSER_FAVORITES },
-    { Qt::Key_Search,                KEY_BROWSER_SEARCH },
-    // Qt::Key_Standby
-    // Qt::Key_OpenUrl
-    // Qt::Key_LaunchMail
-    // Qt::Key_LaunchMedia
-    /* Qt::Key_Launch0 through Qt::Key_LaunchF */
-    /* ... */
-    { Qt::Key_Reload,                KEY_BROWSER_REFRESH },
-};
-
-static int keycmp( const void *a, const void *b )
-{
-    const int *q = (const int *)a;
-    const vlc_qt_key_t *m = (const vlc_qt_key_t *)b;
-
-    return *q - m->qt;
-}
-
-int qtEventToVLCKey( QKeyEvent *e )
-{
-    int qtk = e->key();
-    uint32_t i_vlck = 0;
-
-    if( qtk <= 0xff )
-    {
-        /* VLC and X11 use lowercase whereas Qt uses uppercase, this
-         * method should be equal to towlower in case of latin1 */
-        if( qtk >= 'A' && qtk <= 'Z' ) i_vlck = qtk+32;
-        else if( qtk >= 0xC0 && qtk <= 0xDE && qtk != 0xD7) i_vlck = qtk+32;
-        else i_vlck = qtk;
-    }
-    else
-    {
-        const vlc_qt_key_t *map;
-
-        map = (const vlc_qt_key_t *)
-              bsearch( &qtk, (const void *)keys, sizeof(keys)/sizeof(keys[0]),
-                       sizeof(*keys), keycmp );
-        if( map != NULL )
-            i_vlck = map->vlc;
-    }
-
-    /* Handle modifiers */
-    i_vlck |= qtKeyModifiersToVLC( *e );
-    return i_vlck;
-}
-
-int qtWheelEventToVLCKey( const QWheelEvent& e )
-{
-    const qreal v_cos_deadzone = 0.45; // ~63 degrees
-    const qreal h_cos_deadzone = 0.95; // ~15 degrees
-
-    int i_vlck = qtKeyModifiersToVLC(e);  // Handle modifiers
-
-    QPoint p = e.angleDelta();
-    if (!p.isNull())
-    {
-        qreal cos = qFabs(p.x())/qSqrt(qPow(p.x(), 2) + qPow(p.y(), 2));
-
-        if (cos < v_cos_deadzone)
-        {
-            if (p.y() > 0) i_vlck |= KEY_MOUSEWHEELUP;
-            else           i_vlck |= KEY_MOUSEWHEELDOWN;
-        }
-        else if (cos > h_cos_deadzone)
-        {
-            if (p.x() > 0) i_vlck |= KEY_MOUSEWHEELLEFT;
-            else           i_vlck |= KEY_MOUSEWHEELRIGHT;
-        }
-    }
-
-    return i_vlck;
-}
-
-QString VLCKeyToString( unsigned val, bool locale )
-{
-    char *base = vlc_keycode2str (val, locale);
-    if (base == NULL)
-        return qfu( "" );
-
-    QString r = qfu( base );
-
-    free( base );
-    return r;
-}
-
 /* Animated Icon implementation */
 SpinningIcon::SpinningIcon( QWidget *parent ) : QLabel( parent )
 {


=====================================
modules/gui/qt/widgets/native/customwidgets.hpp
=====================================
@@ -109,15 +109,4 @@ public:
     YesNoCheckBox( QWidget *parent );
 };
 
-/* VLC Key/Wheel hotkeys interactions */
-
-class QKeyEvent;
-class QWheelEvent;
-class QInputEvent;
-
-int qtKeyModifiersToVLC( const QInputEvent& e );
-int qtEventToVLCKey( QKeyEvent *e );
-int qtWheelEventToVLCKey( const QWheelEvent& e );
-QString VLCKeyToString( unsigned val, bool );
-
 #endif



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/2cfdc164d1f407b1cbb810521db1c71507061682...529bd47c2ffff0c851daaa1cf72ec611a174aab2

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/2cfdc164d1f407b1cbb810521db1c71507061682...529bd47c2ffff0c851daaa1cf72ec611a174aab2
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list