[vlc-devel] [PATCH 07/14] qml: add PIP player

Pierre Lamot pierre at videolabs.io
Thu Oct 22 15:14:19 CEST 2020


  A floating player that can be dragged around while browsing the ML
---
 modules/gui/qt/Makefile.am                |   2 +
 modules/gui/qt/player/qml/PIPPlayer.qml   | 138 ++++++++++++++++++++++
 modules/gui/qt/vlc.qrc                    |   2 +
 modules/gui/qt/widgets/qml/IconButton.qml |  46 ++++++++
 4 files changed, 188 insertions(+)
 create mode 100644 modules/gui/qt/player/qml/PIPPlayer.qml
 create mode 100644 modules/gui/qt/widgets/qml/IconButton.qml

diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index f61025ff01..d9aacae1a8 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -650,6 +650,7 @@ libqt_plugin_la_QML = \
 	gui/qt/player/qml/ControlBar.qml \
 	gui/qt/player/qml/ControlButtons.qml \
 	gui/qt/player/qml/MiniPlayer.qml \
+	gui/qt/player/qml/PIPPlayer.qml \
 	gui/qt/player/qml/Player.qml \
 	gui/qt/player/qml/PlayerButtonsLayout.qml \
 	gui/qt/player/qml/PlayerMenu.qml \
@@ -686,6 +687,7 @@ libqt_plugin_la_QML = \
 	gui/qt/widgets/qml/GridItem.qml \
 	gui/qt/widgets/qml/HorizontalResizeHandle.qml \
 	gui/qt/widgets/qml/IconLabel.qml \
+	gui/qt/widgets/qml/IconButton.qml \
 	gui/qt/widgets/qml/IconToolButton.qml \
 	gui/qt/widgets/qml/ImageToolButton.qml \
 	gui/qt/widgets/qml/KeyNavigableGridView.qml \
diff --git a/modules/gui/qt/player/qml/PIPPlayer.qml b/modules/gui/qt/player/qml/PIPPlayer.qml
new file mode 100644
index 0000000000..23509db361
--- /dev/null
+++ b/modules/gui/qt/player/qml/PIPPlayer.qml
@@ -0,0 +1,138 @@
+/*****************************************************************************
+ * Copyright (C) 2020 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 org.videolan.vlc 0.1
+import "qrc:///style/"
+import "qrc:///widgets/" as Widgets
+
+Item {
+    id: root
+    width: VLCStyle.dp(320, VLCStyle.scale)
+    height: VLCStyle.dp(180, VLCStyle.scale)
+
+    //VideoSurface x,y won't update
+    onXChanged: videoSurface.onSurfacePositionChanged()
+    onYChanged: videoSurface.onSurfacePositionChanged()
+
+    property real dragXMin: 0
+    property real dragXMax: 0
+    property real dragYMin: undefined
+    property real dragYMax: undefined
+
+    Connections {
+        target: mouseArea.drag
+        onActiveChanged: {
+            root.anchors.left = undefined;
+            root.anchors.right = undefined
+            root.anchors.top = undefined
+            root.anchors.bottom = undefined
+            root.anchors.verticalCenter = undefined;
+            root.anchors.horizontalCenter = undefined
+        }
+    }
+    Drag.active: mouseArea.drag.active
+
+    VideoSurface {
+        id: videoSurface
+
+        anchors.fill: parent
+
+        enabled: root.enabled
+        visible: root.visible
+
+        ctx: mainctx
+
+        //punch a transparent hole in the interface
+        layer.enabled: true
+        layer.effect: ShaderEffect {
+            blending: false
+            fragmentShader: "void main() { gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); }"
+        }
+    }
+
+    MouseArea {
+        id: mouseArea
+
+        anchors.fill: videoSurface
+        z: 1
+
+        hoverEnabled: true
+        onClicked: mainPlaylistController.togglePlayPause()
+
+        enabled: root.enabled
+        visible: root.visible
+
+        cursorShape: drag.active ? Qt.DragMoveCursor : undefined
+        drag.target: root
+        drag.minimumX: root.dragXMin
+        drag.minimumY: root.dragYMin
+        drag.maximumX: root.dragXMax
+        drag.maximumY: root.dragYMax
+
+        onWheel: wheel.accept()
+
+        Rectangle {
+            color: "#10000000"
+            anchors.fill: parent
+            visible: parent.containsMouse
+
+            Widgets.IconButton {
+                anchors.centerIn: parent
+
+                font.pixelSize: VLCStyle.dp(60, VLCStyle.scale)
+                text: (player.playingState !== PlayerController.PLAYING_STATE_PAUSED
+                       && player.playingState !== PlayerController.PLAYING_STATE_STOPPED)
+                      ? VLCIcons.pause
+                      : VLCIcons.play
+
+                onClicked: mainPlaylistController.togglePlayPause()
+            }
+
+            Widgets.IconButton {
+                anchors {
+                    top: parent.top
+                    topMargin: VLCStyle.margin_small
+                    right: parent.right
+                    rightMargin: VLCStyle.margin_small
+                }
+
+                font.pixelSize: VLCStyle.dp(20, VLCStyle.scale)
+                text: VLCIcons.close
+
+                onClicked: mainPlaylistController.stop()
+            }
+
+
+            Widgets.IconButton {
+                anchors {
+                    top: parent.top
+                    topMargin: VLCStyle.margin_small
+                    left: parent.left
+                    leftMargin: VLCStyle.margin_small
+                }
+
+                font.pixelSize: VLCStyle.dp(20, VLCStyle.scale)
+                text: VLCIcons.fullscreen
+
+                onClicked: history.push(["player"])
+            }
+        }
+    }
+}
diff --git a/modules/gui/qt/vlc.qrc b/modules/gui/qt/vlc.qrc
index 55b26e0b63..56b1519ae3 100644
--- a/modules/gui/qt/vlc.qrc
+++ b/modules/gui/qt/vlc.qrc
@@ -233,6 +233,7 @@
         <file alias="PointingTooltip.qml">widgets/qml/PointingTooltip.qml</file>
         <file alias="FrostedGlassEffect.qml">widgets/qml/FrostedGlassEffect.qml</file>
         <file alias="PageLoader.qml">widgets/qml/PageLoader.qml</file>
+        <file alias="IconButton.qml">widgets/qml/IconButton.qml</file>
     </qresource>
     <qresource prefix="/network">
         <file alias="DiscoverDisplay.qml">network/qml/DiscoverDisplay.qml</file>
@@ -296,6 +297,7 @@
         <file alias="TeletextWidget.qml">player/qml/TeletextWidget.qml</file>
         <file alias="MiniPlayer.qml">player/qml/MiniPlayer.qml</file>
         <file alias="TopBar.qml">player/qml/TopBar.qml</file>
+        <file alias="PIPPlayer.qml">player/qml/PIPPlayer.qml</file>
         <file alias="PlayerButtonsLayout.qml">player/qml/PlayerButtonsLayout.qml</file>
         <file alias="PlayerMenu.qml">player/qml/PlayerMenu.qml</file>
         <file alias="PlayerMenuItem.qml">player/qml/PlayerMenuItem.qml</file>
diff --git a/modules/gui/qt/widgets/qml/IconButton.qml b/modules/gui/qt/widgets/qml/IconButton.qml
new file mode 100644
index 0000000000..90df21ad6e
--- /dev/null
+++ b/modules/gui/qt/widgets/qml/IconButton.qml
@@ -0,0 +1,46 @@
+/*****************************************************************************
+ * Copyright (C) 2020 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.Templates 2.4 as T
+import "qrc:///style/"
+
+T.Button {
+    id: control
+
+    width: content.implicitWidth
+    height: content.implicitHeight
+
+    property color color: "white"
+    font.family: VLCIcons.fontFamily
+
+    contentItem: Item {
+        Label {
+            id: content
+            anchors.centerIn: parent
+            text: control.text
+            color: control.color
+            font: control.font
+        }
+    }
+
+    background: Item {
+        implicitWidth: 10
+        implicitHeight: 10
+    }
+}
-- 
2.25.1



More information about the vlc-devel mailing list