mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 17:14:59 +02:00
Support HTML colors in overlays
This commit is contained in:
parent
817c4147d6
commit
54b7a063e2
2 changed files with 18 additions and 13 deletions
|
@ -66,16 +66,7 @@ Overlay::~Overlay() {
|
|||
|
||||
void Overlay::setProperties(const QScriptValue& properties) {
|
||||
QScriptValue color = properties.property("color");
|
||||
if (color.isValid()) {
|
||||
QScriptValue red = color.property("red");
|
||||
QScriptValue green = color.property("green");
|
||||
QScriptValue blue = color.property("blue");
|
||||
if (red.isValid() && green.isValid() && blue.isValid()) {
|
||||
_color.red = red.toVariant().toInt();
|
||||
_color.green = green.toVariant().toInt();
|
||||
_color.blue = blue.toVariant().toInt();
|
||||
}
|
||||
}
|
||||
xColorFromScriptValue(properties.property("color"), _color);
|
||||
|
||||
if (properties.property("alpha").isValid()) {
|
||||
setAlpha(properties.property("alpha").toVariant().toFloat());
|
||||
|
|
|
@ -197,9 +197,23 @@ QScriptValue xColorToScriptValue(QScriptEngine *engine, const xColor& color) {
|
|||
}
|
||||
|
||||
void xColorFromScriptValue(const QScriptValue &object, xColor& color) {
|
||||
color.red = object.property("red").toVariant().toInt();
|
||||
color.green = object.property("green").toVariant().toInt();
|
||||
color.blue = object.property("blue").toVariant().toInt();
|
||||
if (!object.isValid()) {
|
||||
return;
|
||||
}
|
||||
if (object.isNumber()) {
|
||||
color.red = color.green = color.blue = (uint8_t)object.toUInt32();
|
||||
} else if (object.isString()) {
|
||||
QColor qcolor(object.toString());
|
||||
if (qcolor.isValid()) {
|
||||
color.red = (uint8_t)qcolor.red();
|
||||
color.blue = (uint8_t)qcolor.blue();
|
||||
color.green = (uint8_t)qcolor.green();
|
||||
}
|
||||
} else {
|
||||
color.red = object.property("red").toVariant().toInt();
|
||||
color.green = object.property("green").toVariant().toInt();
|
||||
color.blue = object.property("blue").toVariant().toInt();
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue qColorToScriptValue(QScriptEngine* engine, const QColor& color) {
|
||||
|
|
Loading…
Reference in a new issue