MCPcopy Create free account
hub / github.com/KDE/labplot / getColorFromHTMLText

Function getColorFromHTMLText

tests/backend/TextLabel/TextLabelTest.cpp:29–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27};
28
29QColor getColorFromHTMLText(const QString& text, const QString& colortype) {
30 const QString htmlColorPattern(QStringLiteral("(#[0-9A-Fa-f]{6})|(transparent)"));
31 QRegularExpression fontColorPattern(colortype + QStringLiteral(":") + htmlColorPattern);
32 QRegularExpressionMatch matchColor = fontColorPattern.match(text);
33 // QVERIFY(matchColor.hasMatch());
34 // QCOMPARE(matchColor.capturedTexts().count(), 1);
35 const auto& splitted = matchColor.capturedTexts().at(0).split(colortype + QStringLiteral(":"));
36 QColor c;
37 if (splitted.length() > 1) {
38 QString color = splitted.at(1);
39 int r = color.mid(1, 2).toInt(nullptr, 16);
40 int g = color.mid(3, 2).toInt(nullptr, 16);
41 int b = color.mid(5, 2).toInt(nullptr, 16);
42
43 c = QColor(r, g, b);
44 } else {
45 c = QColor(Qt::transparent);
46 }
47 return c;
48}
49
50#define STORETEXTPROPERTIES(label, propertyVariable) \
51 TextProperties propertyVariable; \

Callers 1

TextLabelTest.cppFile · 0.85

Calls 3

splitMethod · 0.80
lengthMethod · 0.80
QColorClass · 0.50

Tested by

no test coverage detected