[vlc-devel] [PATCH] qt: enable windowed playlist

Abel Tesfaye abeltesfaye45 at gmail.com
Wed Jun 5 20:55:48 CEST 2019


From: Abel Tesfaye <Abeltesfaye45 at gmail.com>

---
 modules/gui/qt/main_interface.cpp             | 14 +++++++
 modules/gui/qt/main_interface.hpp             |  9 +++++
 modules/gui/qt/qml/BannerSources.qml          |  9 +++--
 modules/gui/qt/qml/MainInterface.qml          | 15 ++++++++
 .../gui/qt/qml/mediacenter/MCMainDisplay.qml  | 38 ++++++++-----------
 modules/gui/qt/qml/menus/ViewMenu.qml         | 11 ++++++
 modules/gui/qt/qml/player/ControlBar.qml      |  8 ++--
 modules/gui/qt/qml/player/ModalControlBar.qml |  3 --
 modules/gui/qt/qml/player/Player.qml          | 30 +++++++--------
 9 files changed, 90 insertions(+), 47 deletions(-)

diff --git a/modules/gui/qt/main_interface.cpp b/modules/gui/qt/main_interface.cpp
index ef4b8da8e7..b827b388dc 100644
--- a/modules/gui/qt/main_interface.cpp
+++ b/modules/gui/qt/main_interface.cpp
@@ -552,6 +552,20 @@ void MainInterface::setVideoOnTop( bool on_top )
     }
 }
 
+void MainInterface::setPlaylistDocked( bool docked )
+{
+    b_playlistDocked = docked;
+
+    emit playlistDockedChanged(docked);
+}
+
+void MainInterface::setPlaylistVisible( bool visible )
+{
+    playlistVisible = visible;
+
+    emit playlistVisibleChanged(visible);
+}
+
 void MainInterface::setInterfaceAlwaysOnTop( bool on_top )
 {
     b_interfaceOnTop = on_top;
diff --git a/modules/gui/qt/main_interface.hpp b/modules/gui/qt/main_interface.hpp
index 3ceb91b40f..61a11ec4bf 100644
--- a/modules/gui/qt/main_interface.hpp
+++ b/modules/gui/qt/main_interface.hpp
@@ -63,6 +63,8 @@ class MainInterface : public QVLCMW
 {
     Q_OBJECT
 
+    Q_PROPERTY(bool playlistDocked READ isPlaylistDocked WRITE setPlaylistDocked NOTIFY playlistDockedChanged)
+    Q_PROPERTY(bool playlistVisible READ isPlaylistVisible WRITE setPlaylistVisible NOTIFY playlistVisibleChanged)
     Q_PROPERTY(bool interfaceAlwaysOnTop READ isInterfaceAlwaysOnTop WRITE setInterfaceAlwaysOnTop NOTIFY interfaceAlwaysOnTopChanged)
     Q_PROPERTY(bool interfaceFullScreen READ isInterfaceFullScreen WRITE setInterfaceFullScreen NOTIFY interfaceFullScreenChanged)
     Q_PROPERTY(bool hasEmbededVideo READ hasEmbededVideo NOTIFY hasEmbededVideoChanged)
@@ -111,6 +113,8 @@ public:
         RAISE_AUDIOVIDEO,
     };
     bool isInterfaceFullScreen() { return b_interfaceFullScreen; }
+    bool isPlaylistDocked() { return b_playlistDocked; }
+    bool isPlaylistVisible() { return playlistVisible; }
     bool isInterfaceAlwaysOnTop() { return b_interfaceOnTop; }
     bool hasEmbededVideo() { return m_hasEmbededVideo; }
     QList<QQmlError> qmlErrors() const;
@@ -171,6 +175,7 @@ protected:
     bool                 b_videoFullScreen;     ///< --fullscreen
     bool                 b_hideAfterCreation;
     bool                 b_minimalView;         ///< Minimal video
+    bool                 b_playlistDocked;
     bool                 b_interfaceFullScreen;
     bool                 b_interfaceOnTop;      ///keep UI on top
     bool                 b_pauseOnMinimize;
@@ -196,6 +201,8 @@ public slots:
     void showUpdateSystrayMenu();
     void hideUpdateSystrayMenu();
     void toggleInterfaceFullScreen();
+    void setPlaylistDocked( bool );
+    void setPlaylistVisible( bool );
     void setInterfaceAlwaysOnTop( bool );
 
     void emitBoss();
@@ -242,6 +249,8 @@ signals:
     void askPopupMenu( bool show );
     void kc_pressed(); /* easter eggs */
 
+    void playlistDockedChanged(bool);
+    void playlistVisibleChanged(bool);
     void interfaceAlwaysOnTopChanged(bool);
     void interfaceFullScreenChanged(bool);
     void hasEmbededVideoChanged(bool);
diff --git a/modules/gui/qt/qml/BannerSources.qml b/modules/gui/qt/qml/BannerSources.qml
index 193ffdfe3e..e722d078fa 100644
--- a/modules/gui/qt/qml/BannerSources.qml
+++ b/modules/gui/qt/qml/BannerSources.qml
@@ -33,7 +33,6 @@ Utils.NavigableFocusScope {
 
     property int selectedIndex: 0
     property alias model: pLBannerSources.model
-    signal toogleMenu()
 
     // Triggered when the toogleView button is selected
     function toggleView () {
@@ -179,7 +178,7 @@ Utils.NavigableFocusScope {
 
                         KeyNavigation.left: buttonView
 
-                        onClicked: root.toogleMenu()
+                        onClicked: rootWindow.playlistVisible = !rootWindow.playlistVisible
                     }
 
                     Utils.IconToolButton {
@@ -189,12 +188,16 @@ Utils.NavigableFocusScope {
                         text: VLCIcons.menu
 
                         KeyNavigation.left: playlist_btn
+                        KeyNavigation.right: playlist
 
                         onClicked: mainMenu.openBelow(this)
 
                         Menus.MainDropdownMenu {
                             id: mainMenu
-                            onClosed: menu_selector.forceActiveFocus()
+                            onClosed: {
+                                if (mainMenu.activeFocus)
+                                    menu_selector.forceActiveFocus()
+                            }
                         }
                     }
                 }
diff --git a/modules/gui/qt/qml/MainInterface.qml b/modules/gui/qt/qml/MainInterface.qml
index d104fb44b5..aaa4c23846 100644
--- a/modules/gui/qt/qml/MainInterface.qml
+++ b/modules/gui/qt/qml/MainInterface.qml
@@ -27,11 +27,26 @@ import "qrc:///style/"
 import "qrc:///player/" as Player
 import "qrc:///about/" as AB
 import "qrc:///dialogs/" as DG
+import "qrc:///playlist/" as PL
+import QtQuick.Window 2.11
 
 Rectangle {
     id: root
     color: "transparent"
 
+    Window {
+        id: playlistWindow
+        visible: !rootWindow.playlistDocked && rootWindow.playlistVisible
+        title: qsTr("Playlist")
+        color: VLCStyle.colors.bg
+        onClosing: rootWindow.playlistVisible = false
+        PL.PlaylistListView {
+            id: playlistView
+            focus: true
+            anchors.fill: parent
+        }
+    }
+
     PlaylistControllerModel {
         id: mainPlaylistController
         playlistPtr: mainctx.playlist
diff --git a/modules/gui/qt/qml/mediacenter/MCMainDisplay.qml b/modules/gui/qt/qml/mediacenter/MCMainDisplay.qml
index b8ade228ea..88cfff2cf8 100644
--- a/modules/gui/qt/qml/mediacenter/MCMainDisplay.qml
+++ b/modules/gui/qt/qml/mediacenter/MCMainDisplay.qml
@@ -90,7 +90,7 @@ Utils.NavigableFocusScope {
             focus: true
             id: medialibId
             anchors.fill: parent
-            onActionRight: playlist.show()
+            onActionRight: rootWindow.playlistVisible = true
 
             ColumnLayout {
                 id: column
@@ -125,8 +125,6 @@ Utils.NavigableFocusScope {
                     onActionRight: root.actionRight(index)
                     onActionUp: root.actionUp(index)
                     onActionCancel: root.actionCancel(index)
-
-                    onToogleMenu: playlist.toggleState()
                 }
 
 
@@ -150,7 +148,11 @@ Utils.NavigableFocusScope {
                         focus: false
                         expandHorizontally: true
 
-                        state: "hidden"
+                        state: (rootWindow.playlistDocked && rootWindow.playlistVisible) ? "visible" : "hidden"
+                        onVisibleChanged: {
+                            if (playlist.visible)
+                                playlist.forceActiveFocus()
+                        }
                         component: Rectangle {
                             color: VLCStyle.colors.setColorAlpha(VLCStyle.colors.banner, 0.9)
                             width: root.width/3
@@ -167,28 +169,18 @@ Utils.NavigableFocusScope {
                                     id: playlistView
                                     focus: true
                                     anchors.fill: parent
-                                    onActionLeft: playlist.quit()
-                                    onActionCancel: playlist.quit()
-                                    onActionUp: {
-                                        playlist.state = "hidden"
-                                        sourcesBanner.forceActiveFocus()
-                                    }
+                                    onActionLeft: playlist.closeAndFocus(stackView.currentItem)
+                                    onActionCancel: playlist.closeAndFocus(stackView.currentItem)
+                                    onActionUp: playlist.closeAndFocus(sourcesBanner)
                                 }
                             }
                         }
-                        function toggleState() {
-                            if (state === "hidden")
-                                show()
-                            else
-                                quit()
-                        }
-                        function quit() {
-                            state = "hidden"
-                            stackView.currentItem.forceActiveFocus()
-                        }
-                        function show() {
-                            state = "visible"
-                            playlist.forceActiveFocus()
+                        function closeAndFocus(item){
+                            if (!item)
+                                return
+
+                            rootWindow.playlistVisible = false
+                            item.forceActiveFocus()
                         }
                     }
                 }
diff --git a/modules/gui/qt/qml/menus/ViewMenu.qml b/modules/gui/qt/qml/menus/ViewMenu.qml
index 7a58605092..f8fd0abf2b 100644
--- a/modules/gui/qt/qml/menus/ViewMenu.qml
+++ b/modules/gui/qt/qml/menus/ViewMenu.qml
@@ -22,6 +22,17 @@ import "qrc:///style/"
 import "qrc:///utils/" as Utils
 
 Utils.MenuExt {
+    id: viewMenu
+    Action {
+        text: qsTr("Play&list")
+        onTriggered: rootWindow.playlistVisible = !rootWindow.playlistVisible
+    }
+    Action {
+        text: qsTr("Docked Playlist")
+        checkable: true
+        checked: rootWindow.playlistDocked
+        onTriggered: rootWindow.playlistDocked = !rootWindow.playlistDocked
+    }
     Action {
         text: qsTr("&Always on Top")
         checkable: true
diff --git a/modules/gui/qt/qml/player/ControlBar.qml b/modules/gui/qt/qml/player/ControlBar.qml
index 2649bd3047..11ac262a8a 100644
--- a/modules/gui/qt/qml/player/ControlBar.qml
+++ b/modules/gui/qt/qml/player/ControlBar.qml
@@ -25,12 +25,12 @@ import org.videolan.vlc 0.1
 import "qrc:///style/"
 import "qrc:///utils/" as Utils
 import "qrc:///menus/" as Menus
+import "qrc:///playlist/" as PL
 
 Utils.NavigableFocusScope {
     id: root
 
     signal showTrackBar
-    signal showPlaylist
 
     property bool noAutoHide: mainMenu.opened
     property bool showPlaylistButton: false
@@ -180,7 +180,7 @@ Utils.NavigableFocusScope {
                         visible: showPlaylistButton
                         size: VLCStyle.icon_large
                         text: VLCIcons.playlist
-                        onClicked: root.showPlaylist()
+                        onClicked: rootWindow.playlistVisible = !rootWindow.playlistVisible
                         KeyNavigation.right: menuBtn
                     }
 
@@ -189,11 +189,13 @@ Utils.NavigableFocusScope {
                         size: VLCStyle.icon_large
                         text: VLCIcons.menu
                         onClicked: mainMenu.openAbove(this)
+                        KeyNavigation.right: playlistpopup
 
                         Menus.MainDropdownMenu {
                             id: mainMenu
                             onClosed: {
-                                menuBtn.forceActiveFocus()
+                                if (mainMenu.activeFocus)
+                                    menuBtn.forceActiveFocus()
                             }
                         }
                     }
diff --git a/modules/gui/qt/qml/player/ModalControlBar.qml b/modules/gui/qt/qml/player/ModalControlBar.qml
index d534c8cdd0..a8e0d5ebeb 100644
--- a/modules/gui/qt/qml/player/ModalControlBar.qml
+++ b/modules/gui/qt/qml/player/ModalControlBar.qml
@@ -26,8 +26,6 @@ import "qrc:///utils/" as Utils
 
 Utils.NavigableFocusScope {
     id: root
-    signal showPlaylist();
-
     property bool showPlaylistButton: false
 
     property bool forceNoAutoHide: false
@@ -41,7 +39,6 @@ Utils.NavigableFocusScope {
             showPlaylistButton: root.showPlaylistButton
 
             onShowTrackBar: root.state = "tracks"
-            onShowPlaylist: root.showPlaylist()
 
             onActionUp: root.actionUp(index)
             onActionDown: root.actionDown(index)
diff --git a/modules/gui/qt/qml/player/Player.qml b/modules/gui/qt/qml/player/Player.qml
index 403b8650ed..7beb818947 100644
--- a/modules/gui/qt/qml/player/Player.qml
+++ b/modules/gui/qt/qml/player/Player.qml
@@ -125,7 +125,11 @@ Utils.NavigableFocusScope {
         }
         focus: false
         expandHorizontally: true
-
+        state: (rootWindow.playlistDocked && rootWindow.playlistVisible) ? "visible" : "hidden"
+        onVisibleChanged: {
+            if (playlistpopup.visible)
+                playlistpopup.forceActiveFocus()
+        }
         component: Rectangle {
             color: VLCStyle.colors.setColorAlpha(VLCStyle.colors.banner, 0.8)
             width: root.width/4
@@ -135,18 +139,22 @@ Utils.NavigableFocusScope {
                 id: playlistView
                 focus: true
                 anchors.fill: parent
-                onActionLeft: playlistpopup.quit()
-                onActionCancel: playlistpopup.quit()
+                onActionLeft: playlistpopup.closeAndFocus(controlBarView)
+                onActionCancel: playlistpopup.closeAndFocus(controlBarView)
             }
         }
-        function quit() {
-            state = "hidden"
-            controlBarView.focus = true
-        }
         onStateChanged: {
             if (state === "hidden")
                 toolbarAutoHide.restart()
         }
+
+        function closeAndFocus(item){
+            if (!item)
+                return
+
+            rootWindow.playlistVisible = false
+            item.forceActiveFocus()
+        }
     }
 
 
@@ -193,14 +201,6 @@ Utils.NavigableFocusScope {
                     onActionLeft: root.actionLeft(index)
                     onActionRight: root.actionRight(index)
                     onActionCancel: root.actionCancel(index)
-                    onShowPlaylist: {
-                        if (playlistpopup.state === "visible") {
-                            playlistpopup.state = "hidden"
-                        } else {
-                            playlistpopup.state = "visible"
-                            playlistpopup.focus = true
-                        }
-                    }
 
                     //unhandled keys are forwarded to the vout window
                     Keys.forwardTo: videoSurface
-- 
2.21.0



More information about the vlc-devel mailing list