OSDN Git Service

use QColor::name() instead of expensive conversions in QStaticTextPrivate::paintText...
authorIvailo Monev <xakepa10@gmail.com>
Thu, 9 Sep 2021 16:34:56 +0000 (19:34 +0300)
committerIvailo Monev <xakepa10@gmail.com>
Thu, 9 Sep 2021 16:34:56 +0000 (19:34 +0300)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/gui/text/qstatictext.cpp
src/svg/qsvggenerator.cpp

index 9bcc0e1..933b0a3 100644 (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);        
index 354986e..9c4be6f 100644 (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");
         }
     }