From 92f43d7bedccbf38bf27edf21f83945ca9d4274f Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Tue, 3 Aug 2021 18:30:27 +0200 Subject: [PATCH] UI: Keep track of the position in the MpvControls + log deletion of mpv context (for debug) --- src/UI/DocumentViews/MpvContainer.cc | 1 + src/UI/DocumentViews/MpvControls.cc | 16 ++++++++++++---- src/UI/DocumentViews/MpvControls.hh | 2 ++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/UI/DocumentViews/MpvContainer.cc b/src/UI/DocumentViews/MpvContainer.cc index fcc6d076..1d87e892 100644 --- a/src/UI/DocumentViews/MpvContainer.cc +++ b/src/UI/DocumentViews/MpvContainer.cc @@ -60,6 +60,7 @@ void MpvContainer::closeMpv() noexcept { if (mpv) { + qDebug() << "Closing the MPV context"; registerMpvTimeCallback(nullptr); registerMpvDurationCallback(nullptr); mpv_handle *tmp_mpv = mpv; diff --git a/src/UI/DocumentViews/MpvControls.cc b/src/UI/DocumentViews/MpvControls.cc index 57151389..a40a1988 100644 --- a/src/UI/DocumentViews/MpvControls.cc +++ b/src/UI/DocumentViews/MpvControls.cc @@ -14,17 +14,25 @@ MpvControls::MpvControls(MpvContainer *passedContainer, QWidget *parent) noexcep progressBar->setTracking(false); progressBar->setOrientation(Qt::Horizontal); - mpv->registerMpvDurationCallback([progressBar](double time) noexcept -> void { - progressBar->setMaximum(static_cast<int>(time)); + mpv->registerMpvDurationCallback([progressBar, this](double time) noexcept -> void { + timePosition = 0; + timeDuration = static_cast<int>(time); + progressBar->setMaximum(timeDuration); progressBar->setValue(0); }); - mpv->registerMpvTimeCallback([progressBar](double time) noexcept -> void { + mpv->registerMpvTimeCallback([progressBar, this](double time) noexcept -> void { if (!progressBar->isSliderDown()) { // The user is not pressing the slider - progressBar->setValue(static_cast<int>(time)); + timePosition = static_cast<int>(time); + progressBar->setValue(timePosition); } }); + connect(progressBar, &QAbstractSlider::valueChanged, this, [this](int value) noexcept -> void { + qDebug() << "Slider set to" << value << "max was" << timeDuration; + timePosition = value; + }); + auto *centralLayout = new QVBoxLayout(this); centralLayout->addWidget(progressBar); setLayout(centralLayout); diff --git a/src/UI/DocumentViews/MpvControls.hh b/src/UI/DocumentViews/MpvControls.hh index acb53d11..ef57d299 100644 --- a/src/UI/DocumentViews/MpvControls.hh +++ b/src/UI/DocumentViews/MpvControls.hh @@ -14,6 +14,8 @@ class MpvControls final : public QWidget { private: MpvContainer *mpv{ nullptr }; + int timeDuration; + int timePosition; public: explicit MpvControls(MpvContainer *mpv, QWidget *parent) noexcept; -- GitLab