Sélectionner une révision Git
-
Kubat a rédigé
The race condition between Qt's widget creation and mpv getting the WID doesn't seem to be fixed for now, will need to investigate further.
Kubat a rédigéThe race condition between Qt's widget creation and mpv getting the WID doesn't seem to be fixed for now, will need to investigate further.
MpvControls.cc 3,08 Kio
#include "MpvControls.hh"
#include "MpvContainer.hh"
using namespace Vivy;
MpvControls::MpvControls(MpvContainer *passedContainer, QWidget *parent) noexcept
: QWidget(parent)
, mpv(passedContainer)
{
auto *progressBar = new QSlider(this);
auto *togglePlaybackButton = new QPushButton(playIcon, "", this); // Be default MPV is paused
auto *reCreateMpvButton = new QPushButton(
reCreateMpvIcon, "", this); // Recreate the MPV context if something went wrong
progressBar->setTracking(false);
progressBar->setOrientation(Qt::Horizontal);
mpv->registerMpvDurationCallback([progressBar, this](double time) noexcept -> void {
timePosition = chrono::seconds::zero();
timeDuration = chrono::seconds(static_cast<long>(time));
progressBar->setMaximum(static_cast<int>(timeDuration.count()));
progressBar->setValue(0);
});
mpv->registerMpvTimeCallback([progressBar, this](double time) noexcept -> void {
if (!progressBar->isSliderDown()) {
// The user is not pressing the slider
timePosition = chrono::seconds(static_cast<long>(time));
progressBar->setValue(static_cast<int>(timePosition.count()));
}
});
connect(progressBar, &QAbstractSlider::sliderMoved, this,
[this](int value) noexcept -> void { askedSliderPosition = value; });
connect(progressBar, &QAbstractSlider::actionTriggered, this,
[progressBar](int action) noexcept -> void {
switch (static_cast<QAbstractSlider::SliderAction>(action)) {
case QAbstractSlider::SliderSingleStepAdd:
case QAbstractSlider::SliderSingleStepSub:
case QAbstractSlider::SliderPageStepAdd:
case QAbstractSlider::SliderPageStepSub:
progressBar->setSliderPosition(progressBar->value());
break;
case QAbstractSlider::SliderAction::SliderMove:
case QAbstractSlider::SliderNoAction:
case QAbstractSlider::SliderToMinimum:
case QAbstractSlider::SliderToMaximum: break;
}
});
connect(progressBar, &QAbstractSlider::sliderReleased, this, [this]() noexcept -> void {
qDebug() << "Slider set to" << askedSliderPosition << "max was" << timeDuration.count();
timePosition = chrono::seconds(askedSliderPosition);
mpv->seekInFile(timePosition);
});
connect(togglePlaybackButton, &QAbstractButton::clicked, mpv, &MpvContainer::mpvTogglePlayback);
connect(reCreateMpvButton, &QAbstractButton::clicked, mpv, &MpvContainer::reCreateMpvContext);
connect(mpv, &MpvContainer::mpvPlaybackToggled, this,
[this, togglePlaybackButton](bool isPlay) noexcept -> void {
togglePlaybackButton->setIcon(isPlay ? pauseIcon : playIcon);
});
auto *centralLayout = new QHBoxLayout(this);
centralLayout->addWidget(togglePlaybackButton);
centralLayout->addWidget(reCreateMpvButton);
centralLayout->addWidget(progressBar, 1);
setLayout(centralLayout);
}