Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtextoption.cpp
Go to the documentation of this file.
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
#
include
"qtextoption.h"
5
#
include
"qguiapplication.h"
6
#
include
"qlist.h"
7
8
QT_BEGIN_NAMESPACE
9
10
QT_IMPL_METATYPE_EXTERN_TAGGED(QTextOption::Tab, QTextOption_Tab)
11
12
struct
QTextOptionPrivate
13
{
14
QList<QTextOption::Tab> tabStops;
15
};
16
17
/*!
18
Constructs a text option with default properties for text.
19
The text alignment property is set to Qt::AlignLeft. The
20
word wrap property is set to QTextOption::WordWrap. The
21
using of design metrics flag is set to false.
22
*/
23
QTextOption::QTextOption()
24
: QTextOption(Qt::AlignLeft)
25
{
26
direction = Qt::LayoutDirectionAuto;
27
}
28
29
/*!
30
Constructs a text option with the given \a alignment for text.
31
The word wrap property is set to QTextOption::WordWrap. The using
32
of design metrics flag is set to false.
33
*/
34
QTextOption::QTextOption(Qt::Alignment alignment)
35
: align(alignment),
36
wordWrap(QTextOption::WordWrap),
37
design(
false
),
38
unused(0),
39
f(0),
40
tab(-1),
41
d(
nullptr
)
42
{
43
direction = QGuiApplication::layoutDirection();
44
}
45
46
/*!
47
Destroys the text option.
48
*/
49
QTextOption::~QTextOption()
50
{
51
delete
d;
52
}
53
54
/*!
55
\fn QTextOption::QTextOption(const QTextOption &other)
56
57
Construct a copy of the \a other text option.
58
*/
59
QTextOption::QTextOption(
const
QTextOption &o)
60
: align(o.align),
61
wordWrap(o.wordWrap),
62
design(o.design),
63
direction(o.direction),
64
unused(o.unused),
65
f(o.f),
66
tab(o.tab),
67
d(
nullptr
)
68
{
69
if
(o.d)
70
d =
new
QTextOptionPrivate(*o.d);
71
}
72
73
/*!
74
\fn QTextOption &QTextOption::operator=(const QTextOption &other)
75
76
Returns \c true if the text option is the same as the \a other text option;
77
otherwise returns \c false.
78
*/
79
QTextOption &QTextOption::operator=(
const
QTextOption &o)
80
{
81
if
(
this
== &o)
82
return
*
this
;
83
84
QTextOptionPrivate* dNew =
nullptr
;
85
if
(o.d)
86
dNew =
new
QTextOptionPrivate(*o.d);
87
delete
d;
88
d = dNew;
89
90
align = o.align;
91
wordWrap = o.wordWrap;
92
design = o.design;
93
direction = o.direction;
94
unused = o.unused;
95
f = o.f;
96
tab = o.tab;
97
return
*
this
;
98
}
99
100
/*!
101
Sets the tab positions for the text layout to those specified by
102
\a tabStops.
103
104
\sa tabArray(), setTabStopDistance(), setTabs()
105
*/
106
void
QTextOption::setTabArray(
const
QList<qreal> &tabStops)
107
{
108
if
(!d)
109
d =
new
QTextOptionPrivate;
110
QList<QTextOption::Tab> tabs;
111
QTextOption::Tab tab;
112
tabs.reserve(tabStops.size());
113
for
(qreal pos : tabStops) {
114
tab.position = pos;
115
tabs.append(tab);
116
}
117
d->tabStops = tabs;
118
}
119
120
/*!
121
\since 4.4
122
Sets the tab positions for the text layout to those specified by
123
\a tabStops.
124
125
\sa tabStopDistance()
126
*/
127
void
QTextOption::setTabs(
const
QList<QTextOption::Tab> &tabStops)
128
{
129
if
(!d)
130
d =
new
QTextOptionPrivate;
131
d->tabStops = tabStops;
132
}
133
134
/*!
135
Returns a list of tab positions defined for the text layout.
136
137
\sa setTabArray(), tabStopDistance()
138
*/
139
QList<qreal> QTextOption::tabArray()
const
140
{
141
QList<qreal> answer;
142
if
(!d)
143
return
answer;
144
145
answer.reserve(d->tabStops.size());
146
QList<QTextOption::Tab>::ConstIterator iter = d->tabStops.constBegin();
147
while
(iter != d->tabStops.constEnd()) {
148
answer.append( (*iter).position);
149
++iter;
150
}
151
return
answer;
152
}
153
154
155
QList<QTextOption::Tab> QTextOption::tabs()
const
156
{
157
if
(!d)
158
return
QList<QTextOption::Tab>();
159
return
d->tabStops;
160
}
161
162
/*!
163
\class QTextOption
164
\reentrant
165
166
\brief The QTextOption class provides a description of general rich text
167
properties.
168
\inmodule QtGui
169
170
\ingroup richtext-processing
171
172
QTextOption is used to encapsulate common rich text properties in a single
173
object. It contains information about text alignment, layout direction,
174
word wrapping, and other standard properties associated with text rendering
175
and layout.
176
177
\sa QTextEdit, QTextDocument, QTextCursor
178
*/
179
180
/*!
181
\enum QTextOption::WrapMode
182
183
This enum describes how text is wrapped in a document.
184
185
\value NoWrap Text is not wrapped at all.
186
\value WordWrap Text is wrapped at word boundaries.
187
\value ManualWrap Same as QTextOption::NoWrap
188
\value WrapAnywhere Text can be wrapped at any point on a line, even if
189
it occurs in the middle of a word.
190
\value WrapAtWordBoundaryOrAnywhere If possible, wrapping occurs at a word
191
boundary; otherwise it will occur at the appropriate
192
point on the line, even in the middle of a word.
193
*/
194
195
/*!
196
\fn void QTextOption::setUseDesignMetrics(bool enable)
197
198
If \a enable is true then the layout will use design metrics;
199
otherwise it will use the metrics of the paint device (which is
200
the default behavior).
201
202
\sa useDesignMetrics()
203
*/
204
205
/*!
206
\fn bool QTextOption::useDesignMetrics() const
207
208
Returns \c true if the layout uses design rather than device metrics;
209
otherwise returns \c false.
210
211
\sa setUseDesignMetrics()
212
*/
213
214
/*!
215
\fn Qt::Alignment QTextOption::alignment() const
216
217
Returns the text alignment defined by the option.
218
219
\sa setAlignment()
220
*/
221
222
/*!
223
\fn void QTextOption::setAlignment(Qt::Alignment alignment);
224
225
Sets the option's text alignment to the specified \a alignment.
226
227
\sa alignment()
228
*/
229
230
/*!
231
\fn Qt::LayoutDirection QTextOption::textDirection() const
232
233
Returns the direction of the text layout defined by the option.
234
235
\sa setTextDirection()
236
*/
237
238
/*!
239
\fn void QTextOption::setTextDirection(Qt::LayoutDirection direction)
240
241
Sets the direction of the text layout defined by the option to the
242
given \a direction.
243
244
\sa textDirection()
245
*/
246
247
/*!
248
\fn WrapMode QTextOption::wrapMode() const
249
250
Returns the text wrap mode defined by the option.
251
252
\sa setWrapMode()
253
*/
254
255
/*!
256
\fn void QTextOption::setWrapMode(WrapMode mode)
257
258
Sets the option's text wrap mode to the given \a mode.
259
*/
260
261
/*!
262
\enum QTextOption::Flag
263
264
\value IncludeTrailingSpaces When this option is set, QTextLine::naturalTextWidth() and naturalTextRect() will
265
return a value that includes the width of trailing spaces in the text; otherwise
266
this width is excluded.
267
\value ShowTabsAndSpaces Visualize spaces with little dots, and tabs with little arrows. Non-breaking spaces are
268
shown differently to breaking spaces.
269
\value ShowLineAndParagraphSeparators Visualize line and paragraph separators with appropriate symbol characters.
270
\value [since 5.7] ShowDocumentTerminator Visualize the end of the document with a section sign.
271
\value [since 6.9] ShowDefaultIgnorables Render normally non-visual characters if supported by font.
272
\value AddSpaceForLineAndParagraphSeparators While determining the line-break positions take into account the
273
space added for drawing a separator character.
274
\value SuppressColors Suppress all color changes in the character formats (except the main selection).
275
\value [since 6.9] DisableEmojiParsing By default, Qt will detect emoji sequences in input strings
276
and prioritize using color fonts to display them. This extra step can be disabled by setting the
277
DisableEmojiParsing flag if it is known in advance that it will not be needed.
278
*/
279
280
/*!
281
\fn Flags QTextOption::flags() const
282
283
Returns the flags associated with the option.
284
285
\sa setFlags()
286
*/
287
288
/*!
289
\fn void QTextOption::setFlags(Flags flags)
290
291
Sets the flags associated with the option to the given \a flags.
292
293
\sa flags()
294
*/
295
296
/*!
297
\fn qreal QTextOption::tabStopDistance() const
298
\since 5.10
299
300
Returns the distance in device units between tab stops.
301
302
\sa setTabStopDistance(), tabArray(), setTabs(), tabs()
303
*/
304
305
/*!
306
\fn void QTextOption::setTabStopDistance(qreal tabStopDistance)
307
\since 5.10
308
309
Sets the default distance in device units between tab stops to the value specified
310
by \a tabStopDistance.
311
312
\sa tabStopDistance(), setTabArray(), setTabs(), tabs()
313
*/
314
315
/*!
316
\enum QTextOption::TabType
317
\since 4.4
318
319
This enum holds the different types of tabulator
320
321
\value LeftTab A left-tab
322
\value RightTab A right-tab
323
\value CenterTab A centered-tab
324
\value DelimiterTab A tab stopping at a certain delimiter-character
325
*/
326
327
/*!
328
\class QTextOption::Tab
329
\since 4.4
330
\inmodule QtGui
331
Each tab definition is represented by this struct.
332
*/
333
334
/*!
335
\variable QTextOption::Tab::position
336
Distance from the start of the paragraph.
337
The position of a tab is from the start of the paragraph which implies that when
338
the alignment of the paragraph is set to centered, the tab is interpreted to be
339
moved the same distance as the left edge of the paragraph does.
340
In case the paragraph is set to have a layoutDirection() RightToLeft the position
341
is interpreted to be from the right side of the paragraph with higher numbers moving
342
the tab to the left.
343
*/
344
345
/*!
346
\variable QTextOption::Tab::type
347
Determine which type is used.
348
In a paragraph that has layoutDirection() RightToLeft the type LeftTab will
349
be interpreted to be a RightTab and vice versa.
350
*/
351
352
/*!
353
\variable QTextOption::Tab::delimiter
354
If type is DelimitorTab; tab until this char is found in the text.
355
*/
356
357
/*!
358
\fn QTextOption::Tab::Tab()
359
Creates a default left tab with position 80.
360
*/
361
362
/*!
363
\fn QTextOption::Tab::Tab(qreal pos, TabType tabType, QChar delim = QChar())
364
365
Creates a tab with the given position, tab type, and delimiter
366
(\a pos, \a tabType, \a delim).
367
368
\note \a delim is only used when \a tabType is DelimiterTab.
369
370
\since 4.7
371
*/
372
373
/*!
374
\fn bool QTextOption::Tab::operator==(const QTextOption::Tab &other) const
375
376
Returns \c true if tab \a other is equal to this tab;
377
otherwise returns \c false.
378
*/
379
380
/*!
381
\fn bool QTextOption::Tab::operator!=(const QTextOption::Tab &other) const
382
383
Returns \c true if tab \a other is not equal to this tab;
384
otherwise returns \c false.
385
*/
386
387
/*!
388
\since 4.4
389
\fn QList<QTextOption::Tab> QTextOption::tabs() const
390
Returns a list of tab positions defined for the text layout.
391
392
\sa tabStopDistance(), setTabs(), setTabStopDistance()
393
*/
394
395
396
QT_END_NAMESPACE
QPlatformGraphicsBufferHelper
\inmodule QtGui
qtbase
src
gui
text
qtextoption.cpp
Generated on
for Qt by
1.14.0