summaryrefslogtreecommitdiffstats
path: root/src/gui/painting/qcolor.cpp
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@nokia.com>2010-03-01 15:17:42 +0100
committerErik Verbruggen <erik.verbruggen@nokia.com>2010-03-01 15:20:21 +0100
commit72da039e54a62bf3a481fefc753e0e50ba75df57 (patch)
tree8ca6e0e3797b84ac0e43b853f874be8cfe55027c /src/gui/painting/qcolor.cpp
parent244d4d5610ce288503a73d0aa86f257dce4e74e6 (diff)
Added static method isValidColor to QColor.
Reviewed-by: Gunnar Sletta
Diffstat (limited to 'src/gui/painting/qcolor.cpp')
-rw-r--r--src/gui/painting/qcolor.cpp28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/gui/painting/qcolor.cpp b/src/gui/painting/qcolor.cpp
index d6d288ef95..1b4316143f 100644
--- a/src/gui/painting/qcolor.cpp
+++ b/src/gui/painting/qcolor.cpp
@@ -532,25 +532,46 @@ QString QColor::name() const
void QColor::setNamedColor(const QString &name)
{
+ if (!setColorFromString(name))
+ qWarning("QColor::setNamedColor: Unknown color name '%s'", name.toLatin1().constData());
+}
+
+/*!
+ Checks if the \a name is a valid color name. The algorithm used is the same as with
+ \a setNamedColor().
+
+ \return true if the color name is valid, false otherwise.
+
+ \sa setNamedColor()
+*/
+bool QColor::isValidColor(const QString &name)
+{
+ return QColor().setColorFromString(name);
+}
+
+bool QColor::setColorFromString(const QString &name)
+{
if (name.isEmpty()) {
invalidate();
- return;
+ return false;
}
if (name.startsWith(QLatin1Char('#'))) {
QRgb rgb;
if (qt_get_hex_rgb(name.constData(), name.length(), &rgb)) {
setRgb(rgb);
+ return true;
} else {
invalidate();
+ return false;
}
- return;
}
#ifndef QT_NO_COLORNAMES
QRgb rgb;
if (qt_get_named_rgb(name.constData(), name.length(), &rgb)) {
setRgba(rgb);
+ return true;
} else
#endif
{
@@ -561,11 +582,12 @@ void QColor::setNamedColor(const QString &name)
&& QX11Info::display()
&& XParseColor(QX11Info::display(), QX11Info::appColormap(), name.toLatin1().constData(), &result)) {
setRgb(result.red >> 8, result.green >> 8, result.blue >> 8);
+ return true;
} else
#endif
{
- qWarning("QColor::setNamedColor: Unknown color name '%s'", name.toLatin1().constData());
invalidate();
+ return false;
}
}
}