diff options
Diffstat (limited to 'src/qml/qml/v8')
-rw-r--r-- | src/qml/qml/v8/qqmlbuiltinfunctions.cpp | 28 | ||||
-rw-r--r-- | src/qml/qml/v8/qqmlbuiltinfunctions_p.h | 1 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp index 109629f5f1..8e5cbb8e96 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp +++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp @@ -101,6 +101,7 @@ Heap::QtObject::QtObject(ExecutionEngine *v4, QQmlEngine *qmlEngine) o->defineDefaultProperty(QStringLiteral("isQtObject"), QV4::QtObject::method_isQtObject); o->defineDefaultProperty(QStringLiteral("rgba"), QV4::QtObject::method_rgba); o->defineDefaultProperty(QStringLiteral("hsla"), QV4::QtObject::method_hsla); + o->defineDefaultProperty(QStringLiteral("hsva"), QV4::QtObject::method_hsva); o->defineDefaultProperty(QStringLiteral("colorEqual"), QV4::QtObject::method_colorEqual); o->defineDefaultProperty(QStringLiteral("rect"), QV4::QtObject::method_rect); o->defineDefaultProperty(QStringLiteral("point"), QV4::QtObject::method_point); @@ -215,6 +216,33 @@ ReturnedValue QtObject::method_hsla(QV4::CallContext *ctx) } /*! +\qmlmethod color Qt::hsva(real hue, real saturation, real value, real alpha) + +Returns a color with the specified \c hue, \c saturation, \c value and \c alpha components. +All components should be in the range 0-1 inclusive. + +\since 5.5 +*/ +ReturnedValue QtObject::method_hsva(QV4::CallContext *ctx) +{ + int argCount = ctx->argc(); + if (argCount < 3 || argCount > 4) + V4THROW_ERROR("Qt.hsva(): Invalid arguments"); + + double h = ctx->args()[0].toNumber(); + double s = ctx->args()[1].toNumber(); + double v = ctx->args()[2].toNumber(); + double a = (argCount == 4) ? ctx->args()[3].toNumber() : 1; + + h = qBound(0.0, h, 1.0); + s = qBound(0.0, s, 1.0); + v = qBound(0.0, v, 1.0); + a = qBound(0.0, a, 1.0); + + return ctx->engine()->fromVariant(QQml_colorProvider()->fromHsvF(h, s, v, a)); +} + +/*! \qmlmethod color Qt::colorEqual(color lhs, string rhs) Returns true if both \c lhs and \c rhs yield equal color values. Both arguments diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions_p.h b/src/qml/qml/v8/qqmlbuiltinfunctions_p.h index dc45429aeb..b78375118b 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions_p.h +++ b/src/qml/qml/v8/qqmlbuiltinfunctions_p.h @@ -83,6 +83,7 @@ struct QtObject : Object static ReturnedValue method_isQtObject(CallContext *ctx); static ReturnedValue method_rgba(CallContext *ctx); static ReturnedValue method_hsla(CallContext *ctx); + static ReturnedValue method_hsva(CallContext *ctx); static ReturnedValue method_colorEqual(CallContext *ctx); static ReturnedValue method_font(CallContext *ctx); static ReturnedValue method_rect(CallContext *ctx); |