From eaec53a7af4e098acd957a274f059920d569e0be Mon Sep 17 00:00:00 2001 From: Méven Car Date: Tue, 27 Aug 2019 13:04:56 +0200 Subject: Add click to play/pause feature on previews for audio/video Test Plan: In dolphin, click on a video or audio preview in the information panel. The video or audio preview starts Reviewers: elvisangelaccio, #dolphin, ngraham Reviewed By: elvisangelaccio, #dolphin, ngraham Subscribers: alexde, anthonyfieroni, ngraham, kfm-devel Tags: #dolphin Differential Revision: https://phabricator.kde.org/D22183 --- src/panels/information/phononwidget.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/panels/information/phononwidget.cpp') diff --git a/src/panels/information/phononwidget.cpp b/src/panels/information/phononwidget.cpp index 4ea2e6666..e301df270 100644 --- a/src/panels/information/phononwidget.cpp +++ b/src/panels/information/phononwidget.cpp @@ -95,6 +95,29 @@ QUrl PhononWidget::url() const return m_url; } +void PhononWidget::clearUrl() +{ + m_url.clear(); +} + +bool PhononWidget::eventFilter(QObject *object, QEvent *event) +{ + Q_UNUSED(object) + if (event->type() == QEvent::MouseButtonPress) { + const QMouseEvent *mouseEvent = static_cast(event); + if (mouseEvent->button() == Qt::LeftButton) { + // toggle playback + if (m_media && m_media->state() == Phonon::State::PlayingState) { + m_media->pause(); + } else { + play(); + } + return true; + } + } + return false; +} + void PhononWidget::setVideoSize(const QSize& size) { if (m_videoSize != size) { @@ -172,8 +195,8 @@ void PhononWidget::stateChanged(Phonon::State newstate) switch (newstate) { case Phonon::PlayingState: case Phonon::BufferingState: - m_stopButton->show(); m_playButton->hide(); + m_stopButton->show(); break; default: m_stopButton->hide(); @@ -196,6 +219,7 @@ void PhononWidget::play() if (!m_videoPlayer) { m_videoPlayer = new EmbeddedVideoPlayer(this); + m_videoPlayer->setCursor(Qt::PointingHandCursor); m_videoPlayer->installEventFilter(this); m_topLayout->insertWidget(0, m_videoPlayer); Phonon::createPath(m_media, m_videoPlayer); @@ -227,6 +251,11 @@ void PhononWidget::finished() } } +Phonon::State PhononWidget::state() const +{ + return m_media == nullptr ? Phonon::State::StoppedState : m_media->state(); +} + void PhononWidget::stop() { if (m_media) { -- cgit v1.3