qtextoption.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/text/qtextoption.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtGui module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 2.1 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include "qtextoption.h"-
35#include "qguiapplication.h"-
36#include "qlist.h"-
37-
38QT_BEGIN_NAMESPACE-
39-
40struct QTextOptionPrivate-
41{-
42 QList<QTextOption::Tab> tabStops;-
43};-
44-
45/*!-
46 Constructs a text option with default properties for text.-
47 The text alignment property is set to Qt::AlignLeft. The-
48 word wrap property is set to QTextOption::WordWrap. The-
49 using of design metrics flag is set to false.-
50*/-
51QTextOption::QTextOption()-
52 : align(Qt::AlignLeft),-
53 wordWrap(QTextOption::WordWrap),-
54 design(false),-
55 unused(0),-
56 unused2(0),-
57 f(0),-
58 tab(-1),-
59 d(0)-
60{-
61 direction = Qt::LayoutDirectionAuto;-
62}
never executed: end of block
0
63-
64/*!-
65 Constructs a text option with the given \a alignment for text.-
66 The word wrap property is set to QTextOption::WordWrap. The using-
67 of design metrics flag is set to false.-
68*/-
69QTextOption::QTextOption(Qt::Alignment alignment)-
70 : align(alignment),-
71 wordWrap(QTextOption::WordWrap),-
72 design(false),-
73 unused(0),-
74 unused2(0),-
75 f(0),-
76 tab(-1),-
77 d(0)-
78{-
79 direction = QGuiApplication::layoutDirection();-
80}
never executed: end of block
0
81-
82/*!-
83 Destroys the text option.-
84*/-
85QTextOption::~QTextOption()-
86{-
87 delete d;-
88}
never executed: end of block
0
89-
90/*!-
91 \fn QTextOption::QTextOption(const QTextOption &other)-
92-
93 Construct a copy of the \a other text option.-
94*/-
95QTextOption::QTextOption(const QTextOption &o)-
96 : align(o.align),-
97 wordWrap(o.wordWrap),-
98 design(o.design),-
99 direction(o.direction),-
100 unused(o.unused),-
101 unused2(o.unused2),-
102 f(o.f),-
103 tab(o.tab),-
104 d(0)-
105{-
106 if (o.d)
o.dDescription
TRUEnever evaluated
FALSEnever evaluated
0
107 d = new QTextOptionPrivate(*o.d);
never executed: d = new QTextOptionPrivate(*o.d);
0
108}
never executed: end of block
0
109-
110/*!-
111 \fn QTextOption &QTextOption::operator=(const QTextOption &other)-
112-
113 Returns \c true if the text option is the same as the \a other text option;-
114 otherwise returns \c false.-
115*/-
116QTextOption &QTextOption::operator=(const QTextOption &o)-
117{-
118 if (this == &o)
this == &oDescription
TRUEnever evaluated
FALSEnever evaluated
0
119 return *this;
never executed: return *this;
0
120-
121 QTextOptionPrivate* dNew = 0;-
122 if (o.d)
o.dDescription
TRUEnever evaluated
FALSEnever evaluated
0
123 dNew = new QTextOptionPrivate(*o.d);
never executed: dNew = new QTextOptionPrivate(*o.d);
0
124 delete d;-
125 d = dNew;-
126-
127 align = o.align;-
128 wordWrap = o.wordWrap;-
129 design = o.design;-
130 direction = o.direction;-
131 unused = o.unused;-
132 f = o.f;-
133 tab = o.tab;-
134 return *this;
never executed: return *this;
0
135}-
136-
137/*!-
138 Sets the tab positions for the text layout to those specified by-
139 \a tabStops.-
140-
141 \sa tabArray(), setTabStop(), setTabs()-
142*/-
143void QTextOption::setTabArray(const QList<qreal> &tabStops)-
144{-
145 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
146 d = new QTextOptionPrivate;
never executed: d = new QTextOptionPrivate;
0
147 QList<QTextOption::Tab> tabs;-
148 QTextOption::Tab tab;-
149 tabs.reserve(tabStops.count());-
150 foreach (qreal pos, tabStops) {-
151 tab.position = pos;-
152 tabs.append(tab);-
153 }
never executed: end of block
0
154 d->tabStops = tabs;-
155}
never executed: end of block
0
156-
157/*!-
158 \since 4.4-
159 Sets the tab positions for the text layout to those specified by-
160 \a tabStops.-
161-
162 \sa tabStops()-
163*/-
164void QTextOption::setTabs(const QList<QTextOption::Tab> &tabStops)-
165{-
166 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
167 d = new QTextOptionPrivate;
never executed: d = new QTextOptionPrivate;
0
168 d->tabStops = tabStops;-
169}
never executed: end of block
0
170-
171/*!-
172 Returns a list of tab positions defined for the text layout.-
173-
174 \sa setTabArray(), tabStop()-
175*/-
176QList<qreal> QTextOption::tabArray() const-
177{-
178 QList<qreal> answer;-
179 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
180 return answer;
never executed: return answer;
0
181-
182 answer.reserve(d->tabStops.count());-
183 QList<QTextOption::Tab>::ConstIterator iter = d->tabStops.constBegin();-
184 while(iter != d->tabStops.constEnd()) {
iter != d->tabStops.constEnd()Description
TRUEnever evaluated
FALSEnever evaluated
0
185 answer.append( (*iter).position);-
186 ++iter;-
187 }
never executed: end of block
0
188 return answer;
never executed: return answer;
0
189}-
190-
191-
192QList<QTextOption::Tab> QTextOption::tabs() const-
193{-
194 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
195 return QList<QTextOption::Tab>();
never executed: return QList<QTextOption::Tab>();
0
196 return d->tabStops;
never executed: return d->tabStops;
0
197}-
198-
199/*!-
200 \class QTextOption-
201 \reentrant-
202-
203 \brief The QTextOption class provides a description of general rich text-
204 properties.-
205 \inmodule QtGui-
206-
207 \ingroup richtext-processing-
208-
209 QTextOption is used to encapsulate common rich text properties in a single-
210 object. It contains information about text alignment, layout direction,-
211 word wrapping, and other standard properties associated with text rendering-
212 and layout.-
213-
214 \sa QTextEdit, QTextDocument, QTextCursor-
215*/-
216-
217/*!-
218 \enum QTextOption::WrapMode-
219-
220 This enum describes how text is wrapped in a document.-
221-
222 \value NoWrap Text is not wrapped at all.-
223 \value WordWrap Text is wrapped at word boundaries.-
224 \value ManualWrap Same as QTextOption::NoWrap-
225 \value WrapAnywhere Text can be wrapped at any point on a line, even if-
226 it occurs in the middle of a word.-
227 \value WrapAtWordBoundaryOrAnywhere If possible, wrapping occurs at a word-
228 boundary; otherwise it will occur at the appropriate-
229 point on the line, even in the middle of a word.-
230*/-
231-
232/*!-
233 \fn void QTextOption::setUseDesignMetrics(bool enable)-
234-
235 If \a enable is true then the layout will use design metrics;-
236 otherwise it will use the metrics of the paint device (which is-
237 the default behavior).-
238-
239 \sa useDesignMetrics()-
240*/-
241-
242/*!-
243 \fn bool QTextOption::useDesignMetrics() const-
244-
245 Returns \c true if the layout uses design rather than device metrics;-
246 otherwise returns \c false.-
247-
248 \sa setUseDesignMetrics()-
249*/-
250-
251/*!-
252 \fn Qt::Alignment QTextOption::alignment() const-
253-
254 Returns the text alignment defined by the option.-
255-
256 \sa setAlignment()-
257*/-
258-
259/*!-
260 \fn void QTextOption::setAlignment(Qt::Alignment alignment);-
261-
262 Sets the option's text alignment to the specified \a alignment.-
263-
264 \sa alignment()-
265*/-
266-
267/*!-
268 \fn Qt::LayoutDirection QTextOption::textDirection() const-
269-
270 Returns the direction of the text layout defined by the option.-
271-
272 \sa setTextDirection()-
273*/-
274-
275/*!-
276 \fn void QTextOption::setTextDirection(Qt::LayoutDirection direction)-
277-
278 Sets the direction of the text layout defined by the option to the-
279 given \a direction.-
280-
281 \sa textDirection()-
282*/-
283-
284/*!-
285 \fn WrapMode QTextOption::wrapMode() const-
286-
287 Returns the text wrap mode defined by the option.-
288-
289 \sa setWrapMode()-
290*/-
291-
292/*!-
293 \fn void QTextOption::setWrapMode(WrapMode mode)-
294-
295 Sets the option's text wrap mode to the given \a mode.-
296*/-
297-
298/*!-
299 \enum QTextOption::Flag-
300-
301 \value IncludeTrailingSpaces When this option is set, QTextLine::naturalTextWidth() and naturalTextRect() will-
302 return a value that includes the width of trailing spaces in the text; otherwise-
303 this width is excluded.-
304 \value ShowTabsAndSpaces Visualize spaces with little dots, and tabs with little arrows.-
305 \value ShowLineAndParagraphSeparators Visualize line and paragraph separators with appropriate symbol characters.-
306 \value AddSpaceForLineAndParagraphSeparators While determining the line-break positions take into account the-
307 space added for drawing a separator character.-
308 \value SuppressColors Suppress all color changes in the character formats (except the main selection).-
309*/-
310-
311/*!-
312 \fn Flags QTextOption::flags() const-
313-
314 Returns the flags associated with the option.-
315-
316 \sa setFlags()-
317*/-
318-
319/*!-
320 \fn void QTextOption::setFlags(Flags flags)-
321-
322 Sets the flags associated with the option to the given \a flags.-
323-
324 \sa flags()-
325*/-
326-
327/*!-
328 \fn qreal QTextOption::tabStop() const-
329-
330 Returns the distance in device units between tab stops.-
331 Convenient function for the above method-
332-
333 \sa setTabStop(), tabArray(), setTabs(), tabs()-
334*/-
335-
336/*!-
337 \fn void QTextOption::setTabStop(qreal tabStop)-
338-
339 Sets the default distance in device units between tab stops to the value specified-
340 by \a tabStop.-
341-
342 \sa tabStop(), setTabArray(), setTabs(), tabs()-
343*/-
344-
345/*!-
346 \enum QTextOption::TabType-
347 \since 4.4-
348-
349 This enum holds the different types of tabulator-
350-
351 \value LeftTab A left-tab-
352 \value RightTab A right-tab-
353 \value CenterTab A centered-tab-
354 \value DelimiterTab A tab stopping at a certain delimiter-character-
355*/-
356-
357/*!-
358 \class QTextOption::Tab-
359 \since 4.4-
360 \inmodule QtGui-
361 Each tab definition is represented by this struct.-
362*/-
363-
364/*!-
365 \variable Tab::position-
366 Distance from the start of the paragraph.-
367 The position of a tab is from the start of the paragraph which implies that when-
368 the alignment of the paragraph is set to centered, the tab is interpreted to be-
369 moved the same distance as the left ege of the paragraph does.-
370 In case the paragraph is set to have a layoutDirection() RightToLeft the position-
371 is interpreted to be from the right side of the paragraph with higher numbers moving-
372 the tab to the left.-
373*/-
374-
375/*!-
376 \variable Tab::type-
377 Determine which type is used.-
378 In a paragraph that has layoutDirection() RightToLeft the type LeftTab will-
379 be interpreted to be a RightTab and vice versa.-
380*/-
381-
382/*!-
383 \variable Tab::delimiter-
384 If type is DelimitorTab; tab until this char is found in the text.-
385*/-
386-
387/*!-
388 \fn Tab::Tab()-
389 Creates a default left tab with position 80.-
390*/-
391-
392/*!-
393 \fn Tab::Tab(qreal pos, TabType tabType, QChar delim = QChar())-
394-
395 Creates a tab with the given position, tab type, and delimiter-
396 (\a pos, \a tabType, \a delim).-
397-
398 \note \a delim is only used when \a tabType is DelimiterTab.-
399-
400 \since 4.7-
401*/-
402-
403/*!-
404 \fn bool Tab::operator==(const Tab &other) const-
405-
406 Returns \c true if tab \a other is equal to this tab;-
407 otherwise returns \c false.-
408*/-
409-
410/*!-
411 \fn bool Tab::operator!=(const Tab &other) const-
412-
413 Returns \c true if tab \a other is not equal to this tab;-
414 otherwise returns \c false.-
415*/-
416-
417/*!-
418 \fn void setTabs(const QList<Tab> &tabStops)-
419 Set the Tab properties to \a tabStops.-
420-
421 \sa tabStop(), tabs()-
422*/-
423-
424/*!-
425 \since 4.4-
426 \fn QList<QTextOption::Tab> QTextOption::tabs() const-
427 Returns a list of tab positions defined for the text layout.-
428-
429 \sa tabStop(), setTabs(), setTabStop()-
430*/-
431-
432-
433QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

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