]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/information/mediawidget.h
InformationPanel: Port from Phonon to QtMultimedia
[dolphin.git] / src / panels / information / mediawidget.h
1 /*
2 SPDX-FileCopyrightText: 2007 Matthias Kretz <kretz@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #ifndef MEDIAWIDGET_H
8 #define MEDIAWIDGET_H
9
10 #include <QSize>
11 #include <QSlider>
12 #include <QUrl>
13 #include <QWidget>
14
15 #include <QMediaPlayer>
16
17 class QMediaPlayer;
18 class SeekSlider;
19
20 class EmbeddedVideoPlayer;
21 class QToolButton;
22 class QVBoxLayout;
23
24 class MediaWidget : public QWidget
25 {
26 Q_OBJECT
27 public:
28 enum MediaKind { Video, Audio };
29
30 explicit MediaWidget(QWidget *parent = nullptr);
31
32 void setUrl(const QUrl &url, MediaKind kind);
33 QUrl url() const;
34 void clearUrl();
35
36 void setVideoSize(const QSize &size);
37 QSize videoSize() const;
38 QMediaPlayer::PlaybackState state() const;
39
40 void setAutoPlay(bool autoPlay);
41 bool eventFilter(QObject *object, QEvent *event) override;
42
43 Q_SIGNALS:
44 /**
45 * Is emitted whenever the video-state
46 * has changed: If true is returned, a video
47 * including control-buttons will be shown.
48 * If false is returned, no video is shown
49 * and the control-buttons are available for
50 * audio only.
51 */
52 void hasVideoChanged(bool hasVideo);
53
54 public Q_SLOTS:
55 void play();
56
57 protected:
58 void showEvent(QShowEvent *event) override;
59 void hideEvent(QHideEvent *event) override;
60
61 private Q_SLOTS:
62 void stop();
63 void finished();
64 void setPosition(qint64 position);
65 void onStateChanged(QMediaPlayer::PlaybackState newState);
66 void onPositionChanged(qint64 position);
67 void onDurationChanged(qint64 position);
68
69 private:
70 void applyVideoSize();
71 void togglePlayback();
72 void initPlayer();
73
74 QUrl m_url;
75 QSize m_videoSize;
76
77 QToolButton *m_playButton;
78 QToolButton *m_pauseButton;
79
80 QVBoxLayout *m_topLayout;
81 QMediaPlayer *m_player;
82 QSlider *m_seekSlider;
83 EmbeddedVideoPlayer *m_videoWidget;
84 bool m_autoPlay;
85 bool m_isVideo;
86 };
87
88 #endif // MEDIAWIDGET_H