]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/panels/information/phononwidget.cpp
Merge branch 'release/21.12'
[dolphin.git] / src / panels / information / phononwidget.cpp
index e301df2703139ec24fd94b363aac708a8cd52fa7..c9ccaa86ce0a5ff238f97cc56af7bd4a8d49447f 100644 (file)
@@ -1,26 +1,11 @@
-/*  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>
@@ -28,6 +13,7 @@
 #include <Phonon/VideoWidget>
 
 #include <QShowEvent>
+#include <QStyle>
 #include <QToolButton>
 #include <QVBoxLayout>
 
@@ -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),
@@ -100,6 +86,15 @@ 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)
@@ -107,11 +102,7 @@ bool PhononWidget::eventFilter(QObject *object, QEvent *event)
         const QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
         if (mouseEvent->button() == Qt::LeftButton) {
             // toggle playback
-            if (m_media && m_media->state() == Phonon::State::PlayingState) {
-                m_media->pause();
-            } else {
-                play();
-            }
+            togglePlayback();
             return true;
         }
     }
@@ -147,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"));
@@ -165,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);
 
@@ -196,10 +187,10 @@ void PhononWidget::stateChanged(Phonon::State newstate)
     case Phonon::PlayingState:
     case Phonon::BufferingState:
         m_playButton->hide();
-        m_stopButton->show();
+        m_pauseButton->show();
         break;
     default:
-        m_stopButton->hide();
+        m_pauseButton->hide();
         m_playButton->show();
         break;
     }
@@ -232,7 +223,7 @@ void PhononWidget::play()
     }
 
     if (m_isVideo) {
-        emit hasVideoChanged(true);
+        Q_EMIT hasVideoChanged(true);
     }
 
     if (m_url != m_media->currentSource().url()) {
@@ -247,7 +238,7 @@ void PhononWidget::finished()
 {
     if (m_isVideo) {
         m_videoPlayer->hide();
-        emit hasVideoChanged(false);
+        Q_EMIT hasVideoChanged(false);
     }
 }
 
@@ -261,7 +252,7 @@ void PhononWidget::stop()
     if (m_media) {
         m_media->stop();
         m_videoPlayer->hide();
-        emit hasVideoChanged(false);
+        Q_EMIT hasVideoChanged(false);
     }
 }