From 2e150f56da877bc7ffa5b367d1ef4b422a4887b5 Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Wed, 4 Aug 2021 10:30:20 +0200 Subject: [PATCH] UI: Add a button to control MPV playback --- src/UI/DocumentViews/MpvContainer.cc | 1 + src/UI/DocumentViews/MpvControls.cc | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/UI/DocumentViews/MpvContainer.cc b/src/UI/DocumentViews/MpvContainer.cc index 2930a7d9..ddaebac6 100644 --- a/src/UI/DocumentViews/MpvContainer.cc +++ b/src/UI/DocumentViews/MpvContainer.cc @@ -281,6 +281,7 @@ MpvContainer::mpvPause() noexcept void MpvContainer::mpvTogglePlayback() noexcept { + qDebug() << "MPV: Toggling the playback"; asyncCommand(AsyncCmdType::TogglePlayback, { "cycle", "pause", "up", nullptr }); } diff --git a/src/UI/DocumentViews/MpvControls.cc b/src/UI/DocumentViews/MpvControls.cc index a40a1988..375ca3f9 100644 --- a/src/UI/DocumentViews/MpvControls.cc +++ b/src/UI/DocumentViews/MpvControls.cc @@ -2,7 +2,8 @@ #include "MpvContainer.hh" #include <QSlider> -#include <QVBoxLayout> +#include <QHBoxLayout> +#include <QPushButton> using namespace Vivy; @@ -10,7 +11,9 @@ MpvControls::MpvControls(MpvContainer *passedContainer, QWidget *parent) noexcep : QWidget(parent) , mpv(passedContainer) { - auto *progressBar = new QSlider(this); + auto *progressBar = new QSlider(this); + auto *togglePlaybackButton = new QPushButton("Pause", this); // Be default MPV is paused + progressBar->setTracking(false); progressBar->setOrientation(Qt::Horizontal); @@ -33,7 +36,15 @@ MpvControls::MpvControls(MpvContainer *passedContainer, QWidget *parent) noexcep timePosition = value; }); - auto *centralLayout = new QVBoxLayout(this); - centralLayout->addWidget(progressBar); + connect(togglePlaybackButton, &QAbstractButton::clicked, mpv, &MpvContainer::mpvTogglePlayback); + connect(mpv, &MpvContainer::mpvPlaybackToggled, this, + [togglePlaybackButton](bool isPlay) noexcept -> void { + togglePlaybackButton->setText(isPlay ? QStringLiteral("Play") + : QStringLiteral("Pause")); + }); + + auto *centralLayout = new QHBoxLayout(this); + centralLayout->addWidget(togglePlaybackButton); + centralLayout->addWidget(progressBar, 1); setLayout(centralLayout); } -- GitLab