qtmobility/src/multimedia/qmlgraphicsvideo_p.h
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 5 453da2cfceef
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef QMLGRAPHICSVIDEO_H
       
    43 #define QMLGRAPHICSVIDEO_H
       
    44 
       
    45 #include <qmlmediabase_p.h>
       
    46 
       
    47 #include <qgraphicsvideoitem.h>
       
    48 
       
    49 #include <QtCore/qbasictimer.h>
       
    50 #include <QtDeclarative/qmlgraphicsitem.h>
       
    51 
       
    52 QT_BEGIN_NAMESPACE
       
    53 class QVideoSurfaceFormat;
       
    54 class QTimerEvent;
       
    55 QT_END_NAMESPACE
       
    56 
       
    57 QTM_BEGIN_NAMESPACE
       
    58 
       
    59 class QmlGraphicsVideo : public QmlGraphicsItem, public QmlMediaBase
       
    60 {
       
    61     Q_OBJECT
       
    62     Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
       
    63     Q_PROPERTY(bool playing READ isPlaying WRITE setPlaying NOTIFY playingChanged)
       
    64     Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged)
       
    65     Q_PROPERTY(Status status READ status NOTIFY statusChanged)
       
    66     Q_PROPERTY(int duration READ duration NOTIFY durationChanged)
       
    67     Q_PROPERTY(int position READ position WRITE setPosition NOTIFY positionChanged)
       
    68     Q_PROPERTY(qreal volume READ volume WRITE setVolume NOTIFY volumeChanged)
       
    69     Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged)
       
    70     Q_PROPERTY(bool hasAudio READ hasAudio NOTIFY hasAudioChanged)
       
    71     Q_PROPERTY(bool hasVideo READ hasVideo NOTIFY hasVideoChanged)
       
    72     Q_PROPERTY(int bufferProgress READ bufferProgress NOTIFY bufferProgressChanged)
       
    73     Q_PROPERTY(bool seekable READ isSeekable NOTIFY seekableChanged)
       
    74     Q_PROPERTY(qreal playbackRate READ playbackRate WRITE setPlaybackRate NOTIFY playbackRateChanged)
       
    75     Q_PROPERTY(Error error READ error NOTIFY errorChanged)
       
    76     Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged)
       
    77     Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode)
       
    78     Q_ENUMS(FillMode)
       
    79     Q_ENUMS(Status)
       
    80     Q_ENUMS(Error)
       
    81 public:
       
    82     enum FillMode
       
    83     {
       
    84         Stretch            = Qt::IgnoreAspectRatio,
       
    85         PreserveAspectFit  = Qt::KeepAspectRatio,
       
    86         PreserveAspectCrop = Qt::KeepAspectRatioByExpanding
       
    87     };
       
    88 
       
    89     enum Status
       
    90     {
       
    91         UnknownStatus = QMediaPlayer::UnknownMediaStatus,
       
    92         NoMedia       = QMediaPlayer::NoMedia,
       
    93         Loading       = QMediaPlayer::LoadingMedia,
       
    94         Loaded        = QMediaPlayer::LoadedMedia,
       
    95         Stalled       = QMediaPlayer::StalledMedia,
       
    96         Buffering     = QMediaPlayer::BufferingMedia,
       
    97         Buffered      = QMediaPlayer::BufferedMedia,
       
    98         EndOfMedia    = QMediaPlayer::EndOfMedia,
       
    99         InvalidMedia  = QMediaPlayer::InvalidMedia
       
   100     };
       
   101 
       
   102     enum Error
       
   103     {
       
   104         NoError        = QMediaPlayer::NoError,
       
   105         ResourceError  = QMediaPlayer::ResourceError,
       
   106         FormatError    = QMediaPlayer::FormatError,
       
   107         NetworkError   = QMediaPlayer::NetworkError,
       
   108         AccessDenied   = QMediaPlayer::AccessDeniedError,
       
   109         ServiceMissing = QMediaPlayer::ServiceMissingError
       
   110     };
       
   111 
       
   112     QmlGraphicsVideo(QmlGraphicsItem *parent = 0);
       
   113     ~QmlGraphicsVideo();
       
   114 
       
   115     bool hasAudio() const;
       
   116     bool hasVideo() const;
       
   117 
       
   118     FillMode fillMode() const;
       
   119     void setFillMode(FillMode mode);
       
   120 
       
   121     Status status() const;
       
   122     Error error() const;
       
   123 
       
   124     void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
       
   125 
       
   126 public Q_SLOTS:
       
   127     void play();
       
   128     void pause();
       
   129     void stop();
       
   130 
       
   131 Q_SIGNALS:
       
   132     void sourceChanged();
       
   133 
       
   134     void playingChanged();
       
   135     void pausedChanged();
       
   136 
       
   137     void started();
       
   138     void resumed();
       
   139     void paused();
       
   140     void stopped();
       
   141 
       
   142     void statusChanged();
       
   143 
       
   144     void loaded();
       
   145     void buffering();
       
   146     void stalled();
       
   147     void buffered();
       
   148     void endOfMedia();
       
   149 
       
   150     void durationChanged();
       
   151     void positionChanged();
       
   152 
       
   153     void volumeChanged();
       
   154     void mutedChanged();
       
   155     void hasAudioChanged();
       
   156     void hasVideoChanged();
       
   157 
       
   158     void bufferProgressChanged();
       
   159 
       
   160     void seekableChanged();
       
   161     void playbackRateChanged();
       
   162 
       
   163     void errorChanged();
       
   164     void error(QmlGraphicsVideo::Error error, const QString &errorString);
       
   165 
       
   166 protected:
       
   167     void geometryChanged(const QRectF &geometry, const QRectF &);
       
   168 
       
   169 private Q_SLOTS:
       
   170     void _q_nativeSizeChanged(const QSizeF &size);
       
   171     void _q_error(QMediaPlayer::Error, const QString &);
       
   172 
       
   173 private:
       
   174     Q_DISABLE_COPY(QmlGraphicsVideo)
       
   175 
       
   176     QGraphicsVideoItem *m_graphicsItem;
       
   177 
       
   178     FillMode m_fillMode;
       
   179     QRectF m_scaledRect;
       
   180     bool m_updatePaintDevice;
       
   181 
       
   182     Q_PRIVATE_SLOT(mediaBase(), void _q_stateChanged(QMediaPlayer::State))
       
   183     Q_PRIVATE_SLOT(mediaBase(), void _q_mediaStatusChanged(QMediaPlayer::MediaStatus))
       
   184     Q_PRIVATE_SLOT(mediaBase(), void _q_metaDataChanged())
       
   185 
       
   186     inline QmlMediaBase *mediaBase() { return this; }
       
   187 };
       
   188 
       
   189 QTM_END_NAMESPACE
       
   190 
       
   191 QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QmlGraphicsVideo))
       
   192 
       
   193 #endif