1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qtextoption.h"
43 #include "qguiapplication.h"
48 struct QTextOptionPrivate
50 QList<QTextOption::Tab> tabStops;
54 Constructs a text option with default properties for text.
55 The text alignment property is set to Qt::AlignLeft. The
56 word wrap property is set to QTextOption::WordWrap. The
57 using of design metrics flag is set to false.
59 QTextOption::QTextOption()
60 : align(Qt::AlignLeft),
61 wordWrap(QTextOption::WordWrap),
68 direction = Qt::LayoutDirectionAuto;
72 Constructs a text option with the given \a alignment for text.
73 The word wrap property is set to QTextOption::WordWrap. The using
74 of design metrics flag is set to false.
76 QTextOption::QTextOption(Qt::Alignment alignment)
78 wordWrap(QTextOption::WordWrap),
85 direction = QGuiApplication::layoutDirection();
89 Destroys the text option.
91 QTextOption::~QTextOption()
97 \fn QTextOption::QTextOption(const QTextOption &other)
99 Construct a copy of the \a other text option.
101 QTextOption::QTextOption(const QTextOption &o)
103 wordWrap(o.wordWrap),
105 direction(o.direction),
112 d = new QTextOptionPrivate(*o.d);
116 \fn QTextOption &QTextOption::operator=(const QTextOption &other)
118 Returns true if the text option is the same as the \a other text option;
119 otherwise returns false.
121 QTextOption &QTextOption::operator=(const QTextOption &o)
126 QTextOptionPrivate* dNew = 0;
128 dNew = new QTextOptionPrivate(*o.d);
133 wordWrap = o.wordWrap;
135 direction = o.direction;
143 Sets the tab positions for the text layout to those specified by
146 \sa tabArray(), setTabStop(), setTabs()
148 void QTextOption::setTabArray(const QList<qreal> &tabStops)
151 d = new QTextOptionPrivate;
152 QList<QTextOption::Tab> tabs;
153 QTextOption::Tab tab;
154 foreach (qreal pos, tabStops) {
163 Sets the tab positions for the text layout to those specified by
168 void QTextOption::setTabs(const QList<QTextOption::Tab> &tabStops)
171 d = new QTextOptionPrivate;
172 d->tabStops = tabStops;
176 Returns a list of tab positions defined for the text layout.
178 \sa setTabArray(), tabStop()
180 QList<qreal> QTextOption::tabArray() const
183 return QList<qreal>();
186 QList<QTextOption::Tab>::ConstIterator iter = d->tabStops.constBegin();
187 while(iter != d->tabStops.constEnd()) {
188 answer.append( (*iter).position);
195 QList<QTextOption::Tab> QTextOption::tabs() const
198 return QList<QTextOption::Tab>();
206 \brief The QTextOption class provides a description of general rich text
210 \ingroup richtext-processing
212 QTextOption is used to encapsulate common rich text properties in a single
213 object. It contains information about text alignment, layout direction,
214 word wrapping, and other standard properties associated with text rendering
217 \sa QTextEdit, QTextDocument, QTextCursor
221 \enum QTextOption::WrapMode
223 This enum describes how text is wrapped in a document.
225 \value NoWrap Text is not wrapped at all.
226 \value WordWrap Text is wrapped at word boundaries.
227 \value ManualWrap Same as QTextOption::NoWrap
228 \value WrapAnywhere Text can be wrapped at any point on a line, even if
229 it occurs in the middle of a word.
230 \value WrapAtWordBoundaryOrAnywhere If possible, wrapping occurs at a word
231 boundary; otherwise it will occur at the appropriate
232 point on the line, even in the middle of a word.
236 \fn void QTextOption::setUseDesignMetrics(bool enable)
238 If \a enable is true then the layout will use design metrics;
239 otherwise it will use the metrics of the paint device (which is
240 the default behavior).
242 \sa useDesignMetrics()
246 \fn bool QTextOption::useDesignMetrics() const
248 Returns true if the layout uses design rather than device metrics;
249 otherwise returns false.
251 \sa setUseDesignMetrics()
255 \fn Qt::Alignment QTextOption::alignment() const
257 Returns the text alignment defined by the option.
263 \fn void QTextOption::setAlignment(Qt::Alignment alignment);
265 Sets the option's text alignment to the specified \a alignment.
271 \fn Qt::LayoutDirection QTextOption::textDirection() const
273 Returns the direction of the text layout defined by the option.
275 \sa setTextDirection()
279 \fn void QTextOption::setTextDirection(Qt::LayoutDirection direction)
281 Sets the direction of the text layout defined by the option to the
288 \fn WrapMode QTextOption::wrapMode() const
290 Returns the text wrap mode defined by the option.
296 \fn void QTextOption::setWrapMode(WrapMode mode)
298 Sets the option's text wrap mode to the given \a mode.
302 \enum QTextOption::Flag
304 \value IncludeTrailingSpaces When this option is set, QTextLine::naturalTextWidth() and naturalTextRect() will
305 return a value that includes the width of trailing spaces in the text; otherwise
306 this width is excluded.
307 \value ShowTabsAndSpaces Visualize spaces with little dots, and tabs with little arrows.
308 \value ShowLineAndParagraphSeparators Visualize line and paragraph separators with appropriate symbol characters.
309 \value AddSpaceForLineAndParagraphSeparators While determining the line-break positions take into account the
310 space added for drawing a separator character.
311 \value SuppressColors Suppress all color changes in the character formats (except the main selection).
315 \fn Flags QTextOption::flags() const
317 Returns the flags associated with the option.
323 \fn void QTextOption::setFlags(Flags flags)
325 Sets the flags associated with the option to the given \a flags.
331 \fn qreal QTextOption::tabStop() const
333 Returns the distance in device units between tab stops.
334 Convenient function for the above method
336 \sa setTabStop(), tabArray(), setTabs(), tabs()
340 \fn void QTextOption::setTabStop(qreal tabStop)
342 Sets the default distance in device units between tab stops to the value specified
345 \sa tabStop(), setTabArray(), setTabs(), tabs()
349 \enum QTextOption::TabType
352 This enum holds the different types of tabulator
354 \value LeftTab A left-tab
355 \value RightTab A right-tab
356 \value CenterTab A centered-tab
357 \value DelimiterTab A tab stopping at a certain delimiter-character
361 \class QTextOption::Tab
364 Each tab definition is represented by this struct.
368 \variable Tab::position
369 Distance from the start of the paragraph.
370 The position of a tab is from the start of the paragraph which implies that when
371 the alignment of the paragraph is set to centered, the tab is interpreted to be
372 moved the same distance as the left ege of the paragraph does.
373 In case the paragraph is set to have a layoutDirection() RightToLeft the position
374 is interpreted to be from the right side of the paragraph with higher numbers moving
380 Determine which type is used.
381 In a paragraph that has layoutDirection() RightToLeft the type LeftTab will
382 be interpreted to be a RightTab and vice versa.
386 \variable Tab::delimiter
387 If type is DelimitorTab; tab until this char is found in the text.
392 Creates a default left tab with position 80.
396 \fn Tab::Tab(qreal pos, TabType tabType, QChar delim = QChar())
398 Creates a tab with the given position, tab type, and delimiter
399 (\a pos, \a tabType, \a delim).
401 \note \a delim is only used when \a tabType is DelimiterTab.
407 \fn bool Tab::operator==(const Tab &other) const
409 Returns true if tab \a other is equal to this tab;
410 otherwise returns false.
414 \fn bool Tab::operator!=(const Tab &other) const
416 Returns true if tab \a other is not equal to this tab;
417 otherwise returns false.
421 \fn void setTabs(QList<Tab> tabStops)
422 Set the Tab properties to \a tabStops.
424 \sa tabStop(), tabs()
429 \fn QList<QTextOption::Tab> QTextOption::tabs() const
430 Returns a list of tab positions defined for the text layout.
432 \sa tabStop(), setTabs(), setTabStop()