From 9614dc2c51b54e32de7dac3543c3e044d0b3c240 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 28 Mar 2014 13:30:00 +0100 Subject: Remove custom code for converting from QString to QColor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/quick/util/qquickglobal.cpp | 52 ++++------------------------------------- 1 file 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(data, dataSize, QQuickColorProvider::QColorFromString(s)); + return createFromStringTyped(data, dataSize, QColor(s)); case QMetaType::QVector2D: return createFromStringTyped(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; } -- cgit v1.2.3