From 9a180f7df0601cce018c4b7bf8032dcc2cb85e7f Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Thu, 15 Sep 2022 17:06:04 -0500 Subject: [PATCH] adding a playpause ability in videos --- src/qml/presenter/Presentation.qml | 18 ++++++++++++++- src/qml/presenter/PresentationWindow.qml | 17 +++++++++++++- src/qml/presenter/Slide.qml | 6 ++++- src/slide.cpp | 29 ++++++++++++++++++++++-- src/slide.h | 9 +++++++- 5 files changed, 73 insertions(+), 6 deletions(-) diff --git a/src/qml/presenter/Presentation.qml b/src/qml/presenter/Presentation.qml index 2bda831..93f5671 100644 --- a/src/qml/presenter/Presentation.qml +++ b/src/qml/presenter/Presentation.qml @@ -119,7 +119,7 @@ Item { visible: itemType === "video"; MouseArea { anchors.fill: parent - onPressed: print("pressed play/plause"); + onPressed: SlideObject.playPause(); cursorShape: Qt.PointingHandCursor } } @@ -149,6 +149,22 @@ Item { } + Connections { + target: SlideObject + onVideoBackgroundChanged: { + loadVideo(); + } + onIsPlayingChanged: { + if(SlideObject.isPlaying) + previewSlide.playVideo(); + pauseVideo(); + } + } + + function pauseVideo() { + previewSlide.pauseVideo(); + } + function loadVideo() { previewSlide.loadVideo(); } diff --git a/src/qml/presenter/PresentationWindow.qml b/src/qml/presenter/PresentationWindow.qml index 24ec3c3..e5e3b47 100644 --- a/src/qml/presenter/PresentationWindow.qml +++ b/src/qml/presenter/PresentationWindow.qml @@ -14,7 +14,7 @@ Window { width: maximumWidth screen: presentationScreen /* flags: Qt.X11BypassWindowManagerHint */ - onClosing: presenting = false + onClosing: close() Component.onCompleted: { presentationWindow.showFullScreen(); @@ -34,6 +34,11 @@ Window { onVideoBackgroundChanged: { loadVideo(); } + onIsPlayingChanged: { + if(SlideObject.isPlaying) + presentationSlide.playVideo(); + pauseVideo(); + } } function loadVideo() { @@ -43,4 +48,14 @@ Window { function stopVideo() { presentationSlide.stopVideo() } + + function pauseVideo() { + presentationSlide.pauseVideo(); + } + + function close() { + presentationSlide.stopVideo(); + SlideObject.pause(); + presenting = false; + } } diff --git a/src/qml/presenter/Slide.qml b/src/qml/presenter/Slide.qml index da859c9..619c029 100644 --- a/src/qml/presenter/Slide.qml +++ b/src/qml/presenter/Slide.qml @@ -45,7 +45,7 @@ Item { MpvObject { id: mpv - objectName: "mpv" + /* objectName: "mpv" */ anchors.fill: parent useHwdec: true enableAudio: !preview @@ -178,4 +178,8 @@ Item { function playPauseVideo() { mpv.playPause(); } + + function playVideo() { + mpv.play(); + } } diff --git a/src/slide.cpp b/src/slide.cpp index f079922..338d1e8 100644 --- a/src/slide.cpp +++ b/src/slide.cpp @@ -12,10 +12,12 @@ Slide::Slide(QObject *parent) Slide::Slide(const QString &text, const QString &audio, const QString &imageBackground, const QString &videoBackground, const QString &horizontalTextAlignment, const QString &verticalTextAlignment, const QString &font, - const int &fontSize, const QString &type, QObject *parent) + const int &fontSize, const bool &isPlaying, + const QString &type, QObject *parent) : QObject(parent),m_text(text),m_audio(audio),m_imageBackground(imageBackground), m_videoBackground(videoBackground),m_verticalTextAlignment(verticalTextAlignment), - m_horizontalTextAlignment(horizontalTextAlignment),m_font(font),m_fontSize(fontSize),m_type(type) + m_horizontalTextAlignment(horizontalTextAlignment),m_font(font), + m_fontSize(fontSize),m_isPlaying(isPlaying),m_type(type) { qDebug() << "Initializing slide with defaults"; } @@ -66,6 +68,11 @@ int Slide::fontSize() const return m_fontSize; } +bool Slide::isPlaying() const +{ + return m_isPlaying; +} + void Slide::setText(QString text) { if (m_text == text) @@ -231,3 +238,21 @@ bool Slide::previous(QVariantMap prevItem) return false; } + +void Slide::play() +{ + m_isPlaying = true; + emit isPlayingChanged(m_isPlaying); +} + +void Slide::pause() +{ + m_isPlaying = false; + emit isPlayingChanged(m_isPlaying); +} + +void Slide::playPause() +{ + m_isPlaying = !m_isPlaying; + emit isPlayingChanged(m_isPlaying); +} diff --git a/src/slide.h b/src/slide.h index 06661b2..962f981 100644 --- a/src/slide.h +++ b/src/slide.h @@ -21,13 +21,14 @@ class Slide : public QObject WRITE setVerticalTextAlignment NOTIFY verticalTextAlignmentChanged) Q_PROPERTY(QString font READ font WRITE setFont NOTIFY fontChanged) Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged) + Q_PROPERTY(bool isPlaying READ isPlaying NOTIFY isPlayingChanged) // QML_ELEMENT public: explicit Slide(QObject *parent = nullptr); Slide(const QString &text, const QString &audio, const QString &imageBackground, const QString &videoBackground, const QString &horizontalTextAlignment, const QString &verticalTextAlignment, - const QString &font, const int &fontSize, const QString &type, QObject * parent = nullptr); + const QString &font, const int &fontSize, const bool &isPlaying, const QString &type, QObject * parent = nullptr); QString text() const; QString type() const; @@ -39,6 +40,7 @@ public: QString verticalTextAlignment() const; QString font() const; int fontSize() const; + bool isPlaying() const; Q_INVOKABLE void setText(QString text); Q_INVOKABLE void setType(QString type); @@ -52,6 +54,9 @@ public: Q_INVOKABLE void setFontSize(int fontSize); Q_INVOKABLE void changeSlide(QVariantMap item); + Q_INVOKABLE void play(); + Q_INVOKABLE void pause(); + Q_INVOKABLE void playPause(); Q_INVOKABLE bool next(QVariantMap nextItem); Q_INVOKABLE bool previous(QVariantMap prevItem); @@ -66,6 +71,7 @@ signals: Q_INVOKABLE void verticalTextAlignmentChanged(QString verticalTextAlignment); Q_INVOKABLE void fontChanged(QString font); Q_INVOKABLE void fontSizeChanged(int fontSize); + Q_INVOKABLE void isPlayingChanged(bool isPlaying); private: int m_id; @@ -79,6 +85,7 @@ private: QString m_verticalTextAlignment; QString m_font; int m_fontSize; + bool m_isPlaying; int m_slideIndex; int m_slideSize;