diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2015-02-15 10:51:51 +0000 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2015-02-18 15:56:27 +0000 |
commit | 6f264b755501fd322d1e357187b42120210a7ba3 (patch) | |
tree | 0ea8915de1e41bed87c62deffa19d61a0e6ff288 /src/qml/qml/v8/qqmlbuiltinfunctions.cpp | |
parent | 3fcb6ccac0baa34b820534184f863884e072cfb2 (diff) |
Add Qt.hsva() function
This is more convenient than the alternative hsla() function in many
cases as color pickers in other applications default to the HSV color
space e.g. GIMP, kcolorchooser.
[ChangeLog][QtQml] Added Qt.hsva() function
Change-Id: Id5c1a78173757bf9842b164d90b31682e9a41749
Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/qml/qml/v8/qqmlbuiltinfunctions.cpp')
-rw-r--r-- | src/qml/qml/v8/qqmlbuiltinfunctions.cpp | 28 |
1 files changed, 28 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 |