Showing the changes to libraries/script-engine/src/ScriptValueUtils.cpp (1 of 10 files). Show all
Unified · Split
| @@ -792,14 +792,48 @@ bool qTimerFromScriptValue(const ScriptValue& object, QTimer* &out) { · 791 unmodified lines | |||
| 792 | bool qColorFromScriptValue(const ScriptValue& object, QColor& color) { | 792 | bool qColorFromScriptValue(const ScriptValue& object, QColor& color) { |
| 793 | if (object.isNumber()) { | 793 | if (object.isNumber()) { |
| 794 | color.setRgb(object.toUInt32()); | 794 | color.setRgb(object.toUInt32()); |
| 795 | 795 | return true; | |
| 796 | } else if (object.isString()) { | 796 | } else if (object.isString()) { |
| 797 | color.setNamedColor(object.toString()); | 797 | color.setNamedColor(object.toString()); |
| 798 | return true; | ||
| 799 | } else if (object.isArray()) { | ||
| 800 | auto length = object.property("length").toInt32(); | ||
| 801 | auto r = object.property(0).toInt32(); | ||
| 802 | auto g = object.property(1).toInt32(); | ||
| 803 | auto b = object.property(2).toInt32(); | ||
| 804 | |||
| 805 | color.setRed(r); | ||
| 806 | color.setGreen(g); | ||
| 807 | color.setBlue(b); | ||
| 808 | |||
| 809 | if (length == 3) { | ||
| 810 | color.setAlpha(255); | ||
| 811 | } else if (length == 4) { | ||
| 812 | color.setAlpha(object.property(3).toInt32()); | ||
| 813 | } else { | ||
| 814 | return false; | ||
| 815 | } | ||
| 798 | 816 | ||
| 817 | return true; | ||
| 818 | } else if (object.isObject()) { | ||
| 819 | auto r = object.property("red"); | ||
| 820 | auto g = object.property("green"); | ||
| 821 | auto b = object.property("blue"); | ||
| 822 | auto a = object.property("alpha"); | ||
| 823 | |||
| 824 | if (!r.isNumber()) { r = object.property("r"); } | ||
| 825 | if (!g.isNumber()) { g = object.property("g"); } | ||
| 826 | if (!b.isNumber()) { b = object.property("b"); } | ||
| 827 | if (!a.isNumber()) { a = object.property("a"); } | ||
| 828 | |||
| 829 | color.setRed(r.toInt32()); | ||
| 830 | color.setGreen(g.toInt32()); | ||
| 831 | color.setBlue(b.toInt32()); | ||
| 832 | color.setAlpha(a.isNumber() ? a.toInt32() : 255); | ||
| 833 | |||
| 834 | return true; | ||
| 799 | } else { | 835 | } else { |
| 800 | ScriptValue alphaValue = object.property("alpha"); | 836 | return false; |
| 801 | color.setRgb(object.property("red").toInt32(), object.property("green").toInt32(), object.property("blue").toInt32(), | ||
| 802 | alphaValue.isNumber() ? alphaValue.toInt32() : 255); | ||
| 803 | } | 837 | } |
| 804 | return true; | 838 | return true; |
| 805 | } | 839 | } |