source: trunk/src/gui/text/qtextoption.cpp@ 352

Last change on this file since 352 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

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