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 |
|
---|
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 | 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 | */
|
---|
139 | void 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 |
|
---|
|
---|