mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-24 19:02:59 +00:00
optimize QColor::isValidColor()
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
6657a86017
commit
27e5b160db
1 changed files with 34 additions and 4 deletions
|
@ -699,10 +699,9 @@ bool QColor::setNamedColor(const QString &name)
|
|||
if (qt_get_hex_rgb(latin.constData(), latin.length(), &rgb)) {
|
||||
setRgb(rgb);
|
||||
return true;
|
||||
} else {
|
||||
invalidate();
|
||||
return false;
|
||||
}
|
||||
invalidate();
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifndef QT_NO_COLORNAMES
|
||||
|
@ -742,7 +741,38 @@ bool QColor::setNamedColor(const QString &name)
|
|||
*/
|
||||
bool QColor::isValidColor(const QString &name)
|
||||
{
|
||||
return !name.isEmpty() && QColor().setNamedColor(name);
|
||||
if (name.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QByteArray latin = name.toLatin1();
|
||||
if (name.startsWith(QLatin1Char('#'))) {
|
||||
QRgb rgb;
|
||||
if (qt_get_hex_rgb(latin.constData(), latin.length(), &rgb)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifndef QT_NO_COLORNAMES
|
||||
for (qint16 i = 0; i < rgbTblSize; i++) {
|
||||
if (qstrnicmp(rgbTbl[i].name, latin.constData(), latin.length()) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef Q_WS_X11
|
||||
XColor result;
|
||||
if (allowX11ColorNames()
|
||||
&& QApplication::instance()
|
||||
&& QX11Info::display()
|
||||
&& XParseColor(QX11Info::display(), QX11Info::appColormap(), latin.constData(), &result)) {
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
Loading…
Add table
Reference in a new issue