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 | |
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')
-rw-r--r-- | src/qml/qml/qqmlglobal.cpp | 1 | ||||
-rw-r--r-- | src/qml/qml/qqmlglobal_p.h | 1 | ||||
-rw-r--r-- | src/qml/qml/v8/qqmlbuiltinfunctions.cpp | 28 | ||||
-rw-r--r-- | src/qml/qml/v8/qqmlbuiltinfunctions_p.h | 1 | ||||
-rw-r--r-- | src/quick/util/qquickglobal.cpp | 5 |
5 files changed, 36 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlglobal.cpp b/src/qml/qml/qqmlglobal.cpp index a4554f3513..d904242f93 100644 --- a/src/qml/qml/qqmlglobal.cpp +++ b/src/qml/qml/qqmlglobal.cpp @@ -317,6 +317,7 @@ QVariant QQmlColorProvider::colorFromString(const QString &, bool *ok) { if (ok) unsigned QQmlColorProvider::rgbaFromString(const QString &, bool *ok) { if (ok) *ok = false; return 0; } QVariant QQmlColorProvider::fromRgbF(double, double, double, double) { return QVariant(); } QVariant QQmlColorProvider::fromHslF(double, double, double, double) { return QVariant(); } +QVariant QQmlColorProvider::fromHsvF(double, double, double, double) { return QVariant(); } QVariant QQmlColorProvider::lighter(const QVariant &, qreal) { return QVariant(); } QVariant QQmlColorProvider::darker(const QVariant &, qreal) { return QVariant(); } QVariant QQmlColorProvider::tint(const QVariant &, const QVariant &) { return QVariant(); } diff --git a/src/qml/qml/qqmlglobal_p.h b/src/qml/qml/qqmlglobal_p.h index ef08ab2876..7856d85376 100644 --- a/src/qml/qml/qqmlglobal_p.h +++ b/src/qml/qml/qqmlglobal_p.h @@ -279,6 +279,7 @@ public: virtual QVariant fromRgbF(double, double, double, double); virtual QVariant fromHslF(double, double, double, double); + virtual QVariant fromHsvF(double, double, double, double); virtual QVariant lighter(const QVariant &, qreal); virtual QVariant darker(const QVariant &, qreal); virtual QVariant tint(const QVariant &, const QVariant &); 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); diff --git a/src/quick/util/qquickglobal.cpp b/src/quick/util/qquickglobal.cpp index ad2be02334..6aa7bedc5b 100644 --- a/src/quick/util/qquickglobal.cpp +++ b/src/quick/util/qquickglobal.cpp @@ -98,6 +98,11 @@ public: return QVariant(QColor::fromHslF(h, s, l, a)); } + QVariant fromHsvF(double h, double s, double v, double a) + { + return QVariant(QColor::fromHsvF(h, s, v, a)); + } + QVariant lighter(const QVariant &var, qreal factor) { QColor color = var.value<QColor>(); |