summaryrefslogtreecommitdiffstats
path: root/examples/multimedia/videowidget
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2009-10-15 04:40:33 (GMT)
committerAndrew den Exter <andrew.den-exter@nokia.com>2009-10-16 01:06:24 (GMT)
commit077f9711f0b9174ef9e9ffa7022aa06a9b3fc867 (patch)
treeaa633785152080feb69a7a4690b8fb36eacfe60d /examples/multimedia/videowidget
parentd9ed45eaaf0e8bacfa0f4569f226655057b614eb (diff)
downloadQt-077f9711f0b9174ef9e9ffa7022aa06a9b3fc867.zip
Qt-077f9711f0b9174ef9e9ffa7022aa06a9b3fc867.tar.gz
Qt-077f9711f0b9174ef9e9ffa7022aa06a9b3fc867.tar.bz2
Move audio and video examples into the common multimedia directory.
Brings the video examples into multimedia directory, and removes the audio sub-directory so the directory structure is in line with the other example categories. Task-number: QT-667 Reviewed-by: Kurt Korbatits
Diffstat (limited to 'examples/multimedia/videowidget')
-rw-r--r--examples/multimedia/videowidget/main.cpp54
-rw-r--r--examples/multimedia/videowidget/videoplayer.cpp183
-rw-r--r--examples/multimedia/videowidget/videoplayer.h79
-rw-r--r--examples/multimedia/videowidget/videowidget.cpp114
-rw-r--r--examples/multimedia/videowidget/videowidget.h76
-rw-r--r--examples/multimedia/videowidget/videowidget.pro25
-rw-r--r--examples/multimedia/videowidget/videowidgetsurface.cpp175
-rw-r--r--examples/multimedia/videowidget/videowidgetsurface.h81
8 files changed, 787 insertions, 0 deletions
diff --git a/examples/multimedia/videowidget/main.cpp b/examples/multimedia/videowidget/main.cpp
new file mode 100644
index 0000000..f5edf73
--- /dev/null
+++ b/examples/multimedia/videowidget/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "videoplayer.h"
+
+#include <QtGui/QApplication>
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ VideoPlayer player;
+ player.show();
+
+ return app.exec();
+}
diff --git a/examples/multimedia/videowidget/videoplayer.cpp b/examples/multimedia/videowidget/videoplayer.cpp
new file mode 100644
index 0000000..ed24714
--- /dev/null
+++ b/examples/multimedia/videowidget/videoplayer.cpp
@@ -0,0 +1,183 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "videoplayer.h"
+
+#include "videowidget.h"
+
+#include <QtMultimedia>
+
+VideoPlayer::VideoPlayer(QWidget *parent)
+ : QWidget(parent)
+ , surface(0)
+ , playButton(0)
+ , positionSlider(0)
+{
+ connect(&movie, SIGNAL(stateChanged(QMovie::MovieState)),
+ this, SLOT(movieStateChanged(QMovie::MovieState)));
+ connect(&movie, SIGNAL(frameChanged(int)),
+ this, SLOT(frameChanged(int)));
+
+ VideoWidget *videoWidget = new VideoWidget;
+ surface = videoWidget->videoSurface();
+
+ QAbstractButton *openButton = new QPushButton(tr("Open..."));
+ connect(openButton, SIGNAL(clicked()), this, SLOT(openFile()));
+
+ playButton = new QPushButton;
+ playButton->setEnabled(false);
+ playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
+
+ connect(playButton, SIGNAL(clicked()),
+ this, SLOT(play()));
+
+ positionSlider = new QSlider(Qt::Horizontal);
+ positionSlider->setRange(0, 0);
+
+ connect(positionSlider, SIGNAL(sliderMoved(int)),
+ this, SLOT(setPosition(int)));
+
+ connect(&movie, SIGNAL(frameChanged(int)),
+ positionSlider, SLOT(setValue(int)));
+
+ QBoxLayout *controlLayout = new QHBoxLayout;
+ controlLayout->setMargin(0);
+ controlLayout->addWidget(openButton);
+ controlLayout->addWidget(playButton);
+ controlLayout->addWidget(positionSlider);
+
+ QBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(videoWidget);
+ layout->addLayout(controlLayout);
+
+ setLayout(layout);
+}
+
+VideoPlayer::~VideoPlayer()
+{
+}
+
+void VideoPlayer::openFile()
+{
+ QString fileName = QFileDialog::getOpenFileName(this, tr("Open Movie"));
+
+ if (!fileName.isEmpty()) {
+ if (surface->isStarted())
+ surface->stop();
+
+ movie.setFileName(fileName);
+
+ playButton->setEnabled(true);
+ positionSlider->setMaximum(movie.frameCount());
+
+ movie.jumpToFrame(0);
+ }
+}
+
+void VideoPlayer::play()
+{
+ switch(movie.state()) {
+ case QMovie::NotRunning:
+ movie.start();
+ break;
+ case QMovie::Paused:
+ movie.setPaused(false);
+ break;
+ case QMovie::Running:
+ movie.setPaused(true);
+ break;
+ }
+}
+
+void VideoPlayer::movieStateChanged(QMovie::MovieState state)
+{
+ switch(state) {
+ case QMovie::NotRunning:
+ case QMovie::Paused:
+ playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
+ break;
+ case QMovie::Running:
+ playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPause));
+ break;
+ }
+}
+
+void VideoPlayer::frameChanged(int frame)
+{
+ if (!presentImage(movie.currentImage())) {
+ movie.stop();
+ playButton->setEnabled(false);
+ positionSlider->setMaximum(0);
+ } else {
+ positionSlider->setValue(frame);
+ }
+}
+
+void VideoPlayer::setPosition(int frame)
+{
+ movie.jumpToFrame(frame);
+}
+
+bool VideoPlayer::presentImage(const QImage &image)
+{
+ QVideoFrame frame(image);
+
+ if (!frame.isValid())
+ return false;
+
+ QVideoSurfaceFormat currentFormat = surface->surfaceFormat();
+
+ if (frame.pixelFormat() != currentFormat.pixelFormat()
+ || frame.size() != currentFormat.frameSize()) {
+ QVideoSurfaceFormat format(frame.size(), frame.pixelFormat());
+
+ if (!surface->start(format))
+ return false;
+ }
+
+ if (!surface->present(frame)) {
+ surface->stop();
+
+ return false;
+ } else {
+ return true;
+ }
+}
diff --git a/examples/multimedia/videowidget/videoplayer.h b/examples/multimedia/videowidget/videoplayer.h
new file mode 100644
index 0000000..6547415
--- /dev/null
+++ b/examples/multimedia/videowidget/videoplayer.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef VIDEOPLAYER_H
+#define VIDEOPLAYER_H
+
+#include <QtGui/QMovie>
+#include <QtGui/QWidget>
+
+QT_BEGIN_NAMESPACE
+class QAbstractButton;
+class QAbstractVideoSurface;
+class QSlider;
+QT_END_NAMESPACE
+
+class VideoPlayer : public QWidget
+{
+ Q_OBJECT
+public:
+ VideoPlayer(QWidget *parent = 0);
+ ~VideoPlayer();
+
+public slots:
+ void openFile();
+ void play();
+
+private slots:
+ void movieStateChanged(QMovie::MovieState state);
+ void frameChanged(int frame);
+ void setPosition(int frame);
+
+private:
+ bool presentImage(const QImage &image);
+
+ QMovie movie;
+ QAbstractVideoSurface *surface;
+ QAbstractButton *playButton;
+ QSlider *positionSlider;
+};
+
+#endif
diff --git a/examples/multimedia/videowidget/videowidget.cpp b/examples/multimedia/videowidget/videowidget.cpp
new file mode 100644
index 0000000..80688e1
--- /dev/null
+++ b/examples/multimedia/videowidget/videowidget.cpp
@@ -0,0 +1,114 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "videowidget.h"
+
+#include "videowidgetsurface.h"
+
+#include <QtMultimedia>
+
+//! [0]
+VideoWidget::VideoWidget(QWidget *parent)
+ : QWidget(parent)
+ , surface(0)
+{
+ setAutoFillBackground(false);
+ setAttribute(Qt::WA_NoSystemBackground, true);
+ setAttribute(Qt::WA_PaintOnScreen, true);
+
+ QPalette palette = this->palette();
+ palette.setColor(QPalette::Background, Qt::black);
+ setPalette(palette);
+
+ setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
+
+ surface = new VideoWidgetSurface(this);
+}
+//! [0]
+
+//! [1]
+VideoWidget::~VideoWidget()
+{
+ delete surface;
+}
+//! [1]
+
+//! [2]
+QSize VideoWidget::sizeHint() const
+{
+ return surface->surfaceFormat().sizeHint();
+}
+//! [2]
+
+
+//! [3]
+void VideoWidget::paintEvent(QPaintEvent *event)
+{
+ QPainter painter(this);
+
+ if (surface->isStarted()) {
+ const QRect videoRect = surface->videoRect();
+
+ if (!videoRect.contains(event->rect())) {
+ QRegion region = event->region();
+ region.subtract(videoRect);
+
+ QBrush brush = palette().background();
+
+ foreach (const QRect &rect, region.rects())
+ painter.fillRect(rect, brush);
+ }
+
+ surface->paint(&painter);
+ } else {
+ painter.fillRect(event->rect(), palette().background());
+ }
+}
+//! [3]
+
+//! [4]
+void VideoWidget::resizeEvent(QResizeEvent *event)
+{
+ QWidget::resizeEvent(event);
+
+ surface->updateVideoRect();
+}
+//! [4]
diff --git a/examples/multimedia/videowidget/videowidget.h b/examples/multimedia/videowidget/videowidget.h
new file mode 100644
index 0000000..8c343bf
--- /dev/null
+++ b/examples/multimedia/videowidget/videowidget.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef VIDEOWIDGET_H
+#define VIDEOWIDGET_H
+
+#include "videowidgetsurface.h"
+
+#include <QtGui/QWidget>
+
+QT_BEGIN_NAMESPACE
+class QAbstractVideoSurface;
+QT_END_NAMESPACE
+
+class VideoWidgetSurface;
+
+//! [0]
+class VideoWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ VideoWidget(QWidget *parent = 0);
+ ~VideoWidget();
+
+ QAbstractVideoSurface *videoSurface() const { return surface; }
+
+ QSize sizeHint() const;
+
+protected:
+ void paintEvent(QPaintEvent *event);
+ void resizeEvent(QResizeEvent *event);
+
+private:
+ VideoWidgetSurface *surface;
+};
+//! [0]
+
+#endif
diff --git a/examples/multimedia/videowidget/videowidget.pro b/examples/multimedia/videowidget/videowidget.pro
new file mode 100644
index 0000000..3f93745
--- /dev/null
+++ b/examples/multimedia/videowidget/videowidget.pro
@@ -0,0 +1,25 @@
+TEMPLATE = app
+
+QT += multimedia
+
+HEADERS = \
+ videoplayer.h \
+ videowidget.h \
+ videowidgetsurface.h
+
+SOURCES = \
+ main.cpp \
+ videoplayer.cpp \
+ videowidget.cpp \
+ videowidgetsurface.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/multimedia/videowidget
+sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png images
+sources.path = $$[QT_INSTALL_EXAMPLES]/multimedia/videowidget
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000D7C3
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/multimedia/videowidget/videowidgetsurface.cpp b/examples/multimedia/videowidget/videowidgetsurface.cpp
new file mode 100644
index 0000000..ec9b8b5
--- /dev/null
+++ b/examples/multimedia/videowidget/videowidgetsurface.cpp
@@ -0,0 +1,175 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "videowidgetsurface.h"
+
+#include <QtMultimedia>
+
+VideoWidgetSurface::VideoWidgetSurface(QWidget *widget, QObject *parent)
+ : QAbstractVideoSurface(parent)
+ , widget(widget)
+ , imageFormat(QImage::Format_Invalid)
+{
+}
+
+//! [0]
+QList<QVideoFrame::PixelFormat> VideoWidgetSurface::supportedPixelFormats(
+ QAbstractVideoBuffer::HandleType handleType) const
+{
+ if (handleType == QAbstractVideoBuffer::NoHandle) {
+ return QList<QVideoFrame::PixelFormat>()
+ << QVideoFrame::Format_RGB32
+ << QVideoFrame::Format_ARGB32
+ << QVideoFrame::Format_ARGB32_Premultiplied
+ << QVideoFrame::Format_RGB565
+ << QVideoFrame::Format_RGB555;
+ } else {
+ return QList<QVideoFrame::PixelFormat>();
+ }
+}
+//! [0]
+
+//! [1]
+bool VideoWidgetSurface::isFormatSupported(
+ const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar) const
+{
+ Q_UNUSED(similar);
+
+ const QImage::Format imageFormat = QVideoFrame::equivalentImageFormat(format.pixelFormat());
+ const QSize size = format.frameSize();
+
+ return imageFormat != QImage::Format_Invalid
+ && !size.isEmpty()
+ && format.handleType() == QAbstractVideoBuffer::NoHandle;
+}
+//! [1]
+
+//! [2]
+bool VideoWidgetSurface::start(const QVideoSurfaceFormat &format)
+{
+ const QImage::Format imageFormat = QVideoFrame::equivalentImageFormat(format.pixelFormat());
+ const QSize size = format.frameSize();
+
+ if (imageFormat != QImage::Format_Invalid && !size.isEmpty()) {
+ this->imageFormat = imageFormat;
+ imageSize = size;
+ sourceRect = format.viewport();
+
+ QAbstractVideoSurface::start(format);
+
+ widget->updateGeometry();
+ updateVideoRect();
+
+ return true;
+ } else {
+ return false;
+ }
+}
+//! [2]
+
+//! [3]
+void VideoWidgetSurface::stop()
+{
+ currentFrame = QVideoFrame();
+ targetRect = QRect();
+
+ QAbstractVideoSurface::stop();
+
+ widget->update();
+}
+//! [3]
+
+//! [4]
+bool VideoWidgetSurface::present(const QVideoFrame &frame)
+{
+ if (surfaceFormat().pixelFormat() != frame.pixelFormat()
+ || surfaceFormat().frameSize() != frame.size()) {
+ setError(IncorrectFormatError);
+ stop();
+
+ return false;
+ } else {
+ currentFrame = frame;
+
+ widget->repaint(targetRect);
+
+ return true;
+ }
+}
+//! [4]
+
+//! [5]
+void VideoWidgetSurface::updateVideoRect()
+{
+ QSize size = surfaceFormat().sizeHint();
+ size.scale(widget->size().boundedTo(size), Qt::KeepAspectRatio);
+
+ targetRect = QRect(QPoint(0, 0), size);
+ targetRect.moveCenter(widget->rect().center());
+}
+//! [5]
+
+//! [6]
+void VideoWidgetSurface::paint(QPainter *painter)
+{
+ if (currentFrame.map(QAbstractVideoBuffer::ReadOnly)) {
+ const QTransform oldTransform = painter->transform();
+
+ if (surfaceFormat().scanLineDirection() == QVideoSurfaceFormat::BottomToTop) {
+ painter->scale(1, -1);
+ painter->translate(0, -widget->height());
+ }
+
+ QImage image(
+ currentFrame.bits(),
+ currentFrame.width(),
+ currentFrame.height(),
+ currentFrame.bytesPerLine(),
+ imageFormat);
+
+ painter->drawImage(targetRect, image, sourceRect);
+
+ painter->setTransform(oldTransform);
+
+ currentFrame.unmap();
+ }
+}
+//! [6]
diff --git a/examples/multimedia/videowidget/videowidgetsurface.h b/examples/multimedia/videowidget/videowidgetsurface.h
new file mode 100644
index 0000000..83439d3
--- /dev/null
+++ b/examples/multimedia/videowidget/videowidgetsurface.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef VIDEOWIDGETSURFACE_H
+#define VIDEOWIDGETSURFACE_H
+
+#include <QtCore/QRect>
+#include <QtGui/QImage>
+#include <QtMultimedia/QAbstractVideoSurface>
+#include <QtMultimedia/QVideoFrame>
+
+//! [0]
+class VideoWidgetSurface : public QAbstractVideoSurface
+{
+ Q_OBJECT
+public:
+ VideoWidgetSurface(QWidget *widget, QObject *parent = 0);
+
+ QList<QVideoFrame::PixelFormat> supportedPixelFormats(
+ QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const;
+ bool isFormatSupported(const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar) const;
+
+ bool start(const QVideoSurfaceFormat &format);
+ void stop();
+
+ bool present(const QVideoFrame &frame);
+
+ QRect videoRect() const { return targetRect; }
+ void updateVideoRect();
+
+ void paint(QPainter *painter);
+
+private:
+ QWidget *widget;
+ QImage::Format imageFormat;
+ QRect targetRect;
+ QSize imageSize;
+ QRect sourceRect;
+ QVideoFrame currentFrame;
+};
+//! [0]
+
+#endif