aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2014-03-28 13:30:00 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-28 17:41:41 +0100
commit9614dc2c51b54e32de7dac3543c3e044d0b3c240 (patch)
tree7f426409e43d036a82238a8086c4843295a6b519
parentbc030defad916b073ede55d7a7ad8db9a41e0ad2 (diff)
Remove custom code for converting from QString to QColor
After commit 9b021a1fbd0b974a452a6e18a8c0b4b97cbf8edb in qtbase we can now (about a year later ;-) remove the custom code from handling alpha when converting from string to color and rely on the implementation in qtbase. Change-Id: Ia8086c99f0f782742d3adf12cb2c3b79dee8d578 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
-rw-r--r--src/quick/util/qquickglobal.cpp52
1 files changed, 5 insertions, 47 deletions
diff --git a/src/quick/util/qquickglobal.cpp b/src/quick/util/qquickglobal.cpp
index 5ae74c2fec..4428452aa0 100644
--- a/src/quick/util/qquickglobal.cpp
+++ b/src/quick/util/qquickglobal.cpp
@@ -61,23 +61,9 @@ QT_BEGIN_NAMESPACE
class QQuickColorProvider : public QQmlColorProvider
{
public:
- static inline QColor QColorFromString(const QString &s)
- {
- // Should we also handle #rrggbb here?
- if (s.length() == 9 && s.startsWith(QLatin1Char('#'))) {
- uchar a = fromHex(s, 1);
- uchar r = fromHex(s, 3);
- uchar g = fromHex(s, 5);
- uchar b = fromHex(s, 7);
- return QColor(r, g, b, a);
- }
-
- return QColor(s);
- }
-
QVariant colorFromString(const QString &s, bool *ok)
{
- QColor c(QColorFromString(s));
+ QColor c(s);
if (c.isValid()) {
if (ok) *ok = true;
return QVariant(c);
@@ -89,7 +75,7 @@ public:
unsigned rgbaFromString(const QString &s, bool *ok)
{
- QColor c(QColorFromString(s));
+ QColor c(s);
if (c.isValid()) {
if (ok) *ok = true;
return c.rgba();
@@ -155,34 +141,6 @@ public:
return QVariant::fromValue(QColor::fromRgbF(r, g, b, a + inv_a * baseColor.alphaF()));
}
-
-private:
- static uchar fromHex(const uchar c, const uchar c2)
- {
- uchar rv = 0;
- if (c >= '0' && c <= '9')
- rv += (c - '0') * 16;
- else if (c >= 'A' && c <= 'F')
- rv += (c - 'A' + 10) * 16;
- else if (c >= 'a' && c <= 'f')
- rv += (c - 'a' + 10) * 16;
-
- if (c2 >= '0' && c2 <= '9')
- rv += (c2 - '0');
- else if (c2 >= 'A' && c2 <= 'F')
- rv += (c2 - 'A' + 10);
- else if (c2 >= 'a' && c2 <= 'f')
- rv += (c2 - 'a' + 10);
-
- return rv;
- }
-
- static inline uchar fromHex(const QString &s, int idx)
- {
- uchar c = s.at(idx).toLatin1();
- uchar c2 = s.at(idx + 1).toLatin1();
- return fromHex(c, c2);
- }
};
@@ -639,7 +597,7 @@ public:
switch (type) {
case QMetaType::QColor:
- return createFromStringTyped<QColor>(data, dataSize, QQuickColorProvider::QColorFromString(s));
+ return createFromStringTyped<QColor>(data, dataSize, QColor(s));
case QMetaType::QVector2D:
return createFromStringTyped<QVector2D>(data, dataSize, vector2DFromString(s, &ok));
case QMetaType::QVector3D:
@@ -677,7 +635,7 @@ public:
bool variantFromString(const QString &s, QVariant *v)
{
- QColor c(QQuickColorProvider::QColorFromString(s));
+ QColor c(s);
if (c.isValid()) {
*v = QVariant::fromValue(c);
return true;
@@ -725,7 +683,7 @@ public:
switch (type) {
case QMetaType::QColor:
{
- QColor c(QQuickColorProvider::QColorFromString(s));
+ QColor c(s);
*v = QVariant::fromValue(c);
return true;
}