From 775c5e0f3d6a10f6bcc31ef88cf9cf225ba96343 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Mon, 17 Jun 2019 21:39:08 +0000 Subject: [PATCH] QColor cleanup Signed-off-by: Ivailo Monev --- src/gui/painting/qcolor.cpp | 8 ++++---- src/gui/painting/qcolor_p.cpp | 37 ++++------------------------------- src/gui/painting/qcolor_p.h | 1 - 3 files changed, 8 insertions(+), 38 deletions(-) diff --git a/src/gui/painting/qcolor.cpp b/src/gui/painting/qcolor.cpp index ce821293d..9ae522fe7 100644 --- a/src/gui/painting/qcolor.cpp +++ b/src/gui/painting/qcolor.cpp @@ -52,7 +52,7 @@ # include "qx11info_x11.h" # include "qt_x11_p.h" -static bool allowX11ColorNames = false; +static bool qAllowX11ColorNames = false; #endif @@ -550,7 +550,7 @@ bool QColor::setNamedColor(const QString &name) #ifndef QT_NO_COLORNAMES QRgb rgb; - if (qt_get_named_rgb(name.toLatin1(), &rgb)) { + if (qt_get_named_rgb(name.toLower().toLatin1(), &rgb)) { setRgba(rgb); return true; } else @@ -2393,7 +2393,7 @@ QColor::operator QVariant() const */ bool QColor::allowX11ColorNames() { - return ::allowX11ColorNames; + return qAllowX11ColorNames; } /*! @@ -2407,7 +2407,7 @@ bool QColor::allowX11ColorNames() */ void QColor::setAllowX11ColorNames(bool enabled) { - ::allowX11ColorNames = enabled; + qAllowX11ColorNames = enabled; } #endif diff --git a/src/gui/painting/qcolor_p.cpp b/src/gui/painting/qcolor_p.cpp index 7492d8d76..7546da8bc 100644 --- a/src/gui/painting/qcolor_p.cpp +++ b/src/gui/painting/qcolor_p.cpp @@ -268,10 +268,9 @@ inline bool operator<(const char *name, const RGBData &data) inline bool operator<(const RGBData &data, const char *name) { return qstrcmp(data.name, name) < 0; } -static bool get_named_rgb(const char *name_no_space, QRgb *rgb) +bool qt_get_named_rgb(const char *name, QRgb* rgb) { - QByteArray name = QByteArray::fromRawData(name_no_space, qstrlen(name_no_space)).toLower(); - const RGBData *r = qBinaryFind(rgbTbl, rgbTbl + rgbTblSize, name.constData()); + const RGBData *r = qBinaryFind(rgbTbl, rgbTbl + rgbTblSize, name); if (r != rgbTbl + rgbTblSize) { *rgb = r->value; return true; @@ -279,36 +278,12 @@ static bool get_named_rgb(const char *name_no_space, QRgb *rgb) return false; } -bool qt_get_named_rgb(const char *name, QRgb* rgb) -{ - int len = int(strlen(name)); - if(len > 255) - return false; - char name_no_space[256]; - int pos = 0; - for(int i = 0; i < len; i++) { - if(name[i] != '\t' && name[i] != ' ') - name_no_space[pos++] = name[i]; - } - name_no_space[pos] = 0; - - return get_named_rgb(name_no_space, rgb); -} - -uint qt_get_rgb_val(const char *name) -{ - QRgb r = 0; - qt_get_named_rgb(name,&r); - return r; -} - QStringList qt_get_colornames() { - int i = 0; static QStringList lst; if (lst.isEmpty()) { - for (i = 0; i < rgbTblSize; i++) - lst << QLatin1String(rgbTbl[i].name); + for (int i = 0; i < rgbTblSize; i++) + lst << QString::fromLatin1(rgbTbl[i].name); } return lst; } @@ -320,10 +295,6 @@ bool qt_get_named_rgb(const char *, QRgb*) return false; } -uint qt_get_rgb_val(const char *) -{ - return 0; -} QStringList qt_get_colornames() { return QStringList(); diff --git a/src/gui/painting/qcolor_p.h b/src/gui/painting/qcolor_p.h index afbfddf47..9d32edc1a 100644 --- a/src/gui/painting/qcolor_p.h +++ b/src/gui/painting/qcolor_p.h @@ -50,7 +50,6 @@ QT_BEGIN_NAMESPACE -uint qt_get_rgb_val(const char *name); bool qt_get_named_rgb(const char *, QRgb*); bool qt_get_hex_rgb(const char *, QRgb *); QStringList qt_get_colornames();