Changeset 561 for trunk/src/gui/text/qcssparser.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/text/qcssparser.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information ([email protected]) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation ([email protected]) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you 37 ** @nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 49 49 #include <qbrush.h> 50 50 #include <qimagereader.h> 51 51 52 52 53 #ifndef QT_NO_CSSPARSER … … 57 58 58 59 using namespace QCss; 59 60 const char *Scanner::tokenName(QCss::TokenType t)61 {62 switch (t) {63 case NONE: return "NONE";64 case S: return "S";65 case CDO: return "CDO";66 case CDC: return "CDC";67 case INCLUDES: return "INCLUDES";68 case DASHMATCH: return "DASHMATCH";69 case LBRACE: return "LBRACE";70 case PLUS: return "PLUS";71 case GREATER: return "GREATER";72 case COMMA: return "COMMA";73 case STRING: return "STRING";74 case INVALID: return "INVALID";75 case IDENT: return "IDENT";76 case HASH: return "HASH";77 case ATKEYWORD_SYM: return "ATKEYWORD_SYM";78 case EXCLAMATION_SYM: return "EXCLAMATION_SYM";79 case LENGTH: return "LENGTH";80 case PERCENTAGE: return "PERCENTAGE";81 case NUMBER: return "NUMBER";82 case FUNCTION: return "FUNCTION";83 case COLON: return "COLON";84 case SEMICOLON: return "SEMICOLON";85 case RBRACE: return "RBRACE";86 case SLASH: return "SLASH";87 case MINUS: return "MINUS";88 case DOT: return "DOT";89 case STAR: return "STAR";90 case LBRACKET: return "LBRACKET";91 case RBRACKET: return "RBRACKET";92 case EQUAL: return "EQUAL";93 case LPAREN: return "LPAREN";94 case RPAREN: return "RPAREN";95 case OR: return "OR";96 }97 return "";98 }99 60 100 61 struct QCssKnownValue … … 240 201 { "link-visited", Value_LinkVisited }, 241 202 { "lower-alpha", Value_LowerAlpha }, 203 242 204 { "lowercase", Value_Lowercase }, 243 205 { "medium", Value_Medium }, … … 271 233 { "underline", Value_Underline }, 272 234 { "upper-alpha", Value_UpperAlpha }, 235 273 236 { "uppercase", Value_Uppercase }, 274 237 { "wave", Value_Wave }, … … 279 242 }; 280 243 244 245 246 247 248 249 281 250 QString Value::toString() const 282 251 { 283 static int indexOfId[NumKnownValues - 1];284 static bool hasCachedIndexes = false;285 286 252 if (type == KnownIdentifier) { 287 if (!hasCachedIndexes) {288 for (int i = 0; i < NumKnownValues - 1; ++i)289 indexOfId[values[i].id] = i;290 291 hasCachedIndexes = true;292 }293 294 253 return QLatin1String(values[indexOfId[variant.toInt()]].name); 295 254 } else { … … 383 342 }; 384 343 385 staticbool operator<(const QString &name, const QCssKnownValue &prop)344 bool operator<(const QString &name, const QCssKnownValue &prop) 386 345 { 387 346 return QString::compare(name, QLatin1String(prop.name), Qt::CaseInsensitive) < 0; 388 347 } 389 348 390 staticbool operator<(const QCssKnownValue &prop, const QString &name)349 bool operator<(const QCssKnownValue &prop, const QString &name) 391 350 { 392 351 return QString::compare(QLatin1String(prop.name), name, Qt::CaseInsensitive) < 0; … … 425 384 s.chop(2); 426 385 427 bool ok; 428 data.number = s.toDouble(&ok); 429 if (!ok) 430 data.number = 0; 386 data.number = s.toDouble(); 431 387 return data; 432 388 } … … 754 710 for (int i = 0; i < qMin(colorDigits.count(), 7); i += 2) { 755 711 if (colorDigits.at(i).type == Value::Percentage) { 756 colorDigits[i].variant = colorDigits.at(i).variant.to Double() * 255. / 100.;712 colorDigits[i].variant = colorDigits.at(i).variant.to; 757 713 colorDigits[i].type = Value::Number; 758 714 } else if (colorDigits.at(i).type != Value::Number) { … … 831 787 if(cd.type == ColorData::Role) 832 788 dependsOnThePalette = true; 833 stops.append(QGradientStop(stop.variant.to Double(), colorFromData(cd, pal)));789 stops.append(QGradientStop(stop.variant.to(), colorFromData(cd, pal))); 834 790 } else { 835 791 parser.next(); 836 792 Value value; 837 parser.parseTerm(&value);793 parser.parseTerm(&value); 838 794 if (attr.compare(QLatin1String("spread"), Qt::CaseInsensitive) == 0) { 839 795 spread = spreads.indexOf(value.variant.toString()); 840 796 } else { 841 vars[attr] = value.variant.to String().toDouble();797 vars[attr] = value.variant.to(); 842 798 } 843 799 } 844 800 parser.skipSpace(); 845 parser.test(COMMA);801 parser.test(COMMA); 846 802 } 847 803 … … 1122 1078 s.chop(2); 1123 1079 value.variant = s; 1124 if (value.variant.convert( QVariant::Double)) {1125 font->setPointSizeF(value.variant.to Double());1080 if (value.variant.convert()) { 1081 font->setPointSizeF(value.variant.to()); 1126 1082 valid = true; 1127 1083 } … … 1166 1122 } 1167 1123 1168 static bool setFontFamilyFromValues(const QVector<Value> &values, QFont *font) 1124 /** \internal 1125 * parse the font family from the values (starting from index \a start) 1126 * and set it the \a font 1127 * \returns true if a family was extracted. 1128 */ 1129 static bool setFontFamilyFromValues(const QVector<Value> &values, QFont *font, int start = 0) 1169 1130 { 1170 1131 QString family; 1171 for (int i = 0; i < values.count(); ++i) { 1132 bool shouldAddSpace = false; 1133 for (int i = start; i < values.count(); ++i) { 1172 1134 const Value &v = values.at(i); 1173 if (v.type == Value::TermOperatorComma) 1174 break; 1135 if (v.type == Value::TermOperatorComma) { 1136 family += QLatin1Char(','); 1137 shouldAddSpace = false; 1138 continue; 1139 } 1175 1140 const QString str = v.variant.toString(); 1176 1141 if (str.isEmpty()) 1177 1142 break; 1143 1144 1178 1145 family += str; 1179 family += QLatin1Char(' '); 1180 } 1181 family = family.simplified(); 1146 shouldAddSpace = true; 1147 } 1182 1148 if (family.isEmpty()) 1183 1149 return false; … … 1209 1175 font->setStyle(QFont::StyleNormal); 1210 1176 font->setWeight(QFont::Normal); 1211 *fontSizeAdjustment = 0;1177 *fontSizeAdjustment = ; 1212 1178 1213 1179 int i = 0; … … 1226 1192 1227 1193 if (i < values.count()) { 1228 QString fam = values.at(i).variant.toString(); 1229 if (!fam.isEmpty()) 1230 font->setFamily(fam); 1194 setFontFamilyFromValues(values, font, i); 1231 1195 } 1232 1196 } … … 1508 1472 if (func.count() != 2 || func.at(0).compare(QLatin1String("rect")) != 0) 1509 1473 return QRect(); 1510 QStringList args = func[1].split(QLatin1 String(" "), QString::SkipEmptyParts);1474 QStringList args = func[1].split(QLatin1), QString::SkipEmptyParts); 1511 1475 if (args.count() != 4) 1512 1476 return QRect(); … … 2153 2117 QFile file(css); 2154 2118 if (file.open(QFile::ReadOnly)) { 2155 sourcePath = QFileInfo(styleSheet).absolutePath() + QLatin1 String("/");2119 sourcePath = QFileInfo(styleSheet).absolutePath() + QLatin1); 2156 2120 QTextStream stream(&file); 2157 2121 styleSheet = stream.readAll(); … … 2166 2130 hasEscapeSequences = false; 2167 2131 symbols.resize(0); 2132 2168 2133 Scanner::scan(Scanner::preprocess(styleSheet, &hasEscapeSequences), &symbols); 2169 2134 index = 0; … … 2499 2464 bool Parser::parsePseudo(Pseudo *pseudo) 2500 2465 { 2501 test(COLON);2466 test(COLON); 2502 2467 pseudo->negated = test(EXCLAMATION_SYM); 2503 2468 if (test(IDENT)) {
Note:
See TracChangeset
for help on using the changeset viewer.