[vlc-devel] [PATCH 25/29] qml: add MCNetworksSection and MCNetworksSectionSelectableDM

Abel Tesfaye abeltesfaye45 at gmail.com
Tue Aug 20 12:42:42 CEST 2019


From: Abel Tesfaye <Abeltesfaye45 at gmail.com>

---
 modules/gui/qt/Makefile.am                    |   2 +
 .../qt/qml/mediacenter/MCNetworksSection.qml  | 143 ++++++++++++++++++
 .../MCNetworksSectionSelectableDM.qml         |  79 ++++++++++
 modules/gui/qt/vlc.qrc                        |   2 +
 4 files changed, 226 insertions(+)
 create mode 100644 modules/gui/qt/qml/mediacenter/MCNetworksSection.qml
 create mode 100644 modules/gui/qt/qml/mediacenter/MCNetworksSectionSelectableDM.qml

diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index 4631705d7a..fdc84ac2b4 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -609,6 +609,8 @@ libqt_plugin_la_QML = \
 	gui/qt/qml/mediacenter/MCVideoDisplay.qml \
 	gui/qt/qml/mediacenter/MCVideoListDisplay.qml \
 	gui/qt/qml/mediacenter/MCNetworkDisplay.qml \
+	gui/qt/qml/mediacenter/MCNetworksSection.qml \
+	gui/qt/qml/mediacenter/MCNetworksSectionSelectableDM.qml \
 	gui/qt/qml/mediacenter/MusicAlbumsDisplay.qml \
 	gui/qt/qml/mediacenter/MusicAlbumsGridExpandDelegate.qml \
 	gui/qt/qml/mediacenter/MusicArtistsDisplay.qml \
diff --git a/modules/gui/qt/qml/mediacenter/MCNetworksSection.qml b/modules/gui/qt/qml/mediacenter/MCNetworksSection.qml
new file mode 100644
index 0000000000..8d255d6058
--- /dev/null
+++ b/modules/gui/qt/qml/mediacenter/MCNetworksSection.qml
@@ -0,0 +1,143 @@
+/*****************************************************************************
+ * 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
+import QtQml.Models 2.2
+import QtQml 2.11
+import "qrc:///utils/" as Utils
+import "qrc:///style/"
+
+Rectangle {
+    id: networkSection
+
+    property var selectableDelegateModel: null
+    property alias text: sectionSeparator.text
+    property alias currentIndex: sectionListView.currentIndex
+
+    signal actionDown(int index)
+    signal actionUp(int index)
+
+    function shiftX(index){
+        return sectionListView.shiftX(index)
+    }
+    function adjustTopFlickableViewBound(){
+
+        const itemTop = networkSection.y + sectionListView.currentItem.y
+        const itemBottom = sectionSeparator.height + networkSection.y + sectionListView.currentItem.y + sectionListView.currentItem.height
+        if (itemTop < flickable.contentY)
+            flickable.contentY = itemTop
+
+        else if (itemBottom > (flickable.contentY + flickable.height))
+            flickable.contentY = itemBottom - flickable.height
+    }
+    anchors {
+        left: parent.left
+        right: parent.right
+    }
+    implicitHeight: childrenRect.height
+    color: "transparent"
+    enabled: visible
+
+    /*
+     *define the intial position/selection
+     * This is done on activeFocus rather than Component.onCompleted because delegateModel.
+     * selectedGroup update itself after this event
+     */
+    onActiveFocusChanged: {
+        if(activeFocus){
+            sectionListView.forceActiveFocus()
+        }
+
+        if (networkSection.selectableDelegateModel.items.count > 0 && networkSection.selectableDelegateModel.selectedGroup.count === 0) {
+            var initialIndex = 0
+            if (view[networkSection.selectableDelegateModel.viewIndexPropertyName] !== -1)
+                initialIndex = view.currentIndexProvider
+            networkSection.selectableDelegateModel.items.get(initialIndex).inSelected = true
+            view[networkSection.selectableDelegateModel.viewIndexPropertyName] = initialIndex
+        }
+
+        adjustTopFlickableViewBound()
+    }
+
+    Utils.LabelSeparator {
+        id: sectionSeparator
+    }
+   Rectangle{
+       id: sectionRect
+       anchors {
+           left: parent.left
+           right: parent.right
+           top: sectionSeparator.bottom
+       }
+       height: gridRect.height
+       color: "transparent"
+
+    Rectangle {
+        id: gridRect
+        color: VLCStyle.colors.bg
+        anchors.left: parent.left
+        anchors.right: parent.right
+        anchors.leftMargin: VLCStyle.margin_large
+        anchors.rightMargin: VLCStyle.margin_large
+        height: sectionListView.contentHeight
+        Utils.KeyNavigableListView {
+            id: sectionListView
+            anchors.fill: parent
+
+            model: networkSection.selectableDelegateModel.parts.grid
+            modelCount: networkSection.selectableDelegateModel.items.count
+            currentIndex: networkSection.currentIndex
+            orientation: ListView.Horizontal
+            onCurrentItemChanged: adjustTopFlickableViewBound()
+
+            onSelectAll: networkSection.selectableDelegateModel.selectAll()
+            onSelectionUpdated:  networkSection.selectableDelegateModel.updateSelection( keyModifiers, oldIndex, newIndex )
+            onActionAtIndex: networkSection.selectableDelegateModel.actionAtIndex(index)
+
+            onActionLeft: root.actionLeft(index)
+            onActionRight: root.actionRight(index)
+            onActionUp: networkSection.actionUp(index)
+            onActionDown: networkSection.actionDown(index)
+            onActionCancel: root.actionCancel(index)
+
+        }
+
+    }
+
+    Utils.RoundButton{
+        id: leftBtn
+        anchors.verticalCenter: parent.verticalCenter
+        anchors.left: parent.left
+        text:"<"
+        onClicked: sectionListView.prevPage()
+        visible: sectionListView.contentWidth > sectionListView.width
+        enabled: visible
+    }
+
+
+    Utils.RoundButton{
+        id: rightBtn
+        anchors.verticalCenter: parent.verticalCenter
+        anchors.right: parent.right
+        text:">"
+        onClicked: sectionListView.nextPage()
+        visible: sectionListView.contentWidth > sectionListView.width
+        enabled: visible
+    }
+   }
+}
diff --git a/modules/gui/qt/qml/mediacenter/MCNetworksSectionSelectableDM.qml b/modules/gui/qt/qml/mediacenter/MCNetworksSectionSelectableDM.qml
new file mode 100644
index 0000000000..a113eb01d2
--- /dev/null
+++ b/modules/gui/qt/qml/mediacenter/MCNetworksSectionSelectableDM.qml
@@ -0,0 +1,79 @@
+/*****************************************************************************
+ * 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
+import QtQml.Models 2.2
+import QtQml 2.11
+
+import org.videolan.vlc 0.1
+import org.videolan.medialib 0.1
+
+import "qrc:///utils/" as Utils
+import "qrc:///style/"
+
+Utils.SelectableDelegateModel {
+    id: delegateModel
+    property string viewIndexPropertyName: "currentIndex"
+    delegate: Package {
+        id: element
+        Loader {
+            id: delegateLoaderGrid
+            focus: true
+            Package.name: "grid"
+            source: model.type == MLNetworkModel.TYPE_FILE ?
+                        "qrc:///mediacenter/NetworkFileDisplayGrid.qml" :
+                        "qrc:///mediacenter/NetworkDriveDisplayGrid.qml";
+        }
+
+        Loader {
+            id: delegateLoader
+            focus: true
+            Package.name: "list"
+            source: model.type == MLNetworkModel.TYPE_FILE ?
+                        "qrc:///mediacenter/NetworkFileDisplay.qml" :
+                        "qrc:///mediacenter/NetworkDriveDisplay.qml";
+        }
+        Connections {
+            target: delegateLoader.item
+            onActionLeft: root.actionLeft(0)
+            onActionRight: root.actionRight(0)
+        }
+
+    }
+
+    function actionAtIndex(index) {
+        if ( delegateModel.selectedGroup.count > 1 ) {
+            var list = []
+            for (var i = 0; i < delegateModel.selectedGroup.count; i++) {
+                var type = delegateModel.selectedGroup.get(i).model.type;
+                var mrl = delegateModel.selectedGroup.get(i).model.mrl;
+                if (type == MLNetworkModel.TYPE_FILE)
+                    list.push(mrl)
+            }
+            medialib.addAndPlay( list )
+        } else {
+            if (delegateModel.items.get(index).model.type != MLNetworkModel.TYPE_FILE)  {
+                console.log("not file")
+                root.tree = delegateModel.items.get(index).model.tree
+                history.push(["mc", "network", { tree: delegateModel.items.get(index).model.tree }], History.Go);
+            } else {
+                medialib.addAndPlay( delegateModel.items.get(index).model.mrl );
+            }
+        }
+    }
+}
diff --git a/modules/gui/qt/vlc.qrc b/modules/gui/qt/vlc.qrc
index 778c0159ad..ef72a51955 100644
--- a/modules/gui/qt/vlc.qrc
+++ b/modules/gui/qt/vlc.qrc
@@ -209,6 +209,8 @@
         <file alias="MCMusicDisplay.qml">qml/mediacenter/MCMusicDisplay.qml</file>
         <file alias="MCVideoDisplay.qml">qml/mediacenter/MCVideoDisplay.qml</file>
         <file alias="MCNetworkDisplay.qml">qml/mediacenter/MCNetworkDisplay.qml</file>
+        <file alias="MCNetworksSection.qml">qml/mediacenter/MCNetworksSection.qml</file>
+        <file alias="MCNetworksSectionSelectableDM.qml">qml/mediacenter/MCNetworksSectionSelectableDM.qml</file>
         <file alias="MusicAlbumsDisplay.qml">qml/mediacenter/MusicAlbumsDisplay.qml</file>
         <file alias="MusicAlbumsGridExpandDelegate.qml">qml/mediacenter/MusicAlbumsGridExpandDelegate.qml</file>
         <file alias="MusicArtistsDisplay.qml">qml/mediacenter/MusicArtistsDisplay.qml</file>
-- 
2.21.0



More information about the vlc-devel mailing list