Merge master into api_changes
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickimage.cpp
index 19a8ef1..2346689 100644 (file)
@@ -1,10 +1,9 @@
 /****************************************************************************
 **
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
 **
-** This file is part of the QtDeclarative module of the Qt Toolkit.
+** This file is part of the QtQml module of the Qt Toolkit.
 **
 ** $QT_BEGIN_LICENSE:LGPL$
 ** GNU Lesser General Public License Usage
@@ -35,6 +34,7 @@
 **
 **
 **
+**
 ** $QT_END_LICENSE$
 **
 ****************************************************************************/
@@ -42,7 +42,7 @@
 #include "qquickimage_p.h"
 #include "qquickimage_p_p.h"
 
-#include <QtQuick/private/qsgtextureprovider_p.h>
+#include <QtQuick/qsgtextureprovider.h>
 
 #include <QtQuick/private/qsgcontext_p.h>
 #include <private/qsgadaptationlayer_p.h>
@@ -120,7 +120,7 @@ QQuickImagePrivate::QQuickImagePrivate()
 
     The following example shows the simplest usage of the Image element.
 
-    \snippet doc/src/snippets/declarative/image.qml document
+    \snippet doc/src/snippets/qml/image.qml document
 
     \beginfloatleft
     \image declarative-qtlogo.png
@@ -142,12 +142,12 @@ QQuickImagePrivate::QQuickImagePrivate()
     Images are cached and shared internally, so if several Image elements have the same \l source,
     only one copy of the image will be loaded.
 
-    \bold Note: Images are often the greatest user of memory in QML user interfaces.  It is recommended
+    \b Note: Images are often the greatest user of memory in QML user interfaces.  It is recommended
     that images which do not form part of the user interface have their
     size bounded via the \l sourceSize property. This is especially important for content
     that is loaded from external sources or provided by the user.
 
-    \sa {declarative/imageelements/image}{Image example}, QDeclarativeImageProvider
+    \sa {declarative/imageelements/image}{Image example}, QQmlImageProvider
 */
 
 QQuickImage::QQuickImage(QQuickItem *parent)
@@ -185,20 +185,20 @@ void QQuickImagePrivate::setImage(const QImage &image)
     than the item.
 
     \list
-    \o Image.Stretch - the image is scaled to fit
-    \o Image.PreserveAspectFit - the image is scaled uniformly to fit without cropping
-    \o Image.PreserveAspectCrop - the image is scaled uniformly to fill, cropping if necessary
-    \o Image.Tile - the image is duplicated horizontally and vertically
-    \o Image.TileVertically - the image is stretched horizontally and tiled vertically
-    \o Image.TileHorizontally - the image is stretched vertically and tiled horizontally
-    \o Image.Pad - the image is not transformed
+    \li Image.Stretch - the image is scaled to fit
+    \li Image.PreserveAspectFit - the image is scaled uniformly to fit without cropping
+    \li Image.PreserveAspectCrop - the image is scaled uniformly to fill, cropping if necessary
+    \li Image.Tile - the image is duplicated horizontally and vertically
+    \li Image.TileVertically - the image is stretched horizontally and tiled vertically
+    \li Image.TileHorizontally - the image is stretched vertically and tiled horizontally
+    \li Image.Pad - the image is not transformed
     \endlist
 
     \table
 
     \row
-    \o \image declarative-qtlogo-stretch.png
-    \o Stretch (default)
+    \li \image declarative-qtlogo-stretch.png
+    \li Stretch (default)
     \qml
     Image {
         width: 130; height: 100
@@ -208,8 +208,8 @@ void QQuickImagePrivate::setImage(const QImage &image)
     \endqml
 
     \row
-    \o \image declarative-qtlogo-preserveaspectfit.png
-    \o PreserveAspectFit
+    \li \image declarative-qtlogo-preserveaspectfit.png
+    \li PreserveAspectFit
     \qml
     Image {
         width: 130; height: 100
@@ -220,8 +220,8 @@ void QQuickImagePrivate::setImage(const QImage &image)
     \endqml
 
     \row
-    \o \image declarative-qtlogo-preserveaspectcrop.png
-    \o PreserveAspectCrop
+    \li \image declarative-qtlogo-preserveaspectcrop.png
+    \li PreserveAspectCrop
     \qml
     Image {
         width: 130; height: 100
@@ -233,8 +233,8 @@ void QQuickImagePrivate::setImage(const QImage &image)
     \endqml
 
     \row
-    \o \image declarative-qtlogo-tile.png
-    \o Tile
+    \li \image declarative-qtlogo-tile.png
+    \li Tile
     \qml
     Image {
         width: 120; height: 120
@@ -244,8 +244,8 @@ void QQuickImagePrivate::setImage(const QImage &image)
     \endqml
 
     \row
-    \o \image declarative-qtlogo-tilevertically.png
-    \o TileVertically
+    \li \image declarative-qtlogo-tilevertically.png
+    \li TileVertically
     \qml
     Image {
         width: 120; height: 120
@@ -256,8 +256,8 @@ void QQuickImagePrivate::setImage(const QImage &image)
     \endqml
 
     \row
-    \o \image declarative-qtlogo-tilehorizontally.png
-    \o TileHorizontally
+    \li \image declarative-qtlogo-tilehorizontally.png
+    \li TileHorizontally
     \qml
     Image {
         width: 120; height: 120
@@ -319,22 +319,22 @@ qreal QQuickImage::paintedHeight() const
 
     This property holds the status of image loading.  It can be one of:
     \list
-    \o Image.Null - no image has been set
-    \o Image.Ready - the image has been loaded
-    \o Image.Loading - the image is currently being loaded
-    \o Image.Error - an error occurred while loading the image
+    \li Image.Null - no image has been set
+    \li Image.Ready - the image has been loaded
+    \li Image.Loading - the image is currently being loaded
+    \li Image.Error - an error occurred while loading the image
     \endlist
 
     Use this status to provide an update or respond to the status change in some way.
     For example, you could:
 
     \list
-    \o Trigger a state change:
+    \li Trigger a state change:
     \qml
         State { name: 'loaded'; when: image.status == Image.Ready }
     \endqml
 
-    \o Implement an \c onStatusChanged signal handler:
+    \li Implement an \c onStatusChanged signal handler:
     \qml
         Image {
             id: image
@@ -342,7 +342,7 @@ qreal QQuickImage::paintedHeight() const
         }
     \endqml
 
-    \o Bind to the status value:
+    \li Bind to the status value:
     \qml
         Text { text: image.status == Image.Ready ? 'Loaded' : 'Not loaded' }
     \endqml
@@ -404,6 +404,10 @@ qreal QQuickImage::paintedHeight() const
     other dimension is set in proportion to preserve the source image's aspect ratio.
     (The \l fillMode is independent of this.)
 
+    If both the sourceSize.width and sourceSize.height are set the image will be scaled
+    down to fit within the specified size, maintaining the image's aspect ratio.  The actual
+    size of the image after scaling is available via \l implicitWidth and \l implicitHeight.
+
     If the source is an intrinsically scalable image (eg. SVG), this property
     determines the size of the loaded image regardless of intrinsic size.
     Avoid changing this property dynamically; rendering an SVG is \e slow compared
@@ -413,7 +417,7 @@ qreal QQuickImage::paintedHeight() const
     be no greater than this property specifies. For some formats (currently only JPEG),
     the whole image will never actually be loaded into memory.
 
-    Since QtQuick 1.1 the sourceSize can be cleared to the natural size of the image
+    sourceSize can be cleared to the natural size of the image
     by setting sourceSize to \c undefined.
 
     \note \e {Changing this property dynamically causes the image source to be reloaded,
@@ -427,7 +431,7 @@ qreal QQuickImage::paintedHeight() const
 
     The URL may be absolute, or relative to the URL of the component.
 
-    \sa QDeclarativeImageProvider
+    \sa QQmlImageProvider
 */
 
 /*!
@@ -544,7 +548,7 @@ QSGTextureProvider *QQuickImage::textureProvider() const
         QQuickImagePrivate *dd = const_cast<QQuickImagePrivate *>(d);
         dd->provider = new QQuickImageTextureProvider;
         dd->provider->m_smooth = d->smooth;
-        dd->provider->m_texture = d->sceneGraphContext()->textureForFactory(d->pix.textureFactory());
+        dd->provider->m_texture = d->sceneGraphContext()->textureForFactory(d->pix.textureFactory(), canvas());
     }
 
     return d->provider;
@@ -554,7 +558,7 @@ QSGNode *QQuickImage::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
 {
     Q_D(QQuickImage);
 
-    QSGTexture *texture = d->sceneGraphContext()->textureForFactory(d->pix.textureFactory());
+    QSGTexture *texture = d->sceneGraphContext()->textureForFactory(d->pix.textureFactory(), canvas());
 
     // Copy over the current texture state into the texture provider...
     if (d->provider) {