mirror of
https://github.com/tumic0/QtPBFImagePlugin.git
synced 2024-11-23 19:25:55 +01:00
Added support for named (HTML) colors
This commit is contained in:
parent
f96b530fa3
commit
c3df78a455
@ -13,9 +13,7 @@ QColor Color::fromJsonString(const QString &str)
|
|||||||
{
|
{
|
||||||
QColor ret;
|
QColor ret;
|
||||||
|
|
||||||
if (str.startsWith('#'))
|
if (str.startsWith("rgb(")) {
|
||||||
return QColor(str);
|
|
||||||
else if (str.startsWith("rgb(")) {
|
|
||||||
QStringList comp(str.mid(4, str.size() - 5).split(','));
|
QStringList comp(str.mid(4, str.size() - 5).split(','));
|
||||||
if (comp.size() != 3)
|
if (comp.size() != 3)
|
||||||
return QColor();
|
return QColor();
|
||||||
@ -39,7 +37,8 @@ QColor Color::fromJsonString(const QString &str)
|
|||||||
return QColor();
|
return QColor();
|
||||||
ret = QColor::fromHslF(comp.at(0).toFloat() / 360.0, pval(comp.at(1)),
|
ret = QColor::fromHslF(comp.at(0).toFloat() / 360.0, pval(comp.at(1)),
|
||||||
pval(comp.at(2)), comp.at(3).toFloat());
|
pval(comp.at(2)), comp.at(3).toFloat());
|
||||||
}
|
} else
|
||||||
|
ret = QColor(str);
|
||||||
|
|
||||||
if (!ret.isValid())
|
if (!ret.isValid())
|
||||||
qWarning() << str << ": invalid color";
|
qWarning() << str << ": invalid color";
|
||||||
|
Loading…
Reference in New Issue
Block a user