[vlc-commits] qml: adapt new sort behavior to playlist overlay menu

Fatih Uzunoglu git at videolan.org
Thu Oct 15 10:32:49 CEST 2020


vlc | branch: master | Fatih Uzunoglu <fuzun54 at outlook.com> | Fri Oct  9 19:56:38 2020 +0300| [0a5ed1035db94b15ea2c6b8d4ddf8eca0bd32e5e] | committer: Pierre Lamot

qml: adapt new sort behavior to playlist overlay menu

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=0a5ed1035db94b15ea2c6b8d4ddf8eca0bd32e5e
---

 modules/gui/qt/playlist/qml/PlaylistListView.qml | 127 ++++++++++++++++-------
 modules/gui/qt/playlist/qml/PlaylistMenu.qml     |  61 +++++++++--
 modules/gui/qt/playlist/qml/PlaylistToolbar.qml  |   4 +-
 3 files changed, 139 insertions(+), 53 deletions(-)

diff --git a/modules/gui/qt/playlist/qml/PlaylistListView.qml b/modules/gui/qt/playlist/qml/PlaylistListView.qml
index c99b5577f5..b833e42168 100644
--- a/modules/gui/qt/playlist/qml/PlaylistListView.qml
+++ b/modules/gui/qt/playlist/qml/PlaylistListView.qml
@@ -45,6 +45,18 @@ Widgets.NavigableFocusScope {
 
     VLCColors {id: vlcNightColors; state: "night"}
 
+    function sortPL(key) {
+        if (mainPlaylistController.sortKey !== key) {
+            mainPlaylistController.setSortOrder(PlaylistControllerModel.SORT_ORDER_ASC)
+            mainPlaylistController.setSortKey(key)
+        }
+        else {
+            mainPlaylistController.switchSortOrder()
+        }
+
+        mainPlaylistController.sort()
+    }
+
     Rectangle {
         id: parentRect
         anchors.fill: parent
@@ -95,25 +107,72 @@ Widgets.NavigableFocusScope {
             Action { id:moveTracksAction;   text: i18n.qtr("Move Selection");            onTriggered: view.mode = "move";                                                                                                           }
             Action { id:deleteAction;       text: i18n.qtr("Remove Selected");           onTriggered: view.onDelete();                                                                                                              }
 
-            //sortmenu
-            Action { id: sortTitleAction;   text: i18n.qtr("Title");
-                onTriggered: mainPlaylistController.sort(PlaylistControllerModel.SORT_KEY_TITLE, PlaylistControllerModel.SORT_ORDER_ASC)}
-            Action { id: sortDurationAction;text: i18n.qtr("Duration");
-                onTriggered: mainPlaylistController.sort(PlaylistControllerModel.SORT_KEY_DURATION, PlaylistControllerModel.SORT_ORDER_ASC)}
-            Action { id: sortArtistAction;  text: i18n.qtr("Artist");
-                onTriggered: mainPlaylistController.sort(PlaylistControllerModel.SORT_KEY_ARTIST, PlaylistControllerModel.SORT_ORDER_ASC)}
-            Action { id: sortAlbumAction;   text: i18n.qtr("Album");
-                onTriggered: mainPlaylistController.sort(PlaylistControllerModel.SORT_KEY_ALBUM, PlaylistControllerModel.SORT_ORDER_ASC)}
-            Action { id: sortGenreAction;   text: i18n.qtr("Genre");
-                onTriggered: mainPlaylistController.sort(PlaylistControllerModel.SORT_KEY_GENRE, PlaylistControllerModel.SORT_ORDER_ASC)}
-            Action { id: sortDateAction;    text: i18n.qtr("Date");
-                onTriggered: mainPlaylistController.sort(PlaylistControllerModel.SORT_KEY_DATE, PlaylistControllerModel.SORT_ORDER_ASC)}
-            Action { id: sortTrackAction;   text: i18n.qtr("Track Number");
-                onTriggered: mainPlaylistController.sort(PlaylistControllerModel.SORT_KEY_TRACK_NUMBER, PlaylistControllerModel.SORT_ORDER_ASC)}
-            Action { id: sortURLAction;     text: i18n.qtr("URL");
-                onTriggered: mainPlaylistController.sort(PlaylistControllerModel.SORT_KEY_URL, PlaylistControllerModel.SORT_ORDER_ASC)}
-            Action { id: sortRatingAction;  text: i18n.qtr("Rating");
-                onTriggered: mainPlaylistController.sort(PlaylistControllerModel.SORT_KEY_RATING, PlaylistControllerModel.SORT_ORDER_ASC)}
+            readonly property var sortList: [sortTitleAction,
+                                            sortDurationAction,
+                                            sortArtistAction,
+                                            sortAlbumAction,
+                                            sortGenreAction,
+                                            sortDateAction,
+                                            sortTrackAction,
+                                            sortURLAction,
+                                            sortRatingAction]
+
+            Connections {
+                id: plControllerConnections
+                target: mainPlaylistController
+
+                property alias sortList: overlayMenu.sortList
+
+                function setMark() {
+                    for (var i = 0; i < sortList.length; i++) {
+                        if(sortList[i].key === mainPlaylistController.sortKey) {
+                            sortList[i].sortActiveMark = "✓"
+                            sortList[i].sortOrderMark  = (mainPlaylistController.sortOrder === PlaylistControllerModel.SORT_ORDER_ASC ? "↓" : "↑")
+                            continue
+                        }
+
+                        sortList[i].sortActiveMark = ""
+                        sortList[i].sortOrderMark  = ""
+                    }
+                }
+
+                onSortOrderChanged: {
+                    plControllerConnections.setMark()
+                }
+
+                onSortKeyChanged: {
+                    plControllerConnections.setMark()
+                }
+            }
+
+            // sortmenu
+            Action { id: sortTitleAction;   text: i18n.qtr("Title"); onTriggered: root.sortPL(key);
+                readonly property int key: PlaylistControllerModel.SORT_KEY_TITLE;
+                property string sortActiveMark; property string sortOrderMark }
+            Action { id: sortDurationAction; text: i18n.qtr("Duration"); onTriggered: root.sortPL(key);
+                readonly property int key: PlaylistControllerModel.SORT_KEY_DURATION
+                property string sortActiveMark; property string sortOrderMark }
+            Action { id: sortArtistAction;  text: i18n.qtr("Artist"); onTriggered: root.sortPL(key);
+                readonly property int key: PlaylistControllerModel.SORT_KEY_ARTIST
+                property string sortActiveMark; property string sortOrderMark }
+            Action { id: sortAlbumAction;   text: i18n.qtr("Album"); onTriggered: root.sortPL(key);
+                readonly property int key: PlaylistControllerModel.SORT_KEY_ALBUM
+                property string sortActiveMark; property string sortOrderMark }
+            Action { id: sortGenreAction;   text: i18n.qtr("Genre"); onTriggered: root.sortPL(key);
+                readonly property int key: PlaylistControllerModel.SORT_KEY_GENRE
+                property string sortActiveMark; property string sortOrderMark }
+            Action { id: sortDateAction;    text: i18n.qtr("Date"); onTriggered: root.sortPL(key);
+                readonly property int key: PlaylistControllerModel.SORT_KEY_DATE
+                property string sortActiveMark; property string sortOrderMark }
+            Action { id: sortTrackAction;   text: i18n.qtr("Track Number"); onTriggered: root.sortPL(key);
+                readonly property int key: PlaylistControllerModel.SORT_KEY_TRACK_NUMBER
+                property string sortActiveMark; property string sortOrderMark }
+            Action { id: sortURLAction;     text: i18n.qtr("URL"); onTriggered: root.sortPL(key);
+                readonly property int key: PlaylistControllerModel.SORT_KEY_URL
+                property string sortActiveMark; property string sortOrderMark }
+            Action { id: sortRatingAction;  text: i18n.qtr("Rating"); onTriggered: root.sortPL(key);
+                readonly property int key: PlaylistControllerModel.SORT_KEY_RATING
+                property string sortActiveMark; property string sortOrderMark }
 
             models: {
                 "rootmenu" : {
@@ -159,17 +218,7 @@ Widgets.NavigableFocusScope {
                 },
                 "sortmenu" :{
                     title: i18n.qtr("Sort Playlist"),
-                    entries:  [
-                        sortTitleAction,
-                        sortDurationAction,
-                        sortArtistAction,
-                        sortAlbumAction,
-                        sortGenreAction,
-                        sortDateAction,
-                        sortTrackAction,
-                        sortURLAction,
-                        sortRatingAction,
-                    ]
+                    entries: sortList
                 }
             }
         }
@@ -619,19 +668,19 @@ Widgets.NavigableFocusScope {
                 height: VLCStyle.heightBar_normal
                 visible: !(infoText.text === "")
 
-	            RectangularGlow {
-	                anchors.top: parent.top
-	                anchors.bottom: parent.bottom
-	                anchors.horizontalCenter: parent.horizontalCenter
+                RectangularGlow {
+                    anchors.top: parent.top
+                    anchors.bottom: parent.bottom
+                    anchors.horizontalCenter: parent.horizontalCenter
 
                     width: infoText.width + VLCStyle.dp(18, VLCStyle.scale)
                     height: infoText.height + VLCStyle.dp(12, VLCStyle.scale)
 
-	                glowRadius: 2
-	                cornerRadius: 10
-	                spread: 0.1
-	                color: _colors.glowColorBanner
-	            }
+                    glowRadius: 2
+                    cornerRadius: 10
+                    spread: 0.1
+                    color: _colors.glowColorBanner
+                }
 
                 Label {
                     id: infoText
diff --git a/modules/gui/qt/playlist/qml/PlaylistMenu.qml b/modules/gui/qt/playlist/qml/PlaylistMenu.qml
index 24ec66db57..9a58edea5c 100644
--- a/modules/gui/qt/playlist/qml/PlaylistMenu.qml
+++ b/modules/gui/qt/playlist/qml/PlaylistMenu.qml
@@ -142,12 +142,27 @@ Widgets.NavigableFocusScope {
                 icon.width: VLCStyle.fontHeight_normal
                 icon.height: VLCStyle.fontHeight_normal
 
-                contentItem: Label {
-                    text: control.text
-                    color: "white"
-                    font.pixelSize: VLCStyle.fontSize_normal
-                    leftPadding: VLCStyle.icon_small
+                contentItem: RowLayout {
+                    width: control.width
 
+                    Label {
+                        Layout.fillWidth: true
+
+                        text: control.text
+                        color: "white"
+                        font.pixelSize: VLCStyle.fontSize_normal
+                        leftPadding: VLCStyle.icon_small
+                    }
+
+                    Loader {
+                        active: currentModel === "sortmenu"
+
+                        sourceComponent: Label {
+                            text: modelData.sortOrderMark
+                            color: "white"
+                            font.pixelSize: VLCStyle.fontSize_normal
+                        }
+                    }
                 }
 
                 background: Rectangle {
@@ -155,18 +170,42 @@ Widgets.NavigableFocusScope {
                     implicitHeight: VLCStyle.fontHeight_normal
                     color: control.activeFocus ? "orange" : "transparent"
 
-                    ColorImage {
+                    Item {
+                        id: leftSide
                         width: control.icon.width
                         height: control.icon.height
 
                         x: control.mirrored ? control.width - width - control.rightPadding : control.leftPadding
                         y: control.topPadding + (control.availableHeight - height) / 2
 
-                        source: control.checked ? "qrc:/qt-project.org/imports/QtQuick/Controls.2/images/check.png"
-                            : modelData.icon.source ? modelData.icon.source
-                            : ""
-                        visible: true
-                        color: control.enabled ? VLCStyle.colors.playerFg : VLCStyle.colors.playerFgInactive
+                        Loader {
+                            id: leftTextLoader
+                            active: currentModel === "sortmenu"
+
+                            anchors.fill: parent
+
+                            sourceComponent: Label {
+                                text: modelData.sortActiveMark
+                                color: "white"
+                                font.pixelSize: VLCStyle.fontSize_normal
+                            }
+                        }
+
+                        Loader {
+                            active: !leftTextLoader.active
+                            anchors.fill: parent
+
+                            sourceComponent: ColorImage {
+                                width: leftSide.width
+                                height: leftSide.height
+
+                                source: control.checked ? "qrc:/qt-project.org/imports/QtQuick/Controls.2/images/check.png"
+                                    : modelData.icon.source ? modelData.icon.source
+                                    : ""
+                                visible: true
+                                color: control.enabled ? VLCStyle.colors.playerFg : VLCStyle.colors.playerFgInactive
+                            }
+                        }
                     }
 
                     ColorImage {
diff --git a/modules/gui/qt/playlist/qml/PlaylistToolbar.qml b/modules/gui/qt/playlist/qml/PlaylistToolbar.qml
index 64da3a766d..3741332246 100644
--- a/modules/gui/qt/playlist/qml/PlaylistToolbar.qml
+++ b/modules/gui/qt/playlist/qml/PlaylistToolbar.qml
@@ -99,9 +99,7 @@ Widgets.NavigableFocusScope {
                 
                 listWidth: VLCStyle.widthSortBox
                 onSortSelected: {
-                    if (modelData.criteria !== sortKey)
-                        mainPlaylistController.setSortOrder(PlaylistControllerModel.SORT_ORDER_ASC)
-                    mainPlaylistController.setSortKey(modelData.criteria)
+                    root.sortPL(modelData.criteria)
                 }
 
                 Keys.priority: Keys.AfterItem



More information about the vlc-commits mailing list