qtextformat.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/text/qtextformat.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtGui module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qtextformat.h"-
41#include "qtextformat_p.h"-
42-
43#include <qvariant.h>-
44#include <qdatastream.h>-
45#include <qdebug.h>-
46#include <qmap.h>-
47#include <qhashfunctions.h>-
48-
49QT_BEGIN_NAMESPACE-
50-
51/*!-
52 \class QTextLength-
53 \reentrant-
54-
55 \brief The QTextLength class encapsulates the different types of length-
56 used in a QTextDocument.-
57 \inmodule QtGui-
58-
59 \ingroup richtext-processing-
60-
61 When we specify a value for the length of an element in a text document,-
62 we often need to provide some other information so that the length is-
63 used in the way we expect. For example, when we specify a table width,-
64 the value can represent a fixed number of pixels, or it can be a percentage-
65 value. This information changes both the meaning of the value and the way-
66 it is used.-
67-
68 Generally, this class is used to specify table widths. These can be-
69 specified either as a fixed amount of pixels, as a percentage of the-
70 containing frame's width, or by a variable width that allows it to take-
71 up just the space it requires.-
72-
73 \sa QTextTable-
74*/-
75-
76/*!-
77 \fn explicit QTextLength::QTextLength()-
78-
79 Constructs a new length object which represents a variable size.-
80*/-
81-
82/*!-
83 \fn QTextLength::QTextLength(Type type, qreal value)-
84-
85 Constructs a new length object of the given \a type and \a value.-
86*/-
87-
88/*!-
89 \fn Type QTextLength::type() const-
90-
91 Returns the type of this length object.-
92-
93 \sa QTextLength::Type-
94*/-
95-
96/*!-
97 \fn qreal QTextLength::value(qreal maximumLength) const-
98-
99 Returns the effective length, constrained by the type of the length object-
100 and the specified \a maximumLength.-
101-
102 \sa type()-
103*/-
104-
105/*!-
106 \fn qreal QTextLength::rawValue() const-
107-
108 Returns the constraint value that is specific for the type of the length.-
109 If the length is QTextLength::PercentageLength then the raw value is in-
110 percent, in the range of 0 to 100. If the length is QTextLength::FixedLength-
111 then that fixed amount is returned. For variable lengths, zero is returned.-
112*/-
113-
114/*!-
115 \fn bool QTextLength::operator==(const QTextLength &other) const-
116-
117 Returns \c true if this text length is the same as the \a other text-
118 length.-
119*/-
120-
121/*!-
122 \fn bool QTextLength::operator!=(const QTextLength &other) const-
123-
124 Returns \c true if this text length is different from the \a other text-
125 length.-
126*/-
127-
128/*!-
129 \enum QTextLength::Type-
130-
131 This enum describes the different types a length object can-
132 have.-
133-
134 \value VariableLength The width of the object is variable-
135 \value FixedLength The width of the object is fixed-
136 \value PercentageLength The width of the object is in-
137 percentage of the maximum width-
138-
139 \sa type()-
140*/-
141-
142/*!-
143 Returns the text length as a QVariant-
144*/-
145QTextLength::operator QVariant() const-
146{-
147 return QVariant(QVariant::TextLength, this);-
148}-
149-
150#ifndef QT_NO_DATASTREAM-
151QDataStream &operator<<(QDataStream &stream, const QTextLength &length)-
152{-
153 return stream << qint32(length.lengthType) << double(length.fixedValueOrPercentage);-
154}-
155-
156QDataStream &operator>>(QDataStream &stream, QTextLength &length)-
157{-
158 qint32 type;-
159 double fixedValueOrPercentage;-
160 stream >> type >> fixedValueOrPercentage;-
161 length.fixedValueOrPercentage = fixedValueOrPercentage;-
162 length.lengthType = QTextLength::Type(type);-
163 return stream;-
164}-
165#endif // QT_NO_DATASTREAM-
166-
167class QTextFormatPrivate : public QSharedData-
168{-
169public:-
170 QTextFormatPrivate() : hashDirty(true), fontDirty(true), hashValue(0) {}-
171-
172 struct Property-
173 {-
174 inline Property(qint32 k, const QVariant &v) : key(k), value(v) {}-
175 inline Property() {}-
176-
177 qint32 key;-
178 QVariant value;-
179-
180 inline bool operator==(const Property &other) const-
181 { return key == other.key && value == other.value; }-
182 inline bool operator!=(const Property &other) const-
183 { return key != other.key || value != other.value; }-
184 };-
185-
186 inline uint hash() const-
187 {-
188 if (!hashDirty)-
189 return hashValue;-
190 return recalcHash();-
191 }-
192-
193 inline bool operator==(const QTextFormatPrivate &rhs) const {-
194 if (hash() != rhs.hash())-
195 return false;-
196-
197 return props == rhs.props;-
198 }-
199-
200 inline void insertProperty(qint32 key, const QVariant &value)-
201 {-
202 hashDirty = true;-
203 if (key >= QTextFormat::FirstFontProperty && key <= QTextFormat::LastFontProperty)-
204 fontDirty = true;-
205 for (int i = 0; i < props.count(); ++i)-
206 if (props.at(i).key == key) {-
207 props[i].value = value;-
208 return;-
209 }-
210 props.append(Property(key, value));-
211 }-
212-
213 inline void clearProperty(qint32 key)-
214 {-
215 for (int i = 0; i < props.count(); ++i)-
216 if (props.at(i).key == key) {-
217 hashDirty = true;-
218 if (key >= QTextFormat::FirstFontProperty && key <= QTextFormat::LastFontProperty)-
219 fontDirty = true;-
220 props.remove(i);-
221 return;-
222 }-
223 }-
224-
225 inline int propertyIndex(qint32 key) const-
226 {-
227 for (int i = 0; i < props.count(); ++i)-
228 if (props.at(i).key == key)-
229 return i;-
230 return -1;-
231 }-
232-
233 inline QVariant property(qint32 key) const-
234 {-
235 const int idx = propertyIndex(key);-
236 if (idx < 0)-
237 return QVariant();-
238 return props.at(idx).value;-
239 }-
240-
241 inline bool hasProperty(qint32 key) const-
242 { return propertyIndex(key) != -1; }-
243-
244 void resolveFont(const QFont &defaultFont);-
245-
246 inline const QFont &font() const {-
247 if (fontDirty)-
248 recalcFont();-
249 return fnt;-
250 }-
251-
252 QVector<Property> props;-
253private:-
254-
255 uint recalcHash() const;-
256 void recalcFont() const;-
257-
258 mutable bool hashDirty;-
259 mutable bool fontDirty;-
260 mutable uint hashValue;-
261 mutable QFont fnt;-
262-
263 friend QDataStream &operator<<(QDataStream &, const QTextFormat &);-
264 friend QDataStream &operator>>(QDataStream &, QTextFormat &);-
265};-
266Q_DECLARE_TYPEINFO(QTextFormatPrivate::Property, Q_MOVABLE_TYPE);-
267-
268static inline uint hash(const QColor &color)-
269{-
270 return (color.isValid()) ? color.rgba() : 0x234109;-
271}-
272-
273static inline uint hash(const QPen &pen)-
274{-
275 return hash(pen.color()) + qHash(pen.widthF());-
276}-
277-
278static inline uint hash(const QBrush &brush)-
279{-
280 return hash(brush.color()) + (brush.style() << 3);-
281}-
282-
283static inline uint variantHash(const QVariant &variant)-
284{-
285 // simple and fast hash functions to differentiate between type and value-
286 switch (variant.userType()) { // sorted by occurrence frequency-
287 case QVariant::String: return qHash(variant.toString());-
288 case QVariant::Double: return qHash(variant.toDouble());-
289 case QVariant::Int: return 0x811890 + variant.toInt();-
290 case QVariant::Brush:-
291 return 0x01010101 + hash(qvariant_cast<QBrush>(variant));-
292 case QVariant::Bool: return 0x371818 + variant.toBool();-
293 case QVariant::Pen: return 0x02020202 + hash(qvariant_cast<QPen>(variant));-
294 case QVariant::List:-
295 return 0x8377 + qvariant_cast<QVariantList>(variant).count();-
296 case QVariant::Color: return hash(qvariant_cast<QColor>(variant));-
297 case QVariant::TextLength:-
298 return 0x377 + hash(qvariant_cast<QTextLength>(variant).rawValue());-
299 case QMetaType::Float: return qHash(variant.toFloat());-
300 case QVariant::Invalid: return 0;-
301 default: break;-
302 }-
303 return qHash(variant.typeName());-
304}-
305-
306static inline int getHash(const QTextFormatPrivate *d, int format)-
307{-
308 return (d ? d->hash() : 0) + format;-
309}-
310-
311uint QTextFormatPrivate::recalcHash() const-
312{-
313 hashValue = 0;-
314 for (QVector<Property>::ConstIterator it = props.constBegin(); it != props.constEnd(); ++it)-
315 hashValue += (static_cast<quint32>(it->key) << 16) + variantHash(it->value);-
316-
317 hashDirty = false;-
318-
319 return hashValue;-
320}-
321-
322void QTextFormatPrivate::resolveFont(const QFont &defaultFont)-
323{-
324 recalcFont();-
325 const uint oldMask = fnt.resolve();-
326 fnt = fnt.resolve(defaultFont);-
327-
328 if (hasProperty(QTextFormat::FontSizeAdjustment)) {-
329 const qreal scaleFactors[7] = {qreal(0.7), qreal(0.8), qreal(1.0), qreal(1.2), qreal(1.5), qreal(2), qreal(2.4)};-
330-
331 const int htmlFontSize = qBound(0, property(QTextFormat::FontSizeAdjustment).toInt() + 3 - 1, 6);-
332-
333-
334 if (defaultFont.pointSize() <= 0) {-
335 qreal pixelSize = scaleFactors[htmlFontSize] * defaultFont.pixelSize();-
336 fnt.setPixelSize(qRound(pixelSize));-
337 } else {-
338 qreal pointSize = scaleFactors[htmlFontSize] * defaultFont.pointSizeF();-
339 fnt.setPointSizeF(pointSize);-
340 }-
341 }-
342-
343 fnt.resolve(oldMask);-
344}-
345-
346void QTextFormatPrivate::recalcFont() const-
347{-
348 // update cached font as well-
349 QFont f;-
350-
351 bool hasSpacingInformation = false;-
352 QFont::SpacingType spacingType = QFont::PercentageSpacing;-
353 qreal letterSpacing = 0.0;-
354-
355 for (int i = 0; i < props.count(); ++i) {-
356 switch (props.at(i).key) {-
357 case QTextFormat::FontFamily:-
358 f.setFamily(props.at(i).value.toString());-
359 break;-
360 case QTextFormat::FontPointSize:-
361 f.setPointSizeF(props.at(i).value.toReal());-
362 break;-
363 case QTextFormat::FontPixelSize:-
364 f.setPixelSize(props.at(i).value.toInt());-
365 break;-
366 case QTextFormat::FontWeight: {-
367 const QVariant weightValue = props.at(i).value;-
368 int weight = weightValue.toInt();-
369 if (weight >= 0 && weightValue.isValid())-
370 f.setWeight(weight);-
371 break; }-
372 case QTextFormat::FontItalic:-
373 f.setItalic(props.at(i).value.toBool());-
374 break;-
375 case QTextFormat::FontUnderline:-
376 if (! hasProperty(QTextFormat::TextUnderlineStyle)) // don't use the old one if the new one is there.-
377 f.setUnderline(props.at(i).value.toBool());-
378 break;-
379 case QTextFormat::TextUnderlineStyle:-
380 f.setUnderline(static_cast<QTextCharFormat::UnderlineStyle>(props.at(i).value.toInt()) == QTextCharFormat::SingleUnderline);-
381 break;-
382 case QTextFormat::FontOverline:-
383 f.setOverline(props.at(i).value.toBool());-
384 break;-
385 case QTextFormat::FontStrikeOut:-
386 f.setStrikeOut(props.at(i).value.toBool());-
387 break;-
388 case QTextFormat::FontLetterSpacingType:-
389 spacingType = static_cast<QFont::SpacingType>(props.at(i).value.toInt());-
390 hasSpacingInformation = true;-
391 break;-
392 case QTextFormat::FontLetterSpacing:-
393 letterSpacing = props.at(i).value.toReal();-
394 hasSpacingInformation = true;-
395 break;-
396 case QTextFormat::FontWordSpacing:-
397 f.setWordSpacing(props.at(i).value.toReal());-
398 break;-
399 case QTextFormat::FontCapitalization:-
400 f.setCapitalization(static_cast<QFont::Capitalization> (props.at(i).value.toInt()));-
401 break;-
402 case QTextFormat::FontFixedPitch: {-
403 const bool value = props.at(i).value.toBool();-
404 if (f.fixedPitch() != value)-
405 f.setFixedPitch(value);-
406 break; }-
407 case QTextFormat::FontStretch:-
408 f.setStretch(props.at(i).value.toInt());-
409 break;-
410 case QTextFormat::FontStyleHint:-
411 f.setStyleHint(static_cast<QFont::StyleHint>(props.at(i).value.toInt()), f.styleStrategy());-
412 break;-
413 case QTextFormat::FontHintingPreference:-
414 f.setHintingPreference(static_cast<QFont::HintingPreference>(props.at(i).value.toInt()));-
415 break;-
416 case QTextFormat::FontStyleStrategy:-
417 f.setStyleStrategy(static_cast<QFont::StyleStrategy>(props.at(i).value.toInt()));-
418 break;-
419 case QTextFormat::FontKerning:-
420 f.setKerning(props.at(i).value.toBool());-
421 break;-
422 default:-
423 break;-
424 }-
425 }-
426-
427 if (hasSpacingInformation)-
428 f.setLetterSpacing(spacingType, letterSpacing);-
429-
430 fnt = f;-
431 fontDirty = false;-
432}-
433-
434#ifndef QT_NO_DATASTREAM-
435Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QTextFormat &fmt)-
436{-
437 stream << fmt.format_type << fmt.properties();-
438 return stream;-
439}-
440-
441Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextFormat &fmt)-
442{-
443 QMap<qint32, QVariant> properties;-
444 stream >> fmt.format_type >> properties;-
445-
446 // QTextFormat's default constructor doesn't allocate the private structure, so-
447 // we have to do this, in case fmt is a default constructed value.-
448 if(!fmt.d)-
449 fmt.d = new QTextFormatPrivate();-
450-
451 for (QMap<qint32, QVariant>::ConstIterator it = properties.constBegin();-
452 it != properties.constEnd(); ++it)-
453 fmt.d->insertProperty(it.key(), it.value());-
454-
455 return stream;-
456}-
457#endif // QT_NO_DATASTREAM-
458-
459/*!-
460 \class QTextFormat-
461 \reentrant-
462-
463 \brief The QTextFormat class provides formatting information for a-
464 QTextDocument.-
465 \inmodule QtGui-
466-
467 \ingroup richtext-processing-
468 \ingroup shared-
469-
470 A QTextFormat is a generic class used for describing the format of-
471 parts of a QTextDocument. The derived classes QTextCharFormat,-
472 QTextBlockFormat, QTextListFormat, and QTextTableFormat are usually-
473 more useful, and describe the formatting that is applied to-
474 specific parts of the document.-
475-
476 A format has a \c FormatType which specifies the kinds of text item it-
477 can format; e.g. a block of text, a list, a table, etc. A format-
478 also has various properties (some specific to particular format-
479 types), as described by the Property enum. Every property has a-
480 corresponding Property.-
481-
482 The format type is given by type(), and the format can be tested-
483 with isCharFormat(), isBlockFormat(), isListFormat(),-
484 isTableFormat(), isFrameFormat(), and isImageFormat(). If the-
485 type is determined, it can be retrieved with toCharFormat(),-
486 toBlockFormat(), toListFormat(), toTableFormat(), toFrameFormat(),-
487 and toImageFormat().-
488-
489 A format's properties can be set with the setProperty() functions,-
490 and retrieved with boolProperty(), intProperty(), doubleProperty(),-
491 and stringProperty() as appropriate. All the property IDs used in-
492 the format can be retrieved with allPropertyIds(). One format can-
493 be merged into another using merge().-
494-
495 A format's object index can be set with setObjectIndex(), and-
496 retrieved with objectIndex(). These methods can be used to-
497 associate the format with a QTextObject. It is used to represent-
498 lists, frames, and tables inside the document.-
499-
500 \sa {Rich Text Processing}-
501*/-
502-
503/*!-
504 \enum QTextFormat::FormatType-
505-
506 This enum describes the text item a QTextFormat object is formatting.-
507-
508 \value InvalidFormat An invalid format as created by the default-
509 constructor-
510 \value BlockFormat The object formats a text block-
511 \value CharFormat The object formats a single character-
512 \value ListFormat The object formats a list-
513 \omitvalue TableFormat Unused Value, a table's FormatType is FrameFormat.-
514 \value FrameFormat The object formats a frame-
515-
516 \value UserFormat-
517-
518 \sa QTextCharFormat, QTextBlockFormat, QTextListFormat,-
519 QTextTableFormat, type()-
520*/-
521-
522/*!-
523 \enum QTextFormat::Property-
524-
525 This enum describes the different properties a format can have.-
526-
527 \value ObjectIndex The index of the formatted object. See objectIndex().-
528-
529 Paragraph and character properties-
530-
531 \value CssFloat How a frame is located relative to the surrounding text-
532 \value LayoutDirection The layout direction of the text in the document-
533 (Qt::LayoutDirection).-
534-
535 \value OutlinePen-
536 \value ForegroundBrush-
537 \value BackgroundBrush-
538 \value BackgroundImageUrl-
539-
540 Paragraph properties-
541-
542 \value BlockAlignment-
543 \value BlockTopMargin-
544 \value BlockBottomMargin-
545 \value BlockLeftMargin-
546 \value BlockRightMargin-
547 \value TextIndent-
548 \value TabPositions Specifies the tab positions. The tab positions are structs of QTextOption::Tab which are stored in-
549 a QList (internally, in a QList<QVariant>).-
550 \value BlockIndent-
551 \value LineHeight-
552 \value LineHeightType-
553 \value BlockNonBreakableLines-
554 \value BlockTrailingHorizontalRulerWidth The width of a horizontal ruler element.-
555-
556 Character properties-
557-
558 \value FontFamily-
559 \value FontPointSize-
560 \value FontPixelSize-
561 \value FontSizeAdjustment Specifies the change in size given to the fontsize already set using-
562 FontPointSize or FontPixelSize.-
563 \value FontFixedPitch-
564 \omitvalue FontSizeIncrement-
565 \value FontWeight-
566 \value FontItalic-
567 \value FontUnderline \e{This property has been deprecated.} Use QTextFormat::TextUnderlineStyle instead.-
568 \value FontOverline-
569 \value FontStrikeOut-
570 \value FontCapitalization Specifies the capitalization type that is to be applied to the text.-
571 \value FontLetterSpacingType Specifies the meaning of the FontLetterSpacing property. The default-
572 is QFont::PercentageSpacing.-
573 \value FontLetterSpacing Changes the default spacing between individual letters in the font. The value is-
574 specified as a percentage or absolute value, depending on FontLetterSpacingType.-
575 The default value is 100%.-
576 \value FontWordSpacing Changes the default spacing between individual words. A positive value increases the word spacing-
577 by the corresponding pixels; a negative value decreases the spacing.-
578 \value FontStretch Corresponds to the QFont::Stretch property-
579 \value FontStyleHint Corresponds to the QFont::StyleHint property-
580 \value FontStyleStrategy Corresponds to the QFont::StyleStrategy property-
581 \value FontKerning Specifies whether the font has kerning turned on.-
582 \value FontHintingPreference Controls the use of hinting according to values-
583 of the QFont::HintingPreference enum.-
584-
585 \omitvalue FirstFontProperty-
586 \omitvalue LastFontProperty-
587-
588 \value TextUnderlineColor-
589 \value TextVerticalAlignment-
590 \value TextOutline-
591 \value TextUnderlineStyle-
592 \value TextToolTip Specifies the (optional) tool tip to be displayed for a fragment of text.-
593-
594 \value IsAnchor-
595 \value AnchorHref-
596 \value AnchorName-
597 \value ObjectType-
598-
599 List properties-
600-
601 \value ListStyle Specifies the style used for the items in a list,-
602 described by values of the QTextListFormat::Style enum.-
603 \value ListIndent Specifies the amount of indentation used for a list.-
604 \value ListNumberPrefix Defines the text which is prepended to item numbers in-
605 numeric lists.-
606 \value ListNumberSuffix Defines the text which is appended to item numbers in-
607 numeric lists.-
608-
609 Table and frame properties-
610-
611 \value FrameBorder-
612 \value FrameBorderBrush-
613 \value FrameBorderStyle See the \l{QTextFrameFormat::BorderStyle}{BorderStyle} enum.-
614 \value FrameBottomMargin-
615 \value FrameHeight-
616 \value FrameLeftMargin-
617 \value FrameMargin-
618 \value FramePadding-
619 \value FrameRightMargin-
620 \value FrameTopMargin-
621 \value FrameWidth-
622 \value TableCellSpacing-
623 \value TableCellPadding-
624 \value TableColumns-
625 \value TableColumnWidthConstraints-
626 \value TableHeaderRowCount-
627-
628 Table cell properties-
629-
630 \value TableCellRowSpan-
631 \value TableCellColumnSpan-
632 \value TableCellLeftPadding-
633 \value TableCellRightPadding-
634 \value TableCellTopPadding-
635 \value TableCellBottomPadding-
636-
637 Image properties-
638-
639 \value ImageName-
640 \value ImageWidth-
641 \value ImageHeight-
642-
643 Selection properties-
644-
645 \value FullWidthSelection When set on the characterFormat of a selection,-
646 the whole width of the text will be shown selected.-
647-
648 Page break properties-
649-
650 \value PageBreakPolicy Specifies how pages are broken. See the PageBreakFlag enum.-
651-
652 \value UserProperty-
653-
654 \sa property(), setProperty()-
655*/-
656-
657/*!-
658 \enum QTextFormat::ObjectTypes-
659-
660 This enum describes what kind of QTextObject this format is associated with.-
661-
662 \value NoObject-
663 \value ImageObject-
664 \value TableObject-
665 \value TableCellObject-
666 \value UserObject The first object that can be used for application-specific purposes.-
667-
668 \sa QTextObject, QTextTable, QTextObject::format()-
669*/-
670-
671/*!-
672 \enum QTextFormat::PageBreakFlag-
673 \since 4.2-
674-
675 This enum describes how page breaking is performed when printing. It maps to the-
676 corresponding css properties.-
677-
678 \value PageBreak_Auto The page break is determined automatically depending on the-
679 available space on the current page-
680 \value PageBreak_AlwaysBefore The page is always broken before the paragraph/table-
681 \value PageBreak_AlwaysAfter A new page is always started after the paragraph/table-
682-
683 \sa QTextBlockFormat::pageBreakPolicy(), QTextFrameFormat::pageBreakPolicy(),-
684 PageBreakPolicy-
685*/-
686-
687/*!-
688 \fn bool QTextFormat::isValid() const-
689-
690 Returns \c true if the format is valid (i.e. is not-
691 InvalidFormat); otherwise returns \c false.-
692*/-
693-
694/*!-
695 \fn bool QTextFormat::isEmpty() const-
696 \since 5.3-
697-
698 Returns true if the format does not store any properties; false otherwise.-
699-
700 \sa propertyCount(), properties()-
701*/-
702-
703/*!-
704 \fn bool QTextFormat::isCharFormat() const-
705-
706 Returns \c true if this text format is a \c CharFormat; otherwise-
707 returns \c false.-
708*/-
709-
710-
711/*!-
712 \fn bool QTextFormat::isBlockFormat() const-
713-
714 Returns \c true if this text format is a \c BlockFormat; otherwise-
715 returns \c false.-
716*/-
717-
718-
719/*!-
720 \fn bool QTextFormat::isListFormat() const-
721-
722 Returns \c true if this text format is a \c ListFormat; otherwise-
723 returns \c false.-
724*/-
725-
726-
727/*!-
728 \fn bool QTextFormat::isTableFormat() const-
729-
730 Returns \c true if this text format is a \c TableFormat; otherwise-
731 returns \c false.-
732*/-
733-
734-
735/*!-
736 \fn bool QTextFormat::isFrameFormat() const-
737-
738 Returns \c true if this text format is a \c FrameFormat; otherwise-
739 returns \c false.-
740*/-
741-
742-
743/*!-
744 \fn bool QTextFormat::isImageFormat() const-
745-
746 Returns \c true if this text format is an image format; otherwise-
747 returns \c false.-
748*/-
749-
750-
751/*!-
752 \fn bool QTextFormat::isTableCellFormat() const-
753 \since 4.4-
754-
755 Returns \c true if this text format is a \c TableCellFormat; otherwise-
756 returns \c false.-
757*/-
758-
759-
760/*!-
761 Creates a new text format with an \c InvalidFormat.-
762-
763 \sa FormatType-
764*/-
765QTextFormat::QTextFormat()-
766 : format_type(InvalidFormat)-
767{-
768}-
769-
770/*!-
771 Creates a new text format of the given \a type.-
772-
773 \sa FormatType-
774*/-
775QTextFormat::QTextFormat(int type)-
776 : format_type(type)-
777{-
778}-
779-
780-
781/*!-
782 \fn QTextFormat::QTextFormat(const QTextFormat &other)-
783-
784 Creates a new text format with the same attributes as the \a other-
785 text format.-
786*/-
787QTextFormat::QTextFormat(const QTextFormat &rhs)-
788 : d(rhs.d), format_type(rhs.format_type)-
789{-
790}-
791-
792/*!-
793 \fn QTextFormat &QTextFormat::operator=(const QTextFormat &other)-
794-
795 Assigns the \a other text format to this text format, and returns a-
796 reference to this text format.-
797*/-
798QTextFormat &QTextFormat::operator=(const QTextFormat &rhs)-
799{-
800 d = rhs.d;-
801 format_type = rhs.format_type;-
802 return *this;-
803}-
804-
805/*!-
806 \fn void QTextFormat::swap(QTextFormat &other)-
807 \since 5.0-
808-
809 Swaps this text format with \a other. This function is very fast-
810 and never fails.-
811*/-
812-
813/*!-
814 Destroys this text format.-
815*/-
816QTextFormat::~QTextFormat()-
817{-
818}-
819-
820-
821/*!-
822 Returns the text format as a QVariant-
823*/-
824QTextFormat::operator QVariant() const-
825{-
826 return QVariant(QVariant::TextFormat, this);-
827}-
828-
829/*!-
830 Merges the \a other format with this format; where there are-
831 conflicts the \a other format takes precedence.-
832*/-
833void QTextFormat::merge(const QTextFormat &other)-
834{-
835 if (format_type != other.format_type)-
836 return;-
837-
838 if (!d) {-
839 d = other.d;-
840 return;-
841 }-
842-
843 if (!other.d)-
844 return;-
845-
846 QTextFormatPrivate *d = this->d;-
847-
848 const QVector<QTextFormatPrivate::Property> &otherProps = other.d->props;-
849 d->props.reserve(d->props.size() + otherProps.size());-
850 for (int i = 0; i < otherProps.count(); ++i) {-
851 const QTextFormatPrivate::Property &p = otherProps.at(i);-
852 d->insertProperty(p.key, p.value);-
853 }-
854}-
855-
856/*!-
857 Returns the type of this format.-
858-
859 \sa FormatType-
860*/-
861int QTextFormat::type() const-
862{-
863 return format_type;-
864}-
865-
866/*!-
867 Returns this format as a block format.-
868*/-
869QTextBlockFormat QTextFormat::toBlockFormat() const-
870{-
871 return QTextBlockFormat(*this);-
872}-
873-
874/*!-
875 Returns this format as a character format.-
876*/-
877QTextCharFormat QTextFormat::toCharFormat() const-
878{-
879 return QTextCharFormat(*this);-
880}-
881-
882/*!-
883 Returns this format as a list format.-
884*/-
885QTextListFormat QTextFormat::toListFormat() const-
886{-
887 return QTextListFormat(*this);-
888}-
889-
890/*!-
891 Returns this format as a table format.-
892*/-
893QTextTableFormat QTextFormat::toTableFormat() const-
894{-
895 return QTextTableFormat(*this);-
896}-
897-
898/*!-
899 Returns this format as a frame format.-
900*/-
901QTextFrameFormat QTextFormat::toFrameFormat() const-
902{-
903 return QTextFrameFormat(*this);-
904}-
905-
906/*!-
907 Returns this format as an image format.-
908*/-
909QTextImageFormat QTextFormat::toImageFormat() const-
910{-
911 return QTextImageFormat(*this);-
912}-
913-
914/*!-
915 \since 4.4-
916-
917 Returns this format as a table cell format.-
918*/-
919QTextTableCellFormat QTextFormat::toTableCellFormat() const-
920{-
921 return QTextTableCellFormat(*this);-
922}-
923-
924/*!-
925 Returns the value of the property specified by \a propertyId. If the-
926 property isn't of QTextFormat::Bool type, false is returned instead.-
927-
928 \sa setProperty(), intProperty(), doubleProperty(), stringProperty(), colorProperty(),-
929 lengthProperty(), lengthVectorProperty(), Property-
930*/-
931bool QTextFormat::boolProperty(int propertyId) const-
932{-
933 if (!d)-
934 return false;-
935 const QVariant prop = d->property(propertyId);-
936 if (prop.userType() != QVariant::Bool)-
937 return false;-
938 return prop.toBool();-
939}-
940-
941/*!-
942 Returns the value of the property specified by \a propertyId. If the-
943 property is not of QTextFormat::Integer type, 0 is returned instead.-
944-
945 \sa setProperty(), boolProperty(), doubleProperty(), stringProperty(), colorProperty(),-
946 lengthProperty(), lengthVectorProperty(), Property-
947*/-
948int QTextFormat::intProperty(int propertyId) const-
949{-
950 // required, since the default layout direction has to be LayoutDirectionAuto, which is not integer 0-
951 int def = (propertyId == QTextFormat::LayoutDirection) ? int(Qt::LayoutDirectionAuto) : 0;-
952-
953 if (!d)-
954 return def;-
955 const QVariant prop = d->property(propertyId);-
956 if (prop.userType() != QVariant::Int)-
957 return def;-
958 return prop.toInt();-
959}-
960-
961/*!-
962 Returns the value of the property specified by \a propertyId. If the-
963 property isn't of QVariant::Double or QMetaType::Float type, 0 is-
964 returned instead.-
965-
966 \sa setProperty(), boolProperty(), intProperty(), stringProperty(), colorProperty(),-
967 lengthProperty(), lengthVectorProperty(), Property-
968*/-
969qreal QTextFormat::doubleProperty(int propertyId) const-
970{-
971 if (!d)-
972 return 0.;-
973 const QVariant prop = d->property(propertyId);-
974 if (prop.userType() != QVariant::Double && prop.userType() != QMetaType::Float)-
975 return 0.;-
976 return qvariant_cast<qreal>(prop);-
977}-
978-
979/*!-
980 Returns the value of the property given by \a propertyId; if the-
981 property isn't of QVariant::String type, an empty string is-
982 returned instead.-
983-
984 \sa setProperty(), boolProperty(), intProperty(), doubleProperty(), colorProperty(),-
985 lengthProperty(), lengthVectorProperty(), Property-
986*/-
987QString QTextFormat::stringProperty(int propertyId) const-
988{-
989 if (!d)-
990 return QString();-
991 const QVariant prop = d->property(propertyId);-
992 if (prop.userType() != QVariant::String)-
993 return QString();-
994 return prop.toString();-
995}-
996-
997/*!-
998 Returns the value of the property given by \a propertyId; if the-
999 property isn't of QVariant::Color type, an invalid color is-
1000 returned instead.-
1001-
1002 \sa setProperty(), boolProperty(), intProperty(), doubleProperty(),-
1003 stringProperty(), lengthProperty(), lengthVectorProperty(), Property-
1004*/-
1005QColor QTextFormat::colorProperty(int propertyId) const-
1006{-
1007 if (!d)-
1008 return QColor();-
1009 const QVariant prop = d->property(propertyId);-
1010 if (prop.userType() != QVariant::Color)-
1011 return QColor();-
1012 return qvariant_cast<QColor>(prop);-
1013}-
1014-
1015/*!-
1016 Returns the value of the property given by \a propertyId; if the-
1017 property isn't of QVariant::Pen type, Qt::NoPen is-
1018 returned instead.-
1019-
1020 \sa setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(),-
1021 lengthProperty(), lengthVectorProperty(), Property-
1022*/-
1023QPen QTextFormat::penProperty(int propertyId) const-
1024{-
1025 if (!d)-
1026 return QPen(Qt::NoPen);-
1027 const QVariant prop = d->property(propertyId);-
1028 if (prop.userType() != QVariant::Pen)-
1029 return QPen(Qt::NoPen);-
1030 return qvariant_cast<QPen>(prop);-
1031}-
1032-
1033/*!-
1034 Returns the value of the property given by \a propertyId; if the-
1035 property isn't of QVariant::Brush type, Qt::NoBrush is-
1036 returned instead.-
1037-
1038 \sa setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(),-
1039 lengthProperty(), lengthVectorProperty(), Property-
1040*/-
1041QBrush QTextFormat::brushProperty(int propertyId) const-
1042{-
1043 if (!d)-
1044 return QBrush(Qt::NoBrush);-
1045 const QVariant prop = d->property(propertyId);-
1046 if (prop.userType() != QVariant::Brush)-
1047 return QBrush(Qt::NoBrush);-
1048 return qvariant_cast<QBrush>(prop);-
1049}-
1050-
1051/*!-
1052 Returns the value of the property given by \a propertyId.-
1053-
1054 \sa setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(),-
1055 colorProperty(), lengthVectorProperty(), Property-
1056*/-
1057QTextLength QTextFormat::lengthProperty(int propertyId) const-
1058{-
1059 if (!d)-
1060 return QTextLength();-
1061 return qvariant_cast<QTextLength>(d->property(propertyId));-
1062}-
1063-
1064/*!-
1065 Returns the value of the property given by \a propertyId. If the-
1066 property isn't of QTextFormat::LengthVector type, an empty length-
1067 vector is returned instead.-
1068-
1069 \sa setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(),-
1070 colorProperty(), lengthProperty(), Property-
1071*/-
1072QVector<QTextLength> QTextFormat::lengthVectorProperty(int propertyId) const-
1073{-
1074 QVector<QTextLength> vector;-
1075 if (!d)-
1076 return vector;-
1077 const QVariant prop = d->property(propertyId);-
1078 if (prop.userType() != QVariant::List)-
1079 return vector;-
1080-
1081 QList<QVariant> propertyList = prop.toList();-
1082 for (int i=0; i<propertyList.size(); ++i) {-
1083 QVariant var = propertyList.at(i);-
1084 if (var.userType() == QVariant::TextLength)-
1085 vector.append(qvariant_cast<QTextLength>(var));-
1086 }-
1087-
1088 return vector;-
1089}-
1090-
1091/*!-
1092 Returns the property specified by the given \a propertyId.-
1093-
1094 \sa Property-
1095*/-
1096QVariant QTextFormat::property(int propertyId) const-
1097{-
1098 return d ? d->property(propertyId) : QVariant();-
1099}-
1100-
1101/*!-
1102 Sets the property specified by the \a propertyId to the given \a value.-
1103-
1104 \sa Property-
1105*/-
1106void QTextFormat::setProperty(int propertyId, const QVariant &value)-
1107{-
1108 if (!d)-
1109 d = new QTextFormatPrivate;-
1110 if (!value.isValid())-
1111 clearProperty(propertyId);-
1112 else-
1113 d->insertProperty(propertyId, value);-
1114}-
1115-
1116/*!-
1117 Sets the value of the property given by \a propertyId to \a value.-
1118-
1119 \sa lengthVectorProperty(), Property-
1120*/-
1121void QTextFormat::setProperty(int propertyId, const QVector<QTextLength> &value)-
1122{-
1123 if (!d)-
1124 d = new QTextFormatPrivate;-
1125 QVariantList list;-
1126 const int numValues = value.size();-
1127 list.reserve(numValues);-
1128 for (int i = 0; i < numValues; ++i)-
1129 list << value.at(i);-
1130 d->insertProperty(propertyId, list);-
1131}-
1132-
1133/*!-
1134 Clears the value of the property given by \a propertyId-
1135-
1136 \sa Property-
1137*/-
1138void QTextFormat::clearProperty(int propertyId)-
1139{-
1140 if (!d)-
1141 return;-
1142 d->clearProperty(propertyId);-
1143}-
1144-
1145-
1146/*!-
1147 \fn void QTextFormat::setObjectType(int type)-
1148-
1149 Sets the text format's object type to \a type.-
1150-
1151 \sa ObjectTypes, objectType()-
1152*/-
1153-
1154-
1155/*!-
1156 \fn int QTextFormat::objectType() const-
1157-
1158 Returns the text format's object type.-
1159-
1160 \sa ObjectTypes, setObjectType()-
1161*/-
1162-
1163-
1164/*!-
1165 Returns the index of the format object, or -1 if the format object is invalid.-
1166-
1167 \sa setObjectIndex()-
1168*/-
1169int QTextFormat::objectIndex() const-
1170{-
1171 if (!d)-
1172 return -1;-
1173 const QVariant prop = d->property(ObjectIndex);-
1174 if (prop.userType() != QVariant::Int) // ####-
1175 return -1;-
1176 return prop.toInt();-
1177}-
1178-
1179/*!-
1180 \fn void QTextFormat::setObjectIndex(int index)-
1181-
1182 Sets the format object's object \a index.-
1183-
1184 \sa objectIndex()-
1185*/-
1186void QTextFormat::setObjectIndex(int o)-
1187{-
1188 if (o == -1) {-
1189 if (d)-
1190 d->clearProperty(ObjectIndex);-
1191 } else {-
1192 if (!d)-
1193 d = new QTextFormatPrivate;-
1194 // ### type-
1195 d->insertProperty(ObjectIndex, o);-
1196 }-
1197}-
1198-
1199/*!-
1200 Returns \c true if the text format has a property with the given \a-
1201 propertyId; otherwise returns \c false.-
1202-
1203 \sa properties(), Property-
1204*/-
1205bool QTextFormat::hasProperty(int propertyId) const-
1206{-
1207 return d ? d->hasProperty(propertyId) : false;-
1208}-
1209-
1210/*-
1211 Returns the property type for the given \a propertyId.-
1212-
1213 \sa hasProperty(), allPropertyIds(), Property-
1214*/-
1215-
1216/*!-
1217 Returns a map with all properties of this text format.-
1218*/-
1219QMap<int, QVariant> QTextFormat::properties() const-
1220{-
1221 QMap<int, QVariant> map;-
1222 if (d) {-
1223 for (int i = 0; i < d->props.count(); ++i)-
1224 map.insert(d->props.at(i).key, d->props.at(i).value);-
1225 }-
1226 return map;-
1227}-
1228-
1229/*!-
1230 \since 4.3-
1231 Returns the number of properties stored in the format.-
1232*/-
1233int QTextFormat::propertyCount() const-
1234{-
1235 return d ? d->props.count() : 0;-
1236}-
1237-
1238/*!-
1239 \fn bool QTextFormat::operator!=(const QTextFormat &other) const-
1240-
1241 Returns \c true if this text format is different from the \a other text-
1242 format.-
1243*/-
1244-
1245-
1246/*!-
1247 \fn bool QTextFormat::operator==(const QTextFormat &other) const-
1248-
1249 Returns \c true if this text format is the same as the \a other text-
1250 format.-
1251*/-
1252bool QTextFormat::operator==(const QTextFormat &rhs) const-
1253{-
1254 if (format_type != rhs.format_type)-
1255 return false;-
1256-
1257 if (d == rhs.d)-
1258 return true;-
1259-
1260 if (d && d->props.isEmpty() && !rhs.d)-
1261 return true;-
1262-
1263 if (!d && rhs.d && rhs.d->props.isEmpty())-
1264 return true;-
1265-
1266 if (!d || !rhs.d)-
1267 return false;-
1268-
1269 return *d == *rhs.d;-
1270}-
1271-
1272/*!-
1273 \class QTextCharFormat-
1274 \reentrant-
1275-
1276 \brief The QTextCharFormat class provides formatting information for-
1277 characters in a QTextDocument.-
1278 \inmodule QtGui-
1279-
1280 \ingroup richtext-processing-
1281 \ingroup shared-
1282-
1283 The character format of text in a document specifies the visual properties-
1284 of the text, as well as information about its role in a hypertext document.-
1285-
1286 The font used can be set by supplying a font to the setFont() function, and-
1287 each aspect of its appearance can be adjusted to give the desired effect.-
1288 setFontFamily() and setFontPointSize() define the font's family (e.g. Times)-
1289 and printed size; setFontWeight() and setFontItalic() provide control over-
1290 the style of the font. setFontUnderline(), setFontOverline(),-
1291 setFontStrikeOut(), and setFontFixedPitch() provide additional effects for-
1292 text.-
1293-
1294 The color is set with setForeground(). If the text is intended to be used-
1295 as an anchor (for hyperlinks), this can be enabled with setAnchor(). The-
1296 setAnchorHref() and setAnchorNames() functions are used to specify the-
1297 information about the hyperlink's destination and the anchor's name.-
1298-
1299 \sa QTextFormat, QTextBlockFormat, QTextTableFormat, QTextListFormat-
1300*/-
1301-
1302/*!-
1303 \enum QTextCharFormat::VerticalAlignment-
1304-
1305 This enum describes the ways that adjacent characters can be vertically-
1306 aligned.-
1307-
1308 \value AlignNormal Adjacent characters are positioned in the standard-
1309 way for text in the writing system in use.-
1310 \value AlignSuperScript Characters are placed above the base line for-
1311 normal text.-
1312 \value AlignSubScript Characters are placed below the base line for-
1313 normal text.-
1314 \value AlignMiddle The center of the object is vertically aligned with the-
1315 base line. Currently, this is only implemented for-
1316 inline objects.-
1317 \value AlignBottom The bottom edge of the object is vertically aligned with-
1318 the base line.-
1319 \value AlignTop The top edge of the object is vertically aligned with-
1320 the base line.-
1321 \value AlignBaseline The base lines of the characters are aligned.-
1322*/-
1323-
1324/*!-
1325 \enum QTextCharFormat::UnderlineStyle-
1326-
1327 This enum describes the different ways drawing underlined text.-
1328-
1329 \value NoUnderline Text is draw without any underlining decoration.-
1330 \value SingleUnderline A line is drawn using Qt::SolidLine.-
1331 \value DashUnderline Dashes are drawn using Qt::DashLine.-
1332 \value DotLine Dots are drawn using Qt::DotLine;-
1333 \value DashDotLine Dashs and dots are drawn using Qt::DashDotLine.-
1334 \value DashDotDotLine Underlines draw drawn using Qt::DashDotDotLine.-
1335 \value WaveUnderline The text is underlined using a wave shaped line.-
1336 \value SpellCheckUnderline The underline is drawn depending on the QStyle::SH_SpellCeckUnderlineStyle-
1337 style hint of the QApplication style. By default this is mapped to-
1338 WaveUnderline, on \macos it is mapped to DashDotLine.-
1339-
1340 \sa Qt::PenStyle-
1341*/-
1342-
1343/*!-
1344 \fn QTextCharFormat::QTextCharFormat()-
1345-
1346 Constructs a new character format object.-
1347*/-
1348QTextCharFormat::QTextCharFormat() : QTextFormat(CharFormat) {}-
1349-
1350/*!-
1351 \internal-
1352 \fn QTextCharFormat::QTextCharFormat(const QTextFormat &other)-
1353-
1354 Creates a new character format with the same attributes as the \a given-
1355 text format.-
1356*/-
1357QTextCharFormat::QTextCharFormat(const QTextFormat &fmt)-
1358 : QTextFormat(fmt)-
1359{-
1360}-
1361-
1362/*!-
1363 \fn bool QTextCharFormat::isValid() const-
1364-
1365 Returns \c true if this character format is valid; otherwise returns-
1366 false.-
1367*/-
1368-
1369-
1370/*!-
1371 \fn void QTextCharFormat::setFontFamily(const QString &family)-
1372-
1373 Sets the text format's font \a family.-
1374-
1375 \sa setFont()-
1376*/-
1377-
1378-
1379/*!-
1380 \fn QString QTextCharFormat::fontFamily() const-
1381-
1382 Returns the text format's font family.-
1383-
1384 \sa font()-
1385*/-
1386-
1387-
1388/*!-
1389 \fn void QTextCharFormat::setFontPointSize(qreal size)-
1390-
1391 Sets the text format's font \a size.-
1392-
1393 \sa setFont()-
1394*/-
1395-
1396-
1397/*!-
1398 \fn qreal QTextCharFormat::fontPointSize() const-
1399-
1400 Returns the font size used to display text in this format.-
1401-
1402 \sa font()-
1403*/-
1404-
1405-
1406/*!-
1407 \fn void QTextCharFormat::setFontWeight(int weight)-
1408-
1409 Sets the text format's font weight to \a weight.-
1410-
1411 \sa setFont(), QFont::Weight-
1412*/-
1413-
1414-
1415/*!-
1416 \fn int QTextCharFormat::fontWeight() const-
1417-
1418 Returns the text format's font weight.-
1419-
1420 \sa font(), QFont::Weight-
1421*/-
1422-
1423-
1424/*!-
1425 \fn void QTextCharFormat::setFontItalic(bool italic)-
1426-
1427 If \a italic is true, sets the text format's font to be italic; otherwise-
1428 the font will be non-italic.-
1429-
1430 \sa setFont()-
1431*/-
1432-
1433-
1434/*!-
1435 \fn bool QTextCharFormat::fontItalic() const-
1436-
1437 Returns \c true if the text format's font is italic; otherwise-
1438 returns \c false.-
1439-
1440 \sa font()-
1441*/-
1442-
1443-
1444/*!-
1445 \fn void QTextCharFormat::setFontUnderline(bool underline)-
1446-
1447 If \a underline is true, sets the text format's font to be underlined;-
1448 otherwise it is displayed non-underlined.-
1449-
1450 \sa setFont()-
1451*/-
1452-
1453-
1454/*!-
1455 \fn bool QTextCharFormat::fontUnderline() const-
1456-
1457 Returns \c true if the text format's font is underlined; otherwise-
1458 returns \c false.-
1459-
1460 \sa font()-
1461*/-
1462bool QTextCharFormat::fontUnderline() const-
1463{-
1464 if (hasProperty(TextUnderlineStyle))-
1465 return underlineStyle() == SingleUnderline;-
1466 return boolProperty(FontUnderline);-
1467}-
1468-
1469/*!-
1470 \fn UnderlineStyle QTextCharFormat::underlineStyle() const-
1471 \since 4.2-
1472-
1473 Returns the style of underlining the text.-
1474*/-
1475-
1476/*!-
1477 \fn void QTextCharFormat::setUnderlineStyle(UnderlineStyle style)-
1478 \since 4.2-
1479-
1480 Sets the style of underlining the text to \a style.-
1481*/-
1482void QTextCharFormat::setUnderlineStyle(UnderlineStyle style)-
1483{-
1484 setProperty(TextUnderlineStyle, style);-
1485 // for compatibility-
1486 setProperty(FontUnderline, style == SingleUnderline);-
1487}-
1488-
1489/*!-
1490 \fn void QTextCharFormat::setFontOverline(bool overline)-
1491-
1492 If \a overline is true, sets the text format's font to be overlined;-
1493 otherwise the font is displayed non-overlined.-
1494-
1495 \sa setFont()-
1496*/-
1497-
1498-
1499/*!-
1500 \fn bool QTextCharFormat::fontOverline() const-
1501-
1502 Returns \c true if the text format's font is overlined; otherwise-
1503 returns \c false.-
1504-
1505 \sa font()-
1506*/-
1507-
1508-
1509/*!-
1510 \fn void QTextCharFormat::setFontStrikeOut(bool strikeOut)-
1511-
1512 If \a strikeOut is true, sets the text format's font with strike-out-
1513 enabled (with a horizontal line through it); otherwise it is displayed-
1514 without strikeout.-
1515-
1516 \sa setFont()-
1517*/-
1518-
1519-
1520/*!-
1521 \fn bool QTextCharFormat::fontStrikeOut() const-
1522-
1523 Returns \c true if the text format's font is struck out (has a horizontal line-
1524 drawn through it); otherwise returns \c false.-
1525-
1526 \sa font()-
1527*/-
1528-
1529-
1530/*!-
1531 \since 4.5-
1532 \fn void QTextCharFormat::setFontStyleHint(QFont::StyleHint hint, QFont::StyleStrategy strategy)-
1533-
1534 Sets the font style \a hint and \a strategy.-
1535-
1536 Qt does not support style hints on X11 since this information is not provided by the window system.-
1537-
1538 \sa setFont()-
1539 \sa QFont::setStyleHint()-
1540*/-
1541-
1542-
1543/*!-
1544 \since 4.5-
1545 \fn void QTextCharFormat::setFontStyleStrategy(QFont::StyleStrategy strategy)-
1546-
1547 Sets the font style \a strategy.-
1548-
1549 \sa setFont()-
1550 \sa QFont::setStyleStrategy()-
1551*/-
1552-
1553-
1554/*!-
1555 \since 4.5-
1556 \fn void QTextCharFormat::setFontKerning(bool enable)-
1557 Enables kerning for this font if \a enable is true; otherwise disables it.-
1558-
1559 When kerning is enabled, glyph metrics do not add up anymore, even for-
1560 Latin text. In other words, the assumption that width('a') + width('b')-
1561 is equal to width("ab") is not neccesairly true.-
1562-
1563 \sa setFont()-
1564*/-
1565-
1566-
1567/*!-
1568 \fn QTextCharFormat::StyleHint QTextCharFormat::fontStyleHint() const-
1569 \since 4.5-
1570-
1571 Returns the font style hint.-
1572-
1573 \sa setFontStyleHint(), font()-
1574*/-
1575-
1576-
1577/*!-
1578 \since 4.5-
1579 \fn QTextCharFormat::StyleStrategy QTextCharFormat::fontStyleStrategy() const-
1580-
1581 Returns the current font style strategy.-
1582-
1583 \sa setFontStyleStrategy()-
1584 \sa font()-
1585*/-
1586-
1587-
1588/*!-
1589 \since 4.5-
1590 \fn bool QTextCharFormat::fontKerning() const-
1591 Returns \c true if the font kerning is enabled.-
1592-
1593 \sa setFontKerning()-
1594 \sa font()-
1595*/-
1596-
1597-
1598/*!-
1599 \fn void QTextCharFormat::setFontFixedPitch(bool fixedPitch)-
1600-
1601 If \a fixedPitch is true, sets the text format's font to be fixed pitch;-
1602 otherwise a non-fixed pitch font is used.-
1603-
1604 \sa setFont()-
1605*/-
1606-
1607-
1608/*!-
1609 \fn bool QTextCharFormat::fontFixedPitch() const-
1610-
1611 Returns \c true if the text format's font is fixed pitch; otherwise-
1612 returns \c false.-
1613-
1614 \sa font()-
1615*/-
1616-
1617/*!-
1618 \since 4.8-
1619-
1620 \fn void QTextCharFormat::setFontHintingPreference(QFont::HintingPreference hintingPreference)-
1621-
1622 Sets the hinting preference of the text format's font to be \a hintingPreference.-
1623-
1624 \sa setFont(), QFont::setHintingPreference()-
1625*/-
1626-
1627/*!-
1628 \since 4.8-
1629-
1630 \fn QFont::HintingPreference QTextCharFormat::fontHintingPreference() const-
1631-
1632 Returns the hinting preference set for this text format.-
1633-
1634 \sa font(), QFont::hintingPreference()-
1635*/-
1636-
1637/*!-
1638 \fn QPen QTextCharFormat::textOutline() const-
1639-
1640 Returns the pen used to draw the outlines of characters in this format.-
1641*/-
1642-
1643-
1644/*!-
1645 \fn void QTextCharFormat::setTextOutline(const QPen &pen)-
1646-
1647 Sets the pen used to draw the outlines of characters to the given \a pen.-
1648*/-
1649-
1650/*!-
1651 \fn void QTextCharFormat::setToolTip(const QString &text)-
1652 \since 4.3-
1653-
1654 Sets the tool tip for a fragment of text to the given \a text.-
1655*/-
1656-
1657/*!-
1658 \fn QString QTextCharFormat::toolTip() const-
1659 \since 4.3-
1660-
1661 Returns the tool tip that is displayed for a fragment of text.-
1662*/-
1663-
1664/*!-
1665 \fn void QTextFormat::setForeground(const QBrush &brush)-
1666-
1667 Sets the foreground brush to the specified \a brush. The foreground-
1668 brush is mostly used to render text.-
1669-
1670 \sa foreground(), clearForeground(), setBackground()-
1671*/-
1672-
1673-
1674/*!-
1675 \fn QBrush QTextFormat::foreground() const-
1676-
1677 Returns the brush used to render foreground details, such as text,-
1678 frame outlines, and table borders.-
1679-
1680 \sa setForeground(), clearForeground(), background()-
1681*/-
1682-
1683/*!-
1684 \fn void QTextFormat::clearForeground()-
1685-
1686 Clears the brush used to paint the document's foreground. The default-
1687 brush will be used.-
1688-
1689 \sa foreground(), setForeground(), clearBackground()-
1690*/-
1691-
1692-
1693/*!-
1694 \fn void QTextCharFormat::setAnchor(bool anchor)-
1695-
1696 If \a anchor is true, text with this format represents an anchor, and is-
1697 formatted in the appropriate way; otherwise the text is formatted normally.-
1698 (Anchors are hyperlinks which are often shown underlined and in a different-
1699 color from plain text.)-
1700-
1701 The way the text is rendered is independent of whether or not the format-
1702 has a valid anchor defined. Use setAnchorHref(), and optionally-
1703 setAnchorNames() to create a hypertext link.-
1704-
1705 \sa isAnchor()-
1706*/-
1707-
1708-
1709/*!-
1710 \fn bool QTextCharFormat::isAnchor() const-
1711-
1712 Returns \c true if the text is formatted as an anchor; otherwise-
1713 returns \c false.-
1714-
1715 \sa setAnchor(), setAnchorHref(), setAnchorNames()-
1716*/-
1717-
1718-
1719/*!-
1720 \fn void QTextCharFormat::setAnchorHref(const QString &value)-
1721-
1722 Sets the hypertext link for the text format to the given \a value.-
1723 This is typically a URL like "http://example.com/index.html".-
1724-
1725 The anchor will be displayed with the \a value as its display text;-
1726 if you want to display different text call setAnchorNames().-
1727-
1728 To format the text as a hypertext link use setAnchor().-
1729*/-
1730-
1731-
1732/*!-
1733 \fn QString QTextCharFormat::anchorHref() const-
1734-
1735 Returns the text format's hypertext link, or an empty string if-
1736 none has been set.-
1737*/-
1738-
1739-
1740/*!-
1741 \fn void QTextCharFormat::setAnchorName(const QString &name)-
1742 \obsolete-
1743-
1744 This function is deprecated. Use setAnchorNames() instead.-
1745-
1746 Sets the text format's anchor \a name. For the anchor to work as a-
1747 hyperlink, the destination must be set with setAnchorHref() and-
1748 the anchor must be enabled with setAnchor().-
1749*/-
1750-
1751/*!-
1752 \fn void QTextCharFormat::setAnchorNames(const QStringList &names)-
1753 \since 4.3-
1754-
1755 Sets the text format's anchor \a names. For the anchor to work as a-
1756 hyperlink, the destination must be set with setAnchorHref() and-
1757 the anchor must be enabled with setAnchor().-
1758*/-
1759-
1760/*!-
1761 \fn QString QTextCharFormat::anchorName() const-
1762 \obsolete-
1763-
1764 This function is deprecated. Use anchorNames() instead.-
1765-
1766 Returns the anchor name associated with this text format, or an empty-
1767 string if none has been set. If the anchor name is set, text with this-
1768 format can be the destination of a hypertext link.-
1769*/-
1770QString QTextCharFormat::anchorName() const-
1771{-
1772 QVariant prop = property(AnchorName);-
1773 if (prop.userType() == QVariant::StringList)-
1774 return prop.toStringList().value(0);-
1775 else if (prop.userType() != QVariant::String)-
1776 return QString();-
1777 return prop.toString();-
1778}-
1779-
1780/*!-
1781 \fn QStringList QTextCharFormat::anchorNames() const-
1782 \since 4.3-
1783-
1784 Returns the anchor names associated with this text format, or an empty-
1785 string list if none has been set. If the anchor names are set, text with this-
1786 format can be the destination of a hypertext link.-
1787*/-
1788QStringList QTextCharFormat::anchorNames() const-
1789{-
1790 QVariant prop = property(AnchorName);-
1791 if (prop.userType() == QVariant::StringList)-
1792 return prop.toStringList();-
1793 else if (prop.userType() != QVariant::String)-
1794 return QStringList();-
1795 return QStringList(prop.toString());-
1796}-
1797-
1798-
1799/*!-
1800 \fn void QTextCharFormat::setTableCellRowSpan(int tableCellRowSpan)-
1801 \internal-
1802-
1803 If this character format is applied to characters in a table cell,-
1804 the cell will span \a tableCellRowSpan rows.-
1805*/-
1806-
1807-
1808/*!-
1809 \fn int QTextCharFormat::tableCellRowSpan() const-
1810 \internal-
1811-
1812 If this character format is applied to characters in a table cell,-
1813 this function returns the number of rows spanned by the text (this may-
1814 be 1); otherwise it returns 1.-
1815*/-
1816-
1817/*!-
1818 \fn void QTextCharFormat::setTableCellColumnSpan(int tableCellColumnSpan)-
1819 \internal-
1820-
1821 If this character format is applied to characters in a table cell,-
1822 the cell will span \a tableCellColumnSpan columns.-
1823*/-
1824-
1825-
1826/*!-
1827 \fn int QTextCharFormat::tableCellColumnSpan() const-
1828 \internal-
1829-
1830 If this character format is applied to characters in a table cell,-
1831 this function returns the number of columns spanned by the text (this-
1832 may be 1); otherwise it returns 1.-
1833*/-
1834-
1835/*!-
1836 \fn void QTextCharFormat::setUnderlineColor(const QColor &color)-
1837-
1838 Sets the underline color used for the characters with this format to-
1839 the \a color specified.-
1840-
1841 \sa underlineColor()-
1842*/-
1843-
1844/*!-
1845 \fn QColor QTextCharFormat::underlineColor() const-
1846-
1847 Returns the color used to underline the characters with this format.-
1848-
1849 \sa setUnderlineColor()-
1850*/-
1851-
1852/*!-
1853 \fn void QTextCharFormat::setVerticalAlignment(VerticalAlignment alignment)-
1854-
1855 Sets the vertical alignment used for the characters with this format to-
1856 the \a alignment specified.-
1857-
1858 \sa verticalAlignment()-
1859*/-
1860-
1861/*!-
1862 \fn VerticalAlignment QTextCharFormat::verticalAlignment() const-
1863-
1864 Returns the vertical alignment used for characters with this format.-
1865-
1866 \sa setVerticalAlignment()-
1867*/-
1868-
1869/*!-
1870 \enum QTextCharFormat::FontPropertiesInheritanceBehavior-
1871 \since 5.3-
1872-
1873 This enum specifies how the setFont() function should behave with-
1874 respect to unset font properties.-
1875-
1876 \value FontPropertiesSpecifiedOnly If a property is not explicitly set, do not-
1877 change the text format's property value.-
1878 \value FontPropertiesAll If a property is not explicitly set, override the-
1879 text format's property with a default value.-
1880-
1881 \sa setFont()-
1882*/-
1883-
1884/*!-
1885 \overload-
1886-
1887 Sets the text format's \a font.-
1888-
1889 \sa font()-
1890*/-
1891void QTextCharFormat::setFont(const QFont &font)-
1892{-
1893 setFont(font, FontPropertiesAll);-
1894}-
1895-
1896/*!-
1897 \since 5.3-
1898-
1899 Sets the text format's \a font.-
1900-
1901 If \a behavior is QTextCharFormat::FontPropertiesAll, the font property that-
1902 has not been explicitly set is treated like as it were set with default value;-
1903 If \a behavior is QTextCharFormat::FontPropertiesSpecifiedOnly, the font property that-
1904 has not been explicitly set is ignored and the respective property value-
1905 remains unchanged.-
1906-
1907 \sa font()-
1908*/-
1909void QTextCharFormat::setFont(const QFont &font, FontPropertiesInheritanceBehavior behavior)-
1910{-
1911 const uint mask = behavior == FontPropertiesAll ? uint(QFont::AllPropertiesResolved)-
1912 : font.resolve();-
1913-
1914 if (mask & QFont::FamilyResolved)-
1915 setFontFamily(font.family());-
1916 if (mask & QFont::SizeResolved) {-
1917 const qreal pointSize = font.pointSizeF();-
1918 if (pointSize > 0) {-
1919 setFontPointSize(pointSize);-
1920 } else {-
1921 const int pixelSize = font.pixelSize();-
1922 if (pixelSize > 0)-
1923 setProperty(QTextFormat::FontPixelSize, pixelSize);-
1924 }-
1925 }-
1926-
1927 if (mask & QFont::WeightResolved)-
1928 setFontWeight(font.weight());-
1929 if (mask & QFont::StyleResolved)-
1930 setFontItalic(font.style() != QFont::StyleNormal);-
1931 if (mask & QFont::UnderlineResolved)-
1932 setUnderlineStyle(font.underline() ? SingleUnderline : NoUnderline);-
1933 if (mask & QFont::OverlineResolved)-
1934 setFontOverline(font.overline());-
1935 if (mask & QFont::StrikeOutResolved)-
1936 setFontStrikeOut(font.strikeOut());-
1937 if (mask & QFont::FixedPitchResolved)-
1938 setFontFixedPitch(font.fixedPitch());-
1939 if (mask & QFont::CapitalizationResolved)-
1940 setFontCapitalization(font.capitalization());-
1941 if (mask & QFont::WordSpacingResolved)-
1942 setFontWordSpacing(font.wordSpacing());-
1943 if (mask & QFont::LetterSpacingResolved) {-
1944 setFontLetterSpacingType(font.letterSpacingType());-
1945 setFontLetterSpacing(font.letterSpacing());-
1946 }-
1947 if (mask & QFont::StretchResolved)-
1948 setFontStretch(font.stretch());-
1949 if (mask & QFont::StyleHintResolved)-
1950 setFontStyleHint(font.styleHint());-
1951 if (mask & QFont::StyleStrategyResolved)-
1952 setFontStyleStrategy(font.styleStrategy());-
1953 if (mask & QFont::HintingPreferenceResolved)-
1954 setFontHintingPreference(font.hintingPreference());-
1955 if (mask & QFont::KerningResolved)-
1956 setFontKerning(font.kerning());-
1957}-
1958-
1959/*!-
1960 Returns the font for this character format.-
1961*/-
1962QFont QTextCharFormat::font() const-
1963{-
1964 return d ? d->font() : QFont();-
1965}-
1966-
1967/*!-
1968 \class QTextBlockFormat-
1969 \reentrant-
1970-
1971 \brief The QTextBlockFormat class provides formatting information for-
1972 blocks of text in a QTextDocument.-
1973 \inmodule QtGui-
1974-
1975 \ingroup richtext-processing-
1976 \ingroup shared-
1977-
1978 A document is composed of a list of blocks, represented by QTextBlock-
1979 objects. Each block can contain an item of some kind, such as a-
1980 paragraph of text, a table, a list, or an image. Every block has an-
1981 associated QTextBlockFormat that specifies its characteristics.-
1982-
1983 To cater for left-to-right and right-to-left languages you can set-
1984 a block's direction with setDirection(). Paragraph alignment is-
1985 set with setAlignment(). Margins are controlled by setTopMargin(),-
1986 setBottomMargin(), setLeftMargin(), setRightMargin(). Overall-
1987 indentation is set with setIndent(), the indentation of the first-
1988 line with setTextIndent().-
1989-
1990 Line spacing is set with setLineHeight() and retrieved via lineHeight()-
1991 and lineHeightType(). The types of line spacing available are in the-
1992 LineHeightTypes enum.-
1993-
1994 Line breaking can be enabled and disabled with setNonBreakableLines().-
1995-
1996 The brush used to paint the paragraph's background-
1997 is set with \l{QTextFormat::setBackground()}{setBackground()}, and other-
1998 aspects of the text's appearance can be customized by using the-
1999 \l{QTextFormat::setProperty()}{setProperty()} function with the-
2000 \c OutlinePen, \c ForegroundBrush, and \c BackgroundBrush-
2001 \l{QTextFormat::Property} values.-
2002-
2003 If a text block is part of a list, it can also have a list format that-
2004 is accessible with the listFormat() function.-
2005-
2006 \sa QTextBlock, QTextCharFormat-
2007*/-
2008-
2009/*!-
2010 \since 4.8-
2011 \enum QTextBlockFormat::LineHeightTypes-
2012-
2013 This enum describes the various types of line spacing support paragraphs can have.-
2014-
2015 \value SingleHeight This is the default line height: single spacing.-
2016 \value ProportionalHeight This sets the spacing proportional to the line (in percentage).-
2017 For example, set to 200 for double spacing.-
2018 \value FixedHeight This sets the line height to a fixed line height (in pixels).-
2019 \value MinimumHeight This sets the minimum line height (in pixels).-
2020 \value LineDistanceHeight This adds the specified height between lines (in pixels).-
2021-
2022 \sa lineHeight(), lineHeightType(), setLineHeight()-
2023*/-
2024-
2025/*!-
2026 \fn QTextBlockFormat::QTextBlockFormat()-
2027-
2028 Constructs a new QTextBlockFormat.-
2029*/-
2030QTextBlockFormat::QTextBlockFormat() : QTextFormat(BlockFormat) {}-
2031-
2032/*!-
2033 \internal-
2034 \fn QTextBlockFormat::QTextBlockFormat(const QTextFormat &other)-
2035-
2036 Creates a new block format with the same attributes as the \a given-
2037 text format.-
2038*/-
2039QTextBlockFormat::QTextBlockFormat(const QTextFormat &fmt)-
2040 : QTextFormat(fmt)-
2041{-
2042}-
2043-
2044/*!-
2045 \since 4.4-
2046 Sets the tab positions for the text block to those specified by-
2047 \a tabs.-
2048-
2049 \sa tabPositions()-
2050*/-
2051void QTextBlockFormat::setTabPositions(const QList<QTextOption::Tab> &tabs)-
2052{-
2053 QList<QVariant> list;-
2054 list.reserve(tabs.count());-
2055 QList<QTextOption::Tab>::ConstIterator iter = tabs.constBegin();-
2056 while (iter != tabs.constEnd()) {-
2057 QVariant v;-
2058 v.setValue<QTextOption::Tab>(*iter);-
2059 list.append(v);-
2060 ++iter;-
2061 }-
2062 setProperty(TabPositions, list);-
2063}-
2064-
2065/*!-
2066 \since 4.4-
2067 Returns a list of tab positions defined for the text block.-
2068-
2069 \sa setTabPositions()-
2070*/-
2071QList<QTextOption::Tab> QTextBlockFormat::tabPositions() const-
2072{-
2073 QVariant variant = property(TabPositions);-
2074 if(variant.isNull())-
2075 return QList<QTextOption::Tab>();-
2076 QList<QTextOption::Tab> answer;-
2077 QList<QVariant> variantsList = qvariant_cast<QList<QVariant> >(variant);-
2078 QList<QVariant>::Iterator iter = variantsList.begin();-
2079 answer.reserve(variantsList.count());-
2080 while(iter != variantsList.end()) {-
2081 answer.append( qvariant_cast<QTextOption::Tab>(*iter));-
2082 ++iter;-
2083 }-
2084 return answer;-
2085}-
2086-
2087/*!-
2088 \fn QTextBlockFormat::isValid() const-
2089-
2090 Returns \c true if this block format is valid; otherwise returns-
2091 false.-
2092*/-
2093-
2094/*!-
2095 \fn void QTextFormat::setLayoutDirection(Qt::LayoutDirection direction)-
2096-
2097 Sets the document's layout direction to the specified \a direction.-
2098-
2099 \sa layoutDirection()-
2100*/-
2101-
2102-
2103/*!-
2104 \fn Qt::LayoutDirection QTextFormat::layoutDirection() const-
2105-
2106 Returns the document's layout direction.-
2107-
2108 \sa setLayoutDirection()-
2109*/-
2110-
2111-
2112/*!-
2113 \fn void QTextBlockFormat::setAlignment(Qt::Alignment alignment)-
2114-
2115 Sets the paragraph's \a alignment.-
2116-
2117 \sa alignment()-
2118*/-
2119-
2120-
2121/*!-
2122 \fn Qt::Alignment QTextBlockFormat::alignment() const-
2123-
2124 Returns the paragraph's alignment.-
2125-
2126 \sa setAlignment()-
2127*/-
2128-
2129-
2130/*!-
2131 \fn void QTextBlockFormat::setTopMargin(qreal margin)-
2132-
2133 Sets the paragraph's top \a margin.-
2134-
2135 \sa topMargin(), setBottomMargin(), setLeftMargin(), setRightMargin()-
2136*/-
2137-
2138-
2139/*!-
2140 \fn qreal QTextBlockFormat::topMargin() const-
2141-
2142 Returns the paragraph's top margin.-
2143-
2144 \sa setTopMargin(), bottomMargin()-
2145*/-
2146-
2147-
2148/*!-
2149 \fn void QTextBlockFormat::setBottomMargin(qreal margin)-
2150-
2151 Sets the paragraph's bottom \a margin.-
2152-
2153 \sa bottomMargin(), setTopMargin(), setLeftMargin(), setRightMargin()-
2154*/-
2155-
2156-
2157/*!-
2158 \fn qreal QTextBlockFormat::bottomMargin() const-
2159-
2160 Returns the paragraph's bottom margin.-
2161-
2162 \sa setBottomMargin(), topMargin()-
2163*/-
2164-
2165-
2166/*!-
2167 \fn void QTextBlockFormat::setLeftMargin(qreal margin)-
2168-
2169 Sets the paragraph's left \a margin. Indentation can be applied separately-
2170 with setIndent().-
2171-
2172 \sa leftMargin(), setRightMargin(), setTopMargin(), setBottomMargin()-
2173*/-
2174-
2175-
2176/*!-
2177 \fn qreal QTextBlockFormat::leftMargin() const-
2178-
2179 Returns the paragraph's left margin.-
2180-
2181 \sa setLeftMargin(), rightMargin(), indent()-
2182*/-
2183-
2184-
2185/*!-
2186 \fn void QTextBlockFormat::setRightMargin(qreal margin)-
2187-
2188 Sets the paragraph's right \a margin.-
2189-
2190 \sa rightMargin(), setLeftMargin(), setTopMargin(), setBottomMargin()-
2191*/-
2192-
2193-
2194/*!-
2195 \fn qreal QTextBlockFormat::rightMargin() const-
2196-
2197 Returns the paragraph's right margin.-
2198-
2199 \sa setRightMargin(), leftMargin()-
2200*/-
2201-
2202-
2203/*!-
2204 \fn void QTextBlockFormat::setTextIndent(qreal indent)-
2205-
2206 Sets the \a indent for the first line in the block. This allows the first-
2207 line of a paragraph to be indented differently to the other lines,-
2208 enhancing the readability of the text.-
2209-
2210 \sa textIndent(), setLeftMargin(), setRightMargin(), setTopMargin(), setBottomMargin()-
2211*/-
2212-
2213-
2214/*!-
2215 \fn qreal QTextBlockFormat::textIndent() const-
2216-
2217 Returns the paragraph's text indent.-
2218-
2219 \sa setTextIndent()-
2220*/-
2221-
2222-
2223/*!-
2224 \fn void QTextBlockFormat::setIndent(int indentation)-
2225-
2226 Sets the paragraph's \a indentation. Margins are set independently of-
2227 indentation with setLeftMargin() and setTextIndent().-
2228 The \a indentation is an integer that is multiplied with the document-wide-
2229 standard indent, resulting in the actual indent of the paragraph.-
2230-
2231 \sa indent(), QTextDocument::indentWidth()-
2232*/-
2233-
2234-
2235/*!-
2236 \fn int QTextBlockFormat::indent() const-
2237-
2238 Returns the paragraph's indent.-
2239-
2240 \sa setIndent()-
2241*/-
2242-
2243-
2244/*!-
2245 \fn void QTextBlockFormat::setLineHeight(qreal height, int heightType)-
2246 \since 4.8-
2247-
2248 Sets the line height for the paragraph to the value given by \a height-
2249 which is dependent on \a heightType in the way described by the-
2250 LineHeightTypes enum.-
2251-
2252 \sa LineHeightTypes, lineHeight(), lineHeightType()-
2253*/-
2254-
2255-
2256/*!-
2257 \fn qreal QTextBlockFormat::lineHeight(qreal scriptLineHeight, qreal scaling) const-
2258 \since 4.8-
2259-
2260 Returns the height of the lines in the paragraph based on the height of the-
2261 script line given by \a scriptLineHeight and the specified \a scaling-
2262 factor.-
2263-
2264 The value that is returned is also dependent on the given LineHeightType of-
2265 the paragraph as well as the LineHeight setting that has been set for the-
2266 paragraph.-
2267-
2268 The scaling is needed for heights that include a fixed number of pixels, to-
2269 scale them appropriately for printing.-
2270-
2271 \sa LineHeightTypes, setLineHeight(), lineHeightType()-
2272*/-
2273-
2274-
2275/*!-
2276 \fn qreal QTextBlockFormat::lineHeight() const-
2277 \since 4.8-
2278-
2279 This returns the LineHeight property for the paragraph.-
2280-
2281 \sa LineHeightTypes, setLineHeight(), lineHeightType()-
2282*/-
2283-
2284-
2285/*!-
2286 \fn qreal QTextBlockFormat::lineHeightType() const-
2287 \since 4.8-
2288-
2289 This returns the LineHeightType property of the paragraph.-
2290-
2291 \sa LineHeightTypes, setLineHeight(), lineHeight()-
2292*/-
2293-
2294-
2295/*!-
2296 \fn void QTextBlockFormat::setNonBreakableLines(bool b)-
2297-
2298 If \a b is true, the lines in the paragraph are treated as-
2299 non-breakable; otherwise they are breakable.-
2300-
2301 \sa nonBreakableLines()-
2302*/-
2303-
2304-
2305/*!-
2306 \fn bool QTextBlockFormat::nonBreakableLines() const-
2307-
2308 Returns \c true if the lines in the paragraph are non-breakable;-
2309 otherwise returns \c false.-
2310-
2311 \sa setNonBreakableLines()-
2312*/-
2313-
2314/*!-
2315 \fn QTextFormat::PageBreakFlags QTextBlockFormat::pageBreakPolicy() const-
2316 \since 4.2-
2317-
2318 Returns the currently set page break policy for the paragraph. The default is-
2319 QTextFormat::PageBreak_Auto.-
2320-
2321 \sa setPageBreakPolicy()-
2322*/-
2323-
2324/*!-
2325 \fn void QTextBlockFormat::setPageBreakPolicy(PageBreakFlags policy)-
2326 \since 4.2-
2327-
2328 Sets the page break policy for the paragraph to \a policy.-
2329-
2330 \sa pageBreakPolicy()-
2331*/-
2332-
2333/*!-
2334 \class QTextListFormat-
2335 \reentrant-
2336-
2337 \brief The QTextListFormat class provides formatting information for-
2338 lists in a QTextDocument.-
2339 \inmodule QtGui-
2340-
2341 \ingroup richtext-processing-
2342 \ingroup shared-
2343-
2344 A list is composed of one or more items, represented as text blocks.-
2345 The list's format specifies the appearance of items in the list.-
2346 In particular, it determines the indentation and the style of each item.-
2347-
2348 The indentation of the items is an integer value that causes each item to-
2349 be offset from the left margin by a certain amount. This value is read with-
2350 indent() and set with setIndent().-
2351-
2352 The style used to decorate each item is set with setStyle() and can be read-
2353 with the style() function. The style controls the type of bullet points and-
2354 numbering scheme used for items in the list. Note that lists that use the-
2355 decimal numbering scheme begin counting at 1 rather than 0.-
2356-
2357 Style properties can be set to further configure the appearance of list-
2358 items; for example, the ListNumberPrefix and ListNumberSuffix properties-
2359 can be used to customize the numbers used in an ordered list so that they-
2360 appear as (1), (2), (3), etc.:-
2361-
2362 \snippet textdocument-listitemstyles/mainwindow.cpp add a styled, ordered list-
2363-
2364 \sa QTextList-
2365*/-
2366-
2367/*!-
2368 \enum QTextListFormat::Style-
2369-
2370 This enum describes the symbols used to decorate list items:-
2371-
2372 \value ListDisc a filled circle-
2373 \value ListCircle an empty circle-
2374 \value ListSquare a filled square-
2375 \value ListDecimal decimal values in ascending order-
2376 \value ListLowerAlpha lower case Latin characters in alphabetical order-
2377 \value ListUpperAlpha upper case Latin characters in alphabetical order-
2378 \value ListLowerRoman lower case roman numerals (supports up to 4999 items only)-
2379 \value ListUpperRoman upper case roman numerals (supports up to 4999 items only)-
2380 \omitvalue ListStyleUndefined-
2381*/-
2382-
2383/*!-
2384 \fn QTextListFormat::QTextListFormat()-
2385-
2386 Constructs a new list format object.-
2387*/-
2388QTextListFormat::QTextListFormat()-
2389 : QTextFormat(ListFormat)-
2390{-
2391 setIndent(1);-
2392}-
2393-
2394/*!-
2395 \internal-
2396 \fn QTextListFormat::QTextListFormat(const QTextFormat &other)-
2397-
2398 Creates a new list format with the same attributes as the \a given-
2399 text format.-
2400*/-
2401QTextListFormat::QTextListFormat(const QTextFormat &fmt)-
2402 : QTextFormat(fmt)-
2403{-
2404}-
2405-
2406/*!-
2407 \fn bool QTextListFormat::isValid() const-
2408-
2409 Returns \c true if this list format is valid; otherwise-
2410 returns \c false.-
2411*/-
2412-
2413/*!-
2414 \fn void QTextListFormat::setStyle(Style style)-
2415-
2416 Sets the list format's \a style.-
2417-
2418 \sa style(), Style-
2419*/-
2420-
2421/*!-
2422 \fn Style QTextListFormat::style() const-
2423-
2424 Returns the list format's style.-
2425-
2426 \sa setStyle(), Style-
2427*/-
2428-
2429-
2430/*!-
2431 \fn void QTextListFormat::setIndent(int indentation)-
2432-
2433 Sets the list format's \a indentation.-
2434 The indentation is multiplied by the QTextDocument::indentWidth-
2435 property to get the effective indent in pixels.-
2436-
2437 \sa indent()-
2438*/-
2439-
2440-
2441/*!-
2442 \fn int QTextListFormat::indent() const-
2443-
2444 Returns the list format's indentation.-
2445 The indentation is multiplied by the QTextDocument::indentWidth-
2446 property to get the effective indent in pixels.-
2447-
2448 \sa setIndent()-
2449*/-
2450-
2451/*!-
2452 \fn void QTextListFormat::setNumberPrefix(const QString &numberPrefix)-
2453 \since 4.8-
2454-
2455 Sets the list format's number prefix to the string specified by-
2456 \a numberPrefix. This can be used with all sorted list types. It does not-
2457 have any effect on unsorted list types.-
2458-
2459 The default prefix is an empty string.-
2460-
2461 \sa numberPrefix()-
2462*/-
2463-
2464/*!-
2465 \fn int QTextListFormat::numberPrefix() const-
2466 \since 4.8-
2467-
2468 Returns the list format's number prefix.-
2469-
2470 \sa setNumberPrefix()-
2471*/-
2472-
2473/*!-
2474 \fn void QTextListFormat::setNumberSuffix(const QString &numberSuffix)-
2475 \since 4.8-
2476-
2477 Sets the list format's number suffix to the string specified by-
2478 \a numberSuffix. This can be used with all sorted list types. It does not-
2479 have any effect on unsorted list types.-
2480-
2481 The default suffix is ".".-
2482-
2483 \sa numberSuffix()-
2484*/-
2485-
2486/*!-
2487 \fn int QTextListFormat::numberSuffix() const-
2488 \since 4.8-
2489-
2490 Returns the list format's number suffix.-
2491-
2492 \sa setNumberSuffix()-
2493*/-
2494-
2495/*!-
2496 \class QTextFrameFormat-
2497 \reentrant-
2498-
2499 \brief The QTextFrameFormat class provides formatting information for-
2500 frames in a QTextDocument.-
2501 \inmodule QtGui-
2502-
2503 \ingroup richtext-processing-
2504 \ingroup shared-
2505-
2506 A text frame groups together one or more blocks of text, providing a layer-
2507 of structure larger than the paragraph. The format of a frame specifies-
2508 how it is rendered and positioned on the screen. It does not directly-
2509 specify the behavior of the text formatting within, but provides-
2510 constraints on the layout of its children.-
2511-
2512 The frame format defines the width() and height() of the frame on the-
2513 screen. Each frame can have a border() that surrounds its contents with-
2514 a rectangular box. The border is surrounded by a margin() around the frame,-
2515 and the contents of the frame are kept separate from the border by the-
2516 frame's padding(). This scheme is similar to the box model used by Cascading-
2517 Style Sheets for HTML pages.-
2518-
2519 \image qtextframe-style.png-
2520-
2521 The position() of a frame is set using setPosition() and determines how it-
2522 is located relative to the surrounding text.-
2523-
2524 The validity of a QTextFrameFormat object can be determined with the-
2525 isValid() function.-
2526-
2527 \sa QTextFrame, QTextBlockFormat-
2528*/-
2529-
2530/*!-
2531 \enum QTextFrameFormat::Position-
2532-
2533 This enum describes how a frame is located relative to the surrounding text.-
2534-
2535 \value InFlow-
2536 \value FloatLeft-
2537 \value FloatRight-
2538-
2539 \sa position(), CssFloat-
2540*/-
2541-
2542/*!-
2543 \enum QTextFrameFormat::BorderStyle-
2544 \since 4.3-
2545-
2546 This enum describes different border styles for the text frame.-
2547-
2548 \value BorderStyle_None-
2549 \value BorderStyle_Dotted-
2550 \value BorderStyle_Dashed-
2551 \value BorderStyle_Solid-
2552 \value BorderStyle_Double-
2553 \value BorderStyle_DotDash-
2554 \value BorderStyle_DotDotDash-
2555 \value BorderStyle_Groove-
2556 \value BorderStyle_Ridge-
2557 \value BorderStyle_Inset-
2558 \value BorderStyle_Outset-
2559-
2560 \sa borderStyle(), FrameBorderStyle-
2561*/-
2562-
2563/*!-
2564 \fn QTextFrameFormat::QTextFrameFormat()-
2565-
2566 Constructs a text frame format object with the default properties.-
2567*/-
2568QTextFrameFormat::QTextFrameFormat() : QTextFormat(FrameFormat)-
2569{-
2570 setBorderStyle(BorderStyle_Outset);-
2571 setBorderBrush(Qt::darkGray);-
2572}-
2573-
2574/*!-
2575 \internal-
2576 \fn QTextFrameFormat::QTextFrameFormat(const QTextFormat &other)-
2577-
2578 Creates a new frame format with the same attributes as the \a given-
2579 text format.-
2580*/-
2581QTextFrameFormat::QTextFrameFormat(const QTextFormat &fmt)-
2582 : QTextFormat(fmt)-
2583{-
2584}-
2585-
2586/*!-
2587 \fn QTextFrameFormat::isValid() const-
2588-
2589 Returns \c true if the format description is valid; otherwise returns \c false.-
2590*/-
2591-
2592/*!-
2593 \fn QTextFrameFormat::setPosition(Position policy)-
2594-
2595 Sets the \a policy for positioning frames with this frame format.-
2596-
2597*/-
2598-
2599/*!-
2600 \fn Position QTextFrameFormat::position() const-
2601-
2602 Returns the positioning policy for frames with this frame format.-
2603*/-
2604-
2605/*!-
2606 \fn QTextFrameFormat::setBorder(qreal width)-
2607-
2608 Sets the \a width (in pixels) of the frame's border.-
2609*/-
2610-
2611/*!-
2612 \fn qreal QTextFrameFormat::border() const-
2613-
2614 Returns the width of the border in pixels.-
2615*/-
2616-
2617/*!-
2618 \fn QTextFrameFormat::setBorderBrush(const QBrush &brush)-
2619 \since 4.3-
2620-
2621 Sets the \a brush used for the frame's border.-
2622*/-
2623-
2624/*!-
2625 \fn QBrush QTextFrameFormat::borderBrush() const-
2626 \since 4.3-
2627-
2628 Returns the brush used for the frame's border.-
2629*/-
2630-
2631/*!-
2632 \fn QTextFrameFormat::setBorderStyle(BorderStyle style)-
2633 \since 4.3-
2634-
2635 Sets the \a style of the frame's border.-
2636*/-
2637-
2638/*!-
2639 \fn BorderStyle QTextFrameFormat::borderStyle() const-
2640 \since 4.3-
2641-
2642 Returns the style of the frame's border.-
2643*/-
2644-
2645/*!-
2646 \fn QTextFrameFormat::setMargin(qreal margin)-
2647-
2648 Sets the frame's \a margin in pixels.-
2649 This method also sets the left, right, top and bottom margins-
2650 of the frame to the same value. The individual margins override-
2651 the general margin.-
2652*/-
2653void QTextFrameFormat::setMargin(qreal amargin)-
2654{-
2655 setProperty(FrameMargin, amargin);-
2656 setProperty(FrameTopMargin, amargin);-
2657 setProperty(FrameBottomMargin, amargin);-
2658 setProperty(FrameLeftMargin, amargin);-
2659 setProperty(FrameRightMargin, amargin);-
2660}-
2661-
2662-
2663/*!-
2664 \fn qreal QTextFrameFormat::margin() const-
2665-
2666 Returns the width of the frame's external margin in pixels.-
2667*/-
2668-
2669/*!-
2670 \fn QTextFrameFormat::setTopMargin(qreal margin)-
2671 \since 4.3-
2672-
2673 Sets the frame's top \a margin in pixels.-
2674*/-
2675-
2676/*!-
2677 \fn qreal QTextFrameFormat::topMargin() const-
2678 \since 4.3-
2679-
2680 Returns the width of the frame's top margin in pixels.-
2681*/-
2682qreal QTextFrameFormat::topMargin() const-
2683{-
2684 if (!hasProperty(FrameTopMargin))-
2685 return margin();-
2686 return doubleProperty(FrameTopMargin);-
2687}-
2688-
2689/*!-
2690 \fn QTextFrameFormat::setBottomMargin(qreal margin)-
2691 \since 4.3-
2692-
2693 Sets the frame's bottom \a margin in pixels.-
2694*/-
2695-
2696/*!-
2697 \fn qreal QTextFrameFormat::bottomMargin() const-
2698 \since 4.3-
2699-
2700 Returns the width of the frame's bottom margin in pixels.-
2701*/-
2702qreal QTextFrameFormat::bottomMargin() const-
2703{-
2704 if (!hasProperty(FrameBottomMargin))-
2705 return margin();-
2706 return doubleProperty(FrameBottomMargin);-
2707}-
2708-
2709/*!-
2710 \fn QTextFrameFormat::setLeftMargin(qreal margin)-
2711 \since 4.3-
2712-
2713 Sets the frame's left \a margin in pixels.-
2714*/-
2715-
2716/*!-
2717 \fn qreal QTextFrameFormat::leftMargin() const-
2718 \since 4.3-
2719-
2720 Returns the width of the frame's left margin in pixels.-
2721*/-
2722qreal QTextFrameFormat::leftMargin() const-
2723{-
2724 if (!hasProperty(FrameLeftMargin))-
2725 return margin();-
2726 return doubleProperty(FrameLeftMargin);-
2727}-
2728-
2729/*!-
2730 \fn QTextFrameFormat::setRightMargin(qreal margin)-
2731 \since 4.3-
2732-
2733 Sets the frame's right \a margin in pixels.-
2734*/-
2735-
2736/*!-
2737 \fn qreal QTextFrameFormat::rightMargin() const-
2738 \since 4.3-
2739-
2740 Returns the width of the frame's right margin in pixels.-
2741*/-
2742qreal QTextFrameFormat::rightMargin() const-
2743{-
2744 if (!hasProperty(FrameRightMargin))-
2745 return margin();-
2746 return doubleProperty(FrameRightMargin);-
2747}-
2748-
2749/*!-
2750 \fn QTextFrameFormat::setPadding(qreal width)-
2751-
2752 Sets the \a width of the frame's internal padding in pixels.-
2753*/-
2754-
2755/*!-
2756 \fn qreal QTextFrameFormat::padding() const-
2757-
2758 Returns the width of the frame's internal padding in pixels.-
2759*/-
2760-
2761/*!-
2762 \fn QTextFrameFormat::setWidth(const QTextLength &width)-
2763-
2764 Sets the frame's border rectangle's \a width.-
2765-
2766 \sa QTextLength-
2767*/-
2768-
2769/*!-
2770 \fn QTextFrameFormat::setWidth(qreal width)-
2771 \overload-
2772-
2773 Convenience method that sets the width of the frame's border-
2774 rectangle's width to the specified fixed \a width.-
2775*/-
2776-
2777/*!-
2778 \fn QTextFormat::PageBreakFlags QTextFrameFormat::pageBreakPolicy() const-
2779 \since 4.2-
2780-
2781 Returns the currently set page break policy for the frame/table. The default is-
2782 QTextFormat::PageBreak_Auto.-
2783-
2784 \sa setPageBreakPolicy()-
2785*/-
2786-
2787/*!-
2788 \fn void QTextFrameFormat::setPageBreakPolicy(PageBreakFlags policy)-
2789 \since 4.2-
2790-
2791 Sets the page break policy for the frame/table to \a policy.-
2792-
2793 \sa pageBreakPolicy()-
2794*/-
2795-
2796/*!-
2797 \fn QTextLength QTextFrameFormat::width() const-
2798-
2799 Returns the width of the frame's border rectangle.-
2800-
2801 \sa QTextLength-
2802*/-
2803-
2804/*!-
2805 \fn void QTextFrameFormat::setHeight(const QTextLength &height)-
2806-
2807 Sets the frame's \a height.-
2808*/-
2809-
2810/*!-
2811 \fn void QTextFrameFormat::setHeight(qreal height)-
2812 \overload-
2813-
2814 Sets the frame's \a height.-
2815*/-
2816-
2817/*!-
2818 \fn qreal QTextFrameFormat::height() const-
2819-
2820 Returns the height of the frame's border rectangle.-
2821*/-
2822-
2823/*!-
2824 \class QTextTableFormat-
2825 \reentrant-
2826-
2827 \brief The QTextTableFormat class provides formatting information for-
2828 tables in a QTextDocument.-
2829 \inmodule QtGui-
2830-
2831 \ingroup richtext-processing-
2832 \ingroup shared-
2833-
2834 A table is a group of cells ordered into rows and columns. Each table-
2835 contains at least one row and one column. Each cell contains a block.-
2836 Tables in rich text documents are formatted using the properties-
2837 defined in this class.-
2838-
2839 Tables are horizontally justified within their parent frame according to the-
2840 table's alignment. This can be read with the alignment() function and set-
2841 with setAlignment().-
2842-
2843 Cells within the table are separated by cell spacing. The number of pixels-
2844 between cells is set with setCellSpacing() and read with cellSpacing().-
2845 The contents of each cell is surrounded by cell padding. The number of pixels-
2846 between each cell edge and its contents is set with setCellPadding() and read-
2847 with cellPadding().-
2848-
2849 \image qtexttableformat-cell.png-
2850-
2851 The table's background color can be read with the background() function,-
2852 and can be specified with setBackground(). The background color of each-
2853 cell can be set independently, and will control the color of the cell within-
2854 the padded area.-
2855-
2856 The table format also provides a way to constrain the widths of the columns-
2857 in the table. Columns can be assigned a fixed width, a variable width, or-
2858 a percentage of the available width (see QTextLength). The columns() function-
2859 returns the number of columns with constraints, and the-
2860 columnWidthConstraints() function returns the constraints defined for the-
2861 table. These quantities can also be set by calling setColumnWidthConstraints()-
2862 with a vector containing new constraints. If no constraints are-
2863 required, clearColumnWidthConstraints() can be used to remove them.-
2864-
2865 \sa QTextTable, QTextTableCell, QTextLength-
2866*/-
2867-
2868/*!-
2869 \fn QTextTableFormat::QTextTableFormat()-
2870-
2871 Constructs a new table format object.-
2872*/-
2873QTextTableFormat::QTextTableFormat()-
2874 : QTextFrameFormat()-
2875{-
2876 setObjectType(TableObject);-
2877 setCellSpacing(2);-
2878 setBorder(1);-
2879}-
2880-
2881/*!-
2882 \internal-
2883 \fn QTextTableFormat::QTextTableFormat(const QTextFormat &other)-
2884-
2885 Creates a new table format with the same attributes as the \a given-
2886 text format.-
2887*/-
2888QTextTableFormat::QTextTableFormat(const QTextFormat &fmt)-
2889 : QTextFrameFormat(fmt)-
2890{-
2891}-
2892-
2893/*!-
2894 \fn bool QTextTableFormat::isValid() const-
2895-
2896 Returns \c true if this table format is valid; otherwise-
2897 returns \c false.-
2898*/-
2899-
2900-
2901/*!-
2902 \fn int QTextTableFormat::columns() const-
2903-
2904 Returns the number of columns specified by the table format.-
2905*/-
2906-
2907-
2908/*!-
2909 \internal-
2910 \fn void QTextTableFormat::setColumns(int columns)-
2911-
2912 Sets the number of \a columns required by the table format.-
2913-
2914 \sa columns()-
2915*/-
2916-
2917/*!-
2918 \fn void QTextTableFormat::clearColumnWidthConstraints()-
2919-
2920 Clears the column width constraints for the table.-
2921-
2922 \sa columnWidthConstraints(), setColumnWidthConstraints()-
2923*/-
2924-
2925/*!-
2926 \fn void QTextTableFormat::setColumnWidthConstraints(const QVector<QTextLength> &constraints)-
2927-
2928 Sets the column width \a constraints for the table.-
2929-
2930 \sa columnWidthConstraints(), clearColumnWidthConstraints()-
2931*/-
2932-
2933/*!-
2934 \fn QVector<QTextLength> QTextTableFormat::columnWidthConstraints() const-
2935-
2936 Returns a list of constraints used by this table format to control the-
2937 appearance of columns in a table.-
2938-
2939 \sa setColumnWidthConstraints()-
2940*/-
2941-
2942/*!-
2943 \fn qreal QTextTableFormat::cellSpacing() const-
2944-
2945 Returns the table's cell spacing. This describes the distance between-
2946 adjacent cells.-
2947*/-
2948-
2949/*!-
2950 \fn void QTextTableFormat::setCellSpacing(qreal spacing)-
2951-
2952 Sets the cell \a spacing for the table. This determines the distance-
2953 between adjacent cells.-
2954*/-
2955-
2956/*!-
2957 \fn qreal QTextTableFormat::cellPadding() const-
2958-
2959 Returns the table's cell padding. This describes the distance between-
2960 the border of a cell and its contents.-
2961*/-
2962-
2963/*!-
2964 \fn void QTextTableFormat::setCellPadding(qreal padding)-
2965-
2966 Sets the cell \a padding for the table. This determines the distance-
2967 between the border of a cell and its contents.-
2968*/-
2969-
2970/*!-
2971 \fn void QTextTableFormat::setAlignment(Qt::Alignment alignment)-
2972-
2973 Sets the table's \a alignment.-
2974-
2975 \sa alignment()-
2976*/-
2977-
2978/*!-
2979 \fn Qt::Alignment QTextTableFormat::alignment() const-
2980-
2981 Returns the table's alignment.-
2982-
2983 \sa setAlignment()-
2984*/-
2985-
2986/*!-
2987 \fn void QTextTableFormat::setHeaderRowCount(int count)-
2988 \since 4.2-
2989-
2990 Declares the first \a count rows of the table as table header.-
2991 The table header rows get repeated when a table is broken-
2992 across a page boundary.-
2993*/-
2994-
2995/*!-
2996 \fn int QTextTableFormat::headerRowCount() const-
2997 \since 4.2-
2998-
2999 Returns the number of rows in the table that define the header.-
3000-
3001 \sa setHeaderRowCount()-
3002*/-
3003-
3004/*!-
3005 \fn void QTextFormat::setBackground(const QBrush &brush)-
3006-
3007 Sets the brush use to paint the document's background to the-
3008 \a brush specified.-
3009-
3010 \sa background(), clearBackground(), setForeground()-
3011*/-
3012-
3013/*!-
3014 \fn QColor QTextFormat::background() const-
3015-
3016 Returns the brush used to paint the document's background.-
3017-
3018 \sa setBackground(), clearBackground(), foreground()-
3019*/-
3020-
3021/*!-
3022 \fn void QTextFormat::clearBackground()-
3023-
3024 Clears the brush used to paint the document's background. The default-
3025 brush will be used.-
3026-
3027 \sa background(), setBackground(), clearForeground()-
3028*/-
3029-
3030-
3031/*!-
3032 \class QTextImageFormat-
3033 \reentrant-
3034-
3035 \brief The QTextImageFormat class provides formatting information for-
3036 images in a QTextDocument.-
3037 \inmodule QtGui-
3038-
3039 \ingroup richtext-processing-
3040 \ingroup shared-
3041-
3042 Inline images are represented by a Unicode value U+FFFC (OBJECT-
3043 REPLACEMENT CHARACTER) which has an associated QTextImageFormat. The-
3044 image format specifies a name with setName() that is used to-
3045 locate the image. The size of the rectangle that the image will-
3046 occupy is specified using setWidth() and setHeight().-
3047-
3048 Images can be supplied in any format for which Qt has an image-
3049 reader, so SVG drawings can be included alongside PNG, TIFF and-
3050 other bitmap formats.-
3051-
3052 \sa QImage, QImageReader-
3053*/-
3054-
3055/*!-
3056 \fn QTextImageFormat::QTextImageFormat()-
3057-
3058 Creates a new image format object.-
3059*/-
3060QTextImageFormat::QTextImageFormat() : QTextCharFormat() { setObjectType(ImageObject); }-
3061-
3062/*!-
3063 \internal-
3064 \fn QTextImageFormat::QTextImageFormat(const QTextFormat &other)-
3065-
3066 Creates a new image format with the same attributes as the \a given-
3067 text format.-
3068*/-
3069QTextImageFormat::QTextImageFormat(const QTextFormat &fmt)-
3070 : QTextCharFormat(fmt)-
3071{-
3072}-
3073-
3074/*!-
3075 \fn bool QTextImageFormat::isValid() const-
3076-
3077 Returns \c true if this image format is valid; otherwise returns \c false.-
3078*/-
3079-
3080-
3081/*!-
3082 \fn void QTextImageFormat::setName(const QString &name)-
3083-
3084 Sets the \a name of the image. The \a name is used to locate the image-
3085 in the application's resources.-
3086-
3087 \sa name()-
3088*/-
3089-
3090-
3091/*!-
3092 \fn QString QTextImageFormat::name() const-
3093-
3094 Returns the name of the image. The name refers to an entry in the-
3095 application's resources file.-
3096-
3097 \sa setName()-
3098*/-
3099-
3100/*!-
3101 \fn void QTextImageFormat::setWidth(qreal width)-
3102-
3103 Sets the \a width of the rectangle occupied by the image.-
3104-
3105 \sa width(), setHeight()-
3106*/-
3107-
3108-
3109/*!-
3110 \fn qreal QTextImageFormat::width() const-
3111-
3112 Returns the width of the rectangle occupied by the image.-
3113-
3114 \sa height(), setWidth()-
3115*/-
3116-
3117-
3118/*!-
3119 \fn void QTextImageFormat::setHeight(qreal height)-
3120-
3121 Sets the \a height of the rectangle occupied by the image.-
3122-
3123 \sa height(), setWidth()-
3124*/-
3125-
3126-
3127/*!-
3128 \fn qreal QTextImageFormat::height() const-
3129-
3130 Returns the height of the rectangle occupied by the image.-
3131-
3132 \sa width(), setHeight()-
3133*/-
3134-
3135/*!-
3136 \fn void QTextCharFormat::setFontCapitalization(QFont::Capitalization capitalization)-
3137 \since 4.4-
3138-
3139 Sets the capitalization of the text that apppears in this font to \a capitalization.-
3140-
3141 A font's capitalization makes the text appear in the selected capitalization mode.-
3142-
3143 \sa fontCapitalization()-
3144*/-
3145-
3146/*!-
3147 \fn Capitalization QTextCharFormat::fontCapitalization() const-
3148 \since 4.4-
3149-
3150 Returns the current capitalization type of the font.-
3151*/-
3152-
3153/*!-
3154 \fn void QTextCharFormat::setFontLetterSpacingType(QFont::SpacingType letterSpacingType)-
3155 \since 5.0-
3156-
3157 Sets the letter spacing type of this format to \a letterSpacingType.-
3158-
3159 \sa fontLetterSpacingType()-
3160 \sa setFontLetterSpacing()-
3161 \sa fontLetterSpacing()-
3162*/-
3163-
3164/*!-
3165 \fn QFont::SpacingType QTextCharFormat::fontLetterSpacingType() const-
3166 \since 5.0-
3167-
3168 Returns the letter spacing type of this format..-
3169-
3170 \sa setFontLetterSpacingType()-
3171 \sa setFontLetterSpacing()-
3172 \sa fontLetterSpacing()-
3173*/-
3174-
3175/*!-
3176 \fn void QTextCharFormat::setFontLetterSpacing(qreal spacing)-
3177 \since 4.4-
3178-
3179 Sets the letter spacing of this format to the given \a spacing. The meaning of the value-
3180 depends on the font letter spacing type.-
3181-
3182 For percentage spacing a value of 100 indicates default spacing; a value of 200 doubles the-
3183 amount of space a letter takes.-
3184-
3185 \sa fontLetterSpacing()-
3186 \sa setFontLetterSpacingType()-
3187 \sa fontLetterSpacingType()-
3188*/-
3189-
3190/*!-
3191 \fn qreal QTextCharFormat::fontLetterSpacing() const-
3192 \since 4.4-
3193-
3194 Returns the current letter spacing.-
3195-
3196 \sa setFontLetterSpacing()-
3197 \sa setFontLetterSpacingType()-
3198 \sa fontLetterSpacingType()-
3199*/-
3200-
3201/*!-
3202 \fn void QTextCharFormat::setFontWordSpacing(qreal spacing)-
3203 \since 4.4-
3204-
3205 Sets the word spacing of this format to the given \a spacing, in pixels.-
3206-
3207 \sa fontWordSpacing()-
3208*/-
3209-
3210/*!-
3211 \fn qreal QTextCharFormat::fontWordSpacing() const-
3212 \since 4.4-
3213-
3214 Returns the current word spacing value.-
3215*/-
3216-
3217/*!-
3218 \fn void QTextCharFormat::setFontStretch(int factor)-
3219 \since 5.0-
3220-
3221 Sets the stretch factor for the font to \a factor.-
3222-
3223 The stretch factor changes the width of all characters in the font by factor percent. For example, setting \a factor to 150 results in all characters in the font being 1.5 times (ie. 150%) wider. The default stretch factor is 100. The minimum stretch factor is 1, and the maximum stretch factor is 4000.-
3224-
3225 The stretch factor is only applied to outline fonts. The stretch factor is ignored for bitmap fonts.-
3226-
3227 \sa fontStretch()-
3228*/-
3229-
3230/*!-
3231 \fn int QTextCharFormat::fontStretch() const-
3232 \since 5.0-
3233-
3234 Returns the current font stretching.-
3235 \sa setFontStretch()-
3236*/-
3237-
3238/*!-
3239 \fn qreal QTextTableCellFormat::topPadding() const-
3240 \since 4.4-
3241-
3242 Gets the top padding of the table cell.-
3243-
3244 \sa setTopPadding(), leftPadding(), rightPadding(), bottomPadding()-
3245*/-
3246-
3247/*!-
3248 \fn qreal QTextTableCellFormat::bottomPadding() const-
3249 \since 4.4-
3250-
3251 Gets the bottom padding of the table cell.-
3252-
3253 \sa setBottomPadding(), leftPadding(), rightPadding(), topPadding()-
3254*/-
3255-
3256/*!-
3257 \fn qreal QTextTableCellFormat::leftPadding() const-
3258 \since 4.4-
3259-
3260 Gets the left padding of the table cell.-
3261-
3262 \sa setLeftPadding(), rightPadding(), topPadding(), bottomPadding()-
3263*/-
3264-
3265/*!-
3266 \fn qreal QTextTableCellFormat::rightPadding() const-
3267 \since 4.4-
3268-
3269 Gets the right padding of the table cell.-
3270-
3271 \sa setRightPadding(), leftPadding(), topPadding(), bottomPadding()-
3272*/-
3273-
3274/*!-
3275 \fn void QTextTableCellFormat::setTopPadding(qreal padding)-
3276 \since 4.4-
3277-
3278 Sets the top \a padding of the table cell.-
3279-
3280 \sa topPadding(), setLeftPadding(), setRightPadding(), setBottomPadding()-
3281*/-
3282-
3283/*!-
3284 \fn void QTextTableCellFormat::setBottomPadding(qreal padding)-
3285 \since 4.4-
3286-
3287 Sets the bottom \a padding of the table cell.-
3288-
3289 \sa bottomPadding(), setLeftPadding(), setRightPadding(), setTopPadding()-
3290*/-
3291-
3292/*!-
3293 \fn void QTextTableCellFormat::setLeftPadding(qreal padding)-
3294 \since 4.4-
3295-
3296 Sets the left \a padding of the table cell.-
3297-
3298 \sa leftPadding(), setRightPadding(), setTopPadding(), setBottomPadding()-
3299*/-
3300-
3301/*!-
3302 \fn void QTextTableCellFormat::setRightPadding(qreal padding)-
3303 \since 4.4-
3304-
3305 Sets the right \a padding of the table cell.-
3306-
3307 \sa rightPadding(), setLeftPadding(), setTopPadding(), setBottomPadding()-
3308*/-
3309-
3310/*!-
3311 \fn void QTextTableCellFormat::setPadding(qreal padding)-
3312 \since 4.4-
3313-
3314 Sets the left, right, top, and bottom \a padding of the table cell.-
3315-
3316 \sa setLeftPadding(), setRightPadding(), setTopPadding(), setBottomPadding()-
3317*/-
3318-
3319/*!-
3320 \fn bool QTextTableCellFormat::isValid() const-
3321 \since 4.4-
3322-
3323 Returns \c true if this table cell format is valid; otherwise returns \c false.-
3324*/-
3325-
3326/*!-
3327 \fn QTextTableCellFormat::QTextTableCellFormat()-
3328 \since 4.4-
3329-
3330 Constructs a new table cell format object.-
3331*/-
3332QTextTableCellFormat::QTextTableCellFormat()-
3333 : QTextCharFormat()-
3334{-
3335 setObjectType(TableCellObject);-
3336}-
3337-
3338/*!-
3339 \internal-
3340 \fn QTextTableCellFormat::QTextTableCellFormat(const QTextFormat &other)-
3341-
3342 Creates a new table cell format with the same attributes as the \a given-
3343 text format.-
3344*/-
3345QTextTableCellFormat::QTextTableCellFormat(const QTextFormat &fmt)-
3346 : QTextCharFormat(fmt)-
3347{-
3348}-
3349-
3350/*!-
3351 \class QTextTableCellFormat-
3352 \reentrant-
3353 \since 4.4-
3354-
3355 \brief The QTextTableCellFormat class provides formatting information for-
3356 table cells in a QTextDocument.-
3357 \inmodule QtGui-
3358-
3359 \ingroup richtext-processing-
3360 \ingroup shared-
3361-
3362 The table cell format of a table cell in a document specifies the visual-
3363 properties of the table cell.-
3364-
3365 The padding properties of a table cell are controlled by setLeftPadding(),-
3366 setRightPadding(), setTopPadding(), and setBottomPadding(). All the paddings-
3367 can be set at once using setPadding().-
3368-
3369 \sa QTextFormat, QTextBlockFormat, QTextTableFormat, QTextCharFormat-
3370*/-
3371-
3372// -------------------------------------------------------
3373-
3374-
3375QTextFormatCollection::QTextFormatCollection(const QTextFormatCollection &rhs)-
3376{-
3377 formats = rhs.formats;-
3378 objFormats = rhs.objFormats;-
3379}-
3380-
3381QTextFormatCollection &QTextFormatCollection::operator=(const QTextFormatCollection &rhs)-
3382{-
3383 formats = rhs.formats;-
3384 objFormats = rhs.objFormats;-
3385 return *this;-
3386}-
3387-
3388QTextFormatCollection::~QTextFormatCollection()-
3389{-
3390}-
3391-
3392int QTextFormatCollection::indexForFormat(const QTextFormat &format)-
3393{-
3394 uint hash = getHash(format.d, format.format_type);-
3395 QMultiHash<uint, int>::const_iterator i = hashes.constFind(hash);-
3396 while (i != hashes.constEnd() && i.key() == hash) {-
3397 if (formats.value(i.value()) == format) {-
3398 return i.value();-
3399 }-
3400 ++i;-
3401 }-
3402-
3403 int idx = formats.size();-
3404 formats.append(format);-
3405-
3406 QT_TRY{-
3407 QTextFormat &f = formats.last();-
3408 if (!f.d)-
3409 f.d = new QTextFormatPrivate;-
3410 f.d->resolveFont(defaultFnt);-
3411-
3412 if (!hashes.contains(hash, idx))-
3413 hashes.insert(hash, idx);-
3414-
3415 } QT_CATCH(...) {
dead code: { formats.pop_back(); qt_noop(); }
-
3416 formats.pop_back();
dead code: { formats.pop_back(); qt_noop(); }
-
3417 QT_RETHROW;
dead code: { formats.pop_back(); qt_noop(); }
-
3418 }
dead code: { formats.pop_back(); qt_noop(); }
-
3419 return idx;-
3420}-
3421-
3422bool QTextFormatCollection::hasFormatCached(const QTextFormat &format) const-
3423{-
3424 uint hash = getHash(format.d, format.format_type);-
3425 QMultiHash<uint, int>::const_iterator i = hashes.constFind(hash);-
3426 while (i != hashes.constEnd() && i.key() == hash) {-
3427 if (formats.value(i.value()) == format) {-
3428 return true;-
3429 }-
3430 ++i;-
3431 }-
3432 return false;-
3433}-
3434-
3435int QTextFormatCollection::objectFormatIndex(int objectIndex) const-
3436{-
3437 if (objectIndex == -1)-
3438 return -1;-
3439 return objFormats.at(objectIndex);-
3440}-
3441-
3442void QTextFormatCollection::setObjectFormatIndex(int objectIndex, int formatIndex)-
3443{-
3444 objFormats[objectIndex] = formatIndex;-
3445}-
3446-
3447int QTextFormatCollection::createObjectIndex(const QTextFormat &f)-
3448{-
3449 const int objectIndex = objFormats.size();-
3450 objFormats.append(indexForFormat(f));-
3451 return objectIndex;-
3452}-
3453-
3454QTextFormat QTextFormatCollection::format(int idx) const-
3455{-
3456 if (idx < 0 || idx >= formats.count())-
3457 return QTextFormat();-
3458-
3459 return formats.at(idx);-
3460}-
3461-
3462void QTextFormatCollection::setDefaultFont(const QFont &f)-
3463{-
3464 defaultFnt = f;-
3465 for (int i = 0; i < formats.count(); ++i)
i < formats.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
3466 if (formats[.at(i].).d)
formats.at(i).dDescription
TRUEnever evaluated
FALSEnever evaluated
0
3467 formats[i].d->resolveFont(defaultFnt);
never executed: formats[i].d->resolveFont(defaultFnt);
0
3468}
never executed: end of block
0
3469-
3470#ifndef QT_NO_DEBUG_STREAM-
3471QDebug operator<<(QDebug dbg, const QTextLength &l)-
3472{-
3473 QDebugStateSaver saver(dbg);-
3474 dbg.nospace() << "QTextLength(QTextLength::Type(" << l.type() << "))";-
3475 return dbg;-
3476}-
3477-
3478QDebug operator<<(QDebug dbg, const QTextFormat &f)-
3479{-
3480 QDebugStateSaver saver(dbg);-
3481 dbg.nospace() << "QTextFormat(QTextFormat::FormatType(" << f.type() << "))";-
3482 return dbg;-
3483}-
3484-
3485#endif-
3486-
3487QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

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