Coverage Report

Created: 2026-10-14 08:19

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