Qt 4.8
Classes | Public Types | Public Functions | Properties | List of all members
QTextOption Class Reference

The QTextOption class provides a description of general rich text properties. More...

#include <qtextoption.h>

Classes

class  Tab
 Each tab definition is represented by this struct. More...
 

Public Types

enum  Flag {
  ShowTabsAndSpaces = 0x1, ShowLineAndParagraphSeparators = 0x2, AddSpaceForLineAndParagraphSeparators = 0x4, SuppressColors = 0x8,
  IncludeTrailingSpaces = 0x80000000
}
 
enum  TabType { LeftTab, RightTab, CenterTab, DelimiterTab }
 
enum  WrapMode {
  NoWrap, WordWrap, ManualWrap, WrapAnywhere,
  WrapAtWordBoundaryOrAnywhere
}
 This enum describes how text is wrapped in a document. More...
 

Public Functions

Qt::Alignment alignment () const
 Returns the text alignment defined by the option. More...
 
Flags flags () const
 Returns the flags associated with the option. More...
 
QTextOptionoperator= (const QTextOption &o)
 Returns true if the text option is the same as the other text option; otherwise returns false. More...
 
 QTextOption ()
 Constructs a text option with default properties for text. More...
 
 QTextOption (Qt::Alignment alignment)
 Constructs a text option with the given alignment for text. More...
 
 QTextOption (const QTextOption &o)
 Construct a copy of the other text option. More...
 
void setAlignment (Qt::Alignment alignment)
 Sets the option's text alignment to the specified alignment. More...
 
void setFlags (Flags flags)
 Sets the flags associated with the option to the given flags. More...
 
void setTabArray (QList< qreal > tabStops)
 Sets the tab positions for the text layout to those specified by tabStops. More...
 
void setTabs (QList< Tab > tabStops)
 Sets the tab positions for the text layout to those specified by tabStops. More...
 
void setTabStop (qreal tabStop)
 Sets the default distance in device units between tab stops to the value specified by tabStop. More...
 
void setTextDirection (Qt::LayoutDirection aDirection)
 Sets the direction of the text layout defined by the option to the given direction. More...
 
void setUseDesignMetrics (bool b)
 If enable is true then the layout will use design metrics; otherwise it will use the metrics of the paint device (which is the default behavior). More...
 
void setWrapMode (WrapMode wrap)
 Sets the option's text wrap mode to the given mode. More...
 
QList< qrealtabArray () const
 Returns a list of tab positions defined for the text layout. More...
 
QList< Tabtabs () const
 Returns a list of tab positions defined for the text layout. More...
 
qreal tabStop () const
 Returns the distance in device units between tab stops. More...
 
Qt::LayoutDirection textDirection () const
 Returns the direction of the text layout defined by the option. More...
 
bool useDesignMetrics () const
 Returns true if the layout uses design rather than device metrics; otherwise returns false. More...
 
WrapMode wrapMode () const
 Returns the text wrap mode defined by the option. More...
 
 ~QTextOption ()
 Destroys the text option. More...
 

Properties

uint align: 8
 
QTextOptionPrivated
 
uint design: 1
 
uint direction: 2
 
uint f
 
qreal tab
 
uint unused: 18
 
uint wordWrap: 4
 

Detailed Description

The QTextOption class provides a description of general rich text properties.

Note
This class or function is reentrant.

QTextOption is used to encapsulate common rich text properties in a single object. It contains information about text alignment, layout direction, word wrapping, and other standard properties associated with text rendering and layout.

See also
QTextEdit, QTextDocument, QTextCursor

Definition at line 59 of file qtextoption.h.

Enumerations

◆ Flag

  • IncludeTrailingSpaces When this option is set, QTextLine::naturalTextWidth() and naturalTextRect() will return a value that includes the width of trailing spaces in the text; otherwise this width is excluded.
  • ShowTabsAndSpaces Visualize spaces with little dots, and tabs with little arrows.
  • ShowLineAndParagraphSeparators Visualize line and paragraph separators with appropriate symbol characters.
  • AddSpaceForLineAndParagraphSeparators While determining the line-break positions take into account the space added for drawing a separator character.
  • SuppressColors Suppress all color changes in the character formats (except the main selection).
Enumerator
ShowTabsAndSpaces 
ShowLineAndParagraphSeparators 
AddSpaceForLineAndParagraphSeparators 
SuppressColors 
IncludeTrailingSpaces 

Definition at line 112 of file qtextoption.h.

◆ TabType

Since
4.4

This enum holds the different types of tabulator

  • LeftTab A left-tab
  • RightTab A right-tab
  • CenterTab A centered-tab
  • DelimiterTab A tab stopping at a certain delimiter-character
Enumerator
LeftTab 
RightTab 
CenterTab 
DelimiterTab 

Definition at line 62 of file qtextoption.h.

◆ WrapMode

This enum describes how text is wrapped in a document.

  • NoWrap Text is not wrapped at all.
  • WordWrap Text is wrapped at word boundaries.
  • ManualWrap Same as QTextOption::NoWrap
  • WrapAnywhere Text can be wrapped at any point on a line, even if it occurs in the middle of a word.
  • WrapAtWordBoundaryOrAnywhere If possible, wrapping occurs at a word boundary; otherwise it will occur at the appropriate point on the line, even in the middle of a word.
Enumerator
NoWrap 
WordWrap 
ManualWrap 
WrapAnywhere 
WrapAtWordBoundaryOrAnywhere 

Definition at line 102 of file qtextoption.h.

Constructors and Destructors

◆ QTextOption() [1/3]

QTextOption::QTextOption ( )

Constructs a text option with default properties for text.

The text alignment property is set to Qt::AlignLeft. The word wrap property is set to QTextOption::WordWrap. The using of design metrics flag is set to false.

Definition at line 59 of file qtextoption.cpp.

62  design(false),
63  unused(0),
64  f(0),
65  tab(-1),
66  d(0)
67 {
69 }
QTextOptionPrivate * d
Definition: qtextoption.h:143
uint direction
Definition: qtextoption.h:139

◆ QTextOption() [2/3]

QTextOption::QTextOption ( Qt::Alignment  alignment)

Constructs a text option with the given alignment for text.

The word wrap property is set to QTextOption::WordWrap. The using of design metrics flag is set to false.

Definition at line 76 of file qtextoption.cpp.

77  : align(alignment),
79  design(false),
80  unused(0),
81  f(0),
82  tab(-1),
83  d(0)
84 {
86 }
static Qt::LayoutDirection layoutDirection()
QTextOptionPrivate * d
Definition: qtextoption.h:143
uint direction
Definition: qtextoption.h:139
Qt::Alignment alignment() const
Returns the text alignment defined by the option.
Definition: qtextoption.h:97

◆ ~QTextOption()

QTextOption::~QTextOption ( )

Destroys the text option.

Definition at line 91 of file qtextoption.cpp.

92 {
93  delete d;
94 }
QTextOptionPrivate * d
Definition: qtextoption.h:143

◆ QTextOption() [3/3]

QTextOption::QTextOption ( const QTextOption o)

Construct a copy of the other text option.

Definition at line 104 of file qtextoption.cpp.

105  : align(o.align),
106  wordWrap(o.wordWrap),
107  design(o.design),
108  direction(o.direction),
109  unused(o.unused),
110  f(o.f),
111  tab(o.tab),
112  d(0)
113 {
114  if (o.d)
115  d = new QTextOptionPrivate(*o.d);
116 }
QTextOptionPrivate * d
Definition: qtextoption.h:143
uint direction
Definition: qtextoption.h:139

Functions

◆ alignment()

Qt::Alignment QTextOption::alignment ( ) const
inline

◆ flags()

Flags QTextOption::flags ( ) const
inline

◆ operator=()

QTextOption & QTextOption::operator= ( const QTextOption o)

Returns true if the text option is the same as the other text option; otherwise returns false.

Definition at line 127 of file qtextoption.cpp.

128 {
129  if (this == &o)
130  return *this;
131 
132  QTextOptionPrivate* dNew = 0;
133  if (o.d)
134  dNew = new QTextOptionPrivate(*o.d);
135  delete d;
136  d = dNew;
137 
138  align = o.align;
139  wordWrap = o.wordWrap;
140  design = o.design;
141  direction = o.direction;
142  unused = o.unused;
143  f = o.f;
144  tab = o.tab;
145  return *this;
146 }
QTextOptionPrivate * d
Definition: qtextoption.h:143
uint direction
Definition: qtextoption.h:139

◆ setAlignment()

void QTextOption::setAlignment ( Qt::Alignment  alignment)
inline

◆ setFlags()

void QTextOption::setFlags ( Flags  flags)
inline

Sets the flags associated with the option to the given flags.

See also
flags()

Definition at line 151 of file qtextoption.h.

Referenced by QDeclarativeTextPrivate::textDocumentImage(), and QLineControl::updateDisplayText().

152 { f = aflags; }

◆ setTabArray()

void QTextOption::setTabArray ( QList< qreal tabStops)

Sets the tab positions for the text layout to those specified by tabStops.

See also
tabArray(), setTabStop(), setTabs()

Definition at line 154 of file qtextoption.cpp.

Referenced by qt_format_text().

155 {
156  if (!d)
157  d = new QTextOptionPrivate;
160  foreach (qreal pos, tabStops) {
161  tab.position = pos;
162  tabs.append(tab);
163  }
164  d->tabStops = tabs;
165 }
double qreal
Definition: qglobal.h:1193
QTextOptionPrivate * d
Definition: qtextoption.h:143
qreal position
Distance from the start of the paragraph.
Definition: qtextoption.h:84
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QList< QTextOption::Tab > tabStops
Definition: qtextoption.cpp:50
QList< Tab > tabs() const
Returns a list of tab positions defined for the text layout.
Each tab definition is represented by this struct.
Definition: qtextoption.h:69

◆ setTabs()

void QTextOption::setTabs ( QList< Tab tabStops)

Sets the tab positions for the text layout to those specified by tabStops.

Since
4.4
See also
tabStops()

Definition at line 177 of file qtextoption.cpp.

Referenced by QTextDocumentLayoutPrivate::layoutBlock().

178 {
179  if (!d)
180  d = new QTextOptionPrivate;
181  d->tabStops = tabStops;
182 }
QTextOptionPrivate * d
Definition: qtextoption.h:143
QList< QTextOption::Tab > tabStops
Definition: qtextoption.cpp:50

◆ setTabStop()

void QTextOption::setTabStop ( qreal  tabStop)
inline

Sets the default distance in device units between tab stops to the value specified by tabStop.

See also
tabStop(), setTabArray(), setTabs(), tabs()

Definition at line 154 of file qtextoption.h.

Referenced by qt_format_text(), QTextDocumentPrivate::QTextDocumentPrivate(), QPlainTextEdit::setTabStopWidth(), and QTextEdit::setTabStopWidth().

155 { tab = atabStop; }

◆ setTextDirection()

void QTextOption::setTextDirection ( Qt::LayoutDirection  direction)
inline

Sets the direction of the text layout defined by the option to the given direction.

See also
textDirection()

Definition at line 99 of file qtextoption.h.

Referenced by QTextDocumentLayoutPrivate::drawListItem(), QPainter::drawText(), QTextDocumentLayoutPrivate::layoutBlock(), qt_format_text(), QLineControl::updateDisplayText(), and QCommonStylePrivate::viewItemDrawText().

99 { this->direction = aDirection; }
uint direction
Definition: qtextoption.h:139

◆ setUseDesignMetrics()

void QTextOption::setUseDesignMetrics ( bool  enable)
inline

If enable is true then the layout will use design metrics; otherwise it will use the metrics of the paint device (which is the default behavior).

See also
useDesignMetrics()

Definition at line 132 of file qtextoption.h.

132 { design = b; }

◆ setWrapMode()

void QTextOption::setWrapMode ( WrapMode  wrap)
inline

◆ tabArray()

QList< qreal > QTextOption::tabArray ( ) const

Returns a list of tab positions defined for the text layout.

See also
setTabArray(), tabStop()

Definition at line 189 of file qtextoption.cpp.

Referenced by qt_format_text().

190 {
191  if (!d)
192  return QList<qreal>();
193 
194  QList<qreal> answer;
196  while(iter != d->tabStops.constEnd()) {
197  answer.append( (*iter).position);
198  ++iter;
199  }
200  return answer;
201 }
QTextOptionPrivate * d
Definition: qtextoption.h:143
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QList< QTextOption::Tab > tabStops
Definition: qtextoption.cpp:50
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272

◆ tabs()

QList< QTextOption::Tab > QTextOption::tabs ( ) const

Returns a list of tab positions defined for the text layout.

Since
4.4
See also
tabStop(), setTabs(), setTabStop()

Definition at line 204 of file qtextoption.cpp.

Referenced by QTextEngine::calculateTabWidth(), qt_format_text(), and setTabArray().

205 {
206  if (!d)
207  return QList<QTextOption::Tab>();
208  return d->tabStops;
209 }
QTextOptionPrivate * d
Definition: qtextoption.h:143
QList< QTextOption::Tab > tabStops
Definition: qtextoption.cpp:50

◆ tabStop()

qreal QTextOption::tabStop ( ) const
inline

Returns the distance in device units between tab stops.

Convenient function for the above method

See also
setTabStop(), tabArray(), setTabs(), tabs()

Definition at line 124 of file qtextoption.h.

Referenced by QTextEngine::calculateTabWidth(), qt_format_text(), QPlainTextEdit::setTabStopWidth(), and QTextEdit::setTabStopWidth().

124 { return tab; }

◆ textDirection()

Qt::LayoutDirection QTextOption::textDirection ( ) const
inline

Returns the direction of the text layout defined by the option.

See also
setTextDirection()

Definition at line 100 of file qtextoption.h.

Referenced by QTextEngine::isRightToLeft(), QTextEngine::itemize(), qt_format_text(), and QLabelPrivate::textDirection().

100 { return Qt::LayoutDirection(direction); }
LayoutDirection
Definition: qnamespace.h:1580
uint direction
Definition: qtextoption.h:139

◆ useDesignMetrics()

bool QTextOption::useDesignMetrics ( ) const
inline

Returns true if the layout uses design rather than device metrics; otherwise returns false.

See also
setUseDesignMetrics()

Definition at line 133 of file qtextoption.h.

133 { return design; }

◆ wrapMode()

WrapMode QTextOption::wrapMode ( ) const
inline

Properties

◆ align

uint QTextOption::align
private

Definition at line 136 of file qtextoption.h.

Referenced by operator=().

◆ d

QTextOptionPrivate* QTextOption::d
private

Definition at line 143 of file qtextoption.h.

Referenced by operator=(), QTextOption(), setTabArray(), setTabs(), tabArray(), tabs(), and ~QTextOption().

◆ design

uint QTextOption::design
private

Definition at line 138 of file qtextoption.h.

Referenced by operator=().

◆ direction

uint QTextOption::direction
private

Definition at line 139 of file qtextoption.h.

Referenced by operator=(), and QTextOption().

◆ f

uint QTextOption::f
private

Definition at line 141 of file qtextoption.h.

Referenced by operator=().

◆ tab

qreal QTextOption::tab
private

Definition at line 142 of file qtextoption.h.

Referenced by operator=(), and setTabArray().

◆ unused

uint QTextOption::unused
private

Definition at line 140 of file qtextoption.h.

Referenced by operator=().

◆ wordWrap

uint QTextOption::wordWrap
private

Definition at line 137 of file qtextoption.h.

Referenced by operator=().


The documentation for this class was generated from the following files: