[vlc-devel] [RFC 61/82] qml: provide a base class for key navigable widgets

Pierre Lamot pierre at videolabs.io
Fri Feb 1 14:02:05 CET 2019


---
 modules/gui/qt/Makefile.am                    |  1 +
 .../gui/qt/qml/utils/NavigableFocusScope.qml  | 56 +++++++++++++++++++
 modules/gui/qt/vlc.qrc                        |  3 +
 3 files changed, 60 insertions(+)
 create mode 100644 modules/gui/qt/qml/utils/NavigableFocusScope.qml

diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index edcd74e6b8..7669d61b95 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -522,6 +522,7 @@ libqt_plugin_la_RES = \
 	gui/qt/pixmaps/valid.svg \
 	gui/qt/pixmaps/search_clear.svg \
 	gui/qt/pixmaps/lock.svg \
+	gui/qt/qml/utils/NavigableFocusScope.qml \
 	gui/qt/qml/style/qmldir \
 	gui/qt/qml/style/VLCIcons.qml \
 	gui/qt/qml/style/VLCStyle.qml \
diff --git a/modules/gui/qt/qml/utils/NavigableFocusScope.qml b/modules/gui/qt/qml/utils/NavigableFocusScope.qml
new file mode 100644
index 0000000000..7b9fe78814
--- /dev/null
+++ b/modules/gui/qt/qml/utils/NavigableFocusScope.qml
@@ -0,0 +1,56 @@
+/*****************************************************************************
+ * Copyright (C) 2019 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * ( at your option ) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+import QtQuick 2.11
+import QtQuick.Controls 2.4
+
+/*
+ * This class is designed to be inherited, It provide basic key handling to navigate between view
+ * classes that inherits this class should provide something like
+ * Keys.onPressed {
+ *   //custom key handling
+ *   defaultKeyAction(event, index)
+ * }
+ */
+FocusScope {
+    signal actionUp( int index )
+    signal actionDown( int index )
+    signal actionLeft( int index )
+    signal actionRight( int index )
+    signal actionCancel( int index )
+
+    function defaultKeyAction(event, index) {
+        if (event.accepted)
+            return
+        if ( event.key === Qt.Key_Down || event.matches(StandardKey.MoveToNextLine) ||event.matches(StandardKey.SelectNextLine) ) {
+            event.accepted = true
+            actionDown( index )
+        } else if ( event.key === Qt.Key_Up || event.matches(StandardKey.MoveToPreviousLine) ||event.matches(StandardKey.SelectPreviousLine) ) {
+            event.accepted = true
+            actionUp( index  )
+        } else if (event.key === Qt.Key_Right || event.matches(StandardKey.MoveToNextChar) ) {
+            event.accepted = true
+            actionRight( index )
+        } else if (event.key === Qt.Key_Left || event.matches(StandardKey.MoveToPreviousChar) ) {
+            event.accepted = true
+            actionLeft( index )
+        } else if ( event.key === Qt.Key_Back || event.key === Qt.Key_Cancel || event.matches(StandardKey.Back) || event.matches(StandardKey.Cancel)) {
+            event.accepted = true
+            actionCancel( index )
+        }
+    }
+}
diff --git a/modules/gui/qt/vlc.qrc b/modules/gui/qt/vlc.qrc
index a9f053f4db..4ab1340161 100644
--- a/modules/gui/qt/vlc.qrc
+++ b/modules/gui/qt/vlc.qrc
@@ -158,6 +158,9 @@
         <file alias="addon_red.svg">pixmaps/addons/addon_red.svg</file>
         <file alias="addon_yellow.svg">pixmaps/addons/addon_yellow.svg</file>
     </qresource>
+    <qresource prefix="/utils">
+        <file alias="NavigableFocusScope.qml">qml/utils/NavigableFocusScope.qml</file>
+    </qresource>
     <qresource prefix="/style">
         <file alias="qmldir">qml/style/qmldir</file>
         <file alias="VLCStyle.qml">qml/style/VLCStyle.qml</file>
-- 
2.19.1



More information about the vlc-devel mailing list