diff options
author | Michael Goddard <michael.goddard@nokia.com> | 2012-01-06 14:29:20 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-03 03:21:43 +0100 |
commit | 78ffd1bc18ecaf5c989187f89fba82dd53503ecc (patch) | |
tree | d330232da42c89b3b16a2ad3ab58c76eb9c3c576 | |
parent | 4bbe267f303f379311a2d8f98aa8dfcf173b1ad6 (diff) |
Remove QMediaImageViewer (SC break).
This class has turned out to be not very useful at this point in time.
Change-Id: Ic07132bdcd01a912a6dd1160c867979fd1307b6a
Reviewed-by: Jonas Rabbe <jonas.rabbe@nokia.com>
28 files changed, 3 insertions, 3074 deletions
diff --git a/doc/src/examples/slideshow.qdoc b/doc/src/examples/slideshow.qdoc deleted file mode 100644 index e621e57f0..000000000 --- a/doc/src/examples/slideshow.qdoc +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** GNU Free Documentation License -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms -** and conditions contained in a signed written agreement between you -** and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \example slideshow - \title SlideShow Example - - - \image slideshow-img1.png - - - Slideshow displays a series of time delayed images after you select a - source image directory to use. The folder button presents a list of three - options: browse for a directory, load a playlist or enter a location. - - This implementation uses a QMediaImageViewer object for the image with - a QVideoWidget used to do the display. Whether the the source is a - browsed directory, a playlist file or a URL to a local or remote - location the playlist object in Slideshow is updated with the file or - multiple file locations. - - \code - connect(imageViewer, SIGNAL(stateChanged(QMediaImageViewer::State)), - this, SLOT(stateChanged(QMediaImageViewer::State))); - - playlist = new QMediaPlaylist; - playlist->setMediaObject(imageViewer); - \endcode - - We create a QVideoWidget to display the viewer and add it to the dialog. - - \code - QVideoWidget *videoWidget = new QVideoWidget; - videoWidget->setMediaObject(imageViewer); - \endcode - - - \code - layout->addWidget(videoWidget, Qt::AlignCenter); - \endcode - - - The timeout between images is set by changing the timeout property in - QMediaImageViewer which is in milliseconds. So to change the timeout - to five seconds - \code - imageViewer->setTimeout( 5000 ); - \endcode - - -*/ diff --git a/doc/src/snippets/multimedia-snippets/media.cpp b/doc/src/snippets/multimedia-snippets/media.cpp index c46317641..d59374bd8 100644 --- a/doc/src/snippets/multimedia-snippets/media.cpp +++ b/doc/src/snippets/multimedia-snippets/media.cpp @@ -46,8 +46,6 @@ #include "qmediaplaylist.h" #include "qmediarecorder.h" #include "qmediaservice.h" -#include "qmediaimageviewer.h" -#include "qmediaimageviewer.h" #include "qmediaplayercontrol.h" #include "qmediaplayer.h" #include "qradiotuner.h" @@ -59,7 +57,6 @@ class MediaExample : public QObject { Q_OBJECT void MediaControl(); - void MediaImageViewer(); void MediaPlayer(); void RadioTuna(); void MediaRecorder(); @@ -75,7 +72,6 @@ private: QMediaPlaylist *playlist; QMediaContent video; QMediaRecorder *recorder; - QMediaImageViewer *viewer; QCamera *camera; QCameraImageCapture *imageCapture; QString fileName; @@ -136,29 +132,6 @@ void MediaExample::ImageEncoderSettings() //! [Image encoder settings] } -void MediaExample::MediaImageViewer() -{ - //! [Binding] - viewer = new QMediaImageViewer(this); - - videoWidget = new QVideoWidget; - viewer->bind(videoWidget); - videoWidget->show(); - //! [Binding] - - //! [Playlist] - playlist = new QMediaPlaylist(this); - playlist->setPlaybackMode(QMediaPlaylist::Loop); - playlist->addMedia(image1); - playlist->addMedia(image2); - playlist->addMedia(image3); - - viewer->setPlaylist(playlist); - viewer->setTimeout(5000); - viewer->play(); - //! [Playlist] -} - void MediaExample::MediaPlayer() { //! [Player] diff --git a/examples/examples.pro b/examples/examples.pro index 9d9442e72..3f2aaca97 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -5,7 +5,6 @@ TEMPLATE = subdirs SUBDIRS += \ radio \ camera \ - slideshow \ spectrum \ audiorecorder \ audiodevices \ diff --git a/examples/slideshow/main.cpp b/examples/slideshow/main.cpp deleted file mode 100644 index 46350eb66..000000000 --- a/examples/slideshow/main.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "slideshow.h" - -#include <QtWidgets> - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - SlideShow slideShow; - slideShow.show(); - - return app.exec(); -} diff --git a/examples/slideshow/slideshow.cpp b/examples/slideshow/slideshow.cpp deleted file mode 100644 index 55174fe06..000000000 --- a/examples/slideshow/slideshow.cpp +++ /dev/null @@ -1,215 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "slideshow.h" - -#include <qmediaservice.h> -#include <qmediaplaylist.h> -#include <qvideowidget.h> - -#include <QtWidgets> - -SlideShow::SlideShow(QWidget *parent) - : QMainWindow(parent) - , imageViewer(0) - , playlist(0) - , statusLabel(0) - , countdownLabel(0) - , playAction(0) - , stopAction(0) -{ - imageViewer = new QMediaImageViewer(this); - - connect(imageViewer, SIGNAL(stateChanged(QMediaImageViewer::State)), - this, SLOT(stateChanged(QMediaImageViewer::State))); - connect(imageViewer, SIGNAL(mediaStatusChanged(QMediaImageViewer::MediaStatus)), - this, SLOT(statusChanged(QMediaImageViewer::MediaStatus))); - connect(imageViewer, SIGNAL(elapsedTimeChanged(int)), this, SLOT(elapsedTimeChanged(int))); - - playlist = new QMediaPlaylist; - imageViewer->bind(playlist); - - connect(playlist, SIGNAL(loaded()), this, SLOT(playlistLoaded())); - connect(playlist, SIGNAL(loadFailed()), this, SLOT(playlistLoadFailed())); - - QVideoWidget *videoWidget = new QVideoWidget; - imageViewer->setVideoOutput(videoWidget); - - menuBar()->addAction(tr("Open Directory..."), this, SLOT(openDirectory())); - menuBar()->addAction(tr("Open Playlist..."), this, SLOT(openPlaylist())); - - toolBar = new QToolBar; - toolBar->setMovable(false); - toolBar->setFloatable(false); - toolBar->setEnabled(false); - - toolBar->addAction( - style()->standardIcon(QStyle::SP_MediaSkipBackward), - tr("Previous"), - playlist, - SLOT(previous())); - stopAction = toolBar->addAction( - style()->standardIcon(QStyle::SP_MediaStop), tr("Stop"), imageViewer, SLOT(stop())); - playAction = toolBar->addAction( - style()->standardIcon(QStyle::SP_MediaPlay), tr("Play"), this, SLOT(play())); - toolBar->addAction( - style()->standardIcon(QStyle::SP_MediaSkipForward), tr("Next"), playlist, SLOT(next())); - - addToolBar(Qt::BottomToolBarArea, toolBar); - - statusLabel = new QLabel(tr("%1 Images").arg(0)); - statusLabel->setAlignment(Qt::AlignCenter); - - countdownLabel = new QLabel; - countdownLabel->setAlignment(Qt::AlignRight); - - statusBar()->addPermanentWidget(statusLabel, 1); - statusBar()->addPermanentWidget(countdownLabel); - - setCentralWidget(videoWidget); -} - -void SlideShow::openPlaylist() -{ - QString path = QFileDialog::getOpenFileName(this); - - if (!path.isEmpty()) { - playlist->clear(); - playlist->load(QUrl::fromLocalFile(path)); - } -} - -void SlideShow::openDirectory() -{ - QString path = QFileDialog::getExistingDirectory(this); - - if (!path.isEmpty()) { - playlist->clear(); - - QDir dir(path); - - foreach (const QString &fileName, dir.entryList(QDir::Files)) - playlist->addMedia(QUrl::fromLocalFile(dir.absoluteFilePath(fileName))); - - statusChanged(imageViewer->mediaStatus()); - - toolBar->setEnabled(playlist->mediaCount() > 0); - } -} - -void SlideShow::play() -{ - switch (imageViewer->state()) { - case QMediaImageViewer::StoppedState: - case QMediaImageViewer::PausedState: - imageViewer->play(); - break; - case QMediaImageViewer::PlayingState: - imageViewer->pause(); - break; - } -} - -void SlideShow::stateChanged(QMediaImageViewer::State state) -{ - switch (state) { - case QMediaImageViewer::StoppedState: - stopAction->setEnabled(false); - playAction->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); - break; - case QMediaImageViewer::PlayingState: - stopAction->setEnabled(true); - playAction->setIcon(style()->standardIcon(QStyle::SP_MediaPause)); - break; - case QMediaImageViewer::PausedState: - stopAction->setEnabled(true); - playAction->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); - break; - } -} - -void SlideShow::statusChanged(QMediaImageViewer::MediaStatus status) -{ - switch (status) { - case QMediaImageViewer::NoMedia: - statusLabel->setText(tr("%1 Images").arg(playlist->mediaCount())); - break; - case QMediaImageViewer::LoadingMedia: - statusLabel->setText(tr("Image %1 of %2\nLoading...") - .arg(playlist->currentIndex()) - .arg(playlist->mediaCount())); - break; - case QMediaImageViewer::LoadedMedia: - statusLabel->setText(tr("Image %1 of %2") - .arg(playlist->currentIndex()) - .arg(playlist->mediaCount())); - break; - case QMediaImageViewer::InvalidMedia: - statusLabel->setText(tr("Image %1 of %2\nInvalid") - .arg(playlist->currentIndex()) - .arg(playlist->mediaCount())); - break; - default: - break; - } -} - -void SlideShow::playlistLoaded() -{ - statusChanged(imageViewer->mediaStatus()); - - toolBar->setEnabled(playlist->mediaCount() > 0); -} - -void SlideShow::playlistLoadFailed() -{ - statusLabel->setText(playlist->errorString()); - - toolBar->setEnabled(false); -} - -void SlideShow::elapsedTimeChanged(int time) -{ - const int remaining = (imageViewer->timeout() - time) / 1000; - - countdownLabel->setText(tr("%1:%2") - .arg(remaining / 60, 2, 10, QLatin1Char('0')) - .arg(remaining % 60, 2, 10, QLatin1Char('0'))); -} diff --git a/examples/slideshow/slideshow.h b/examples/slideshow/slideshow.h deleted file mode 100644 index 4ea2e492c..000000000 --- a/examples/slideshow/slideshow.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef SLIDESHOW_H -#define SLIDESHOW_H - -#include <QMainWindow> -#include <qmediaimageviewer.h> - -QT_BEGIN_NAMESPACE -class QAbstractButton; -class QLabel; -class QStackedLayout; - -class QMediaPlaylist; -QT_END_NAMESPACE - -QT_USE_NAMESPACE - -class SlideShow : public QMainWindow -{ - Q_OBJECT -public: - SlideShow(QWidget *parent = 0); - -private slots: - void openPlaylist(); - void openDirectory(); - - void play(); - - void stateChanged(QMediaImageViewer::State state); - void statusChanged(QMediaImageViewer::MediaStatus status); - - void playlistLoaded(); - void playlistLoadFailed(); - - void elapsedTimeChanged(int time); - -private: - QMediaImageViewer *imageViewer; - QMediaPlaylist *playlist; - QLabel *statusLabel; - QLabel *countdownLabel; - QAction *playAction; - QAction *stopAction; - QToolBar *toolBar; -}; - -#endif diff --git a/examples/slideshow/slideshow.pro b/examples/slideshow/slideshow.pro deleted file mode 100644 index 133735d6f..000000000 --- a/examples/slideshow/slideshow.pro +++ /dev/null @@ -1,19 +0,0 @@ -TEMPLATE = app -TARGET = slideshow - -QT += multimedia multimediawidgets - -HEADERS = \ - slideshow.h - -SOURCES = \ - main.cpp \ - slideshow.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/qtmultimedia/slideshow -sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro -sources.path = $$[QT_INSTALL_EXAMPLES]/qtmultimedia/slideshow - -INSTALLS += target sources - -QT+=widgets diff --git a/src/multimedia/imageviewer/imageviewer.pri b/src/multimedia/imageviewer/imageviewer.pri deleted file mode 100644 index 409615c7e..000000000 --- a/src/multimedia/imageviewer/imageviewer.pri +++ /dev/null @@ -1,13 +0,0 @@ - -INCLUDEPATH += imageviewer - -PUBLIC_HEADERS += \ - imageviewer/qmediaimageviewer.h - -PRIVATE_HEADERS += \ - imageviewer/qmediaimageviewerservice_p.h - -SOURCES += \ - imageviewer/qmediaimageviewer.cpp \ - imageviewer/qmediaimageviewerservice.cpp - diff --git a/src/multimedia/imageviewer/qmediaimageviewer.cpp b/src/multimedia/imageviewer/qmediaimageviewer.cpp deleted file mode 100644 index a965a74ac..000000000 --- a/src/multimedia/imageviewer/qmediaimageviewer.cpp +++ /dev/null @@ -1,596 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmediaimageviewer.h" - -#include "qmediaobject_p.h" -#include "qmediaimageviewerservice_p.h" - -#include <qmediaplaylist.h> -#include <qmediaplaylistsourcecontrol.h> -#include <qmediacontent.h> -#include <qmediaresource.h> -#include "qvideosurfaceoutput_p.h" - -#include <QtCore/qcoreevent.h> -#include <QtCore/qdatetime.h> -#include <QtCore/qpointer.h> -#include <QtCore/qtextstream.h> - -QT_BEGIN_NAMESPACE - -namespace -{ - class QMediaImageViewerPrivateRegisterMetaTypes - { - public: - QMediaImageViewerPrivateRegisterMetaTypes() - { - qRegisterMetaType<QMediaImageViewer::MediaStatus>(); - qRegisterMetaType<QMediaImageViewer::State>(); - } - } _registerMetaTypes; -} - -class QMediaImageViewerPrivate : public QMediaObjectPrivate -{ - Q_DECLARE_NON_CONST_PUBLIC(QMediaImageViewer) -public: - QMediaImageViewerPrivate(): - viewerControl(0), playlist(0), - state(QMediaImageViewer::StoppedState), timeout(3000), pauseTime(0) - { - } - - void _q_mediaStatusChanged(QMediaImageViewer::MediaStatus status); - void _q_playlistMediaChanged(const QMediaContent &content); - void _q_playlistDestroyed(); - - QMediaImageViewerControl *viewerControl; - QMediaPlaylist *playlist; - QPointer<QObject> videoOutput; - QVideoSurfaceOutput surfaceOutput; - QMediaImageViewer::State state; - int timeout; - int pauseTime; - QTime time; - QBasicTimer timer; - QMediaContent media; -}; - -void QMediaImageViewerPrivate::_q_mediaStatusChanged(QMediaImageViewer::MediaStatus status) -{ - switch (status) { - case QMediaImageViewer::NoMedia: - case QMediaImageViewer::LoadingMedia: - emit q_func()->mediaStatusChanged(status); - break; - case QMediaImageViewer::LoadedMedia: - if (state == QMediaImageViewer::PlayingState) { - time.start(); - timer.start(qMax(0, timeout), q_func()); - q_func()->addPropertyWatch("elapsedTime"); - } - emit q_func()->mediaStatusChanged(status); - emit q_func()->elapsedTimeChanged(0); - break; - case QMediaImageViewer::InvalidMedia: - emit q_func()->mediaStatusChanged(status); - - if (state == QMediaImageViewer::PlayingState) { - playlist->next(); - if (playlist->currentIndex() < 0) - emit q_func()->stateChanged(state = QMediaImageViewer::StoppedState); - } - break; - } -} - -void QMediaImageViewerPrivate::_q_playlistMediaChanged(const QMediaContent &content) -{ - media = content; - pauseTime = 0; - - viewerControl->showMedia(media); - - emit q_func()->mediaChanged(media); -} - -void QMediaImageViewerPrivate::_q_playlistDestroyed() -{ - playlist = 0; - timer.stop(); - - if (state != QMediaImageViewer::StoppedState) - emit q_func()->stateChanged(state = QMediaImageViewer::StoppedState); - - q_func()->setMedia(QMediaContent()); -} - -/*! - \class QMediaImageViewer - \brief The QMediaImageViewer class provides a means of viewing image media. - \inmodule QtMultimedia - \ingroup multimedia - - - QMediaImageViewer is used together with a media display object such as - QVideoWidget to present an image. A display object is attached to the - image viewer by means of the bind function. - - \snippet doc/src/snippets/multimedia-snippets/media.cpp Binding - - QMediaImageViewer can be paired with a QMediaPlaylist to create a slide - show of images. Constructing a QMediaPlaylist with a pointer to an - instance of QMediaImageViewer will attach it to the image viewer; - changing the playlist's selection will then change the media displayed - by the image viewer. With a playlist attached QMediaImageViewer's - play(), pause(), and stop() slots can be control the progression of the - playlist. The \l timeout property determines how long an image is - displayed for before progressing to the next in the playlist, and the - \l elapsedTime property holds how the duration the current image has - been displayed for. - - \snippet doc/src/snippets/multimedia-snippets/media.cpp Playlist -*/ - -/*! - \enum QMediaImageViewer::State - - Enumerates the possible control states an image viewer may be in. The - control state of an image viewer determines whether the image viewer is - automatically progressing through images in an attached playlist. - - \value StoppedState The image viewer is stopped, and will not automatically move to the next - image. The \l elapsedTime is fixed at 0. - \value PlayingState The slide show is playing, and will move to the next image when the - \l elapsedTime reaches the \l timeout. The \l elapsedTime is being incremented. - \value PausedState The image viewer is paused, and will not automatically move the to next - image. The \l elapsedTime is fixed at the time the image viewer was paused. -*/ - -/*! - \enum QMediaImageViewer::MediaStatus - - Enumerates the status of an image viewer's current media. - - \value NoMedia There is no current media. - \value LoadingMedia The image viewer is loading the current media. - \value LoadedMedia The image viewer has loaded the current media. - \value InvalidMedia The current media cannot be loaded. -*/ - -/*! - Constructs a new image viewer with the given \a parent. -*/ -QMediaImageViewer::QMediaImageViewer(QObject *parent) - : QMediaObject(*new QMediaImageViewerPrivate, parent, new QMediaImageViewerService) -{ - Q_D(QMediaImageViewer); - - d->viewerControl = qobject_cast<QMediaImageViewerControl*>( - d->service->requestControl(QMediaImageViewerControl_iid)); - - connect(d->viewerControl, SIGNAL(mediaStatusChanged(QMediaImageViewer::MediaStatus)), - this, SLOT(_q_mediaStatusChanged(QMediaImageViewer::MediaStatus))); -} - -/*! - Destroys an image viewer. -*/ -QMediaImageViewer::~QMediaImageViewer() -{ - Q_D(QMediaImageViewer); - - delete d->service; -} - -/*! - \property QMediaImageViewer::state - \brief the playlist control state of a slide show. -*/ - -QMediaImageViewer::State QMediaImageViewer::state() const -{ - return d_func()->state; -} - -/*! - \fn QMediaImageViewer::stateChanged(QMediaImageViewer::State state) - - Signals that the playlist control \a state of an image viewer has changed. -*/ - -/*! - \property QMediaImageViewer::mediaStatus - \brief the status of the current media. -*/ - -QMediaImageViewer::MediaStatus QMediaImageViewer::mediaStatus() const -{ - return d_func()->viewerControl->mediaStatus(); -} - -/*! - \fn QMediaImageViewer::mediaStatusChanged(QMediaImageViewer::MediaStatus status) - - Signals the the \a status of the current media has changed. -*/ - -/*! - \property QMediaImageViewer::media - \brief the media an image viewer is presenting. -*/ - -QMediaContent QMediaImageViewer::media() const -{ - Q_D(const QMediaImageViewer); - - return d->media; -} - -void QMediaImageViewer::setMedia(const QMediaContent &media) -{ - Q_D(QMediaImageViewer); - - if (d->playlist && d->playlist->currentMedia() != media) { - disconnect(d->playlist, SIGNAL(currentMediaChanged(QMediaContent)), - this, SLOT(_q_playlistMediaChanged(QMediaContent))); - disconnect(d->playlist, SIGNAL(destroyed()), this, SLOT(_q_playlistDestroyed())); - - d->playlist = 0; - } - - d->media = media; - - if (d->timer.isActive()) { - d->pauseTime = 0; - d->timer.stop(); - removePropertyWatch("elapsedTime"); - emit elapsedTimeChanged(0); - } - - if (d->state != QMediaImageViewer::StoppedState) - emit stateChanged(d->state = QMediaImageViewer::StoppedState); - - d->viewerControl->showMedia(d->media); - - emit mediaChanged(d->media); -} - -/*! - Use \a playlist as the source of images to be displayed in the viewer. -*/ -void QMediaImageViewer::setPlaylist(QMediaPlaylist *playlist) -{ - Q_D(QMediaImageViewer); - - if (d->playlist) { - disconnect(d->playlist, SIGNAL(currentMediaChanged(QMediaContent)), - this, SLOT(_q_playlistMediaChanged(QMediaContent))); - disconnect(d->playlist, SIGNAL(destroyed()), this, SLOT(_q_playlistDestroyed())); - - QMediaObject::unbind(d->playlist); - } - - d->playlist = playlist; - - if (d->playlist) { - connect(d->playlist, SIGNAL(currentMediaChanged(QMediaContent)), - this, SLOT(_q_playlistMediaChanged(QMediaContent))); - connect(d->playlist, SIGNAL(destroyed()), this, SLOT(_q_playlistDestroyed())); - - QMediaObject::bind(d->playlist); - - setMedia(d->playlist->currentMedia()); - } else { - setMedia(QMediaContent()); - } -} - -/*! - Returns the current playlist, or 0 if none. -*/ -QMediaPlaylist *QMediaImageViewer::playlist() const -{ - return d_func()->playlist; -} - -/*! - \fn QMediaImageViewer::mediaChanged(const QMediaContent &media) - - Signals that the \a media an image viewer is presenting has changed. -*/ - -/*! - \property QMediaImageViewer::timeout - \brief the amount of time in milliseconds an image is displayed for before moving to the next - image. - - The timeout only applies if the image viewer has a playlist attached and is in the PlayingState. -*/ - -int QMediaImageViewer::timeout() const -{ - return d_func()->timeout; -} - -void QMediaImageViewer::setTimeout(int timeout) -{ - Q_D(QMediaImageViewer); - - d->timeout = qMax(0, timeout); - - if (d->timer.isActive()) - d->timer.start(qMax(0, d->timeout - d->pauseTime - d->time.elapsed()), this); -} - -/*! - \property QMediaImageViewer::elapsedTime - \brief the amount of time in milliseconds that has elapsed since the current image was loaded. - - The elapsed time only increases while the image viewer is in the PlayingState. If stopped the - elapsed time will be reset to 0. -*/ - -int QMediaImageViewer::elapsedTime() const -{ - Q_D(const QMediaImageViewer); - - int elapsedTime = d->pauseTime; - - if (d->timer.isActive()) - elapsedTime += d->time.elapsed(); - - return elapsedTime; -} - -/*! - \fn QMediaImageViewer::elapsedTimeChanged(int time) - - Signals that the amount of \a time in milliseconds since the current - image was loaded has changed. - - This signal is emitted at a regular interval when the image viewer is - in the PlayingState and an image is loaded. The notification interval - is controlled by the QMediaObject::notifyInterval property. - - \sa timeout, QMediaObject::notifyInterval -*/ - -/*! - Sets a video \a widget as the current video output. - - This will unbind any previous video output bound with setVideoOutput(). -*/ - -void QMediaImageViewer::setVideoOutput(QVideoWidget *widget) -{ - Q_D(QMediaImageViewer); - - if (d->videoOutput) - unbind(d->videoOutput); - - // We don't know (in this library) that QVideoWidget inherits QObject - QObject *widgetObject = reinterpret_cast<QObject*>(widget); - - d->videoOutput = widgetObject && bind(widgetObject) ? widgetObject : 0; -} - -/*! - Sets a video \a item as the current video output. - - This will unbind any previous video output bound with setVideoOutput(). -*/ - -void QMediaImageViewer::setVideoOutput(QGraphicsVideoItem *item) -{ - Q_D(QMediaImageViewer); - - if (d->videoOutput) - unbind(d->videoOutput); - - // We don't know (in this library) that QGraphicsVideoItem (multiply) inherits QObject - // but QObject inheritance depends on QObject coming first, so try this out. - QObject *itemObject = reinterpret_cast<QObject*>(item); - - d->videoOutput = itemObject && bind(itemObject) ? itemObject : 0; -} - -/*! - Sets a video \a surface as the video output of a image viewer. - - If a video output has already been set on the image viewer the new surface - will replace it. -*/ - -void QMediaImageViewer::setVideoOutput(QAbstractVideoSurface *surface) -{ - Q_D(QMediaImageViewer); - - d->surfaceOutput.setVideoSurface(surface); - - if (d->videoOutput != &d->surfaceOutput) { - if (d->videoOutput) - unbind(d->videoOutput); - - d->videoOutput = bind(&d->surfaceOutput) ? &d->surfaceOutput : 0; - } -} - -/*! - \internal -*/ -bool QMediaImageViewer::bind(QObject *object) -{ - if (QMediaPlaylist *playlist = qobject_cast<QMediaPlaylist *>(object)) { - setPlaylist(playlist); - - return true; - } else { - return QMediaObject::bind(object); - } -} - -/*! - \internal - */ -void QMediaImageViewer::unbind(QObject *object) -{ - if (object == d_func()->playlist) - setPlaylist(0); - else - QMediaObject::unbind(object); -} - -/*! - Starts a slide show. - - If the playlist has no current media this will start at the beginning of the playlist, otherwise - it will resume from the current media. - - If no playlist is attached to an image viewer this will do nothing. -*/ -void QMediaImageViewer::play() -{ - Q_D(QMediaImageViewer); - - if (d->playlist && d->playlist->mediaCount() > 0 && d->state != PlayingState) { - d->state = PlayingState; - - switch (d->viewerControl->mediaStatus()) { - case NoMedia: - case InvalidMedia: - d->playlist->next(); - if (d->playlist->currentIndex() < 0) - d->state = StoppedState; - break; - case LoadingMedia: - break; - case LoadedMedia: - d->time.start(); - d->timer.start(qMax(0, d->timeout - d->pauseTime), this); - break; - } - - if (d->state == PlayingState) - emit stateChanged(d->state); - } -} - -/*! - Pauses a slide show. - - The current media and elapsed time are retained. If resumed, the current image will be - displayed for the remainder of the time out period before the next image is loaded. -*/ -void QMediaImageViewer::pause() -{ - Q_D(QMediaImageViewer); - - if (d->state == PlayingState) { - if (d->viewerControl->mediaStatus() == LoadedMedia) { - d->pauseTime += d->timeout - d->time.elapsed(); - d->timer.stop(); - removePropertyWatch("elapsedTime"); - } - - emit stateChanged(d->state = PausedState); - emit elapsedTimeChanged(d->pauseTime); - } -} - -/*! - Stops a slide show. - - The current media is retained, but the elapsed time is discarded. If resumed, the current - image will be displayed for the full time out period before the next image is loaded. -*/ -void QMediaImageViewer::stop() -{ - Q_D(QMediaImageViewer); - - switch (d->state) { - case PlayingState: - d->timer.stop(); - removePropertyWatch("elapsedTime"); - // fall through. - case PausedState: - d->pauseTime = 0; - d->state = QMediaImageViewer::StoppedState; - - emit stateChanged(d->state); - emit elapsedTimeChanged(0); - break; - case StoppedState: - break; - } -} - -/*! - \reimp - - \internal -*/ -void QMediaImageViewer::timerEvent(QTimerEvent *event) -{ - Q_D(QMediaImageViewer); - - if (event->timerId() == d->timer.timerId()) { - d->timer.stop(); - removePropertyWatch("elapsedTime"); - emit elapsedTimeChanged(d->pauseTime = d->timeout); - - d->playlist->next(); - - if (d->playlist->currentIndex() < 0) { - d->pauseTime = 0; - emit stateChanged(d->state = StoppedState); - emit elapsedTimeChanged(0); - } - } else { - QMediaObject::timerEvent(event); - } -} - -#include "moc_qmediaimageviewer.cpp" -QT_END_NAMESPACE - diff --git a/src/multimedia/imageviewer/qmediaimageviewer.h b/src/multimedia/imageviewer/qmediaimageviewer.h deleted file mode 100644 index d853402c6..000000000 --- a/src/multimedia/imageviewer/qmediaimageviewer.h +++ /dev/null @@ -1,142 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMEDIAIMAGEVIEWER_H -#define QMEDIAIMAGEVIEWER_H - -#include "qmediaobject.h" -#include "qmediacontent.h" -#include <qmediaenumdebug.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - - -class QAbstractVideoSurface; -class QGraphicsVideoItem; -class QMediaPlaylist; -class QVideoWidget; - -class QMediaImageViewerPrivate; -class Q_MULTIMEDIA_EXPORT QMediaImageViewer : public QMediaObject -{ - Q_OBJECT - Q_PROPERTY(State state READ state NOTIFY stateChanged) - Q_PROPERTY(MediaStatus mediaStatus READ mediaStatus NOTIFY mediaStatusChanged) - Q_PROPERTY(QMediaContent media READ media WRITE setMedia NOTIFY mediaChanged) - Q_PROPERTY(int timeout READ timeout WRITE setTimeout) - Q_PROPERTY(int elapsedTime READ elapsedTime NOTIFY elapsedTimeChanged) - Q_ENUMS(State MediaStatus) - -public: - enum State - { - StoppedState, - PlayingState, - PausedState - }; - - enum MediaStatus - { - NoMedia, - LoadingMedia, - LoadedMedia, - InvalidMedia - }; - - explicit QMediaImageViewer(QObject *parent = 0); - ~QMediaImageViewer(); - - State state() const; - MediaStatus mediaStatus() const; - - QMediaContent media() const; - QMediaPlaylist *playlist() const; - - int timeout() const; - int elapsedTime() const; - - void setVideoOutput(QVideoWidget *widget); - void setVideoOutput(QGraphicsVideoItem *item); - void setVideoOutput(QAbstractVideoSurface *surface); - - bool bind(QObject *); - void unbind(QObject *); - -public Q_SLOTS: - void setMedia(const QMediaContent &media); - void setPlaylist(QMediaPlaylist *playlist); - - void play(); - void pause(); - void stop(); - - void setTimeout(int timeout); - -Q_SIGNALS: - void stateChanged(QMediaImageViewer::State state); - void mediaStatusChanged(QMediaImageViewer::MediaStatus status); - void mediaChanged(const QMediaContent &media); - void elapsedTimeChanged(int time); -protected: - void timerEvent(QTimerEvent *event); - -private: - Q_DECLARE_PRIVATE(QMediaImageViewer) - Q_PRIVATE_SLOT(d_func(), void _q_mediaStatusChanged(QMediaImageViewer::MediaStatus)) - Q_PRIVATE_SLOT(d_func(), void _q_playlistMediaChanged(const QMediaContent &)) - Q_PRIVATE_SLOT(d_func(), void _q_playlistDestroyed()) -}; - -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(QMediaImageViewer::State) -Q_DECLARE_METATYPE(QMediaImageViewer::MediaStatus) - -Q_MEDIA_ENUM_DEBUG(QMediaImageViewer, State) -Q_MEDIA_ENUM_DEBUG(QMediaImageViewer, MediaStatus) - -QT_END_HEADER - -#endif diff --git a/src/multimedia/imageviewer/qmediaimageviewerservice.cpp b/src/multimedia/imageviewer/qmediaimageviewerservice.cpp deleted file mode 100644 index 21ef4e443..000000000 --- a/src/multimedia/imageviewer/qmediaimageviewerservice.cpp +++ /dev/null @@ -1,458 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmediaimageviewerservice_p.h" - -#include "qmediacontrol_p.h" -#include "qmediaservice_p.h" - -#include <qmediacontent.h> -#include <qmediaresource.h> -#include "qmediaobject_p.h" -#include <qvideorenderercontrol.h> - -#include <QtCore/qdebug.h> - -#include <QtCore/qurl.h> -#include <QtGui/qimagereader.h> - -#include <QtNetwork/qnetworkaccessmanager.h> -#include <QtNetwork/qnetworkreply.h> -#include <QtNetwork/qnetworkrequest.h> - -#include <qabstractvideosurface.h> -#include <qvideosurfaceformat.h> - -QT_BEGIN_NAMESPACE - -class QMediaImageViewerServicePrivate : public QMediaServicePrivate -{ -public: - QMediaImageViewerServicePrivate() - : viewerControl(0) - , rendererControl(0) - , network(0) - , internalNetwork(0) - { - } - - bool load(QIODevice *device); - void clear(); - - QMediaImageViewerControl *viewerControl; - QMediaImageViewerRenderer *rendererControl; - QNetworkAccessManager *network; - QNetworkAccessManager *internalNetwork; - QImage m_image; -}; - - -QMediaImageViewerRenderer::QMediaImageViewerRenderer(QObject *parent) - : QVideoRendererControl(parent) - , m_surface(0) -{ -} - -QMediaImageViewerRenderer::~QMediaImageViewerRenderer() -{ - if (m_surface) - m_surface->stop(); -} - -QAbstractVideoSurface *QMediaImageViewerRenderer::surface() const -{ - return m_surface; -} - -void QMediaImageViewerRenderer::setSurface(QAbstractVideoSurface *surface) -{ - if (m_surface) - m_surface->stop(); - - m_surface = surface; - - if (m_surface && !m_image.isNull()) - showImage(m_image); -} - -void QMediaImageViewerRenderer::showImage(const QImage &image) -{ - m_image = image; - - if (m_surface) { - if (m_image.isNull()) { - m_surface->stop(); - } else { - QVideoSurfaceFormat format( - image.size(), QVideoFrame::pixelFormatFromImageFormat(image.format())); - - if (!m_surface->isFormatSupported(format)) { - foreach (QVideoFrame::PixelFormat pixelFormat, m_surface->supportedPixelFormats()) { - const QImage::Format imageFormat - = QVideoFrame::imageFormatFromPixelFormat(pixelFormat); - - if (imageFormat != QImage::Format_Invalid) { - format = QVideoSurfaceFormat(image.size(), pixelFormat); - - if (m_surface->isFormatSupported(format) && m_surface->start(format)) { - m_image = image.convertToFormat(imageFormat); - - m_surface->present(QVideoFrame(m_image)); - - return; - } - } - } - } else if (m_surface->start(format)) { - m_surface->present(QVideoFrame(image)); - } - } - } -} - -bool QMediaImageViewerServicePrivate::load(QIODevice *device) -{ - QImageReader reader(device); - - if (!reader.canRead()) { - m_image = QImage(); - } else { - m_image = reader.read(); - } - - if (rendererControl) - rendererControl->showImage(m_image); - - return !m_image.isNull(); -} - -void QMediaImageViewerServicePrivate::clear() -{ - m_image = QImage(); - - if (rendererControl) - rendererControl->showImage(m_image); -} - -/*! - \class QMediaImageViewerService - \internal -*/ - -/*! -*/ -QMediaImageViewerService::QMediaImageViewerService(QObject *parent) - : QMediaService(*new QMediaImageViewerServicePrivate, parent) -{ - Q_D(QMediaImageViewerService); - - d->viewerControl = new QMediaImageViewerControl(this); -} - -/*! -*/ -QMediaImageViewerService::~QMediaImageViewerService() -{ - Q_D(QMediaImageViewerService); - - delete d->rendererControl; - delete d->viewerControl; -} - -/*! -*/ -QMediaControl *QMediaImageViewerService::requestControl(const char *name) -{ - Q_D(QMediaImageViewerService); - - if (qstrcmp(name, QMediaImageViewerControl_iid) == 0) { - return d->viewerControl; - } else if (qstrcmp(name, QVideoRendererControl_iid) == 0) { - if (!d->rendererControl) { - d->rendererControl = new QMediaImageViewerRenderer; - d->rendererControl->showImage(d->m_image); - - return d->rendererControl; - } - } - return 0; -} - -void QMediaImageViewerService::releaseControl(QMediaControl *control) -{ - Q_D(QMediaImageViewerService); - - if (!control) { - qWarning("QMediaService::releaseControl():" - " Attempted release of null control"); - } else if (control == d->rendererControl) { - delete d->rendererControl; - - d->rendererControl = 0; - } -} - -/*! -*/ -QNetworkAccessManager *QMediaImageViewerService::networkManager() const -{ - Q_D(const QMediaImageViewerService); - - if (!d->network) { - QMediaImageViewerServicePrivate *_d = const_cast<QMediaImageViewerServicePrivate *>(d); - - if (!_d->internalNetwork) - _d->internalNetwork = new QNetworkAccessManager( - const_cast<QMediaImageViewerService *>(this)); - - _d->network = d->internalNetwork; - } - - return d->network; -} - - -void QMediaImageViewerService::setNetworkManager(QNetworkAccessManager *manager) -{ - d_func()->network = manager; -} - -class QMediaImageViewerControlPrivate : public QMediaControlPrivate -{ - Q_DECLARE_NON_CONST_PUBLIC(QMediaImageViewerControl) -public: - QMediaImageViewerControlPrivate() - : service(0) - , getReply(0) - , headReply(0) - , status(QMediaImageViewer::NoMedia) - { - foreach (const QByteArray &format, QImageReader::supportedImageFormats()) { - supportedExtensions.append( - QLatin1Char('.') + QString::fromLatin1(format.data(), format.size())); - } - } - - bool isImageType(const QUrl &url, const QString &mimeType) const; - - void loadImage(); - void cancelRequests(); - - void _q_getFinished(); - void _q_headFinished(); - - QMediaImageViewerService *service; - QNetworkReply *getReply; - QNetworkReply *headReply; - QMediaImageViewer::MediaStatus status; - QMediaContent media; - QMediaResource currentMedia; - QList<QMediaResource> possibleResources; - QStringList supportedExtensions; -}; - -bool QMediaImageViewerControlPrivate::isImageType(const QUrl &url, const QString &mimeType) const -{ - if (!mimeType.isEmpty()) { - return mimeType.startsWith(QLatin1String("image/")) - || mimeType == QLatin1String("application/xml+svg"); - } else if (url.scheme() == QLatin1String("file")) { - QString path = url.path(); - - foreach (const QString &extension, supportedExtensions) { - if (path.endsWith(extension, Qt::CaseInsensitive)) - return true; - } - } - return false; -} - -void QMediaImageViewerControlPrivate::loadImage() -{ - cancelRequests(); - - QMediaImageViewer::MediaStatus currentStatus = status; - status = QMediaImageViewer::InvalidMedia; - - QNetworkAccessManager *network = service->networkManager(); - - while (!possibleResources.isEmpty() && !headReply && !getReply) { - currentMedia = possibleResources.takeFirst(); - - QUrl url = currentMedia.url(); - QString mimeType = currentMedia.mimeType(); - - if (isImageType(url, mimeType)) { - getReply = network->get(QNetworkRequest(url)); - QObject::connect(getReply, SIGNAL(finished()), q_func(), SLOT(_q_getFinished())); - - status = QMediaImageViewer::LoadingMedia; - } else if (mimeType.isEmpty() && url.scheme() != QLatin1String("file")) { - headReply = network->head(QNetworkRequest(currentMedia.url())); - QObject::connect(headReply, SIGNAL(finished()), q_func(), SLOT(_q_headFinished())); - - status = QMediaImageViewer::LoadingMedia; - } - } - - if (status == QMediaImageViewer::InvalidMedia) - currentMedia = QMediaResource(); - - if (status != currentStatus) - emit q_func()->mediaStatusChanged(status); -} - -void QMediaImageViewerControlPrivate::cancelRequests() -{ - if (getReply) { - getReply->abort(); - getReply->deleteLater(); - getReply = 0; - } - - if (headReply) { - headReply->abort(); - headReply->deleteLater(); - headReply = 0; - } -} - -void QMediaImageViewerControlPrivate::_q_getFinished() -{ - if (getReply != q_func()->sender()) - return; - - QImage image; - - if (service->d_func()->load(getReply)) { - possibleResources.clear(); - - status = QMediaImageViewer::LoadedMedia; - - emit q_func()->mediaStatusChanged(status); - } else { - loadImage(); - } -} - -void QMediaImageViewerControlPrivate::_q_headFinished() -{ - if (headReply != q_func()->sender()) - return; - - QString mimeType = headReply->header(QNetworkRequest::ContentTypeHeader) - .toString().section(QLatin1Char(';'), 0, 0); - QUrl url = headReply->url(); - if (url.isEmpty()) - url = headReply->request().url(); - - headReply->deleteLater(); - headReply = 0; - - if (isImageType(url, mimeType) || mimeType.isEmpty()) { - QNetworkAccessManager *network = service->networkManager(); - - getReply = network->get(QNetworkRequest(url)); - - QObject::connect(getReply, SIGNAL(finished()), q_func(), SLOT(_q_getFinished())); - } else { - loadImage(); - } -} - -/*! - \class QMediaImageViewerControl - \internal -*/ -QMediaImageViewerControl::QMediaImageViewerControl(QMediaImageViewerService *parent) - : QMediaControl(*new QMediaImageViewerControlPrivate, parent) -{ - Q_D(QMediaImageViewerControl); - - d->service = parent; -} - -/*! -*/ -QMediaImageViewerControl::~QMediaImageViewerControl() -{ - Q_D(QMediaImageViewerControl); - - delete d->getReply; -} - -/*! -*/ -QMediaImageViewer::MediaStatus QMediaImageViewerControl::mediaStatus() const -{ - return d_func()->status; -} - -/*! - \fn QMediaImageViewerControl::mediaStatusChanged(QMediaImageViewer::MediaStatus status); -*/ - -/*! -*/ -void QMediaImageViewerControl::showMedia(const QMediaContent &media) -{ - Q_D(QMediaImageViewerControl); - - d->media = media; - d->currentMedia = QMediaResource(); - d->cancelRequests(); - - if (media.isNull()) { - d->service->d_func()->clear(); - if (d->status != QMediaImageViewer::NoMedia) { - d->status = QMediaImageViewer::NoMedia; - emit mediaStatusChanged(d->status); - } - } else { - d->possibleResources = media.resources(); - d->loadImage(); - } -} - - -#include "moc_qmediaimageviewerservice_p.cpp" -QT_END_NAMESPACE - diff --git a/src/multimedia/imageviewer/qmediaimageviewerservice_p.h b/src/multimedia/imageviewer/qmediaimageviewerservice_p.h deleted file mode 100644 index 351721269..000000000 --- a/src/multimedia/imageviewer/qmediaimageviewerservice_p.h +++ /dev/null @@ -1,147 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMEDIASLIDESHOWSERVICE_P_H -#define QMEDIASLIDESHOWSERVICE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <qtmultimediadefs.h> -#include <qmediaservice.h> -#include <qmediaimageviewer.h> -#include <qvideorenderercontrol.h> - -#include <QtCore/qpointer.h> -#include <QtGui/qimage.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - -class QAbstractVideoSurface; -class QNetworkAccessManager; -QT_END_NAMESPACE - -QT_BEGIN_NAMESPACE - -class QMediaImageViewerServicePrivate; - -class Q_AUTOTEST_EXPORT QMediaImageViewerService : public QMediaService -{ - Q_OBJECT -public: - explicit QMediaImageViewerService(QObject *parent = 0); - ~QMediaImageViewerService(); - - QMediaControl *requestControl(const char *name); - void releaseControl(QMediaControl *); - - QNetworkAccessManager *networkManager() const; - void setNetworkManager(QNetworkAccessManager *manager); - -private: - Q_DECLARE_PRIVATE(QMediaImageViewerService) - friend class QMediaImageViewerControl; - friend class QMediaImageViewerControlPrivate; -}; - -class QMediaImageViewerControlPrivate; - -class QMediaImageViewerControl : public QMediaControl -{ - Q_OBJECT -public: - explicit QMediaImageViewerControl(QMediaImageViewerService *parent); - ~QMediaImageViewerControl(); - - QMediaImageViewer::MediaStatus mediaStatus() const; - - void showMedia(const QMediaContent &media); - -Q_SIGNALS: - void mediaStatusChanged(QMediaImageViewer::MediaStatus status); - -private: - Q_DECLARE_PRIVATE(QMediaImageViewerControl) - Q_PRIVATE_SLOT(d_func(), void _q_headFinished()) - Q_PRIVATE_SLOT(d_func(), void _q_getFinished()) -}; - -#define QMediaImageViewerControl_iid "com.nokia.Qt.QMediaImageViewerControl/1.0" -Q_MEDIA_DECLARE_CONTROL(QMediaImageViewerControl, QMediaImageViewerControl_iid) - -class QMediaImageViewerRenderer : public QVideoRendererControl -{ - Q_OBJECT -public: - QMediaImageViewerRenderer(QObject *parent = 0); - ~QMediaImageViewerRenderer(); - - QAbstractVideoSurface *surface() const; - void setSurface(QAbstractVideoSurface *surface); - - void showImage(const QImage &image); - -Q_SIGNALS: - void surfaceChanged(QAbstractVideoSurface *surface); - -private: - QPointer<QAbstractVideoSurface> m_surface; - QImage m_image; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - - -#endif diff --git a/src/multimedia/multimedia.pro b/src/multimedia/multimedia.pro index 35193307b..ab883d97d 100644 --- a/src/multimedia/multimedia.pro +++ b/src/multimedia/multimedia.pro @@ -52,7 +52,6 @@ SOURCES += \ include(audio/audio.pri) include(camera/camera.pri) include(controls/controls.pri) -include(imageviewer/imageviewer.pri) include(playback/playback.pri) include(radio/radio.pri) include(recording/recording.pri) diff --git a/src/multimedia/playback/qmediaplaylist.cpp b/src/multimedia/playback/qmediaplaylist.cpp index 3767f8eac..67db7f554 100644 --- a/src/multimedia/playback/qmediaplaylist.cpp +++ b/src/multimedia/playback/qmediaplaylist.cpp @@ -85,7 +85,7 @@ namespace \brief The QMediaPlaylist class provides a list of media content to play. QMediaPlaylist is intended to be used with other media objects, - like QMediaPlayer or QMediaImageViewer. + like QMediaPlayer. QMediaPlaylist allows to access the service intrinsic playlist functionality if available, otherwise it provides the the local memory playlist implementation. diff --git a/tests/auto/unit/multimedia.pro b/tests/auto/unit/multimedia.pro index 164cc20ed..1fe7e7c55 100644 --- a/tests/auto/unit/multimedia.pro +++ b/tests/auto/unit/multimedia.pro @@ -34,6 +34,5 @@ SUBDIRS += \ # these interfaces are exported. contains (QT_CONFIG, private_tests) { SUBDIRS += \ - qdeclarativeaudio \ - qmediaimageviewer + qdeclarativeaudio } diff --git a/tests/auto/unit/multimediawidgets.pro b/tests/auto/unit/multimediawidgets.pro index 0105e3ed7..31f8e546c 100644 --- a/tests/auto/unit/multimediawidgets.pro +++ b/tests/auto/unit/multimediawidgets.pro @@ -11,7 +11,6 @@ contains (QT_CONFIG, private_tests) { SUBDIRS += \ qgraphicsvideoitem \ qpaintervideosurface \ - qmediaimageviewerwidgets \ - qvideowidget \ + qvideowidget } diff --git a/tests/auto/unit/qmediaimageviewer/images.qrc b/tests/auto/unit/qmediaimageviewer/images.qrc deleted file mode 100644 index 508de1369..000000000 --- a/tests/auto/unit/qmediaimageviewer/images.qrc +++ /dev/null @@ -1,9 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>images/coverart.png</file> - <file>images/image.jpg</file> - <file>images/image.png</file> - <file>images/invalid.png</file> - <file>images/poster.png</file> - </qresource> -</RCC> diff --git a/tests/auto/unit/qmediaimageviewer/images/coverart.png b/tests/auto/unit/qmediaimageviewer/images/coverart.png Binary files differdeleted file mode 100644 index a24db1b13..000000000 --- a/tests/auto/unit/qmediaimageviewer/images/coverart.png +++ /dev/null diff --git a/tests/auto/unit/qmediaimageviewer/images/image.jpg b/tests/auto/unit/qmediaimageviewer/images/image.jpg Binary files differdeleted file mode 100644 index 8771224cb..000000000 --- a/tests/auto/unit/qmediaimageviewer/images/image.jpg +++ /dev/null diff --git a/tests/auto/unit/qmediaimageviewer/images/image.png b/tests/auto/unit/qmediaimageviewer/images/image.png Binary files differdeleted file mode 100644 index a24db1b13..000000000 --- a/tests/auto/unit/qmediaimageviewer/images/image.png +++ /dev/null diff --git a/tests/auto/unit/qmediaimageviewer/images/invalid.png b/tests/auto/unit/qmediaimageviewer/images/invalid.png deleted file mode 100644 index 3aba327ee..000000000 --- a/tests/auto/unit/qmediaimageviewer/images/invalid.png +++ /dev/null @@ -1,2 +0,0 @@ -This is not really a PNG file. - diff --git a/tests/auto/unit/qmediaimageviewer/images/poster.png b/tests/auto/unit/qmediaimageviewer/images/poster.png Binary files differdeleted file mode 100644 index a24db1b13..000000000 --- a/tests/auto/unit/qmediaimageviewer/images/poster.png +++ /dev/null diff --git a/tests/auto/unit/qmediaimageviewer/qmediaimageviewer.pro b/tests/auto/unit/qmediaimageviewer/qmediaimageviewer.pro deleted file mode 100644 index 4724f6141..000000000 --- a/tests/auto/unit/qmediaimageviewer/qmediaimageviewer.pro +++ /dev/null @@ -1,16 +0,0 @@ -CONFIG += testcase -TARGET = tst_qmediaimageviewer - -QT += multimedia-private network testlib -CONFIG += no_private_qt_headers_warning - -SOURCES += tst_qmediaimageviewer.cpp - -RESOURCES += \ - images.qrc - -!contains(QT_CONFIG, no-jpeg):DEFINES += QTEST_HAVE_JPEG - -wince* { - !contains(QT_CONFIG, no-jpeg): DEPLOYMENT_PLUGIN += qjpeg -} diff --git a/tests/auto/unit/qmediaimageviewer/tst_qmediaimageviewer.cpp b/tests/auto/unit/qmediaimageviewer/tst_qmediaimageviewer.cpp deleted file mode 100644 index a59c2b436..000000000 --- a/tests/auto/unit/qmediaimageviewer/tst_qmediaimageviewer.cpp +++ /dev/null @@ -1,1044 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -//TESTED_COMPONENT=src/multimedia - -#include <qtmultimediadefs.h> -#include <QtTest/QtTest> - -#include <QtCore/qdir.h> - -#include <qmediaimageviewer.h> -#include <private/qmediaimageviewerservice_p.h> -#include <qmediaplaylist.h> -#include <qmediaservice.h> -#include <qvideorenderercontrol.h> - -#include <QtCore/qfile.h> -#include <QtNetwork/qnetworkaccessmanager.h> -#include <QtNetwork/qnetworkreply.h> - -#include <qabstractvideosurface.h> -#include <qvideosurfaceformat.h> - -QT_USE_NAMESPACE -class QtTestNetworkAccessManager; - -class tst_QMediaImageViewer : public QObject -{ - Q_OBJECT -private slots: - void initTestCase(); - - void isValid(); - void timeout(); - void setMedia_data(); - void setMedia(); - void setConsecutiveMedia(); - void setInvalidMedia(); - void playlist(); - void multiplePlaylists(); - void invalidPlaylist(); - void elapsedTime(); - void rendererControl(); - void setVideoOutput(); - void debugEnums(); - - void mediaChanged_signal(); - -public: - tst_QMediaImageViewer() : m_network(0) {} - -private: - QUrl imageUrl(const char *fileName) const { - return QUrl(QLatin1String("qrc:///images/") + QLatin1String(fileName)); } - QString imageFileName(const char *fileName) { - return QLatin1String(":/images/") + QLatin1String(fileName); } - - QtTestNetworkAccessManager *m_network; - QString m_fileProtocol; -}; - -class QtTestVideoSurface : public QAbstractVideoSurface -{ -public: - QList<QVideoFrame::PixelFormat> supportedPixelFormats( - QAbstractVideoBuffer::HandleType handleType) const { - QList<QVideoFrame::PixelFormat> formats; - if (handleType == QAbstractVideoBuffer::NoHandle) { - formats << QVideoFrame::Format_RGB32; - } - return formats; - } - - QVideoFrame frame() const { return m_frame; } - - bool present(const QVideoFrame &frame) { m_frame = frame; return true; } - -private: - QVideoFrame m_frame; -}; - -class QtTestNetworkReply : public QNetworkReply -{ -public: - QtTestNetworkReply( - const QNetworkRequest &request, - const QByteArray &mimeType, - QObject *parent) - : QNetworkReply(parent) - { - setRequest(request); - setOperation(QNetworkAccessManager::HeadOperation); - setRawHeader("content-type", mimeType); - - QCoreApplication::postEvent(this, new QEvent(QEvent::User)); - } - - QtTestNetworkReply( - const QNetworkRequest &request, - const QByteArray &mimeType, - const QString &fileName, - QObject *parent) - : QNetworkReply(parent) - , m_file(fileName) - { - setRequest(request); - setOperation(QNetworkAccessManager::GetOperation); - setRawHeader("content-type", mimeType); - - if (m_file.open(QIODevice::ReadOnly | QIODevice::Unbuffered)) { - setOpenMode(QIODevice::ReadOnly); - } - - QCoreApplication::postEvent(this, new QEvent(QEvent::User)); - } - - void abort() { m_file.close(); } - - bool atEnd () const { return m_file.atEnd(); } - qint64 bytesAvailable() const { return m_file.bytesAvailable() + QIODevice::bytesAvailable(); } - void close() { m_file.close(); setOpenMode(QIODevice::NotOpen); } - bool isSequential() const { return true; } - bool open(OpenMode) { return false; } - qint64 pos() const { return 0; } - bool seek(qint64) { return false; } - qint64 size() const { return m_file.size(); } - qint64 readData(char * data, qint64 maxSize) { return m_file.read(data, maxSize); } - qint64 writeData(const char *, qint64) { return -1; } - -protected: - void customEvent(QEvent *event) - { - if (event->type() == QEvent::User) { - event->accept(); - emit finished(); - } - } - -private: - QFile m_file; -}; - -class QtTestNetworkAccessManager : public QNetworkAccessManager -{ -public: - QtTestNetworkAccessManager(QObject *parent = 0) - : QNetworkAccessManager(parent) - { - } - - void appendDocument(const QUrl &url, const QByteArray &mimeType, const QString &fileName) - { - m_documents.append(Document(url, mimeType, fileName)); - } - -protected: - QNetworkReply *createRequest( - Operation op, const QNetworkRequest &request, QIODevice *outgoingData = 0) - { - foreach (const Document &document, m_documents) { - if (document.url == request.url()) { - if (op == GetOperation) { - return new QtTestNetworkReply( - request, document.mimeType, document.fileName, this); - } else if (op == HeadOperation) { - return new QtTestNetworkReply(request, document.mimeType, this); - } - } - } - return QNetworkAccessManager::createRequest(op, request, outgoingData); - } - -private: - struct Document - { - Document(const QUrl url, const QByteArray mimeType, const QString &fileName) - : url(url), mimeType(mimeType), fileName(fileName) - { - } - - QUrl url; - QByteArray mimeType; - QString fileName; - }; - - QList<Document> m_documents; -}; - -void tst_QMediaImageViewer::initTestCase() -{ - qRegisterMetaType<QMediaImageViewer::State>(); - qRegisterMetaType<QMediaImageViewer::MediaStatus>(); - - m_network = new QtTestNetworkAccessManager(this); - - m_network->appendDocument( - QUrl(QLatin1String("test://image/png?id=1")), - "image/png", - imageFileName("image.png")); - m_network->appendDocument( - QUrl(QLatin1String("test://image/png?id=2")), - QByteArray(), - imageFileName("image.png")); - m_network->appendDocument( - QUrl(QLatin1String("test://image/invalid?id=1")), - "image/png", - imageFileName("invalid.png")); - m_network->appendDocument( - QUrl(QLatin1String("test://image/invalid?id=2")), - QByteArray(), - imageFileName("invalid.png")); -#ifdef QTEST_HAVE_JPEG - m_network->appendDocument( - QUrl(QLatin1String("test://image/jpeg?id=1")), - "image/jpeg", - imageFileName("image.jpg")); -#endif - m_network->appendDocument( - QUrl(QLatin1String("test://music/songs/mp3?id=1")), - "audio/mpeg", - QString()); - m_network->appendDocument( - QUrl(QLatin1String("test://music/covers/small?id=1")), - "image/png", - imageFileName("coverart.png")); - m_network->appendDocument( - QUrl(QLatin1String("test://music/covers/large?id=1")), - "image/png", - imageFileName("coverart.png")); - m_network->appendDocument( - QUrl(QLatin1String("test://video/movies/mp4?id=1")), - "video/mp4", - QString()); - m_network->appendDocument( - QUrl(QLatin1String("test://video/posters/png?id=1")), - "image/png", - imageFileName("poster.png")); -} - -void tst_QMediaImageViewer::isValid() -{ - QMediaImageViewer viewer; - - QVERIFY(viewer.service() != 0); -} - -void tst_QMediaImageViewer::timeout() -{ - QMediaImageViewer viewer; - - QCOMPARE(viewer.timeout(), 3000); - - viewer.setTimeout(0); - QCOMPARE(viewer.timeout(), 0); - - viewer.setTimeout(45); - QCOMPARE(viewer.timeout(), 45); - - viewer.setTimeout(-3000); - QCOMPARE(viewer.timeout(), 0); -} - -void tst_QMediaImageViewer::setMedia_data() -{ - QTest::addColumn<QMediaContent>("media"); - - { - QMediaContent media(imageUrl("image.png")); - - QTest::newRow("file: png image") - << media; - } { - QMediaContent media(QUrl(QLatin1String("test://image/png?id=1"))); - - QTest::newRow("network: png image") - << media; - } { - QMediaContent media(QMediaResource( - QUrl(QLatin1String("test://image/png?id=1")), QLatin1String("image/png"))); - - QTest::newRow("network: png image, explicit mime type") - << media; - } { - QMediaContent media(QUrl(QLatin1String("test://image/png?id=2"))); - - QTest::newRow("network: png image, no mime type") - << media; -#ifdef QTEST_HAVE_JPEG - } { - QMediaContent media(imageUrl("image.jpg")); - - QTest::newRow("file: jpg image") - << media; - } { - QMediaContent media(QUrl(QLatin1String("test://image/jpeg?id=1"))); - - QTest::newRow("network: jpg image") - << media; -#endif - } -} - -void tst_QMediaImageViewer::setMedia() -{ - QFETCH(QMediaContent, media); - - QMediaImageViewer viewer; - - QMediaImageViewerService *service = qobject_cast<QMediaImageViewerService *>(viewer.service()); - service->setNetworkManager(m_network); - - connect(&viewer, SIGNAL(mediaStatusChanged(QMediaImageViewer::MediaStatus)), - &QTestEventLoop::instance(), SLOT(exitLoop())); - - viewer.setMedia(media); - QCOMPARE(viewer.media(), media); - - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); - - QTestEventLoop::instance().enterLoop(2); - - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); -} - -void tst_QMediaImageViewer::setConsecutiveMedia() -{ - QMediaContent fileMedia1(imageUrl("image.png")); - QMediaContent fileMedia2(imageUrl("coverart.png")); - QMediaContent networkMedia1(QUrl(QLatin1String("test://image/png?id=1"))); - QMediaContent networkMedia2(QUrl(QLatin1String("test://image/png?id=2"))); - - QMediaImageViewer viewer; - - connect(&viewer, SIGNAL(mediaStatusChanged(QMediaImageViewer::MediaStatus)), - &QTestEventLoop::instance(), SLOT(exitLoop())); - - viewer.setMedia(fileMedia1); - viewer.setMedia(fileMedia2); - - QCOMPARE(viewer.media(), fileMedia2); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); - - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(viewer.media(), fileMedia2); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); - - QMediaImageViewerService *service = qobject_cast<QMediaImageViewerService *>(viewer.service()); - service->setNetworkManager(m_network); - - viewer.setMedia(networkMedia2); - viewer.setMedia(networkMedia1); - - QCOMPARE(viewer.media(), networkMedia1); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); - - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(viewer.media(), networkMedia1); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); - - viewer.setMedia(fileMedia1); - viewer.setMedia(networkMedia2); - - QCOMPARE(viewer.media(), networkMedia2); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); - - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(viewer.media(), networkMedia2); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); - - viewer.setMedia(fileMedia1); - viewer.setMedia(networkMedia2); - - QCOMPARE(viewer.media(), networkMedia2); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); - - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(viewer.media(), networkMedia2); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); - - viewer.setMedia(networkMedia1); - viewer.setMedia(fileMedia2); - - QCOMPARE(viewer.media(), fileMedia2); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); - - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(viewer.media(), fileMedia2); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); -} - -void tst_QMediaImageViewer::setInvalidMedia() -{ - QMediaImageViewer viewer; - viewer.setTimeout(250); - - QMediaImageViewerService *service = qobject_cast<QMediaImageViewerService *>(viewer.service()); - service->setNetworkManager(m_network); - - connect(&viewer, SIGNAL(mediaStatusChanged(QMediaImageViewer::MediaStatus)), - &QTestEventLoop::instance(), SLOT(exitLoop())); - - { - QMediaContent media(imageUrl("invalid.png")); - - viewer.setMedia(media); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); - - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::InvalidMedia); - QCOMPARE(viewer.media(), media); - } { - QMediaContent media(imageUrl("deleted.png")); - - viewer.setMedia(media); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); - - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::InvalidMedia); - QCOMPARE(viewer.media(), media); - } { - QMediaResource invalidResource(imageUrl("invalid.png")); - QMediaResource deletedResource(imageUrl("deleted.png")); - QMediaContent media(QMediaResourceList() << invalidResource << deletedResource); - - viewer.setMedia(media); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); - - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::InvalidMedia); - QCOMPARE(viewer.media(), media); - } { - QMediaResource resource(imageUrl("image.png"), QLatin1String("audio/mpeg")); - QMediaContent media(resource); - - viewer.setMedia(media); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::InvalidMedia); - QCOMPARE(viewer.media(), media); - } { - QMediaResource audioResource(imageUrl("image.png"), QLatin1String("audio/mpeg")); - QMediaResource invalidResource(imageUrl("invalid.png")); - QMediaContent media(QMediaResourceList() << audioResource << invalidResource); - - viewer.setMedia(media); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); - - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::InvalidMedia); - QCOMPARE(viewer.media(), media); - } { - QMediaContent media(QUrl(QLatin1String("test://image/invalid?id=1"))); - - viewer.setMedia(media); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); - - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::InvalidMedia); - QCOMPARE(viewer.media(), media); - } { - QMediaContent media(QUrl(QLatin1String("test://image/invalid?id=2"))); - - viewer.setMedia(media); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); - - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::InvalidMedia); - QCOMPARE(viewer.media(), media); - } { - QMediaContent media(QUrl(QLatin1String("test://image/invalid?id=3"))); - - viewer.setMedia(media); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); - - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::InvalidMedia); - QCOMPARE(viewer.media(), media); - } -} - -void tst_QMediaImageViewer::playlist() -{ - QMediaContent imageMedia(imageUrl("image.png")); - QMediaContent posterMedia(imageUrl("poster.png")); - QMediaContent coverArtMedia(imageUrl("coverart.png")); - - QMediaImageViewer viewer; - viewer.setTimeout(250); - - connect(&viewer, SIGNAL(mediaStatusChanged(QMediaImageViewer::MediaStatus)), - &QTestEventLoop::instance(), SLOT(exitLoop())); - - QSignalSpy stateSpy(&viewer, SIGNAL(stateChanged(QMediaImageViewer::State))); - - QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); - - // No playlist so can't exit stopped state. - viewer.play(); - QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); - QCOMPARE(stateSpy.count(), 0); - viewer.pause(); - QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); - QCOMPARE(stateSpy.count(), 0); - - QMediaPlaylist playlist; - viewer.setPlaylist(&playlist); - - // Empty playlist so can't exit stopped state. - viewer.play(); - QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); - QCOMPARE(stateSpy.count(), 0); - viewer.pause(); - QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); - QCOMPARE(stateSpy.count(), 0); - - playlist.addMedia(imageMedia); - playlist.addMedia(posterMedia); - playlist.addMedia(coverArtMedia); - - // Play progresses immediately to the first image and starts loading. - viewer.play(); - QCOMPARE(viewer.state(), QMediaImageViewer::PlayingState); - QCOMPARE(stateSpy.count(), 1); - QCOMPARE(qvariant_cast<QMediaImageViewer::State>(stateSpy.last().value(0)), - QMediaImageViewer::PlayingState); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); - QCOMPARE(playlist.currentIndex(), 0); - QCOMPARE(viewer.media(), imageMedia); - - // Image is loaded asynchronously. - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); - QCOMPARE(playlist.currentIndex(), 0); - - // Time out causes progression to second image, which starts loading. - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); - QCOMPARE(playlist.currentIndex(), 1); - QCOMPARE(viewer.media(), posterMedia); - - // Image is loaded asynchronously. - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(viewer.state(), QMediaImageViewer::PlayingState); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); - QCOMPARE(playlist.currentIndex(), 1); - - // Pausing stops progression at current image. - viewer.pause(); - QCOMPARE(viewer.state(), QMediaImageViewer::PausedState); - QCOMPARE(stateSpy.count(), 2); - QCOMPARE(qvariant_cast<QMediaImageViewer::State>(stateSpy.last().value(0)), - QMediaImageViewer::PausedState); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); - QCOMPARE(playlist.currentIndex(), 1); - - // No time out. - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(viewer.state(), QMediaImageViewer::PausedState); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); - QCOMPARE(playlist.currentIndex(), 1); - - // Resuming playback does not immediately progress to the next item - viewer.play(); - QCOMPARE(viewer.state(), QMediaImageViewer::PlayingState); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); - QCOMPARE(playlist.currentIndex(), 1); - - // Time out causes progression to next image, which starts loading. - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); - QCOMPARE(playlist.currentIndex(), 2); - QCOMPARE(viewer.media(), coverArtMedia); - - // Image is loaded asynchronously. - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); - QCOMPARE(playlist.currentIndex(), 2); - - // Time out causes progression to end of list - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); - QCOMPARE(stateSpy.count(), 4); - QCOMPARE(qvariant_cast<QMediaImageViewer::State>(stateSpy.last().value(0)), - QMediaImageViewer::StoppedState); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::NoMedia); - QCOMPARE(playlist.currentIndex(), -1); - QCOMPARE(viewer.media(), QMediaContent()); - - // Stopped, no time out. - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::NoMedia); - QCOMPARE(playlist.currentIndex(), -1); - - // Play progresses immediately to the first image and starts loading. - viewer.play(); - QCOMPARE(viewer.state(), QMediaImageViewer::PlayingState); - QCOMPARE(stateSpy.count(), 5); - QCOMPARE(qvariant_cast<QMediaImageViewer::State>(stateSpy.last().value(0)), - QMediaImageViewer::PlayingState); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); - QCOMPARE(playlist.currentIndex(), 0); - QCOMPARE(viewer.media(), imageMedia); - - // Image is loaded asynchronously. - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); - QCOMPARE(playlist.currentIndex(), 0); - - // Stop ends progress, but retains current index. - viewer.stop(); - QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); - QCOMPARE(stateSpy.count(), 6); - QCOMPARE(qvariant_cast<QMediaImageViewer::State>(stateSpy.last().value(0)), - QMediaImageViewer::StoppedState); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); - QCOMPARE(playlist.currentIndex(), 0); - QCOMPARE(viewer.media(), imageMedia); - - // Stoppped, No time out. - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); - QCOMPARE(playlist.currentIndex(), 0); - QCOMPARE(viewer.media(), imageMedia); - - // Stop when already stopped doesn't emit additional signals. - viewer.stop(); - QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); - QCOMPARE(stateSpy.count(), 6); - - viewer.play(); - QCOMPARE(stateSpy.count(), 7); - - // Play when already playing doesn't emit additional signals. - viewer.play(); - QCOMPARE(viewer.state(), QMediaImageViewer::PlayingState); - QCOMPARE(stateSpy.count(), 7); - - playlist.next(); - QCOMPARE(viewer.state(), QMediaImageViewer::PlayingState); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); - - // Pausing while loading, doesn't stop loading. - viewer.pause(); - QCOMPARE(viewer.state(), QMediaImageViewer::PausedState); - QCOMPARE(stateSpy.count(), 8); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); - - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(viewer.state(), QMediaImageViewer::PausedState); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); - - // Pause while paused doesn't emit additional signals. - viewer.pause(); - QCOMPARE(viewer.state(), QMediaImageViewer::PausedState); - QCOMPARE(stateSpy.count(), 8); - - // Calling setMedia stops the playlist. - viewer.setMedia(imageMedia); - QCOMPARE(viewer.media(), imageMedia); - QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); - QCOMPARE(stateSpy.count(), 9); - QCOMPARE(qvariant_cast<QMediaImageViewer::State>(stateSpy.last().value(0)), - QMediaImageViewer::StoppedState); - -} - -void tst_QMediaImageViewer::multiplePlaylists() -{ - QMediaContent imageMedia(imageUrl("image.png")); - QMediaContent posterMedia(imageUrl("poster.png")); - QMediaContent coverArtMedia(imageUrl("coverart.png")); - - QMediaImageViewer viewer; - - QMediaPlaylist *playlist1 = new QMediaPlaylist; - viewer.setPlaylist(playlist1); - playlist1->addMedia(imageMedia); - playlist1->addMedia(posterMedia); - - playlist1->setCurrentIndex(0); - QCOMPARE(viewer.media(), imageMedia); - - QMediaPlaylist *playlist2 = new QMediaPlaylist; - - viewer.setPlaylist(playlist2); - playlist2->addMedia(coverArtMedia); - - QVERIFY(viewer.media().isNull()); - - playlist2->setCurrentIndex(0); - QCOMPARE(viewer.media(), coverArtMedia); - - delete playlist2; - QVERIFY(viewer.media().isNull()); - QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); - - viewer.setPlaylist(playlist1); - playlist1->setCurrentIndex(0); - QCOMPARE(viewer.media(), imageMedia); - - viewer.play(); - QCOMPARE(viewer.state(), QMediaImageViewer::PlayingState); - - delete playlist1; - QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); -} - - -void tst_QMediaImageViewer::invalidPlaylist() -{ - QMediaContent imageMedia(imageUrl("image.png")); - QMediaContent invalidMedia(imageUrl("invalid.png")); - - QMediaImageViewer viewer; - viewer.setTimeout(250); - - connect(&viewer, SIGNAL(mediaStatusChanged(QMediaImageViewer::MediaStatus)), - &QTestEventLoop::instance(), SLOT(exitLoop())); - - QSignalSpy stateSpy(&viewer, SIGNAL(stateChanged(QMediaImageViewer::State))); - QSignalSpy statusSpy(&viewer, SIGNAL(mediaStatusChanged(QMediaImageViewer::MediaStatus))); - - QMediaPlaylist playlist; - viewer.setPlaylist(&playlist); - playlist.addMedia(invalidMedia); - playlist.addMedia(imageMedia); - playlist.addMedia(invalidMedia); - - // Test play initially tries to load the first invalid image. - viewer.play(); - QCOMPARE(viewer.state(), QMediaImageViewer::PlayingState); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); - QCOMPARE(viewer.media(), invalidMedia); - QCOMPARE(playlist.currentIndex(), 0); - QCOMPARE(statusSpy.count(), 1); - QCOMPARE(qvariant_cast<QMediaImageViewer::MediaStatus>(statusSpy.value(0).value(0)), - QMediaImageViewer::LoadingMedia); - - // Test status is changed to InvalidMedia, and loading of the next image is started immediately. - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(viewer.state(), QMediaImageViewer::PlayingState); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); - QCOMPARE(viewer.media(), imageMedia); - QCOMPARE(playlist.currentIndex(), 1); - QCOMPARE(statusSpy.count(), 3); - QCOMPARE(qvariant_cast<QMediaImageViewer::MediaStatus>(statusSpy.value(1).value(0)), - QMediaImageViewer::InvalidMedia); - QCOMPARE(qvariant_cast<QMediaImageViewer::MediaStatus>(statusSpy.value(2).value(0)), - QMediaImageViewer::LoadingMedia); - - // Test if the last image is invalid, the image viewer is stopped. - playlist.next(); - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::NoMedia); - QCOMPARE(playlist.currentIndex(), -1); - QCOMPARE(stateSpy.count(), 2); - - playlist.setCurrentIndex(2); - QTestEventLoop::instance().enterLoop(2); - - // Test play immediately moves to the next item if the current one is invalid, and no state - // change signals are emitted if the viewer never effectively moves from the StoppedState. - viewer.play(); - QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); - QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::NoMedia); - QCOMPARE(playlist.currentIndex(), -1); - QCOMPARE(stateSpy.count(), 2); -} - -void tst_QMediaImageViewer::elapsedTime() -{ - QMediaContent imageMedia(imageUrl("image.png")); - - QMediaImageViewer viewer; - viewer.setTimeout(250); - viewer.setNotifyInterval(150); - - QSignalSpy spy(&viewer, SIGNAL(elapsedTimeChanged(int))); - - connect(&viewer, SIGNAL(elapsedTimeChanged(int)), - &QTestEventLoop::instance(), SLOT(exitLoop())); - - - QMediaPlaylist playlist; - viewer.setPlaylist(&playlist); - playlist.addMedia(imageMedia); - - QCOMPARE(viewer.elapsedTime(), 0); - - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(spy.count(), 0); - - viewer.play(); - QCOMPARE(viewer.elapsedTime(), 0); - - // Emits an initial elapsed time at 0 milliseconds signal when the image is loaded. - QTestEventLoop::instance().enterLoop(1); - QCOMPARE(spy.count(), 1); - QCOMPARE(spy.last().value(0).toInt(), 0); - - // Emits a scheduled signal after the notify interval is up. The exact time will be a little - // fuzzy. - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(spy.count(), 2); - QVERIFY(spy.last().value(0).toInt() != 0); - - // Pausing will emit a signal with the elapsed time when paused. - viewer.pause(); - QCOMPARE(spy.count(), 3); - QCOMPARE(viewer.elapsedTime(), spy.last().value(0).toInt()); - - // No elapsed time signals will be emitted while paused. - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(spy.count(), 3); - - // Stopping a paused viewer resets the elapsed time to 0 with signals emitted. - viewer.stop(); - QCOMPARE(viewer.elapsedTime(), 0); - QCOMPARE(spy.count(), 4); - QCOMPARE(spy.last().value(0).toInt(), 0); - - disconnect(&viewer, SIGNAL(elapsedTimeChanged(int)), - &QTestEventLoop::instance(), SLOT(exitLoop())); - - connect(&viewer, SIGNAL(mediaStatusChanged(QMediaImageViewer::MediaStatus)), - &QTestEventLoop::instance(), SLOT(exitLoop())); - - // Play until end. - viewer.play(); - QTestEventLoop::instance().enterLoop(2); - - // Verify at least two more signals are emitted. - // The second to last at the instant the timeout expired, and the last as it's reset when the - // current media is cleared. - QVERIFY(spy.count() >= 5); - QCOMPARE(spy.value(spy.count() - 2).value(0).toInt(), 250); - QCOMPARE(spy.value(spy.count() - 1).value(0).toInt(), 0); - - viewer.play(); - QTestEventLoop::instance().enterLoop(2); - - // Test extending the timeout applies to an already loaded image. - viewer.setTimeout(10000); - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(viewer.state(), QMediaImageViewer::PlayingState); - - // Test reducing the timeout applies to an already loaded image. - viewer.setTimeout(1000); - QTestEventLoop::instance().enterLoop(2); - QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); - -} - -void tst_QMediaImageViewer::rendererControl() -{ - QtTestVideoSurface surfaceA; - QtTestVideoSurface surfaceB; - QAbstractVideoSurface *nullSurface = 0; - - QMediaImageViewer viewer; - - QMediaService *service = viewer.service(); - if (service == 0) - QSKIP("Image viewer object has no service."); - - QMediaControl *mediaControl = service->requestControl(QVideoRendererControl_iid); - QVERIFY(mediaControl != 0); - - QVideoRendererControl *rendererControl = qobject_cast<QVideoRendererControl *>(mediaControl); - QVERIFY(rendererControl != 0); - - rendererControl->setSurface(&surfaceA); - QCOMPARE(rendererControl->surface(), (QAbstractVideoSurface *)&surfaceA); - - // Load an image so the viewer has some dimensions to work with. - viewer.setMedia(QMediaContent(imageUrl("image.png"))); - - connect(&viewer, SIGNAL(mediaStatusChanged(QMediaImageViewer::MediaStatus)), - &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(2); - - if (viewer.mediaStatus() != QMediaImageViewer::LoadedMedia) - QSKIP("failed to load test image"); - - QCOMPARE(surfaceA.isActive(), true); - - { - QVideoSurfaceFormat format = surfaceA.surfaceFormat(); - QCOMPARE(format.handleType(), QAbstractVideoBuffer::NoHandle); - QCOMPARE(format.pixelFormat(), QVideoFrame::Format_RGB32); - QCOMPARE(format.frameSize(), QSize(75, 50)); - - QVideoFrame frame = surfaceA.frame(); - QCOMPARE(frame.handleType(), QAbstractVideoBuffer::NoHandle); - QCOMPARE(frame.pixelFormat(), QVideoFrame::Format_RGB32); - QCOMPARE(frame.size(), QSize(75, 50)); - } - // Test clearing the output stops the video surface. - service->releaseControl(rendererControl); - QCOMPARE(surfaceA.isActive(), false); - - // Test reseting the output restarts it. - mediaControl = service->requestControl(QVideoRendererControl_iid); - QVERIFY(mediaControl != 0); - - rendererControl = qobject_cast<QVideoRendererControl *>(mediaControl); - rendererControl->setSurface(&surfaceA); - QVERIFY(rendererControl != 0); - { - QVideoSurfaceFormat format = surfaceA.surfaceFormat(); - QCOMPARE(format.handleType(), QAbstractVideoBuffer::NoHandle); - QCOMPARE(format.pixelFormat(), QVideoFrame::Format_RGB32); - QCOMPARE(format.frameSize(), QSize(75, 50)); - - QVideoFrame frame = surfaceA.frame(); - QCOMPARE(frame.handleType(), QAbstractVideoBuffer::NoHandle); - QCOMPARE(frame.pixelFormat(), QVideoFrame::Format_RGB32); - QCOMPARE(frame.size(), QSize(75, 50)); - } - - // Test changing the surface while viewing an image stops the old surface and starts - // the new one and presents the image. - rendererControl->setSurface(&surfaceB); - QCOMPARE(rendererControl->surface(), (QAbstractVideoSurface*)&surfaceB); - - QCOMPARE(surfaceA.isActive(), false); - QCOMPARE(surfaceB.isActive(), true); - - QVideoSurfaceFormat format = surfaceB.surfaceFormat(); - QCOMPARE(format.handleType(), QAbstractVideoBuffer::NoHandle); - QCOMPARE(format.pixelFormat(), QVideoFrame::Format_RGB32); - QCOMPARE(format.frameSize(), QSize(75, 50)); - - QVideoFrame frame = surfaceB.frame(); - QCOMPARE(frame.handleType(), QAbstractVideoBuffer::NoHandle); - QCOMPARE(frame.pixelFormat(), QVideoFrame::Format_RGB32); - QCOMPARE(frame.size(), QSize(75, 50)); - - // Test setting null media stops the surface. - viewer.setMedia(QMediaContent()); - QCOMPARE(surfaceB.isActive(), false); - - // Test the renderer control accepts a null surface. - rendererControl->setSurface(0); - QCOMPARE(rendererControl->surface(), nullSurface); -} - -void tst_QMediaImageViewer::setVideoOutput() -{ - QMediaImageViewer imageViewer; - imageViewer.setMedia(QMediaContent(imageUrl("image.png"))); - - connect(&imageViewer, SIGNAL(mediaStatusChanged(QMediaImageViewer::MediaStatus)), - &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(2); - - if (imageViewer.mediaStatus() != QMediaImageViewer::LoadedMedia) - QSKIP("failed to load test image"); - - QtTestVideoSurface surface; - - imageViewer.setVideoOutput(reinterpret_cast<QVideoWidget *>(0)); - - imageViewer.setVideoOutput(reinterpret_cast<QGraphicsVideoItem *>(0)); - - imageViewer.setVideoOutput(&surface); - QVERIFY(surface.isActive()); - - imageViewer.setVideoOutput(reinterpret_cast<QAbstractVideoSurface *>(0)); - QVERIFY(!surface.isActive()); - - imageViewer.setVideoOutput(&surface); - QVERIFY(surface.isActive()); - - imageViewer.setVideoOutput(reinterpret_cast<QVideoWidget *>(0)); - QVERIFY(!surface.isActive()); - - imageViewer.setVideoOutput(&surface); - QVERIFY(surface.isActive()); -} - -void tst_QMediaImageViewer::debugEnums() -{ - QTest::ignoreMessage(QtDebugMsg, "QMediaImageViewer::PlayingState "); - qDebug() << QMediaImageViewer::PlayingState; - QTest::ignoreMessage(QtDebugMsg, "QMediaImageViewer::NoMedia "); - qDebug() << QMediaImageViewer::NoMedia; -} - -void tst_QMediaImageViewer::mediaChanged_signal() -{ - QMediaContent imageMedia(imageUrl("image.png")); - QMediaImageViewer viewer; - viewer.setTimeout(250); - viewer.setNotifyInterval(150); - - QSignalSpy spy(&viewer, SIGNAL(mediaChanged(QMediaContent))); - QVERIFY(spy.size() == 0); - - viewer.setMedia(imageMedia); - QVERIFY(spy.size() == 1); -} - -QTEST_MAIN(tst_QMediaImageViewer) - -#include "tst_qmediaimageviewer.moc" diff --git a/tests/auto/unit/qmediaimageviewerwidgets/images.qrc b/tests/auto/unit/qmediaimageviewerwidgets/images.qrc deleted file mode 100644 index 1d4edce17..000000000 --- a/tests/auto/unit/qmediaimageviewerwidgets/images.qrc +++ /dev/null @@ -1,5 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>images/image.png</file> - </qresource> -</RCC> diff --git a/tests/auto/unit/qmediaimageviewerwidgets/images/image.png b/tests/auto/unit/qmediaimageviewerwidgets/images/image.png Binary files differdeleted file mode 100644 index a24db1b13..000000000 --- a/tests/auto/unit/qmediaimageviewerwidgets/images/image.png +++ /dev/null diff --git a/tests/auto/unit/qmediaimageviewerwidgets/qmediaimageviewerwidgets.pro b/tests/auto/unit/qmediaimageviewerwidgets/qmediaimageviewerwidgets.pro deleted file mode 100644 index a37ae8832..000000000 --- a/tests/auto/unit/qmediaimageviewerwidgets/qmediaimageviewerwidgets.pro +++ /dev/null @@ -1,17 +0,0 @@ -CONFIG += testcase -TARGET = tst_qmediaimageviewerwidgets - -QT += multimedia-private multimediawidgets-private network testlib -CONFIG += no_private_qt_headers_warning - -SOURCES += tst_qmediaimageviewerwidgets.cpp - -RESOURCES += \ - images.qrc - -!contains(QT_CONFIG, no-jpeg):DEFINES += QTEST_HAVE_JPEG - -wince* { - !contains(QT_CONFIG, no-jpeg): DEPLOYMENT_PLUGIN += qjpeg -} -QT+=widgets diff --git a/tests/auto/unit/qmediaimageviewerwidgets/tst_qmediaimageviewerwidgets.cpp b/tests/auto/unit/qmediaimageviewerwidgets/tst_qmediaimageviewerwidgets.cpp deleted file mode 100644 index f1ceab996..000000000 --- a/tests/auto/unit/qmediaimageviewerwidgets/tst_qmediaimageviewerwidgets.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -//TESTED_COMPONENT=src/multimedia - -#include <qtmultimediadefs.h> -#include <QtTest/QtTest> - -#include <QtCore/qdir.h> - -#include <qgraphicsvideoitem.h> -#include <qmediaimageviewer.h> -#include <private/qmediaimageviewerservice_p.h> -#include <qmediaplaylist.h> -#include <qmediaservice.h> -#include <qvideorenderercontrol.h> -#include <qvideowidget.h> -#include <qvideowidgetcontrol.h> - -#include <qabstractvideosurface.h> -#include <qvideosurfaceformat.h> - -QT_USE_NAMESPACE - -class tst_QMediaImageViewerWidgets : public QObject -{ - Q_OBJECT -private slots: - void setVideoOutput(); -}; - -class QtTestVideoSurface : public QAbstractVideoSurface -{ -public: - QList<QVideoFrame::PixelFormat> supportedPixelFormats( - QAbstractVideoBuffer::HandleType handleType) const { - QList<QVideoFrame::PixelFormat> formats; - if (handleType == QAbstractVideoBuffer::NoHandle) { - formats << QVideoFrame::Format_RGB32; - } - return formats; - } - - QVideoFrame frame() const { return m_frame; } - - bool present(const QVideoFrame &frame) { m_frame = frame; return true; } - -private: - QVideoFrame m_frame; -}; - -void tst_QMediaImageViewerWidgets::setVideoOutput() -{ - QMediaImageViewer imageViewer; - imageViewer.setMedia(QMediaContent(QUrl("qrc:///images/image.png"))); - - connect(&imageViewer, SIGNAL(mediaStatusChanged(QMediaImageViewer::MediaStatus)), - &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(2); - - if (imageViewer.mediaStatus() != QMediaImageViewer::LoadedMedia) - QSKIP("failed to load test image"); - - QVideoWidget widget; - QGraphicsVideoItem item; - QtTestVideoSurface surface; - - imageViewer.setVideoOutput(&widget); - QVERIFY(widget.mediaObject() == &imageViewer); - - imageViewer.setVideoOutput(&item); - QVERIFY(widget.mediaObject() == 0); - QVERIFY(item.mediaObject() == &imageViewer); - - imageViewer.setVideoOutput(reinterpret_cast<QVideoWidget *>(0)); - QVERIFY(item.mediaObject() == 0); - - imageViewer.setVideoOutput(&widget); - QVERIFY(widget.mediaObject() == &imageViewer); - - imageViewer.setVideoOutput(reinterpret_cast<QGraphicsVideoItem *>(0)); - QVERIFY(widget.mediaObject() == 0); - - imageViewer.setVideoOutput(&surface); - QVERIFY(surface.isActive()); - - imageViewer.setVideoOutput(reinterpret_cast<QAbstractVideoSurface *>(0)); - QVERIFY(!surface.isActive()); - - imageViewer.setVideoOutput(&surface); - QVERIFY(surface.isActive()); - - imageViewer.setVideoOutput(&widget); - QVERIFY(!surface.isActive()); - QVERIFY(widget.mediaObject() == &imageViewer); - - imageViewer.setVideoOutput(&surface); - QVERIFY(surface.isActive()); - QVERIFY(widget.mediaObject() == 0); -} - -QTEST_MAIN(tst_QMediaImageViewerWidgets) - -#include "tst_qmediaimageviewerwidgets.moc" |