diff options
author | Albert Astals Cid <albert.astals@canonical.com> | 2013-04-25 10:59:35 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-04-26 09:59:04 +0200 |
commit | 9b021a1fbd0b974a452a6e18a8c0b4b97cbf8edb (patch) | |
tree | 8cbb52f561e6d3a64bc46a3be3d0fbe259d1600c /src/gui/painting/qcolor_p.cpp | |
parent | 08585f02dc0eb8dc5567f47c55915540c0a34e01 (diff) |
Make QColor understand #AARRGGBB
This way I can have in my QtQuick something like
Text {
text: "<font color='#ff0000'>H</font> <font color='#99ff0000'>H</font>"
}
and it works properly
QtQuick already supports #AARRGGBB for color: properties so I've
decided to go the notation
Once this is merged we can remove the extra code
in QQuickColorProvider::QColorFromString
I've also added some tests for the hex -> QColor conversion that where
non existent
Change-Id: I1dd4a2ec113293aec26968329b2e4930df6fdcb7
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
Diffstat (limited to 'src/gui/painting/qcolor_p.cpp')
-rw-r--r-- | src/gui/painting/qcolor_p.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/gui/painting/qcolor_p.cpp b/src/gui/painting/qcolor_p.cpp index 35e607ec54..b913f5338c 100644 --- a/src/gui/painting/qcolor_p.cpp +++ b/src/gui/painting/qcolor_p.cpp @@ -79,7 +79,8 @@ bool qt_get_hex_rgb(const char *name, QRgb *rgb) return false; name++; int len = qstrlen(name); - int r, g, b; + int a, r, g, b; + a = 255; if (len == 12) { r = hex2int(name); g = hex2int(name + 4); @@ -88,6 +89,11 @@ bool qt_get_hex_rgb(const char *name, QRgb *rgb) r = hex2int(name); g = hex2int(name + 3); b = hex2int(name + 6); + } else if (len == 8) { + a = hex2int(name); + r = hex2int(name + 2); + g = hex2int(name + 4); + b = hex2int(name + 6); } else if (len == 6) { r = hex2int(name); g = hex2int(name + 2); @@ -99,11 +105,11 @@ bool qt_get_hex_rgb(const char *name, QRgb *rgb) } else { r = g = b = -1; } - if ((uint)r > 255 || (uint)g > 255 || (uint)b > 255) { + if ((uint)r > 255 || (uint)g > 255 || (uint)b > 255 || (uint)a > 255) { *rgb = 0; return false; } - *rgb = qRgb(r, g ,b); + *rgb = qRgba(r, g ,b, a); return true; } |