diff options
Diffstat (limited to 'src/gui/text/qcssparser.cpp')
-rw-r--r-- | src/gui/text/qcssparser.cpp | 274 |
1 files changed, 174 insertions, 100 deletions
diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp index eff9ffbc8c..7886d9ba91 100644 --- a/src/gui/text/qcssparser.cpp +++ b/src/gui/text/qcssparser.cpp @@ -12,6 +12,7 @@ #include <qfontmetrics.h> #include <qbrush.h> #include <qimagereader.h> +#include <qtextformat.h> #include <algorithm> @@ -35,18 +36,28 @@ struct QCssKnownValue quint64 id; }; +// This array is sorted alphabetically. static const QCssKnownValue properties[NumProperties - 1] = { { "-qt-background-role", QtBackgroundRole }, { "-qt-block-indent", QtBlockIndent }, { "-qt-fg-texture-cachekey", QtForegroundTextureCacheKey }, + { "-qt-foreground", QtForeground }, { "-qt-line-height-type", QtLineHeightType }, { "-qt-list-indent", QtListIndent }, { "-qt-list-number-prefix", QtListNumberPrefix }, { "-qt-list-number-suffix", QtListNumberSuffix }, { "-qt-paragraph-type", QtParagraphType }, + { "-qt-stroke-color", QtStrokeColor }, + { "-qt-stroke-dasharray", QtStrokeDashArray }, + { "-qt-stroke-dashoffset", QtStrokeDashOffset }, + { "-qt-stroke-linecap", QtStrokeLineCap }, + { "-qt-stroke-linejoin", QtStrokeLineJoin }, + { "-qt-stroke-miterlimit", QtStrokeMiterLimit }, + { "-qt-stroke-width", QtStrokeWidth }, { "-qt-style-features", QtStyleFeatures }, { "-qt-table-type", QtTableType }, { "-qt-user-state", QtUserState }, + { "accent-color", QtAccent }, { "alternate-background-color", QtAlternateBackground }, { "background", Background }, { "background-attachment", BackgroundAttachment }, @@ -128,6 +139,7 @@ static const QCssKnownValue properties[NumProperties - 1] = { { "padding-top", PaddingTop }, { "page-break-after", PageBreakAfter }, { "page-break-before", PageBreakBefore }, + { "placeholder-text-color", QtPlaceHolderTextColor }, { "position", Position }, { "right", Right }, { "selection-background-color", QtSelectionBackground }, @@ -154,6 +166,7 @@ static const QCssKnownValue values[NumKnownValues - 1] = { { "always", Value_Always }, { "auto", Value_Auto }, { "base", Value_Base }, + { "beveljoin", Value_BevelJoin}, { "bold", Value_Bold }, { "bottom", Value_Bottom }, { "bright-text", Value_BrightText }, @@ -170,6 +183,7 @@ static const QCssKnownValue values[NumKnownValues - 1] = { { "dot-dot-dash", Value_DotDotDash }, { "dotted", Value_Dotted }, { "double", Value_Double }, + { "flatcap", Value_FlatCap}, { "groove", Value_Groove }, { "highlight", Value_Highlight }, { "highlighted-text", Value_HighlightedText }, @@ -188,6 +202,7 @@ static const QCssKnownValue values[NumKnownValues - 1] = { { "mid", Value_Mid }, { "middle", Value_Middle }, { "midlight", Value_Midlight }, + { "miterjoin", Value_MiterJoin}, { "native", Value_Native }, { "none", Value_None }, { "normal", Value_Normal }, @@ -202,14 +217,18 @@ static const QCssKnownValue values[NumKnownValues - 1] = { { "pre-wrap", Value_PreWrap }, { "ridge", Value_Ridge }, { "right", Value_Right }, + { "roundcap", Value_RoundCap}, + { "roundjoin", Value_RoundJoin}, { "selected", Value_Selected }, { "shadow", Value_Shadow }, { "small" , Value_Small }, { "small-caps", Value_SmallCaps }, { "solid", Value_Solid }, { "square", Value_Square }, + { "squarecap", Value_SquareCap}, { "sub", Value_Sub }, { "super", Value_Super }, + { "svgmiterjoin", Value_SvgMiterJoin}, { "text", Value_Text }, { "top", Value_Top }, { "transparent", Value_Transparent }, @@ -225,10 +244,10 @@ static const QCssKnownValue values[NumKnownValues - 1] = { }; //Map id to strings as they appears in the 'values' array above -static const short indexOfId[NumKnownValues] = { 0, 41, 48, 42, 49, 50, 55, 35, 26, 71, 72, 25, 43, 5, 64, 48, - 29, 59, 60, 27, 52, 62, 6, 10, 39, 56, 19, 13, 17, 18, 20, 21, 51, 24, 46, 68, 37, 3, 2, 40, 63, 16, - 11, 58, 14, 32, 65, 33, 66, 56, 67, 34, 70, 8, 28, 38, 12, 36, 61, 7, 9, 4, 69, 54, 22, 23, 30, 31, - 1, 15, 0, 53, 45, 44 }; +static const short indexOfId[NumKnownValues] = { 0, 44, 51, 45, 52, 53, 60, 37, 28, 78, 79, 27, 46, 6, 71, 50, + 31, 65, 66, 29, 55, 69, 7, 11, 42, 62, 20, 14, 18, 19, 21, 23, 54, 26, 49, 75, 39, 3, 2, 43, 70, 17, 12, + 63, 15, 34, 72, 35, 73, 61, 74, 36, 64, 22, 56, 41, 5, 57, 67, 77, 9, 30, 40, 13, 38, 68, 8, 10, 4, 76, + 59, 24, 25, 32, 33, 1, 16, 0, 58, 48, 47 }; QString Value::toString() const { @@ -391,6 +410,8 @@ LengthData ValueExtractor::lengthValue(const Value& v) if (data.unit != LengthData::None) s.chop(2); + else if (v.type == Value::Percentage) + data.unit = LengthData::Percent; data.number = s.toDouble(); return data; @@ -404,11 +425,20 @@ static int lengthValueFromData(const LengthData& data, const QFont& f) return qRound(qBound(double(INT_MIN) + 0.1, scale * data.number, double(INT_MAX))); } +QTextLength ValueExtractor::textLength(const Declaration &decl) +{ + const LengthData data = lengthValue(decl.d->values.at(0)); + if (data.unit == LengthData::Percent) + return QTextLength(QTextLength::PercentageLength, data.number); + + return QTextLength(QTextLength::FixedLength, lengthValueFromData(data, f)); +} + int ValueExtractor::lengthValue(const Declaration &decl) { if (decl.d->parsed.isValid()) return lengthValueFromData(qvariant_cast<LengthData>(decl.d->parsed), f); - if (decl.d->values.count() < 1) + if (decl.d->values.size() < 1) return 0; LengthData data = lengthValue(decl.d->values.at(0)); decl.d->parsed = QVariant::fromValue<LengthData>(data); @@ -427,7 +457,7 @@ void ValueExtractor::lengthValues(const Declaration &decl, int *m) LengthData datas[4]; int i; - for (i = 0; i < qMin(decl.d->values.count(), 4); i++) + for (i = 0; i < qMin(decl.d->values.size(), 4); i++) datas[i] = lengthValue(decl.d->values[i]); if (i == 0) { @@ -455,7 +485,7 @@ bool ValueExtractor::extractGeometry(int *w, int *h, int *minw, int *minh, int * { extractFont(); bool hit = false; - for (int i = 0; i < declarations.count(); i++) { + for (int i = 0; i < declarations.size(); i++) { const Declaration &decl = declarations.at(i); switch (decl.d->propertyId) { case Width: *w = lengthValue(decl); break; @@ -477,7 +507,7 @@ bool ValueExtractor::extractPosition(int *left, int *top, int *right, int *botto { extractFont(); bool hit = false; - for (int i = 0; i < declarations.count(); i++) { + for (int i = 0; i < declarations.size(); i++) { const Declaration &decl = declarations.at(i); switch (decl.d->propertyId) { case Left: *left = lengthValue(decl); break; @@ -500,7 +530,7 @@ bool ValueExtractor::extractBox(int *margins, int *paddings, int *spacing) { extractFont(); bool hit = false; - for (int i = 0; i < declarations.count(); i++) { + for (int i = 0; i < declarations.size(); i++) { const Declaration &decl = declarations.at(i); switch (decl.d->propertyId) { case PaddingLeft: paddings[LeftEdge] = lengthValue(decl); break; @@ -527,7 +557,7 @@ bool ValueExtractor::extractBox(int *margins, int *paddings, int *spacing) int ValueExtractor::extractStyleFeatures() { int features = StyleFeature_None; - for (int i = 0; i < declarations.count(); i++) { + for (int i = 0; i < declarations.size(); i++) { const Declaration &decl = declarations.at(i); if (decl.d->propertyId == QtStyleFeatures) features = decl.styleFeaturesValue(); @@ -544,9 +574,9 @@ QSize ValueExtractor::sizeValue(const Declaration &decl) } LengthData x[2] = { {0, LengthData::None }, {0, LengthData::None} }; - if (decl.d->values.count() > 0) + if (decl.d->values.size() > 0) x[0] = lengthValue(decl.d->values.at(0)); - if (decl.d->values.count() > 1) + if (decl.d->values.size() > 1) x[1] = lengthValue(decl.d->values.at(1)); else x[1] = x[0]; @@ -568,7 +598,7 @@ bool ValueExtractor::extractBorder(int *borders, QBrush *colors, BorderStyle *st { extractFont(); bool hit = false; - for (int i = 0; i < declarations.count(); i++) { + for (int i = 0; i < declarations.size(); i++) { const Declaration &decl = declarations.at(i); switch (decl.d->propertyId) { case BorderLeftWidth: borders[LeftEdge] = lengthValue(decl); break; @@ -627,7 +657,7 @@ bool ValueExtractor::extractOutline(int *borders, QBrush *colors, BorderStyle *s { extractFont(); bool hit = false; - for (int i = 0; i < declarations.count(); i++) { + for (int i = 0; i < declarations.size(); i++) { const Declaration &decl = declarations.at(i); switch (decl.d->propertyId) { case OutlineWidth: lengthValues(decl, borders); break; @@ -696,7 +726,7 @@ static ColorData parseColorValue(QCss::Value v) return ColorData(); QStringList lst = v.variant.toStringList(); - if (lst.count() != 2) + if (lst.size() != 2) return ColorData(); const QString &identifier = lst.at(0); @@ -726,7 +756,7 @@ static ColorData parseColorValue(QCss::Value v) QList<QCss::Value> colorDigits; if (!p.parseExpr(&colorDigits)) return ColorData(); - const int tokenCount = colorDigits.count(); + const int tokenCount = colorDigits.size(); for (int i = 0; i < qMin(tokenCount, 7); i += 2) { if (colorDigits.at(i).type == Value::Percentage) { @@ -793,7 +823,7 @@ static BrushData parseBrushValue(const QCss::Value &v, const QPalette &pal) return BrushData(); QStringList lst = v.variant.toStringList(); - if (lst.count() != 2) + if (lst.size() != 2) return BrushData(); QStringList gradFuncs; @@ -810,6 +840,10 @@ static BrushData parseBrushValue(const QCss::Value &v, const QPalette &pal) QStringList spreads; spreads << "pad"_L1 << "reflect"_L1 << "repeat"_L1; + int coordinateMode = -1; + QStringList coordinateModes; + coordinateModes << "logical"_L1 << "stretchtodevice"_L1 << "objectbounding"_L1 << "object"_L1; + bool dependsOnThePalette = false; Parser parser(lst.at(1)); while (parser.hasNext()) { @@ -836,11 +870,12 @@ static BrushData parseBrushValue(const QCss::Value &v, const QPalette &pal) parser.next(); QCss::Value value; (void)parser.parseTerm(&value); - if (attr.compare("spread"_L1, Qt::CaseInsensitive) == 0) { + if (attr.compare("spread"_L1, Qt::CaseInsensitive) == 0) spread = spreads.indexOf(value.variant.toString()); - } else { + else if (attr.compare("coordinatemode"_L1, Qt::CaseInsensitive) == 0) + coordinateMode = coordinateModes.indexOf(value.variant.toString()); + else vars[attr] = value.variant.toReal(); - } } parser.skipSpace(); (void)parser.test(COMMA); @@ -849,7 +884,7 @@ static BrushData parseBrushValue(const QCss::Value &v, const QPalette &pal) if (gradType == 0) { QLinearGradient lg(vars.value("x1"_L1), vars.value("y1"_L1), vars.value("x2"_L1), vars.value("y2"_L1)); - lg.setCoordinateMode(QGradient::ObjectBoundingMode); + lg.setCoordinateMode(coordinateMode < 0 ? QGradient::ObjectBoundingMode : QGradient::CoordinateMode(coordinateMode)); lg.setStops(stops); if (spread != -1) lg.setSpread(QGradient::Spread(spread)); @@ -863,7 +898,7 @@ static BrushData parseBrushValue(const QCss::Value &v, const QPalette &pal) QRadialGradient rg(vars.value("cx"_L1), vars.value("cy"_L1), vars.value("radius"_L1), vars.value("fx"_L1), vars.value("fy"_L1)); - rg.setCoordinateMode(QGradient::ObjectBoundingMode); + rg.setCoordinateMode(coordinateMode < 0 ? QGradient::ObjectBoundingMode : QGradient::CoordinateMode(coordinateMode)); rg.setStops(stops); if (spread != -1) rg.setSpread(QGradient::Spread(spread)); @@ -875,7 +910,7 @@ static BrushData parseBrushValue(const QCss::Value &v, const QPalette &pal) if (gradType == 2) { QConicalGradient cg(vars.value("cx"_L1), vars.value("cy"_L1), vars.value("angle"_L1)); - cg.setCoordinateMode(QGradient::ObjectBoundingMode); + cg.setCoordinateMode(coordinateMode < 0 ? QGradient::ObjectBoundingMode : QGradient::CoordinateMode(coordinateMode)); cg.setStops(stops); if (spread != -1) cg.setSpread(QGradient::Spread(spread)); @@ -959,7 +994,7 @@ void ValueExtractor::borderValue(const Declaration &decl, int *width, QCss::Bord if (decl.d->values.at(i).type == Value::Length || decl.d->values.at(i).type == Value::Number) { data.width = lengthValue(decl.d->values.at(i)); *width = lengthValueFromData(data.width, f); - if (++i >= decl.d->values.count()) { + if (++i >= decl.d->values.size()) { decl.d->parsed = QVariant::fromValue<BorderData>(data); return; } @@ -968,7 +1003,7 @@ void ValueExtractor::borderValue(const Declaration &decl, int *width, QCss::Bord data.style = parseStyleValue(decl.d->values.at(i)); if (data.style != BorderStyle_Unknown) { *style = data.style; - if (++i >= decl.d->values.count()) { + if (++i >= decl.d->values.size()) { decl.d->parsed = QVariant::fromValue<BorderData>(data); return; } @@ -977,9 +1012,11 @@ void ValueExtractor::borderValue(const Declaration &decl, int *width, QCss::Bord } data.color = parseBrushValue(decl.d->values.at(i), pal); - *color = brushFromData(data.color, pal); - if (data.color.type != BrushData::DependsOnThePalette) - decl.d->parsed = QVariant::fromValue<BorderData>(data); + if (data.color.type != BrushData::Invalid) { + *color = brushFromData(data.color, pal); + if (data.color.type != BrushData::DependsOnThePalette) + decl.d->parsed = QVariant::fromValue<BorderData>(data); + } } static void parseShorthandBackgroundProperty(const QList<QCss::Value> &values, BrushData *brush, QString *image, Repeat *repeat, Qt::Alignment *alignment, const QPalette &pal) @@ -989,7 +1026,7 @@ static void parseShorthandBackgroundProperty(const QList<QCss::Value> &values, B *repeat = Repeat_XY; *alignment = Qt::AlignTop | Qt::AlignLeft; - for (int i = 0; i < values.count(); ++i) { + for (int i = 0; i < values.size(); ++i) { const QCss::Value &v = values.at(i); if (v.type == Value::Uri) { *image = v.variant.toString(); @@ -1011,7 +1048,7 @@ static void parseShorthandBackgroundProperty(const QList<QCss::Value> &values, B if (v.type == Value::KnownIdentifier) { const int start = i; int count = 1; - if (i < values.count() - 1 + if (i < values.size() - 1 && values.at(i + 1).type == Value::KnownIdentifier) { ++i; ++count; @@ -1033,7 +1070,7 @@ bool ValueExtractor::extractBackground(QBrush *brush, QString *image, Repeat *re Origin *clip) { bool hit = false; - for (int i = 0; i < declarations.count(); ++i) { + for (int i = 0; i < declarations.size(); ++i) { const Declaration &decl = declarations.at(i); if (decl.d->values.isEmpty()) continue; @@ -1181,7 +1218,7 @@ static bool setFontFamilyFromValues(const QList<QCss::Value> &values, QFont *fon QString family; QStringList families; bool shouldAddSpace = false; - for (int i = start; i < values.count(); ++i) { + for (int i = start; i < values.size(); ++i) { const QCss::Value &v = values.at(i); if (v.type == Value::TermOperatorComma) { families << family; @@ -1207,7 +1244,7 @@ static bool setFontFamilyFromValues(const QList<QCss::Value> &values, QFont *fon static void setTextDecorationFromValues(const QList<QCss::Value> &values, QFont *font) { - for (int i = 0; i < values.count(); ++i) { + for (int i = 0; i < values.size(); ++i) { if (values.at(i).type != Value::KnownIdentifier) continue; switch (values.at(i).variant.toInt()) { @@ -1262,7 +1299,7 @@ static void parseShorthandFontProperty(const QList<QCss::Value> &values, QFont * *fontSizeAdjustment = -255; int i = 0; - while (i < values.count()) { + while (i < values.size()) { if (setFontStyleFromValue(values.at(i), font) || setFontWeightFromValue(values.at(i), font)) ++i; @@ -1270,12 +1307,12 @@ static void parseShorthandFontProperty(const QList<QCss::Value> &values, QFont * break; } - if (i < values.count()) { + if (i < values.size()) { setFontSizeFromValue(values.at(i), font, fontSizeAdjustment); ++i; } - if (i < values.count()) { + if (i < values.size()) { setFontFamilyFromValues(values, font, i); } } @@ -1312,7 +1349,7 @@ bool ValueExtractor::extractFont(QFont *font, int *fontSizeAdjustment) } bool hit = false; - for (int i = 0; i < declarations.count(); ++i) { + for (int i = 0; i < declarations.size(); ++i) { const Declaration &decl = declarations.at(i); if (decl.d->values.isEmpty()) continue; @@ -1340,16 +1377,23 @@ bool ValueExtractor::extractFont(QFont *font, int *fontSizeAdjustment) return hit; } -bool ValueExtractor::extractPalette(QBrush *fg, QBrush *sfg, QBrush *sbg, QBrush *abg) +bool ValueExtractor::extractPalette(QBrush *foreground, + QBrush *selectedForeground, + QBrush *selectedBackground, + QBrush *alternateBackground, + QBrush *placeHolderTextForeground, + QBrush *accent) { bool hit = false; - for (int i = 0; i < declarations.count(); ++i) { + for (int i = 0; i < declarations.size(); ++i) { const Declaration &decl = declarations.at(i); switch (decl.d->propertyId) { - case Color: *fg = decl.brushValue(pal); break; - case QtSelectionForeground: *sfg = decl.brushValue(pal); break; - case QtSelectionBackground: *sbg = decl.brushValue(pal); break; - case QtAlternateBackground: *abg = decl.brushValue(pal); break; + case Color: *foreground = decl.brushValue(pal); break; + case QtSelectionForeground: *selectedForeground = decl.brushValue(pal); break; + case QtSelectionBackground: *selectedBackground = decl.brushValue(pal); break; + case QtAlternateBackground: *alternateBackground = decl.brushValue(pal); break; + case QtPlaceHolderTextColor: *placeHolderTextForeground = decl.brushValue(pal); break; + case QtAccent: *accent = decl.brushValue(pal); break; default: continue; } hit = true; @@ -1368,12 +1412,12 @@ void ValueExtractor::extractFont() bool ValueExtractor::extractImage(QIcon *icon, Qt::Alignment *a, QSize *size) { bool hit = false; - for (int i = 0; i < declarations.count(); ++i) { + for (int i = 0; i < declarations.size(); ++i) { const Declaration &decl = declarations.at(i); switch (decl.d->propertyId) { case QtImage: *icon = decl.iconValue(); - if (decl.d->values.count() > 0 && decl.d->values.at(0).type == Value::Uri) { + if (decl.d->values.size() > 0 && decl.d->values.at(0).type == Value::Uri) { // try to pull just the size from the image... QImageReader imageReader(decl.d->values.at(0).variant.toString()); if ((*size = imageReader.size()).isNull()) { @@ -1426,7 +1470,7 @@ bool ValueExtractor::extractIcon(QIcon *icon, QSize *size) // Declaration QColor Declaration::colorValue(const QPalette &pal) const { - if (d->values.count() != 1) + if (d->values.size() != 1) return QColor(); if (d->parsed.isValid()) { @@ -1437,7 +1481,8 @@ QColor Declaration::colorValue(const QPalette &pal) const return pal.color((QPalette::ColorRole)(d->parsed.toInt())); case qMetaTypeId<QList<QVariant>>(): if (d->parsed.toList().size() == 1) { - const auto &value = d->parsed.toList().at(0); + auto parsedList = d->parsed.toList(); + const auto &value = parsedList.at(0); return qvariant_cast<QColor>(value); } break; @@ -1456,7 +1501,7 @@ QColor Declaration::colorValue(const QPalette &pal) const QBrush Declaration::brushValue(const QPalette &pal) const { - if (d->values.count() != 1) + if (d->values.size() != 1) return QBrush(); if (d->parsed.isValid()) { @@ -1487,7 +1532,7 @@ void Declaration::brushValues(QBrush *c, const QPalette &pal) const needParse = 0; Q_ASSERT(d->parsed.metaType() == QMetaType::fromType<QList<QVariant>>()); QList<QVariant> v = d->parsed.toList(); - for (i = 0; i < qMin(v.count(), 4); i++) { + for (i = 0; i < qMin(v.size(), 4); i++) { if (v.at(i).userType() == QMetaType::QBrush) { c[i] = qvariant_cast<QBrush>(v.at(i)); } else if (v.at(i).userType() == QMetaType::Int) { @@ -1499,7 +1544,7 @@ void Declaration::brushValues(QBrush *c, const QPalette &pal) const } if (needParse != 0) { QList<QVariant> v; - for (i = 0; i < qMin(d->values.count(), 4); i++) { + for (i = 0; i < qMin(d->values.size(), 4); i++) { if (!(needParse & (1<<i))) continue; BrushData data = parseBrushValue(d->values.at(i), pal); @@ -1526,7 +1571,7 @@ void Declaration::brushValues(QBrush *c, const QPalette &pal) const bool Declaration::realValue(qreal *real, const char *unit) const { - if (d->values.count() != 1) + if (d->values.size() != 1) return false; const Value &v = d->values.at(0); if (unit && v.type != Value::Length) @@ -1567,7 +1612,7 @@ static bool intValueHelper(const QCss::Value &v, int *i, const char *unit) bool Declaration::intValue(int *i, const char *unit) const { - if (d->values.count() != 1) + if (d->values.size() != 1) return false; return intValueHelper(d->values.at(0), i, unit); } @@ -1578,7 +1623,7 @@ QSize Declaration::sizeValue() const return qvariant_cast<QSize>(d->parsed); int x[2] = { 0, 0 }; - const int count = d->values.count(); + const int count = d->values.size(); for (int i = 0; i < count; ++i) { if (i > 1) { qWarning("QCssParser::sizeValue: Too many values provided"); @@ -1605,7 +1650,7 @@ QSize Declaration::sizeValue() const QRect Declaration::rectValue() const { - if (d->values.count() != 1) + if (d->values.size() != 1) return QRect(); if (d->parsed.isValid()) @@ -1615,10 +1660,10 @@ QRect Declaration::rectValue() const if (v.type != Value::Function) return QRect(); const QStringList func = v.variant.toStringList(); - if (func.count() != 2 || func.at(0).compare("rect"_L1) != 0) + if (func.size() != 2 || func.at(0).compare("rect"_L1) != 0) return QRect(); const auto args = QStringView{func[1]}.split(u' ', Qt::SkipEmptyParts); - if (args.count() != 4) + if (args.size() != 4) return QRect(); QRect rect(args[0].toInt(), args[1].toInt(), args[2].toInt(), args[3].toInt()); d->parsed = QVariant::fromValue<QRect>(rect); @@ -1630,7 +1675,7 @@ void Declaration::colorValues(QColor *c, const QPalette &pal) const int i; if (d->parsed.isValid()) { QList<QVariant> v = d->parsed.toList(); - for (i = 0; i < qMin(d->values.count(), 4); i++) { + for (i = 0; i < qMin(d->values.size(), 4); i++) { if (v.at(i).userType() == QMetaType::QColor) { c[i] = qvariant_cast<QColor>(v.at(i)); } else { @@ -1639,7 +1684,7 @@ void Declaration::colorValues(QColor *c, const QPalette &pal) const } } else { QList<QVariant> v; - for (i = 0; i < qMin(d->values.count(), 4); i++) { + for (i = 0; i < qMin(d->values.size(), 4); i++) { ColorData color = parseColorValue(d->values.at(i)); if (color.type == ColorData::Role) { v += QVariant::fromValue<int>(color.role); @@ -1660,7 +1705,7 @@ void Declaration::colorValues(QColor *c, const QPalette &pal) const BorderStyle Declaration::styleValue() const { - if (d->values.count() != 1) + if (d->values.size() != 1) return BorderStyle_None; return parseStyleValue(d->values.at(0)); } @@ -1668,7 +1713,7 @@ BorderStyle Declaration::styleValue() const void Declaration::styleValues(BorderStyle *s) const { int i; - for (i = 0; i < qMin(d->values.count(), 4); i++) + for (i = 0; i < qMin(d->values.size(), 4); i++) s[i] = parseStyleValue(d->values.at(i)); if (i == 0) s[0] = s[1] = s[2] = s[3] = BorderStyle_None; else if (i == 1) s[3] = s[2] = s[1] = s[0]; @@ -1680,7 +1725,7 @@ Repeat Declaration::repeatValue() const { if (d->parsed.isValid()) return static_cast<Repeat>(d->parsed.toInt()); - if (d->values.count() != 1) + if (d->values.size() != 1) return Repeat_Unknown; int v = findKnownValue(d->values.at(0).variant.toString(), repeats, NumKnownRepeats); @@ -1692,7 +1737,7 @@ Origin Declaration::originValue() const { if (d->parsed.isValid()) return static_cast<Origin>(d->parsed.toInt()); - if (d->values.count() != 1) + if (d->values.size() != 1) return Origin_Unknown; int v = findKnownValue(d->values.at(0).variant.toString(), origins, NumKnownOrigins); @@ -1704,7 +1749,7 @@ PositionMode Declaration::positionValue() const { if (d->parsed.isValid()) return static_cast<PositionMode>(d->parsed.toInt()); - if (d->values.count() != 1) + if (d->values.size() != 1) return PositionMode_Unknown; int v = findKnownValue(d->values.at(0).variant.toString(), positions, NumKnownPositionModes); @@ -1716,7 +1761,7 @@ Attachment Declaration::attachmentValue() const { if (d->parsed.isValid()) return static_cast<Attachment>(d->parsed.toInt()); - if (d->values.count() != 1) + if (d->values.size() != 1) return Attachment_Unknown; int v = findKnownValue(d->values.at(0).variant.toString(), attachments, NumKnownAttachments); @@ -1730,7 +1775,7 @@ int Declaration::styleFeaturesValue() const if (d->parsed.isValid()) return d->parsed.toInt(); int features = StyleFeature_None; - for (int i = 0; i < d->values.count(); i++) { + for (int i = 0; i < d->values.size(); i++) { features |= static_cast<int>(findKnownValue(d->values.value(i).variant.toString(), styleFeatures, NumKnownStyleFeatures)); } @@ -1749,10 +1794,10 @@ Qt::Alignment Declaration::alignmentValue() const { if (d->parsed.isValid()) return Qt::Alignment(d->parsed.toInt()); - if (d->values.isEmpty() || d->values.count() > 2) + if (d->values.isEmpty() || d->values.size() > 2) return Qt::AlignLeft | Qt::AlignTop; - Qt::Alignment v = parseAlignment(d->values.constData(), d->values.count()); + Qt::Alignment v = parseAlignment(d->values.constData(), d->values.size()); d->parsed = int(v); return v; } @@ -1766,12 +1811,12 @@ void Declaration::borderImageValue(QString *image, int *cuts, cuts[i] = -1; *h = *v = TileMode_Stretch; - if (d->values.count() < 2) + if (d->values.size() < 2) return; if (d->values.at(1).type == Value::Number) { // cuts! int i; - for (i = 0; i < qMin(d->values.count()-1, 4); i++) { + for (i = 0; i < qMin(d->values.size()-1, 4); i++) { const Value& v = d->values.at(i+1); if (v.type != Value::Number) break; @@ -1787,9 +1832,9 @@ void Declaration::borderImageValue(QString *image, int *cuts, *v = static_cast<TileMode>(findKnownValue(d->values.last().variant.toString(), tileModes, NumKnownTileModes)); } - if (d->values[d->values.count() - 2].type == Value::Identifier) { + if (d->values[d->values.size() - 2].type == Value::Identifier) { *h = static_cast<TileMode> - (findKnownValue(d->values[d->values.count()-2].variant.toString(), + (findKnownValue(d->values[d->values.size()-2].variant.toString(), tileModes, NumKnownTileModes)); } else *h = *v; @@ -1797,19 +1842,48 @@ void Declaration::borderImageValue(QString *image, int *cuts, bool Declaration::borderCollapseValue() const { - if (d->values.count() != 1) + if (d->values.size() != 1) return false; else return d->values.at(0).toString() == "collapse"_L1; } +QList<qreal> Declaration::dashArray() const +{ + if (d->propertyId != Property::QtStrokeDashArray || d->values.empty()) + return QList<qreal>(); + + bool isValid = true; + QList<qreal> dashes; + for (int i = 0; i < d->values.size(); i++) { + Value v = d->values[i]; + // Separators must be at odd indices and Numbers at even indices. + bool isValidSeparator = (i & 1) && v.type == Value::TermOperatorComma; + bool isValidNumber = !(i & 1) && v.type == Value::Number; + if (!isValidNumber && !isValidSeparator) { + isValid = false; + break; + } else if (isValidNumber) { + bool ok; + dashes.append(v.variant.toReal(&ok)); + if (!ok) { + isValid = false; + break; + } + } + } + + isValid &= !(dashes.size() & 1); + return isValid ? dashes : QList<qreal>(); +} + QIcon Declaration::iconValue() const { if (d->parsed.isValid()) return qvariant_cast<QIcon>(d->parsed); QIcon icon; - for (int i = 0; i < d->values.count();) { + for (int i = 0; i < d->values.size();) { const Value &value = d->values.at(i++); if (value.type != Value::Uri) break; @@ -1817,7 +1891,7 @@ QIcon Declaration::iconValue() const QIcon::Mode mode = QIcon::Normal; QIcon::State state = QIcon::Off; for (int j = 0; j < 2; j++) { - if (i != d->values.count() && d->values.at(i).type == Value::KnownIdentifier) { + if (i != d->values.size() && d->values.at(i).type == Value::KnownIdentifier) { switch (d->values.at(i).variant.toInt()) { case Value_Disabled: mode = QIcon::Disabled; break; case Value_Active: mode = QIcon::Active; break; @@ -1839,7 +1913,7 @@ QIcon Declaration::iconValue() const else icon.addPixmap(uri, mode, state); - if (i == d->values.count()) + if (i == d->values.size()) break; if (d->values.at(i).type == Value::TermOperatorComma) @@ -1855,13 +1929,13 @@ QIcon Declaration::iconValue() const int Selector::specificity() const { int val = 0; - for (int i = 0; i < basicSelectors.count(); ++i) { + for (int i = 0; i < basicSelectors.size(); ++i) { const BasicSelector &sel = basicSelectors.at(i); if (!sel.elementName.isEmpty()) val += 1; - val += (sel.pseudos.count() + sel.attributeSelectors.count()) * 0x10; - val += sel.ids.count() * 0x100; + val += (sel.pseudos.size() + sel.attributeSelectors.size()) * 0x10; + val += sel.ids.size() * 0x100; } return val; } @@ -1880,7 +1954,7 @@ quint64 Selector::pseudoClass(quint64 *negated) const if (bs.pseudos.isEmpty()) return PseudoClass_Unspecified; quint64 pc = PseudoClass_Unknown; - for (int i = !pseudoElement().isEmpty(); i < bs.pseudos.count(); i++) { + for (int i = !pseudoElement().isEmpty(); i < bs.pseudos.size(); i++) { const Pseudo &pseudo = bs.pseudos.at(i); if (pseudo.type == PseudoClass_Unknown) return PseudoClass_Unknown; @@ -1897,23 +1971,23 @@ quint64 Selector::pseudoClass(quint64 *negated) const void StyleSheet::buildIndexes(Qt::CaseSensitivity nameCaseSensitivity) { QList<StyleRule> universals; - for (int i = 0; i < styleRules.count(); ++i) { + for (int i = 0; i < styleRules.size(); ++i) { const StyleRule &rule = styleRules.at(i); QList<Selector> universalsSelectors; - for (int j = 0; j < rule.selectors.count(); ++j) { + for (int j = 0; j < rule.selectors.size(); ++j) { const Selector& selector = rule.selectors.at(j); if (selector.basicSelectors.isEmpty()) continue; if (selector.basicSelectors.at(0).relationToNext == BasicSelector::NoRelation) { - if (selector.basicSelectors.count() != 1) + if (selector.basicSelectors.size() != 1) continue; - } else if (selector.basicSelectors.count() <= 1) { + } else if (selector.basicSelectors.size() <= 1) { continue; } - const BasicSelector &sel = selector.basicSelectors.at(selector.basicSelectors.count() - 1); + const BasicSelector &sel = selector.basicSelectors.at(selector.basicSelectors.size() - 1); if (!sel.ids.isEmpty()) { StyleRule nr; @@ -1967,14 +2041,14 @@ bool StyleSelector::selectorMatches(const Selector &selector, NodePtr node) return false; if (selector.basicSelectors.at(0).relationToNext == BasicSelector::NoRelation) { - if (selector.basicSelectors.count() != 1) + if (selector.basicSelectors.size() != 1) return false; return basicSelectorMatches(selector.basicSelectors.at(0), node); } - if (selector.basicSelectors.count() <= 1) + if (selector.basicSelectors.size() <= 1) return false; - int i = selector.basicSelectors.count() - 1; + int i = selector.basicSelectors.size() - 1; node = duplicateNode(node); bool match = true; @@ -1982,7 +2056,7 @@ bool StyleSelector::selectorMatches(const Selector &selector, NodePtr node) do { match = basicSelectorMatches(sel, node); if (!match) { - if (i == selector.basicSelectors.count() - 1) // first element must always match! + if (i == selector.basicSelectors.size() - 1) // first element must always match! break; if (sel.relationToNext != BasicSelector::MatchNextSelectorIfAncestor && sel.relationToNext != BasicSelector::MatchNextSelectorIfIndirectAdjecent) @@ -2027,7 +2101,7 @@ bool StyleSelector::basicSelectorMatches(const BasicSelector &sel, NodePtr node) if (!hasAttributes(node)) return false; - for (int i = 0; i < sel.attributeSelectors.count(); ++i) { + for (int i = 0; i < sel.attributeSelectors.size(); ++i) { const QCss::AttributeSelector &a = sel.attributeSelectors.at(i); const QString attrValue = attributeValue(node, a); @@ -2090,14 +2164,14 @@ bool StyleSelector::basicSelectorMatches(const BasicSelector &sel, NodePtr node) void StyleSelector::matchRule(NodePtr node, const StyleRule &rule, StyleSheetOrigin origin, int depth, QMultiMap<uint, StyleRule> *weightedRules) { - for (int j = 0; j < rule.selectors.count(); ++j) { + for (int j = 0; j < rule.selectors.size(); ++j) { const Selector& selector = rule.selectors.at(j); if (selectorMatches(selector, node)) { uint weight = rule.order + selector.specificity() *0x100 + (uint(origin) + depth)*0x100000; StyleRule newRule = rule; - if (rule.selectors.count() > 1) { + if (rule.selectors.size() > 1) { newRule.selectors.resize(1); newRule.selectors[0] = selector; } @@ -2118,15 +2192,15 @@ QList<StyleRule> StyleSelector::styleRulesForNode(NodePtr node) QMultiMap<uint, StyleRule> weightedRules; // (spec, rule) that will be sorted below //prune using indexed stylesheet - for (int sheetIdx = 0; sheetIdx < styleSheets.count(); ++sheetIdx) { + for (int sheetIdx = 0; sheetIdx < styleSheets.size(); ++sheetIdx) { const StyleSheet &styleSheet = styleSheets.at(sheetIdx); - for (int i = 0; i < styleSheet.styleRules.count(); ++i) { + for (int i = 0; i < styleSheet.styleRules.size(); ++i) { matchRule(node, styleSheet.styleRules.at(i), styleSheet.origin, styleSheet.depth, &weightedRules); } if (!styleSheet.idIndex.isEmpty()) { QStringList ids = nodeIds(node); - for (int i = 0; i < ids.count(); i++) { + for (int i = 0; i < ids.size(); i++) { const QString &key = ids.at(i); QMultiHash<QString, StyleRule>::const_iterator it = styleSheet.idIndex.constFind(key); while (it != styleSheet.idIndex.constEnd() && it.key() == key) { @@ -2137,7 +2211,7 @@ QList<StyleRule> StyleSelector::styleRulesForNode(NodePtr node) } if (!styleSheet.nameIndex.isEmpty()) { QStringList names = nodeNames(node); - for (int i = 0; i < names.count(); i++) { + for (int i = 0; i < names.size(); i++) { QString name = names.at(i); if (nameCaseSensitivity == Qt::CaseInsensitive) name = std::move(name).toLower(); @@ -2149,9 +2223,9 @@ QList<StyleRule> StyleSelector::styleRulesForNode(NodePtr node) } } if (!medium.isEmpty()) { - for (int i = 0; i < styleSheet.mediaRules.count(); ++i) { + for (int i = 0; i < styleSheet.mediaRules.size(); ++i) { if (styleSheet.mediaRules.at(i).media.contains(medium, Qt::CaseInsensitive)) { - for (int j = 0; j < styleSheet.mediaRules.at(i).styleRules.count(); ++j) { + for (int j = 0; j < styleSheet.mediaRules.at(i).styleRules.size(); ++j) { matchRule(node, styleSheet.mediaRules.at(i).styleRules.at(j), styleSheet.origin, styleSheet.depth, &weightedRules); } @@ -2160,7 +2234,7 @@ QList<StyleRule> StyleSelector::styleRulesForNode(NodePtr node) } } - rules.reserve(weightedRules.count()); + rules.reserve(weightedRules.size()); QMultiMap<uint, StyleRule>::const_iterator it = weightedRules.constBegin(); for ( ; it != weightedRules.constEnd() ; ++it) rules += *it; @@ -2174,7 +2248,7 @@ QList<Declaration> StyleSelector::declarationsForNode(NodePtr node, const char * { QList<Declaration> decls; QList<StyleRule> rules = styleRulesForNode(node); - for (int i = 0; i < rules.count(); i++) { + for (int i = 0; i < rules.size(); i++) { const Selector& selector = rules.at(i).selectors.at(0); const QString pseudoElement = selector.pseudoElement(); @@ -2888,7 +2962,7 @@ bool Parser::next(QCss::TokenType t) bool Parser::test(QCss::TokenType t) { - if (index >= symbols.count()) + if (index >= symbols.size()) return false; if (symbols.at(index).token == t) { ++index; |