1 #ifndef VIDEOITEM_H 2 #define VIDEOITEM_H 3 4 #include <QQuickItem> 5 6 struct VideoItemPrivate; 7 8 class VideoItem : public QQuickItem 9 { 10 Q_OBJECT 11 Q_PROPERTY(bool hasVideo READ hasVideo NOTIFY hasVideoChanged) 12 Q_PROPERTY(State state READ state NOTIFY stateChanged) 13 Q_PROPERTY(QString source READ source WRITE setSource NOTIFY sourceChanged) 14 Q_PROPERTY(QRect rect READ rect NOTIFY rectChanged) 15 Q_PROPERTY(QSize resolution READ resolution NOTIFY resolutionChanged) 16 17 public: 18 enum State { 19 STATE_VOID_PENDING = 0, 20 STATE_NULL = 1, 21 STATE_READY = 2, 22 STATE_PAUSED = 3, 23 STATE_PLAYING = 4 24 }; 25 Q_ENUM(State); 26 27 explicit VideoItem(QQuickItem *parent = nullptr); 28 ~VideoItem(); 29 30 bool hasVideo() const; 31 32 QString source() const; 33 void setSource(const QString &source); 34 35 State state() const; 36 void setState(State state); 37 38 QRect rect() const; 39 40 QSize resolution() const; 41 42 Q_INVOKABLE void play(); 43 Q_INVOKABLE void stop(); 44 45 signals: 46 void hasVideoChanged(bool hasVideo); 47 void stateChanged(VideoItem::State state); 48 void sourceChanged(const QString &source); 49 void rectChanged(const QRect &rect); 50 void resolutionChanged(const QSize &resolution); 51 52 void errorOccurred(const QString &error); 53 54 protected: 55 void componentComplete() override; 56 void releaseResources() override; 57 58 private: 59 void updateRect(); 60 void setRect(const QRect &rect); 61 void setResolution(const QSize &resolution); 62 63 private: 64 QSharedPointer<VideoItemPrivate> _priv; 65 }; 66 67 #endif // VIDEOITEM_H 68