Misc. fixes.
[wallplayer.git] / src / qmpwidget.h
blob5dcbeefbdd4575cea3ad21d28705fcc9bc633da7
1 /*
2 * qmpwidget - A Qt widget for embedding MPlayer
3 * Copyright (C) 2010 by Jonas Gehring
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef QMPWIDGET_H_
21 #define QMPWIDGET_H_
24 #include <QHash>
25 #include <QPointer>
26 #include <QTimer>
27 #include <QWidget>
29 class QAbstractSlider;
30 class QImage;
31 class QProcess;
32 class QStringList;
34 class QMPProcess;
37 class QMPwidget : public QWidget
39 Q_OBJECT
40 Q_PROPERTY(State state READ state);
41 Q_PROPERTY(double streamPosition READ tell);
42 Q_PROPERTY(QString videoOutput READ videoOutput WRITE setVideoOutput);
43 Q_PROPERTY(QString mplayerPath READ mplayerPath WRITE setMPlayerPath);
44 Q_PROPERTY(QString mplayerVersion READ mplayerVersion);
45 Q_ENUMS(state);
47 public:
48 enum State {
49 NotStartedState = -1,
50 IdleState,
51 LoadingState,
52 StoppedState,
53 PlayingState,
54 BufferingState,
55 PausedState,
56 ErrorState
59 struct MediaInfo {
60 QString videoFormat;
61 int videoBitrate;
62 QSize size;
63 double framesPerSecond;
65 QString audioFormat;
66 double audioBitrate;
67 int sampleRate;
68 int numChannels;
70 QHash<QString, QString> tags;
72 bool ok;
73 double length;
74 bool seekable;
76 MediaInfo();
79 enum Mode {
80 EmbeddedMode = 0,
81 PipeMode
84 enum SeekMode {
85 RelativeSeek = 0,
86 PercentageSeek,
87 AbsoluteSeek
90 public:
91 QMPwidget(QWidget *parent = 0);
92 virtual ~QMPwidget();
94 State state() const;
95 MediaInfo mediaInfo() const;
96 double tell() const;
97 QProcess *process() const;
99 void setMode(Mode mode);
100 Mode mode() const;
102 void setVideoOutput(const QString &output);
103 QString videoOutput() const;
105 void setMPlayerPath(const QString &path);
106 QString mplayerPath() const;
107 QString mplayerVersion();
109 void setSeekSlider(QAbstractSlider *slider);
110 void setVolumeSlider(QAbstractSlider *slider);
112 void showImage(const QImage &image);
114 virtual QSize sizeHint() const;
116 public slots:
117 void start(const QStringList &args = QStringList());
118 void load(const QString &url);
119 void play();
120 void pause();
121 void stop();
122 bool seek(int offset, int whence = AbsoluteSeek);
123 bool seek(double offset, int whence = AbsoluteSeek);
125 void toggleFullScreen();
127 void writeCommand(const QString &command);
129 void updateWidgetSize();
131 protected:
132 QWidget *m_widget;
133 virtual void mouseDoubleClickEvent(QMouseEvent *event);
134 virtual void keyPressEvent(QKeyEvent *event);
135 virtual void resizeEvent(QResizeEvent *event);
137 public slots:
138 void setVolume(int volume);
140 private slots:
141 void mpStateChanged(int state);
142 void mpStreamPositionChanged(double position);
143 void mpVolumeChanged(int volume);
144 void delayedSeek();
146 signals:
147 void stateChanged(int state);
148 void error(const QString &reason);
150 void readStandardOutput(const QString &line);
151 void readStandardError(const QString &line);
153 private:
154 QMPProcess *m_process;
155 QPointer<QAbstractSlider> m_seekSlider;
156 QPointer<QAbstractSlider> m_volumeSlider;
157 Qt::WindowFlags m_windowFlags;
158 QRect m_geometry;
160 QTimer m_seekTimer;
161 QString m_seekCommand;
165 #endif // QMPWIDGET_H_