From a3be06639bfb64ee08905a0555f2b0273ddfc448 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Thu, 6 Oct 2022 03:33:56 -0500 Subject: [PATCH] ui components to control looping on the fly --- src/mpv/mpvobject.cpp | 16 +++++++++------- src/mpv/mpvobject.h | 1 + src/qml/presenter/MainWindow.qml | 5 +++++ src/qml/presenter/Presentation.qml | 18 ++++++++++++++++-- src/qml/presenter/PresentationWindow.qml | 3 +++ src/qml/presenter/Slide.qml | 13 ++++++++++++- src/qml/presenter/VideoEditor.qml | 12 ++++++++++++ 7 files changed, 58 insertions(+), 10 deletions(-) diff --git a/src/mpv/mpvobject.cpp b/src/mpv/mpvobject.cpp index e2f40a4..52a2f98 100644 --- a/src/mpv/mpvobject.cpp +++ b/src/mpv/mpvobject.cpp @@ -224,6 +224,7 @@ MpvObject::MpvObject(QQuickItem *parent) WATCH_PROP_STRING("hwdec") WATCH_PROP_STRING("hwdec-current") WATCH_PROP_STRING("hwdec-interop") + WATCH_PROP_STRING("loop") WATCH_PROP_STRING("media-title") WATCH_PROP_STRING("path") WATCH_PROP_STRING("video-codec") @@ -430,13 +431,14 @@ void MpvObject::handle_mpv_event(mpv_event *event) else if HANDLE_PROP_STRING("hwdec", hwdec) else if HANDLE_PROP_STRING("hwdec-current", hwdecCurrent) else if HANDLE_PROP_STRING("hwdec-interop", hwdecInterop) - else if HANDLE_PROP_STRING("media-title", mediaTitle) - else if HANDLE_PROP_STRING("path", path) - else if HANDLE_PROP_STRING("video-codec", videoCodec) - else if HANDLE_PROP_STRING("video-format", videoFormat) - else if HANDLE_PROP_STRING("video-params/pixelformat", videoParamsPixelformat) - else if HANDLE_PROP_STRING("video-out-params/pixelformat", videoOutParamsPixelformat) - else if HANDLE_PROP_STRING("ytdl-format", ytdlFormat) + else if HANDLE_PROP_STRING("loop", loop) + else if HANDLE_PROP_STRING("media-title", mediaTitle) + else if HANDLE_PROP_STRING("path", path) + else if HANDLE_PROP_STRING("video-codec", videoCodec) + else if HANDLE_PROP_STRING("video-format", videoFormat) + else if HANDLE_PROP_STRING("video-params/pixelformat", videoParamsPixelformat) + else if HANDLE_PROP_STRING("video-out-params/pixelformat", videoOutParamsPixelformat) + else if HANDLE_PROP_STRING("ytdl-format", ytdlFormat) } else if (prop->format == MPV_FORMAT_INT64) { diff --git a/src/mpv/mpvobject.h b/src/mpv/mpvobject.h index b43a4b1..d7a0244 100644 --- a/src/mpv/mpvobject.h +++ b/src/mpv/mpvobject.h @@ -94,6 +94,7 @@ class MpvObject : public QQuickFramebufferObject WRITABLE_PROP_STRING("hwdec", hwdec) READONLY_PROP_STRING("hwdec-current", hwdecCurrent) READONLY_PROP_STRING("hwdec-interop", hwdecInterop) + WRITABLE_PROP_STRING("loop", loop) READONLY_PROP_STRING("media-title", mediaTitle) READONLY_PROP_STRING("path", path) READONLY_PROP_STRING("video-codec", videoCodec) diff --git a/src/qml/presenter/MainWindow.qml b/src/qml/presenter/MainWindow.qml index 910d54b..05ca1ac 100644 --- a/src/qml/presenter/MainWindow.qml +++ b/src/qml/presenter/MainWindow.qml @@ -163,6 +163,11 @@ Controls.Page { print("Slide changed to: " + item.name); } + function loopVideo() { + presentation.loopVideo(); + pWindow.loopVideo(); + } + function editSwitch(item) { if (editMode) { switch (editType) { diff --git a/src/qml/presenter/Presentation.qml b/src/qml/presenter/Presentation.qml index 8348ee6..63b586c 100644 --- a/src/qml/presenter/Presentation.qml +++ b/src/qml/presenter/Presentation.qml @@ -19,8 +19,6 @@ FocusScope { property Item slide: previewSlide - onActiveFocusChanged: showPassiveNotification("OUCH") - Item { id: keyHandler anchors.fill: parent @@ -65,6 +63,11 @@ FocusScope { Controls.ToolSeparator {} Item { Layout.fillWidth: true } Controls.ToolSeparator {} + Controls.ToolButton { + text: "Repeat" + icon.name: "repeat" + onClicked: mainPage.loopVideo() + } Controls.ToolButton { text: "Effects" icon.name: "image-auto-adjust" @@ -152,6 +155,13 @@ FocusScope { live: true onMoved: changeVidPos(value); } + + Controls.Switch { + text: "Loop" + visible: itemType === "video"; + checked: previewSlide.mpvLoop === "inf" ? true : false + onToggled: mainPage.loopVideo() + } } Item { @@ -273,6 +283,10 @@ FocusScope { previewSlide.loadVideo(); } + function loopVideo() { + previewSlide.loopVideo(); + } + function stopVideo() { /* showPassiveNotification("Stopping Video") */ previewSlide.stopVideo() diff --git a/src/qml/presenter/PresentationWindow.qml b/src/qml/presenter/PresentationWindow.qml index da35a0e..5f04c6f 100644 --- a/src/qml/presenter/PresentationWindow.qml +++ b/src/qml/presenter/PresentationWindow.qml @@ -79,4 +79,7 @@ Window { presentationSlide.pauseVideo(); } + function loopVideo() { + presentationSlide.loopVideo(); + } } diff --git a/src/qml/presenter/Slide.qml b/src/qml/presenter/Slide.qml index 08b8fde..b02dbcf 100644 --- a/src/qml/presenter/Slide.qml +++ b/src/qml/presenter/Slide.qml @@ -31,7 +31,7 @@ Item { //these properties are for giving video info to parents property int mpvPosition: mpv.position property int mpvDuration: mpv.duration - property var mpvLoop: mpv.getProperty("loop") + property var mpvLoop: mpv.loop property bool mpvIsPlaying: mpv.isPlaying // These properties help to determine the state of the slide @@ -167,6 +167,17 @@ Item { lyrics.text = text } + function loopVideo() { + if (mpv.getProperty("loop") === "inf") { + showPassiveNotification("already looping"); + mpv.setProperty("loop", "no"); + } + else { + mpv.setProperty("loop", "inf"); + showPassiveNotification("looping video"); + } + } + function loadVideo() { mpvLoadingTimer.restart() } diff --git a/src/qml/presenter/VideoEditor.qml b/src/qml/presenter/VideoEditor.qml index 9028644..27f44fc 100644 --- a/src/qml/presenter/VideoEditor.qml +++ b/src/qml/presenter/VideoEditor.qml @@ -143,6 +143,18 @@ Item { onEditingFinished: updateTitle(text); } + Controls.CheckBox { + id: loopCheckBox + Layout.preferredWidth: 300 + Layout.fillWidth: true + Layout.leftMargin: 20 + Layout.rightMargin: 20 + + text: "Repeat" + padding: 10 + onToggled: showPassiveNotification("BOOM!") + } + RowLayout { Layout.preferredWidth: 300 Layout.fillWidth: true