-/* This file is part of the KDE project
- Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
-
- 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 <kretz@kde.org>
+ SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "phononwidget.h"
-#include <KIconLoader>
#include <KLocalizedString>
#include <Phonon/AudioOutput>
#include <Phonon/MediaObject>
#include <Phonon/VideoWidget>
#include <QShowEvent>
+#include <QStyle>
#include <QToolButton>
#include <QVBoxLayout>
: QWidget(parent),
m_url(),
m_playButton(nullptr),
- m_stopButton(nullptr),
+ m_pauseButton(nullptr),
m_topLayout(nullptr),
m_media(nullptr),
m_seekSlider(nullptr),
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<QMouseEvent*>(event);
+ if (mouseEvent->button() == Qt::LeftButton) {
+ // toggle playback
+ togglePlayback();
+ return true;
+ }
+ }
+ return false;
+}
+
void PhononWidget::setVideoSize(const QSize& size)
{
if (m_videoSize != size) {
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"));
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);
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;
}
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);
}
}
+Phonon::State PhononWidget::state() const
+{
+ return m_media == nullptr ? Phonon::State::StoppedState : m_media->state();
+}
+
void PhononWidget::stop()
{
if (m_media) {