| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 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 | ** 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 have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 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
|
|---|
|
|---|