X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/e6c1b97d67f6b6c6d4ad935db14241b041b3fca4..c68f1f6f8d6c24123c9c5df4d2e91a9d2462ceb6:/src/panels/information/phononwidget.cpp diff --git a/src/panels/information/phononwidget.cpp b/src/panels/information/phononwidget.cpp index 4ea2e6666..c9ccaa86c 100644 --- a/src/panels/information/phononwidget.cpp +++ b/src/panels/information/phononwidget.cpp @@ -1,26 +1,11 @@ -/* This file is part of the KDE project - Copyright (C) 2007 Matthias Kretz - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. +/* + SPDX-FileCopyrightText: 2007 Matthias Kretz + SPDX-License-Identifier: GPL-2.0-or-later */ #include "phononwidget.h" -#include #include #include #include @@ -28,6 +13,7 @@ #include #include +#include #include #include @@ -60,7 +46,7 @@ PhononWidget::PhononWidget(QWidget *parent) : QWidget(parent), m_url(), m_playButton(nullptr), - m_stopButton(nullptr), + m_pauseButton(nullptr), m_topLayout(nullptr), m_media(nullptr), m_seekSlider(nullptr), @@ -95,6 +81,34 @@ QUrl PhononWidget::url() const return m_url; } +void PhononWidget::clearUrl() +{ + m_url.clear(); +} + +void PhononWidget::togglePlayback() +{ + if (m_media && m_media->state() == Phonon::State::PlayingState) { + m_media->pause(); + } else { + play(); + } +} + +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 + togglePlayback(); + return true; + } + } + return false; +} + void PhononWidget::setVideoSize(const QSize& size) { if (m_videoSize != size) { @@ -124,16 +138,16 @@ void PhononWidget::showEvent(QShowEvent *event) controlsLayout->setSpacing(0); m_playButton = new QToolButton(this); - m_stopButton = new QToolButton(this); + m_pauseButton = new QToolButton(this); m_seekSlider = new Phonon::SeekSlider(this); controlsLayout->addWidget(m_playButton); - controlsLayout->addWidget(m_stopButton); + controlsLayout->addWidget(m_pauseButton); controlsLayout->addWidget(m_seekSlider); m_topLayout->addLayout(controlsLayout); - const int smallIconSize = IconSize(KIconLoader::Small); + const int smallIconSize = style()->pixelMetric(QStyle::PM_SmallIconSize); const QSize buttonSize(smallIconSize, smallIconSize); m_playButton->setToolTip(i18n("play")); @@ -142,12 +156,12 @@ void PhononWidget::showEvent(QShowEvent *event) m_playButton->setAutoRaise(true); connect(m_playButton, &QToolButton::clicked, this, &PhononWidget::play); - m_stopButton->setToolTip(i18n("stop")); - m_stopButton->setIconSize(buttonSize); - m_stopButton->setIcon(QIcon::fromTheme(QStringLiteral("media-playback-stop"))); - m_stopButton->setAutoRaise(true); - m_stopButton->hide(); - connect(m_stopButton, &QToolButton::clicked, this, &PhononWidget::stop); + m_pauseButton->setToolTip(i18n("pause")); + m_pauseButton->setIconSize(buttonSize); + m_pauseButton->setIcon(QIcon::fromTheme(QStringLiteral("media-playback-pause"))); + m_pauseButton->setAutoRaise(true); + m_pauseButton->hide(); + connect(m_pauseButton, &QToolButton::clicked, this, &PhononWidget::togglePlayback); m_seekSlider->setIconVisible(false); @@ -172,11 +186,11 @@ void PhononWidget::stateChanged(Phonon::State newstate) switch (newstate) { case Phonon::PlayingState: case Phonon::BufferingState: - m_stopButton->show(); m_playButton->hide(); + m_pauseButton->show(); break; default: - m_stopButton->hide(); + m_pauseButton->hide(); m_playButton->show(); break; } @@ -196,6 +210,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); @@ -208,7 +223,7 @@ void PhononWidget::play() } if (m_isVideo) { - emit hasVideoChanged(true); + Q_EMIT hasVideoChanged(true); } if (m_url != m_media->currentSource().url()) { @@ -223,16 +238,21 @@ void PhononWidget::finished() { if (m_isVideo) { m_videoPlayer->hide(); - emit hasVideoChanged(false); + Q_EMIT hasVideoChanged(false); } } +Phonon::State PhononWidget::state() const +{ + return m_media == nullptr ? Phonon::State::StoppedState : m_media->state(); +} + void PhononWidget::stop() { if (m_media) { m_media->stop(); m_videoPlayer->hide(); - emit hasVideoChanged(false); + Q_EMIT hasVideoChanged(false); } }