Changeset 561 for trunk/src/gui/text/qtextformat.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/qtextformat.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 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 have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 58 58 used in a QTextDocument. 59 59 60 \ingroup text60 \ingroup richtext-processing 61 61 62 62 When we specify a value for the length of an element in a text document, … … 90 90 \fn Type QTextLength::type() const 91 91 92 Returns the type of length.92 Returns the type of this length object. 93 93 94 94 \sa QTextLength::Type … … 130 130 \enum QTextLength::Type 131 131 132 \value VariableLength 133 \value FixedLength 134 \value PercentageLength 132 This enum describes the different types a length object can 133 have. 134 135 \value VariableLength The width of the object is variable 136 \value FixedLength The width of the object is fixed 137 \value PercentageLength The width of the object is in 138 percentage of the maximum width 139 140 \sa type() 135 141 */ 136 142 … … 143 149 } 144 150 151 #ifndef QT_NO_DATASTREAM 145 152 QDataStream &operator<<(QDataStream &stream, const QTextLength &length) 146 153 { … … 157 164 return stream; 158 165 } 166 #endif // QT_NO_DATASTREAM 159 167 160 168 class QTextFormatPrivate : public QSharedData … … 258 266 }; 259 267 260 static uint variantHash(const QVariant &variant) 261 { 262 switch (variant.type()) { 268 // this is only safe if sizeof(int) == sizeof(float) 269 static inline uint hash(float d) 270 { 271 return reinterpret_cast<uint&>(d); 272 } 273 274 static inline uint hash(const QColor &color) 275 { 276 return (color.isValid()) ? color.rgba() : 0x234109; 277 } 278 279 static inline uint hash(const QPen &pen) 280 { 281 return hash(pen.color()) + hash(pen.widthF()); 282 } 283 284 static inline uint hash(const QBrush &brush) 285 { 286 return hash(brush.color()) + (brush.style() << 3); 287 } 288 289 static inline uint variantHash(const QVariant &variant) 290 { 291 // simple and fast hash functions to differentiate between type and value 292 switch (variant.userType()) { // sorted by occurrence frequency 293 case QVariant::String: return qHash(variant.toString()); 294 case QVariant::Double: return hash(variant.toDouble()); 295 case QVariant::Int: return 0x811890 + variant.toInt(); 296 case QVariant::Brush: 297 return 0x01010101 + hash(qvariant_cast<QBrush>(variant)); 298 case QVariant::Bool: return 0x371818 + variant.toBool(); 299 case QVariant::Pen: return 0x02020202 + hash(qvariant_cast<QPen>(variant)); 300 case QVariant::List: 301 return 0x8377 + qvariant_cast<QVariantList>(variant).count(); 302 case QVariant::Color: return hash(qvariant_cast<QColor>(variant)); 303 case QVariant::TextLength: 304 return 0x377 + hash(qvariant_cast<QTextLength>(variant).rawValue()); 305 case QMetaType::Float: return hash(variant.toFloat()); 263 306 case QVariant::Invalid: return 0; 264 case QVariant::Bool: return variant.toBool();265 case QVariant::Int: return variant.toInt();266 case QVariant::Double: return static_cast<int>(variant.toDouble());267 case QVariant::String: return qHash(variant.toString());268 case QVariant::Color: return qHash(qvariant_cast<QColor>(variant).rgb());269 307 default: break; 270 308 } 271 309 return qHash(variant.typeName()); 310 } 311 312 static inline int getHash(const QTextFormatPrivate *d, int format) 313 { 314 return (d ? d->hash() : 0) + format; 272 315 } 273 316 … … 318 361 break; 319 362 case QTextFormat::FontPointSize: 320 f.setPointSizeF(props.at(i).value.to Double());363 f.setPointSizeF(props.at(i).value.toReal()); 321 364 break; 322 365 case QTextFormat::FontPixelSize: … … 345 388 break; 346 389 case QTextFormat::FontLetterSpacing: 347 f.setLetterSpacing(QFont::PercentageSpacing, props.at(i).value.to Double());390 f.setLetterSpacing(QFont::PercentageSpacing, props.at(i).value.toReal()); 348 391 break; 349 392 case QTextFormat::FontWordSpacing: 350 f.setWordSpacing(props.at(i).value.to Double());393 f.setWordSpacing(props.at(i).value.toReal()); 351 394 break; 352 395 case QTextFormat::FontCapitalization: … … 375 418 } 376 419 420 #ifndef QT_NO_DATASTREAM 377 421 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QTextFormat &fmt) 378 422 { … … 397 441 return stream; 398 442 } 443 #endif // QT_NO_DATASTREAM 399 444 400 445 /*! … … 405 450 QTextDocument. 406 451 407 \ingroup text452 \ingroup richtext-processing 408 453 \ingroup shared 409 454 … … 414 459 specific parts of the document. 415 460 416 A format has a \c FormatType which specifies the kinds of t hingit461 A format has a \c FormatType which specifies the kinds of text item it 417 462 can format; e.g. a block of text, a list, a table, etc. A format 418 463 also has various properties (some specific to particular format … … 438 483 lists, frames, and tables inside the document. 439 484 440 \sa { Text Processing Classes}485 \sa {Rich Text Processing} 441 486 */ 442 487 … … 444 489 \enum QTextFormat::FormatType 445 490 446 \value InvalidFormat 447 \value BlockFormat 448 \value CharFormat 449 \value ListFormat 450 \value TableFormat 451 \value FrameFormat 491 This enum describes the text item a QTextFormat object is formatting. 492 493 \value InvalidFormat An invalid format as created by the default 494 constructor 495 \value BlockFormat The object formats a text block 496 \value CharFormat The object formats a single character 497 \value ListFormat The object formats a list 498 \value TableFormat The object formats a table 499 \value FrameFormat The object formats a frame 452 500 453 501 \value UserFormat 502 503 \sa QTextCharFormat, QTextBlockFormat, QTextListFormat, 504 QTextTableFormat, type() 454 505 */ 455 506 … … 457 508 \enum QTextFormat::Property 458 509 459 \value ObjectIndex 510 This enum describes the different properties a format can have. 511 512 \value ObjectIndex The index of the formatted object. See objectIndex(). 460 513 461 514 Paragraph and character properties 462 515 463 \value CssFloat 516 \value CssFloat How a frame is located relative to the surrounding text 464 517 \value LayoutDirection The layout direction of the text in the document 465 518 (Qt::LayoutDirection). … … 479 532 \value TextIndent 480 533 \value TabPositions Specifies the tab positions. The tab positions are structs of QTextOption::Tab which are stored in 481 534 a QList (internally, in a QList<QVariant>). 482 535 \value BlockIndent 483 536 \value BlockNonBreakableLines 484 \value BlockTrailingHorizontalRulerWidth 537 \value BlockTrailingHorizontalRulerWidth The width of a horizontal ruler element. 485 538 486 539 Character properties … … 488 541 \value FontFamily 489 542 \value FontPointSize 543 \value FontPixelSize 490 544 \value FontSizeAdjustment Specifies the change in size given to the fontsize already set using 491 545 FontPointSize or FontPixelSize. 546 \value FontFixedPitch 492 547 \omitvalue FontSizeIncrement 493 548 \value FontWeight … … 496 551 \value FontOverline 497 552 \value FontStrikeOut 498 \value FontFixedPitch499 \value FontPixelSize500 553 \value FontCapitalization Specifies the capitalization type that is to be applied to the text. 501 554 \value FontLetterSpacing Changes the default spacing between individual letters in the font. The value is … … 509 562 \omitvalue FirstFontProperty 510 563 \omitvalue LastFontProperty 511 564 512 565 \value TextUnderlineColor 513 566 \value TextVerticalAlignment … … 530 583 \value FrameBorder 531 584 \value FrameBorderBrush 532 \value FrameBorderStyle 585 \value FrameBorderStyle See the \l{QTextFrameFormat::BorderStyle}{BorderStyle} enum. 533 586 \value FrameBottomMargin 534 587 \value FrameHeight … … 562 615 Selection properties 563 616 564 \value FullWidthSelection When set on the characterFormat of a selection, the whole width of the text will be shown selected 617 \value FullWidthSelection When set on the characterFormat of a selection, 618 the whole width of the text will be shown selected. 565 619 566 620 Page break properties 567 621 568 \value PageBreakPolicy 622 \value PageBreakPolicy Specifies how pages are broken. See the PageBreakFlag enum. 569 623 570 624 \value UserProperty 625 626 \sa property(), setProperty() 571 627 */ 572 628 573 629 /*! 574 630 \enum QTextFormat::ObjectTypes 631 632 This enum describes what kind of QTextObject this format is associated with. 575 633 576 634 \value NoObject … … 579 637 \value TableCellObject 580 638 \value UserObject The first object that can be used for application-specific purposes. 639 640 \sa QTextObject, QTextTable, QTextObject::format() 581 641 */ 582 642 … … 584 644 \enum QTextFormat::PageBreakFlag 585 645 \since 4.2 646 647 This enum describes how page breaking is performed when printing. It maps to the 648 corresponding css properties. 586 649 587 650 \value PageBreak_Auto The page break is determined automatically depending on the … … 589 652 \value PageBreak_AlwaysBefore The page is always broken before the paragraph/table 590 653 \value PageBreak_AlwaysAfter A new page is always started after the paragraph/table 654 655 \sa QTextBlockFormat::pageBreakPolicy(), QTextFrameFormat::pageBreakPolicy(), 656 PageBreakPolicy 591 657 */ 592 658 … … 822 888 return false; 823 889 const QVariant prop = d->property(propertyId); 824 if (prop. type() != QVariant::Bool)890 if (prop.userType() != QVariant::Bool) 825 891 return false; 826 892 return prop.toBool(); … … 838 904 return 0; 839 905 const QVariant prop = d->property(propertyId); 840 if (prop. type() != QVariant::Int)906 if (prop.userType() != QVariant::Int) 841 907 return 0; 842 908 return prop.toInt(); … … 845 911 /*! 846 912 Returns the value of the property specified by \a propertyId. If the 847 property isn't of QVariant::Double type, 0 is returned instead. 913 property isn't of QVariant::Double or QMetaType::Float type, 0 is 914 returned instead. 848 915 849 916 \sa setProperty() boolProperty() intProperty() stringProperty() colorProperty() lengthProperty() lengthVectorProperty() Property … … 854 921 return 0.; 855 922 const QVariant prop = d->property(propertyId); 856 if (prop. type() != QVariant::Double)923 if (prop.userType() != QVariant::Double && prop.userType() != QMetaType::Float) 857 924 return 0.; 858 return prop.toDouble(); // ####925 return qVariantValue<qreal>(prop); 859 926 } 860 927 … … 871 938 return QString(); 872 939 const QVariant prop = d->property(propertyId); 873 if (prop. type() != QVariant::String)940 if (prop.userType() != QVariant::String) 874 941 return QString(); 875 942 return prop.toString(); … … 889 956 return QColor(); 890 957 const QVariant prop = d->property(propertyId); 891 if (prop. type() != QVariant::Color)958 if (prop.userType() != QVariant::Color) 892 959 return QColor(); 893 960 return qvariant_cast<QColor>(prop); … … 906 973 return QPen(Qt::NoPen); 907 974 const QVariant prop = d->property(propertyId); 908 if (prop. type() != QVariant::Pen)975 if (prop.userType() != QVariant::Pen) 909 976 return QPen(Qt::NoPen); 910 977 return qvariant_cast<QPen>(prop); … … 923 990 return QBrush(Qt::NoBrush); 924 991 const QVariant prop = d->property(propertyId); 925 if (prop. type() != QVariant::Brush)992 if (prop.userType() != QVariant::Brush) 926 993 return QBrush(Qt::NoBrush); 927 994 return qvariant_cast<QBrush>(prop); … … 953 1020 return vector; 954 1021 const QVariant prop = d->property(propertyId); 955 if (prop. type() != QVariant::List)1022 if (prop.userType() != QVariant::List) 956 1023 return vector; 957 1024 … … 959 1026 for (int i=0; i<propertyList.size(); ++i) { 960 1027 QVariant var = propertyList.at(i); 961 if (var. type() == QVariant::TextLength)1028 if (var.userType() == QVariant::TextLength) 962 1029 vector.append(qvariant_cast<QTextLength>(var)); 963 1030 } … … 968 1035 /*! 969 1036 Returns the property specified by the given \a propertyId. 1037 1038 \sa Property 970 1039 */ 971 1040 QVariant QTextFormat::property(int propertyId) const … … 976 1045 /*! 977 1046 Sets the property specified by the \a propertyId to the given \a value. 1047 1048 \sa Property 978 1049 */ 979 1050 void QTextFormat::setProperty(int propertyId, const QVariant &value) … … 1003 1074 1004 1075 /*! 1005 Clears the value of the property given by \a propertyId 1006 */ 1076 Clears the value of the property given by \a propertyId 1077 1078 \sa Property 1079 */ 1007 1080 void QTextFormat::clearProperty(int propertyId) 1008 1081 { … … 1016 1089 \fn void QTextFormat::setObjectType(int type) 1017 1090 1018 Sets the text format's object \a type. See \c{ObjectTypes}. 1091 Sets the text format's object type to \a type. 1092 1093 \sa ObjectTypes, objectType() 1019 1094 */ 1020 1095 … … 1023 1098 \fn int QTextFormat::objectType() const 1024 1099 1025 Returns the text format's object type. See \c{ObjectTypes}. 1100 Returns the text format's object type. 1101 1102 \sa ObjectTypes, setObjectType() 1026 1103 */ 1027 1104 … … 1037 1114 return -1; 1038 1115 const QVariant prop = d->property(ObjectIndex); 1039 if (prop. type() != QVariant::Int) // ####1116 if (prop.userType() != QVariant::Int) // #### 1040 1117 return -1; 1041 1118 return prop.toInt(); … … 1142 1219 characters in a QTextDocument. 1143 1220 1144 \ingroup text1221 \ingroup richtext-processing 1145 1222 1146 1223 The character format of text in a document specifies the visual properties … … 1450 1527 \since 4.5 1451 1528 \fn bool QTextCharFormat::fontKerning() const 1452 Returns true if the thefont kerning is enabled.1529 Returns true if the font kerning is enabled. 1453 1530 1454 1531 \sa setFontKerning() … … 1563 1640 1564 1641 Sets the hypertext link for the text format to the given \a value. 1565 This is typically a URL like "http:// qtsoftware.com/index.html".1642 This is typically a URL like "http://example.com/index.html". 1566 1643 1567 1644 The anchor will be displayed with the \a value as its display text; … … 1613 1690 { 1614 1691 QVariant prop = property(AnchorName); 1615 if (prop. type() == QVariant::StringList)1692 if (prop.userType() == QVariant::StringList) 1616 1693 return prop.toStringList().value(0); 1617 else if (prop. type() != QVariant::String)1694 else if (prop.userType() != QVariant::String) 1618 1695 return QString(); 1619 1696 return prop.toString(); … … 1631 1708 { 1632 1709 QVariant prop = property(AnchorName); 1633 if (prop. type() == QVariant::StringList)1710 if (prop.userType() == QVariant::StringList) 1634 1711 return prop.toStringList(); 1635 else if (prop. type() != QVariant::String)1712 else if (prop.userType() != QVariant::String) 1636 1713 return QStringList(); 1637 1714 return QStringList(prop.toString()); … … 1755 1832 blocks of text in a QTextDocument. 1756 1833 1757 \ingroup text1834 \ingroup richtext-processing 1758 1835 1759 1836 A document is composed of a list of blocks, represented by QTextBlock … … 2046 2123 lists in a QTextDocument. 2047 2124 2048 \ingroup text2125 \ingroup richtext-processing 2049 2126 2050 2127 A list is composed of one or more items, represented as text blocks. … … 2075 2152 \value ListLowerAlpha lower case Latin characters in alphabetical order 2076 2153 \value ListUpperAlpha upper case Latin characters in alphabetical order 2154 \value ListLowerRoman lower case roman numerals (supports up to 4999 items only) 2155 \value ListUpperRoman upper case roman numerals (supports up to 4999 items only) 2077 2156 \omitvalue ListStyleUndefined 2078 2157 */ … … 2111 2190 \fn void QTextListFormat::setStyle(Style style) 2112 2191 2113 Sets the list format's \a style. See \c{Style} for the available styles.2114 2115 \sa style() 2192 Sets the list format's \a style. 2193 2194 \sa style() Style 2116 2195 */ 2117 2196 … … 2119 2198 \fn Style QTextListFormat::style() const 2120 2199 2121 Returns the list format's style. See \c{Style}.2122 2123 \sa setStyle() 2200 Returns the list format's style. 2201 2202 \sa setStyle() Style 2124 2203 */ 2125 2204 … … 2154 2233 frames in a QTextDocument. 2155 2234 2156 \ingroup text2235 \ingroup richtext-processing 2157 2236 2158 2237 A text frame groups together one or more blocks of text, providing a layer … … 2183 2262 \enum QTextFrameFormat::Position 2184 2263 2264 This enum describes how a frame is located relative to the surrounding text. 2265 2185 2266 \value InFlow 2186 2267 \value FloatLeft 2187 2268 \value FloatRight 2188 2269 2270 \sa position() CssFloat 2189 2271 */ 2190 2272 … … 2192 2274 \enum QTextFrameFormat::BorderStyle 2193 2275 \since 4.3 2276 2277 This enum describes different border styles for the text frame. 2194 2278 2195 2279 \value BorderStyle_None … … 2205 2289 \value BorderStyle_Outset 2206 2290 2291 \sa borderStyle() FrameBorderStyle 2207 2292 */ 2208 2293 … … 2474 2559 tables in a QTextDocument. 2475 2560 2476 \ingroup text2561 \ingroup richtext-processing 2477 2562 2478 2563 A table is a group of cells ordered into rows and columns. Each table … … 2680 2765 images in a QTextDocument. 2681 2766 2682 \ingroup text2767 \ingroup richtext-processing 2683 2768 2684 2769 Inline images are represented by an object replacement character … … 2949 3034 table cells in a QTextDocument. 2950 3035 2951 \ingroup text3036 \ingroup richtext-processing 2952 3037 2953 3038 The table cell format of a table cell in a document specifies the visual … … 2983 3068 int QTextFormatCollection::indexForFormat(const QTextFormat &format) 2984 3069 { 2985 uint hash = format.d ? format.d->hash() : 0;2986 if (hashes.contains(hash)) {2987 for (int i = 0; i < formats.size(); ++i) {2988 if (formats.at(i) == format)2989 return i;3070 uint hash = getHash(format.d, format.format_type); 3071 QMultiHash<uint, int>::const_iterator i = hashes.find(hash); 3072 while (i != hashes.end() && i.key() == hash) { 3073 if (formats.value(i.value()) == format) { 3074 return i.value(); 2990 3075 } 3076 ++i; 2991 3077 } 3078 2992 3079 int idx = formats.size(); 2993 3080 formats.append(format); 2994 3081 2995 QTextFormat &f = formats.last(); 2996 if (!f.d) 2997 f.d = new QTextFormatPrivate; 2998 f.d->resolveFont(defaultFnt); 2999 3000 hashes.insert(hash); 3082 QT_TRY{ 3083 QTextFormat &f = formats.last(); 3084 if (!f.d) 3085 f.d = new QTextFormatPrivate; 3086 f.d->resolveFont(defaultFnt); 3087 3088 hashes.insert(hash, idx); 3089 3090 } QT_CATCH(...) { 3091 formats.pop_back(); 3092 QT_RETHROW; 3093 } 3001 3094 return idx; 3002 3095 } … … 3004 3097 bool QTextFormatCollection::hasFormatCached(const QTextFormat &format) const 3005 3098 { 3006 uint hash = format.d ? format.d->hash() : 0; 3007 if (hashes.contains(hash)) { 3008 for (int i = 0; i < formats.size(); ++i) 3009 if (formats.at(i) == format) 3010 return true; 3099 uint hash = getHash(format.d, format.format_type); 3100 QMultiHash<uint, int>::const_iterator i = hashes.find(hash); 3101 while (i != hashes.end() && i.key() == hash) { 3102 if (formats.value(i.value()) == format) { 3103 return true; 3104 } 3105 ++i; 3011 3106 } 3012 3107 return false;
Note:
See TracChangeset
for help on using the changeset viewer.