19 #include <QEasingCurve>
21 #include <QScriptValue>
22 #include <QScriptEngine>
23 #include <QScriptContext>
24 #include <QScriptable>
26 Q_DECLARE_METATYPE(QEasingCurve)
27 Q_DECLARE_METATYPE(QEasingCurve*)
28 #define ADD_ENUM_VALUE(__c__, __ns__, __v__) \
29 __c__.setProperty(#__v__, QScriptValue(__c__.engine(), __ns__::__v__))
31 #define DECLARE_SELF(Class, __fn__) \
32 Class* self = qscriptvalue_cast<Class*>(ctx->thisObject()); \
34 return ctx->throwError(QScriptContext::TypeError, \
35 QString::fromLatin1("%0.prototype.%1: this object is not a %0") \
36 .arg(#Class).arg(#__fn__)); \
42 static QScriptValue
ctor(QScriptContext *ctx, QScriptEngine *eng)
44 if (ctx->argumentCount() > 0) {
45 QScriptValue arg = ctx->argument(0);
47 qint32
type = arg.toInt32();
48 if (type > -1 && type < QEasingCurve::Custom) {
49 return qScriptValueFromValue(eng, QEasingCurve(static_cast<QEasingCurve::Type>(type)));
54 return qScriptValueFromValue(eng, QEasingCurve());
57 static QScriptValue
toString(QScriptContext *ctx, QScriptEngine *eng)
60 return QScriptValue(eng, QString::fromLatin1(
"QEasingCurve(type=%0)").arg(self->type()));
63 static QScriptValue
type(QScriptContext *ctx, QScriptEngine *eng)
67 if (ctx->argumentCount()) {
68 QScriptValue arg = ctx->argument(0);
73 }
else if (arg.isString()) {
74 QMetaObject meta = QEasingCurve::staticMetaObject;
75 QMetaEnum easingCurveEnum = meta.enumerator(meta.indexOfEnumerator(
"Type"));
77 type = easingCurveEnum.keyToValue(arg.toString().toLatin1().data());
79 if (type > -1 && type < QEasingCurve::Custom) {
80 self->setType(static_cast<QEasingCurve::Type>(type));
84 return QScriptValue(eng, self->type());
90 if (ctx->argumentCount() < 1 || !ctx->argument(0).isNumber()) {
91 return eng->undefinedValue();
94 return self->valueForProgress(ctx->argument(0).toNumber());
99 QScriptValue proto = qScriptValueFromValue(eng, QEasingCurve());
100 QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter;
101 QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter;
103 proto.setProperty(
"type", eng->newFunction(
type), getter | setter);
104 proto.setProperty(
"toString", eng->newFunction(
toString), getter);
105 proto.setProperty(
"valueForProgress", eng->newFunction(
valueForProgress), getter);
107 QScriptValue ctorFun = eng->newFunction(
ctor, proto);
165 eng->setDefaultPrototype(qMetaTypeId<QEasingCurve>(), proto);
166 eng->setDefaultPrototype(qMetaTypeId<QEasingCurve*>(), proto);
#define DECLARE_SELF(Class, __fn__)
#define ADD_ENUM_VALUE(__c__, __ns__, __v__)
static QScriptValue toString(QScriptContext *ctx, QScriptEngine *eng)
static QScriptValue type(QScriptContext *ctx, QScriptEngine *eng)
QScriptValue constructEasingCurveClass(QScriptEngine *engine)
static QScriptValue valueForProgress(QScriptContext *ctx, QScriptEngine *eng)
static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng)