summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2009-08-21 03:28:39 (GMT)
committerMartin Jones <martin.jones@nokia.com>2009-08-21 03:28:39 (GMT)
commitaf23b7a78ce50d747efc06cd26ea5b69349df811 (patch)
tree9199d28b4bbd32b3ba4de35486aeadaf626bd069 /src
parent08a4fffc4c93c324f95f5759c620287330c68d9d (diff)
parent61486c42722a6ab5701c331645d6c25bce81a17e (diff)
downloadQt-af23b7a78ce50d747efc06cd26ea5b69349df811.zip
Qt-af23b7a78ce50d747efc06cd26ea5b69349df811.tar.gz
Qt-af23b7a78ce50d747efc06cd26ea5b69349df811.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src')
-rw-r--r--src/declarative/qml/qmlbinding.cpp6
-rw-r--r--src/declarative/qml/qmlcompiler.cpp19
-rw-r--r--src/declarative/qml/qmlengine.cpp41
-rw-r--r--src/declarative/qml/qmlengine_p.h1
-rw-r--r--src/declarative/qml/qmlinstruction.cpp3
-rw-r--r--src/declarative/qml/qmlinstruction_p.h5
-rw-r--r--src/declarative/qml/qmlmetatype.cpp7
-rw-r--r--src/declarative/qml/qmlstringconverters.cpp29
-rw-r--r--src/declarative/qml/qmlstringconverters_p.h2
-rw-r--r--src/declarative/qml/qmlvme.cpp13
-rw-r--r--src/declarative/util/qmlanimation.cpp4
11 files changed, 130 insertions, 0 deletions
diff --git a/src/declarative/qml/qmlbinding.cpp b/src/declarative/qml/qmlbinding.cpp
index 45d20f4..39851ff 100644
--- a/src/declarative/qml/qmlbinding.cpp
+++ b/src/declarative/qml/qmlbinding.cpp
@@ -49,6 +49,7 @@
#include <QtCore/qdebug.h>
#include <private/qmlcontext_p.h>
#include <private/qmldeclarativedata_p.h>
+#include <private/qmlstringconverters_p.h>
Q_DECLARE_METATYPE(QList<QObject *>);
@@ -129,6 +130,11 @@ void QmlBinding::update()
(value.type() == QVariant::String || value.type() == QVariant::ByteArray) && !value.isNull())
value.setValue(context()->resolvedUrl(QUrl(value.toString())));
+ if (d->property.propertyType() == QVariant::Vector3D &&
+ value.type() == QVariant::String) {
+ value = qVariantFromValue(QmlStringConverters::vector3DFromString(value.toString()));
+ }
+
d->property.write(value);
}
diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp
index afc8698..1fb4b46 100644
--- a/src/declarative/qml/qmlcompiler.cpp
+++ b/src/declarative/qml/qmlcompiler.cpp
@@ -297,6 +297,13 @@ bool QmlCompiler::testLiteralAssignment(const QMetaProperty &prop,
if (!v->value.isBoolean()) COMPILE_EXCEPTION(v, "Invalid property assignment: boolean expected");
}
break;
+ case QVariant::Vector3D:
+ {
+ bool ok;
+ QVector3D point = QmlStringConverters::vector3DFromString(string, &ok);
+ if (!ok) COMPILE_EXCEPTION(v, "Invalid property assignment: 3D vector expected");
+ }
+ break;
default:
{
int t = prop.type();
@@ -487,6 +494,18 @@ void QmlCompiler::genLiteralAssignment(const QMetaProperty &prop,
instr.storeBool.value = b;
}
break;
+ case QVariant::Vector3D:
+ {
+ bool ok;
+ QVector3D vector =
+ QmlStringConverters::vector3DFromString(string, &ok);
+ float data[] = { vector.x(), vector.y(), vector.z() };
+ int index = output->indexForFloat(data, 3);
+ instr.type = QmlInstruction::StoreVector3D;
+ instr.storeRealPair.propertyIndex = prop.propertyIndex();
+ instr.storeRealPair.valueIndex = index;
+ }
+ break;
default:
{
int t = prop.type();
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index 84c9553..7f2a3e1 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -158,6 +158,8 @@ void QmlEnginePrivate::init()
scriptEngine.newFunction(QmlEnginePrivate::createQmlObject, 1));
scriptEngine.globalObject().setProperty(QLatin1String("createComponent"),
scriptEngine.newFunction(QmlEnginePrivate::createComponent, 1));
+ scriptEngine.globalObject().setProperty(QLatin1String("vector"),
+ scriptEngine.newFunction(QmlEnginePrivate::vector, 1));
if (QCoreApplication::instance()->thread() == q->thread() &&
QmlEngineDebugServer::isDebuggingEnabled()) {
@@ -692,6 +694,45 @@ QScriptValue QmlEnginePrivate::createQmlObject(QScriptContext *ctxt, QScriptEngi
return engine->nullValue();
}
+/*!
+ This function is intended for use inside QML only. In C++ just create a
+ QVector3D as usual.
+
+ This function takes three numeric components and combines them into a
+ QMLJS string that can be used with any property that takes a
+ QVector3D argument. The following QML code:
+
+ \code
+ transform: Rotation {
+ id: Rotation
+ origin.x: Container.width / 2;
+ axis: vector(0, 1, 1)
+ }
+ \endcode
+
+ is equivalent to:
+
+ \code
+ transform: Rotation {
+ id: Rotation
+ origin.x: Container.width / 2;
+ axis.x: 0; axis.y: 1; axis.z: 0
+ }
+ \endcode
+*/
+QScriptValue QmlEnginePrivate::vector(QScriptContext *ctxt, QScriptEngine *engine)
+{
+ if(ctxt->argumentCount() < 3)
+ return engine->nullValue();
+ qsreal x = ctxt->argument(0).toNumber();
+ qsreal y = ctxt->argument(1).toNumber();
+ qsreal z = ctxt->argument(2).toNumber();
+ QString s = QString::number(x) + QLatin1Char(',') +
+ QString::number(y) + QLatin1Char(',') +
+ QString::number(z);
+ return QScriptValue(s);
+}
+
QmlScriptClass::QmlScriptClass(QmlEngine *bindengine)
: QScriptClass(QmlEnginePrivate::getScriptEngine(bindengine)),
engine(bindengine)
diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h
index aaf679f..4142872 100644
--- a/src/declarative/qml/qmlengine_p.h
+++ b/src/declarative/qml/qmlengine_p.h
@@ -204,6 +204,7 @@ public:
static QScriptValue qmlScriptObject(QObject*, QmlEngine*);
static QScriptValue createComponent(QScriptContext*, QScriptEngine*);
static QScriptValue createQmlObject(QScriptContext*, QScriptEngine*);
+ static QScriptValue vector(QScriptContext*, QScriptEngine*);
static QScriptEngine *getScriptEngine(QmlEngine *e) { return &e->d_func()->scriptEngine; }
static QmlEnginePrivate *get(QmlEngine *e) { return e->d_func(); }
diff --git a/src/declarative/qml/qmlinstruction.cpp b/src/declarative/qml/qmlinstruction.cpp
index fd912ac..02e4883 100644
--- a/src/declarative/qml/qmlinstruction.cpp
+++ b/src/declarative/qml/qmlinstruction.cpp
@@ -119,6 +119,9 @@ void QmlCompiledData::dump(QmlInstruction *instr, int idx)
case QmlInstruction::StoreRectF:
qWarning() << idx << "\t" << line << "\t" << "STORE_RECTF\t\t" << instr->storeRect.propertyIndex << "\t" << instr->storeRect.valueIndex;
break;
+ case QmlInstruction::StoreVector3D:
+ qWarning() << idx << "\t" << line << "\t" << "STORE_VECTOR3D\t\t" << instr->storeVector3D.propertyIndex << "\t" << instr->storeVector3D.valueIndex;
+ break;
case QmlInstruction::StoreVariant:
qWarning() << idx << "\t" << line << "\t" << "STORE_VARIANT\t\t" << instr->storeString.propertyIndex << "\t" << instr->storeString.value << "\t\t" << primitives.at(instr->storeString.value);
break;
diff --git a/src/declarative/qml/qmlinstruction_p.h b/src/declarative/qml/qmlinstruction_p.h
index 7f3498f..0f2995a 100644
--- a/src/declarative/qml/qmlinstruction_p.h
+++ b/src/declarative/qml/qmlinstruction_p.h
@@ -111,6 +111,7 @@ public:
StoreSizeF, /* storeRealPair */
StoreRect, /* storeRect */
StoreRectF, /* storeRect */
+ StoreVector3D, /* storeVector3D */
StoreVariant, /* storeString */
StoreObject, /* storeObject */
StoreVariantObject, /* storeObject */
@@ -263,6 +264,10 @@ public:
} storeRect;
struct {
int propertyIndex;
+ int valueIndex;
+ } storeVector3D;
+ struct {
+ int propertyIndex;
} storeObject;
struct {
int propertyIndex;
diff --git a/src/declarative/qml/qmlmetatype.cpp b/src/declarative/qml/qmlmetatype.cpp
index 091bd1b..ab64079 100644
--- a/src/declarative/qml/qmlmetatype.cpp
+++ b/src/declarative/qml/qmlmetatype.cpp
@@ -75,6 +75,7 @@
# include <qpoint.h>
# include <qrect.h>
# include <qline.h>
+# include <qvector3d.h>
#endif
#define NS(x) QT_PREPEND_NAMESPACE(x)
@@ -1028,6 +1029,9 @@ bool QmlMetaType::copy(int type, void *data, const void *copy)
case QMetaType::QPointF:
*static_cast<NS(QPointF) *>(data) = *static_cast<const NS(QPointF)*>(copy);
return true;
+ case QMetaType::QVector3D:
+ *static_cast<NS(QVector3D) *>(data) = *static_cast<const NS(QVector3D)*>(copy);
+ return true;
#endif
#ifndef QT_NO_REGEXP
case QMetaType::QRegExp:
@@ -1155,6 +1159,9 @@ bool QmlMetaType::copy(int type, void *data, const void *copy)
case QMetaType::QPointF:
*static_cast<NS(QPointF) *>(data) = NS(QPointF)();
return true;
+ case QMetaType::QVector3D:
+ *static_cast<NS(QVector3D) *>(data) = NS(QVector3D)();
+ return true;
#endif
#ifndef QT_NO_REGEXP
case QMetaType::QRegExp:
diff --git a/src/declarative/qml/qmlstringconverters.cpp b/src/declarative/qml/qmlstringconverters.cpp
index c1f4b8c..34025c5 100644
--- a/src/declarative/qml/qmlstringconverters.cpp
+++ b/src/declarative/qml/qmlstringconverters.cpp
@@ -40,6 +40,7 @@
****************************************************************************/
#include <QtGui/qcolor.h>
+#include <QtGui/qvector3d.h>
#include <QtCore/qpoint.h>
#include <QtCore/qrect.h>
#include <QtCore/qsize.h>
@@ -94,6 +95,8 @@ QVariant QmlStringConverters::variantFromString(const QString &s)
if (ok) return QVariant(sz);
bool b = boolFromString(s, &ok);
if (ok) return QVariant(b);
+ QVector3D v = vector3DFromString(s, &ok);
+ if (ok) return qVariantFromValue(v);
return QVariant(s);
}
@@ -209,4 +212,30 @@ bool QmlStringConverters::boolFromString(const QString &str, bool *ok)
return true;
}
+//expects input of "x,y,z"
+QVector3D QmlStringConverters::vector3DFromString(const QString &s, bool *ok)
+{
+ if (s.count(QLatin1Char(',')) != 2) {
+ if (ok)
+ *ok = false;
+ return QVector3D();
+ }
+
+ bool xGood, yGood, zGood;
+ int index = s.indexOf(QLatin1Char(','));
+ int index2 = s.indexOf(QLatin1Char(','), index+1);
+ 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 = false;
+ return QVector3D();
+ }
+
+ if (ok)
+ *ok = true;
+ return QVector3D(xCoord, yCoord, zCoord);
+}
+
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qmlstringconverters_p.h b/src/declarative/qml/qmlstringconverters_p.h
index 52426a7..ab7448c 100644
--- a/src/declarative/qml/qmlstringconverters_p.h
+++ b/src/declarative/qml/qmlstringconverters_p.h
@@ -60,6 +60,7 @@ class QSizeF;
class QRectF;
class QString;
class QByteArray;
+class QVector3D;
QT_BEGIN_NAMESPACE
@@ -72,6 +73,7 @@ namespace QmlStringConverters
QSizeF Q_DECLARATIVE_EXPORT sizeFFromString(const QString &, bool *ok = 0);
QRectF Q_DECLARATIVE_EXPORT rectFFromString(const QString &, bool *ok = 0);
bool Q_DECLARATIVE_EXPORT boolFromString(const QString &, bool *ok = 0);
+ QVector3D Q_DECLARATIVE_EXPORT vector3DFromString(const QString &, bool *ok = 0);
};
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp
index 79b1d89..7455eb4 100644
--- a/src/declarative/qml/qmlvme.cpp
+++ b/src/declarative/qml/qmlvme.cpp
@@ -439,6 +439,19 @@ QObject *QmlVME::run(QStack<QObject *> &stack, QmlContext *ctxt, QmlCompiledData
}
break;
+ case QmlInstruction::StoreVector3D:
+ {
+ QObject *target = stack.top();
+ void *a[1];
+ QVector3D p(floatData.at(instr.storeVector3D.valueIndex),
+ floatData.at(instr.storeVector3D.valueIndex+1),
+ floatData.at(instr.storeVector3D.valueIndex+2));
+ a[0] = (void *)&p;
+ QMetaObject::metacall(target, QMetaObject::WriteProperty,
+ instr.storeVector3D.propertyIndex, a);
+ }
+ break;
+
case QmlInstruction::StoreObject:
{
QObject *assignObj = stack.pop();
diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp
index e5b7c47..0e93cc7 100644
--- a/src/declarative/util/qmlanimation.cpp
+++ b/src/declarative/util/qmlanimation.cpp
@@ -1462,6 +1462,10 @@ void QmlPropertyAnimationPrivate::convertVariant(QVariant &variant, int type)
variant.setValue(QmlStringConverters::colorFromString(variant.toString()));
break;
}
+ case QVariant::Vector3D: {
+ variant.setValue(QmlStringConverters::vector3DFromString(variant.toString()));
+ break;
+ }
default:
if ((uint)type >= QVariant::UserType) {
QmlMetaType::StringConverter converter = QmlMetaType::customStringConverter(type);