Qt 4.8
Classes | Functions | Variables
qcssparser.cpp File Reference
#include "qcssparser_p.h"
#include <qdebug.h>
#include <qcolor.h>
#include <qfont.h>
#include <qfileinfo.h>
#include <qfontmetrics.h>
#include <qbrush.h>
#include <qimagereader.h>
#include "private/qfunctions_p.h"
#include "qcssscanner.cpp"

Go to the source code of this file.

Classes

struct  QCssKnownValue
 

Functions

static QBrush brushFromData (const BrushData &c, const QPalette &pal)
 
static QColor colorFromData (const ColorData &c, const QPalette &pal)
 
static quint64 findKnownValue (const QString &name, const QCssKnownValue *start, int numValues)
 
static bool intValueHelper (const QCss::Value &v, int *i, const char *unit)
 
static bool isHexDigit (const char c)
 
static int lengthValueFromData (const LengthData &data, const QFont &f)
 
Q_STATIC_GLOBAL_OPERATOR bool operator< (const QString &name, const QCssKnownValue &prop)
 
Q_STATIC_GLOBAL_OPERATOR bool operator< (const QCssKnownValue &prop, const QString &name)
 
static Qt::Alignment parseAlignment (const QCss::Value *values, int count)
 
static BrushData parseBrushValue (const QCss::Value &v, const QPalette &pal)
 
static ColorData parseColorValue (QCss::Value v)
 
static void parseShorthandBackgroundProperty (const QVector< QCss::Value > &values, BrushData *brush, QString *image, Repeat *repeat, Qt::Alignment *alignment, const QPalette &pal)
 
static void parseShorthandFontProperty (const QVector< QCss::Value > &values, QFont *font, int *fontSizeAdjustment)
 
static BorderStyle parseStyleValue (QCss::Value v)
 
static void removeOptionalQuotes (QString *str)
 
static bool setFontFamilyFromValues (const QVector< QCss::Value > &values, QFont *font, int start=0)
 
static bool setFontSizeFromValue (QCss::Value value, QFont *font, int *fontSizeAdjustment)
 
static bool setFontStyleFromValue (const QCss::Value &value, QFont *font)
 
static void setFontVariantFromValue (const QCss::Value &value, QFont *font)
 
static bool setFontWeightFromValue (const QCss::Value &value, QFont *font)
 
static void setTextDecorationFromValues (const QVector< QCss::Value > &values, QFont *font)
 
static void setTextTransformFromValue (const QCss::Value &value, QFont *font)
 

Variables

static const QCssKnownValue attachments [NumKnownAttachments - 1]
 
static const short indexOfId [NumKnownValues]
 
static const QCssKnownValue origins [NumKnownOrigins - 1]
 
static const QCssKnownValue positions [NumKnownPositionModes - 1]
 
static const QCssKnownValue properties [NumProperties - 1]
 
static const QCssKnownValue pseudos [NumPseudos - 1]
 
static const QCssKnownValue repeats [NumKnownRepeats - 1]
 
static const QCssKnownValue styleFeatures [NumKnownStyleFeatures - 1]
 
static const QCssKnownValue tileModes [NumKnownTileModes - 1]
 
static const QCssKnownValue values [NumKnownValues - 1]
 

Function Documentation

◆ brushFromData()

static QBrush brushFromData ( const BrushData c,
const QPalette pal 
)
static

Definition at line 850 of file qcssparser.cpp.

Referenced by QCss::ValueExtractor::borderValue(), and QCss::ValueExtractor::extractBackground().

851 {
852  if (c.type == BrushData::Role) {
853  return pal.color(c.role);
854  } else {
855  return c.brush;
856  }
857 }
QPalette::ColorRole role
Definition: qcssparser_p.h:390
enum QCss::BrushData::@265 type
const QColor & color(ColorGroup cg, ColorRole cr) const
Returns the color in the specified color group, used for the given color role.
Definition: qpalette.h:107

◆ colorFromData()

static QColor colorFromData ( const ColorData c,
const QPalette pal 
)
static

Definition at line 731 of file qcssparser.cpp.

Referenced by parseBrushValue().

732 {
733  if (c.type == ColorData::Color) {
734  return c.color;
735  } else if (c.type == ColorData::Role) {
736  return pal.color(c.role);
737  }
738  return QColor();
739 }
QPalette::ColorRole role
Definition: qcssparser_p.h:381
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
const QColor & color(ColorGroup cg, ColorRole cr) const
Returns the color in the specified color group, used for the given color role.
Definition: qpalette.h:107
enum QCss::ColorData::@264 type

◆ findKnownValue()

static quint64 findKnownValue ( const QString name,
const QCssKnownValue start,
int  numValues 
)
static

Definition at line 357 of file qcssparser.cpp.

Referenced by QCss::Declaration::attachmentValue(), QCss::Declaration::borderImageValue(), QCss::ValueExtractor::extractBackground(), QCss::Declaration::originValue(), parseColorValue(), QCss::Parser::parseProperty(), parseShorthandBackgroundProperty(), QCss::Parser::parseTerm(), QCss::Declaration::positionValue(), QCss::Declaration::repeatValue(), and QCss::Declaration::styleFeaturesValue().

358 {
359  const QCssKnownValue *end = &start[numValues - 1];
360  const QCssKnownValue *prop = qBinaryFind(start, end, name);
361  if (prop == end)
362  return 0;
363  return prop->id;
364 }
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qBinaryFind(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
Definition: qalgorithms.h:295
static const KeyPair *const end

◆ intValueHelper()

static bool intValueHelper ( const QCss::Value v,
int *  i,
const char *  unit 
)
static

Definition at line 1414 of file qcssparser.cpp.

Referenced by QCss::Declaration::intValue(), and QCss::Declaration::sizeValue().

1415 {
1416  if (unit && v.type != Value::Length)
1417  return false;
1418  QString s = v.variant.toString();
1419  if (unit) {
1421  return false;
1422  s.chop(qstrlen(unit));
1423  }
1424  bool ok = false;
1425  int val = s.toInt(&ok);
1426  if (ok)
1427  *i = val;
1428  return ok;
1429 }
int toInt(bool *ok=0, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
Definition: qstring.cpp:6090
void chop(int n)
Removes n characters from the end of the string.
Definition: qstring.cpp:4623
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
The QString class provides a Unicode character string.
Definition: qstring.h:83
QVariant variant
Definition: qcssparser_p.h:372
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
uint qstrlen(const char *str)
Definition: qbytearray.h:79
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796

◆ isHexDigit()

static bool isHexDigit ( const char  c)
inlinestatic

Definition at line 2004 of file qcssparser.cpp.

Referenced by QCss::Scanner::preprocess().

2005 {
2006  return (c >= '0' && c <= '9')
2007  || (c >= 'a' && c <= 'f')
2008  || (c >= 'A' && c <= 'F')
2009  ;
2010 }
unsigned char c[8]
Definition: qnumeric_p.h:62

◆ lengthValueFromData()

static int lengthValueFromData ( const LengthData data,
const QFont f 
)
static

Definition at line 393 of file qcssparser.cpp.

Referenced by QCss::ValueExtractor::borderValue(), QCss::ValueExtractor::lengthValue(), QCss::ValueExtractor::lengthValues(), and QCss::ValueExtractor::sizeValue().

394 {
395  if (data.unit == LengthData::Ex)
396  return qRound(QFontMetrics(f).xHeight() * data.number);
397  else if (data.unit == LengthData::Em)
398  return qRound(QFontMetrics(f).height() * data.number);
399  return qRound(data.number);
400 }
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
enum QCss::LengthData::@266 unit
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ operator<() [1/2]

Q_STATIC_GLOBAL_OPERATOR bool operator< ( const QString name,
const QCssKnownValue prop 
)

Definition at line 347 of file qcssparser.cpp.

348 {
349  return QString::compare(name, QLatin1String(prop.name), Qt::CaseInsensitive) < 0;
350 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int compare(const QString &s) const
Definition: qstring.cpp:5037
const char * name
Definition: qcssparser.cpp:63

◆ operator<() [2/2]

Q_STATIC_GLOBAL_OPERATOR bool operator< ( const QCssKnownValue prop,
const QString name 
)

Definition at line 352 of file qcssparser.cpp.

353 {
354  return QString::compare(QLatin1String(prop.name), name, Qt::CaseInsensitive) < 0;
355 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int compare(const QString &s) const
Definition: qstring.cpp:5037
const char * name
Definition: qcssparser.cpp:63

◆ parseAlignment()

static Qt::Alignment parseAlignment ( const QCss::Value values,
int  count 
)
static

Definition at line 652 of file qcssparser.cpp.

Referenced by QCss::Declaration::alignmentValue(), and parseShorthandBackgroundProperty().

653 {
654  Qt::Alignment a[2] = { 0, 0 };
655  for (int i = 0; i < qMin(2, count); i++) {
656  if (values[i].type != Value::KnownIdentifier)
657  break;
658  switch (values[i].variant.toInt()) {
659  case Value_Left: a[i] = Qt::AlignLeft; break;
660  case Value_Right: a[i] = Qt::AlignRight; break;
661  case Value_Top: a[i] = Qt::AlignTop; break;
662  case Value_Bottom: a[i] = Qt::AlignBottom; break;
663  case Value_Center: a[i] = Qt::AlignCenter; break;
664  default: break;
665  }
666  }
667 
668  if (a[0] == Qt::AlignCenter && a[1] != 0 && a[1] != Qt::AlignCenter)
669  a[0] = (a[1] == Qt::AlignLeft || a[1] == Qt::AlignRight) ? Qt::AlignVCenter : Qt::AlignHCenter;
670  if ((a[1] == 0 || a[1] == Qt::AlignCenter) && a[0] != Qt::AlignCenter)
671  a[1] = (a[0] == Qt::AlignLeft || a[0] == Qt::AlignRight) ? Qt::AlignVCenter : Qt::AlignHCenter;
672  return a[0] | a[1];
673 }
int type
Definition: qmetatype.cpp:239
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
long ASN1_INTEGER_get ASN1_INTEGER * a
const char * variant

◆ parseBrushValue()

static BrushData parseBrushValue ( const QCss::Value v,
const QPalette pal 
)
static

Definition at line 741 of file qcssparser.cpp.

Referenced by QCss::ValueExtractor::borderValue(), QCss::Declaration::brushValue(), QCss::Declaration::brushValues(), and parseShorthandBackgroundProperty().

742 {
744  if (c.type == ColorData::Color) {
745  return QBrush(c.color);
746  } else if (c.type == ColorData::Role) {
747  return c.role;
748  }
749 
750  if (v.type != Value::Function)
751  return BrushData();
752 
753  QStringList lst = v.variant.toStringList();
754  if (lst.count() != 2)
755  return BrushData();
756 
757  QStringList gradFuncs;
758  gradFuncs << QLatin1String("qlineargradient") << QLatin1String("qradialgradient") << QLatin1String("qconicalgradient") << QLatin1String("qgradient");
759  int gradType = -1;
760 
761  if ((gradType = gradFuncs.indexOf(lst.at(0).toLower())) == -1)
762  return BrushData();
763 
766 
767  int spread = -1;
768  QStringList spreads;
769  spreads << QLatin1String("pad") << QLatin1String("reflect") << QLatin1String("repeat");
770 
771  bool dependsOnThePalette = false;
772  Parser parser(lst.at(1));
773  while (parser.hasNext()) {
774  parser.skipSpace();
775  if (!parser.test(IDENT))
776  return BrushData();
777  QString attr = parser.lexem();
778  parser.skipSpace();
779  if (!parser.test(COLON))
780  return BrushData();
781  parser.skipSpace();
782  if (attr.compare(QLatin1String("stop"), Qt::CaseInsensitive) == 0) {
783  QCss::Value stop, color;
784  parser.next();
785  if (!parser.parseTerm(&stop)) return BrushData();
786  parser.skipSpace();
787  parser.next();
788  if (!parser.parseTerm(&color)) return BrushData();
789  ColorData cd = parseColorValue(color);
790  if(cd.type == ColorData::Role)
791  dependsOnThePalette = true;
792  stops.append(QGradientStop(stop.variant.toReal(), colorFromData(cd, pal)));
793  } else {
794  parser.next();
795  QCss::Value value;
796  (void)parser.parseTerm(&value);
797  if (attr.compare(QLatin1String("spread"), Qt::CaseInsensitive) == 0) {
798  spread = spreads.indexOf(value.variant.toString());
799  } else {
800  vars[attr] = value.variant.toReal();
801  }
802  }
803  parser.skipSpace();
804  (void)parser.test(COMMA);
805  }
806 
807  if (gradType == 0) {
808  QLinearGradient lg(vars.value(QLatin1String("x1")), vars.value(QLatin1String("y1")),
809  vars.value(QLatin1String("x2")), vars.value(QLatin1String("y2")));
811  lg.setStops(stops);
812  if (spread != -1)
813  lg.setSpread(QGradient::Spread(spread));
814  BrushData bd = QBrush(lg);
815  if (dependsOnThePalette)
816  bd.type = BrushData::DependsOnThePalette;
817  return bd;
818  }
819 
820  if (gradType == 1) {
821  QRadialGradient rg(vars.value(QLatin1String("cx")), vars.value(QLatin1String("cy")),
822  vars.value(QLatin1String("radius")), vars.value(QLatin1String("fx")),
823  vars.value(QLatin1String("fy")));
825  rg.setStops(stops);
826  if (spread != -1)
827  rg.setSpread(QGradient::Spread(spread));
828  BrushData bd = QBrush(rg);
829  if (dependsOnThePalette)
830  bd.type = BrushData::DependsOnThePalette;
831  return bd;
832  }
833 
834  if (gradType == 2) {
835  QConicalGradient cg(vars.value(QLatin1String("cx")), vars.value(QLatin1String("cy")),
836  vars.value(QLatin1String("angle")));
838  cg.setStops(stops);
839  if (spread != -1)
840  cg.setSpread(QGradient::Spread(spread));
841  BrushData bd = QBrush(cg);
842  if (dependsOnThePalette)
843  bd.type = BrushData::DependsOnThePalette;
844  return bd;
845  }
846 
847  return BrushData();
848 }
QPalette::ColorRole role
Definition: qcssparser_p.h:381
unsigned char c[8]
Definition: qnumeric_p.h:62
enum QCss::BrushData::@265 type
The QConicalGradient class is used in combination with QBrush to specify a conical gradient brush...
Definition: qbrush.h:329
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
static QColor colorFromData(const ColorData &c, const QPalette &pal)
Definition: qcssparser.cpp:731
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QRadialGradient class is used in combination with QBrush to specify a radial gradient brush...
Definition: qbrush.h:297
The QString class provides a Unicode character string.
Definition: qstring.h:83
void skipSpace()
Definition: qcssparser_p.h:809
QVariant variant
Definition: qcssparser_p.h:372
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
QStringList toStringList() const
Returns the variant as a QStringList if the variant has type() StringList, String ...
Definition: qvariant.cpp:2259
int indexOf(const QRegExp &rx, int from=0) const
Returns the index position of the first exact match of rx in the list, searching forward from index p...
Definition: qstringlist.h:195
QGradientStop
Typedef for QPair<qreal , QColor>.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
Spread
Specifies how the area outside the gradient area should be filled.
Definition: qbrush.h:213
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
static ColorData parseColorValue(QCss::Value v)
Definition: qcssparser.cpp:675
int compare(const QString &s) const
Definition: qstring.cpp:5037
The QLinearGradient class is used in combination with QBrush to specify a linear gradient brush...
Definition: qbrush.h:280
void setCoordinateMode(CoordinateMode mode)
Sets the coordinate mode of this gradient to mode.
Definition: qbrush.cpp:1578
enum QCss::ColorData::@264 type
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
qreal toReal(bool *ok=0) const
Returns the variant as a qreal if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2740

◆ parseColorValue()

static ColorData parseColorValue ( QCss::Value  v)
static

Definition at line 675 of file qcssparser.cpp.

Referenced by QCss::Declaration::colorValue(), QCss::Declaration::colorValues(), and parseBrushValue().

676 {
677  if (v.type == Value::Identifier || v.type == Value::String) {
679  v.type = Value::Color;
680  }
681 
682  if (v.type == Value::Color)
683  return qvariant_cast<QColor>(v.variant);
684 
685  if (v.type == Value::KnownIdentifier && v.variant.toInt() == Value_Transparent)
686  return QColor(Qt::transparent);
687 
688  if (v.type != Value::Function)
689  return ColorData();
690 
691  QStringList lst = v.variant.toStringList();
692  if (lst.count() != 2)
693  return ColorData();
694 
695  if ((lst.at(0).compare(QLatin1String("palette"), Qt::CaseInsensitive)) == 0) {
696  int role = findKnownValue(lst.at(1).trimmed(), values, NumKnownValues);
697  if (role >= Value_FirstColorRole && role <= Value_LastColorRole)
699 
700  return ColorData();
701  }
702 
703  bool rgb = lst.at(0).startsWith(QLatin1String("rgb"));
704 
705  Parser p(lst.at(1));
706  if (!p.testExpr())
707  return ColorData();
708 
709  QVector<QCss::Value> colorDigits;
710  if (!p.parseExpr(&colorDigits))
711  return ColorData();
712 
713  for (int i = 0; i < qMin(colorDigits.count(), 7); i += 2) {
714  if (colorDigits.at(i).type == Value::Percentage) {
715  colorDigits[i].variant = colorDigits.at(i).variant.toReal() * (255. / 100.);
716  colorDigits[i].type = Value::Number;
717  } else if (colorDigits.at(i).type != Value::Number) {
718  return ColorData();
719  }
720  }
721 
722  int v1 = colorDigits.at(0).variant.toInt();
723  int v2 = colorDigits.at(2).variant.toInt();
724  int v3 = colorDigits.at(4).variant.toInt();
725  int alpha = colorDigits.count() >= 7 ? colorDigits.at(6).variant.toInt() : 255;
726 
727  return rgb ? QColor::fromRgb(v1, v2, v3, alpha)
728  : QColor::fromHsv(v1, v2, v3, alpha);
729 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
ColorRole
The ColorRole enum defines the different symbolic color roles used in current GUIs.
Definition: qpalette.h:93
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QVariant variant
Definition: qcssparser_p.h:372
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
QStringList toStringList() const
Returns the variant as a QStringList if the variant has type() StringList, String ...
Definition: qvariant.cpp:2259
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static quint64 findKnownValue(const QString &name, const QCssKnownValue *start, int numValues)
Definition: qcssparser.cpp:357
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
static const QCssKnownValue values[NumKnownValues - 1]
Definition: qcssparser.cpp:172
#define rgb(r, g, b)
Definition: qcolor_p.cpp:130
bool convert(Type t)
Casts the variant to the requested type, t.
Definition: qvariant.cpp:2959
int compare(const QString &s) const
Definition: qstring.cpp:5037
static QColor fromRgb(QRgb rgb)
Static convenience function that returns a QColor constructed from the given QRgb value rgb...
Definition: qcolor.cpp:1958
qreal toReal(bool *ok=0) const
Returns the variant as a qreal if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2740
T qvariant_cast(const QVariant &value)
Returns the given value converted to the template type T.
Definition: qvariant.h:571

◆ parseShorthandBackgroundProperty()

static void parseShorthandBackgroundProperty ( const QVector< QCss::Value > &  values,
BrushData brush,
QString image,
Repeat repeat,
Qt::Alignment *  alignment,
const QPalette pal 
)
static

Definition at line 944 of file qcssparser.cpp.

Referenced by QCss::ValueExtractor::extractBackground().

945 {
946  *brush = BrushData();
947  *image = QString();
948  *repeat = Repeat_XY;
949  *alignment = Qt::AlignTop | Qt::AlignLeft;
950 
951  for (int i = 0; i < values.count(); ++i) {
952  const QCss::Value &v = values.at(i);
953  if (v.type == Value::Uri) {
954  *image = v.variant.toString();
955  continue;
956  } else if (v.type == Value::KnownIdentifier && v.variant.toInt() == Value_None) {
957  *image = QString();
958  continue;
959  } else if (v.type == Value::KnownIdentifier && v.variant.toInt() == Value_Transparent) {
960  *brush = QBrush(Qt::transparent);
961  }
962 
963  Repeat repeatAttempt = static_cast<Repeat>(findKnownValue(v.variant.toString(),
965  if (repeatAttempt != Repeat_Unknown) {
966  *repeat = repeatAttempt;
967  continue;
968  }
969 
970  if (v.type == Value::KnownIdentifier) {
971  const int start = i;
972  int count = 1;
973  if (i < values.count() - 1
974  && values.at(i + 1).type == Value::KnownIdentifier) {
975  ++i;
976  ++count;
977  }
978  Qt::Alignment a = parseAlignment(values.constData() + start, count);
979  if (int(a) != 0) {
980  *alignment = a;
981  continue;
982  }
983  i -= count - 1;
984  }
985 
986  *brush = parseBrushValue(v, pal);
987  }
988 }
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
static Qt::Alignment parseAlignment(const QCss::Value *values, int count)
Definition: qcssparser.cpp:652
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
long ASN1_INTEGER_get ASN1_INTEGER * a
The QString class provides a Unicode character string.
Definition: qstring.h:83
static BrushData parseBrushValue(const QCss::Value &v, const QPalette &pal)
Definition: qcssparser.cpp:741
QVariant variant
Definition: qcssparser_p.h:372
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
static quint64 findKnownValue(const QString &name, const QCssKnownValue *start, int numValues)
Definition: qcssparser.cpp:357
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
const T * constData() const
Returns a const pointer to the data stored in the vector.
Definition: qvector.h:154
static const QCssKnownValue repeats[NumKnownRepeats - 1]
Definition: qcssparser.cpp:316

◆ parseShorthandFontProperty()

static void parseShorthandFontProperty ( const QVector< QCss::Value > &  values,
QFont font,
int *  fontSizeAdjustment 
)
static

Definition at line 1168 of file qcssparser.cpp.

Referenced by QCss::ValueExtractor::extractFont().

1169 {
1171  font->setWeight(QFont::Normal);
1172  *fontSizeAdjustment = -255;
1173 
1174  int i = 0;
1175  while (i < values.count()) {
1176  if (setFontStyleFromValue(values.at(i), font)
1177  || setFontWeightFromValue(values.at(i), font))
1178  ++i;
1179  else
1180  break;
1181  }
1182 
1183  if (i < values.count()) {
1184  setFontSizeFromValue(values.at(i), font, fontSizeAdjustment);
1185  ++i;
1186  }
1187 
1188  if (i < values.count()) {
1189  setFontFamilyFromValues(values, font, i);
1190  }
1191 }
static bool setFontFamilyFromValues(const QVector< QCss::Value > &values, QFont *font, int start=0)
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
static bool setFontStyleFromValue(const QCss::Value &value, QFont *font)
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
void setWeight(int)
Sets the weight the font to weight, which should be a value from the QFont::Weight enumeration...
Definition: qfont.cpp:1278
static bool setFontSizeFromValue(QCss::Value value, QFont *font, int *fontSizeAdjustment)
static bool setFontWeightFromValue(const QCss::Value &value, QFont *font)
void setStyle(Style style)
Sets the style of the font to style.
Definition: qfont.cpp:1234

◆ parseStyleValue()

static BorderStyle parseStyleValue ( QCss::Value  v)
static

Definition at line 859 of file qcssparser.cpp.

Referenced by QCss::ValueExtractor::borderValue(), QCss::Declaration::styleValue(), and QCss::Declaration::styleValues().

860 {
861  if (v.type == Value::KnownIdentifier) {
862  switch (v.variant.toInt()) {
863  case Value_None:
864  return BorderStyle_None;
865  case Value_Dotted:
866  return BorderStyle_Dotted;
867  case Value_Dashed:
868  return BorderStyle_Dashed;
869  case Value_Solid:
870  return BorderStyle_Solid;
871  case Value_Double:
872  return BorderStyle_Double;
873  case Value_DotDash:
874  return BorderStyle_DotDash;
875  case Value_DotDotDash:
876  return BorderStyle_DotDotDash;
877  case Value_Groove:
878  return BorderStyle_Groove;
879  case Value_Ridge:
880  return BorderStyle_Ridge;
881  case Value_Inset:
882  return BorderStyle_Inset;
883  case Value_Outset:
884  return BorderStyle_Outset;
885  case Value_Native:
886  return BorderStyle_Native;
887  default:
888  break;
889  }
890  }
891 
892  return BorderStyle_Unknown;
893 }
QVariant variant
Definition: qcssparser_p.h:372
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625

◆ removeOptionalQuotes()

static void removeOptionalQuotes ( QString str)
inlinestatic

Definition at line 2179 of file qcssparser.cpp.

Referenced by QCss::Parser::parseImport(), QCss::Parser::parseTerm(), and QCss::Parser::testAndParseUri().

2180 {
2181  if (!str->startsWith(QLatin1Char('\''))
2182  && !str->startsWith(QLatin1Char('\"')))
2183  return;
2184  str->remove(0, 1);
2185  str->chop(1);
2186 }
void chop(int n)
Removes n characters from the end of the string.
Definition: qstring.cpp:4623
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ setFontFamilyFromValues()

static bool setFontFamilyFromValues ( const QVector< QCss::Value > &  values,
QFont font,
int  start = 0 
)
static
Warning
This function is not part of the public interface. parse the font family from the values (starting from index start) and set it the font
Returns
true if a family was extracted.

Definition at line 1124 of file qcssparser.cpp.

Referenced by QCss::ValueExtractor::extractFont(), and parseShorthandFontProperty().

1125 {
1126  QString family;
1127  bool shouldAddSpace = false;
1128  for (int i = start; i < values.count(); ++i) {
1129  const QCss::Value &v = values.at(i);
1130  if (v.type == Value::TermOperatorComma) {
1131  family += QLatin1Char(',');
1132  shouldAddSpace = false;
1133  continue;
1134  }
1135  const QString str = v.variant.toString();
1136  if (str.isEmpty())
1137  break;
1138  if (shouldAddSpace)
1139  family += QLatin1Char(' ');
1140  family += str;
1141  shouldAddSpace = true;
1142  }
1143  if (family.isEmpty())
1144  return false;
1145  font->setFamily(family);
1146  return true;
1147 }
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
The QString class provides a Unicode character string.
Definition: qstring.h:83
QVariant variant
Definition: qcssparser_p.h:372
void setFamily(const QString &)
Sets the family name of the font.
Definition: qfont.cpp:924
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ setFontSizeFromValue()

static bool setFontSizeFromValue ( QCss::Value  value,
QFont font,
int *  fontSizeAdjustment 
)
static

Definition at line 1053 of file qcssparser.cpp.

Referenced by QCss::ValueExtractor::extractFont(), and parseShorthandFontProperty().

1054 {
1055  if (value.type == Value::KnownIdentifier) {
1056  bool valid = true;
1057  switch (value.variant.toInt()) {
1058  case Value_Small: *fontSizeAdjustment = -1; break;
1059  case Value_Medium: *fontSizeAdjustment = 0; break;
1060  case Value_Large: *fontSizeAdjustment = 1; break;
1061  case Value_XLarge: *fontSizeAdjustment = 2; break;
1062  case Value_XXLarge: *fontSizeAdjustment = 3; break;
1063  default: valid = false; break;
1064  }
1065  return valid;
1066  }
1067  if (value.type != Value::Length)
1068  return false;
1069 
1070  bool valid = false;
1071  QString s = value.variant.toString();
1072  if (s.endsWith(QLatin1String("pt"), Qt::CaseInsensitive)) {
1073  s.chop(2);
1074  value.variant = s;
1075  if (value.variant.convert((QVariant::Type)qMetaTypeId<qreal>())) {
1076  font->setPointSizeF(value.variant.toReal());
1077  valid = true;
1078  }
1079  } else if (s.endsWith(QLatin1String("px"), Qt::CaseInsensitive)) {
1080  s.chop(2);
1081  value.variant = s;
1082  if (value.variant.convert(QVariant::Int)) {
1083  font->setPixelSize(value.variant.toInt());
1084  valid = true;
1085  }
1086  }
1087  return valid;
1088 }
void chop(int n)
Removes n characters from the end of the string.
Definition: qstring.cpp:4623
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
The QString class provides a Unicode character string.
Definition: qstring.h:83
QVariant variant
Definition: qcssparser_p.h:372
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
bool convert(Type t)
Casts the variant to the requested type, t.
Definition: qvariant.cpp:2959
void setPointSizeF(qreal)
Sets the point size to pointSize.
Definition: qfont.cpp:1121
void setPixelSize(int)
Sets the font size to pixelSize pixels.
Definition: qfont.cpp:1156
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
qreal toReal(bool *ok=0) const
Returns the variant as a qreal if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2740

◆ setFontStyleFromValue()

static bool setFontStyleFromValue ( const QCss::Value value,
QFont font 
)
static

Definition at line 1090 of file qcssparser.cpp.

Referenced by QCss::ValueExtractor::extractFont(), and parseShorthandFontProperty().

1091 {
1092  if (value.type != Value::KnownIdentifier)
1093  return false ;
1094  switch (value.variant.toInt()) {
1095  case Value_Normal: font->setStyle(QFont::StyleNormal); return true;
1096  case Value_Italic: font->setStyle(QFont::StyleItalic); return true;
1097  case Value_Oblique: font->setStyle(QFont::StyleOblique); return true;
1098  default: break;
1099  }
1100  return false;
1101 }
QVariant variant
Definition: qcssparser_p.h:372
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
void setStyle(Style style)
Sets the style of the font to style.
Definition: qfont.cpp:1234

◆ setFontVariantFromValue()

static void setFontVariantFromValue ( const QCss::Value value,
QFont font 
)
static

Definition at line 1193 of file qcssparser.cpp.

Referenced by QCss::ValueExtractor::extractFont().

1194 {
1195  if (value.type == Value::KnownIdentifier) {
1196  switch (value.variant.toInt()) {
1197  case Value_Normal: font->setCapitalization(QFont::MixedCase); break;
1199  default: break;
1200  }
1201  }
1202 }
void setCapitalization(Capitalization)
Sets the capitalization of the text in this font to caps.
Definition: qfont.cpp:1798
QVariant variant
Definition: qcssparser_p.h:372
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625

◆ setFontWeightFromValue()

static bool setFontWeightFromValue ( const QCss::Value value,
QFont font 
)
static

Definition at line 1103 of file qcssparser.cpp.

Referenced by QCss::ValueExtractor::extractFont(), and parseShorthandFontProperty().

1104 {
1105  if (value.type == Value::KnownIdentifier) {
1106  switch (value.variant.toInt()) {
1107  case Value_Normal: font->setWeight(QFont::Normal); return true;
1108  case Value_Bold: font->setWeight(QFont::Bold); return true;
1109  default: break;
1110  }
1111  return false;
1112  }
1113  if (value.type != Value::Number)
1114  return false;
1115  font->setWeight(qMin(value.variant.toInt() / 8, 99));
1116  return true;
1117 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
QVariant variant
Definition: qcssparser_p.h:372
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
void setWeight(int)
Sets the weight the font to weight, which should be a value from the QFont::Weight enumeration...
Definition: qfont.cpp:1278

◆ setTextDecorationFromValues()

static void setTextDecorationFromValues ( const QVector< QCss::Value > &  values,
QFont font 
)
static

Definition at line 1149 of file qcssparser.cpp.

Referenced by QCss::ValueExtractor::extractFont().

1150 {
1151  for (int i = 0; i < values.count(); ++i) {
1152  if (values.at(i).type != Value::KnownIdentifier)
1153  continue;
1154  switch (values.at(i).variant.toInt()) {
1155  case Value_Underline: font->setUnderline(true); break;
1156  case Value_Overline: font->setOverline(true); break;
1157  case Value_LineThrough: font->setStrikeOut(true); break;
1158  case Value_None:
1159  font->setUnderline(false);
1160  font->setOverline(false);
1161  font->setStrikeOut(false);
1162  break;
1163  default: break;
1164  }
1165  }
1166 }
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
void setUnderline(bool)
If enable is true, sets underline on; otherwise sets underline off.
Definition: qfont.cpp:1331
QVariant variant
Definition: qcssparser_p.h:372
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
void setStrikeOut(bool)
If enable is true, sets strikeout on; otherwise sets strikeout off.
Definition: qfont.cpp:1378
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
void setOverline(bool)
If enable is true, sets overline on; otherwise sets overline off.
Definition: qfont.cpp:1354

◆ setTextTransformFromValue()

static void setTextTransformFromValue ( const QCss::Value value,
QFont font 
)
static

Definition at line 1204 of file qcssparser.cpp.

Referenced by QCss::ValueExtractor::extractFont().

1205 {
1206  if (value.type == Value::KnownIdentifier) {
1207  switch (value.variant.toInt()) {
1208  case Value_None: font->setCapitalization(QFont::MixedCase); break;
1211  default: break;
1212  }
1213  }
1214 }
void setCapitalization(Capitalization)
Sets the capitalization of the text in this font to caps.
Definition: qfont.cpp:1798
QVariant variant
Definition: qcssparser_p.h:372
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625

Variable Documentation

◆ attachments

const QCssKnownValue attachments[NumKnownAttachments - 1]
static
Initial value:

Definition at line 336 of file qcssparser.cpp.

Referenced by QCss::Declaration::attachmentValue().

◆ indexOfId

const short indexOfId[NumKnownValues]
static
Initial value:
= { 0, 41, 48, 42, 49, 54, 35, 26, 70, 71, 25, 43, 5, 63, 47,
29, 58, 59, 27, 51, 61, 6, 10, 39, 56, 19, 13, 17, 18, 20, 21, 50, 24, 46, 67, 37, 3, 2, 40, 62, 16,
11, 57, 14, 32, 64, 33, 65, 55, 66, 34, 69, 8, 28, 38, 12, 36, 60, 7, 9, 4, 68, 53, 22, 23, 30, 31,
1, 15, 0, 52, 45, 44 }

Definition at line 248 of file qcssparser.cpp.

Referenced by QCss::Value::toString().

◆ origins

const QCssKnownValue origins[NumKnownOrigins - 1]
static
Initial value:

Definition at line 309 of file qcssparser.cpp.

Referenced by QCss::Declaration::originValue().

◆ positions

const QCssKnownValue positions[NumKnownPositionModes - 1]
static

◆ properties

const QCssKnownValue properties[NumProperties - 1]
static

◆ pseudos

const QCssKnownValue pseudos[NumPseudos - 1]
static

Definition at line 262 of file qcssparser.cpp.

◆ repeats

const QCssKnownValue repeats[NumKnownRepeats - 1]
static
Initial value:
= {
{ "no-repeat", Repeat_None },
{ "repeat-x", Repeat_X },
{ "repeat-xy", Repeat_XY },
{ "repeat-y", Repeat_Y }
}

Definition at line 316 of file qcssparser.cpp.

Referenced by QCss::ValueExtractor::extractBackground(), parseShorthandBackgroundProperty(), and QCss::Declaration::repeatValue().

◆ styleFeatures

const QCssKnownValue styleFeatures[NumKnownStyleFeatures - 1]
static

◆ tileModes

const QCssKnownValue tileModes[NumKnownTileModes - 1]
static
Initial value:

Definition at line 323 of file qcssparser.cpp.

Referenced by QCss::Declaration::borderImageValue().

◆ values

const QCssKnownValue values[NumKnownValues - 1]
static

Definition at line 172 of file qcssparser.cpp.

Referenced by parseColorValue().