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