aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick
diff options
context:
space:
mode:
Diffstat (limited to 'src/quick')
-rw-r--r--src/quick/items/qquickanimatedimage.cpp2
-rw-r--r--src/quick/items/qquickborderimage.cpp2
-rw-r--r--src/quick/items/qquickcanvas.cpp4
-rw-r--r--src/quick/items/qquickimage.cpp4
-rw-r--r--src/quick/items/qquickitem.cpp11
-rw-r--r--src/quick/items/qquickitem.h1
-rw-r--r--src/quick/items/qquickrectangle.cpp5
-rw-r--r--src/quick/items/qquickrectangle_p.h1
-rw-r--r--src/quick/items/qquickshadereffect.cpp2
-rw-r--r--src/quick/qtquick2.cpp8
-rw-r--r--src/quick/scenegraph/qsgcontext.cpp1
-rw-r--r--src/quick/scenegraph/qsgcontextplugin_p.h3
-rw-r--r--src/quick/util/qquickanimation.cpp43
-rw-r--r--src/quick/util/qquickapplication.cpp124
-rw-r--r--src/quick/util/qquickapplication_p.h86
-rw-r--r--src/quick/util/qquickglobal.cpp530
-rw-r--r--src/quick/util/qquickimageprovider.cpp342
-rw-r--r--src/quick/util/qquickimageprovider.h91
-rw-r--r--src/quick/util/qquickpixmapcache.cpp59
-rw-r--r--src/quick/util/qquickpixmapcache_p.h2
-rw-r--r--src/quick/util/qquickvaluetypes.cpp468
-rw-r--r--src/quick/util/qquickvaluetypes_p.h310
-rw-r--r--src/quick/util/util.pri11
23 files changed, 2042 insertions, 68 deletions
diff --git a/src/quick/items/qquickanimatedimage.cpp b/src/quick/items/qquickanimatedimage.cpp
index 6567892fb4..9319cf1252 100644
--- a/src/quick/items/qquickanimatedimage.cpp
+++ b/src/quick/items/qquickanimatedimage.cpp
@@ -95,7 +95,7 @@ QT_BEGIN_NAMESPACE
AnimatedImage can handle any image format supported by Qt, loaded from any
URL scheme supported by Qt.
- \sa QQmlImageProvider
+ \sa QQuickImageProvider
*/
/*!
diff --git a/src/quick/items/qquickborderimage.cpp b/src/quick/items/qquickborderimage.cpp
index 71514593a3..b99a2f4cae 100644
--- a/src/quick/items/qquickborderimage.cpp
+++ b/src/quick/items/qquickborderimage.cpp
@@ -257,7 +257,7 @@ QQuickBorderImage::~QQuickBorderImage()
The URL may be absolute, or relative to the URL of the component.
- \sa QQmlImageProvider
+ \sa QQuickImageProvider
*/
/*!
diff --git a/src/quick/items/qquickcanvas.cpp b/src/quick/items/qquickcanvas.cpp
index 0748dad8ed..a288531beb 100644
--- a/src/quick/items/qquickcanvas.cpp
+++ b/src/quick/items/qquickcanvas.cpp
@@ -1824,7 +1824,7 @@ void QQuickCanvasPrivate::updateDirtyNode(QQuickItem *item)
if (item->clip()) {
Q_ASSERT(itemPriv->clipNode() == 0);
- itemPriv->extra.value().clipNode = new QQuickDefaultClipNode(item->boundingRect());
+ itemPriv->extra.value().clipNode = new QQuickDefaultClipNode(item->clipRect());
itemPriv->clipNode()->update();
if (child)
@@ -1916,7 +1916,7 @@ void QQuickCanvasPrivate::updateDirtyNode(QQuickItem *item)
}
if ((dirty & QQuickItemPrivate::Size) && itemPriv->clipNode()) {
- itemPriv->clipNode()->setRect(item->boundingRect());
+ itemPriv->clipNode()->setRect(item->clipRect());
itemPriv->clipNode()->update();
}
diff --git a/src/quick/items/qquickimage.cpp b/src/quick/items/qquickimage.cpp
index 2346689178..64c8ba1e55 100644
--- a/src/quick/items/qquickimage.cpp
+++ b/src/quick/items/qquickimage.cpp
@@ -147,7 +147,7 @@ QQuickImagePrivate::QQuickImagePrivate()
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}, QQmlImageProvider
+ \sa {declarative/imageelements/image}{Image example}, QQuickImageProvider
*/
QQuickImage::QQuickImage(QQuickItem *parent)
@@ -431,7 +431,7 @@ qreal QQuickImage::paintedHeight() const
The URL may be absolute, or relative to the URL of the component.
- \sa QQmlImageProvider
+ \sa QQuickImageProvider
*/
/*!
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp
index c5a2b447fc..ffaec540a2 100644
--- a/src/quick/items/qquickitem.cpp
+++ b/src/quick/items/qquickitem.cpp
@@ -3777,13 +3777,20 @@ void QQuickItem::updateInputMethod(Qt::InputMethodQueries queries)
/*! \internal */
// XXX todo - do we want/need this anymore?
-// Note that it's now used for varying clip rect
QRectF QQuickItem::boundingRect() const
{
Q_D(const QQuickItem);
return QRectF(0, 0, d->width, d->height);
}
+/*! \internal */
+QRectF QQuickItem::clipRect() const
+{
+ Q_D(const QQuickItem);
+ return QRectF(0, 0, d->width, d->height);
+}
+
+
QQuickItem::TransformOrigin QQuickItem::transformOrigin() const
{
Q_D(const QQuickItem);
@@ -6001,7 +6008,7 @@ void QQuickItemLayer::updateGeometry()
{
QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
Q_ASSERT(l);
- QRectF bounds = m_item->boundingRect();
+ QRectF bounds = m_item->clipRect();
l->setWidth(bounds.width());
l->setHeight(bounds.height());
l->setX(bounds.x() + m_item->x());
diff --git a/src/quick/items/qquickitem.h b/src/quick/items/qquickitem.h
index 39f3fd1aea..16dee80380 100644
--- a/src/quick/items/qquickitem.h
+++ b/src/quick/items/qquickitem.h
@@ -266,6 +266,7 @@ public:
void setFlags(Flags flags);
virtual QRectF boundingRect() const;
+ virtual QRectF clipRect() const;
bool hasActiveFocus() const;
bool hasFocus() const;
diff --git a/src/quick/items/qquickrectangle.cpp b/src/quick/items/qquickrectangle.cpp
index 062df127b3..13c101d8a2 100644
--- a/src/quick/items/qquickrectangle.cpp
+++ b/src/quick/items/qquickrectangle.cpp
@@ -553,4 +553,9 @@ QRectF QQuickRectangle::boundingRect() const
d->width + 2 * d->penMargin, d->height + 2 * d->penMargin);
}
+QRectF QQuickRectangle::clipRect() const
+{
+ return QQuickRectangle::boundingRect();
+}
+
QT_END_NAMESPACE
diff --git a/src/quick/items/qquickrectangle_p.h b/src/quick/items/qquickrectangle_p.h
index eec2b56fd3..52aa9e81f9 100644
--- a/src/quick/items/qquickrectangle_p.h
+++ b/src/quick/items/qquickrectangle_p.h
@@ -159,6 +159,7 @@ public:
void setRadius(qreal radius);
virtual QRectF boundingRect() const;
+ virtual QRectF clipRect() const;
Q_SIGNALS:
void colorChanged();
diff --git a/src/quick/items/qquickshadereffect.cpp b/src/quick/items/qquickshadereffect.cpp
index 871e319380..1549057ef8 100644
--- a/src/quick/items/qquickshadereffect.cpp
+++ b/src/quick/items/qquickshadereffect.cpp
@@ -244,7 +244,7 @@ void QQuickShaderEffectCommon::connectPropertySignals(QQuickItem *item, Key::Sha
if (!mp.hasNotifySignal())
qWarning("QQuickShaderEffect: property '%s' does not have notification method!", d.name.constData());
QByteArray signalName("2");
- signalName.append(mp.notifySignal().signature());
+ signalName.append(mp.notifySignal().methodSignature());
QSignalMapper *mapper = signalMappers[shaderType].at(i);
QObject::connect(item, signalName, mapper, SLOT(map()));
QObject::connect(mapper, SIGNAL(mapped(int)), item, SLOT(propertyChanged(int)));
diff --git a/src/quick/qtquick2.cpp b/src/quick/qtquick2.cpp
index 3e04a12d58..8a0c05618a 100644
--- a/src/quick/qtquick2.cpp
+++ b/src/quick/qtquick2.cpp
@@ -42,13 +42,14 @@
#include "qtquick2_p.h"
#include <private/qqmlengine_p.h>
#include <private/qquickutilmodule_p.h>
-#include <private/qqmlvaluetype_p.h>
+#include <private/qquickvaluetypes_p.h>
#include <private/qquickitemsmodule_p.h>
#include <private/qqmlenginedebugservice_p.h>
#include <private/qqmldebugstatesdelegate_p.h>
#include <private/qqmlbinding_p.h>
#include <private/qqmlcontext_p.h>
+#include <private/qquickapplication_p.h>
#include <QtQuick/private/qquickpropertychanges_p.h>
#include <QtQuick/private/qquickstate_p.h>
#include <qqmlproperty.h>
@@ -173,7 +174,10 @@ void QQmlQtQuick2Module::defineModule()
QQuickUtilModule::defineModule();
QQmlEnginePrivate::defineModule();
QQuickItemsModule::defineModule();
- QQmlValueTypeFactory::registerValueTypes();
+
+ qmlRegisterUncreatableType<QQuickApplication>("QtQuick",2,0,"Application", QQuickApplication::tr("Application is an abstract class"));
+
+ QQuickValueTypes::registerValueTypes();
if (QQmlEngineDebugService::isDebuggingEnabled()) {
QQmlEngineDebugService::instance()->setStatesDelegate(
diff --git a/src/quick/scenegraph/qsgcontext.cpp b/src/quick/scenegraph/qsgcontext.cpp
index 8b632661c5..da1c8e6ee9 100644
--- a/src/quick/scenegraph/qsgcontext.cpp
+++ b/src/quick/scenegraph/qsgcontext.cpp
@@ -56,7 +56,6 @@
#include <QOpenGLContext>
#include <QtGui/qopenglframebufferobject.h>
-#include <QQmlImageProvider>
#include <private/qqmlglobal_p.h>
#include <QtQuick/private/qsgtexture_p.h>
diff --git a/src/quick/scenegraph/qsgcontextplugin_p.h b/src/quick/scenegraph/qsgcontextplugin_p.h
index cc7761a095..2c4531c239 100644
--- a/src/quick/scenegraph/qsgcontextplugin_p.h
+++ b/src/quick/scenegraph/qsgcontextplugin_p.h
@@ -43,11 +43,10 @@
#define QSGCONTEXTPLUGIN_H
#include <QtQuick/qtquickglobal.h>
+#include <QtQuick/qquickimageprovider.h>
#include <QtCore/qplugin.h>
#include <QtCore/qfactoryinterface.h>
-#include <QQmlImageProvider>
-
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
diff --git a/src/quick/util/qquickanimation.cpp b/src/quick/util/qquickanimation.cpp
index 6b51ac596c..badbf51240 100644
--- a/src/quick/util/qquickanimation.cpp
+++ b/src/quick/util/qquickanimation.cpp
@@ -1766,38 +1766,19 @@ void QQuickPropertyAnimationPrivate::convertVariant(QVariant &variant, int type)
}
switch (type) {
- case QVariant::Rect: {
- variant.setValue(QQmlStringConverters::rectFFromString(variant.toString()).toRect());
- break;
- }
- case QVariant::RectF: {
- variant.setValue(QQmlStringConverters::rectFFromString(variant.toString()));
- break;
- }
- case QVariant::Point: {
- variant.setValue(QQmlStringConverters::pointFFromString(variant.toString()).toPoint());
- break;
- }
- case QVariant::PointF: {
- variant.setValue(QQmlStringConverters::pointFFromString(variant.toString()));
- break;
- }
- case QVariant::Size: {
- variant.setValue(QQmlStringConverters::sizeFFromString(variant.toString()).toSize());
- break;
- }
- case QVariant::SizeF: {
- variant.setValue(QQmlStringConverters::sizeFFromString(variant.toString()));
- break;
- }
- case QVariant::Color: {
- variant.setValue(QQmlStringConverters::colorFromString(variant.toString()));
- break;
- }
- case QVariant::Vector3D: {
- variant.setValue(QQmlStringConverters::vector3DFromString(variant.toString()));
+ case QVariant::Rect:
+ case QVariant::RectF:
+ case QVariant::Point:
+ case QVariant::PointF:
+ case QVariant::Size:
+ case QVariant::SizeF:
+ case QVariant::Color:
+ case QVariant::Vector3D:
+ {
+ bool ok = false;
+ variant = QQmlStringConverters::variantFromString(variant.toString(), type, &ok);
+ }
break;
- }
default:
if (QQmlValueTypeFactory::isValueType((uint)type)) {
variant.convert((QVariant::Type)type);
diff --git a/src/quick/util/qquickapplication.cpp b/src/quick/util/qquickapplication.cpp
new file mode 100644
index 0000000000..55ebb11d29
--- /dev/null
+++ b/src/quick/util/qquickapplication.cpp
@@ -0,0 +1,124 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtQuick module 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 "qquickapplication_p.h"
+
+#include <private/qobject_p.h>
+#include <QtGui/QGuiApplication>
+#include <QtCore/QDebug>
+
+QT_BEGIN_NAMESPACE
+
+class QQuickApplicationPrivate : public QObjectPrivate
+{
+ Q_DECLARE_PUBLIC(QQuickApplication)
+public:
+ QQuickApplicationPrivate()
+ : isActive(QGuiApplication::focusWindow() != 0),
+ direction(QGuiApplication::layoutDirection())
+ {
+ }
+
+private:
+ bool isActive;
+ Qt::LayoutDirection direction;
+};
+
+/*
+ This object and its properties are documented as part of the Qt object,
+ in qqmlengine.cpp
+*/
+
+QQuickApplication::QQuickApplication(QObject *parent)
+ : QObject(*new QQuickApplicationPrivate(), parent)
+{
+ if (qApp) {
+ qApp->installEventFilter(this);
+ }
+}
+
+QQuickApplication::~QQuickApplication()
+{
+}
+
+bool QQuickApplication::active() const
+{
+ Q_D(const QQuickApplication);
+ return d->isActive;
+}
+
+Qt::LayoutDirection QQuickApplication::layoutDirection() const
+{
+ Q_D(const QQuickApplication);
+ return d->direction;
+}
+
+QObject *QQuickApplication::inputPanel() const
+{
+ static bool warned = false;
+ if (!warned) {
+ qWarning() << "Qt.application.inputPanel is deprecated, use Qt.inputMethod instead";
+ warned = true;
+ }
+ return qGuiApp->inputMethod();
+}
+
+bool QQuickApplication::eventFilter(QObject *, QEvent *event)
+{
+ Q_D(QQuickApplication);
+ if ((event->type() == QEvent::ApplicationActivate) ||
+ (event->type() == QEvent::ApplicationDeactivate)) {
+ bool wasActive = d->isActive;
+ d->isActive = (event->type() == QEvent::ApplicationActivate);
+ if (d->isActive != wasActive) {
+ emit activeChanged();
+ }
+ } else if (event->type() == QEvent::LayoutDirectionChange) {
+ Qt::LayoutDirection newDirection = QGuiApplication::layoutDirection();
+ if (d->direction != newDirection) {
+ d->direction = newDirection;
+ emit layoutDirectionChanged();
+ }
+ }
+ return false;
+}
+
+QT_END_NAMESPACE
diff --git a/src/quick/util/qquickapplication_p.h b/src/quick/util/qquickapplication_p.h
new file mode 100644
index 0000000000..e8a3cd58ca
--- /dev/null
+++ b/src/quick/util/qquickapplication_p.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtQuick module 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 QQUICKAPPLICATION_P_H
+#define QQUICKAPPLICATION_P_H
+
+#include <QtCore/QObject>
+#include <qqml.h>
+#include <private/qtquickglobal_p.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+
+class QQuickApplicationPrivate;
+class Q_QUICK_PRIVATE_EXPORT QQuickApplication : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(bool active READ active NOTIFY activeChanged)
+ Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection NOTIFY layoutDirectionChanged)
+ Q_PROPERTY(QObject *inputPanel READ inputPanel CONSTANT)
+
+public:
+ explicit QQuickApplication(QObject *parent = 0);
+ virtual ~QQuickApplication();
+ bool active() const;
+ Qt::LayoutDirection layoutDirection() const;
+ QT_DEPRECATED QObject *inputPanel() const;
+
+Q_SIGNALS:
+ void activeChanged();
+ void layoutDirectionChanged();
+
+private:
+ bool eventFilter(QObject *, QEvent *event);
+
+ Q_DISABLE_COPY(QQuickApplication)
+ Q_DECLARE_PRIVATE(QQuickApplication)
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QQuickApplication)
+
+QT_END_HEADER
+
+#endif // QQUICKAPPLICATION_P_H
diff --git a/src/quick/util/qquickglobal.cpp b/src/quick/util/qquickglobal.cpp
new file mode 100644
index 0000000000..b99cb7a1d4
--- /dev/null
+++ b/src/quick/util/qquickglobal.cpp
@@ -0,0 +1,530 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtQml module 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 <private/qquickvaluetypes_p.h>
+#include <private/qquickapplication_p.h>
+#include <private/qqmlglobal_p.h>
+
+#include <QtGui/QGuiApplication>
+#include <QtGui/qdesktopservices.h>
+#include <QtGui/qfontdatabase.h>
+
+
+QT_BEGIN_NAMESPACE
+
+class QQuickColorProvider : public QQmlColorProvider
+{
+public:
+ static inline QColor QColorFromString(const QString &s)
+ {
+ // Should we also handle #rrggbb here?
+ if (s.length() == 9 && s.startsWith(QLatin1Char('#'))) {
+ uchar a = fromHex(s, 1);
+ uchar r = fromHex(s, 3);
+ uchar g = fromHex(s, 5);
+ uchar b = fromHex(s, 7);
+ return QColor(r, g, b, a);
+ }
+
+ return QColor(s);
+ }
+
+ QVariant colorFromString(const QString &s, bool *ok)
+ {
+ QColor c(QColorFromString(s));
+ if (c.isValid()) {
+ if (ok) *ok = true;
+ return QVariant(c);
+ }
+
+ if (ok) *ok = false;
+ return QVariant();
+ }
+
+ unsigned rgbaFromString(const QString &s, bool *ok)
+ {
+ QColor c(QColorFromString(s));
+ if (c.isValid()) {
+ if (ok) *ok = true;
+ return c.rgba();
+ }
+
+ if (ok) *ok = false;
+ return 0;
+ }
+
+ QString stringFromRgba(unsigned rgba)
+ {
+ QColor c(QColor::fromRgba(rgba));
+ if (c.isValid()) {
+ return QVariant(c).toString();
+ }
+
+ return QString();
+ }
+
+ QVariant fromRgbF(double r, double g, double b, double a)
+ {
+ return QVariant(QColor::fromRgbF(r, g, b, a));
+ }
+
+ QVariant fromHslF(double h, double s, double l, double a)
+ {
+ return QVariant(QColor::fromHslF(h, s, l, a));
+ }
+
+ QVariant lighter(const QVariant &var, qreal factor)
+ {
+ QColor color = var.value<QColor>();
+ color = color.lighter(int(qRound(factor*100.)));
+ return QVariant::fromValue(color);
+ }
+
+ QVariant darker(const QVariant &var, qreal factor)
+ {
+ QColor color = var.value<QColor>();
+ color = color.darker(int(qRound(factor*100.)));
+ return QVariant::fromValue(color);
+ }
+
+ QVariant tint(const QVariant &baseVar, const QVariant &tintVar)
+ {
+ QColor tintColor = tintVar.value<QColor>();
+
+ int tintAlpha = tintColor.alpha();
+ if (tintAlpha == 0xFF) {
+ return tintVar;
+ } else if (tintAlpha == 0x00) {
+ return baseVar;
+ }
+
+ // tint the base color and return the final color
+ QColor baseColor = baseVar.value<QColor>();
+ qreal a = tintColor.alphaF();
+ qreal inv_a = 1.0 - a;
+
+ qreal r = tintColor.redF() * a + baseColor.redF() * inv_a;
+ qreal g = tintColor.greenF() * a + baseColor.greenF() * inv_a;
+ qreal b = tintColor.blueF() * a + baseColor.blueF() * inv_a;
+
+ return QVariant::fromValue(QColor::fromRgbF(r, g, b, a + inv_a * baseColor.alphaF()));
+ }
+
+private:
+ static uchar fromHex(const uchar c, const uchar c2)
+ {
+ uchar rv = 0;
+ if (c >= '0' && c <= '9')
+ rv += (c - '0') * 16;
+ else if (c >= 'A' && c <= 'F')
+ rv += (c - 'A' + 10) * 16;
+ else if (c >= 'a' && c <= 'f')
+ rv += (c - 'a' + 10) * 16;
+
+ if (c2 >= '0' && c2 <= '9')
+ rv += (c2 - '0');
+ else if (c2 >= 'A' && c2 <= 'F')
+ rv += (c2 - 'A' + 10);
+ else if (c2 >= 'a' && c2 <= 'f')
+ rv += (c2 - 'a' + 10);
+
+ return rv;
+ }
+
+ static inline uchar fromHex(const QString &s, int idx)
+ {
+ uchar c = s.at(idx).toAscii();
+ uchar c2 = s.at(idx + 1).toAscii();
+ return fromHex(c, c2);
+ }
+};
+
+
+class QQuickValueTypeProvider : public QQmlValueTypeProvider
+{
+public:
+ static QVector3D vector3DFromString(const QString &s, bool *ok)
+ {
+ if (s.count(QLatin1Char(',')) == 2) {
+ int index = s.indexOf(QLatin1Char(','));
+ int index2 = s.indexOf(QLatin1Char(','), index+1);
+
+ bool xGood, yGood, zGood;
+ qreal xCoord = s.left(index).toDouble(&xGood);
+ qreal yCoord = s.mid(index+1, index2-index-1).toDouble(&yGood);
+ qreal zCoord = s.mid(index2+1).toDouble(&zGood);
+
+ if (xGood && yGood && zGood) {
+ if (ok) *ok = true;
+ return QVector3D(xCoord, yCoord, zCoord);
+ }
+ }
+
+ if (ok) *ok = false;
+ return QVector3D();
+ }
+
+ static QVector4D vector4DFromString(const QString &s, bool *ok)
+ {
+ if (s.count(QLatin1Char(',')) == 3) {
+ int index = s.indexOf(QLatin1Char(','));
+ int index2 = s.indexOf(QLatin1Char(','), index+1);
+ int index3 = s.indexOf(QLatin1Char(','), index2+1);
+
+ bool xGood, yGood, zGood, wGood;
+ qreal xCoord = s.left(index).toDouble(&xGood);
+ qreal yCoord = s.mid(index+1, index2-index-1).toDouble(&yGood);
+ qreal zCoord = s.mid(index2+1, index3-index2-1).toDouble(&zGood);
+ qreal wCoord = s.mid(index3+1).toDouble(&wGood);
+
+ if (xGood && yGood && zGood && wGood) {
+ if (ok) *ok = true;
+ return QVector4D(xCoord, yCoord, zCoord, wCoord);
+ }
+ }
+
+ if (ok) *ok = false;
+ return QVector4D();
+ }
+
+ bool create(int type, QQmlValueType *&v)
+ {
+ switch (type) {
+ case QMetaType::QColor:
+ v = new QQuickColorValueType;
+ return true;
+ case QMetaType::QVector2D:
+ v = new QQuickVector2DValueType;
+ return true;
+ case QMetaType::QVector3D:
+ v = new QQuickVector3DValueType;
+ return true;
+ case QMetaType::QVector4D:
+ v = new QQuickVector4DValueType;
+ return true;
+ case QMetaType::QQuaternion:
+ v = new QQuickQuaternionValueType;
+ return true;
+ case QMetaType::QMatrix4x4:
+ v = new QQuickMatrix4x4ValueType;
+ return true;
+ case QMetaType::QFont:
+ v = new QQuickFontValueType;
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ bool init(int type, void *data, size_t n)
+ {
+ if (type == QMetaType::QColor) {
+ Q_ASSERT(n >= sizeof(QColor));
+ QColor *color = reinterpret_cast<QColor *>(data);
+ new (color) QColor();
+ return true;
+ }
+
+ return false;
+ }
+
+ bool destroy(int type, void *data, size_t n)
+ {
+ if (type == QMetaType::QColor) {
+ Q_ASSERT(n >= sizeof(QColor));
+ QColor *color = reinterpret_cast<QColor *>(data);
+ color->~QColor();
+ return true;
+ }
+
+ return false;
+ }
+
+ bool copy(int type, const void *src, void *dst, size_t n)
+ {
+ if (type == QMetaType::QColor) {
+ Q_ASSERT(n >= sizeof(QColor));
+ const QColor *srcColor = reinterpret_cast<const QColor *>(src);
+ QColor *dstColor = reinterpret_cast<QColor *>(dst);
+ new (dstColor) QColor(*srcColor);
+ return true;
+ }
+
+ return false;
+ }
+
+ bool create(int type, int argc, const void *argv[], QVariant *v)
+ {
+ switch (type) {
+ case QMetaType::QVector3D:
+ if (argc == 1) {
+ const float *xyz = reinterpret_cast<const float*>(argv[0]);
+ QVector3D v3(xyz[0], xyz[1], xyz[2]);
+ *v = QVariant(v3);
+ return true;
+ }
+ break;
+ case QMetaType::QVector4D:
+ if (argc == 1) {
+ const float *xyzw = reinterpret_cast<const float*>(argv[0]);
+ QVector4D v4(xyzw[0], xyzw[1], xyzw[2], xyzw[3]);
+ *v = QVariant(v4);
+ return true;
+ }
+ break;
+ }
+
+ return false;
+ }
+
+ bool createFromString(int type, const QString &s, void *data, size_t n)
+ {
+ bool ok = false;
+
+ switch (type) {
+ case QMetaType::QColor:
+ {
+ Q_ASSERT(n >= sizeof(QColor));
+ QColor *color = reinterpret_cast<QColor *>(data);
+ new (color) QColor(QQuickColorProvider::QColorFromString(s));
+ return true;
+ }
+ case QMetaType::QVector3D:
+ {
+ Q_ASSERT(n >= sizeof(QVector3D));
+ QVector3D *v3 = reinterpret_cast<QVector3D *>(data);
+ new (v3) QVector3D(vector3DFromString(s, &ok));
+ return true;
+ }
+ case QMetaType::QVector4D:
+ {
+ Q_ASSERT(n >= sizeof(QVector4D));
+ QVector4D *v4 = reinterpret_cast<QVector4D *>(data);
+ new (v4) QVector4D(vector4DFromString(s, &ok));
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ bool createStringFrom(int type, const void *data, QString *s)
+ {
+ if (type == QMetaType::QColor) {
+ const QColor *color = reinterpret_cast<const QColor *>(data);
+ new (s) QString(QVariant(*color).toString());
+ return true;
+ }
+
+ return false;
+ }
+
+ bool variantFromString(const QString &s, QVariant *v)
+ {
+ QColor c(QQuickColorProvider::QColorFromString(s));
+ if (c.isValid()) {
+ *v = QVariant::fromValue(c);
+ return true;
+ }
+
+ bool ok = false;
+
+ QVector3D v3 = vector3DFromString(s, &ok);
+ if (ok) {
+ *v = QVariant::fromValue(v3);
+ return true;
+ }
+
+ QVector4D v4 = vector4DFromString(s, &ok);
+ if (ok) {
+ *v = QVariant::fromValue(v4);
+ return true;
+ }
+
+ return false;
+ }
+
+ bool variantFromString(int type, const QString &s, QVariant *v)
+ {
+ bool ok = false;
+
+ switch (type) {
+ case QMetaType::QColor:
+ {
+ QColor c(QQuickColorProvider::QColorFromString(s));
+ *v = QVariant::fromValue(c);
+ return true;
+ }
+ case QMetaType::QVector3D:
+ *v = QVariant::fromValue(vector3DFromString(s, &ok));
+ return true;
+ case QMetaType::QVector4D:
+ *v = QVariant::fromValue(vector4DFromString(s, &ok));
+ return true;
+ }
+
+ return false;
+ }
+
+ bool store(int type, const void *src, void *dst, size_t n)
+ {
+ switch (type) {
+ case QMetaType::QColor:
+ {
+ Q_ASSERT(n >= sizeof(QColor));
+ const QRgb *rgb = reinterpret_cast<const QRgb *>(src);
+ QColor *color = reinterpret_cast<QColor *>(dst);
+ new (color) QColor(QColor::fromRgba(*rgb));
+ return true;
+ }
+ case QMetaType::QVector3D:
+ {
+ Q_ASSERT(n >= sizeof(QVector3D));
+ const QVector3D *srcVector = reinterpret_cast<const QVector3D *>(src);
+ QVector3D *dstVector = reinterpret_cast<QVector3D *>(dst);
+ new (dstVector) QVector3D(*srcVector);
+ return true;
+ }
+ case QMetaType::QVector4D:
+ {
+ Q_ASSERT(n >= sizeof(QVector4D));
+ const QVector4D *srcVector = reinterpret_cast<const QVector4D *>(src);
+ QVector4D *dstVector = reinterpret_cast<QVector4D *>(dst);
+ new (dstVector) QVector4D(*srcVector);
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ bool read(int srcType, const void *src, int dstType, void *dst)
+ {
+ if (dstType == QMetaType::QColor) {
+ QColor *dstColor = reinterpret_cast<QColor *>(dst);
+ if (srcType == QMetaType::QColor) {
+ const QColor *srcColor = reinterpret_cast<const QColor *>(src);
+ *dstColor = *srcColor;
+ } else {
+ *dstColor = QColor();
+ }
+ return true;
+ }
+
+ return false;
+ }
+
+ bool write(int type, const void *src, void *dst, size_t n)
+ {
+ if (type == QMetaType::QColor) {
+ Q_ASSERT(n >= sizeof(QColor));
+ const QColor *srcColor = reinterpret_cast<const QColor *>(src);
+ QColor *dstColor = reinterpret_cast<QColor *>(dst);
+ if (*dstColor != *srcColor) {
+ *dstColor = *srcColor;
+ return true;
+ }
+ }
+
+ return false;
+ }
+};
+
+
+class QQuickGuiProvider : public QQmlGuiProvider
+{
+public:
+ QQuickApplication *application(QObject *parent)
+ {
+ return new QQuickApplication(parent);
+ }
+
+ QInputMethod *inputMethod()
+ {
+ return qGuiApp->inputMethod();
+ }
+
+ QStringList fontFamilies()
+ {
+ QFontDatabase database;
+ return database.families();
+ }
+
+ bool openUrlExternally(QUrl &url)
+ {
+#ifndef QT_NO_DESKTOPSERVICES
+ return QDesktopServices::openUrl(url);
+#else
+ return false;
+#endif
+ }
+};
+
+
+static QQuickValueTypeProvider *getValueTypeProvider()
+{
+ static QQuickValueTypeProvider valueTypeProvider;
+ return &valueTypeProvider;
+}
+
+static QQuickColorProvider *getColorProvider()
+{
+ static QQuickColorProvider colorProvider;
+ return &colorProvider;
+}
+
+static QQuickGuiProvider *getGuiProvider()
+{
+ static QQuickGuiProvider guiProvider;
+ return &guiProvider;
+}
+
+static bool initializeProviders()
+{
+ QQml_addValueTypeProvider(getValueTypeProvider());
+ QQml_setColorProvider(getColorProvider());
+ QQml_setGuiProvider(getGuiProvider());
+ return true;
+}
+
+static bool initialized = initializeProviders();
+
+QT_END_NAMESPACE
diff --git a/src/quick/util/qquickimageprovider.cpp b/src/quick/util/qquickimageprovider.cpp
new file mode 100644
index 0000000000..b306ab3419
--- /dev/null
+++ b/src/quick/util/qquickimageprovider.cpp
@@ -0,0 +1,342 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtQml module 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 "qquickimageprovider.h"
+
+QT_BEGIN_NAMESPACE
+
+class QQuickImageProviderPrivate
+{
+public:
+ QQuickImageProvider::ImageType type;
+};
+
+/*!
+ \class QQuickTextureFactory
+ \since 5.0
+ \brief The QQuickTextureFactory class provides an interface for loading custom textures from QML.
+ \inmodule QtQml
+
+ The purpose of the texture factory is to provide a placeholder for a image
+ data that can be converted into an OpenGL texture.
+
+ Creating a texture directly is not possible as there is rarely an OpenGL context
+ available in the thread that is responsible for loading the image data.
+ */
+
+QQuickTextureFactory::QQuickTextureFactory()
+{
+}
+
+QQuickTextureFactory::~QQuickTextureFactory()
+{
+}
+
+
+/*!
+ \fn QImage QQuickTextureFactory::image() const
+
+ Returns an image version of this texture.
+
+ The lifespan of the returned image is unknown, so the implementation should
+ return a self contained QImage, not make use of the QImage(uchar *, ...)
+ constructor.
+
+ This function is not commonly used and is expected to be slow.
+ */
+
+QImage QQuickTextureFactory::image() const
+{
+ return QImage();
+}
+
+
+/*!
+ \fn QSGTexture *QQuickTextureFactory::createTexture() const
+
+ This function is called on the scene graph rendering thread to create a QSGTexture
+ instance from the factory.
+
+ QML will internally cache the returned texture as needed. Each call to this
+ function should return a unique instance.
+
+ The OpenGL context used for rendering is bound when this function is called.
+ */
+
+/*!
+ \fn QSize QQuickTextureFactory::textureSize() const
+
+ Returns the size of the texture. This function will be called from arbitrary threads
+ and should not rely on an OpenGL context bound.
+ */
+
+
+/*!
+ \class QQuickImageProvider
+ \since 5.0
+ \inmodule QtQuick
+ \brief The QQuickImageProvider class provides an interface for supporting pixmaps and threaded image requests in QML.
+
+ QQuickImageProvider is used to provide advanced image loading features
+ in QML applications. It allows images in QML to be:
+
+ \list
+ \li Loaded using QPixmaps rather than actual image files
+ \li Loaded asynchronously in a separate thread, if imageType() is \l{QQmlImageProvider::ImageType}{ImageType::Image}
+ \endlist
+
+ To specify that an image should be loaded by an image provider, use the
+ \b {"image:"} scheme for the URL source of the image, followed by the
+ identifiers of the image provider and the requested image. For example:
+
+ \qml
+ Image { source: "image://myimageprovider/image.png" }
+ \endqml
+
+ This specifies that the image should be loaded by the image provider named
+ "myimageprovider", and the image to be loaded is named "image.png". The QML engine
+ invokes the appropriate image provider according to the providers that have
+ been registered through QQmlEngine::addImageProvider().
+
+ Note that the identifiers are case-insensitive, but the rest of the URL will be passed on with
+ preserved case. For example, the below snippet would still specify that the image is loaded by the
+ image provider named "myimageprovider", but it would request a different image than the above snippet
+ ("Image.png" instead of "image.png").
+ \qml
+ Image { source: "image://MyImageProvider/Image.png" }
+ \endqml
+
+ If you want the rest of the URL to be case insensitive, you will have to take care
+ of that yourself inside your image provider.
+
+ \section2 An example
+
+ Here are two images. Their \c source values indicate they should be loaded by
+ an image provider named "colors", and the images to be loaded are "yellow"
+ and "red", respectively:
+
+ \snippet examples/declarative/cppextensions/imageprovider/imageprovider-example.qml 0
+
+ When these images are loaded by QML, it looks for a matching image provider
+ and calls its requestImage() or requestPixmap() method (depending on its
+ imageType()) to load the image. The method is called with the \c id
+ parameter set to "yellow" for the first image, and "red" for the second.
+
+ Here is an image provider implementation that can load the images
+ requested by the above QML. This implementation dynamically
+ generates QPixmap images that are filled with the requested color:
+
+ \snippet examples/declarative/cppextensions/imageprovider/imageprovider.cpp 0
+ \codeline
+ \snippet examples/declarative/cppextensions/imageprovider/imageprovider.cpp 1
+
+ To make this provider accessible to QML, it is registered with the QML engine
+ with a "colors" identifier:
+
+ \code
+ int main(int argc, char *argv[])
+ {
+ ...
+
+ QQmlEngine engine;
+ engine->addImageProvider(QLatin1String("colors"), new ColorPixmapProvider);
+
+ ...
+ }
+ \endcode
+
+ Now the images can be successfully loaded in QML:
+
+ \image imageprovider.png
+
+ A complete example is available in Qt's
+ \l {declarative/cppextensions/imageprovider}{examples/declarative/cppextensions/imageprovider}
+ directory. Note the example registers the provider via a \l{QQmlExtensionPlugin}{plugin}
+ instead of registering it in the application \c main() function as shown above.
+
+
+ \section2 Asynchronous image loading
+
+ Image providers that support QImage loading automatically include support
+ for asychronous loading of images. To enable asynchronous loading for an
+ image source, set the \c asynchronous property to \c true for the relevant
+ \l Image, \l BorderImage or \l AnimatedImage object. When this is enabled,
+ the image request to the provider is run in a low priority thread,
+ allowing image loading to be executed in the background, and reducing the
+ performance impact on the user interface.
+
+ Asynchronous loading is not supported for image providers that provide
+ QPixmap rather than QImage values, as pixmaps can only be created in the
+ main thread. In this case, if \l {Image::}{asynchronous} is set to
+ \c true, the value is ignored and the image is loaded
+ synchronously.
+
+
+ \section2 Image caching
+
+ Images returned by a QQuickImageProvider are automatically cached,
+ similar to any image loaded by the QML engine. When an image with a
+ "image://" prefix is loaded from cache, requestImage() and requestPixmap()
+ will not be called for the relevant image provider. If an image should always
+ be fetched from the image provider, and should not be cached at all, set the
+ \c cache property to \c false for the relevant \l Image, \l BorderImage or
+ \l AnimatedImage object.
+
+ The QtQuick 1 version of this class is named QDeclarativeImageProvider.
+
+ \sa QQmlEngine::addImageProvider()
+*/
+
+/*!
+ Creates an image provider that will provide images of the given \a type.
+*/
+QQuickImageProvider::QQuickImageProvider(ImageType type)
+ : d(new QQuickImageProviderPrivate)
+{
+ d->type = type;
+}
+
+/*!
+ Destroys the QQuickImageProvider
+
+ \note The destructor of your derived class need to be thread safe.
+*/
+QQuickImageProvider::~QQuickImageProvider()
+{
+ delete d;
+}
+
+/*!
+ Returns the image type supported by this provider.
+*/
+QQuickImageProvider::ImageType QQuickImageProvider::imageType() const
+{
+ return d->type;
+}
+
+/*!
+ Implement this method to return the image with \a id. The default
+ implementation returns an empty image.
+
+ The \a id is the requested image source, with the "image:" scheme and
+ provider identifier removed. For example, if the image \l{Image::}{source}
+ was "image://myprovider/icons/home", the given \a id would be "icons/home".
+
+ The \a requestedSize corresponds to the \l {Image::sourceSize} requested by
+ an Image element. If \a requestedSize is a valid size, the image
+ returned should be of that size.
+
+ In all cases, \a size must be set to the original size of the image. This
+ is used to set the \l {Item::}{width} and \l {Item::}{height} of the
+ relevant \l Image if these values have not been set explicitly.
+
+ \note this method may be called by multiple threads, so ensure the
+ implementation of this method is reentrant.
+*/
+QImage QQuickImageProvider::requestImage(const QString &id, QSize *size, const QSize& requestedSize)
+{
+ Q_UNUSED(id);
+ Q_UNUSED(size);
+ Q_UNUSED(requestedSize);
+ if (d->type == Image)
+ qWarning("ImageProvider supports Image type but has not implemented requestImage()");
+ return QImage();
+}
+
+/*!
+ Implement this method to return the pixmap with \a id. The default
+ implementation returns an empty pixmap.
+
+ The \a id is the requested image source, with the "image:" scheme and
+ provider identifier removed. For example, if the image \l{Image::}{source}
+ was "image://myprovider/icons/home", the given \a id would be "icons/home".
+
+ The \a requestedSize corresponds to the \l {Image::sourceSize} requested by
+ an Image element. If \a requestedSize is a valid size, the image
+ returned should be of that size.
+
+ In all cases, \a size must be set to the original size of the image. This
+ is used to set the \l {Item::}{width} and \l {Item::}{height} of the
+ relevant \l Image if these values have not been set explicitly.
+*/
+QPixmap QQuickImageProvider::requestPixmap(const QString &id, QSize *size, const QSize& requestedSize)
+{
+ Q_UNUSED(id);
+ Q_UNUSED(size);
+ Q_UNUSED(requestedSize);
+ if (d->type == Pixmap)
+ qWarning("ImageProvider supports Pixmap type but has not implemented requestPixmap()");
+ return QPixmap();
+}
+
+
+/*!
+ Implement this method to return the texture with \a id. The default
+ implementation returns 0.
+
+ The \a id is the requested image source, with the "image:" scheme and
+ provider identifier removed. For example, if the image \l{Image::}{source}
+ was "image://myprovider/icons/home", the given \a id would be "icons/home".
+
+ The \a requestedSize corresponds to the \l {Image::sourceSize} requested by
+ an Image element. If \a requestedSize is a valid size, the image
+ returned should be of that size.
+
+ In all cases, \a size must be set to the original size of the image. This
+ is used to set the \l {Item::}{width} and \l {Item::}{height} of the
+ relevant \l Image if these values have not been set explicitly.
+
+ \note this method may be called by multiple threads, so ensure the
+ implementation of this method is reentrant.
+*/
+
+QQuickTextureFactory *QQuickImageProvider::requestTexture(const QString &id, QSize *size, const QSize &requestedSize)
+{
+ Q_UNUSED(id);
+ Q_UNUSED(size);
+ Q_UNUSED(requestedSize);
+ if (d->type == Texture)
+ qWarning("ImageProvider supports Texture type but has not implemented requestTexture()");
+ return 0;
+}
+
+QT_END_NAMESPACE
+
diff --git a/src/quick/util/qquickimageprovider.h b/src/quick/util/qquickimageprovider.h
new file mode 100644
index 0000000000..252d57b1d6
--- /dev/null
+++ b/src/quick/util/qquickimageprovider.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtQml module 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 QQUICKIMAGEPROVIDER_H
+#define QQUICKIMAGEPROVIDER_H
+
+#include <QtQuick/qtquickglobal.h>
+#include <QtGui/qimage.h>
+#include <QtGui/qpixmap.h>
+#include <QtQml/qqmlengine.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+
+class QQuickImageProviderPrivate;
+class QSGTexture;
+class QQuickCanvas;
+
+class Q_QUICK_EXPORT QQuickTextureFactory : public QObject
+{
+public:
+ QQuickTextureFactory();
+ virtual ~QQuickTextureFactory();
+
+ virtual QSGTexture *createTexture(QQuickCanvas *canvas) const = 0;
+ virtual QSize textureSize() const = 0;
+ virtual int textureByteCount() const = 0;
+ virtual QImage image() const;
+};
+
+class Q_QUICK_EXPORT QQuickImageProvider : public QQmlImageProviderBase
+{
+public:
+ QQuickImageProvider(ImageType type);
+ virtual ~QQuickImageProvider();
+
+ ImageType imageType() const;
+
+ virtual QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize);
+ virtual QPixmap requestPixmap(const QString &id, QSize *size, const QSize& requestedSize);
+ virtual QQuickTextureFactory *requestTexture(const QString &id, QSize *size, const QSize &requestedSize);
+
+private:
+ QQuickImageProviderPrivate *d;
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QQUICKIMAGEPROVIDER_H
diff --git a/src/quick/util/qquickpixmapcache.cpp b/src/quick/util/qquickpixmapcache.cpp
index 9185fba343..801b007cdd 100644
--- a/src/quick/util/qquickpixmapcache.cpp
+++ b/src/quick/util/qquickpixmapcache.cpp
@@ -41,7 +41,7 @@
#include "qquickpixmapcache_p.h"
#include <qqmlnetworkaccessmanagerfactory.h>
-#include <qqmlimageprovider.h>
+#include <qquickimageprovider.h>
#include <qqmlengine.h>
#include <private/qqmlglobal_p.h>
@@ -76,6 +76,16 @@ QT_BEGIN_NAMESPACE
// The cache limit describes the maximum "junk" in the cache.
static int cache_limit = 2048 * 1024; // 2048 KB cache limit for embedded in qpixmapcache.cpp
+static inline QString imageProviderId(const QUrl &url)
+{
+ return url.host();
+}
+
+static inline QString imageId(const QUrl &url)
+{
+ return url.toString(QUrl::RemoveScheme | QUrl::RemoveAuthority).mid(1);
+}
+
QSGTexture *QQuickDefaultTextureFactory::createTexture(QQuickCanvas *) const
{
QSGPlainTexture *t = new QSGPlainTexture();
@@ -502,11 +512,15 @@ void QQuickPixmapReader::processJob(QQuickPixmapReply *runningJob, const QUrl &u
{
// fetch
if (url.scheme() == QLatin1String("image")) {
- // Use QmlImageProvider
+ // Use QQuickImageProvider
QSize readSize;
- QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine);
- QQmlImageProvider::ImageType imageType = ep->getImageProviderType(url);
- if (imageType == QQmlImageProvider::Invalid) {
+
+ QQuickImageProvider::ImageType imageType = QQuickImageProvider::Invalid;
+ QQuickImageProvider *provider = static_cast<QQuickImageProvider *>(engine->imageProvider(imageProviderId(url)));
+ if (provider)
+ imageType = provider->imageType();
+
+ if (imageType == QQuickImageProvider::Invalid) {
QQuickPixmapReply::ReadError errorCode = QQuickPixmapReply::Loading;
QString errorStr = QQuickPixmap::tr("Invalid image provider: %1").arg(url.toString());
QImage image;
@@ -514,8 +528,8 @@ void QQuickPixmapReader::processJob(QQuickPixmapReply *runningJob, const QUrl &u
if (!cancelled.contains(runningJob))
runningJob->postReply(errorCode, errorStr, readSize, textureFactoryForImage(image));
mutex.unlock();
- } else if (imageType == QQmlImageProvider::Image) {
- QImage image = ep->getImageFromProvider(url, &readSize, requestSize);
+ } else if (imageType == QQuickImageProvider::Image) {
+ QImage image = provider->requestImage(imageId(url), &readSize, requestSize);
QQuickPixmapReply::ReadError errorCode = QQuickPixmapReply::NoError;
QString errorStr;
if (image.isNull()) {
@@ -527,7 +541,7 @@ void QQuickPixmapReader::processJob(QQuickPixmapReply *runningJob, const QUrl &u
runningJob->postReply(errorCode, errorStr, readSize, textureFactoryForImage(image));
mutex.unlock();
} else {
- QQuickTextureFactory *t = ep->getTextureFromProvider(url, &readSize, requestSize);
+ QQuickTextureFactory *t = provider->requestTexture(imageId(url), &readSize, requestSize);
QQuickPixmapReply::ReadError errorCode = QQuickPixmapReply::NoError;
QString errorStr;
if (!t) {
@@ -919,33 +933,36 @@ static QQuickPixmapData* createPixmapDataSync(QQuickPixmap *declarativePixmap, Q
{
if (url.scheme() == QLatin1String("image")) {
QSize readSize;
- QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine);
- QQmlImageProvider::ImageType imageType = ep->getImageProviderType(url);
+
+ QQuickImageProvider::ImageType imageType = QQuickImageProvider::Invalid;
+ QQuickImageProvider *provider = static_cast<QQuickImageProvider *>(engine->imageProvider(imageProviderId(url)));
+ if (provider)
+ imageType = provider->imageType();
switch (imageType) {
- case QQmlImageProvider::Invalid:
+ case QQuickImageProvider::Invalid:
return new QQuickPixmapData(declarativePixmap, url, requestSize,
QQuickPixmap::tr("Invalid image provider: %1").arg(url.toString()));
- case QQmlImageProvider::Texture:
+ case QQuickImageProvider::Texture:
{
- QQuickTextureFactory *texture = ep->getTextureFromProvider(url, &readSize, requestSize);
+ QQuickTextureFactory *texture = provider->requestTexture(imageId(url), &readSize, requestSize);
if (texture) {
*ok = true;
return new QQuickPixmapData(declarativePixmap, url, texture, readSize, requestSize);
}
}
- case QQmlImageProvider::Image:
+ case QQuickImageProvider::Image:
{
- QImage image = ep->getImageFromProvider(url, &readSize, requestSize);
+ QImage image = provider->requestImage(imageId(url), &readSize, requestSize);
if (!image.isNull()) {
*ok = true;
return new QQuickPixmapData(declarativePixmap, url, textureFactoryForImage(image), readSize, requestSize);
}
}
- case QQmlImageProvider::Pixmap:
+ case QQuickImageProvider::Pixmap:
{
- QPixmap pixmap = ep->getPixmapFromProvider(url, &readSize, requestSize);
+ QPixmap pixmap = provider->requestPixmap(imageId(url), &readSize, requestSize);
if (!pixmap.isNull()) {
*ok = true;
return new QQuickPixmapData(declarativePixmap, url, textureFactoryForImage(pixmap.toImage()), readSize, requestSize);
@@ -1152,9 +1169,11 @@ void QQuickPixmap::load(QQmlEngine *engine, const QUrl &url, const QSize &reques
if (iter == store->m_cache.end()) {
if (options & QQuickPixmap::Asynchronous) {
// pixmaps can only be loaded synchronously
- if (url.scheme() == QLatin1String("image")
- && QQmlEnginePrivate::get(engine)->getImageProviderType(url) == QQmlImageProvider::Pixmap) {
- options &= ~QQuickPixmap::Asynchronous;
+ if (url.scheme() == QLatin1String("image")) {
+ QQuickImageProvider *provider = static_cast<QQuickImageProvider *>(engine->imageProvider(imageProviderId(url)));
+ if (provider && provider->imageType() == QQuickImageProvider::Pixmap) {
+ options &= ~QQuickPixmap::Asynchronous;
+ }
}
}
diff --git a/src/quick/util/qquickpixmapcache_p.h b/src/quick/util/qquickpixmapcache_p.h
index b339e6f1a0..03f2e65cc2 100644
--- a/src/quick/util/qquickpixmapcache_p.h
+++ b/src/quick/util/qquickpixmapcache_p.h
@@ -47,9 +47,9 @@
#include <QtGui/qpixmap.h>
#include <QtCore/qurl.h>
#include <QtQuick/qtquickglobal.h>
+#include <QtQuick/qquickimageprovider.h>
#include <private/qintrusivelist_p.h>
-#include <qqmlimageprovider.h>
QT_BEGIN_HEADER
diff --git a/src/quick/util/qquickvaluetypes.cpp b/src/quick/util/qquickvaluetypes.cpp
new file mode 100644
index 0000000000..179f840acd
--- /dev/null
+++ b/src/quick/util/qquickvaluetypes.cpp
@@ -0,0 +1,468 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtQml module 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 <private/qquickvaluetypes_p.h>
+
+#include <qtquickglobal.h>
+#include <private/qqmlvaluetype_p.h>
+#include <private/qfont_p.h>
+
+
+QT_BEGIN_NAMESPACE
+
+namespace QQuickValueTypes {
+
+void registerValueTypes()
+{
+ QQmlValueTypeFactory::registerValueTypes();
+
+ qmlRegisterValueTypeEnums<QQuickFontValueType>("QtQuick", 2, 0, "Font");
+}
+
+}
+
+QQuickColorValueType::QQuickColorValueType(QObject *parent)
+ : QQmlValueTypeBase<QColor>(parent)
+{
+}
+
+QString QQuickColorValueType::toString() const
+{
+ // to maintain behaviour with QtQuick 1.0, we just output normal toString() value.
+ return QVariant(v).toString();
+}
+
+qreal QQuickColorValueType::r() const
+{
+ return v.redF();
+}
+
+qreal QQuickColorValueType::g() const
+{
+ return v.greenF();
+}
+
+qreal QQuickColorValueType::b() const
+{
+ return v.blueF();
+}
+
+qreal QQuickColorValueType::a() const
+{
+ return v.alphaF();
+}
+
+void QQuickColorValueType::setR(qreal r)
+{
+ v.setRedF(r);
+}
+
+void QQuickColorValueType::setG(qreal g)
+{
+ v.setGreenF(g);
+}
+
+void QQuickColorValueType::setB(qreal b)
+{
+ v.setBlueF(b);
+}
+
+void QQuickColorValueType::setA(qreal a)
+{
+ v.setAlphaF(a);
+}
+
+
+QQuickVector2DValueType::QQuickVector2DValueType(QObject *parent)
+ : QQmlValueTypeBase<QVector2D>(parent)
+{
+}
+
+QString QQuickVector2DValueType::toString() const
+{
+ return QString(QLatin1String("QVector2D(%1, %2)")).arg(v.x()).arg(v.y());
+}
+
+qreal QQuickVector2DValueType::x() const
+{
+ return v.x();
+}
+
+qreal QQuickVector2DValueType::y() const
+{
+ return v.y();
+}
+
+void QQuickVector2DValueType::setX(qreal x)
+{
+ v.setX(x);
+}
+
+void QQuickVector2DValueType::setY(qreal y)
+{
+ v.setY(y);
+}
+
+
+QQuickVector3DValueType::QQuickVector3DValueType(QObject *parent)
+ : QQmlValueTypeBase<QVector3D>(parent)
+{
+}
+
+QString QQuickVector3DValueType::toString() const
+{
+ return QString(QLatin1String("QVector3D(%1, %2, %3)")).arg(v.x()).arg(v.y()).arg(v.z());
+}
+
+qreal QQuickVector3DValueType::x() const
+{
+ return v.x();
+}
+
+qreal QQuickVector3DValueType::y() const
+{
+ return v.y();
+}
+
+qreal QQuickVector3DValueType::z() const
+{
+ return v.z();
+}
+
+void QQuickVector3DValueType::setX(qreal x)
+{
+ v.setX(x);
+}
+
+void QQuickVector3DValueType::setY(qreal y)
+{
+ v.setY(y);
+}
+
+void QQuickVector3DValueType::setZ(qreal z)
+{
+ v.setZ(z);
+}
+
+
+QQuickVector4DValueType::QQuickVector4DValueType(QObject *parent)
+ : QQmlValueTypeBase<QVector4D>(parent)
+{
+}
+
+QString QQuickVector4DValueType::toString() const
+{
+ return QString(QLatin1String("QVector4D(%1, %2, %3, %4)")).arg(v.x()).arg(v.y()).arg(v.z()).arg(v.w());
+}
+
+qreal QQuickVector4DValueType::x() const
+{
+ return v.x();
+}
+
+qreal QQuickVector4DValueType::y() const
+{
+ return v.y();
+}
+
+qreal QQuickVector4DValueType::z() const
+{
+ return v.z();
+}
+
+qreal QQuickVector4DValueType::w() const
+{
+ return v.w();
+}
+
+void QQuickVector4DValueType::setX(qreal x)
+{
+ v.setX(x);
+}
+
+void QQuickVector4DValueType::setY(qreal y)
+{
+ v.setY(y);
+}
+
+void QQuickVector4DValueType::setZ(qreal z)
+{
+ v.setZ(z);
+}
+
+void QQuickVector4DValueType::setW(qreal w)
+{
+ v.setW(w);
+}
+
+
+QQuickQuaternionValueType::QQuickQuaternionValueType(QObject *parent)
+ : QQmlValueTypeBase<QQuaternion>(parent)
+{
+}
+
+QString QQuickQuaternionValueType::toString() const
+{
+ return QString(QLatin1String("QQuaternion(%1, %2, %3, %4)")).arg(v.scalar()).arg(v.x()).arg(v.y()).arg(v.z());
+}
+
+qreal QQuickQuaternionValueType::scalar() const
+{
+ return v.scalar();
+}
+
+qreal QQuickQuaternionValueType::x() const
+{
+ return v.x();
+}
+
+qreal QQuickQuaternionValueType::y() const
+{
+ return v.y();
+}
+
+qreal QQuickQuaternionValueType::z() const
+{
+ return v.z();
+}
+
+void QQuickQuaternionValueType::setScalar(qreal scalar)
+{
+ v.setScalar(scalar);
+}
+
+void QQuickQuaternionValueType::setX(qreal x)
+{
+ v.setX(x);
+}
+
+void QQuickQuaternionValueType::setY(qreal y)
+{
+ v.setY(y);
+}
+
+void QQuickQuaternionValueType::setZ(qreal z)
+{
+ v.setZ(z);
+}
+
+
+QQuickMatrix4x4ValueType::QQuickMatrix4x4ValueType(QObject *parent)
+ : QQmlValueTypeBase<QMatrix4x4>(parent)
+{
+}
+
+QString QQuickMatrix4x4ValueType::toString() const
+{
+ return QString(QLatin1String("QMatrix4x4(%1, %2, %3, %4, %5, %6, %7, %8, %9, %10, %11, %12, %13, %14, %15, %16)"))
+ .arg(v(0, 0)).arg(v(0, 1)).arg(v(0, 2)).arg(v(0, 3))
+ .arg(v(1, 0)).arg(v(1, 1)).arg(v(1, 2)).arg(v(1, 3))
+ .arg(v(2, 0)).arg(v(2, 1)).arg(v(2, 2)).arg(v(2, 3))
+ .arg(v(3, 0)).arg(v(3, 1)).arg(v(3, 2)).arg(v(3, 3));
+}
+
+
+QQuickFontValueType::QQuickFontValueType(QObject *parent)
+ : QQmlValueTypeBase<QFont>(parent),
+ pixelSizeSet(false),
+ pointSizeSet(false)
+{
+}
+
+void QQuickFontValueType::onLoad()
+{
+ pixelSizeSet = false;
+ pointSizeSet = false;
+}
+
+QString QQuickFontValueType::toString() const
+{
+ return QString(QLatin1String("QFont(%1)")).arg(v.toString());
+}
+
+QString QQuickFontValueType::family() const
+{
+ return v.family();
+}
+
+void QQuickFontValueType::setFamily(const QString &family)
+{
+ v.setFamily(family);
+}
+
+bool QQuickFontValueType::bold() const
+{
+ return v.bold();
+}
+
+void QQuickFontValueType::setBold(bool b)
+{
+ v.setBold(b);
+}
+
+QQuickFontValueType::FontWeight QQuickFontValueType::weight() const
+{
+ return (QQuickFontValueType::FontWeight)v.weight();
+}
+
+void QQuickFontValueType::setWeight(QQuickFontValueType::FontWeight w)
+{
+ v.setWeight((QFont::Weight)w);
+}
+
+bool QQuickFontValueType::italic() const
+{
+ return v.italic();
+}
+
+void QQuickFontValueType::setItalic(bool b)
+{
+ v.setItalic(b);
+}
+
+bool QQuickFontValueType::underline() const
+{
+ return v.underline();
+}
+
+void QQuickFontValueType::setUnderline(bool b)
+{
+ v.setUnderline(b);
+}
+
+bool QQuickFontValueType::overline() const
+{
+ return v.overline();
+}
+
+void QQuickFontValueType::setOverline(bool b)
+{
+ v.setOverline(b);
+}
+
+bool QQuickFontValueType::strikeout() const
+{
+ return v.strikeOut();
+}
+
+void QQuickFontValueType::setStrikeout(bool b)
+{
+ v.setStrikeOut(b);
+}
+
+qreal QQuickFontValueType::pointSize() const
+{
+ if (v.pointSizeF() == -1) {
+ if (dpi.isNull)
+ dpi = qt_defaultDpi();
+ return v.pixelSize() * qreal(72.) / qreal(dpi);
+ }
+ return v.pointSizeF();
+}
+
+void QQuickFontValueType::setPointSize(qreal size)
+{
+ if (pixelSizeSet) {
+ qWarning() << "Both point size and pixel size set. Using pixel size.";
+ return;
+ }
+
+ if (size >= 0.0) {
+ pointSizeSet = true;
+ v.setPointSizeF(size);
+ } else {
+ pointSizeSet = false;
+ }
+}
+
+int QQuickFontValueType::pixelSize() const
+{
+ if (v.pixelSize() == -1) {
+ if (dpi.isNull)
+ dpi = qt_defaultDpi();
+ return (v.pointSizeF() * dpi) / qreal(72.);
+ }
+ return v.pixelSize();
+}
+
+void QQuickFontValueType::setPixelSize(int size)
+{
+ if (size >0) {
+ if (pointSizeSet)
+ qWarning() << "Both point size and pixel size set. Using pixel size.";
+ v.setPixelSize(size);
+ pixelSizeSet = true;
+ } else {
+ pixelSizeSet = false;
+ }
+}
+
+QQuickFontValueType::Capitalization QQuickFontValueType::capitalization() const
+{
+ return (QQuickFontValueType::Capitalization)v.capitalization();
+}
+
+void QQuickFontValueType::setCapitalization(QQuickFontValueType::Capitalization c)
+{
+ v.setCapitalization((QFont::Capitalization)c);
+}
+
+qreal QQuickFontValueType::letterSpacing() const
+{
+ return v.letterSpacing();
+}
+
+void QQuickFontValueType::setLetterSpacing(qreal size)
+{
+ v.setLetterSpacing(QFont::AbsoluteSpacing, size);
+}
+
+qreal QQuickFontValueType::wordSpacing() const
+{
+ return v.wordSpacing();
+}
+
+void QQuickFontValueType::setWordSpacing(qreal size)
+{
+ v.setWordSpacing(size);
+}
+
+QT_END_NAMESPACE
diff --git a/src/quick/util/qquickvaluetypes_p.h b/src/quick/util/qquickvaluetypes_p.h
new file mode 100644
index 0000000000..d2767db329
--- /dev/null
+++ b/src/quick/util/qquickvaluetypes_p.h
@@ -0,0 +1,310 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtQml module 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 QQUICKVALUETYPES_P_H
+#define QQUICKVALUETYPES_P_H
+
+#include <qqml.h>
+#include <qtquickglobal.h>
+#include <private/qqmlvaluetype_p.h>
+
+#include <QtGui/QColor>
+#include <QtGui/QVector2D>
+#include <QtGui/QVector3D>
+#include <QtGui/QVector4D>
+#include <QtGui/QQuaternion>
+#include <QtGui/QMatrix4x4>
+#include <QtGui/QFont>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QQuickValueTypes {
+
+void registerValueTypes();
+
+}
+
+class Q_AUTOTEST_EXPORT QQuickColorValueType : public QQmlValueTypeBase<QColor>
+{
+ Q_PROPERTY(qreal r READ r WRITE setR)
+ Q_PROPERTY(qreal g READ g WRITE setG)
+ Q_PROPERTY(qreal b READ b WRITE setB)
+ Q_PROPERTY(qreal a READ a WRITE setA)
+ Q_OBJECT
+public:
+ QQuickColorValueType(QObject *parent = 0);
+
+ virtual QString toString() const;
+
+ qreal r() const;
+ qreal g() const;
+ qreal b() const;
+ qreal a() const;
+ void setR(qreal);
+ void setG(qreal);
+ void setB(qreal);
+ void setA(qreal);
+};
+
+class Q_AUTOTEST_EXPORT QQuickVector2DValueType : public QQmlValueTypeBase<QVector2D>
+{
+ Q_PROPERTY(qreal x READ x WRITE setX)
+ Q_PROPERTY(qreal y READ y WRITE setY)
+ Q_OBJECT
+public:
+ QQuickVector2DValueType(QObject *parent = 0);
+
+ virtual QString toString() const;
+
+ qreal x() const;
+ qreal y() const;
+ void setX(qreal);
+ void setY(qreal);
+};
+
+class Q_AUTOTEST_EXPORT QQuickVector3DValueType : public QQmlValueTypeBase<QVector3D>
+{
+ Q_PROPERTY(qreal x READ x WRITE setX)
+ Q_PROPERTY(qreal y READ y WRITE setY)
+ Q_PROPERTY(qreal z READ z WRITE setZ)
+ Q_OBJECT
+public:
+ QQuickVector3DValueType(QObject *parent = 0);
+
+ virtual QString toString() const;
+
+ qreal x() const;
+ qreal y() const;
+ qreal z() const;
+ void setX(qreal);
+ void setY(qreal);
+ void setZ(qreal);
+};
+
+class Q_AUTOTEST_EXPORT QQuickVector4DValueType : public QQmlValueTypeBase<QVector4D>
+{
+ Q_PROPERTY(qreal x READ x WRITE setX)
+ Q_PROPERTY(qreal y READ y WRITE setY)
+ Q_PROPERTY(qreal z READ z WRITE setZ)
+ Q_PROPERTY(qreal w READ w WRITE setW)
+ Q_OBJECT
+public:
+ QQuickVector4DValueType(QObject *parent = 0);
+
+ virtual QString toString() const;
+
+ qreal x() const;
+ qreal y() const;
+ qreal z() const;
+ qreal w() const;
+ void setX(qreal);
+ void setY(qreal);
+ void setZ(qreal);
+ void setW(qreal);
+};
+
+class Q_AUTOTEST_EXPORT QQuickQuaternionValueType : public QQmlValueTypeBase<QQuaternion>
+{
+ Q_PROPERTY(qreal scalar READ scalar WRITE setScalar)
+ Q_PROPERTY(qreal x READ x WRITE setX)
+ Q_PROPERTY(qreal y READ y WRITE setY)
+ Q_PROPERTY(qreal z READ z WRITE setZ)
+ Q_OBJECT
+public:
+ QQuickQuaternionValueType(QObject *parent = 0);
+
+ virtual QString toString() const;
+
+ qreal scalar() const;
+ qreal x() const;
+ qreal y() const;
+ qreal z() const;
+ void setScalar(qreal);
+ void setX(qreal);
+ void setY(qreal);
+ void setZ(qreal);
+};
+
+class Q_AUTOTEST_EXPORT QQuickMatrix4x4ValueType : public QQmlValueTypeBase<QMatrix4x4>
+{
+ Q_PROPERTY(qreal m11 READ m11 WRITE setM11)
+ Q_PROPERTY(qreal m12 READ m12 WRITE setM12)
+ Q_PROPERTY(qreal m13 READ m13 WRITE setM13)
+ Q_PROPERTY(qreal m14 READ m14 WRITE setM14)
+ Q_PROPERTY(qreal m21 READ m21 WRITE setM21)
+ Q_PROPERTY(qreal m22 READ m22 WRITE setM22)
+ Q_PROPERTY(qreal m23 READ m23 WRITE setM23)
+ Q_PROPERTY(qreal m24 READ m24 WRITE setM24)
+ Q_PROPERTY(qreal m31 READ m31 WRITE setM31)
+ Q_PROPERTY(qreal m32 READ m32 WRITE setM32)
+ Q_PROPERTY(qreal m33 READ m33 WRITE setM33)
+ Q_PROPERTY(qreal m34 READ m34 WRITE setM34)
+ Q_PROPERTY(qreal m41 READ m41 WRITE setM41)
+ Q_PROPERTY(qreal m42 READ m42 WRITE setM42)
+ Q_PROPERTY(qreal m43 READ m43 WRITE setM43)
+ Q_PROPERTY(qreal m44 READ m44 WRITE setM44)
+ Q_OBJECT
+public:
+ QQuickMatrix4x4ValueType(QObject *parent = 0);
+
+ virtual QString toString() const;
+
+ qreal m11() const { return v(0, 0); }
+ qreal m12() const { return v(0, 1); }
+ qreal m13() const { return v(0, 2); }
+ qreal m14() const { return v(0, 3); }
+ qreal m21() const { return v(1, 0); }
+ qreal m22() const { return v(1, 1); }
+ qreal m23() const { return v(1, 2); }
+ qreal m24() const { return v(1, 3); }
+ qreal m31() const { return v(2, 0); }
+ qreal m32() const { return v(2, 1); }
+ qreal m33() const { return v(2, 2); }
+ qreal m34() const { return v(2, 3); }
+ qreal m41() const { return v(3, 0); }
+ qreal m42() const { return v(3, 1); }
+ qreal m43() const { return v(3, 2); }
+ qreal m44() const { return v(3, 3); }
+
+ void setM11(qreal value) { v(0, 0) = value; }
+ void setM12(qreal value) { v(0, 1) = value; }
+ void setM13(qreal value) { v(0, 2) = value; }
+ void setM14(qreal value) { v(0, 3) = value; }
+ void setM21(qreal value) { v(1, 0) = value; }
+ void setM22(qreal value) { v(1, 1) = value; }
+ void setM23(qreal value) { v(1, 2) = value; }
+ void setM24(qreal value) { v(1, 3) = value; }
+ void setM31(qreal value) { v(2, 0) = value; }
+ void setM32(qreal value) { v(2, 1) = value; }
+ void setM33(qreal value) { v(2, 2) = value; }
+ void setM34(qreal value) { v(2, 3) = value; }
+ void setM41(qreal value) { v(3, 0) = value; }
+ void setM42(qreal value) { v(3, 1) = value; }
+ void setM43(qreal value) { v(3, 2) = value; }
+ void setM44(qreal value) { v(3, 3) = value; }
+};
+
+class Q_AUTOTEST_EXPORT QQuickFontValueType : public QQmlValueTypeBase<QFont>
+{
+ Q_OBJECT
+ Q_ENUMS(FontWeight)
+ Q_ENUMS(Capitalization)
+
+ Q_PROPERTY(QString family READ family WRITE setFamily)
+ Q_PROPERTY(bool bold READ bold WRITE setBold)
+ Q_PROPERTY(FontWeight weight READ weight WRITE setWeight)
+ Q_PROPERTY(bool italic READ italic WRITE setItalic)
+ Q_PROPERTY(bool underline READ underline WRITE setUnderline)
+ Q_PROPERTY(bool overline READ overline WRITE setOverline)
+ Q_PROPERTY(bool strikeout READ strikeout WRITE setStrikeout)
+ Q_PROPERTY(qreal pointSize READ pointSize WRITE setPointSize)
+ Q_PROPERTY(int pixelSize READ pixelSize WRITE setPixelSize)
+ Q_PROPERTY(Capitalization capitalization READ capitalization WRITE setCapitalization)
+ Q_PROPERTY(qreal letterSpacing READ letterSpacing WRITE setLetterSpacing)
+ Q_PROPERTY(qreal wordSpacing READ wordSpacing WRITE setWordSpacing)
+
+public:
+ enum FontWeight { Light = QFont::Light,
+ Normal = QFont::Normal,
+ DemiBold = QFont::DemiBold,
+ Bold = QFont::Bold,
+ Black = QFont::Black };
+ enum Capitalization { MixedCase = QFont::MixedCase,
+ AllUppercase = QFont::AllUppercase,
+ AllLowercase = QFont::AllLowercase,
+ SmallCaps = QFont::SmallCaps,
+ Capitalize = QFont::Capitalize };
+
+ QQuickFontValueType(QObject *parent = 0);
+
+ virtual QString toString() const;
+
+ QString family() const;
+ void setFamily(const QString &);
+
+ bool bold() const;
+ void setBold(bool b);
+
+ FontWeight weight() const;
+ void setWeight(FontWeight);
+
+ bool italic() const;
+ void setItalic(bool b);
+
+ bool underline() const;
+ void setUnderline(bool b);
+
+ bool overline() const;
+ void setOverline(bool b);
+
+ bool strikeout() const;
+ void setStrikeout(bool b);
+
+ qreal pointSize() const;
+ void setPointSize(qreal size);
+
+ int pixelSize() const;
+ void setPixelSize(int size);
+
+ Capitalization capitalization() const;
+ void setCapitalization(Capitalization);
+
+ qreal letterSpacing() const;
+ void setLetterSpacing(qreal spacing);
+
+ qreal wordSpacing() const;
+ void setWordSpacing(qreal spacing);
+
+ void onLoad();
+
+private:
+ bool pixelSizeSet;
+ bool pointSizeSet;
+ mutable QQmlNullableValue<int> dpi;
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QQUICKVALUETYPES_P_H
diff --git a/src/quick/util/util.pri b/src/quick/util/util.pri
index c3cec91404..3d93b9f2f5 100644
--- a/src/quick/util/util.pri
+++ b/src/quick/util/util.pri
@@ -1,4 +1,5 @@
SOURCES += \
+ $$PWD/qquickapplication.cpp\
$$PWD/qquickutilmodule.cpp\
$$PWD/qquickconnections.cpp \
$$PWD/qquickpackage.cpp \
@@ -25,9 +26,13 @@ SOURCES += \
$$PWD/qquickchangeset.cpp \
$$PWD/qquicklistcompositor.cpp \
$$PWD/qquickpathinterpolator.cpp \
- $$PWD/qquicksvgparser.cpp
+ $$PWD/qquickimageprovider.cpp \
+ $$PWD/qquicksvgparser.cpp \
+ $$PWD/qquickvaluetypes.cpp \
+ $$PWD/qquickglobal.cpp
HEADERS += \
+ $$PWD/qquickapplication_p.h\
$$PWD/qquickutilmodule_p.h\
$$PWD/qquickconnections_p.h \
$$PWD/qquickpackage_p.h \
@@ -58,4 +63,6 @@ HEADERS += \
$$PWD/qquickchangeset_p.h \
$$PWD/qquicklistcompositor_p.h \
$$PWD/qquickpathinterpolator_p.h \
- $$PWD/qquicksvgparser_p.h
+ $$PWD/qquickimageprovider.h \
+ $$PWD/qquicksvgparser_p.h \
+ $$PWD/qquickvaluetypes_p.h