File indexing completed on 2024-05-12 17:18:50

0001 /*
0002   SPDX-FileCopyrightText: 2007 Matthias Kretz <kretz@kde.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef PHONONWIDGET_H
0008 #define PHONONWIDGET_H
0009 
0010 #include <phonon/Global>
0011 
0012 #include <QSize>
0013 #include <QUrl>
0014 #include <QWidget>
0015 
0016 namespace Phonon
0017 {
0018 class AudioOutput;
0019 class MediaObject;
0020 class SeekSlider;
0021 class VideoPlayer;
0022 } // namespace Phonon
0023 
0024 class EmbeddedVideoPlayer;
0025 class QToolButton;
0026 class QVBoxLayout;
0027 
0028 class PhononWidget : public QWidget
0029 {
0030     Q_OBJECT
0031 public:
0032     enum MediaKind { Video, Audio };
0033 
0034     explicit PhononWidget(QWidget *parent = nullptr);
0035 
0036     void setUrl(const QUrl &url, MediaKind kind);
0037     QUrl url() const;
0038     void clearUrl();
0039 
0040     void setVideoSize(const QSize &size);
0041     QSize videoSize() const;
0042     Phonon::State state() const;
0043 
0044     void setAutoPlay(bool autoPlay);
0045     bool eventFilter(QObject *object, QEvent *event) override;
0046 
0047 Q_SIGNALS:
0048     /**
0049      * Is emitted whenever the video-state
0050      * has changed: If true is returned, a video
0051      * including control-buttons will be shown.
0052      * If false is returned, no video is shown
0053      * and the control-buttons are available for
0054      * audio only.
0055      */
0056     void hasVideoChanged(bool hasVideo);
0057 
0058 public Q_SLOTS:
0059     void play();
0060 
0061 protected:
0062     void showEvent(QShowEvent *event) override;
0063     void hideEvent(QHideEvent *event) override;
0064 
0065 private Q_SLOTS:
0066     void stateChanged(Phonon::State newstate);
0067     void stop();
0068     void finished();
0069 
0070 private:
0071     void applyVideoSize();
0072 
0073 private:
0074     void togglePlayback();
0075 
0076     QUrl m_url;
0077     QSize m_videoSize;
0078 
0079     QToolButton *m_playButton;
0080     QToolButton *m_pauseButton;
0081 
0082     QVBoxLayout *m_topLayout;
0083     Phonon::MediaObject *m_media;
0084     Phonon::SeekSlider *m_seekSlider;
0085     Phonon::AudioOutput *m_audioOutput;
0086     EmbeddedVideoPlayer *m_videoPlayer;
0087     bool m_autoPlay;
0088     bool m_isVideo;
0089 };
0090 
0091 #endif // PHONONWIDGET_H