[vlc-devel] [PATCH 02/15] qml: Move player buttons layout to another qml

Rohan Rajpal rohan17089 at iiitd.ac.in
Mon Aug 12 15:24:16 CEST 2019


Move player buttons layout to another qml file to use it in
future by miniplayer.
---
 modules/gui/qt/Makefile.am                    |  1 +
 modules/gui/qt/qml/player/ControlBar.qml      | 34 +---------
 .../gui/qt/qml/player/PlayerButtonsLayout.qml | 62 +++++++++++++++++++
 modules/gui/qt/vlc.qrc                        |  1 +
 4 files changed, 66 insertions(+), 32 deletions(-)
 create mode 100644 modules/gui/qt/qml/player/PlayerButtonsLayout.qml

diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index afbadf0bb8..75c310a9ed 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -553,6 +553,7 @@ libqt_plugin_la_QML = \
 	gui/qt/qml/player/TrackSelector.qml \
 	gui/qt/qml/player/ControlBar.qml \
 	gui/qt/qml/player/ControlButtons.qml \
+	gui/qt/qml/player/PlayerButtonsLayout.qml \
 	gui/qt/qml/player/VolumeWidget.qml \
 	gui/qt/qml/player/ModalControlBar.qml \
 	gui/qt/qml/player/SliderBar.qml \
diff --git a/modules/gui/qt/qml/player/ControlBar.qml b/modules/gui/qt/qml/player/ControlBar.qml
index a02cde9e6c..e65dfac186 100644
--- a/modules/gui/qt/qml/player/ControlBar.qml
+++ b/modules/gui/qt/qml/player/ControlBar.qml
@@ -85,40 +85,10 @@ Utils.NavigableFocusScope {
                     color: "transparent"
                 }
 
-                RowLayout{
-                    id: buttonrow
-                    property bool _focusGiven: false
+                PlayerButtonsLayout {
                     focus: true
                     anchors.fill: parent
-                    Repeater{
-                        model: playerControlBarModel
-                        delegate: Loader{
-                            id: buttonloader
-
-                            sourceComponent: controlmodelbuttons.returnbuttondelegate(model.id)
-                            onLoaded: {
-                                if (! buttonloader.item.acceptFocus)
-                                    return
-                                else
-                                    if (!buttonrow._focusGiven){
-                                        buttonloader.item.forceActiveFocus()
-                                        buttonrow._focusGiven = true
-                                    }
-                                if(buttonloader.item instanceof Utils.IconToolButton)
-                                    buttonloader.item.size = model.size === PlayerControlBarModel.WIDGET_BIG ?
-                                                VLCStyle.icon_large : VLCStyle.icon_medium
-
-                                var buttonindex = DelegateModel.itemsIndex
-                                while(buttonindex > 0 && !(buttonrow.children[buttonindex-1].item.acceptFocus))
-                                    buttonindex = buttonindex-1
-
-                                if (buttonindex > 0)
-                                    buttonloader.item.KeyNavigation.left = buttonrow.children[buttonindex-1].item
-
-
-                            }
-                        }
-                    }
+                    model: playerControlBarModel
                 }
             }
         }
diff --git a/modules/gui/qt/qml/player/PlayerButtonsLayout.qml b/modules/gui/qt/qml/player/PlayerButtonsLayout.qml
new file mode 100644
index 0000000000..04f2a676f5
--- /dev/null
+++ b/modules/gui/qt/qml/player/PlayerButtonsLayout.qml
@@ -0,0 +1,62 @@
+/*****************************************************************************
+ * 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 QtQuick.Layouts 1.3
+import QtQml.Models 2.11
+
+import org.videolan.vlc 0.1
+
+import "qrc:///style/"
+import "qrc:///utils/" as Utils
+
+RowLayout{
+    id: buttonrow
+    property bool _focusGiven: false
+    property alias model: buttonsRepeater.model
+    property var defaultSize: VLCStyle.icon_medium
+
+    Repeater{
+        id: buttonsRepeater
+        delegate: Loader{
+            id: buttonloader
+
+            sourceComponent: controlmodelbuttons.returnbuttondelegate(model.id)
+            onLoaded: {
+                if (! buttonloader.item.acceptFocus)
+                    return
+                else
+                    if (!buttonrow._focusGiven){
+                        buttonloader.item.forceActiveFocus()
+                        buttonrow._focusGiven = true
+                    }
+                if(buttonloader.item instanceof Utils.IconToolButton)
+                    buttonloader.item.size = model.size === PlayerControlBarModel.WIDGET_BIG ?
+                                VLCStyle.icon_large : defaultSize
+
+                var buttonindex = DelegateModel.itemsIndex
+                while(buttonindex > 0 && !(buttonrow.children[buttonindex-1].item.acceptFocus))
+                    buttonindex = buttonindex-1
+
+                if (buttonindex > 0)
+                    buttonloader.item.KeyNavigation.left = buttonrow.children[buttonindex-1].item
+            }
+        }
+    }
+}
diff --git a/modules/gui/qt/vlc.qrc b/modules/gui/qt/vlc.qrc
index 724497a007..2d9839e0b1 100644
--- a/modules/gui/qt/vlc.qrc
+++ b/modules/gui/qt/vlc.qrc
@@ -257,6 +257,7 @@
         <file alias="TeletextWidget.qml">qml/player/TeletextWidget.qml</file>
         <file alias="MiniPlayer.qml">qml/player/MiniPlayer.qml</file>
         <file alias="TopBar.qml">qml/player/TopBar.qml</file>
+        <file alias="PlayerButtonsLayout.qml">qml/player/PlayerButtonsLayout.qml</file>
     </qresource>
     <qresource prefix="/about">
         <file alias="About.qml">qml/about/About.qml</file>
-- 
2.17.1



More information about the vlc-devel mailing list