use QColor::name() instead of expensive conversions in QStaticTextPrivate::paintText() and QSvgPaintEngine::saveGradientStops()

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2021-09-09 19:34:56 +03:00
parent 0cfbbb99f4
commit 186c8b17ab
2 changed files with 4 additions and 11 deletions

View file

@ -566,11 +566,9 @@ void QStaticTextPrivate::paintText(const QPointF &topLeftPosition, QPainter *p)
} else {
QTextDocument document;
#ifndef QT_NO_CSSPARSER
QColor color = p->pen().color();
document.setDefaultStyleSheet(QString::fromLatin1("body { color: #%1%2%3 }")
.arg(QString::number(color.red(), 16), 2, QLatin1Char('0'))
.arg(QString::number(color.green(), 16), 2, QLatin1Char('0'))
.arg(QString::number(color.blue(), 16), 2, QLatin1Char('0')));
const QColor color = p->pen().color();
document.setDefaultStyleSheet(QString::fromLatin1("body { color: %1 }")
.arg(color.name()));
#endif
document.setDefaultFont(font);
document.setDocumentMargin(0.0);

View file

@ -257,13 +257,8 @@ public:
}
foreach(QGradientStop stop, stops) {
QString color =
QString::fromLatin1("#%1%2%3")
.arg(stop.second.red(), 2, 16, QLatin1Char('0'))
.arg(stop.second.green(), 2, 16, QLatin1Char('0'))
.arg(stop.second.blue(), 2, 16, QLatin1Char('0'));
str << QLatin1String(" <stop offset=\"")<< stop.first << QLatin1String("\" ")
<< QLatin1String("stop-color=\"") << color << QLatin1String("\" ")
<< QLatin1String("stop-color=\"") << stop.second.name() << QLatin1String("\" ")
<< QLatin1String("stop-opacity=\"") << stop.second.alphaF() <<QLatin1String("\" />\n");
}
}