1// Copyright (C) 2016 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#ifndef QTEXTFORMAT_P_H
5#define QTEXTFORMAT_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtGui/private/qtguiglobal_p.h>
19#include "QtGui/qtextformat.h"
20#include "QtCore/qlist.h"
21#include <QtCore/qhash.h> // QMultiHash
22
23QT_BEGIN_NAMESPACE
24
25class Q_GUI_EXPORT QTextFormatCollection
26{
27public:
28 QTextFormatCollection() {}
29 ~QTextFormatCollection();
30
31 void clear();
32
33 inline QTextFormat objectFormat(int objectIndex) const
34 { return format(idx: objectFormatIndex(objectIndex)); }
35 inline void setObjectFormat(int objectIndex, const QTextFormat &format)
36 { setObjectFormatIndex(objectIndex, formatIndex: indexForFormat(f: format)); }
37
38 int objectFormatIndex(int objectIndex) const;
39 void setObjectFormatIndex(int objectIndex, int formatIndex);
40
41 int createObjectIndex(const QTextFormat &f);
42
43 int indexForFormat(const QTextFormat &f);
44 bool hasFormatCached(const QTextFormat &format) const;
45
46 QTextFormat format(int idx) const;
47 inline QTextBlockFormat blockFormat(int index) const
48 { return format(idx: index).toBlockFormat(); }
49 inline QTextCharFormat charFormat(int index) const
50 { return format(idx: index).toCharFormat(); }
51 inline QTextListFormat listFormat(int index) const
52 { return format(idx: index).toListFormat(); }
53 inline QTextTableFormat tableFormat(int index) const
54 { return format(idx: index).toTableFormat(); }
55 inline QTextImageFormat imageFormat(int index) const
56 { return format(idx: index).toImageFormat(); }
57
58 inline int numFormats() const { return formats.size(); }
59
60 typedef QList<QTextFormat> FormatVector;
61
62 FormatVector formats;
63 QList<qint32> objFormats;
64 QMultiHash<size_t,int> hashes;
65
66 inline QFont defaultFont() const { return defaultFnt; }
67 void setDefaultFont(const QFont &f);
68
69 inline void setSuperScriptBaseline(qreal baseline) { defaultFormat.setSuperScriptBaseline(baseline); }
70 inline void setSubScriptBaseline(qreal baseline) { defaultFormat.setSubScriptBaseline(baseline); }
71 inline void setBaselineOffset(qreal baseline) { defaultFormat.setBaselineOffset(baseline); }
72
73 inline QTextCharFormat defaultTextFormat() const { return defaultFormat; }
74
75private:
76 QFont defaultFnt;
77 QTextCharFormat defaultFormat;
78
79 Q_DISABLE_COPY_MOVE(QTextFormatCollection)
80};
81
82QT_END_NAMESPACE
83
84#endif // QTEXTFORMAT_P_H
85

source code of qtbase/src/gui/text/qtextformat_p.h