aboutsummaryrefslogtreecommitdiffstats
path: root/src/declarative/items/context2d/qsgcanvasitem.cpp
diff options
context:
space:
mode:
authorCharles Yin <charles.yin@nokia.com>2011-10-04 17:12:12 +1000
committerQt by Nokia <qt-info@nokia.com>2011-10-06 02:40:52 +0200
commitfdc87143eb9eff98938b6a086c3e81432be08e4d (patch)
tree088aa464d7fd464281b7fbd8ee8b09fc1298844a /src/declarative/items/context2d/qsgcanvasitem.cpp
parent8a1b17f80c131a2bf6681070db43604029b3a8c0 (diff)
Add more unit tests for qsgcanvasitem and fix unstable tests
Change-Id:I5fc11a5874d55ad423dc1fb9c3e1b75a38003465 Reviewed-on: http://codereview.qt-project.org/5962 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Charles Yin <charles.yin@nokia.com>
Diffstat (limited to 'src/declarative/items/context2d/qsgcanvasitem.cpp')
-rw-r--r--src/declarative/items/context2d/qsgcanvasitem.cpp33
1 files changed, 19 insertions, 14 deletions
diff --git a/src/declarative/items/context2d/qsgcanvasitem.cpp b/src/declarative/items/context2d/qsgcanvasitem.cpp
index 50cbc7e2f1..6b0b438ddb 100644
--- a/src/declarative/items/context2d/qsgcanvasitem.cpp
+++ b/src/declarative/items/context2d/qsgcanvasitem.cpp
@@ -85,7 +85,7 @@ QSGCanvasItemPrivate::QSGCanvasItemPrivate()
, hasTileSize(false)
, hasCanvasWindow(false)
, componentCompleted(false)
- , renderTarget(QSGCanvasItem::Image)
+ , renderTarget(QSGCanvasItem::FramebufferObject)
{
}
@@ -512,7 +512,9 @@ void QSGCanvasItem::createContext()
QDeclarativeV8Handle QSGCanvasItem::getContext(const QString &contextId)
{
Q_D(QSGCanvasItem);
- Q_UNUSED(contextId);
+
+ if (contextId.toLower() != QLatin1String("2d"))
+ return QDeclarativeV8Handle::fromHandle(v8::Undefined());
if (!d->context)
createContext();
@@ -552,7 +554,9 @@ void QSGCanvasItem::markDirty(const QRectF& region)
*/
bool QSGCanvasItem::save(const QString &filename) const
{
- return toImage().save(filename);
+ Q_D(const QSGCanvasItem);
+ QUrl url = d->baseUrl.resolved(QUrl::fromLocalFile(filename));
+ return toImage().save(url.toLocalFile());
}
QImage QSGCanvasItem::loadedImage(const QUrl& url)
@@ -683,24 +687,25 @@ QString QSGCanvasItem::toDataURL(const QString& mimeType) const
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
- QString mime = mimeType;
+ QString mime = mimeType.toLower();
QString type;
- if (mimeType == QLatin1Literal("image/bmp"))
+ if (mime == QLatin1Literal("image/png")) {
+ type = QLatin1Literal("PNG");
+ } else if (mime == QLatin1Literal("image/bmp"))
type = QLatin1Literal("BMP");
- else if (mimeType == QLatin1Literal("image/jpeg"))
+ else if (mime == QLatin1Literal("image/jpeg"))
type = QLatin1Literal("JPEG");
- else if (mimeType == QLatin1Literal("image/x-portable-pixmap"))
+ else if (mime == QLatin1Literal("image/x-portable-pixmap"))
type = QLatin1Literal("PPM");
- else if (mimeType == QLatin1Literal("image/tiff"))
+ else if (mime == QLatin1Literal("image/tiff"))
type = QLatin1Literal("TIFF");
- else if (mimeType == QLatin1Literal("image/xbm"))
+ else if (mime == QLatin1Literal("image/xbm"))
type = QLatin1Literal("XBM");
- else if (mimeType == QLatin1Literal("image/xpm"))
+ else if (mime == QLatin1Literal("image/xpm"))
type = QLatin1Literal("XPM");
- else {
- type = QLatin1Literal("PNG");
- mime = QLatin1Literal("image/png");
- }
+ else
+ return QLatin1Literal("data:,");
+
image.save(&buffer, type.toAscii());
buffer.close();
QString dataUrl = QLatin1Literal("data:%1;base64,%2");