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