[vlc-devel] [PATCH 6/7] qml: add a resume playback dialog in the player
Hugo Beauzée-Luyssen
hugo at beauzee.fr
Tue Jan 21 16:18:03 CET 2020
From: Pierre Lamot <pierre at videolabs.io>
---
modules/gui/qt/Makefile.am | 1 +
modules/gui/qt/player/qml/Player.qml | 2 +
modules/gui/qt/player/qml/ResumeDialog.qml | 118 +++++++++++++++++++++
modules/gui/qt/player/qml/SliderBar.qml | 2 +-
modules/gui/qt/player/qml/TopBar.qml | 18 +++-
modules/gui/qt/vlc.qrc | 1 +
6 files changed, 140 insertions(+), 2 deletions(-)
create mode 100644 modules/gui/qt/player/qml/ResumeDialog.qml
diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index 27442fdbe5..a527e81ad9 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -592,6 +592,7 @@ libqt_plugin_la_QML = \
gui/qt/player/qml/PlayerButtonsLayout.qml \
gui/qt/player/qml/PlayerMenu.qml \
gui/qt/player/qml/PlayerMenuItem.qml \
+ gui/qt/player/qml/ResumeDialog.qml \
gui/qt/player/qml/SliderBar.qml \
gui/qt/player/qml/TeletextWidget.qml \
gui/qt/player/qml/TopBar.qml \
diff --git a/modules/gui/qt/player/qml/Player.qml b/modules/gui/qt/player/qml/Player.qml
index 333a84e6db..1cc8adb969 100644
--- a/modules/gui/qt/player/qml/Player.qml
+++ b/modules/gui/qt/player/qml/Player.qml
@@ -194,6 +194,8 @@ Widgets.NavigableFocusScope {
rootWindow.playlistVisible = !rootWindow.playlistVisible
}
+ onResumeDialogHidden: controlBarView.forceActiveFocus()
+
navigationParent: rootPlayer
navigationDownItem: playlistpopup.showPlaylist ? playlistpopup : controlBarView
}
diff --git a/modules/gui/qt/player/qml/ResumeDialog.qml b/modules/gui/qt/player/qml/ResumeDialog.qml
new file mode 100644
index 0000000000..3ab05af1f3
--- /dev/null
+++ b/modules/gui/qt/player/qml/ResumeDialog.qml
@@ -0,0 +1,118 @@
+/*****************************************************************************
+ * 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.Layouts 1.3
+
+import org.videolan.vlc 0.1
+
+import "qrc:///style/"
+import "qrc:///widgets/" as Widgets
+
+Widgets.NavigableFocusScope {
+ id: resumePanel
+
+ implicitWidth: layout.implicitWidth
+ implicitHeight: layout.implicitHeight
+
+ visible: false
+
+ signal hidden()
+
+ function showResumePanel ()
+ {
+ resumePanel.visible = true
+ continueBtn.forceActiveFocus()
+ resumeTimeout.start()
+ }
+
+ function hideResumePanel() {
+ resumeTimeout.stop()
+ resumePanel.visible = false
+ hidden()
+ }
+
+ Timer {
+ id: resumeTimeout
+ interval: 10000
+ onTriggered: {
+ resumePanel.visible = false
+ hidden()
+ }
+ }
+
+ Connections {
+ target: player
+ onCanRestorePlaybackChanged: {
+ if (player.canRestorePlayback) {
+ showResumePanel()
+ } else {
+ hideResumePanel()
+ }
+ }
+ }
+
+ Component.onCompleted: {
+ if (player.canRestorePlayback) {
+ showResumePanel()
+ }
+ }
+
+ RowLayout {
+ id: layout
+ anchors.fill: parent
+
+ Text {
+ Layout.preferredHeight: implicitHeight
+ Layout.fillWidth: true
+
+ color: VLCStyle.colors.playerFg
+ font.pixelSize: VLCStyle.fontSize_normal
+ font.bold: true
+
+ text: i18n.qtr("Do you want to restart the playback where you left off?")
+ }
+
+ Widgets.TabButtonExt {
+ id: continueBtn
+ Layout.preferredHeight: implicitHeight
+ Layout.preferredWidth: implicitWidth
+ text: i18n.qtr("Continue")
+ font.bold: true
+ focus: true
+ onClicked: {
+ player.restorePlaybackPos()
+ hideResumePanel()
+ }
+
+ KeyNavigation.right: closeBtn
+ }
+
+ Widgets.TabButtonExt {
+ id: closeBtn
+ Layout.preferredHeight: implicitHeight
+ Layout.preferredWidth: implicitWidth
+ text: "X"
+ font.bold: true
+ onClicked: hideResumePanel()
+
+ KeyNavigation.left: continueBtn
+ }
+ }
+}
+
diff --git a/modules/gui/qt/player/qml/SliderBar.qml b/modules/gui/qt/player/qml/SliderBar.qml
index 69c7f6da43..77d0556a65 100644
--- a/modules/gui/qt/player/qml/SliderBar.qml
+++ b/modules/gui/qt/player/qml/SliderBar.qml
@@ -109,7 +109,7 @@ Slider {
hoverEnabled: true
onPressed: function (event) {
- control.focus = true
+ control.forceActiveFocus()
control._isHold = true
control.value = event.x / control.width
player.position = control.value
diff --git a/modules/gui/qt/player/qml/TopBar.qml b/modules/gui/qt/player/qml/TopBar.qml
index fcc9dc4f79..d53d14d8ae 100644
--- a/modules/gui/qt/player/qml/TopBar.qml
+++ b/modules/gui/qt/player/qml/TopBar.qml
@@ -35,6 +35,7 @@ Widgets.NavigableFocusScope{
property bool lockAutoHide: false
signal togglePlaylistVisiblity();
+ signal resumeDialogHidden()
Keys.priority: Keys.AfterItem
Keys.onPressed: defaultKeyAction(event, 0)
@@ -77,12 +78,25 @@ Widgets.NavigableFocusScope{
}
history.previous(History.Go)
}
- KeyNavigation.right: playlistBtn
+ KeyNavigation.right: resumeDialog.visible ? resumeDialog : playlistBtn
focus: true
}
Item{
Layout.fillWidth: true
+ Layout.preferredHeight: resumeDialog.implicitHeight
+
+ ResumeDialog {
+ id: resumeDialog
+ anchors.fill: parent
+ onHidden: {
+ if (activeFocus) {
+ focus = false
+ playlistBtn.focus = true
+ }
+ resumeDialogHidden()
+ }
+ }
}
Widgets.IconToolButton {
@@ -94,6 +108,8 @@ Widgets.NavigableFocusScope{
color: VLCStyle.colors.playerFg
onClicked: togglePlaylistVisiblity()
property bool acceptFocus: true
+
+ KeyNavigation.left: resumeDialog.visible ? resumeDialog : backBtn
}
}
}
diff --git a/modules/gui/qt/vlc.qrc b/modules/gui/qt/vlc.qrc
index afba395b70..1b1ff3a47c 100644
--- a/modules/gui/qt/vlc.qrc
+++ b/modules/gui/qt/vlc.qrc
@@ -269,6 +269,7 @@
<qresource prefix="/player">
<file alias="Player.qml">player/qml/Player.qml</file>
<file alias="ControlBar.qml">player/qml/ControlBar.qml</file>
+ <file alias="ResumeDialog.qml">player/qml/ResumeDialog.qml</file>
<file alias="SliderBar.qml">player/qml/SliderBar.qml</file>
<file alias="TrackInfo.qml">player/qml/TrackInfo.qml</file>
<file alias="ControlButtons.qml">player/qml/ControlButtons.qml</file>
--
2.20.1
More information about the vlc-devel
mailing list