X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/15faff457dd5ff609b3d6d824e0366beae1abe28..e6c1b97d67f6b6c6d4ad935db14241b041b3fca4:/src/panels/information/phononwidget.cpp diff --git a/src/panels/information/phononwidget.cpp b/src/panels/information/phononwidget.cpp index a36ada180..4ea2e6666 100644 --- a/src/panels/information/phononwidget.cpp +++ b/src/panels/information/phononwidget.cpp @@ -20,26 +20,23 @@ #include "phononwidget.h" +#include +#include #include -#include #include #include #include -#include -#include #include #include - -#include -#include -#include -#include +#include class EmbeddedVideoPlayer : public Phonon::VideoWidget { + Q_OBJECT + public: - EmbeddedVideoPlayer(QWidget *parent = 0) : + EmbeddedVideoPlayer(QWidget *parent = nullptr) : Phonon::VideoWidget(parent) { } @@ -50,7 +47,7 @@ class EmbeddedVideoPlayer : public Phonon::VideoWidget updateGeometry(); } - virtual QSize sizeHint() const + QSize sizeHint() const override { return m_sizeHint.isValid() ? m_sizeHint : Phonon::VideoWidget::sizeHint(); } @@ -62,25 +59,38 @@ class EmbeddedVideoPlayer : public Phonon::VideoWidget PhononWidget::PhononWidget(QWidget *parent) : QWidget(parent), m_url(), - m_playButton(0), - m_stopButton(0), - m_topLayout(0), - m_media(0), - m_seekSlider(0), - m_audioOutput(0), - m_videoPlayer(0) + m_playButton(nullptr), + m_stopButton(nullptr), + m_topLayout(nullptr), + m_media(nullptr), + m_seekSlider(nullptr), + m_audioOutput(nullptr), + m_videoPlayer(nullptr) { } -void PhononWidget::setUrl(const KUrl &url) +void PhononWidget::setUrl(const QUrl &url, MediaKind kind) { if (m_url != url) { - stop(); // emits playingStopped() signal m_url = url; + m_isVideo = kind == MediaKind::Video; + } + if (m_autoPlay) { + play(); + } else { + stop(); } } -KUrl PhononWidget::url() const +void PhononWidget::setAutoPlay(bool autoPlay) +{ + m_autoPlay = autoPlay; + if (!m_url.isEmpty() && (m_media == nullptr || m_media->state() != Phonon::State::PlayingState) && m_autoPlay && isVisible()) { + play(); + } +} + +QUrl PhononWidget::url() const { return m_url; } @@ -107,10 +117,10 @@ void PhononWidget::showEvent(QShowEvent *event) if (!m_topLayout) { m_topLayout = new QVBoxLayout(this); - m_topLayout->setMargin(0); - m_topLayout->setSpacing(KDialog::spacingHint()); - QHBoxLayout *controlsLayout = new QHBoxLayout(this); - controlsLayout->setMargin(0); + m_topLayout->setContentsMargins(0, 0, 0, 0); + + QHBoxLayout *controlsLayout = new QHBoxLayout(); + controlsLayout->setContentsMargins(0, 0, 0, 0); controlsLayout->setSpacing(0); m_playButton = new QToolButton(this); @@ -128,16 +138,16 @@ void PhononWidget::showEvent(QShowEvent *event) m_playButton->setToolTip(i18n("play")); m_playButton->setIconSize(buttonSize); - m_playButton->setIcon(KIcon("media-playback-start")); + m_playButton->setIcon(QIcon::fromTheme(QStringLiteral("media-playback-start"))); m_playButton->setAutoRaise(true); - connect(m_playButton, SIGNAL(clicked()), this, SLOT(play())); + connect(m_playButton, &QToolButton::clicked, this, &PhononWidget::play); m_stopButton->setToolTip(i18n("stop")); m_stopButton->setIconSize(buttonSize); - m_stopButton->setIcon(KIcon("media-playback-stop")); + m_stopButton->setIcon(QIcon::fromTheme(QStringLiteral("media-playback-stop"))); m_stopButton->setAutoRaise(true); m_stopButton->hide(); - connect(m_stopButton, SIGNAL(clicked()), this, SLOT(stop())); + connect(m_stopButton, &QToolButton::clicked, this, &PhononWidget::stop); m_seekSlider->setIconVisible(false); @@ -177,56 +187,52 @@ void PhononWidget::play() { if (!m_media) { m_media = new Phonon::MediaObject(this); - connect(m_media, SIGNAL(stateChanged(Phonon::State,Phonon::State)), - this, SLOT(stateChanged(Phonon::State))); - connect(m_media, SIGNAL(hasVideoChanged(bool)), - this, SLOT(slotHasVideoChanged(bool))); + connect(m_media, &Phonon::MediaObject::stateChanged, + this, &PhononWidget::stateChanged); + connect(m_media, &Phonon::MediaObject::finished, + this, &PhononWidget::finished); m_seekSlider->setMediaObject(m_media); } + if (!m_videoPlayer) { + m_videoPlayer = new EmbeddedVideoPlayer(this); + m_videoPlayer->installEventFilter(this); + m_topLayout->insertWidget(0, m_videoPlayer); + Phonon::createPath(m_media, m_videoPlayer); + applyVideoSize(); + } + if (!m_audioOutput) { m_audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); Phonon::createPath(m_media, m_audioOutput); } - emit hasVideoChanged(false); + if (m_isVideo) { + emit hasVideoChanged(true); + } - m_media->setCurrentSource(m_url); - m_media->hasVideo(); + if (m_url != m_media->currentSource().url()) { + m_media->setCurrentSource(m_url); + } m_media->play(); + + m_videoPlayer->setVisible(m_isVideo); } -void PhononWidget::stop() +void PhononWidget::finished() { - if (m_media) { - m_media->stop(); - - m_stopButton->hide(); - m_playButton->show(); - } - - if (m_videoPlayer) { + if (m_isVideo) { m_videoPlayer->hide(); + emit hasVideoChanged(false); } - - emit hasVideoChanged(false); } -void PhononWidget::slotHasVideoChanged(bool hasVideo) +void PhononWidget::stop() { - emit hasVideoChanged(hasVideo); - - if (hasVideo) { - if (!m_videoPlayer) { - // Replay the media to apply path changes - m_media->stop(); - m_videoPlayer = new EmbeddedVideoPlayer(this); - m_topLayout->insertWidget(0, m_videoPlayer); - Phonon::createPath(m_media, m_videoPlayer); - m_media->play(); - } - applyVideoSize(); - m_videoPlayer->show(); + if (m_media) { + m_media->stop(); + m_videoPlayer->hide(); + emit hasVideoChanged(false); } } @@ -236,3 +242,5 @@ void PhononWidget::applyVideoSize() m_videoPlayer->setSizeHint(m_videoSize); } } + +#include "phononwidget.moc"