qtextformat.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/text/qtextformat.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4QTextLength::operator QVariant() const-
5{-
6 return QVariant(QVariant::TextLength, this);-
7}-
8-
9-
10QDataStream &operator<<(QDataStream &stream, const QTextLength &length)-
11{-
12 return stream << qint32(length.lengthType) << double(length.fixedValueOrPercentage);-
13}-
14-
15QDataStream &operator>>(QDataStream &stream, QTextLength &length)-
16{-
17 qint32 type;-
18 double fixedValueOrPercentage;-
19 stream >> type >> fixedValueOrPercentage;-
20 length.fixedValueOrPercentage = fixedValueOrPercentage;-
21 length.lengthType = QTextLength::Type(type);-
22 return stream;-
23}-
24-
25-
26class QTextFormatPrivate : public QSharedData-
27{-
28public:-
29 QTextFormatPrivate() : hashDirty(true), fontDirty(true), hashValue(0) {}-
30-
31 struct Property-
32 {-
33 inline Property(qint32 k, const QVariant &v) : key(k), value(v) {}-
34 inline Property() {}-
35-
36 qint32 key;-
37 QVariant value;-
38-
39 inline bool operator==(const Property &other) const-
40 { return key == other.key && value == other.value; }-
41 inline bool operator!=(const Property &other) const-
42 { return key != other.key || value != other.value; }-
43 };-
44-
45 inline uint hash() const-
46 {-
47 if (!hashDirty)-
48 return hashValue;-
49 return recalcHash();-
50 }-
51-
52 inline bool operator==(const QTextFormatPrivate &rhs) const {-
53 if (hash() != rhs.hash())-
54 return false;-
55-
56 return props == rhs.props;-
57 }-
58-
59 inline void insertProperty(qint32 key, const QVariant &value)-
60 {-
61 hashDirty = true;-
62 if (key >= QTextFormat::FirstFontProperty && key <= QTextFormat::LastFontProperty)-
63 fontDirty = true;-
64 for (int i = 0; i < props.count(); ++i)-
65 if (props.at(i).key == key) {-
66 props[i].value = value;-
67 return;-
68 }-
69 props.append(Property(key, value));-
70 }-
71-
72 inline void clearProperty(qint32 key)-
73 {-
74 for (int i = 0; i < props.count(); ++i)-
75 if (props.at(i).key == key) {-
76 hashDirty = true;-
77 if (key >= QTextFormat::FirstFontProperty && key <= QTextFormat::LastFontProperty)-
78 fontDirty = true;-
79 props.remove(i);-
80 return;-
81 }-
82 }-
83-
84 inline int propertyIndex(qint32 key) const-
85 {-
86 for (int i = 0; i < props.count(); ++i)-
87 if (props.at(i).key == key)-
88 return i;-
89 return -1;-
90 }-
91-
92 inline QVariant property(qint32 key) const-
93 {-
94 const int idx = propertyIndex(key);-
95 if (idx < 0)-
96 return QVariant();-
97 return props.at(idx).value;-
98 }-
99-
100 inline bool hasProperty(qint32 key) const-
101 { return propertyIndex(key) != -1; }-
102-
103 void resolveFont(const QFont &defaultFont);-
104-
105 inline const QFont &font() const {-
106 if (fontDirty)-
107 recalcFont();-
108 return fnt;-
109 }-
110-
111 QVector<Property> props;-
112private:-
113-
114 uint recalcHash() const;-
115 void recalcFont() const;-
116-
117 mutable bool hashDirty;-
118 mutable bool fontDirty;-
119 mutable uint hashValue;-
120 mutable QFont fnt;-
121-
122 friend QDataStream &operator<<(QDataStream &, const QTextFormat &);-
123 friend QDataStream &operator>>(QDataStream &, QTextFormat &);-
124};-
125template<> class QTypeInfo<QTextFormatPrivate::Property > { public: enum { isComplex = (((Q_MOVABLE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_MOVABLE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_MOVABLE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(QTextFormatPrivate::Property)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< QTextFormatPrivate::Property >::value, isDummy = (((Q_MOVABLE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(QTextFormatPrivate::Property) }; static inline const char *name() { return "QTextFormatPrivate::Property"; } };-
126-
127static inline uint hash(const QColor &color)-
128{-
129 return (color.isValid()) ? color.rgba() : 0x234109;-
130}-
131-
132static inline uint hash(const QPen &pen)-
133{-
134 return hash(pen.color()) + qHash(pen.widthF());-
135}-
136-
137static inline uint hash(const QBrush &brush)-
138{-
139 return hash(brush.color()) + (brush.style() << 3);-
140}-
141-
142static inline uint variantHash(const QVariant &variant)-
143{-
144-
145 switch (variant.userType()) {-
146 case QVariant::String: return qHash(variant.toString());-
147 case QVariant::Double: return qHash(variant.toDouble());-
148 case QVariant::Int: return 0x811890 + variant.toInt();-
149 case QVariant::Brush:-
150 return 0x01010101 + hash(qvariant_cast<QBrush>(variant));-
151 case QVariant::Bool: return 0x371818 + variant.toBool();-
152 case QVariant::Pen: return 0x02020202 + hash(qvariant_cast<QPen>(variant));-
153 case QVariant::List:-
154 return 0x8377 + qvariant_cast<QVariantList>(variant).count();-
155 case QVariant::Color: return hash(qvariant_cast<QColor>(variant));-
156 case QVariant::TextLength:-
157 return 0x377 + hash(qvariant_cast<QTextLength>(variant).rawValue());-
158 case QMetaType::Float: return qHash(variant.toFloat());-
159 case QVariant::Invalid: return 0;-
160 default: break;-
161 }-
162 return qHash(variant.typeName());-
163}-
164-
165static inline int getHash(const QTextFormatPrivate *d, int format)-
166{-
167 return (d ? d->hash() : 0) + format;-
168}-
169-
170uint QTextFormatPrivate::recalcHash() const-
171{-
172 hashValue = 0;-
173 for (QVector<Property>::ConstIterator it = props.constBegin(); it != props.constEnd(); ++it)-
174 hashValue += (static_cast<quint32>(it->key) << 16) + variantHash(it->value);-
175-
176 hashDirty = false;-
177-
178 return hashValue;-
179}-
180-
181void QTextFormatPrivate::resolveFont(const QFont &defaultFont)-
182{-
183 recalcFont();-
184 const uint oldMask = fnt.resolve();-
185 fnt = fnt.resolve(defaultFont);-
186-
187 if (hasProperty(QTextFormat::FontSizeAdjustment)) {-
188 const qreal scaleFactors[7] = {qreal(0.7), qreal(0.8), qreal(1.0), qreal(1.2), qreal(1.5), qreal(2), qreal(2.4)};-
189-
190 const int htmlFontSize = qBound(0, property(QTextFormat::FontSizeAdjustment).toInt() + 3 - 1, 6);-
191-
192-
193 if (defaultFont.pointSize() <= 0) {-
194 qreal pixelSize = scaleFactors[htmlFontSize] * defaultFont.pixelSize();-
195 fnt.setPixelSize(qRound(pixelSize));-
196 } else {-
197 qreal pointSize = scaleFactors[htmlFontSize] * defaultFont.pointSizeF();-
198 fnt.setPointSizeF(pointSize);-
199 }-
200 }-
201-
202 fnt.resolve(oldMask);-
203}-
204-
205void QTextFormatPrivate::recalcFont() const-
206{-
207-
208 QFont f;-
209-
210 bool hasSpacingInformation = false;-
211 QFont::SpacingType spacingType = QFont::PercentageSpacing;-
212 qreal letterSpacing = 0.0;-
213-
214 for (int i = 0; i < props.count(); ++i) {-
215 switch (props.at(i).key) {-
216 case QTextFormat::FontFamily:-
217 f.setFamily(props.at(i).value.toString());-
218 break;-
219 case QTextFormat::FontPointSize:-
220 f.setPointSizeF(props.at(i).value.toReal());-
221 break;-
222 case QTextFormat::FontPixelSize:-
223 f.setPixelSize(props.at(i).value.toInt());-
224 break;-
225 case QTextFormat::FontWeight: {-
226 const QVariant weightValue = props.at(i).value;-
227 int weight = weightValue.toInt();-
228 if (weight >= 0 && weightValue.isValid())-
229 f.setWeight(weight);-
230 break; }-
231 case QTextFormat::FontItalic:-
232 f.setItalic(props.at(i).value.toBool());-
233 break;-
234 case QTextFormat::FontUnderline:-
235 if (! hasProperty(QTextFormat::TextUnderlineStyle))-
236 f.setUnderline(props.at(i).value.toBool());-
237 break;-
238 case QTextFormat::TextUnderlineStyle:-
239 f.setUnderline(static_cast<QTextCharFormat::UnderlineStyle>(props.at(i).value.toInt()) == QTextCharFormat::SingleUnderline);-
240 break;-
241 case QTextFormat::FontOverline:-
242 f.setOverline(props.at(i).value.toBool());-
243 break;-
244 case QTextFormat::FontStrikeOut:-
245 f.setStrikeOut(props.at(i).value.toBool());-
246 break;-
247 case QTextFormat::FontLetterSpacingType:-
248 spacingType = static_cast<QFont::SpacingType>(props.at(i).value.toInt());-
249 hasSpacingInformation = true;-
250 break;-
251 case QTextFormat::FontLetterSpacing:-
252 letterSpacing = props.at(i).value.toReal();-
253 hasSpacingInformation = true;-
254 break;-
255 case QTextFormat::FontWordSpacing:-
256 f.setWordSpacing(props.at(i).value.toReal());-
257 break;-
258 case QTextFormat::FontCapitalization:-
259 f.setCapitalization(static_cast<QFont::Capitalization> (props.at(i).value.toInt()));-
260 break;-
261 case QTextFormat::FontFixedPitch: {-
262 const bool value = props.at(i).value.toBool();-
263 if (f.fixedPitch() != value)-
264 f.setFixedPitch(value);-
265 break; }-
266 case QTextFormat::FontStretch:-
267 f.setStretch(props.at(i).value.toInt());-
268 break;-
269 case QTextFormat::FontStyleHint:-
270 f.setStyleHint(static_cast<QFont::StyleHint>(props.at(i).value.toInt()), f.styleStrategy());-
271 break;-
272 case QTextFormat::FontHintingPreference:-
273 f.setHintingPreference(static_cast<QFont::HintingPreference>(props.at(i).value.toInt()));-
274 break;-
275 case QTextFormat::FontStyleStrategy:-
276 f.setStyleStrategy(static_cast<QFont::StyleStrategy>(props.at(i).value.toInt()));-
277 break;-
278 case QTextFormat::FontKerning:-
279 f.setKerning(props.at(i).value.toBool());-
280 break;-
281 default:-
282 break;-
283 }-
284 }-
285-
286 if (hasSpacingInformation)-
287 f.setLetterSpacing(spacingType, letterSpacing);-
288-
289 fnt = f;-
290 fontDirty = false;-
291}-
292-
293-
294__attribute__((visibility("default"))) QDataStream &operator<<(QDataStream &stream, const QTextFormat &fmt)-
295{-
296 stream << fmt.format_type << fmt.properties();-
297 return stream;-
298}-
299-
300__attribute__((visibility("default"))) QDataStream &operator>>(QDataStream &stream, QTextFormat &fmt)-
301{-
302 QMap<qint32, QVariant> properties;-
303 stream >> fmt.format_type >> properties;-
304-
305-
306-
307 if(!fmt.d)-
308 fmt.d = new QTextFormatPrivate();-
309-
310 for (QMap<qint32, QVariant>::ConstIterator it = properties.constBegin();-
311 it != properties.constEnd(); ++it)-
312 fmt.d->insertProperty(it.key(), it.value());-
313-
314 return stream;-
315}-
316QTextFormat::QTextFormat()-
317 : format_type(InvalidFormat)-
318{-
319}-
320-
321-
322-
323-
324-
325-
326QTextFormat::QTextFormat(int type)-
327 : format_type(type)-
328{-
329}-
330QTextFormat::QTextFormat(const QTextFormat &rhs)-
331 : d(rhs.d), format_type(rhs.format_type)-
332{-
333}-
334-
335-
336-
337-
338-
339-
340-
341QTextFormat &QTextFormat::operator=(const QTextFormat &rhs)-
342{-
343 d = rhs.d;-
344 format_type = rhs.format_type;-
345 return *this;-
346}-
347QTextFormat::~QTextFormat()-
348{-
349}-
350-
351-
352-
353-
354-
355QTextFormat::operator QVariant() const-
356{-
357 return QVariant(QVariant::TextFormat, this);-
358}-
359-
360-
361-
362-
363-
364void QTextFormat::merge(const QTextFormat &other)-
365{-
366 if (format_type != other.format_type)-
367 return;-
368-
369 if (!d) {-
370 d = other.d;-
371 return;-
372 }-
373-
374 if (!other.d)-
375 return;-
376-
377 QTextFormatPrivate *d = this->d;-
378-
379 const QVector<QTextFormatPrivate::Property> &otherProps = other.d->props;-
380 d->props.reserve(d->props.size() + otherProps.size());-
381 for (int i = 0; i < otherProps.count(); ++i) {-
382 const QTextFormatPrivate::Property &p = otherProps.at(i);-
383 d->insertProperty(p.key, p.value);-
384 }-
385}-
386-
387-
388-
389-
390-
391-
392int QTextFormat::type() const-
393{-
394 return format_type;-
395}-
396-
397-
398-
399-
400QTextBlockFormat QTextFormat::toBlockFormat() const-
401{-
402 return QTextBlockFormat(*this);-
403}-
404-
405-
406-
407-
408QTextCharFormat QTextFormat::toCharFormat() const-
409{-
410 return QTextCharFormat(*this);-
411}-
412-
413-
414-
415-
416QTextListFormat QTextFormat::toListFormat() const-
417{-
418 return QTextListFormat(*this);-
419}-
420-
421-
422-
423-
424QTextTableFormat QTextFormat::toTableFormat() const-
425{-
426 return QTextTableFormat(*this);-
427}-
428-
429-
430-
431-
432QTextFrameFormat QTextFormat::toFrameFormat() const-
433{-
434 return QTextFrameFormat(*this);-
435}-
436-
437-
438-
439-
440QTextImageFormat QTextFormat::toImageFormat() const-
441{-
442 return QTextImageFormat(*this);-
443}-
444-
445-
446-
447-
448-
449-
450QTextTableCellFormat QTextFormat::toTableCellFormat() const-
451{-
452 return QTextTableCellFormat(*this);-
453}-
454bool QTextFormat::boolProperty(int propertyId) const-
455{-
456 if (!d)-
457 return false;-
458 const QVariant prop = d->property(propertyId);-
459 if (prop.userType() != QVariant::Bool)-
460 return false;-
461 return prop.toBool();-
462}-
463int QTextFormat::intProperty(int propertyId) const-
464{-
465-
466 int def = (propertyId == QTextFormat::LayoutDirection) ? int(Qt::LayoutDirectionAuto) : 0;-
467-
468 if (!d)-
469 return def;-
470 const QVariant prop = d->property(propertyId);-
471 if (prop.userType() != QVariant::Int)-
472 return def;-
473 return prop.toInt();-
474}-
475qreal QTextFormat::doubleProperty(int propertyId) const-
476{-
477 if (!d)-
478 return 0.;-
479 const QVariant prop = d->property(propertyId);-
480 if (prop.userType() != QVariant::Double && prop.userType() != QMetaType::Float)-
481 return 0.;-
482 return qvariant_cast<qreal>(prop);-
483}-
484QString QTextFormat::stringProperty(int propertyId) const-
485{-
486 if (!d)-
487 return QString();-
488 const QVariant prop = d->property(propertyId);-
489 if (prop.userType() != QVariant::String)-
490 return QString();-
491 return prop.toString();-
492}-
493QColor QTextFormat::colorProperty(int propertyId) const-
494{-
495 if (!d)-
496 return QColor();-
497 const QVariant prop = d->property(propertyId);-
498 if (prop.userType() != QVariant::Color)-
499 return QColor();-
500 return qvariant_cast<QColor>(prop);-
501}-
502QPen QTextFormat::penProperty(int propertyId) const-
503{-
504 if (!d)-
505 return QPen(Qt::NoPen);-
506 const QVariant prop = d->property(propertyId);-
507 if (prop.userType() != QVariant::Pen)-
508 return QPen(Qt::NoPen);-
509 return qvariant_cast<QPen>(prop);-
510}-
511QBrush QTextFormat::brushProperty(int propertyId) const-
512{-
513 if (!d)-
514 return QBrush(Qt::NoBrush);-
515 const QVariant prop = d->property(propertyId);-
516 if (prop.userType() != QVariant::Brush)-
517 return QBrush(Qt::NoBrush);-
518 return qvariant_cast<QBrush>(prop);-
519}-
520-
521-
522-
523-
524-
525-
526-
527QTextLength QTextFormat::lengthProperty(int propertyId) const-
528{-
529 if (!d)-
530 return QTextLength();-
531 return qvariant_cast<QTextLength>(d->property(propertyId));-
532}-
533QVector<QTextLength> QTextFormat::lengthVectorProperty(int propertyId) const-
534{-
535 QVector<QTextLength> vector;-
536 if (!d)-
537 return vector;-
538 const QVariant prop = d->property(propertyId);-
539 if (prop.userType() != QVariant::List)-
540 return vector;-
541-
542 QList<QVariant> propertyList = prop.toList();-
543 for (int i=0; i<propertyList.size(); ++i) {-
544 QVariant var = propertyList.at(i);-
545 if (var.userType() == QVariant::TextLength)-
546 vector.append(qvariant_cast<QTextLength>(var));-
547 }-
548-
549 return vector;-
550}-
551-
552-
553-
554-
555-
556-
557QVariant QTextFormat::property(int propertyId) const-
558{-
559 return d ? d->property(propertyId) : QVariant();-
560}-
561-
562-
563-
564-
565-
566-
567void QTextFormat::setProperty(int propertyId, const QVariant &value)-
568{-
569 if (!d)-
570 d = new QTextFormatPrivate;-
571 if (!value.isValid())-
572 clearProperty(propertyId);-
573 else-
574 d->insertProperty(propertyId, value);-
575}-
576-
577-
578-
579-
580-
581-
582void QTextFormat::setProperty(int propertyId, const QVector<QTextLength> &value)-
583{-
584 if (!d)-
585 d = new QTextFormatPrivate;-
586 QVariantList list;-
587 const int numValues = value.size();-
588 list.reserve(numValues);-
589 for (int i = 0; i < numValues; ++i)-
590 list << value.at(i);-
591 d->insertProperty(propertyId, list);-
592}-
593-
594-
595-
596-
597-
598-
599void QTextFormat::clearProperty(int propertyId)-
600{-
601 if (!d)-
602 return;-
603 d->clearProperty(propertyId);-
604}-
605int QTextFormat::objectIndex() const-
606{-
607 if (!d)-
608 return -1;-
609 const QVariant prop = d->property(ObjectIndex);-
610 if (prop.userType() != QVariant::Int)-
611 return -1;-
612 return prop.toInt();-
613}-
614void QTextFormat::setObjectIndex(int o)-
615{-
616 if (o == -1) {-
617 if (d)-
618 d->clearProperty(ObjectIndex);-
619 } else {-
620 if (!d)-
621 d = new QTextFormatPrivate;-
622-
623 d->insertProperty(ObjectIndex, o);-
624 }-
625}-
626-
627-
628-
629-
630-
631-
632-
633bool QTextFormat::hasProperty(int propertyId) const-
634{-
635 return d ? d->hasProperty(propertyId) : false;-
636}-
637QMap<int, QVariant> QTextFormat::properties() const-
638{-
639 QMap<int, QVariant> map;-
640 if (d) {-
641 for (int i = 0; i < d->props.count(); ++i)-
642 map.insert(d->props.at(i).key, d->props.at(i).value);-
643 }-
644 return map;-
645}-
646-
647-
648-
649-
650-
651int QTextFormat::propertyCount() const-
652{-
653 return d ? d->props.count() : 0;-
654}-
655bool QTextFormat::operator==(const QTextFormat &rhs) const-
656{-
657 if (format_type != rhs.format_type)-
658 return false;-
659-
660 if (d == rhs.d)-
661 return true;-
662-
663 if (d && d->props.isEmpty() && !rhs.d)-
664 return true;-
665-
666 if (!d && rhs.d && rhs.d->props.isEmpty())-
667 return true;-
668-
669 if (!d || !rhs.d)-
670 return false;-
671-
672 return *d == *rhs.d;-
673}-
674QTextCharFormat::QTextCharFormat() : QTextFormat(CharFormat) {}-
675QTextCharFormat::QTextCharFormat(const QTextFormat &fmt)-
676 : QTextFormat(fmt)-
677{-
678}-
679bool QTextCharFormat::fontUnderline() const-
680{-
681 if (hasProperty(TextUnderlineStyle))-
682 return underlineStyle() == SingleUnderline;-
683 return boolProperty(FontUnderline);-
684}-
685void QTextCharFormat::setUnderlineStyle(UnderlineStyle style)-
686{-
687 setProperty(TextUnderlineStyle, style);-
688-
689 setProperty(FontUnderline, style == SingleUnderline);-
690}-
691QString QTextCharFormat::anchorName() const-
692{-
693 QVariant prop = property(AnchorName);-
694 if (prop.userType() == QVariant::StringList)-
695 return prop.toStringList().value(0);-
696 else if (prop.userType() != QVariant::String)-
697 return QString();-
698 return prop.toString();-
699}-
700QStringList QTextCharFormat::anchorNames() const-
701{-
702 QVariant prop = property(AnchorName);-
703 if (prop.userType() == QVariant::StringList)-
704 return prop.toStringList();-
705 else if (prop.userType() != QVariant::String)-
706 return QStringList();-
707 return QStringList(prop.toString());-
708}-
709void QTextCharFormat::setFont(const QFont &font)-
710{-
711 setFont(font, FontPropertiesAll);-
712}-
713void QTextCharFormat::setFont(const QFont &font, FontPropertiesInheritanceBehavior behavior)-
714{-
715 const uint mask = behavior == FontPropertiesAll ? uint(QFont::AllPropertiesResolved)-
716 : font.resolve();-
717-
718 if (mask & QFont::FamilyResolved)-
719 setFontFamily(font.family());-
720 if (mask & QFont::SizeResolved) {-
721 const qreal pointSize = font.pointSizeF();-
722 if (pointSize > 0) {-
723 setFontPointSize(pointSize);-
724 } else {-
725 const int pixelSize = font.pixelSize();-
726 if (pixelSize > 0)-
727 setProperty(QTextFormat::FontPixelSize, pixelSize);-
728 }-
729 }-
730-
731 if (mask & QFont::WeightResolved)-
732 setFontWeight(font.weight());-
733 if (mask & QFont::StyleResolved)-
734 setFontItalic(font.style() != QFont::StyleNormal);-
735 if (mask & QFont::UnderlineResolved)-
736 setUnderlineStyle(font.underline() ? SingleUnderline : NoUnderline);-
737 if (mask & QFont::OverlineResolved)-
738 setFontOverline(font.overline());-
739 if (mask & QFont::StrikeOutResolved)-
740 setFontStrikeOut(font.strikeOut());-
741 if (mask & QFont::FixedPitchResolved)-
742 setFontFixedPitch(font.fixedPitch());-
743 if (mask & QFont::CapitalizationResolved)-
744 setFontCapitalization(font.capitalization());-
745 if (mask & QFont::WordSpacingResolved)-
746 setFontWordSpacing(font.wordSpacing());-
747 if (mask & QFont::LetterSpacingResolved) {-
748 setFontLetterSpacingType(font.letterSpacingType());-
749 setFontLetterSpacing(font.letterSpacing());-
750 }-
751 if (mask & QFont::StretchResolved)-
752 setFontStretch(font.stretch());-
753 if (mask & QFont::StyleHintResolved)-
754 setFontStyleHint(font.styleHint());-
755 if (mask & QFont::StyleStrategyResolved)-
756 setFontStyleStrategy(font.styleStrategy());-
757 if (mask & QFont::HintingPreferenceResolved)-
758 setFontHintingPreference(font.hintingPreference());-
759 if (mask & QFont::KerningResolved)-
760 setFontKerning(font.kerning());-
761}-
762-
763-
764-
765-
766QFont QTextCharFormat::font() const-
767{-
768 return d ? d->font() : QFont();-
769}-
770QTextBlockFormat::QTextBlockFormat() : QTextFormat(BlockFormat) {}-
771QTextBlockFormat::QTextBlockFormat(const QTextFormat &fmt)-
772 : QTextFormat(fmt)-
773{-
774}-
775void QTextBlockFormat::setTabPositions(const QList<QTextOption::Tab> &tabs)-
776{-
777 QList<QVariant> list;-
778 list.reserve(tabs.count());-
779 QList<QTextOption::Tab>::ConstIterator iter = tabs.constBegin();-
780 while (iter != tabs.constEnd()) {-
781 QVariant v;-
782 v.setValue<QTextOption::Tab>(*iter);-
783 list.append(v);-
784 ++iter;-
785 }-
786 setProperty(TabPositions, list);-
787}-
788-
789-
790-
791-
792-
793-
794-
795QList<QTextOption::Tab> QTextBlockFormat::tabPositions() const-
796{-
797 QVariant variant = property(TabPositions);-
798 if(variant.isNull())-
799 return QList<QTextOption::Tab>();-
800 QList<QTextOption::Tab> answer;-
801 QList<QVariant> variantsList = qvariant_cast<QList<QVariant> >(variant);-
802 QList<QVariant>::Iterator iter = variantsList.begin();-
803 answer.reserve(variantsList.count());-
804 while(iter != variantsList.end()) {-
805 answer.append( qvariant_cast<QTextOption::Tab>(*iter));-
806 ++iter;-
807 }-
808 return answer;-
809}-
810QTextListFormat::QTextListFormat()-
811 : QTextFormat(ListFormat)-
812{-
813 setIndent(1);-
814}-
815QTextListFormat::QTextListFormat(const QTextFormat &fmt)-
816 : QTextFormat(fmt)-
817{-
818}-
819QTextFrameFormat::QTextFrameFormat() : QTextFormat(FrameFormat)-
820{-
821 setBorderStyle(BorderStyle_Outset);-
822 setBorderBrush(Qt::darkGray);-
823}-
824QTextFrameFormat::QTextFrameFormat(const QTextFormat &fmt)-
825 : QTextFormat(fmt)-
826{-
827}-
828void QTextFrameFormat::setMargin(qreal amargin)-
829{-
830 setProperty(FrameMargin, amargin);-
831 setProperty(FrameTopMargin, amargin);-
832 setProperty(FrameBottomMargin, amargin);-
833 setProperty(FrameLeftMargin, amargin);-
834 setProperty(FrameRightMargin, amargin);-
835}-
836qreal QTextFrameFormat::topMargin() const-
837{-
838 if (!hasProperty(FrameTopMargin))-
839 return margin();-
840 return doubleProperty(FrameTopMargin);-
841}-
842qreal QTextFrameFormat::bottomMargin() const-
843{-
844 if (!hasProperty(FrameBottomMargin))-
845 return margin();-
846 return doubleProperty(FrameBottomMargin);-
847}-
848qreal QTextFrameFormat::leftMargin() const-
849{-
850 if (!hasProperty(FrameLeftMargin))-
851 return margin();-
852 return doubleProperty(FrameLeftMargin);-
853}-
854qreal QTextFrameFormat::rightMargin() const-
855{-
856 if (!hasProperty(FrameRightMargin))-
857 return margin();-
858 return doubleProperty(FrameRightMargin);-
859}-
860QTextTableFormat::QTextTableFormat()-
861 : QTextFrameFormat()-
862{-
863 setObjectType(TableObject);-
864 setCellSpacing(2);-
865 setBorder(1);-
866}-
867QTextTableFormat::QTextTableFormat(const QTextFormat &fmt)-
868 : QTextFrameFormat(fmt)-
869{-
870}-
871QTextImageFormat::QTextImageFormat() : QTextCharFormat() { setObjectType(ImageObject); }-
872QTextImageFormat::QTextImageFormat(const QTextFormat &fmt)-
873 : QTextCharFormat(fmt)-
874{-
875}-
876QTextTableCellFormat::QTextTableCellFormat()-
877 : QTextCharFormat()-
878{-
879 setObjectType(TableCellObject);-
880}-
881QTextTableCellFormat::QTextTableCellFormat(const QTextFormat &fmt)-
882 : QTextCharFormat(fmt)-
883{-
884}-
885QTextFormatCollection::QTextFormatCollection(const QTextFormatCollection &rhs)-
886{-
887 formats = rhs.formats;-
888 objFormats = rhs.objFormats;-
889}-
890-
891QTextFormatCollection &QTextFormatCollection::operator=(const QTextFormatCollection &rhs)-
892{-
893 formats = rhs.formats;-
894 objFormats = rhs.objFormats;-
895 return *this;-
896}-
897-
898QTextFormatCollection::~QTextFormatCollection()-
899{-
900}-
901-
902int QTextFormatCollection::indexForFormat(const QTextFormat &format)-
903{-
904 uint hash = getHash(format.d, format.format_type);-
905 QMultiHash<uint, int>::const_iterator i = hashes.constFind(hash);-
906 while (i != hashes.constEnd() && i.key() == hash) {-
907 if (formats.value(i.value()) == format) {-
908 return i.value();-
909 }-
910 ++i;-
911 }-
912-
913 int idx = formats.size();-
914 formats.append(format);-
915-
916 if (true){-
917 QTextFormat &f = formats.last();-
918 if (!f.d)-
919 f.d = new QTextFormatPrivate;-
920 f.d->resolveFont(defaultFnt);-
921-
922 if (!hashes.contains(hash, idx))-
923 hashes.insert(hash, idx);-
924-
925 } else {
dead code: { formats.pop_back(); qt_noop(); }
-
926 formats.pop_back();
dead code: { formats.pop_back(); qt_noop(); }
-
927 qt_noop();
dead code: { formats.pop_back(); qt_noop(); }
-
928 }
dead code: { formats.pop_back(); qt_noop(); }
-
929 return idx;-
930}-
931-
932bool QTextFormatCollection::hasFormatCached(const QTextFormat &format) const-
933{-
934 uint hash = getHash(format.d, format.format_type);-
935 QMultiHash<uint, int>::const_iterator i = hashes.constFind(hash);-
936 while (i != hashes.constEnd() && i.key() == hash) {-
937 if (formats.value(i.value()) == format) {-
938 return true;-
939 }-
940 ++i;-
941 }-
942 return false;-
943}-
944-
945int QTextFormatCollection::objectFormatIndex(int objectIndex) const-
946{-
947 if (objectIndex == -1)-
948 return -1;-
949 return objFormats.at(objectIndex);-
950}-
951-
952void QTextFormatCollection::setObjectFormatIndex(int objectIndex, int formatIndex)-
953{-
954 objFormats[objectIndex] = formatIndex;-
955}-
956-
957int QTextFormatCollection::createObjectIndex(const QTextFormat &f)-
958{-
959 const int objectIndex = objFormats.size();-
960 objFormats.append(indexForFormat(f));-
961 return objectIndex;-
962}-
963-
964QTextFormat QTextFormatCollection::format(int idx) const-
965{-
966 if (idx < 0 || idx >= formats.count())-
967 return QTextFormat();-
968-
969 return formats.at(idx);-
970}-
971-
972void QTextFormatCollection::setDefaultFont(const QFont &f)-
973{-
974 defaultFnt = f;-
975 for (int i = 0; i < formats.count()
i < formats.count()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
976 if (formats[.at(i].).d
formats.at(i).dDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
977 formats[i].d->resolveFont(defaultFnt);
never executed: formats[i].d->resolveFont(defaultFnt);
0
978}
never executed: end of block
0
979-
980-
981QDebug operator<<(QDebug dbg, const QTextLength &l)-
982{-
983 QDebugStateSaver saver(dbg);-
984 dbg.nospace() << "QTextLength(QTextLength::Type(" << l.type() << "))";-
985 return dbg;-
986}-
987-
988QDebug operator<<(QDebug dbg, const QTextFormat &f)-
989{-
990 QDebugStateSaver saver(dbg);-
991 dbg.nospace() << "QTextFormat(QTextFormat::FormatType(" << f.type() << "))";-
992 return dbg;-
993}-
994-
995-
996-
997-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9