[vlc-devel] [PATCH 15/49] qml: add navigable row layout

Pierre Lamot pierre at videolabs.io
Fri Oct 11 15:17:39 CEST 2019


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

diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index 833be84540..f0cbe210ae 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -589,6 +589,7 @@ libqt_plugin_la_QML = \
 	gui/qt/qml/utils/MultiCoverPreview.qml \
 	gui/qt/qml/utils/ExpandGridView.qml \
 	gui/qt/qml/utils/NavigableFocusScope.qml \
+	gui/qt/qml/utils/NavigableRow.qml \
 	gui/qt/qml/utils/KeyNavigableGridView.qml \
 	gui/qt/qml/utils/KeyNavigableListView.qml \
 	gui/qt/qml/utils/KeyNavigableTableView.qml \
diff --git a/modules/gui/qt/qml/utils/NavigableRow.qml b/modules/gui/qt/qml/utils/NavigableRow.qml
new file mode 100644
index 0000000000..7e708c6079
--- /dev/null
+++ b/modules/gui/qt/qml/utils/NavigableRow.qml
@@ -0,0 +1,117 @@
+/*****************************************************************************
+ * 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 org.videolan.vlc 0.1
+
+
+NavigableFocusScope {
+    id: navigableRow
+
+    property alias model: rowRepeater.model
+    property alias delegate: rowRepeater.delegate
+
+    width: row.width
+    height: row.height
+    property alias implicitWidth: row.implicitWidth
+    property alias implicitHeight: row.implicitHeight
+
+    Keys.priority: Keys.AfterItem
+    Keys.onPressed: defaultKeyAction(event, 0)
+
+    navigable: _countEnabled > 0
+    property int _countEnabled: 0
+
+    Component {
+        id: enabledConnection
+        Connections {
+            onEnabledChanged: {
+                navigableRow._countEnabled += ( target.enabled ? 1 : -1)
+            }
+        }
+    }
+
+    Row {
+        id: row
+
+        Repeater{
+            id: rowRepeater
+
+            onItemAdded: {
+                if (item.enabled) {
+                    navigableRow._countEnabled += 1
+                }
+                enabledConnection.createObject(item, {target: item})
+
+                item.Keys.pressed.connect(function(event) {
+                    if (event.accepted)
+                        return
+                    var i = index
+                    if (event.key ===  Qt.Key_Left) {
+                        do {
+                            i--;
+                        } while (i >= 0 && (!rowRepeater.itemAt(i).enabled || !rowRepeater.itemAt(i).visible))
+
+                        if (i === -1) {
+                            navigableRow.navigationLeft()
+                        } else {
+                            rowRepeater.itemAt(i).forceActiveFocus()
+                        }
+                        event.accepted = true
+
+                    } else if (event.key ===  Qt.Key_Right) {
+                        do {
+                            i++;
+                        } while (i < rowRepeater.count && (!rowRepeater.itemAt(i).enabled || !rowRepeater.itemAt(i).visible))
+
+                        if (i === rowRepeater.count) {
+                            navigableRow.navigationRight()
+                        } else {
+                            rowRepeater.itemAt(i).forceActiveFocus()
+                        }
+                        event.accepted = true
+                    }
+                })
+            }
+
+            onItemRemoved:  {
+                if (item.enabled) {
+                    navigableRow._countEnabled -= 1
+                }
+            }
+        }
+    }
+
+    onActiveFocusChanged: {
+        if (activeFocus) {
+            var firstWithoutFocus = undefined
+            for (var i = 0 ; i < rowRepeater.count; i++) {
+                var item= rowRepeater.itemAt(i)
+                if (item.enabled && item.visible) {
+                    //already an item with the focus, keep it this way
+                    if (item.focus )
+                        return
+                    else if (!firstWithoutFocus)
+                        firstWithoutFocus = item
+                }
+            }
+            if (firstWithoutFocus)
+                firstWithoutFocus.focus = true
+            return
+        }
+    }
+}
diff --git a/modules/gui/qt/vlc.qrc b/modules/gui/qt/vlc.qrc
index 0021b6f912..f7b28be11a 100644
--- a/modules/gui/qt/vlc.qrc
+++ b/modules/gui/qt/vlc.qrc
@@ -205,6 +205,7 @@
         <file alias="RoundImage.qml">qml/utils/RoundImage.qml</file>
         <file alias="VideoQualityLabel.qml">qml/utils/VideoQualityLabel.qml</file>
         <file alias="VideoProgressBar.qml">qml/utils/VideoProgressBar.qml</file>
+        <file alias="NavigableRow.qml">qml/utils/NavigableRow.qml</file>
         <file alias="TabButtonExt.qml">qml/utils/TabButtonExt.qml</file>
     </qresource>
     <qresource prefix="/mediacenter">
-- 
2.20.1



More information about the vlc-devel mailing list