~ubuntu-app-review-contributors/ubuntu-app-reviews/minicast

« back to all changes in this revision

Viewing changes to qmpwidget.h

  • Committer: Aaron Lewis
  • Date: 2012-07-09 07:20:16 UTC
  • Revision ID: the.warl0ck.1989@gmail.com-20120709072016-qskuu5vwffan7reu
Initial Release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  qmpwidget - A Qt widget for embedding MPlayer
 
3
 *  Copyright (C) 2010 by Jonas Gehring
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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/>.
 
17
 */
 
18
 
 
19
 
 
20
#ifndef QMPWIDGET_H_
 
21
#define QMPWIDGET_H_
 
22
 
 
23
 
 
24
#include <QHash>
 
25
#include <QPointer>
 
26
#include <QTimer>
 
27
#include <QWidget>
 
28
 
 
29
class QAbstractSlider;
 
30
class QImage;
 
31
class QProcess;
 
32
class QStringList;
 
33
 
 
34
class QMPProcess;
 
35
 
 
36
 
 
37
class QMPwidget : public QWidget
 
38
{
 
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)
 
46
 
 
47
        public:
 
48
                enum State {
 
49
                        NotStartedState = -1,
 
50
                        IdleState,
 
51
                        LoadingState,
 
52
                        StoppedState,
 
53
                        PlayingState,
 
54
                        BufferingState,
 
55
                        PausedState,
 
56
                        ErrorState
 
57
                };
 
58
 
 
59
                struct MediaInfo {
 
60
                        QString videoFormat;
 
61
                        int videoBitrate;
 
62
                        QSize size;
 
63
                        double framesPerSecond;
 
64
 
 
65
                        QString audioFormat;
 
66
                        double audioBitrate;
 
67
                        int sampleRate;
 
68
                        int numChannels;
 
69
 
 
70
                        QHash<QString, QString> tags;
 
71
 
 
72
                        bool ok;
 
73
                        double length;
 
74
                        bool seekable;
 
75
 
 
76
                        MediaInfo();
 
77
                };
 
78
 
 
79
                enum Mode {
 
80
                        EmbeddedMode = 0,
 
81
                        PipeMode
 
82
                };
 
83
 
 
84
                enum SeekMode {
 
85
                        RelativeSeek = 0,
 
86
                        PercentageSeek,
 
87
                        AbsoluteSeek
 
88
                };
 
89
 
 
90
        public:
 
91
                QMPwidget(QWidget *parent = 0);
 
92
                virtual ~QMPwidget();
 
93
 
 
94
                State state() const;
 
95
                MediaInfo mediaInfo() const;
 
96
                double tell() const;
 
97
                QProcess *process() const;
 
98
 
 
99
                void setMode(Mode mode);
 
100
                Mode mode() const;
 
101
 
 
102
                void setVideoOutput(const QString &output);
 
103
                QString videoOutput() const;
 
104
 
 
105
                void setMPlayerPath(const QString &path);
 
106
                QString mplayerPath() const;
 
107
                QString mplayerVersion();
 
108
 
 
109
                void setSeekSlider(QAbstractSlider *slider);
 
110
                void setVolumeSlider(QAbstractSlider *slider);
 
111
 
 
112
                void showImage(const QImage &image);
 
113
 
 
114
                virtual QSize sizeHint() const;
 
115
 
 
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);
 
124
 
 
125
                void toggleFullScreen();
 
126
 
 
127
                void writeCommand(const QString &command);
 
128
 
 
129
        protected:
 
130
                virtual void mouseDoubleClickEvent(QMouseEvent *event);
 
131
                virtual void keyPressEvent(QKeyEvent *event);
 
132
                virtual void resizeEvent(QResizeEvent *event);
 
133
 
 
134
        private:
 
135
                void updateWidgetSize();
 
136
 
 
137
        private slots:
 
138
                void setVolume(int volume);
 
139
 
 
140
                void mpStateChanged(int state);
 
141
                void mpStreamPositionChanged(double position);
 
142
                void mpVolumeChanged(int volume);
 
143
                void delayedSeek();
 
144
 
 
145
        signals:
 
146
                void stateChanged(int state);
 
147
                void error(const QString &reason);
 
148
 
 
149
                void readStandardOutput(const QString &line);
 
150
                void readStandardError(const QString &line);
 
151
 
 
152
        private:
 
153
                QMPProcess *m_process;
 
154
                QWidget *m_widget;
 
155
                QPointer<QAbstractSlider> m_seekSlider;
 
156
                QPointer<QAbstractSlider> m_volumeSlider;
 
157
                Qt::WindowFlags m_windowFlags;
 
158
                QRect m_geometry;
 
159
 
 
160
                QTimer m_seekTimer;
 
161
                QString m_seekCommand;
 
162
};
 
163
 
 
164
 
 
165
#endif // QMPWIDGET_H_