QmlJS: Use QmlJS::toQColor to convert a string to a QColor.

The QColor constructor prints a warning if the string it gets passed
isn't a known color name. Also, it doesn't know about the alpha value
in strings like "#ff00ff00".

Reviewed-by: Thomas Hartmann
This commit is contained in:
Christian Kamm
2010-08-13 13:26:44 +02:00
parent b1e1692e23
commit 6ec2174791
2 changed files with 4 additions and 2 deletions

View File

@@ -31,6 +31,7 @@
#include "ui_contextpanewidgetrectangle.h" #include "ui_contextpanewidgetrectangle.h"
#include "contextpanewidget.h" #include "contextpanewidget.h"
#include <qmljs/qmljspropertyreader.h> #include <qmljs/qmljspropertyreader.h>
#include <qmljs/qmljscheck.h>
#include <customcolordialog.h> #include <customcolordialog.h>
#include <QDebug> #include <QDebug>
@@ -79,7 +80,7 @@ void ContextPaneWidgetRectangle::setProperties(QmlJS::PropertyReader *propertyRe
if (propertyReader->hasProperty(QLatin1String("color"))) { if (propertyReader->hasProperty(QLatin1String("color"))) {
QString str = propertyReader->readProperty("color").toString(); QString str = propertyReader->readProperty("color").toString();
if (QColor(str).alpha() == 0) if (QmlJS::toQColor(str).alpha() == 0)
m_none = true; m_none = true;
ui->colorColorButton->setColor(str); ui->colorColorButton->setColor(str);

View File

@@ -30,6 +30,7 @@
#include "qmljspropertyreader.h" #include "qmljspropertyreader.h"
#include "qmljsdocument.h" #include "qmljsdocument.h"
#include <qmljs/parser/qmljsast_p.h> #include <qmljs/parser/qmljsast_p.h>
#include <qmljs/qmljscheck.h>
namespace QmlJS { namespace QmlJS {
@@ -265,7 +266,7 @@ QLinearGradient PropertyReader::parseGradient(const QString &propertyName, bool
if (UiObjectDefinition *objectDefinition = cast<UiObjectDefinition *>(member)) { if (UiObjectDefinition *objectDefinition = cast<UiObjectDefinition *>(member)) {
PropertyReader localParser(m_doc, objectDefinition->initializer); PropertyReader localParser(m_doc, objectDefinition->initializer);
if (localParser.hasProperty("color") && localParser.hasProperty("position")) { if (localParser.hasProperty("color") && localParser.hasProperty("position")) {
QColor color = localParser.readProperty("color").value<QColor>(); QColor color = QmlJS::toQColor(localParser.readProperty("color").toString());
qreal position = localParser.readProperty("position").toReal(); qreal position = localParser.readProperty("position").toReal();
if (localParser.isBindingOrEnum("color") || localParser.isBindingOrEnum("position")) if (localParser.isBindingOrEnum("color") || localParser.isBindingOrEnum("position"))
*isBound = true; *isBound = true;