7#include <QtCore/qmap.h>
13#include <qfontmetrics.h>
15#include <qimagereader.h>
16#include <qtextformat.h>
18#include <QtCore/q20algorithm.h>
20#ifndef QT_NO_CSSPARSER
24using namespace Qt::StringLiterals;
26QT_IMPL_METATYPE_EXTERN_TAGGED(QCss::BackgroundData, QCss__BackgroundData)
27QT_IMPL_METATYPE_EXTERN_TAGGED(QCss::LengthData, QCss__LengthData)
28QT_IMPL_METATYPE_EXTERN_TAGGED(QCss::BorderData, QCss__BorderData)
47 {
return std::string_view{lhs.name} < std::string_view{rhs.name}; }
49#if !defined(Q_CC_GNU_ONLY) || Q_CC_GNU >= 1000
50# define NOT_OLD_GCCs(...) __VA_ARGS__
52# define NOT_OLD_GCCs(...)
54#define CHECK_ARRAY_IS_SORTED(array, type)
56 static_assert(q20::is_sorted(std::begin(array), std::end(array),
57 QCssKnownValue<type>::ByName{}));
277 0, 46, 54, 47, 55, 56, 63, 38, 29, 83, 84, 28, 48, 7, 76, 52,
278 32, 68, 69, 30, 58, 74, 8, 12, 43, 65, 21, 15, 19, 20, 22, 24,
279 57, 27, 51, 80, 40, 4, 3, 45, 75, 18, 13, 66, 16, 35, 77, 36,
280 78, 64, 79, 37, 67, 23, 59, 42, 6, 60, 70, 82, 10, 31, 41, 14,
281 39, 71, 9, 11, 5, 81, 62, 25, 26, 33, 34, 2, 44, 72, 73, 53,
282 0, 17, 1, 61, 50, 49 };
284static_assert(std::size(indexOfId) == std::size(values) + 1);
289 return QLatin1StringView(values[indexOfId[variant.toInt()]].name);
291 return variant.toString();
296 {
"active", PseudoClass_Active },
297 {
"adjoins-item", PseudoClass_Item },
298 {
"alternate", PseudoClass_Alternate },
299 {
"bottom", PseudoClass_Bottom },
300 {
"checked", PseudoClass_Checked },
301 {
"closable", PseudoClass_Closable },
302 {
"closed", PseudoClass_Closed },
303 {
"default", PseudoClass_Default },
304 {
"disabled", PseudoClass_Disabled },
305 {
"edit-focus", PseudoClass_EditFocus },
306 {
"editable", PseudoClass_Editable },
307 {
"enabled", PseudoClass_Enabled },
308 {
"exclusive", PseudoClass_Exclusive },
309 {
"first", PseudoClass_First },
310 {
"flat", PseudoClass_Flat },
311 {
"floatable", PseudoClass_Floatable },
312 {
"focus", PseudoClass_Focus },
313 {
"has-children", PseudoClass_Children },
314 {
"has-siblings", PseudoClass_Sibling },
315 {
"horizontal", PseudoClass_Horizontal },
316 {
"hover", PseudoClass_Hover },
317 {
"indeterminate" , PseudoClass_Indeterminate },
318 {
"last", PseudoClass_Last },
319 {
"left", PseudoClass_Left },
320 {
"maximized", PseudoClass_Maximized },
321 {
"middle", PseudoClass_Middle },
322 {
"minimized", PseudoClass_Minimized },
323 {
"movable", PseudoClass_Movable },
324 {
"next-selected", PseudoClass_NextSelected },
325 {
"no-frame", PseudoClass_Frameless },
326 {
"non-exclusive", PseudoClass_NonExclusive },
327 {
"off", PseudoClass_Unchecked },
328 {
"on", PseudoClass_Checked },
329 {
"only-one", PseudoClass_OnlyOne },
330 {
"open", PseudoClass_Open },
331 {
"pressed", PseudoClass_Pressed },
332 {
"previous-selected", PseudoClass_PreviousSelected },
333 {
"read-only", PseudoClass_ReadOnly },
334 {
"right", PseudoClass_Right },
335 {
"selected", PseudoClass_Selected },
336 {
"top", PseudoClass_Top },
337 {
"unchecked" , PseudoClass_Unchecked },
338 {
"vertical", PseudoClass_Vertical },
339 {
"window", PseudoClass_Window }
390 return QString::compare(name, QLatin1StringView(prop.name), Qt::CaseInsensitive) < 0;
396 return QString::compare(QLatin1StringView(prop.name), name, Qt::CaseInsensitive) < 0;
399#undef CHECK_ARRAY_IS_SORTED
405 const auto *prop = std::lower_bound(std::begin(arr), std::end(arr), name);
406 if ((prop == std::end(arr)) || (name < *prop))
407 return static_cast<
decltype(prop->id)>(0);
413 switch (propertyId) {
439ValueExtractor::ValueExtractor(
const QList<Declaration> &decls,
const QPalette &pal)
440: declarations(decls), adjustment(0), fontExtracted(
false), pal(pal)
444LengthData ValueExtractor::lengthValue(
const Value& v)
446 const QString str = v.variant.toString();
449 data.unit = LengthData::None;
450 if (s.endsWith(u"px", Qt::CaseInsensitive))
451 data.unit = LengthData::Px;
452 else if (s.endsWith(u"ex", Qt::CaseInsensitive))
453 data.unit = LengthData::Ex;
454 else if (s.endsWith(u"em", Qt::CaseInsensitive))
455 data.unit = LengthData::Em;
457 if (data.unit != LengthData::None)
459 else if (v.type == Value::Percentage)
460 data.unit = LengthData::Percent;
462 data.number = s.toDouble();
468 const int scale = (data.unit ==
LengthData::Ex ? QFontMetrics(f).xHeight()
471 return qRound(qBound(
double(INT_MIN) + 0.1, scale * data.number,
double(INT_MAX)));
474QTextLength ValueExtractor::textLength(
const Declaration &decl)
476 const LengthData data = lengthValue(decl.d->values.at(0));
477 if (data.unit == LengthData::Percent)
478 return QTextLength(QTextLength::PercentageLength, data.number);
480 return QTextLength(QTextLength::FixedLength, lengthValueFromData(data, f));
483int ValueExtractor::lengthValue(
const Declaration &decl)
485 if (decl.d->parsed.isValid())
486 return lengthValueFromData(qvariant_cast<LengthData>(decl.d->parsed), f);
487 if (decl.d->values.size() < 1)
489 LengthData data = lengthValue(decl.d->values.at(0));
490 decl.d->parsed = QVariant::fromValue<LengthData>(data);
491 return lengthValueFromData(data,f);
494void ValueExtractor::lengthValues(
const Declaration &decl,
int *m)
496 if (decl.d->parsed.isValid()) {
497 QList<QVariant> v = decl.d->parsed.toList();
498 Q_ASSERT(v.size() == 4);
499 for (
int i = 0; i < 4; i++)
500 m[i] = lengthValueFromData(qvariant_cast<LengthData>(v.at(i)), f);
506 for (i = 0; i < qMin(decl.d->values.size(), 4); i++)
507 datas[i] = lengthValue(decl.d->values[i]);
510 LengthData zero = {0.0, LengthData::None};
511 datas[0] = datas[1] = datas[2] = datas[3] = zero;
513 datas[3] = datas[2] = datas[1] = datas[0];
523 for (i = 0; i < 4; i++) {
524 v += QVariant::fromValue<LengthData>(datas[i]);
525 m[i] = lengthValueFromData(datas[i], f);
527 decl.d->parsed = std::move(v);
530bool ValueExtractor::extractGeometry(
int *w,
int *h,
int *minw,
int *minh,
int *maxw,
int *maxh)
534 for (
const Declaration &decl : std::as_const(declarations)) {
535 switch (decl.d->propertyId) {
536 case Property::Width: *w = lengthValue(decl);
break;
537 case Property::Height: *h = lengthValue(decl);
break;
538 case Property::MinimumWidth: *minw = lengthValue(decl);
break;
539 case Property::MinimumHeight: *minh = lengthValue(decl);
break;
540 case Property::MaximumWidth: *maxw = lengthValue(decl);
break;
541 case Property::MaximumHeight: *maxh = lengthValue(decl);
break;
550bool ValueExtractor::extractPosition(
int *left,
int *top,
int *right,
int *bottom, QCss::Origin *origin,
551 Qt::Alignment *position, QCss::PositionMode *mode, Qt::Alignment *textAlignment)
555 for (
const Declaration &decl : std::as_const(declarations)) {
556 switch (decl.d->propertyId) {
557 case Property::Left: *left = lengthValue(decl);
break;
558 case Property::Top: *top = lengthValue(decl);
break;
559 case Property::Right: *right = lengthValue(decl);
break;
560 case Property::Bottom: *bottom = lengthValue(decl);
break;
561 case Property::QtOrigin: *origin = decl.originValue();
break;
562 case Property::QtPosition: *position = decl.alignmentValue();
break;
563 case Property::TextAlignment: *textAlignment = decl.alignmentValue();
break;
564 case Property::Position: *mode = decl.positionValue();
break;
573bool ValueExtractor::extractBox(
int *margins,
int *paddings,
int *spacing)
577 for (
const Declaration &decl : std::as_const(declarations)) {
578 switch (decl.d->propertyId) {
579 case Property::PaddingLeft: paddings[LeftEdge] = lengthValue(decl);
break;
580 case Property::PaddingRight: paddings[RightEdge] = lengthValue(decl);
break;
581 case Property::PaddingTop: paddings[TopEdge] = lengthValue(decl);
break;
582 case Property::PaddingBottom: paddings[BottomEdge] = lengthValue(decl);
break;
583 case Property::Padding: lengthValues(decl, paddings);
break;
585 case Property::MarginLeft: margins[LeftEdge] = lengthValue(decl);
break;
586 case Property::MarginRight: margins[RightEdge] = lengthValue(decl);
break;
587 case Property::MarginTop: margins[TopEdge] = lengthValue(decl);
break;
588 case Property::MarginBottom: margins[BottomEdge] = lengthValue(decl);
break;
589 case Property::Margin: lengthValues(decl, margins);
break;
590 case Property::QtSpacing:
if (spacing) *spacing = lengthValue(decl);
break;
600int ValueExtractor::extractStyleFeatures()
const
602 int features = StyleFeature_None;
603 for (
const Declaration &decl : declarations) {
604 if (decl.d->propertyId == Property::QtStyleFeatures)
605 features = decl.styleFeaturesValue();
610QSize ValueExtractor::sizeValue(
const Declaration &decl)
612 if (decl.d->parsed.isValid()) {
613 QList<QVariant> v = decl.d->parsed.toList();
614 return QSize(lengthValueFromData(qvariant_cast<LengthData>(v.at(0)), f),
615 lengthValueFromData(qvariant_cast<LengthData>(v.at(1)), f));
618 LengthData x[2] = { {0, LengthData::None }, {0, LengthData::None} };
619 if (decl.d->values.size() > 0)
620 x[0] = lengthValue(decl.d->values.at(0));
621 if (decl.d->values.size() > 1)
622 x[1] = lengthValue(decl.d->values.at(1));
626 v << QVariant::fromValue<LengthData>(x[0]) << QVariant::fromValue<LengthData>(x[1]);
627 decl.d->parsed = std::move(v);
628 return QSize(lengthValueFromData(x[0], f), lengthValueFromData(x[1], f));
631void ValueExtractor::sizeValues(
const Declaration &decl, QSize *radii)
633 radii[0] = sizeValue(decl);
634 for (
int i = 1; i < 4; i++)
638bool ValueExtractor::extractBorder(
int *borders, QBrush *colors, BorderStyle *styles,
643 for (
const Declaration &decl : std::as_const(declarations)) {
644 switch (decl.d->propertyId) {
645 case Property::BorderLeftWidth: borders[LeftEdge] = lengthValue(decl);
break;
646 case Property::BorderRightWidth: borders[RightEdge] = lengthValue(decl);
break;
647 case Property::BorderTopWidth: borders[TopEdge] = lengthValue(decl);
break;
648 case Property::BorderBottomWidth: borders[BottomEdge] = lengthValue(decl);
break;
649 case Property::BorderWidth: lengthValues(decl, borders);
break;
651 case Property::BorderLeftColor: colors[LeftEdge] = decl.brushValue(pal);
break;
652 case Property::BorderRightColor: colors[RightEdge] = decl.brushValue(pal);
break;
653 case Property::BorderTopColor: colors[TopEdge] = decl.brushValue(pal);
break;
654 case Property::BorderBottomColor: colors[BottomEdge] = decl.brushValue(pal);
break;
655 case Property::BorderColor: decl.brushValues(colors, pal);
break;
657 case Property::BorderTopStyle: styles[TopEdge] = decl.styleValue();
break;
658 case Property::BorderBottomStyle: styles[BottomEdge] = decl.styleValue();
break;
659 case Property::BorderLeftStyle: styles[LeftEdge] = decl.styleValue();
break;
660 case Property::BorderRightStyle: styles[RightEdge] = decl.styleValue();
break;
661 case Property::BorderStyles: decl.styleValues(styles);
break;
663 case Property::BorderTopLeftRadius: radii[0] = sizeValue(decl);
break;
664 case Property::BorderTopRightRadius: radii[1] = sizeValue(decl);
break;
665 case Property::BorderBottomLeftRadius: radii[2] = sizeValue(decl);
break;
666 case Property::BorderBottomRightRadius: radii[3] = sizeValue(decl);
break;
667 case Property::BorderRadius: sizeValues(decl, radii);
break;
669 case Property::BorderLeft:
670 borderValue(decl, &borders[LeftEdge], &styles[LeftEdge], &colors[LeftEdge]);
672 case Property::BorderTop:
673 borderValue(decl, &borders[TopEdge], &styles[TopEdge], &colors[TopEdge]);
675 case Property::BorderRight:
676 borderValue(decl, &borders[RightEdge], &styles[RightEdge], &colors[RightEdge]);
678 case Property::BorderBottom:
679 borderValue(decl, &borders[BottomEdge], &styles[BottomEdge], &colors[BottomEdge]);
681 case Property::Border:
682 borderValue(decl, &borders[LeftEdge], &styles[LeftEdge], &colors[LeftEdge]);
683 borders[TopEdge] = borders[RightEdge] = borders[BottomEdge] = borders[LeftEdge];
684 styles[TopEdge] = styles[RightEdge] = styles[BottomEdge] = styles[LeftEdge];
685 colors[TopEdge] = colors[RightEdge] = colors[BottomEdge] = colors[LeftEdge];
696bool ValueExtractor::extractOutline(
int *borders, QBrush *colors, BorderStyle *styles,
697 QSize *radii,
int *offsets)
701 for (
const Declaration &decl : std::as_const(declarations)) {
702 switch (decl.d->propertyId) {
703 case Property::OutlineWidth: lengthValues(decl, borders);
break;
704 case Property::OutlineColor: decl.brushValues(colors, pal);
break;
705 case Property::OutlineStyle: decl.styleValues(styles);
break;
707 case Property::OutlineTopLeftRadius: radii[0] = sizeValue(decl);
break;
708 case Property::OutlineTopRightRadius: radii[1] = sizeValue(decl);
break;
709 case Property::OutlineBottomLeftRadius: radii[2] = sizeValue(decl);
break;
710 case Property::OutlineBottomRightRadius: radii[3] = sizeValue(decl);
break;
711 case Property::OutlineRadius: sizeValues(decl, radii);
break;
712 case Property::OutlineOffset: lengthValues(decl, offsets);
break;
714 case Property::Outline:
715 borderValue(decl, &borders[LeftEdge], &styles[LeftEdge], &colors[LeftEdge]);
716 borders[TopEdge] = borders[RightEdge] = borders[BottomEdge] = borders[LeftEdge];
717 styles[TopEdge] = styles[RightEdge] = styles[BottomEdge] = styles[LeftEdge];
718 colors[TopEdge] = colors[RightEdge] = colors[BottomEdge] = colors[LeftEdge];
731 Qt::Alignment a[2] = { { }, { } };
732 for (
int i = 0; i < qMin(2, count); i++) {
735 switch (values[i].variant.value<
KnownValue>()) {
745 if (a[0] == Qt::AlignCenter && a[1] != 0 && a[1] != Qt::AlignCenter)
746 a[0] = (a[1] == Qt::AlignLeft || a[1] == Qt::AlignRight) ? Qt::AlignVCenter : Qt::AlignHCenter;
747 if ((a[1] == 0 || a[1] == Qt::AlignCenter) && a[0] != Qt::AlignCenter)
748 a[1] = (a[0] == Qt::AlignLeft || a[0] == Qt::AlignRight) ? Qt::AlignVCenter : Qt::AlignHCenter;
755 v.variant.convert(QMetaType::fromType<QColor>());
760 return qvariant_cast<QColor>(v.variant);
762 if (v.type == Value::KnownIdentifier && v.variant.value<KnownValue>() == KnownValue::Transparent)
763 return QColor(Qt::transparent);
768 QStringList lst = v.variant.toStringList();
772 const QString &identifier = lst.at(0);
773 if ((identifier.compare(
"palette"_L1, Qt::CaseInsensitive)) == 0) {
774 static_assert((
int(KnownValue::LastColorRole) -
int(KnownValue::FirstColorRole) + 1) == QPalette::ColorRole::NColorRoles);
776 const KnownValue role = findKnownValue(lst.at(1).trimmed(), values);
777 if (role >= KnownValue::FirstColorRole && role <= KnownValue::LastColorRole)
778 return (QPalette::ColorRole)(
int(role) -
int(KnownValue::FirstColorRole));
783 const bool rgb = identifier.startsWith(
"rgb"_L1);
784 const bool hsv = !rgb && identifier.startsWith(
"hsv"_L1);
785 const bool hsl = !rgb && !hsv && identifier.startsWith(
"hsl"_L1);
787 if (!rgb && !hsv && !hsl)
790 const bool hasAlpha = identifier.size() == 4 && identifier.at(3) == u'a';
791 if (identifier.size() > 3 && !hasAlpha)
798 QList<QCss::Value> colorDigits;
799 if (!p.parseExpr(&colorDigits))
801 const int tokenCount = colorDigits.size();
803 for (
int i = 0; i < qMin(tokenCount, 7); i += 2) {
805 const qreal maxRange = (rgb || i != 0) ? 255. : 359.;
806 colorDigits[i].variant = colorDigits.at(i).variant.toReal() * (maxRange / 100.);
817 if (hasAlpha && tokenCount != 7) {
818 qWarning(
"QCssParser::parseColorValue: Specified color with alpha value but no alpha given: '%s'", qPrintable(lst.join(u' ')));
821 if (!hasAlpha && tokenCount != 5) {
822 qWarning(
"QCssParser::parseColorValue: Specified color without alpha value but alpha given: '%s'", qPrintable(lst.join(u' ')));
826 int v1 = colorDigits.at(0).variant.toInt();
827 int v2 = colorDigits.at(2).variant.toInt();
828 int v3 = colorDigits.at(4).variant.toInt();
830 if (tokenCount == 7) {
831 int alphaValue = colorDigits.at(6).variant.toInt();
833 alpha = colorDigits.at(6).variant.toReal() * 255.;
839 return QColor::fromRgb(v1, v2, v3, alpha);
841 return QColor::fromHsv(v1, v2, v3, alpha);
842 return QColor::fromHsl(v1, v2, v3, alpha);
850 return pal.color(c.role);
859 return QBrush(c.color);
867 QStringList lst = v.variant.toStringList();
871 QStringList gradFuncs;
872 gradFuncs <<
"qlineargradient"_L1 <<
"qradialgradient"_L1 <<
"qconicalgradient"_L1 <<
"qgradient"_L1;
875 if ((gradType = gradFuncs.indexOf(lst.at(0).toLower())) == -1)
878 QHash<QString, qreal> vars;
879 QList<QGradientStop> stops;
883 spreads <<
"pad"_L1 <<
"reflect"_L1 <<
"repeat"_L1;
885 int coordinateMode = -1;
886 QStringList coordinateModes;
887 coordinateModes <<
"logical"_L1 <<
"stretchtodevice"_L1 <<
"objectbounding"_L1 <<
"object"_L1;
889 bool dependsOnThePalette =
false;
891 while (parser.hasNext()) {
893 if (!parser.test(IDENT))
895 QString attr = parser.lexem();
897 if (!parser.test(COLON))
900 if (attr.compare(
"stop"_L1, Qt::CaseInsensitive) == 0) {
909 dependsOnThePalette =
true;
910 stops.append(QGradientStop(stop.variant.toReal(), colorFromData(cd, pal)));
914 (
void)parser.parseTerm(&value);
915 if (attr.compare(
"spread"_L1, Qt::CaseInsensitive) == 0)
916 spread = spreads.indexOf(value.variant.toString());
917 else if (attr.compare(
"coordinatemode"_L1, Qt::CaseInsensitive) == 0)
918 coordinateMode = coordinateModes.indexOf(value.variant.toString());
920 vars[attr] = value.variant.toReal();
923 (
void)parser.test(COMMA);
928 vars.value(
"x2"_L1), vars.value(
"y2"_L1));
929 lg.setCoordinateMode(coordinateMode < 0 ? QGradient::ObjectBoundingMode : QGradient::CoordinateMode(coordinateMode));
932 lg.setSpread(QGradient::Spread(spread));
934 if (dependsOnThePalette)
941 vars.value(
"radius"_L1), vars.value(
"fx"_L1),
942 vars.value(
"fy"_L1));
943 rg.setCoordinateMode(coordinateMode < 0 ? QGradient::ObjectBoundingMode : QGradient::CoordinateMode(coordinateMode));
946 rg.setSpread(QGradient::Spread(spread));
948 if (dependsOnThePalette)
954 QConicalGradient cg(vars.value(
"cx"_L1), vars.value(
"cy"_L1), vars.value(
"angle"_L1));
955 cg.setCoordinateMode(coordinateMode < 0 ? QGradient::ObjectBoundingMode : QGradient::CoordinateMode(coordinateMode));
958 cg.setSpread(QGradient::Spread(spread));
960 if (dependsOnThePalette)
971 return pal.color(c.role);
1012void ValueExtractor::borderValue(
const Declaration &decl,
int *width, QCss::BorderStyle *style, QBrush *color)
1014 if (decl.d->parsed.isValid()) {
1015 BorderData data = qvariant_cast<BorderData>(decl.d->parsed);
1016 *width = lengthValueFromData(data.width, f);
1017 *style = data.style;
1018 *color = data.color.type != BrushData::Invalid ? brushFromData(data.color, pal) : QBrush(QColor());
1023 *style = BorderStyle::None;
1026 if (decl.d->values.isEmpty())
1030 data.width.number = 0;
1031 data.width.unit = LengthData::None;
1032 data.style = BorderStyle::None;
1035 if (decl.d->values.at(i).type == Value::Length || decl.d->values.at(i).type == Value::Number) {
1036 data.width = lengthValue(decl.d->values.at(i));
1037 *width = lengthValueFromData(data.width, f);
1038 if (++i >= decl.d->values.size()) {
1039 decl.d->parsed = QVariant::fromValue<BorderData>(data);
1044 data.style = parseStyleValue(decl.d->values.at(i));
1045 if (data.style != BorderStyle::Unknown) {
1046 *style = data.style;
1047 if (++i >= decl.d->values.size()) {
1048 decl.d->parsed = QVariant::fromValue<BorderData>(data);
1052 data.style = BorderStyle::None;
1055 data.color = parseBrushValue(decl.d->values.at(i), pal);
1056 if (data.color.type != BrushData::Invalid) {
1057 *color = brushFromData(data.color, pal);
1058 if (data.color.type != BrushData::DependsOnThePalette)
1059 decl.d->parsed = QVariant::fromValue<BorderData>(data);
1068 *alignment = Qt::AlignTop | Qt::AlignLeft;
1070 for (qsizetype i = 0; i < values.size(); ++i) {
1073 *image = v.variant.toString();
1079 *brush = QBrush(Qt::transparent);
1082 const Repeat repeatAttempt = findKnownValue(v.variant.toString(), repeats);
1084 *repeat = repeatAttempt;
1089 const int start = i;
1091 if (i < values.size() - 1
1096 Qt::Alignment a = parseAlignment(values.constData() + start, count);
1104 *brush = parseBrushValue(v, pal);
1108bool ValueExtractor::extractBackground(QBrush *brush, QString *image, Repeat *repeat,
1109 Qt::Alignment *alignment, Origin *origin, Attachment *attachment,
1113 for (
const Declaration &decl : declarations) {
1114 if (decl.d->values.isEmpty())
1116 const QCss::Value &val = decl.d->values.at(0);
1117 switch (decl.d->propertyId) {
1118 case Property::BackgroundColor:
1119 *brush = decl.brushValue();
1121 case Property::BackgroundImage:
1122 if (val.type == Value::Uri)
1123 *image = val.variant.toString();
1125 case Property::BackgroundRepeat:
1126 if (decl.d->parsed.isValid()) {
1127 *repeat = decl.d->parsed.value<Repeat>();
1129 *repeat = findKnownValue(val.variant.toString(), repeats);
1130 decl.d->parsed = QVariant::fromValue(*repeat);
1133 case Property::BackgroundPosition:
1134 *alignment = decl.alignmentValue();
1136 case Property::BackgroundOrigin:
1137 *origin = decl.originValue();
1139 case Property::BackgroundClip:
1140 *clip = decl.originValue();
1142 case Property::Background:
1143 if (decl.d->parsed.isValid()) {
1144 BackgroundData data = qvariant_cast<BackgroundData>(decl.d->parsed);
1145 *brush = brushFromData(data.brush, pal);
1146 *image = data.image;
1147 *repeat = data.repeat;
1148 *alignment = data.alignment;
1150 BrushData brushData;
1151 parseShorthandBackgroundProperty(decl.d->values, &brushData, image, repeat, alignment, pal);
1152 *brush = brushFromData(brushData, pal);
1153 if (brushData.type != BrushData::DependsOnThePalette) {
1154 BackgroundData data = { brushData, *image, *repeat, *alignment };
1155 decl.d->parsed = QVariant::fromValue<BackgroundData>(data);
1159 case Property::BackgroundAttachment:
1160 *attachment = decl.attachmentValue();
1179 default: valid =
false;
break;
1187 QString s = value.variant.toString();
1188 if (s.endsWith(
"pt"_L1, Qt::CaseInsensitive)) {
1190 value.variant = std::move(s);
1191 if (value.variant.convert(QMetaType::fromType<qreal>())) {
1192 font->setPointSizeF(qBound(qreal(0), value.variant.toReal(), qreal(1 << 24) - 1));
1195 }
else if (s.endsWith(
"px"_L1, Qt::CaseInsensitive)) {
1197 value.variant = std::move(s);
1198 if (value.variant.convert(QMetaType::fromType<qreal>())) {
1199 font->setPixelSize(qBound(0, value.variant.toInt(), (1 << 24) - 1));
1245 font->setWeight(QFont::Weight(qRound(qBound(0.0, value.variant.toDouble(), 1001.0))));
1250
1251
1252
1253
1257 QStringList families;
1258 bool shouldAddSpace =
false;
1259 for (qsizetype i = start; i < values.size(); ++i) {
1264 shouldAddSpace =
false;
1267 const QString str = v.variant.toString();
1273 shouldAddSpace =
true;
1275 if (!family.isEmpty())
1277 if (families.isEmpty())
1279 font->setFamilies(families);
1285 for (
const QCss::Value &value : values) {
1286 if (value.type != Value::KnownIdentifier)
1288 switch (value.variant.value<KnownValue>()) {
1289 case KnownValue::Underline: font->setUnderline(
true);
break;
1290 case KnownValue::Overline: font->setOverline(
true);
break;
1291 case KnownValue::LineThrough: font->setStrikeOut(
true);
break;
1292 case KnownValue::None:
1293 font->setUnderline(
false);
1294 font->setOverline(
false);
1295 font->setStrikeOut(
false);
1304 QString s = value.variant.toString();
1307 if (s.endsWith(
"em"_L1, Qt::CaseInsensitive)) {
1309 val = s.toDouble(&ok);
1311 font->setLetterSpacing(QFont::PercentageSpacing, (val + 1.0) * 100);
1312 }
else if (s.endsWith(
"px"_L1, Qt::CaseInsensitive)) {
1314 val = s.toDouble(&ok);
1316 font->setLetterSpacing(QFont::AbsoluteSpacing, val);
1322 QString s = value.variant.toString();
1323 if (s.endsWith(
"px"_L1, Qt::CaseInsensitive)) {
1327 val = s.toDouble(&ok);
1329 font->setWordSpacing(val);
1335 font->setStyle(QFont::StyleNormal);
1336 font->setWeight(QFont::Normal);
1337 *fontSizeAdjustment = -255;
1340 while (i < values.size()) {
1341 if (setFontStyleFromValue(values.at(i), font)
1342 || setFontWeightFromValue(values.at(i), font))
1348 if (i < values.size()) {
1349 setFontSizeFromValue(values.at(i), font, fontSizeAdjustment);
1353 if (i < values.size()) {
1354 setFontFamilyFromValues(values, font, i);
1381bool ValueExtractor::extractFont(QFont *font,
int *fontSizeAdjustment)
1383 if (fontExtracted) {
1385 *fontSizeAdjustment = adjustment;
1386 return fontExtracted == 1;
1390 for (
const Declaration &decl : std::as_const(declarations)) {
1391 if (decl.d->values.isEmpty())
1393 const QCss::Value &val = decl.d->values.at(0);
1394 switch (decl.d->propertyId) {
1395 case Property::FontSize: setFontSizeFromValue(val, font, fontSizeAdjustment);
break;
1396 case Property::FontStyle: setFontStyleFromValue(val, font);
break;
1397 case Property::FontWeight: setFontWeightFromValue(val, font);
break;
1398 case Property::FontFamily: setFontFamilyFromValues(decl.d->values, font);
break;
1399 case Property::FontKerning: setFontKerningFromValue(val, font);
break;
1400 case Property::TextDecoration: setTextDecorationFromValues(decl.d->values, font);
break;
1401 case Property::Font: parseShorthandFontProperty(decl.d->values, font, fontSizeAdjustment);
break;
1402 case Property::FontVariant: setFontVariantFromValue(val, font);
break;
1403 case Property::TextTransform: setTextTransformFromValue(val, font);
break;
1404 case Property::LetterSpacing: setLetterSpacingFromValue(val, font);
break;
1405 case Property::WordSpacing: setWordSpacingFromValue(val, font);
break;
1412 adjustment = *fontSizeAdjustment;
1413 fontExtracted = hit ? 1 : 2;
1417bool ValueExtractor::extractPalette(QBrush *foreground,
1418 QBrush *selectedForeground,
1419 QBrush *selectedBackground,
1420 QBrush *alternateBackground,
1421 QBrush *placeHolderTextForeground,
1422 QBrush *accent)
const
1425 for (
const Declaration &decl : declarations) {
1426 switch (decl.d->propertyId) {
1427 case Property::Color: *foreground = decl.brushValue(pal);
break;
1428 case Property::QtSelectionForeground: *selectedForeground = decl.brushValue(pal);
break;
1429 case Property::QtSelectionBackground: *selectedBackground = decl.brushValue(pal);
break;
1430 case Property::QtAlternateBackground: *alternateBackground = decl.brushValue(pal);
break;
1431 case Property::QtPlaceHolderText: *placeHolderTextForeground = decl.brushValue(pal);
break;
1432 case Property::QtAccent: *accent = decl.brushValue(pal);
break;
1440void ValueExtractor::extractFont()
1445 extractFont(&f, &dummy);
1448bool ValueExtractor::extractImage(QIcon *icon, Qt::Alignment *a, QSize *size)
const
1451 for (
const Declaration &decl : declarations) {
1452 switch (decl.d->propertyId) {
1453 case Property::QtImage:
1454 *icon = decl.iconValue();
1455 if (decl.d->values.size() > 0 && decl.d->values.at(0).type == Value::Uri) {
1457 QImageReader imageReader(decl.d->values.at(0).variant.toString());
1458 if ((*size = imageReader.size()).isNull()) {
1461 *size = imageReader.read().size();
1465 case Property::QtImageAlignment: *a = decl.alignmentValue();
break;
1473bool ValueExtractor::extractIcon(QIcon *icon, QSize *size)
const
1476 const auto declaration = std::find_if(
1477 declarations.rbegin(), declarations.rend(),
1478 [](
const Declaration &decl) {
return decl.d->propertyId == Property::QtIcon; });
1479 if (declaration == declarations.rend())
1482 *icon = declaration->iconValue();
1485 if (declaration->d->values.isEmpty())
1488 const auto &propertyValue = declaration->d->values.constFirst();
1489 if (propertyValue.type != Value::Uri)
1493 const QString url(propertyValue.variant.toString());
1494 QImageReader imageReader(url);
1495 *size = imageReader.size();
1496 if (!size->isNull())
1500 *size = imageReader.read().size();
1506QColor Declaration::colorValue(
const QPalette &pal)
const
1508 if (d->values.size() != 1)
1511 if (d->parsed.isValid()) {
1512 switch (d->parsed.typeId()) {
1513 case qMetaTypeId<QColor>():
1514 return qvariant_cast<QColor>(d->parsed);
1515 case qMetaTypeId<
int>():
1516 return pal.color((QPalette::ColorRole)(d->parsed.toInt()));
1517 case qMetaTypeId<QList<QVariant>>():
1518 if (d->parsed.toList().size() == 1) {
1519 auto parsedList = d->parsed.toList();
1520 const auto &value = parsedList.at(0);
1521 return qvariant_cast<QColor>(value);
1527 ColorData color = parseColorValue(d->values.at(0));
1528 if (color.type == ColorData::Role) {
1529 d->parsed = QVariant::fromValue<
int>(color.role);
1530 return pal.color((QPalette::ColorRole)(color.role));
1532 d->parsed = QVariant::fromValue<QColor>(color.color);
1537QBrush Declaration::brushValue(
const QPalette &pal)
const
1539 if (d->values.size() != 1)
1542 if (d->parsed.isValid()) {
1543 if (d->parsed.userType() == QMetaType::QBrush)
1544 return qvariant_cast<QBrush>(d->parsed);
1545 if (d->parsed.userType() == QMetaType::Int)
1546 return pal.color((QPalette::ColorRole)(d->parsed.toInt()));
1549 BrushData data = parseBrushValue(d->values.at(0), pal);
1551 if (data.type == BrushData::Role) {
1552 d->parsed = QVariant::fromValue<
int>(data.role);
1553 return pal.color((QPalette::ColorRole)(data.role));
1555 if (data.type != BrushData::DependsOnThePalette)
1556 d->parsed = QVariant::fromValue<QBrush>(data.brush);
1561void Declaration::brushValues(QBrush *c,
const QPalette &pal)
const
1563 int needParse = 0x1f;
1566 if (d->parsed.isValid()) {
1568 Q_ASSERT(d->parsed.metaType() == QMetaType::fromType<QList<QVariant>>());
1569 QList<QVariant> v = d->parsed.toList();
1570 for (i = 0; i < qMin(v.size(), 4); i++) {
1571 if (v.at(i).userType() == QMetaType::QBrush) {
1572 c[i] = qvariant_cast<QBrush>(v.at(i));
1573 }
else if (v.at(i).userType() == QMetaType::Int) {
1574 c[i] = pal.color((QPalette::ColorRole)(v.at(i).toInt()));
1576 needParse |= (1<<i);
1580 if (needParse != 0) {
1582 for (i = 0; i < qMin(d->values.size(), 4); i++) {
1583 if (!(needParse & (1<<i)))
1585 BrushData data = parseBrushValue(d->values.at(i), pal);
1586 if (data.type == BrushData::Role) {
1587 v += QVariant::fromValue<
int>(data.role);
1588 c[i] = pal.color((QPalette::ColorRole)(data.role));
1590 if (data.type != BrushData::DependsOnThePalette) {
1591 v += QVariant::fromValue<QBrush>(data.brush);
1598 if (needParse & 0x10)
1599 d->parsed = std::move(v);
1601 if (i == 0) c[0] = c[1] = c[2] = c[3] = QBrush();
1602 else if (i == 1) c[3] = c[2] = c[1] = c[0];
1603 else if (i == 2) c[2] = c[0], c[3] = c[1];
1604 else if (i == 3) c[3] = c[1];
1607bool Declaration::realValue(qreal *real,
const char *unit)
const
1609 if (d->values.size() != 1)
1611 const Value &v = d->values.at(0);
1612 if (unit && v.type != Value::Length)
1614 const QString str = v.variant.toString();
1617 const QLatin1StringView unitStr(unit);
1618 if (!s.endsWith(unitStr, Qt::CaseInsensitive))
1620 s.chop(unitStr.size());
1623 qreal val = s.toDouble(&ok);
1633 const QString str = v.variant.toString();
1636 const QLatin1StringView unitStr(unit);
1637 if (!s.endsWith(unitStr, Qt::CaseInsensitive))
1639 s.chop(unitStr.size());
1642 int val = s.toInt(&ok);
1648bool Declaration::intValue(
int *i,
const char *unit)
const
1650 if (d->values.size() != 1)
1652 return intValueHelper(d->values.at(0), i, unit);
1655QSize Declaration::sizeValue()
const
1657 if (d->parsed.isValid())
1658 return qvariant_cast<QSize>(d->parsed);
1660 int x[2] = { 0, 0 };
1661 const qsizetype count = d->values.size();
1662 for (qsizetype i = 0; i < count; ++i) {
1664 qWarning(
"QCssParser::sizeValue: Too many values provided");
1667 const auto &value = d->values.at(i);
1668 const QString valueString = value.variant.toString();
1669 if (valueString.endsWith(u"pt", Qt::CaseInsensitive)) {
1670 intValueHelper(value, &x[i],
"pt");
1673 x[i] = (x[i] * 72) / 96;
1676 intValueHelper(value, &x[i],
"px");
1681 QSize size(x[0], x[1]);
1682 d->parsed = QVariant::fromValue<QSize>(size);
1686QRect Declaration::rectValue()
const
1688 if (d->values.size() != 1)
1691 if (d->parsed.isValid())
1692 return qvariant_cast<QRect>(d->parsed);
1694 const QCss::Value &v = d->values.at(0);
1695 if (v.type != Value::Function)
1697 const QStringList func = v.variant.toStringList();
1698 if (func.size() != 2 || func.at(0).compare(
"rect"_L1) != 0)
1700 const auto args = QStringView{func[1]}.split(u' ', Qt::SkipEmptyParts);
1701 if (args.size() != 4)
1703 QRect rect(args[0].toInt(), args[1].toInt(), args[2].toInt(), args[3].toInt());
1704 d->parsed = QVariant::fromValue<QRect>(rect);
1708void Declaration::colorValues(QColor *c,
const QPalette &pal)
const
1711 if (d->parsed.isValid()) {
1712 QList<QVariant> v = d->parsed.toList();
1713 for (i = 0; i < qMin(d->values.size(), 4); i++) {
1714 if (v.at(i).userType() == QMetaType::QColor) {
1715 c[i] = qvariant_cast<QColor>(v.at(i));
1717 c[i] = pal.color((QPalette::ColorRole)(v.at(i).toInt()));
1722 for (i = 0; i < qMin(d->values.size(), 4); i++) {
1723 ColorData color = parseColorValue(d->values.at(i));
1724 if (color.type == ColorData::Role) {
1725 v += QVariant::fromValue<
int>(color.role);
1726 c[i] = pal.color((QPalette::ColorRole)(color.role));
1728 v += QVariant::fromValue<QColor>(color.color);
1732 d->parsed = std::move(v);
1735 if (i == 0) c[0] = c[1] = c[2] = c[3] = QColor();
1736 else if (i == 1) c[3] = c[2] = c[1] = c[0];
1737 else if (i == 2) c[2] = c[0], c[3] = c[1];
1738 else if (i == 3) c[3] = c[1];
1741BorderStyle Declaration::styleValue()
const
1743 if (d->values.size() != 1)
1744 return BorderStyle::None;
1745 return parseStyleValue(d->values.at(0));
1748void Declaration::styleValues(BorderStyle *s)
const
1751 for (i = 0; i < qMin(d->values.size(), 4); i++)
1752 s[i] = parseStyleValue(d->values.at(i));
1753 if (i == 0) s[0] = s[1] = s[2] = s[3] = BorderStyle::None;
1754 else if (i == 1) s[3] = s[2] = s[1] = s[0];
1755 else if (i == 2) s[2] = s[0], s[3] = s[1];
1756 else if (i == 3) s[3] = s[1];
1759Repeat Declaration::repeatValue()
const
1761 if (d->parsed.isValid())
1762 return static_cast<Repeat>(d->parsed.toInt());
1763 if (d->values.size() != 1)
1764 return Repeat::Unknown;
1765 Repeat v = findKnownValue(d->values.at(0).variant.toString(), repeats);
1766 d->parsed = QVariant::fromValue(v);
1770Origin Declaration::originValue()
const
1772 if (d->parsed.isValid())
1773 return static_cast<Origin>(d->parsed.toInt());
1774 if (d->values.size() != 1)
1775 return Origin::Unknown;
1776 Origin v = findKnownValue(d->values.at(0).variant.toString(), origins);
1777 d->parsed = QVariant::fromValue(v);
1781PositionMode Declaration::positionValue()
const
1783 if (d->parsed.isValid())
1784 return static_cast<PositionMode>(d->parsed.toInt());
1785 if (d->values.size() != 1)
1786 return PositionMode::Unknown;
1787 PositionMode v = findKnownValue(d->values.at(0).variant.toString(), positions);
1788 d->parsed = QVariant::fromValue(v);
1792Attachment Declaration::attachmentValue()
const
1794 if (d->parsed.isValid())
1795 return static_cast<Attachment>(d->parsed.toInt());
1796 if (d->values.size() != 1)
1797 return Attachment::Unknown;
1798 Attachment v = findKnownValue(d->values.at(0).variant.toString(), attachments);
1799 d->parsed = QVariant::fromValue(v);
1803int Declaration::styleFeaturesValue()
const
1805 Q_ASSERT(d->propertyId == Property::QtStyleFeatures);
1806 if (d->parsed.isValid())
1807 return d->parsed.toInt();
1808 int features = StyleFeature_None;
1809 for (
const Value &value : std::as_const(d->values)) {
1810 features |= findKnownValue(value.variant.toString(), styleFeatures);
1812 d->parsed = features;
1816QString Declaration::uriValue()
const
1818 if (d->values.isEmpty() || d->values.at(0).type != Value::Uri)
1820 return d->values.at(0).variant.toString();
1823Qt::Alignment Declaration::alignmentValue()
const
1825 if (d->parsed.isValid())
1826 return Qt::Alignment(d->parsed.toInt());
1827 if (d->values.isEmpty() || d->values.size() > 2)
1828 return Qt::AlignLeft | Qt::AlignTop;
1830 Qt::Alignment v = parseAlignment(d->values.constData(), d->values.size());
1835void Declaration::borderImageValue(QString *image,
int *cuts,
1836 TileMode *h, TileMode *v)
const
1838 const DeclarationData *d =
this->d.data();
1839 *image = uriValue();
1840 for (
int i = 0; i < 4; i++)
1842 *h = *v = TileMode::Stretch;
1844 if (d->values.size() < 2)
1847 if (d->values.at(1).type == Value::Number) {
1849 for (i = 0; i < qMin(d->values.size()-1, 4); i++) {
1850 const Value& v = d->values.at(i+1);
1851 if (v.type != Value::Number)
1853 cuts[i] = v.variant.toString().toInt();
1855 qWarning(
"Declaration::borderImageValue: Invalid cut value %d at position %d",
1857 cuts[0] = cuts[1] = cuts[2] = cuts[3] = -1;
1862 if (i == 0) cuts[0] = cuts[1] = cuts[2] = cuts[3] = 0;
1863 else if (i == 1) cuts[3] = cuts[2] = cuts[1] = cuts[0];
1864 else if (i == 2) cuts[2] = cuts[0], cuts[3] = cuts[1];
1865 else if (i == 3) cuts[3] = cuts[1];
1868 if (d->values.last().type == Value::Identifier) {
1869 *v = findKnownValue(d->values.last().variant.toString(), tileModes);
1871 if (d->values[d->values.size() - 2].type == Value::Identifier) {
1872 *h = findKnownValue(d->values[d->values.size()-2].variant.toString(), tileModes);
1877bool Declaration::borderCollapseValue()
const
1879 if (d->values.size() != 1)
1882 return d->values.at(0).toString() ==
"collapse"_L1;
1885QList<qreal> Declaration::dashArray()
const
1887 if (d->propertyId != Property::QtStrokeDashArray || d->values.empty())
1888 return QList<qreal>();
1890 bool isValid =
true;
1891 QList<qreal> dashes;
1892 for (qsizetype i = 0; i < d->values.size(); i++) {
1893 const Value &v = d->values[i];
1895 bool isValidSeparator = (i & 1) && v.type == Value::TermOperatorComma;
1896 bool isValidNumber = !(i & 1) && v.type == Value::Number;
1897 if (!isValidNumber && !isValidSeparator) {
1900 }
else if (isValidNumber) {
1902 dashes.append(v.variant.toReal(&ok));
1910 isValid &= !(dashes.size() & 1);
1911 return isValid ? dashes : QList<qreal>();
1914QIcon Declaration::iconValue()
const
1916 if (d->parsed.isValid())
1917 return qvariant_cast<QIcon>(d->parsed);
1920 for (qsizetype i = 0; i < d->values.size();) {
1921 const Value &value = d->values.at(i++);
1922 if (value.type != Value::Uri)
1924 QString uri = value.variant.toString();
1925 QIcon::Mode mode = QIcon::Normal;
1926 QIcon::State state = QIcon::Off;
1927 for (
int j = 0; j < 2; j++) {
1928 if (i != d->values.size() && d->values.at(i).type == Value::KnownIdentifier) {
1929 switch (d->values.at(i).variant.value<KnownValue>()) {
1930 case KnownValue::Disabled: mode = QIcon::Disabled;
break;
1931 case KnownValue::Active: mode = QIcon::Active;
break;
1932 case KnownValue::Selected: mode = QIcon::Selected;
break;
1933 case KnownValue::Normal: mode = QIcon::Normal;
break;
1934 case KnownValue::On: state = QIcon::On;
break;
1935 case KnownValue::Off: state = QIcon::Off;
break;
1948 icon.addPixmap(uri, mode, state);
1950 if (i == d->values.size())
1953 if (d->values.at(i).type == Value::TermOperatorComma)
1957 d->parsed = QVariant::fromValue<QIcon>(icon);
1963int Selector::specificity()
const
1966 for (
const BasicSelector &sel : basicSelectors) {
1967 if (!sel.elementName.isEmpty())
1970 val += (sel.pseudos.size() + sel.attributeSelectors.size()) * 0x10;
1971 val += sel.ids.size() * 0x100;
1976QString Selector::pseudoElement()
const
1978 const BasicSelector& bs = basicSelectors.last();
1979 if (!bs.pseudos.isEmpty() && bs.pseudos.at(0).type == PseudoClass_Unknown)
1980 return bs.pseudos.at(0).name;
1984quint64 Selector::pseudoClass(quint64 *negated)
const
1986 const BasicSelector& bs = basicSelectors.last();
1987 if (bs.pseudos.isEmpty())
1988 return PseudoClass_Unspecified;
1989 quint64 pc = PseudoClass_Unknown;
1990 for (
int i = !pseudoElement().isEmpty(); i < bs.pseudos.size(); i++) {
1991 const Pseudo &pseudo = bs.pseudos.at(i);
1992 if (pseudo.type == PseudoClass_Unknown)
1993 return PseudoClass_Unknown;
1994 if (!pseudo.negated)
1997 *negated |= pseudo.type;
2006 QList<StyleRule> universals;
2007 for (qsizetype i = 0; i < styleRules.size(); ++i) {
2008 const StyleRule &rule = styleRules.at(i);
2009 QList<Selector> universalsSelectors;
2010 for (
const Selector &selector : rule.selectors) {
2012 if (selector.basicSelectors.isEmpty())
2015 if (selector.basicSelectors.at(0).relationToNext == BasicSelector::NoRelation) {
2016 if (selector.basicSelectors.size() != 1)
2018 }
else if (selector.basicSelectors.size() <= 1) {
2022 const BasicSelector &sel = selector.basicSelectors.at(selector.basicSelectors.size() - 1);
2024 if (!sel.ids.isEmpty()) {
2026 nr.selectors += selector;
2027 nr.declarations = rule.declarations;
2029 idIndex.insert(sel.ids.at(0), nr);
2030 }
else if (!sel.elementName.isEmpty()) {
2032 nr.selectors += selector;
2033 nr.declarations = rule.declarations;
2035 QString name = sel.elementName;
2036 if (nameCaseSensitivity == Qt::CaseInsensitive)
2037 name = std::move(name).toLower();
2038 nameIndex.insert(name, nr);
2040 universalsSelectors += selector;
2043 if (!universalsSelectors.isEmpty()) {
2045 nr.selectors = universalsSelectors;
2046 nr.declarations = rule.declarations;
2051 styleRules = universals;
2056StyleSelector::~StyleSelector()
2060bool StyleSelector::nodeNameEquals(NodePtr node,
const QString& nodeName)
const
2062 return nodeNames(node).contains(nodeName, nameCaseSensitivity);
2065QStringList StyleSelector::nodeIds(NodePtr node)
const
2067 return QStringList(attributeValue(node, QCss::AttributeSelector{
"id"_L1, {}, AttributeSelector::NoMatch}));
2070bool StyleSelector::selectorMatches(
const Selector &selector, NodePtr node)
const
2072 if (selector.basicSelectors.isEmpty())
2075 if (selector.basicSelectors.at(0).relationToNext == BasicSelector::NoRelation) {
2076 if (selector.basicSelectors.size() != 1)
2078 return basicSelectorMatches(selector.basicSelectors.at(0), node);
2080 if (selector.basicSelectors.size() <= 1)
2083 qsizetype i = selector.basicSelectors.size() - 1;
2084 node = duplicateNode(node);
2087 BasicSelector sel = selector.basicSelectors.at(i);
2089 match = basicSelectorMatches(sel, node);
2091 if (i == selector.basicSelectors.size() - 1)
2093 if (sel.relationToNext != BasicSelector::MatchNextSelectorIfAncestor &&
2094 sel.relationToNext != BasicSelector::MatchNextSelectorIfIndirectAdjecent)
2098 if (match || (sel.relationToNext != BasicSelector::MatchNextSelectorIfAncestor &&
2099 sel.relationToNext != BasicSelector::MatchNextSelectorIfIndirectAdjecent))
2105 sel = selector.basicSelectors.at(i);
2106 if (sel.relationToNext == BasicSelector::MatchNextSelectorIfAncestor
2107 || sel.relationToNext == BasicSelector::MatchNextSelectorIfParent) {
2109 NodePtr nextParent = parentNode(node);
2112 }
else if (sel.relationToNext == BasicSelector::MatchNextSelectorIfDirectAdjecent
2113 || sel.relationToNext == BasicSelector::MatchNextSelectorIfIndirectAdjecent) {
2114 NodePtr previousSibling = previousSiblingNode(node);
2116 node = previousSibling;
2118 if (isNullNode(node)) {
2122 }
while (i >= 0 && (match || sel.relationToNext == BasicSelector::MatchNextSelectorIfAncestor
2123 || sel.relationToNext == BasicSelector::MatchNextSelectorIfIndirectAdjecent));
2130bool StyleSelector::basicSelectorMatches(
const BasicSelector &sel, NodePtr node)
const
2132 if (!sel.attributeSelectors.isEmpty()) {
2133 if (!hasAttributes(node))
2136 for (
const QCss::AttributeSelector &a : sel.attributeSelectors) {
2138 const QString attrValue = attributeValue(node, a);
2139 if (attrValue.isNull())
2142 switch (a.valueMatchCriterium) {
2143 case QCss::AttributeSelector::NoMatch:
2145 case QCss::AttributeSelector::MatchEqual:
2146 if (attrValue != a.value)
2149 case QCss::AttributeSelector::MatchIncludes: {
2150 const auto lst = QStringView{attrValue}.tokenize(u' ');
2152 for (
auto s : lst) {
2162 case QCss::AttributeSelector::MatchDashMatch: {
2163 const QString dashPrefix = a.value + u'-';
2164 if (attrValue != a.value && !attrValue.startsWith(dashPrefix))
2168 case QCss::AttributeSelector::MatchBeginsWith:
2169 if (!attrValue.startsWith(a.value))
2172 case QCss::AttributeSelector::MatchEndsWith:
2173 if (!attrValue.endsWith(a.value))
2176 case QCss::AttributeSelector::MatchContains:
2177 if (!attrValue.contains(a.value))
2184 if (!sel.elementName.isEmpty()
2185 && !nodeNameEquals(node, sel.elementName))
2188 if (!sel.ids.isEmpty()
2189 && sel.ids != nodeIds(node))
2195void StyleSelector::matchRule(NodePtr node,
const StyleRule &rule, StyleSheetOrigin origin,
2196 int depth, std::multimap<uint64_t, StyleRule> *weightedRules)
const
2198 for (
const Selector &selector : rule.selectors) {
2199 if (selectorMatches(selector, node)) {
2200 if (uint32_t(rule.order) >= 0x100000ULL)
2201 qWarning(
"StyleSelector: rule order is to large - style sheet"
2202 "must not contain more than 0x100000 entries");
2203 if (uint32_t(selector.specificity()) >= 0x100000ULL)
2204 qWarning(
"StyleSelector: selector specifity is to large - "
2205 "style sheet must not contain more than 0x100000 selectors "
2207 const uint64_t weight = rule.order
2208 + selector.specificity() * 0x100000ULL
2209 + (uint(origin) + depth) * 0x10000000000ULL;
2210 StyleRule newRule = rule;
2211 if (rule.selectors.size() > 1)
2212 newRule.selectors = { selector };
2215 weightedRules->emplace(weight, std::move(newRule));
2222QList<StyleRule> StyleSelector::styleRulesForNode(NodePtr node)
2224 QList<StyleRule> rules;
2225 if (styleSheets.isEmpty())
2228 std::multimap<uint64_t, StyleRule> weightedRules;
2231 for (
const StyleSheet &styleSheet : std::as_const(styleSheets)) {
2232 for (
const StyleRule &styleRule : styleSheet.styleRules)
2233 matchRule(node, styleRule, styleSheet.origin, styleSheet.depth, &weightedRules);
2235 if (!styleSheet.idIndex.isEmpty()) {
2236 const QStringList ids = nodeIds(node);
2237 for (
const QString &key : ids) {
2238 auto it = styleSheet.idIndex.constFind(key);
2239 while (it != styleSheet.idIndex.constEnd() && it.key() == key) {
2240 matchRule(node, it.value(), styleSheet.origin, styleSheet.depth, &weightedRules);
2245 if (!styleSheet.nameIndex.isEmpty()) {
2246 const QStringList names = nodeNames(node);
2247 for (QString name : names) {
2248 if (nameCaseSensitivity == Qt::CaseInsensitive)
2249 name = std::move(name).toLower();
2250 auto it = styleSheet.nameIndex.constFind(name);
2251 while (it != styleSheet.nameIndex.constEnd() && it.key() == name) {
2252 matchRule(node, it.value(), styleSheet.origin, styleSheet.depth, &weightedRules);
2257 if (!medium.isEmpty()) {
2258 for (
const MediaRule &mediaRule : styleSheet.mediaRules) {
2259 if (mediaRule.media.contains(medium, Qt::CaseInsensitive)) {
2260 for (
const StyleRule &styleRule : mediaRule.styleRules) {
2261 matchRule(node, styleRule, styleSheet.origin,
2262 styleSheet.depth, &weightedRules);
2269 rules.reserve(weightedRules.size());
2270 for (
const auto &weigthedRule : weightedRules)
2271 rules.push_back(std::move(weigthedRule.second));
2278QList<Declaration> StyleSelector::declarationsForNode(NodePtr node,
const char *extraPseudo)
2280 QList<Declaration> decls;
2281 const QList<StyleRule> rules = styleRulesForNode(node);
2282 for (
const StyleRule &styleRule : rules) {
2283 const Selector &selector = styleRule.selectors.at(0);
2284 const QString pseudoElement = selector.pseudoElement();
2286 if (extraPseudo && pseudoElement == QLatin1StringView(extraPseudo)) {
2287 decls += styleRule.declarations;
2291 if (!pseudoElement.isEmpty())
2293 quint64 pseudoClass = selector.pseudoClass();
2294 if (pseudoClass == PseudoClass_Enabled || pseudoClass == PseudoClass_Unspecified)
2295 decls += styleRule.declarations;
2302 return (c >=
'0' && c <=
'9')
2303 || (c >=
'a' && c <=
'f')
2304 || (c >=
'A' && c <=
'F')
2308QString Scanner::preprocess(
const QString &input,
bool *hasEscapeSequences)
2310 QString output = input;
2312 if (hasEscapeSequences)
2313 *hasEscapeSequences =
false;
2316 while (i < output.size()) {
2317 if (output.at(i) == u'\\') {
2322 const int hexStart = i;
2323 while (i < output.size()
2324 && isHexDigit(output.at(i).toLatin1())
2329 if (hexCount == 0) {
2330 if (hasEscapeSequences)
2331 *hasEscapeSequences =
true;
2335 hexCount = qMin(hexCount, 6);
2337 const char16_t code = QStringView{output}.mid(hexStart, hexCount).toUShort(&ok, 16);
2339 output.replace(hexStart - 1, hexCount + 1, code);
2351int QCssScanner_Generated::handleCommentStart()
2353 while (pos < input.size() - 1) {
2354 if (input.at(pos) == u'*' && input.at(pos + 1) == u'/') {
2363void Scanner::scan(
const QString &preprocessedInput, QList<Symbol> *symbols)
2365 QCssScanner_Generated scanner(preprocessedInput);
2367 int tok = scanner.lex();
2369 sym.token =
static_cast<QCss::TokenType>(tok);
2370 sym.text = scanner.input;
2371 sym.start = scanner.lexemStart;
2372 sym.len = scanner.lexemLength;
2373 symbols->append(sym);
2374 tok = scanner.lex();
2382 result.reserve(
len);
2383 for (
int i = 0; i <
len; ++i) {
2384 if (text.at(start + i) == u'\\' && i < len - 1)
2386 result += text.at(start + i);
2391Parser::Parser(
const QString &css,
bool isFile)
2400 hasEscapeSequences =
false;
2403void Parser::init(
const QString &css,
bool isFile)
2405 QString styleSheet = css;
2408 if (file.open(QFile::ReadOnly)) {
2409 sourcePath = QFileInfo(styleSheet).absolutePath() + u'/';
2410 QTextStream stream(&file);
2411 styleSheet = stream.readAll();
2413 qWarning() <<
"QCss::Parser - Failed to load file " << css;
2420 hasEscapeSequences =
false;
2423 Scanner::scan(Scanner::preprocess(styleSheet, &hasEscapeSequences), &symbols);
2428bool Parser::parse(StyleSheet *styleSheet, Qt::CaseSensitivity nameCaseSensitivity)
2430 if (testTokenAndEndsWith(ATKEYWORD_SYM,
"charset"_L1)) {
2431 while (test(S) || test(CDO) || test(CDC)) {}
2432 if (!next(STRING))
return false;
2433 if (!next(SEMICOLON))
return false;
2436 while (test(S) || test(CDO) || test(CDC)) {}
2438 while (testImport()) {
2440 if (!parseImport(&rule))
return false;
2441 styleSheet->importRules.append(rule);
2442 while (test(S) || test(CDO) || test(CDC)) {}
2448 if (!parseMedia(&rule))
return false;
2449 styleSheet->mediaRules.append(rule);
2450 }
else if (testPage()) {
2452 if (!parsePage(&rule))
return false;
2453 styleSheet->pageRules.append(rule);
2454 }
else if (testAnimation()) {
2456 if (!parseAnimation(&rule))
return false;
2457 styleSheet->animationRules.append(rule);
2458 }
else if (testRuleset()) {
2460 if (!parseRuleset(&rule))
return false;
2461 styleSheet->styleRules.append(rule);
2462 }
else if (test(ATKEYWORD_SYM)) {
2463 if (!until(RBRACE))
return false;
2464 }
else if (hasNext()) {
2467 while (test(S) || test(CDO) || test(CDC)) {}
2468 }
while (hasNext());
2469 styleSheet->buildIndexes(nameCaseSensitivity);
2473Symbol Parser::errorSymbol()
2475 if (errorIndex == -1)
return Symbol();
2476 return symbols.at(errorIndex);
2481 if (!str->startsWith(u'\'') && !str->startsWith(u'\"'))
2487bool Parser::parseImport(ImportRule *importRule)
2492 importRule->href = lexem();
2494 if (!testAndParseUri(&importRule->href))
return false;
2496 removeOptionalQuotes(&importRule->href);
2501 if (!parseMedium(&importRule->media))
return false;
2503 while (test(COMMA)) {
2505 if (!parseNextMedium(&importRule->media))
return false;
2509 if (!next(SEMICOLON))
return false;
2515bool Parser::parseMedia(MediaRule *mediaRule)
2519 if (!parseNextMedium(&mediaRule->media))
return false;
2520 }
while (test(COMMA));
2522 if (!next(LBRACE))
return false;
2525 while (testRuleset()) {
2527 if (!parseRuleset(&rule))
return false;
2528 mediaRule->styleRules.append(rule);
2531 if (!next(RBRACE))
return false;
2536bool Parser::parseMedium(QStringList *media)
2538 media->append(lexem());
2543bool Parser::parsePage(PageRule *pageRule)
2547 if (testPseudoPage())
2548 if (!parsePseudoPage(&pageRule->selector))
return false;
2551 if (!next(LBRACE))
return false;
2556 if (!parseNextDeclaration(&decl))
return false;
2557 if (!decl.isEmpty())
2558 pageRule->declarations.append(decl);
2559 }
while (test(SEMICOLON));
2561 if (!next(RBRACE))
return false;
2566bool Parser::parsePseudoPage(QString *selector)
2568 if (!next(IDENT))
return false;
2569 *selector = lexem();
2573bool Parser::parseNextOperator(Value *value)
2575 if (!hasNext())
return true;
2577 case SLASH: value->type = Value::TermOperatorSlash; skipSpace();
break;
2578 case COMMA: value->type = Value::TermOperatorComma; skipSpace();
break;
2579 default: prev();
break;
2584bool Parser::parseAnimation(AnimationRule *animationRule)
2587 if (!test(IDENT))
return false;
2589 animationRule->animName = lexem();
2591 if (!next(LBRACE))
return false;
2594 while (test(PERCENTAGE) || test(IDENT)) {
2595 AnimationRule::AnimationRuleSet set;
2596 if (lookup() == PERCENTAGE) {
2597 QString name = lexem();
2599 float keyFrame = name.toFloat() / 100;
2600 set.keyFrame = keyFrame;
2601 }
else if (lookup() == IDENT) {
2603 if (parseElementName(&name)) {
2604 if (name == QStringLiteral(
"from"))
2606 else if (name == QStringLiteral(
"to"))
2612 if (!next(LBRACE))
return false;
2613 const int declarationStart = index;
2618 const int rewind = index;
2619 if (!parseNextDeclaration(&decl)) {
2621 const bool foundSemicolon = until(SEMICOLON);
2622 const int semicolonIndex = index;
2624 index = declarationStart;
2625 const bool foundRBrace = until(RBRACE);
2627 if (foundSemicolon && semicolonIndex < index) {
2628 decl = Declaration();
2629 index = semicolonIndex - 1;
2635 if (!decl.isEmpty()) {
2636 if (decl.d->property ==
"animation-timing-function"_L1)
2637 set.timingFunction = std::move(decl);
2639 set.declarations.push_back(std::move(decl));
2641 }
while (test(SEMICOLON));
2643 if (!next(RBRACE))
return false;
2645 animationRule->ruleSets.append(set);
2648 if (!next(RBRACE))
return false;
2654bool Parser::parseCombinator(BasicSelector::Relation *relation)
2656 *relation = BasicSelector::NoRelation;
2657 if (lookup() == S) {
2658 *relation = BasicSelector::MatchNextSelectorIfAncestor;
2664 *relation = BasicSelector::MatchNextSelectorIfDirectAdjecent;
2665 }
else if (test(GREATER)) {
2666 *relation = BasicSelector::MatchNextSelectorIfParent;
2667 }
else if (test(TILDE)) {
2668 *relation = BasicSelector::MatchNextSelectorIfIndirectAdjecent;
2674bool Parser::parseProperty(Declaration *decl)
2676 decl->d->property = lexem();
2677 decl->d->propertyId = findKnownValue(decl->d->property, properties);
2678 decl->d->inheritable = isInheritable(decl->d->propertyId);
2683bool Parser::parseRuleset(StyleRule *styleRule)
2686 if (!parseSelector(&sel))
return false;
2687 styleRule->selectors.append(sel);
2689 while (test(COMMA)) {
2692 if (!parseNextSelector(&sel))
return false;
2693 styleRule->selectors.append(sel);
2697 if (!next(LBRACE))
return false;
2698 const int declarationStart = index;
2703 const int rewind = index;
2704 if (!parseNextDeclaration(&decl)) {
2706 const bool foundSemicolon = until(SEMICOLON);
2707 const int semicolonIndex = index;
2709 index = declarationStart;
2710 const bool foundRBrace = until(RBRACE);
2712 if (foundSemicolon && semicolonIndex < index) {
2713 decl = Declaration();
2714 index = semicolonIndex - 1;
2720 if (!decl.isEmpty())
2721 styleRule->declarations.append(decl);
2722 }
while (test(SEMICOLON));
2724 if (!next(RBRACE))
return false;
2729bool Parser::parseSelector(Selector *sel)
2731 BasicSelector basicSel;
2732 if (!parseSimpleSelector(&basicSel))
return false;
2733 while (testCombinator()) {
2734 if (!parseCombinator(&basicSel.relationToNext))
return false;
2736 if (!testSimpleSelector())
break;
2737 sel->basicSelectors.append(basicSel);
2739 basicSel = BasicSelector();
2740 if (!parseSimpleSelector(&basicSel))
return false;
2742 sel->basicSelectors.append(basicSel);
2746bool Parser::parseSimpleSelector(BasicSelector *basicSel)
2749 if (lookupElementName()) {
2750 if (!parseElementName(&basicSel->elementName))
return false;
2760 QString theid = lexem();
2763 basicSel->ids.append(theid);
2765 }
else if (testClass()) {
2767 AttributeSelector a;
2768 a.name =
"class"_L1;
2769 a.valueMatchCriterium = AttributeSelector::MatchIncludes;
2770 if (!parseClass(&a.value))
return false;
2771 basicSel->attributeSelectors.append(a);
2772 }
else if (testAttrib()) {
2774 AttributeSelector a;
2775 if (!parseAttrib(&a))
return false;
2776 basicSel->attributeSelectors.append(a);
2777 }
else if (testPseudo()) {
2780 if (!parsePseudo(&ps))
return false;
2781 basicSel->pseudos.append(ps);
2783 if (onceMore) ++count;
2785 return count >= minCount;
2788bool Parser::parseClass(QString *name)
2790 if (!next(IDENT))
return false;
2795bool Parser::parseElementName(QString *name)
2798 case STAR: name->clear();
break;
2799 case IDENT: *name = lexem();
break;
2800 default:
return false;
2805bool Parser::parseAttrib(AttributeSelector *attr)
2808 if (!next(IDENT))
return false;
2809 attr->name = lexem();
2813 attr->valueMatchCriterium = AttributeSelector::MatchEqual;
2814 }
else if (test(INCLUDES)) {
2815 attr->valueMatchCriterium = AttributeSelector::MatchIncludes;
2816 }
else if (test(DASHMATCH)) {
2817 attr->valueMatchCriterium = AttributeSelector::MatchDashMatch;
2818 }
else if (test(BEGINSWITH)) {
2819 attr->valueMatchCriterium = AttributeSelector::MatchBeginsWith;
2820 }
else if (test(ENDSWITH)) {
2821 attr->valueMatchCriterium = AttributeSelector::MatchEndsWith;
2822 }
else if (test(CONTAINS)) {
2823 attr->valueMatchCriterium = AttributeSelector::MatchContains;
2825 return next(RBRACKET);
2830 if (!test(IDENT) && !test(STRING))
return false;
2831 attr->value = unquotedLexem();
2834 return next(RBRACKET);
2837bool Parser::parsePseudo(Pseudo *pseudo)
2840 pseudo->negated = test(EXCLAMATION_SYM);
2842 pseudo->name = lexem();
2843 pseudo->type = findKnownValue(pseudo->name, pseudos);
2846 if (!next(FUNCTION))
return false;
2847 pseudo->function = lexem();
2849 pseudo->function.chop(1);
2851 if (!test(IDENT))
return false;
2852 pseudo->name = lexem();
2854 return next(RPAREN);
2857bool Parser::parseNextDeclaration(Declaration *decl)
2859 if (!testProperty())
2861 if (!parseProperty(decl))
return false;
2862 if (!next(COLON))
return false;
2864 if (!parseNextExpr(&decl->d->values))
return false;
2866 if (!parsePrio(decl))
return false;
2870bool Parser::testPrio()
2872 const int rewind = index;
2873 if (!test(EXCLAMATION_SYM))
return false;
2879 if (lexem().compare(
"important"_L1, Qt::CaseInsensitive) != 0) {
2886bool Parser::parsePrio(Declaration *declaration)
2888 declaration->d->important =
true;
2893bool Parser::parseExpr(QList<Value> *values)
2896 if (!parseTerm(&val))
return false;
2897 values->append(val);
2902 if (!parseNextOperator(&val))
return false;
2903 if (val.type != QCss::Value::Unknown)
2904 values->append(val);
2908 if (!parseTerm(&val))
return false;
2909 values->append(val);
2915bool Parser::testTerm()
2917 return test(PLUS) || test(MINUS)
2927bool Parser::parseTerm(Value *value)
2929 QString str = lexem();
2930 bool haveUnary =
false;
2931 if (lookup() == PLUS || lookup() == MINUS) {
2933 if (!hasNext())
return false;
2938 value->variant = str;
2939 value->type = QCss::Value::String;
2942 value->type = Value::Number;
2943 value->variant.convert(QMetaType::fromType<
double>());
2946 value->type = Value::Percentage;
2948 value->variant = str;
2951 value->type = Value::Length;
2955 if (haveUnary)
return false;
2956 value->type = Value::String;
2959 value->variant = str;
2962 if (haveUnary)
return false;
2963 value->type = Value::Identifier;
2964 const KnownValue theid = findKnownValue(str, values);
2965 if (theid != KnownValue::Unknown) {
2966 value->type = Value::KnownIdentifier;
2967 value->variant = QVariant::fromValue(theid);
2972 if (haveUnary)
return false;
2974 if (testHexColor()) {
2976 if (!parseHexColor(&col))
return false;
2977 value->type = Value::Color;
2978 value->variant = col;
2979 }
else if (testFunction()) {
2981 if (!parseFunction(&name, &args))
return false;
2982 if (name ==
"url"_L1) {
2983 value->type = Value::Uri;
2984 removeOptionalQuotes(&args);
2985 if (QFileInfo(args).isRelative() && !sourcePath.isEmpty()) {
2986 args.prepend(sourcePath);
2988 value->variant = std::move(args);
2990 value->type = Value::Function;
2991 value->variant = QStringList() << name << args;
2994 return recordError();
3003bool Parser::parseFunction(QString *name, QString *args)
3010 std::swap(start, index);
3011 if (!until(RPAREN))
return false;
3012 for (
int i = start; i < index - 1; ++i)
3013 args->append(symbols.at(i).lexem());
3015
3016
3017
3022bool Parser::parseHexColor(QColor *col)
3024 *col = QColor::fromString(lexem());
3025 if (!col->isValid()) {
3026 qWarning(
"QCssParser::parseHexColor: Unknown color name '%s'",lexem().toLatin1().constData());
3033bool Parser::testAndParseUri(QString *uri)
3035 const int rewind = index;
3036 if (!testFunction())
return false;
3039 if (!parseFunction(&name, &args)) {
3043 if (name.compare(
"url"_L1, Qt::CaseInsensitive) != 0) {
3047 *uri = std::move(args);
3048 removeOptionalQuotes(uri);
3052bool Parser::testSimpleSelector()
3054 return testElementName()
3061bool Parser::next(QCss::TokenType t)
3063 if (hasNext() && next() == t)
3065 return recordError();
3068bool Parser::test(QCss::TokenType t)
3070 if (index >= symbols.size())
3072 if (symbols.at(index).token == t) {
3079QString Parser::unquotedLexem()
const
3081 QString s = lexem();
3082 if (lookup() == STRING) {
3089QString Parser::lexemUntil(QCss::TokenType t)
3092 while (hasNext() && next() != t)
3093 lexem += symbol().lexem();
3097bool Parser::until(QCss::TokenType target, QCss::TokenType target2)
3103 switch(symbols.at(index-1).token) {
3104 case LBRACE: ++braceCount;
break;
3105 case LBRACKET: ++brackCount;
break;
3107 case LPAREN: ++parenCount;
break;
3111 while (index < symbols.size()) {
3112 QCss::TokenType t = symbols.at(index++).token;
3114 case LBRACE: ++braceCount;
break;
3115 case RBRACE: --braceCount;
break;
3116 case LBRACKET: ++brackCount;
break;
3117 case RBRACKET: --brackCount;
break;
3119 case LPAREN: ++parenCount;
break;
3120 case RPAREN: --parenCount;
break;
3123 if ((t == target || (target2 != NONE && t == target2))
3129 if (braceCount < 0 || brackCount < 0 || parenCount < 0) {
3137bool Parser::testTokenAndEndsWith(QCss::TokenType t, QLatin1StringView str)
3139 if (!test(t))
return false;
3140 if (!lexem().endsWith(str, Qt::CaseInsensitive)) {
@ StyleFeature_BackgroundGradient
@ StyleFeature_BackgroundColor
@ OutlineBottomLeftRadius
@ OutlineBottomRightRadius
@ QtForegroundTextureCacheKey
@ BorderBottomRightRadius
Combined button and popup list for selecting options.
static void setTextDecorationFromValues(const QList< QCss::Value > &values, QFont *font)
static bool operator<(const QString &name, const QCssKnownValue< T > &prop)
static constexpr QCssKnownValue< PositionMode > positions[]
static void removeOptionalQuotes(QString *str)
static constexpr QCssKnownValue< quint64 > pseudos[]
static constexpr QCssKnownValue< Repeat > repeats[]
static bool setFontFamilyFromValues(const QList< QCss::Value > &values, QFont *font, int start=0)
static bool setFontWeightFromValue(const QCss::Value &value, QFont *font)
static int lengthValueFromData(const LengthData &data, const QFont &f)
static void setTextTransformFromValue(const QCss::Value &value, QFont *font)
static bool setFontSizeFromValue(QCss::Value value, QFont *font, int *fontSizeAdjustment)
static constexpr QCssKnownValue< TileMode > tileModes[]
static bool setFontStyleFromValue(const QCss::Value &value, QFont *font)
static constexpr QCssKnownValue< Attachment > attachments[]
static ColorData parseColorValue(QCss::Value v)
static BorderStyle parseStyleValue(const QCss::Value &v)
static constexpr QCssKnownValue< Origin > origins[]
static void setFontVariantFromValue(const QCss::Value &value, QFont *font)
static bool intValueHelper(const QCss::Value &v, int *i, const char *unit)
#define CHECK_ARRAY_IS_SORTED(array, type)
static Qt::Alignment parseAlignment(const QCss::Value *values, int count)
static void setLetterSpacingFromValue(const QCss::Value &value, QFont *font)
static BrushData parseBrushValue(const QCss::Value &v, const QPalette &pal)
static bool isHexDigit(const char c)
static bool isInheritable(Property propertyId)
static constexpr QCssKnownValue< Property > properties[]
static constexpr uchar indexOfId[]
static bool setFontKerningFromValue(const QCss::Value &value, QFont *font)
static void parseShorthandBackgroundProperty(const QList< QCss::Value > &values, BrushData *brush, QString *image, Repeat *repeat, Qt::Alignment *alignment, const QPalette &pal)
static void parseShorthandFontProperty(const QList< QCss::Value > &values, QFont *font, int *fontSizeAdjustment)
static constexpr QCssKnownValue< int > styleFeatures[]
static constexpr QCssKnownValue< KnownValue > values[]
static QBrush brushFromData(const BrushData &c, const QPalette &pal)
static auto findKnownValue(const QString &name, const C &arr)
static void setWordSpacingFromValue(const QCss::Value &value, QFont *font)
static bool operator<(const QCssKnownValue< T > &prop, const QString &name)
static QColor colorFromData(const ColorData &c, const QPalette &pal)
constexpr bool operator()(const QCssKnownValue< T > &lhs, const QCssKnownValue< T > &rhs) const noexcept
Q_GUI_EXPORT void buildIndexes(Qt::CaseSensitivity nameCaseSensitivity=Qt::CaseSensitive)