author | eckhart.koppen@nokia.com |
Wed, 31 Mar 2010 11:06:36 +0300 | |
changeset 7 | f7bc934e204c |
parent 3 | 41300fa6a67c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
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 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "qtextformat.h" |
|
43 |
#include "qtextformat_p.h" |
|
44 |
||
45 |
#include <qvariant.h> |
|
46 |
#include <qdatastream.h> |
|
47 |
#include <qdebug.h> |
|
48 |
#include <qmap.h> |
|
49 |
#include <qhash.h> |
|
50 |
||
51 |
QT_BEGIN_NAMESPACE |
|
52 |
||
53 |
/*! |
|
54 |
\class QTextLength |
|
55 |
\reentrant |
|
56 |
||
57 |
\brief The QTextLength class encapsulates the different types of length |
|
58 |
used in a QTextDocument. |
|
59 |
||
60 |
\ingroup richtext-processing |
|
61 |
||
62 |
When we specify a value for the length of an element in a text document, |
|
63 |
we often need to provide some other information so that the length is |
|
64 |
used in the way we expect. For example, when we specify a table width, |
|
65 |
the value can represent a fixed number of pixels, or it can be a percentage |
|
66 |
value. This information changes both the meaning of the value and the way |
|
67 |
it is used. |
|
68 |
||
69 |
Generally, this class is used to specify table widths. These can be |
|
70 |
specified either as a fixed amount of pixels, as a percentage of the |
|
71 |
containing frame's width, or by a variable width that allows it to take |
|
72 |
up just the space it requires. |
|
73 |
||
74 |
\sa QTextTable |
|
75 |
*/ |
|
76 |
||
77 |
/*! |
|
78 |
\fn explicit QTextLength::QTextLength() |
|
79 |
||
80 |
Constructs a new length object which represents a variable size. |
|
81 |
*/ |
|
82 |
||
83 |
/*! |
|
84 |
\fn QTextLength::QTextLength(Type type, qreal value) |
|
85 |
||
86 |
Constructs a new length object of the given \a type and \a value. |
|
87 |
*/ |
|
88 |
||
89 |
/*! |
|
90 |
\fn Type QTextLength::type() const |
|
91 |
||
92 |
Returns the type of this length object. |
|
93 |
||
94 |
\sa QTextLength::Type |
|
95 |
*/ |
|
96 |
||
97 |
/*! |
|
98 |
\fn qreal QTextLength::value(qreal maximumLength) const |
|
99 |
||
100 |
Returns the effective length, constrained by the type of the length object |
|
101 |
and the specified \a maximumLength. |
|
102 |
||
103 |
\sa type() |
|
104 |
*/ |
|
105 |
||
106 |
/*! |
|
107 |
\fn qreal QTextLength::rawValue() const |
|
108 |
||
109 |
Returns the constraint value that is specific for the type of the length. |
|
110 |
If the length is QTextLength::PercentageLength then the raw value is in |
|
111 |
percent, in the range of 0 to 100. If the length is QTextLength::FixedLength |
|
112 |
then that fixed amount is returned. For variable lengths, zero is returned. |
|
113 |
*/ |
|
114 |
||
115 |
/*! |
|
116 |
\fn bool QTextLength::operator==(const QTextLength &other) const |
|
117 |
||
118 |
Returns true if this text length is the same as the \a other text |
|
119 |
length. |
|
120 |
*/ |
|
121 |
||
122 |
/*! |
|
123 |
\fn bool QTextLength::operator!=(const QTextLength &other) const |
|
124 |
||
125 |
Returns true if this text length is different from the \a other text |
|
126 |
length. |
|
127 |
*/ |
|
128 |
||
129 |
/*! |
|
130 |
\enum QTextLength::Type |
|
131 |
||
132 |
This enum describes the different types a length object can |
|
133 |
have. |
|
134 |
||
135 |
\value VariableLength The width of the object is variable |
|
136 |
\value FixedLength The width of the object is fixed |
|
137 |
\value PercentageLength The width of the object is in |
|
138 |
percentage of the maximum width |
|
139 |
||
140 |
\sa type() |
|
141 |
*/ |
|
142 |
||
143 |
/*! |
|
144 |
Returns the text length as a QVariant |
|
145 |
*/ |
|
146 |
QTextLength::operator QVariant() const |
|
147 |
{ |
|
148 |
return QVariant(QVariant::TextLength, this); |
|
149 |
} |
|
150 |
||
151 |
#ifndef QT_NO_DATASTREAM |
|
152 |
QDataStream &operator<<(QDataStream &stream, const QTextLength &length) |
|
153 |
{ |
|
154 |
return stream << qint32(length.lengthType) << double(length.fixedValueOrPercentage); |
|
155 |
} |
|
156 |
||
157 |
QDataStream &operator>>(QDataStream &stream, QTextLength &length) |
|
158 |
{ |
|
159 |
qint32 type; |
|
160 |
double fixedValueOrPercentage; |
|
161 |
stream >> type >> fixedValueOrPercentage; |
|
162 |
length.fixedValueOrPercentage = fixedValueOrPercentage; |
|
163 |
length.lengthType = QTextLength::Type(type); |
|
164 |
return stream; |
|
165 |
} |
|
166 |
#endif // QT_NO_DATASTREAM |
|
167 |
||
168 |
class QTextFormatPrivate : public QSharedData |
|
169 |
{ |
|
170 |
public: |
|
171 |
QTextFormatPrivate() : hashDirty(true), fontDirty(true), hashValue(0) {} |
|
172 |
||
173 |
struct Property |
|
174 |
{ |
|
175 |
inline Property(qint32 k, const QVariant &v) : key(k), value(v) {} |
|
176 |
inline Property() {} |
|
177 |
||
178 |
qint32 key; |
|
179 |
QVariant value; |
|
180 |
||
181 |
inline bool operator==(const Property &other) const |
|
182 |
{ return key == other.key && value == other.value; } |
|
183 |
inline bool operator!=(const Property &other) const |
|
184 |
{ return key != other.key || value != other.value; } |
|
185 |
}; |
|
186 |
||
187 |
inline uint hash() const |
|
188 |
{ |
|
189 |
if (!hashDirty) |
|
190 |
return hashValue; |
|
191 |
return recalcHash(); |
|
192 |
} |
|
193 |
||
194 |
inline bool operator==(const QTextFormatPrivate &rhs) const { |
|
195 |
if (hash() != rhs.hash()) |
|
196 |
return false; |
|
197 |
||
198 |
return props == rhs.props; |
|
199 |
} |
|
200 |
||
201 |
inline void insertProperty(qint32 key, const QVariant &value) |
|
202 |
{ |
|
203 |
hashDirty = true; |
|
204 |
if (key >= QTextFormat::FirstFontProperty && key <= QTextFormat::LastFontProperty) |
|
205 |
fontDirty = true; |
|
206 |
for (int i = 0; i < props.count(); ++i) |
|
207 |
if (props.at(i).key == key) { |
|
208 |
props[i].value = value; |
|
209 |
return; |
|
210 |
} |
|
211 |
props.append(Property(key, value)); |
|
212 |
} |
|
213 |
||
214 |
inline void clearProperty(qint32 key) |
|
215 |
{ |
|
216 |
for (int i = 0; i < props.count(); ++i) |
|
217 |
if (props.at(i).key == key) { |
|
218 |
hashDirty = true; |
|
219 |
if (key >= QTextFormat::FirstFontProperty && key <= QTextFormat::LastFontProperty) |
|
220 |
fontDirty = true; |
|
221 |
props.remove(i); |
|
222 |
return; |
|
223 |
} |
|
224 |
} |
|
225 |
||
226 |
inline int propertyIndex(qint32 key) const |
|
227 |
{ |
|
228 |
for (int i = 0; i < props.count(); ++i) |
|
229 |
if (props.at(i).key == key) |
|
230 |
return i; |
|
231 |
return -1; |
|
232 |
} |
|
233 |
||
234 |
inline QVariant property(qint32 key) const |
|
235 |
{ |
|
236 |
const int idx = propertyIndex(key); |
|
237 |
if (idx < 0) |
|
238 |
return QVariant(); |
|
239 |
return props.at(idx).value; |
|
240 |
} |
|
241 |
||
242 |
inline bool hasProperty(qint32 key) const |
|
243 |
{ return propertyIndex(key) != -1; } |
|
244 |
||
245 |
void resolveFont(const QFont &defaultFont); |
|
246 |
||
247 |
inline const QFont &font() const { |
|
248 |
if (fontDirty) |
|
249 |
recalcFont(); |
|
250 |
return fnt; |
|
251 |
} |
|
252 |
||
253 |
QVector<Property> props; |
|
254 |
private: |
|
255 |
||
256 |
uint recalcHash() const; |
|
257 |
void recalcFont() const; |
|
258 |
||
259 |
mutable bool hashDirty; |
|
260 |
mutable bool fontDirty; |
|
261 |
mutable uint hashValue; |
|
262 |
mutable QFont fnt; |
|
263 |
||
264 |
friend QDataStream &operator<<(QDataStream &, const QTextFormat &); |
|
265 |
friend QDataStream &operator>>(QDataStream &, QTextFormat &); |
|
266 |
}; |
|
267 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
268 |
// this is only safe if sizeof(int) == sizeof(float) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
269 |
static inline uint hash(float d) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
270 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
271 |
return reinterpret_cast<uint&>(d); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
272 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
273 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
274 |
static inline uint hash(const QColor &color) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
275 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
276 |
return (color.isValid()) ? color.rgba() : 0x234109; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
277 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
278 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
279 |
static inline uint hash(const QPen &pen) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
280 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
281 |
return hash(pen.color()) + hash(pen.widthF()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
282 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
283 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
284 |
static inline uint hash(const QBrush &brush) |
0 | 285 |
{ |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
286 |
return hash(brush.color()) + (brush.style() << 3); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
287 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
288 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
289 |
static inline uint variantHash(const QVariant &variant) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
290 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
291 |
// simple and fast hash functions to differentiate between type and value |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
292 |
switch (variant.userType()) { // sorted by occurrence frequency |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
293 |
case QVariant::String: return qHash(variant.toString()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
294 |
case QVariant::Double: return hash(variant.toDouble()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
295 |
case QVariant::Int: return 0x811890 + variant.toInt(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
296 |
case QVariant::Brush: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
297 |
return 0x01010101 + hash(qvariant_cast<QBrush>(variant)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
298 |
case QVariant::Bool: return 0x371818 + variant.toBool(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
299 |
case QVariant::Pen: return 0x02020202 + hash(qvariant_cast<QPen>(variant)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
300 |
case QVariant::List: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
301 |
return 0x8377 + qvariant_cast<QVariantList>(variant).count(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
302 |
case QVariant::Color: return hash(qvariant_cast<QColor>(variant)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
303 |
case QVariant::TextLength: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
304 |
return 0x377 + hash(qvariant_cast<QTextLength>(variant).rawValue()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
305 |
case QMetaType::Float: return hash(variant.toFloat()); |
0 | 306 |
case QVariant::Invalid: return 0; |
307 |
default: break; |
|
308 |
} |
|
309 |
return qHash(variant.typeName()); |
|
310 |
} |
|
311 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
312 |
static inline int getHash(const QTextFormatPrivate *d, int format) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
313 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
314 |
return (d ? d->hash() : 0) + format; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
315 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
316 |
|
0 | 317 |
uint QTextFormatPrivate::recalcHash() const |
318 |
{ |
|
319 |
hashValue = 0; |
|
320 |
for (QVector<Property>::ConstIterator it = props.constBegin(); it != props.constEnd(); ++it) |
|
321 |
hashValue += (it->key << 16) + variantHash(it->value); |
|
322 |
||
323 |
hashDirty = false; |
|
324 |
||
325 |
return hashValue; |
|
326 |
} |
|
327 |
||
328 |
void QTextFormatPrivate::resolveFont(const QFont &defaultFont) |
|
329 |
{ |
|
330 |
recalcFont(); |
|
331 |
const uint oldMask = fnt.resolve(); |
|
332 |
fnt = fnt.resolve(defaultFont); |
|
333 |
||
334 |
if (hasProperty(QTextFormat::FontSizeAdjustment)) { |
|
335 |
const qreal scaleFactors[7] = {qreal(0.7), qreal(0.8), qreal(1.0), qreal(1.2), qreal(1.5), qreal(2), qreal(2.4)}; |
|
336 |
||
337 |
const int htmlFontSize = qBound(0, property(QTextFormat::FontSizeAdjustment).toInt() + 3 - 1, 6); |
|
338 |
||
339 |
||
340 |
if (defaultFont.pointSize() <= 0) { |
|
341 |
qreal pixelSize = scaleFactors[htmlFontSize] * defaultFont.pixelSize(); |
|
342 |
fnt.setPixelSize(qRound(pixelSize)); |
|
343 |
} else { |
|
344 |
qreal pointSize = scaleFactors[htmlFontSize] * defaultFont.pointSizeF(); |
|
345 |
fnt.setPointSizeF(pointSize); |
|
346 |
} |
|
347 |
} |
|
348 |
||
349 |
fnt.resolve(oldMask); |
|
350 |
} |
|
351 |
||
352 |
void QTextFormatPrivate::recalcFont() const |
|
353 |
{ |
|
354 |
// update cached font as well |
|
355 |
QFont f; |
|
356 |
||
357 |
for (int i = 0; i < props.count(); ++i) { |
|
358 |
switch (props.at(i).key) { |
|
359 |
case QTextFormat::FontFamily: |
|
360 |
f.setFamily(props.at(i).value.toString()); |
|
361 |
break; |
|
362 |
case QTextFormat::FontPointSize: |
|
363 |
f.setPointSizeF(props.at(i).value.toReal()); |
|
364 |
break; |
|
365 |
case QTextFormat::FontPixelSize: |
|
366 |
f.setPixelSize(props.at(i).value.toInt()); |
|
367 |
break; |
|
368 |
case QTextFormat::FontWeight: { |
|
369 |
int weight = props.at(i).value.toInt(); |
|
370 |
if (weight == 0) weight = QFont::Normal; |
|
371 |
f.setWeight(weight); |
|
372 |
break; } |
|
373 |
case QTextFormat::FontItalic: |
|
374 |
f.setItalic(props.at(i).value.toBool()); |
|
375 |
break; |
|
376 |
case QTextFormat::FontUnderline: |
|
377 |
if (! hasProperty(QTextFormat::TextUnderlineStyle)) // don't use the old one if the new one is there. |
|
378 |
f.setUnderline(props.at(i).value.toBool()); |
|
379 |
break; |
|
380 |
case QTextFormat::TextUnderlineStyle: |
|
381 |
f.setUnderline(static_cast<QTextCharFormat::UnderlineStyle>(props.at(i).value.toInt()) == QTextCharFormat::SingleUnderline); |
|
382 |
break; |
|
383 |
case QTextFormat::FontOverline: |
|
384 |
f.setOverline(props.at(i).value.toBool()); |
|
385 |
break; |
|
386 |
case QTextFormat::FontStrikeOut: |
|
387 |
f.setStrikeOut(props.at(i).value.toBool()); |
|
388 |
break; |
|
389 |
case QTextFormat::FontLetterSpacing: |
|
390 |
f.setLetterSpacing(QFont::PercentageSpacing, props.at(i).value.toReal()); |
|
391 |
break; |
|
392 |
case QTextFormat::FontWordSpacing: |
|
393 |
f.setWordSpacing(props.at(i).value.toReal()); |
|
394 |
break; |
|
395 |
case QTextFormat::FontCapitalization: |
|
396 |
f.setCapitalization(static_cast<QFont::Capitalization> (props.at(i).value.toInt())); |
|
397 |
break; |
|
398 |
case QTextFormat::FontFixedPitch: { |
|
399 |
const bool value = props.at(i).value.toBool(); |
|
400 |
if (f.fixedPitch() != value) |
|
401 |
f.setFixedPitch(value); |
|
402 |
break; } |
|
403 |
case QTextFormat::FontStyleHint: |
|
404 |
f.setStyleHint(static_cast<QFont::StyleHint>(props.at(i).value.toInt()), f.styleStrategy()); |
|
405 |
break; |
|
406 |
case QTextFormat::FontStyleStrategy: |
|
407 |
f.setStyleStrategy(static_cast<QFont::StyleStrategy>(props.at(i).value.toInt())); |
|
408 |
break; |
|
409 |
case QTextFormat::FontKerning: |
|
410 |
f.setKerning(props.at(i).value.toBool()); |
|
411 |
break; |
|
412 |
default: |
|
413 |
break; |
|
414 |
} |
|
415 |
} |
|
416 |
fnt = f; |
|
417 |
fontDirty = false; |
|
418 |
} |
|
419 |
||
420 |
#ifndef QT_NO_DATASTREAM |
|
421 |
Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QTextFormat &fmt) |
|
422 |
{ |
|
423 |
stream << fmt.format_type << fmt.properties(); |
|
424 |
return stream; |
|
425 |
} |
|
426 |
||
427 |
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextFormat &fmt) |
|
428 |
{ |
|
429 |
QMap<qint32, QVariant> properties; |
|
430 |
stream >> fmt.format_type >> properties; |
|
431 |
||
432 |
// QTextFormat's default constructor doesn't allocate the private structure, so |
|
433 |
// we have to do this, in case fmt is a default constructed value. |
|
434 |
if(!fmt.d) |
|
435 |
fmt.d = new QTextFormatPrivate(); |
|
436 |
||
437 |
for (QMap<qint32, QVariant>::ConstIterator it = properties.constBegin(); |
|
438 |
it != properties.constEnd(); ++it) |
|
439 |
fmt.d->insertProperty(it.key(), it.value()); |
|
440 |
||
441 |
return stream; |
|
442 |
} |
|
443 |
#endif // QT_NO_DATASTREAM |
|
444 |
||
445 |
/*! |
|
446 |
\class QTextFormat |
|
447 |
\reentrant |
|
448 |
||
449 |
\brief The QTextFormat class provides formatting information for a |
|
450 |
QTextDocument. |
|
451 |
||
452 |
\ingroup richtext-processing |
|
453 |
\ingroup shared |
|
454 |
||
455 |
A QTextFormat is a generic class used for describing the format of |
|
456 |
parts of a QTextDocument. The derived classes QTextCharFormat, |
|
457 |
QTextBlockFormat, QTextListFormat, and QTextTableFormat are usually |
|
458 |
more useful, and describe the formatting that is applied to |
|
459 |
specific parts of the document. |
|
460 |
||
461 |
A format has a \c FormatType which specifies the kinds of text item it |
|
462 |
can format; e.g. a block of text, a list, a table, etc. A format |
|
463 |
also has various properties (some specific to particular format |
|
464 |
types), as described by the Property enum. Every property has a |
|
465 |
corresponding Property. |
|
466 |
||
467 |
The format type is given by type(), and the format can be tested |
|
468 |
with isCharFormat(), isBlockFormat(), isListFormat(), |
|
469 |
isTableFormat(), isFrameFormat(), and isImageFormat(). If the |
|
470 |
type is determined, it can be retrieved with toCharFormat(), |
|
471 |
toBlockFormat(), toListFormat(), toTableFormat(), toFrameFormat(), |
|
472 |
and toImageFormat(). |
|
473 |
||
474 |
A format's properties can be set with the setProperty() functions, |
|
475 |
and retrieved with boolProperty(), intProperty(), doubleProperty(), |
|
476 |
and stringProperty() as appropriate. All the property IDs used in |
|
477 |
the format can be retrieved with allPropertyIds(). One format can |
|
478 |
be merged into another using merge(). |
|
479 |
||
480 |
A format's object index can be set with setObjectIndex(), and |
|
481 |
retrieved with objectIndex(). These methods can be used to |
|
482 |
associate the format with a QTextObject. It is used to represent |
|
483 |
lists, frames, and tables inside the document. |
|
484 |
||
485 |
\sa {Rich Text Processing} |
|
486 |
*/ |
|
487 |
||
488 |
/*! |
|
489 |
\enum QTextFormat::FormatType |
|
490 |
||
491 |
This enum describes the text item a QTextFormat object is formatting. |
|
492 |
||
493 |
\value InvalidFormat An invalid format as created by the default |
|
494 |
constructor |
|
495 |
\value BlockFormat The object formats a text block |
|
496 |
\value CharFormat The object formats a single character |
|
497 |
\value ListFormat The object formats a list |
|
498 |
\value TableFormat The object formats a table |
|
499 |
\value FrameFormat The object formats a frame |
|
500 |
||
501 |
\value UserFormat |
|
502 |
||
503 |
\sa QTextCharFormat, QTextBlockFormat, QTextListFormat, |
|
504 |
QTextTableFormat, type() |
|
505 |
*/ |
|
506 |
||
507 |
/*! |
|
508 |
\enum QTextFormat::Property |
|
509 |
||
510 |
This enum describes the different properties a format can have. |
|
511 |
||
512 |
\value ObjectIndex The index of the formatted object. See objectIndex(). |
|
513 |
||
514 |
Paragraph and character properties |
|
515 |
||
516 |
\value CssFloat How a frame is located relative to the surrounding text |
|
517 |
\value LayoutDirection The layout direction of the text in the document |
|
518 |
(Qt::LayoutDirection). |
|
519 |
||
520 |
\value OutlinePen |
|
521 |
\value ForegroundBrush |
|
522 |
\value BackgroundBrush |
|
523 |
\value BackgroundImageUrl |
|
524 |
||
525 |
Paragraph properties |
|
526 |
||
527 |
\value BlockAlignment |
|
528 |
\value BlockTopMargin |
|
529 |
\value BlockBottomMargin |
|
530 |
\value BlockLeftMargin |
|
531 |
\value BlockRightMargin |
|
532 |
\value TextIndent |
|
533 |
\value TabPositions Specifies the tab positions. The tab positions are structs of QTextOption::Tab which are stored in |
|
534 |
a QList (internally, in a QList<QVariant>). |
|
535 |
\value BlockIndent |
|
536 |
\value BlockNonBreakableLines |
|
537 |
\value BlockTrailingHorizontalRulerWidth The width of a horizontal ruler element. |
|
538 |
||
539 |
Character properties |
|
540 |
||
541 |
\value FontFamily |
|
542 |
\value FontPointSize |
|
543 |
\value FontPixelSize |
|
544 |
\value FontSizeAdjustment Specifies the change in size given to the fontsize already set using |
|
545 |
FontPointSize or FontPixelSize. |
|
546 |
\value FontFixedPitch |
|
547 |
\omitvalue FontSizeIncrement |
|
548 |
\value FontWeight |
|
549 |
\value FontItalic |
|
550 |
\value FontUnderline \e{This property has been deprecated.} Use QTextFormat::TextUnderlineStyle instead. |
|
551 |
\value FontOverline |
|
552 |
\value FontStrikeOut |
|
553 |
\value FontCapitalization Specifies the capitalization type that is to be applied to the text. |
|
554 |
\value FontLetterSpacing Changes the default spacing between individual letters in the font. The value is |
|
555 |
specified in percentage, with 100 as the default value. |
|
556 |
\value FontWordSpacing Changes the default spacing between individual words. A positive value increases the word spacing |
|
557 |
by the corresponding pixels; a negative value decreases the spacing. |
|
558 |
\value FontStyleHint Corresponds to the QFont::StyleHint property |
|
559 |
\value FontStyleStrategy Corresponds to the QFont::StyleStrategy property |
|
560 |
\value FontKerning Specifies whether the font has kerning turned on. |
|
561 |
||
562 |
\omitvalue FirstFontProperty |
|
563 |
\omitvalue LastFontProperty |
|
564 |
||
565 |
\value TextUnderlineColor |
|
566 |
\value TextVerticalAlignment |
|
567 |
\value TextOutline |
|
568 |
\value TextUnderlineStyle |
|
569 |
\value TextToolTip Specifies the (optional) tool tip to be displayed for a fragment of text. |
|
570 |
||
571 |
\value IsAnchor |
|
572 |
\value AnchorHref |
|
573 |
\value AnchorName |
|
574 |
\value ObjectType |
|
575 |
||
576 |
List properties |
|
577 |
||
578 |
\value ListStyle |
|
579 |
\value ListIndent |
|
580 |
||
581 |
Table and frame properties |
|
582 |
||
583 |
\value FrameBorder |
|
584 |
\value FrameBorderBrush |
|
585 |
\value FrameBorderStyle See the \l{QTextFrameFormat::BorderStyle}{BorderStyle} enum. |
|
586 |
\value FrameBottomMargin |
|
587 |
\value FrameHeight |
|
588 |
\value FrameLeftMargin |
|
589 |
\value FrameMargin |
|
590 |
\value FramePadding |
|
591 |
\value FrameRightMargin |
|
592 |
\value FrameTopMargin |
|
593 |
\value FrameWidth |
|
594 |
\value TableCellSpacing |
|
595 |
\value TableCellPadding |
|
596 |
\value TableColumns |
|
597 |
\value TableColumnWidthConstraints |
|
598 |
\value TableHeaderRowCount |
|
599 |
||
600 |
Table cell properties |
|
601 |
||
602 |
\value TableCellRowSpan |
|
603 |
\value TableCellColumnSpan |
|
604 |
\value TableCellLeftPadding |
|
605 |
\value TableCellRightPadding |
|
606 |
\value TableCellTopPadding |
|
607 |
\value TableCellBottomPadding |
|
608 |
||
609 |
Image properties |
|
610 |
||
611 |
\value ImageName |
|
612 |
\value ImageWidth |
|
613 |
\value ImageHeight |
|
614 |
||
615 |
Selection properties |
|
616 |
||
617 |
\value FullWidthSelection When set on the characterFormat of a selection, |
|
618 |
the whole width of the text will be shown selected. |
|
619 |
||
620 |
Page break properties |
|
621 |
||
622 |
\value PageBreakPolicy Specifies how pages are broken. See the PageBreakFlag enum. |
|
623 |
||
624 |
\value UserProperty |
|
625 |
||
626 |
\sa property(), setProperty() |
|
627 |
*/ |
|
628 |
||
629 |
/*! |
|
630 |
\enum QTextFormat::ObjectTypes |
|
631 |
||
632 |
This enum describes what kind of QTextObject this format is associated with. |
|
633 |
||
634 |
\value NoObject |
|
635 |
\value ImageObject |
|
636 |
\value TableObject |
|
637 |
\value TableCellObject |
|
638 |
\value UserObject The first object that can be used for application-specific purposes. |
|
639 |
||
640 |
\sa QTextObject, QTextTable, QTextObject::format() |
|
641 |
*/ |
|
642 |
||
643 |
/*! |
|
644 |
\enum QTextFormat::PageBreakFlag |
|
645 |
\since 4.2 |
|
646 |
||
647 |
This enum describes how page breaking is performed when printing. It maps to the |
|
648 |
corresponding css properties. |
|
649 |
||
650 |
\value PageBreak_Auto The page break is determined automatically depending on the |
|
651 |
available space on the current page |
|
652 |
\value PageBreak_AlwaysBefore The page is always broken before the paragraph/table |
|
653 |
\value PageBreak_AlwaysAfter A new page is always started after the paragraph/table |
|
654 |
||
655 |
\sa QTextBlockFormat::pageBreakPolicy(), QTextFrameFormat::pageBreakPolicy(), |
|
656 |
PageBreakPolicy |
|
657 |
*/ |
|
658 |
||
659 |
/*! |
|
660 |
\fn bool QTextFormat::isValid() const |
|
661 |
||
662 |
Returns true if the format is valid (i.e. is not |
|
663 |
InvalidFormat); otherwise returns false. |
|
664 |
*/ |
|
665 |
||
666 |
/*! |
|
667 |
\fn bool QTextFormat::isCharFormat() const |
|
668 |
||
669 |
Returns true if this text format is a \c CharFormat; otherwise |
|
670 |
returns false. |
|
671 |
*/ |
|
672 |
||
673 |
||
674 |
/*! |
|
675 |
\fn bool QTextFormat::isBlockFormat() const |
|
676 |
||
677 |
Returns true if this text format is a \c BlockFormat; otherwise |
|
678 |
returns false. |
|
679 |
*/ |
|
680 |
||
681 |
||
682 |
/*! |
|
683 |
\fn bool QTextFormat::isListFormat() const |
|
684 |
||
685 |
Returns true if this text format is a \c ListFormat; otherwise |
|
686 |
returns false. |
|
687 |
*/ |
|
688 |
||
689 |
||
690 |
/*! |
|
691 |
\fn bool QTextFormat::isTableFormat() const |
|
692 |
||
693 |
Returns true if this text format is a \c TableFormat; otherwise |
|
694 |
returns false. |
|
695 |
*/ |
|
696 |
||
697 |
||
698 |
/*! |
|
699 |
\fn bool QTextFormat::isFrameFormat() const |
|
700 |
||
701 |
Returns true if this text format is a \c FrameFormat; otherwise |
|
702 |
returns false. |
|
703 |
*/ |
|
704 |
||
705 |
||
706 |
/*! |
|
707 |
\fn bool QTextFormat::isImageFormat() const |
|
708 |
||
709 |
Returns true if this text format is an image format; otherwise |
|
710 |
returns false. |
|
711 |
*/ |
|
712 |
||
713 |
||
714 |
/*! |
|
715 |
\fn bool QTextFormat::isTableCellFormat() const |
|
716 |
\since 4.4 |
|
717 |
||
718 |
Returns true if this text format is a \c TableCellFormat; otherwise |
|
719 |
returns false. |
|
720 |
*/ |
|
721 |
||
722 |
||
723 |
/*! |
|
724 |
Creates a new text format with an \c InvalidFormat. |
|
725 |
||
726 |
\sa FormatType |
|
727 |
*/ |
|
728 |
QTextFormat::QTextFormat() |
|
729 |
: format_type(InvalidFormat) |
|
730 |
{ |
|
731 |
} |
|
732 |
||
733 |
/*! |
|
734 |
Creates a new text format of the given \a type. |
|
735 |
||
736 |
\sa FormatType |
|
737 |
*/ |
|
738 |
QTextFormat::QTextFormat(int type) |
|
739 |
: format_type(type) |
|
740 |
{ |
|
741 |
} |
|
742 |
||
743 |
||
744 |
/*! |
|
745 |
\fn QTextFormat::QTextFormat(const QTextFormat &other) |
|
746 |
||
747 |
Creates a new text format with the same attributes as the \a other |
|
748 |
text format. |
|
749 |
*/ |
|
750 |
QTextFormat::QTextFormat(const QTextFormat &rhs) |
|
751 |
: d(rhs.d), format_type(rhs.format_type) |
|
752 |
{ |
|
753 |
} |
|
754 |
||
755 |
/*! |
|
756 |
\fn QTextFormat &QTextFormat::operator=(const QTextFormat &other) |
|
757 |
||
758 |
Assigns the \a other text format to this text format, and returns a |
|
759 |
reference to this text format. |
|
760 |
*/ |
|
761 |
QTextFormat &QTextFormat::operator=(const QTextFormat &rhs) |
|
762 |
{ |
|
763 |
d = rhs.d; |
|
764 |
format_type = rhs.format_type; |
|
765 |
return *this; |
|
766 |
} |
|
767 |
||
768 |
/*! |
|
769 |
Destroys this text format. |
|
770 |
*/ |
|
771 |
QTextFormat::~QTextFormat() |
|
772 |
{ |
|
773 |
} |
|
774 |
||
775 |
||
776 |
/*! |
|
777 |
Returns the text format as a QVariant |
|
778 |
*/ |
|
779 |
QTextFormat::operator QVariant() const |
|
780 |
{ |
|
781 |
return QVariant(QVariant::TextFormat, this); |
|
782 |
} |
|
783 |
||
784 |
/*! |
|
785 |
Merges the \a other format with this format; where there are |
|
786 |
conflicts the \a other format takes precedence. |
|
787 |
*/ |
|
788 |
void QTextFormat::merge(const QTextFormat &other) |
|
789 |
{ |
|
790 |
if (format_type != other.format_type) |
|
791 |
return; |
|
792 |
||
793 |
if (!d) { |
|
794 |
d = other.d; |
|
795 |
return; |
|
796 |
} |
|
797 |
||
798 |
if (!other.d) |
|
799 |
return; |
|
800 |
||
801 |
QTextFormatPrivate *d = this->d; |
|
802 |
||
803 |
const QVector<QTextFormatPrivate::Property> &otherProps = other.d->props; |
|
804 |
d->props.reserve(d->props.size() + otherProps.size()); |
|
805 |
for (int i = 0; i < otherProps.count(); ++i) { |
|
806 |
const QTextFormatPrivate::Property &p = otherProps.at(i); |
|
807 |
d->insertProperty(p.key, p.value); |
|
808 |
} |
|
809 |
} |
|
810 |
||
811 |
/*! |
|
812 |
Returns the type of this format. |
|
813 |
||
814 |
\sa FormatType |
|
815 |
*/ |
|
816 |
int QTextFormat::type() const |
|
817 |
{ |
|
818 |
return format_type; |
|
819 |
} |
|
820 |
||
821 |
/*! |
|
822 |
Returns this format as a block format. |
|
823 |
*/ |
|
824 |
QTextBlockFormat QTextFormat::toBlockFormat() const |
|
825 |
{ |
|
826 |
return QTextBlockFormat(*this); |
|
827 |
} |
|
828 |
||
829 |
/*! |
|
830 |
Returns this format as a character format. |
|
831 |
*/ |
|
832 |
QTextCharFormat QTextFormat::toCharFormat() const |
|
833 |
{ |
|
834 |
return QTextCharFormat(*this); |
|
835 |
} |
|
836 |
||
837 |
/*! |
|
838 |
Returns this format as a list format. |
|
839 |
*/ |
|
840 |
QTextListFormat QTextFormat::toListFormat() const |
|
841 |
{ |
|
842 |
return QTextListFormat(*this); |
|
843 |
} |
|
844 |
||
845 |
/*! |
|
846 |
Returns this format as a table format. |
|
847 |
*/ |
|
848 |
QTextTableFormat QTextFormat::toTableFormat() const |
|
849 |
{ |
|
850 |
return QTextTableFormat(*this); |
|
851 |
} |
|
852 |
||
853 |
/*! |
|
854 |
Returns this format as a frame format. |
|
855 |
*/ |
|
856 |
QTextFrameFormat QTextFormat::toFrameFormat() const |
|
857 |
{ |
|
858 |
return QTextFrameFormat(*this); |
|
859 |
} |
|
860 |
||
861 |
/*! |
|
862 |
Returns this format as an image format. |
|
863 |
*/ |
|
864 |
QTextImageFormat QTextFormat::toImageFormat() const |
|
865 |
{ |
|
866 |
return QTextImageFormat(*this); |
|
867 |
} |
|
868 |
||
869 |
/*! |
|
870 |
\since 4.4 |
|
871 |
||
872 |
Returns this format as a table cell format. |
|
873 |
*/ |
|
874 |
QTextTableCellFormat QTextFormat::toTableCellFormat() const |
|
875 |
{ |
|
876 |
return QTextTableCellFormat(*this); |
|
877 |
} |
|
878 |
||
879 |
/*! |
|
880 |
Returns the value of the property specified by \a propertyId. If the |
|
881 |
property isn't of QTextFormat::Bool type, false is returned instead. |
|
882 |
||
883 |
\sa setProperty() intProperty() doubleProperty() stringProperty() colorProperty() lengthProperty() lengthVectorProperty() Property |
|
884 |
*/ |
|
885 |
bool QTextFormat::boolProperty(int propertyId) const |
|
886 |
{ |
|
887 |
if (!d) |
|
888 |
return false; |
|
889 |
const QVariant prop = d->property(propertyId); |
|
890 |
if (prop.userType() != QVariant::Bool) |
|
891 |
return false; |
|
892 |
return prop.toBool(); |
|
893 |
} |
|
894 |
||
895 |
/*! |
|
896 |
Returns the value of the property specified by \a propertyId. If the |
|
897 |
property is not of QTextFormat::Integer type, 0 is returned instead. |
|
898 |
||
899 |
\sa setProperty() boolProperty() doubleProperty() stringProperty() colorProperty() lengthProperty() lengthVectorProperty() Property |
|
900 |
*/ |
|
901 |
int QTextFormat::intProperty(int propertyId) const |
|
902 |
{ |
|
903 |
if (!d) |
|
904 |
return 0; |
|
905 |
const QVariant prop = d->property(propertyId); |
|
906 |
if (prop.userType() != QVariant::Int) |
|
907 |
return 0; |
|
908 |
return prop.toInt(); |
|
909 |
} |
|
910 |
||
911 |
/*! |
|
912 |
Returns the value of the property specified by \a propertyId. If the |
|
913 |
property isn't of QVariant::Double or QMetaType::Float type, 0 is |
|
914 |
returned instead. |
|
915 |
||
916 |
\sa setProperty() boolProperty() intProperty() stringProperty() colorProperty() lengthProperty() lengthVectorProperty() Property |
|
917 |
*/ |
|
918 |
qreal QTextFormat::doubleProperty(int propertyId) const |
|
919 |
{ |
|
920 |
if (!d) |
|
921 |
return 0.; |
|
922 |
const QVariant prop = d->property(propertyId); |
|
923 |
if (prop.userType() != QVariant::Double && prop.userType() != QMetaType::Float) |
|
924 |
return 0.; |
|
925 |
return qVariantValue<qreal>(prop); |
|
926 |
} |
|
927 |
||
928 |
/*! |
|
929 |
Returns the value of the property given by \a propertyId; if the |
|
930 |
property isn't of QVariant::String type, an empty string is |
|
931 |
returned instead. |
|
932 |
||
933 |
\sa setProperty() boolProperty() intProperty() doubleProperty() colorProperty() lengthProperty() lengthVectorProperty() Property |
|
934 |
*/ |
|
935 |
QString QTextFormat::stringProperty(int propertyId) const |
|
936 |
{ |
|
937 |
if (!d) |
|
938 |
return QString(); |
|
939 |
const QVariant prop = d->property(propertyId); |
|
940 |
if (prop.userType() != QVariant::String) |
|
941 |
return QString(); |
|
942 |
return prop.toString(); |
|
943 |
} |
|
944 |
||
945 |
/*! |
|
946 |
Returns the value of the property given by \a propertyId; if the |
|
947 |
property isn't of QVariant::Color type, an invalid color is |
|
948 |
returned instead. |
|
949 |
||
950 |
\sa setProperty(), boolProperty(), intProperty(), doubleProperty(), |
|
951 |
stringProperty(), lengthProperty(), lengthVectorProperty(), Property |
|
952 |
*/ |
|
953 |
QColor QTextFormat::colorProperty(int propertyId) const |
|
954 |
{ |
|
955 |
if (!d) |
|
956 |
return QColor(); |
|
957 |
const QVariant prop = d->property(propertyId); |
|
958 |
if (prop.userType() != QVariant::Color) |
|
959 |
return QColor(); |
|
960 |
return qvariant_cast<QColor>(prop); |
|
961 |
} |
|
962 |
||
963 |
/*! |
|
964 |
Returns the value of the property given by \a propertyId; if the |
|
965 |
property isn't of QVariant::Pen type, Qt::NoPen is |
|
966 |
returned instead. |
|
967 |
||
968 |
\sa setProperty() boolProperty() intProperty() doubleProperty() stringProperty() lengthProperty() lengthVectorProperty() Property |
|
969 |
*/ |
|
970 |
QPen QTextFormat::penProperty(int propertyId) const |
|
971 |
{ |
|
972 |
if (!d) |
|
973 |
return QPen(Qt::NoPen); |
|
974 |
const QVariant prop = d->property(propertyId); |
|
975 |
if (prop.userType() != QVariant::Pen) |
|
976 |
return QPen(Qt::NoPen); |
|
977 |
return qvariant_cast<QPen>(prop); |
|
978 |
} |
|
979 |
||
980 |
/*! |
|
981 |
Returns the value of the property given by \a propertyId; if the |
|
982 |
property isn't of QVariant::Brush type, Qt::NoBrush is |
|
983 |
returned instead. |
|
984 |
||
985 |
\sa setProperty() boolProperty() intProperty() doubleProperty() stringProperty() lengthProperty() lengthVectorProperty() Property |
|
986 |
*/ |
|
987 |
QBrush QTextFormat::brushProperty(int propertyId) const |
|
988 |
{ |
|
989 |
if (!d) |
|
990 |
return QBrush(Qt::NoBrush); |
|
991 |
const QVariant prop = d->property(propertyId); |
|
992 |
if (prop.userType() != QVariant::Brush) |
|
993 |
return QBrush(Qt::NoBrush); |
|
994 |
return qvariant_cast<QBrush>(prop); |
|
995 |
} |
|
996 |
||
997 |
/*! |
|
998 |
Returns the value of the property given by \a propertyId. |
|
999 |
||
1000 |
\sa setProperty() boolProperty() intProperty() doubleProperty() stringProperty() colorProperty() lengthVectorProperty() Property |
|
1001 |
*/ |
|
1002 |
QTextLength QTextFormat::lengthProperty(int propertyId) const |
|
1003 |
{ |
|
1004 |
if (!d) |
|
1005 |
return QTextLength(); |
|
1006 |
return qvariant_cast<QTextLength>(d->property(propertyId)); |
|
1007 |
} |
|
1008 |
||
1009 |
/*! |
|
1010 |
Returns the value of the property given by \a propertyId. If the |
|
1011 |
property isn't of QTextFormat::LengthVector type, an empty length |
|
1012 |
vector is returned instead. |
|
1013 |
||
1014 |
\sa setProperty() boolProperty() intProperty() doubleProperty() stringProperty() colorProperty() lengthProperty() Property |
|
1015 |
*/ |
|
1016 |
QVector<QTextLength> QTextFormat::lengthVectorProperty(int propertyId) const |
|
1017 |
{ |
|
1018 |
QVector<QTextLength> vector; |
|
1019 |
if (!d) |
|
1020 |
return vector; |
|
1021 |
const QVariant prop = d->property(propertyId); |
|
1022 |
if (prop.userType() != QVariant::List) |
|
1023 |
return vector; |
|
1024 |
||
1025 |
QList<QVariant> propertyList = prop.toList(); |
|
1026 |
for (int i=0; i<propertyList.size(); ++i) { |
|
1027 |
QVariant var = propertyList.at(i); |
|
1028 |
if (var.userType() == QVariant::TextLength) |
|
1029 |
vector.append(qvariant_cast<QTextLength>(var)); |
|
1030 |
} |
|
1031 |
||
1032 |
return vector; |
|
1033 |
} |
|
1034 |
||
1035 |
/*! |
|
1036 |
Returns the property specified by the given \a propertyId. |
|
1037 |
||
1038 |
\sa Property |
|
1039 |
*/ |
|
1040 |
QVariant QTextFormat::property(int propertyId) const |
|
1041 |
{ |
|
1042 |
return d ? d->property(propertyId) : QVariant(); |
|
1043 |
} |
|
1044 |
||
1045 |
/*! |
|
1046 |
Sets the property specified by the \a propertyId to the given \a value. |
|
1047 |
||
1048 |
\sa Property |
|
1049 |
*/ |
|
1050 |
void QTextFormat::setProperty(int propertyId, const QVariant &value) |
|
1051 |
{ |
|
1052 |
if (!d) |
|
1053 |
d = new QTextFormatPrivate; |
|
1054 |
if (!value.isValid()) |
|
1055 |
clearProperty(propertyId); |
|
1056 |
else |
|
1057 |
d->insertProperty(propertyId, value); |
|
1058 |
} |
|
1059 |
||
1060 |
/*! |
|
1061 |
Sets the value of the property given by \a propertyId to \a value. |
|
1062 |
||
1063 |
\sa lengthVectorProperty() Property |
|
1064 |
*/ |
|
1065 |
void QTextFormat::setProperty(int propertyId, const QVector<QTextLength> &value) |
|
1066 |
{ |
|
1067 |
if (!d) |
|
1068 |
d = new QTextFormatPrivate; |
|
1069 |
QVariantList list; |
|
1070 |
for (int i=0; i<value.size(); ++i) |
|
1071 |
list << value.at(i); |
|
1072 |
d->insertProperty(propertyId, list); |
|
1073 |
} |
|
1074 |
||
1075 |
/*! |
|
1076 |
Clears the value of the property given by \a propertyId |
|
1077 |
||
1078 |
\sa Property |
|
1079 |
*/ |
|
1080 |
void QTextFormat::clearProperty(int propertyId) |
|
1081 |
{ |
|
1082 |
if (!d) |
|
1083 |
return; |
|
1084 |
d->clearProperty(propertyId); |
|
1085 |
} |
|
1086 |
||
1087 |
||
1088 |
/*! |
|
1089 |
\fn void QTextFormat::setObjectType(int type) |
|
1090 |
||
1091 |
Sets the text format's object type to \a type. |
|
1092 |
||
1093 |
\sa ObjectTypes, objectType() |
|
1094 |
*/ |
|
1095 |
||
1096 |
||
1097 |
/*! |
|
1098 |
\fn int QTextFormat::objectType() const |
|
1099 |
||
1100 |
Returns the text format's object type. |
|
1101 |
||
1102 |
\sa ObjectTypes, setObjectType() |
|
1103 |
*/ |
|
1104 |
||
1105 |
||
1106 |
/*! |
|
1107 |
Returns the index of the format object, or -1 if the format object is invalid. |
|
1108 |
||
1109 |
\sa setObjectIndex() |
|
1110 |
*/ |
|
1111 |
int QTextFormat::objectIndex() const |
|
1112 |
{ |
|
1113 |
if (!d) |
|
1114 |
return -1; |
|
1115 |
const QVariant prop = d->property(ObjectIndex); |
|
1116 |
if (prop.userType() != QVariant::Int) // #### |
|
1117 |
return -1; |
|
1118 |
return prop.toInt(); |
|
1119 |
} |
|
1120 |
||
1121 |
/*! |
|
1122 |
\fn void QTextFormat::setObjectIndex(int index) |
|
1123 |
||
1124 |
Sets the format object's object \a index. |
|
1125 |
||
1126 |
\sa objectIndex() |
|
1127 |
*/ |
|
1128 |
void QTextFormat::setObjectIndex(int o) |
|
1129 |
{ |
|
1130 |
if (o == -1) { |
|
1131 |
if (d) |
|
1132 |
d->clearProperty(ObjectIndex); |
|
1133 |
} else { |
|
1134 |
if (!d) |
|
1135 |
d = new QTextFormatPrivate; |
|
1136 |
// ### type |
|
1137 |
d->insertProperty(ObjectIndex, o); |
|
1138 |
} |
|
1139 |
} |
|
1140 |
||
1141 |
/*! |
|
1142 |
Returns true if the text format has a property with the given \a |
|
1143 |
propertyId; otherwise returns false. |
|
1144 |
||
1145 |
\sa properties() Property |
|
1146 |
*/ |
|
1147 |
bool QTextFormat::hasProperty(int propertyId) const |
|
1148 |
{ |
|
1149 |
return d ? d->hasProperty(propertyId) : false; |
|
1150 |
} |
|
1151 |
||
1152 |
/* |
|
1153 |
Returns the property type for the given \a propertyId. |
|
1154 |
||
1155 |
\sa hasProperty() allPropertyIds() Property |
|
1156 |
*/ |
|
1157 |
||
1158 |
/*! |
|
1159 |
Returns a map with all properties of this text format. |
|
1160 |
*/ |
|
1161 |
QMap<int, QVariant> QTextFormat::properties() const |
|
1162 |
{ |
|
1163 |
QMap<int, QVariant> map; |
|
1164 |
if (d) { |
|
1165 |
for (int i = 0; i < d->props.count(); ++i) |
|
1166 |
map.insert(d->props.at(i).key, d->props.at(i).value); |
|
1167 |
} |
|
1168 |
return map; |
|
1169 |
} |
|
1170 |
||
1171 |
/*! |
|
1172 |
\since 4.3 |
|
1173 |
Returns the number of properties stored in the format. |
|
1174 |
*/ |
|
1175 |
int QTextFormat::propertyCount() const |
|
1176 |
{ |
|
1177 |
return d ? d->props.count() : 0; |
|
1178 |
} |
|
1179 |
||
1180 |
/*! |
|
1181 |
\fn bool QTextFormat::operator!=(const QTextFormat &other) const |
|
1182 |
||
1183 |
Returns true if this text format is different from the \a other text |
|
1184 |
format. |
|
1185 |
*/ |
|
1186 |
||
1187 |
||
1188 |
/*! |
|
1189 |
\fn bool QTextFormat::operator==(const QTextFormat &other) const |
|
1190 |
||
1191 |
Returns true if this text format is the same as the \a other text |
|
1192 |
format. |
|
1193 |
*/ |
|
1194 |
bool QTextFormat::operator==(const QTextFormat &rhs) const |
|
1195 |
{ |
|
1196 |
if (format_type != rhs.format_type) |
|
1197 |
return false; |
|
1198 |
||
1199 |
if (d == rhs.d) |
|
1200 |
return true; |
|
1201 |
||
1202 |
if (d && d->props.isEmpty() && !rhs.d) |
|
1203 |
return true; |
|
1204 |
||
1205 |
if (!d && rhs.d && rhs.d->props.isEmpty()) |
|
1206 |
return true; |
|
1207 |
||
1208 |
if (!d || !rhs.d) |
|
1209 |
return false; |
|
1210 |
||
1211 |
return *d == *rhs.d; |
|
1212 |
} |
|
1213 |
||
1214 |
/*! |
|
1215 |
\class QTextCharFormat |
|
1216 |
\reentrant |
|
1217 |
||
1218 |
\brief The QTextCharFormat class provides formatting information for |
|
1219 |
characters in a QTextDocument. |
|
1220 |
||
1221 |
\ingroup richtext-processing |
|
1222 |
||
1223 |
The character format of text in a document specifies the visual properties |
|
1224 |
of the text, as well as information about its role in a hypertext document. |
|
1225 |
||
1226 |
The font used can be set by supplying a font to the setFont() function, and |
|
1227 |
each aspect of its appearance can be adjusted to give the desired effect. |
|
1228 |
setFontFamily() and setFontPointSize() define the font's family (e.g. Times) |
|
1229 |
and printed size; setFontWeight() and setFontItalic() provide control over |
|
1230 |
the style of the font. setFontUnderline(), setFontOverline(), |
|
1231 |
setFontStrikeOut(), and setFontFixedPitch() provide additional effects for |
|
1232 |
text. |
|
1233 |
||
1234 |
The color is set with setForeground(). If the text is intended to be used |
|
1235 |
as an anchor (for hyperlinks), this can be enabled with setAnchor(). The |
|
1236 |
setAnchorHref() and setAnchorNames() functions are used to specify the |
|
1237 |
information about the hyperlink's destination and the anchor's name. |
|
1238 |
||
1239 |
\sa QTextFormat QTextBlockFormat QTextTableFormat QTextListFormat |
|
1240 |
*/ |
|
1241 |
||
1242 |
/*! |
|
1243 |
\enum QTextCharFormat::VerticalAlignment |
|
1244 |
||
1245 |
This enum describes the ways that adjacent characters can be vertically |
|
1246 |
aligned. |
|
1247 |
||
1248 |
\value AlignNormal Adjacent characters are positioned in the standard |
|
1249 |
way for text in the writing system in use. |
|
1250 |
\value AlignSuperScript Characters are placed above the baseline for |
|
1251 |
normal text. |
|
1252 |
\value AlignSubScript Characters are placed below the baseline for |
|
1253 |
normal text. |
|
1254 |
\value AlignMiddle The center of the object is vertically aligned with the base line. |
|
1255 |
Currently, this is only implemented for inline objects. |
|
1256 |
\value AlignBottom The bottom edge of the object is vertically aligned with |
|
1257 |
the base line. |
|
1258 |
\value AlignTop The top edge of the object is vertically aligned with |
|
1259 |
the base line. |
|
1260 |
*/ |
|
1261 |
||
1262 |
/*! |
|
1263 |
\enum QTextCharFormat::UnderlineStyle |
|
1264 |
||
1265 |
This enum describes the different ways drawing underlined text. |
|
1266 |
||
1267 |
\value NoUnderline Text is draw without any underlining decoration. |
|
1268 |
\value SingleUnderline A line is drawn using Qt::SolidLine. |
|
1269 |
\value DashUnderline Dashes are drawn using Qt::DashLine. |
|
1270 |
\value DotLine Dots are drawn using Qt::DotLine; |
|
1271 |
\value DashDotLine Dashs and dots are drawn using Qt::DashDotLine. |
|
1272 |
\value DashDotDotLine Underlines draw drawn using Qt::DashDotDotLine. |
|
1273 |
\value WaveUnderline The text is underlined using a wave shaped line. |
|
1274 |
\value SpellCheckUnderline The underline is drawn depending on the QStyle::SH_SpellCeckUnderlineStyle |
|
1275 |
style hint of the QApplication style. By default this is mapped to |
|
1276 |
WaveUnderline, on Mac OS X it is mapped to DashDotLine. |
|
1277 |
||
1278 |
\sa Qt::PenStyle |
|
1279 |
*/ |
|
1280 |
||
1281 |
/*! |
|
1282 |
\fn QTextCharFormat::QTextCharFormat() |
|
1283 |
||
1284 |
Constructs a new character format object. |
|
1285 |
*/ |
|
1286 |
QTextCharFormat::QTextCharFormat() : QTextFormat(CharFormat) {} |
|
1287 |
||
1288 |
/*! |
|
1289 |
\internal |
|
1290 |
\fn QTextCharFormat::QTextCharFormat(const QTextFormat &other) |
|
1291 |
||
1292 |
Creates a new character format with the same attributes as the \a given |
|
1293 |
text format. |
|
1294 |
*/ |
|
1295 |
QTextCharFormat::QTextCharFormat(const QTextFormat &fmt) |
|
1296 |
: QTextFormat(fmt) |
|
1297 |
{ |
|
1298 |
} |
|
1299 |
||
1300 |
/*! |
|
1301 |
\fn bool QTextCharFormat::isValid() const |
|
1302 |
||
1303 |
Returns true if this character format is valid; otherwise returns |
|
1304 |
false. |
|
1305 |
*/ |
|
1306 |
||
1307 |
||
1308 |
/*! |
|
1309 |
\fn void QTextCharFormat::setFontFamily(const QString &family) |
|
1310 |
||
1311 |
Sets the text format's font \a family. |
|
1312 |
||
1313 |
\sa setFont() |
|
1314 |
*/ |
|
1315 |
||
1316 |
||
1317 |
/*! |
|
1318 |
\fn QString QTextCharFormat::fontFamily() const |
|
1319 |
||
1320 |
Returns the text format's font family. |
|
1321 |
||
1322 |
\sa font() |
|
1323 |
*/ |
|
1324 |
||
1325 |
||
1326 |
/*! |
|
1327 |
\fn void QTextCharFormat::setFontPointSize(qreal size) |
|
1328 |
||
1329 |
Sets the text format's font \a size. |
|
1330 |
||
1331 |
\sa setFont() |
|
1332 |
*/ |
|
1333 |
||
1334 |
||
1335 |
/*! |
|
1336 |
\fn qreal QTextCharFormat::fontPointSize() const |
|
1337 |
||
1338 |
Returns the font size used to display text in this format. |
|
1339 |
||
1340 |
\sa font() |
|
1341 |
*/ |
|
1342 |
||
1343 |
||
1344 |
/*! |
|
1345 |
\fn void QTextCharFormat::setFontWeight(int weight) |
|
1346 |
||
1347 |
Sets the text format's font weight to \a weight. |
|
1348 |
||
1349 |
\sa setFont(), QFont::Weight |
|
1350 |
*/ |
|
1351 |
||
1352 |
||
1353 |
/*! |
|
1354 |
\fn int QTextCharFormat::fontWeight() const |
|
1355 |
||
1356 |
Returns the text format's font weight. |
|
1357 |
||
1358 |
\sa font(), QFont::Weight |
|
1359 |
*/ |
|
1360 |
||
1361 |
||
1362 |
/*! |
|
1363 |
\fn void QTextCharFormat::setFontItalic(bool italic) |
|
1364 |
||
1365 |
If \a italic is true, sets the text format's font to be italic; otherwise |
|
1366 |
the font will be non-italic. |
|
1367 |
||
1368 |
\sa setFont() |
|
1369 |
*/ |
|
1370 |
||
1371 |
||
1372 |
/*! |
|
1373 |
\fn bool QTextCharFormat::fontItalic() const |
|
1374 |
||
1375 |
Returns true if the text format's font is italic; otherwise |
|
1376 |
returns false. |
|
1377 |
||
1378 |
\sa font() |
|
1379 |
*/ |
|
1380 |
||
1381 |
||
1382 |
/*! |
|
1383 |
\fn void QTextCharFormat::setFontUnderline(bool underline) |
|
1384 |
||
1385 |
If \a underline is true, sets the text format's font to be underlined; |
|
1386 |
otherwise it is displayed non-underlined. |
|
1387 |
||
1388 |
\sa setFont() |
|
1389 |
*/ |
|
1390 |
||
1391 |
||
1392 |
/*! |
|
1393 |
\fn bool QTextCharFormat::fontUnderline() const |
|
1394 |
||
1395 |
Returns true if the text format's font is underlined; otherwise |
|
1396 |
returns false. |
|
1397 |
||
1398 |
\sa font() |
|
1399 |
*/ |
|
1400 |
bool QTextCharFormat::fontUnderline() const |
|
1401 |
{ |
|
1402 |
if (hasProperty(TextUnderlineStyle)) |
|
1403 |
return underlineStyle() == SingleUnderline; |
|
1404 |
return boolProperty(FontUnderline); |
|
1405 |
} |
|
1406 |
||
1407 |
/*! |
|
1408 |
\fn UnderlineStyle QTextCharFormat::underlineStyle() const |
|
1409 |
\since 4.2 |
|
1410 |
||
1411 |
Returns the style of underlining the text. |
|
1412 |
*/ |
|
1413 |
||
1414 |
/*! |
|
1415 |
\fn void QTextCharFormat::setUnderlineStyle(UnderlineStyle style) |
|
1416 |
\since 4.2 |
|
1417 |
||
1418 |
Sets the style of underlining the text to \a style. |
|
1419 |
*/ |
|
1420 |
void QTextCharFormat::setUnderlineStyle(UnderlineStyle style) |
|
1421 |
{ |
|
1422 |
setProperty(TextUnderlineStyle, style); |
|
1423 |
// for compatibility |
|
1424 |
setProperty(FontUnderline, style == SingleUnderline); |
|
1425 |
} |
|
1426 |
||
1427 |
/*! |
|
1428 |
\fn void QTextCharFormat::setFontOverline(bool overline) |
|
1429 |
||
1430 |
If \a overline is true, sets the text format's font to be overlined; |
|
1431 |
otherwise the font is displayed non-overlined. |
|
1432 |
||
1433 |
\sa setFont() |
|
1434 |
*/ |
|
1435 |
||
1436 |
||
1437 |
/*! |
|
1438 |
\fn bool QTextCharFormat::fontOverline() const |
|
1439 |
||
1440 |
Returns true if the text format's font is overlined; otherwise |
|
1441 |
returns false. |
|
1442 |
||
1443 |
\sa font() |
|
1444 |
*/ |
|
1445 |
||
1446 |
||
1447 |
/*! |
|
1448 |
\fn void QTextCharFormat::setFontStrikeOut(bool strikeOut) |
|
1449 |
||
1450 |
If \a strikeOut is true, sets the text format's font with strike-out |
|
1451 |
enabled (with a horizontal line through it); otherwise it is displayed |
|
1452 |
without strikeout. |
|
1453 |
||
1454 |
\sa setFont() |
|
1455 |
*/ |
|
1456 |
||
1457 |
||
1458 |
/*! |
|
1459 |
\fn bool QTextCharFormat::fontStrikeOut() const |
|
1460 |
||
1461 |
Returns true if the text format's font is struck out (has a horizontal line |
|
1462 |
drawn through it); otherwise returns false. |
|
1463 |
||
1464 |
\sa font() |
|
1465 |
*/ |
|
1466 |
||
1467 |
||
1468 |
/*! |
|
1469 |
\since 4.5 |
|
1470 |
\fn void QTextCharFormat::setFontStyleHint(QFont::StyleHint hint, QFont::StyleStrategy strategy) |
|
1471 |
||
1472 |
Sets the font style \a hint and \a strategy. |
|
1473 |
||
1474 |
Qt does not support style hints on X11 since this information is not provided by the window system. |
|
1475 |
||
1476 |
\sa setFont() |
|
1477 |
\sa QFont::setStyleHint() |
|
1478 |
*/ |
|
1479 |
||
1480 |
||
1481 |
/*! |
|
1482 |
\since 4.5 |
|
1483 |
\fn void QTextCharFormat::setFontStyleStrategy(QFont::StyleStrategy strategy) |
|
1484 |
||
1485 |
Sets the font style \a strategy. |
|
1486 |
||
1487 |
\sa setFont() |
|
1488 |
\sa QFont::setStyleStrategy() |
|
1489 |
*/ |
|
1490 |
||
1491 |
||
1492 |
/*! |
|
1493 |
\since 4.5 |
|
1494 |
\fn void QTextCharFormat::setFontKerning(bool enable) |
|
1495 |
Enables kerning for this font if \a enable is true; otherwise disables it. |
|
1496 |
||
1497 |
When kerning is enabled, glyph metrics do not add up anymore, even for |
|
1498 |
Latin text. In other words, the assumption that width('a') + width('b') |
|
1499 |
is equal to width("ab") is not neccesairly true. |
|
1500 |
||
1501 |
\sa setFont() |
|
1502 |
*/ |
|
1503 |
||
1504 |
||
1505 |
/*! |
|
1506 |
\fn QTextCharFormat::StyleHint QTextCharFormat::fontStyleHint() const |
|
1507 |
\since 4.5 |
|
1508 |
||
1509 |
Returns the font style hint. |
|
1510 |
||
1511 |
\sa setFontStyleHint(), font() |
|
1512 |
*/ |
|
1513 |
||
1514 |
||
1515 |
/*! |
|
1516 |
\since 4.5 |
|
1517 |
\fn QTextCharFormat::StyleStrategy QTextCharFormat::fontStyleStrategy() const |
|
1518 |
||
1519 |
Returns the current font style strategy. |
|
1520 |
||
1521 |
\sa setFontStyleStrategy() |
|
1522 |
\sa font() |
|
1523 |
*/ |
|
1524 |
||
1525 |
||
1526 |
/*! |
|
1527 |
\since 4.5 |
|
1528 |
\fn bool QTextCharFormat::fontKerning() const |
|
1529 |
Returns true if the font kerning is enabled. |
|
1530 |
||
1531 |
\sa setFontKerning() |
|
1532 |
\sa font() |
|
1533 |
*/ |
|
1534 |
||
1535 |
||
1536 |
/*! |
|
1537 |
\fn void QTextCharFormat::setFontFixedPitch(bool fixedPitch) |
|
1538 |
||
1539 |
If \a fixedPitch is true, sets the text format's font to be fixed pitch; |
|
1540 |
otherwise a non-fixed pitch font is used. |
|
1541 |
||
1542 |
\sa setFont() |
|
1543 |
*/ |
|
1544 |
||
1545 |
||
1546 |
/*! |
|
1547 |
\fn bool QTextCharFormat::fontFixedPitch() const |
|
1548 |
||
1549 |
Returns true if the text format's font is fixed pitch; otherwise |
|
1550 |
returns false. |
|
1551 |
||
1552 |
\sa font() |
|
1553 |
*/ |
|
1554 |
||
1555 |
||
1556 |
/*! |
|
1557 |
\fn QPen QTextCharFormat::textOutline() const |
|
1558 |
||
1559 |
Returns the pen used to draw the outlines of characters in this format. |
|
1560 |
*/ |
|
1561 |
||
1562 |
||
1563 |
/*! |
|
1564 |
\fn void QTextCharFormat::setTextOutline(const QPen &pen) |
|
1565 |
||
1566 |
Sets the pen used to draw the outlines of characters to the given \a pen. |
|
1567 |
*/ |
|
1568 |
||
1569 |
/*! |
|
1570 |
\fn void QTextCharFormat::setToolTip(const QString &text) |
|
1571 |
\since 4.3 |
|
1572 |
||
1573 |
Sets the tool tip for a fragment of text to the given \a text. |
|
1574 |
*/ |
|
1575 |
||
1576 |
/*! |
|
1577 |
\fn QString QTextCharFormat::toolTip() const |
|
1578 |
\since 4.3 |
|
1579 |
||
1580 |
Returns the tool tip that is displayed for a fragment of text. |
|
1581 |
*/ |
|
1582 |
||
1583 |
/*! |
|
1584 |
\fn void QTextFormat::setForeground(const QBrush &brush) |
|
1585 |
||
1586 |
Sets the foreground brush to the specified \a brush. The foreground |
|
1587 |
brush is mostly used to render text. |
|
1588 |
||
1589 |
\sa foreground() clearForeground() setBackground() |
|
1590 |
*/ |
|
1591 |
||
1592 |
||
1593 |
/*! |
|
1594 |
\fn QBrush QTextFormat::foreground() const |
|
1595 |
||
1596 |
Returns the brush used to render foreground details, such as text, |
|
1597 |
frame outlines, and table borders. |
|
1598 |
||
1599 |
\sa setForeground() clearForeground() background() |
|
1600 |
*/ |
|
1601 |
||
1602 |
/*! |
|
1603 |
\fn void QTextFormat::clearForeground() |
|
1604 |
||
1605 |
Clears the brush used to paint the document's foreground. The default |
|
1606 |
brush will be used. |
|
1607 |
||
1608 |
\sa foreground() setForeground() clearBackground() |
|
1609 |
*/ |
|
1610 |
||
1611 |
||
1612 |
/*! |
|
1613 |
\fn void QTextCharFormat::setAnchor(bool anchor) |
|
1614 |
||
1615 |
If \a anchor is true, text with this format represents an anchor, and is |
|
1616 |
formatted in the appropriate way; otherwise the text is formatted normally. |
|
1617 |
(Anchors are hyperlinks which are often shown underlined and in a different |
|
1618 |
color from plain text.) |
|
1619 |
||
1620 |
The way the text is rendered is independent of whether or not the format |
|
1621 |
has a valid anchor defined. Use setAnchorHref(), and optionally |
|
1622 |
setAnchorNames() to create a hypertext link. |
|
1623 |
||
1624 |
\sa isAnchor() |
|
1625 |
*/ |
|
1626 |
||
1627 |
||
1628 |
/*! |
|
1629 |
\fn bool QTextCharFormat::isAnchor() const |
|
1630 |
||
1631 |
Returns true if the text is formatted as an anchor; otherwise |
|
1632 |
returns false. |
|
1633 |
||
1634 |
\sa setAnchor() setAnchorHref() setAnchorNames() |
|
1635 |
*/ |
|
1636 |
||
1637 |
||
1638 |
/*! |
|
1639 |
\fn void QTextCharFormat::setAnchorHref(const QString &value) |
|
1640 |
||
1641 |
Sets the hypertext link for the text format to the given \a value. |
|
1642 |
This is typically a URL like "http://example.com/index.html". |
|
1643 |
||
1644 |
The anchor will be displayed with the \a value as its display text; |
|
1645 |
if you want to display different text call setAnchorNames(). |
|
1646 |
||
1647 |
To format the text as a hypertext link use setAnchor(). |
|
1648 |
*/ |
|
1649 |
||
1650 |
||
1651 |
/*! |
|
1652 |
\fn QString QTextCharFormat::anchorHref() const |
|
1653 |
||
1654 |
Returns the text format's hypertext link, or an empty string if |
|
1655 |
none has been set. |
|
1656 |
*/ |
|
1657 |
||
1658 |
||
1659 |
/*! |
|
1660 |
\fn void QTextCharFormat::setAnchorName(const QString &name) |
|
1661 |
\obsolete |
|
1662 |
||
1663 |
This function is deprecated. Use setAnchorNames() instead. |
|
1664 |
||
1665 |
Sets the text format's anchor \a name. For the anchor to work as a |
|
1666 |
hyperlink, the destination must be set with setAnchorHref() and |
|
1667 |
the anchor must be enabled with setAnchor(). |
|
1668 |
*/ |
|
1669 |
||
1670 |
/*! |
|
1671 |
\fn void QTextCharFormat::setAnchorNames(const QStringList &names) |
|
1672 |
\since 4.3 |
|
1673 |
||
1674 |
Sets the text format's anchor \a names. For the anchor to work as a |
|
1675 |
hyperlink, the destination must be set with setAnchorHref() and |
|
1676 |
the anchor must be enabled with setAnchor(). |
|
1677 |
*/ |
|
1678 |
||
1679 |
/*! |
|
1680 |
\fn QString QTextCharFormat::anchorName() const |
|
1681 |
\obsolete |
|
1682 |
||
1683 |
This function is deprecated. Use anchorNames() instead. |
|
1684 |
||
1685 |
Returns the anchor name associated with this text format, or an empty |
|
1686 |
string if none has been set. If the anchor name is set, text with this |
|
1687 |
format can be the destination of a hypertext link. |
|
1688 |
*/ |
|
1689 |
QString QTextCharFormat::anchorName() const |
|
1690 |
{ |
|
1691 |
QVariant prop = property(AnchorName); |
|
1692 |
if (prop.userType() == QVariant::StringList) |
|
1693 |
return prop.toStringList().value(0); |
|
1694 |
else if (prop.userType() != QVariant::String) |
|
1695 |
return QString(); |
|
1696 |
return prop.toString(); |
|
1697 |
} |
|
1698 |
||
1699 |
/*! |
|
1700 |
\fn QStringList QTextCharFormat::anchorNames() const |
|
1701 |
\since 4.3 |
|
1702 |
||
1703 |
Returns the anchor names associated with this text format, or an empty |
|
1704 |
string list if none has been set. If the anchor names are set, text with this |
|
1705 |
format can be the destination of a hypertext link. |
|
1706 |
*/ |
|
1707 |
QStringList QTextCharFormat::anchorNames() const |
|
1708 |
{ |
|
1709 |
QVariant prop = property(AnchorName); |
|
1710 |
if (prop.userType() == QVariant::StringList) |
|
1711 |
return prop.toStringList(); |
|
1712 |
else if (prop.userType() != QVariant::String) |
|
1713 |
return QStringList(); |
|
1714 |
return QStringList(prop.toString()); |
|
1715 |
} |
|
1716 |
||
1717 |
||
1718 |
/*! |
|
1719 |
\fn void QTextCharFormat::setTableCellRowSpan(int tableCellRowSpan) |
|
1720 |
\internal |
|
1721 |
||
1722 |
If this character format is applied to characters in a table cell, |
|
1723 |
the cell will span \a tableCellRowSpan rows. |
|
1724 |
*/ |
|
1725 |
||
1726 |
||
1727 |
/*! |
|
1728 |
\fn int QTextCharFormat::tableCellRowSpan() const |
|
1729 |
\internal |
|
1730 |
||
1731 |
If this character format is applied to characters in a table cell, |
|
1732 |
this function returns the number of rows spanned by the text (this may |
|
1733 |
be 1); otherwise it returns 1. |
|
1734 |
*/ |
|
1735 |
||
1736 |
/*! |
|
1737 |
\fn void QTextCharFormat::setTableCellColumnSpan(int tableCellColumnSpan) |
|
1738 |
\internal |
|
1739 |
||
1740 |
If this character format is applied to characters in a table cell, |
|
1741 |
the cell will span \a tableCellColumnSpan columns. |
|
1742 |
*/ |
|
1743 |
||
1744 |
||
1745 |
/*! |
|
1746 |
\fn int QTextCharFormat::tableCellColumnSpan() const |
|
1747 |
\internal |
|
1748 |
||
1749 |
If this character format is applied to characters in a table cell, |
|
1750 |
this function returns the number of columns spanned by the text (this |
|
1751 |
may be 1); otherwise it returns 1. |
|
1752 |
*/ |
|
1753 |
||
1754 |
/*! |
|
1755 |
\fn void QTextCharFormat::setUnderlineColor(const QColor &color) |
|
1756 |
||
1757 |
Sets the underline color used for the characters with this format to |
|
1758 |
the \a color specified. |
|
1759 |
||
1760 |
\sa underlineColor() |
|
1761 |
*/ |
|
1762 |
||
1763 |
/*! |
|
1764 |
\fn QColor QTextCharFormat::underlineColor() const |
|
1765 |
||
1766 |
Returns the color used to underline the characters with this format. |
|
1767 |
||
1768 |
\sa setUnderlineColor() |
|
1769 |
*/ |
|
1770 |
||
1771 |
/*! |
|
1772 |
\fn void QTextCharFormat::setVerticalAlignment(VerticalAlignment alignment) |
|
1773 |
||
1774 |
Sets the vertical alignment used for the characters with this format to |
|
1775 |
the \a alignment specified. |
|
1776 |
||
1777 |
\sa verticalAlignment() |
|
1778 |
*/ |
|
1779 |
||
1780 |
/*! |
|
1781 |
\fn VerticalAlignment QTextCharFormat::verticalAlignment() const |
|
1782 |
||
1783 |
Returns the vertical alignment used for characters with this format. |
|
1784 |
||
1785 |
\sa setVerticalAlignment() |
|
1786 |
*/ |
|
1787 |
||
1788 |
/*! |
|
1789 |
Sets the text format's \a font. |
|
1790 |
*/ |
|
1791 |
void QTextCharFormat::setFont(const QFont &font) |
|
1792 |
{ |
|
1793 |
setFontFamily(font.family()); |
|
1794 |
||
1795 |
const qreal pointSize = font.pointSizeF(); |
|
1796 |
if (pointSize > 0) { |
|
1797 |
setFontPointSize(pointSize); |
|
1798 |
} else { |
|
1799 |
const int pixelSize = font.pixelSize(); |
|
1800 |
if (pixelSize > 0) |
|
1801 |
setProperty(QTextFormat::FontPixelSize, pixelSize); |
|
1802 |
} |
|
1803 |
||
1804 |
setFontWeight(font.weight()); |
|
1805 |
setFontItalic(font.italic()); |
|
1806 |
setUnderlineStyle(font.underline() ? SingleUnderline : NoUnderline); |
|
1807 |
setFontOverline(font.overline()); |
|
1808 |
setFontStrikeOut(font.strikeOut()); |
|
1809 |
setFontFixedPitch(font.fixedPitch()); |
|
1810 |
setFontCapitalization(font.capitalization()); |
|
1811 |
setFontWordSpacing(font.wordSpacing()); |
|
1812 |
if (font.letterSpacingType() == QFont::PercentageSpacing) |
|
1813 |
setFontLetterSpacing(font.letterSpacing()); |
|
1814 |
setFontStyleHint(font.styleHint()); |
|
1815 |
setFontStyleStrategy(font.styleStrategy()); |
|
1816 |
setFontKerning(font.kerning()); |
|
1817 |
} |
|
1818 |
||
1819 |
/*! |
|
1820 |
Returns the font for this character format. |
|
1821 |
*/ |
|
1822 |
QFont QTextCharFormat::font() const |
|
1823 |
{ |
|
1824 |
return d ? d->font() : QFont(); |
|
1825 |
} |
|
1826 |
||
1827 |
/*! |
|
1828 |
\class QTextBlockFormat |
|
1829 |
\reentrant |
|
1830 |
||
1831 |
\brief The QTextBlockFormat class provides formatting information for |
|
1832 |
blocks of text in a QTextDocument. |
|
1833 |
||
1834 |
\ingroup richtext-processing |
|
1835 |
||
1836 |
A document is composed of a list of blocks, represented by QTextBlock |
|
1837 |
objects. Each block can contain an item of some kind, such as a |
|
1838 |
paragraph of text, a table, a list, or an image. Every block has an |
|
1839 |
associated QTextBlockFormat that specifies its characteristics. |
|
1840 |
||
1841 |
To cater for left-to-right and right-to-left languages you can set |
|
1842 |
a block's direction with setDirection(). Paragraph alignment is |
|
1843 |
set with setAlignment(). Margins are controlled by setTopMargin(), |
|
1844 |
setBottomMargin(), setLeftMargin(), setRightMargin(). Overall |
|
1845 |
indentation is set with setIndent(), the indentation of the first |
|
1846 |
line with setTextIndent(). |
|
1847 |
||
1848 |
Line breaking can be enabled and disabled with setNonBreakableLines(). |
|
1849 |
||
1850 |
The brush used to paint the paragraph's background |
|
1851 |
is set with \l{QTextFormat::setBackground()}{setBackground()}, and other |
|
1852 |
aspects of the text's appearance can be customized by using the |
|
1853 |
\l{QTextFormat::setProperty()}{setProperty()} function with the |
|
1854 |
\c OutlinePen, \c ForegroundBrush, and \c BackgroundBrush |
|
1855 |
\l{QTextFormat::Property} values. |
|
1856 |
||
1857 |
If a text block is part of a list, it can also have a list format that |
|
1858 |
is accessible with the listFormat() function. |
|
1859 |
||
1860 |
\sa QTextBlock, QTextCharFormat |
|
1861 |
*/ |
|
1862 |
||
1863 |
/*! |
|
1864 |
\fn QTextBlockFormat::QTextBlockFormat() |
|
1865 |
||
1866 |
Constructs a new QTextBlockFormat. |
|
1867 |
*/ |
|
1868 |
QTextBlockFormat::QTextBlockFormat() : QTextFormat(BlockFormat) {} |
|
1869 |
||
1870 |
/*! |
|
1871 |
\internal |
|
1872 |
\fn QTextBlockFormat::QTextBlockFormat(const QTextFormat &other) |
|
1873 |
||
1874 |
Creates a new block format with the same attributes as the \a given |
|
1875 |
text format. |
|
1876 |
*/ |
|
1877 |
QTextBlockFormat::QTextBlockFormat(const QTextFormat &fmt) |
|
1878 |
: QTextFormat(fmt) |
|
1879 |
{ |
|
1880 |
} |
|
1881 |
||
1882 |
/*! |
|
1883 |
\since 4.4 |
|
1884 |
Sets the tab positions for the text block to those specified by |
|
1885 |
\a tabs. |
|
1886 |
||
1887 |
\sa tabPositions() |
|
1888 |
*/ |
|
1889 |
void QTextBlockFormat::setTabPositions(const QList<QTextOption::Tab> &tabs) |
|
1890 |
{ |
|
1891 |
QList<QVariant> list; |
|
1892 |
QList<QTextOption::Tab>::ConstIterator iter = tabs.constBegin(); |
|
1893 |
while (iter != tabs.constEnd()) { |
|
1894 |
QVariant v; |
|
1895 |
qVariantSetValue<QTextOption::Tab>(v, *iter); |
|
1896 |
list.append(v); |
|
1897 |
++iter; |
|
1898 |
} |
|
1899 |
setProperty(TabPositions, list); |
|
1900 |
} |
|
1901 |
||
1902 |
/*! |
|
1903 |
\since 4.4 |
|
1904 |
Returns a list of tab positions defined for the text block. |
|
1905 |
||
1906 |
\sa setTabPositions() |
|
1907 |
*/ |
|
1908 |
QList<QTextOption::Tab> QTextBlockFormat::tabPositions() const |
|
1909 |
{ |
|
1910 |
QVariant variant = property(TabPositions); |
|
1911 |
if(variant.isNull()) |
|
1912 |
return QList<QTextOption::Tab>(); |
|
1913 |
QList<QTextOption::Tab> answer; |
|
1914 |
QList<QVariant> variantsList = qvariant_cast<QList<QVariant> >(variant); |
|
1915 |
QList<QVariant>::Iterator iter = variantsList.begin(); |
|
1916 |
while(iter != variantsList.end()) { |
|
1917 |
answer.append( qVariantValue<QTextOption::Tab>(*iter)); |
|
1918 |
++iter; |
|
1919 |
} |
|
1920 |
return answer; |
|
1921 |
} |
|
1922 |
||
1923 |
/*! |
|
1924 |
\fn QTextBlockFormat::isValid() const |
|
1925 |
||
1926 |
Returns true if this block format is valid; otherwise returns |
|
1927 |
false. |
|
1928 |
*/ |
|
1929 |
||
1930 |
/*! |
|
1931 |
\fn void QTextFormat::setLayoutDirection(Qt::LayoutDirection direction) |
|
1932 |
||
1933 |
Sets the document's layout direction to the specified \a direction. |
|
1934 |
||
1935 |
\sa layoutDirection() |
|
1936 |
*/ |
|
1937 |
||
1938 |
||
1939 |
/*! |
|
1940 |
\fn Qt::LayoutDirection QTextFormat::layoutDirection() const |
|
1941 |
||
1942 |
Returns the document's layout direction. |
|
1943 |
||
1944 |
\sa setLayoutDirection() |
|
1945 |
*/ |
|
1946 |
||
1947 |
||
1948 |
/*! |
|
1949 |
\fn void QTextBlockFormat::setAlignment(Qt::Alignment alignment) |
|
1950 |
||
1951 |
Sets the paragraph's \a alignment. |
|
1952 |
||
1953 |
\sa alignment() |
|
1954 |
*/ |
|
1955 |
||
1956 |
||
1957 |
/*! |
|
1958 |
\fn Qt::Alignment QTextBlockFormat::alignment() const |
|
1959 |
||
1960 |
Returns the paragraph's alignment. |
|
1961 |
||
1962 |
\sa setAlignment() |
|
1963 |
*/ |
|
1964 |
||
1965 |
||
1966 |
/*! |
|
1967 |
\fn void QTextBlockFormat::setTopMargin(qreal margin) |
|
1968 |
||
1969 |
Sets the paragraph's top \a margin. |
|
1970 |
||
1971 |
\sa topMargin() setBottomMargin() setLeftMargin() setRightMargin() |
|
1972 |
*/ |
|
1973 |
||
1974 |
||
1975 |
/*! |
|
1976 |
\fn qreal QTextBlockFormat::topMargin() const |
|
1977 |
||
1978 |
Returns the paragraph's top margin. |
|
1979 |
||
1980 |
\sa setTopMargin() bottomMargin() |
|
1981 |
*/ |
|
1982 |
||
1983 |
||
1984 |
/*! |
|
1985 |
\fn void QTextBlockFormat::setBottomMargin(qreal margin) |
|
1986 |
||
1987 |
Sets the paragraph's bottom \a margin. |
|
1988 |
||
1989 |
\sa bottomMargin() setTopMargin() setLeftMargin() setRightMargin() |
|
1990 |
*/ |
|
1991 |
||
1992 |
||
1993 |
/*! |
|
1994 |
\fn qreal QTextBlockFormat::bottomMargin() const |
|
1995 |
||
1996 |
Returns the paragraph's bottom margin. |
|
1997 |
||
1998 |
\sa setBottomMargin() topMargin() |
|
1999 |
*/ |
|
2000 |
||
2001 |
||
2002 |
/*! |
|
2003 |
\fn void QTextBlockFormat::setLeftMargin(qreal margin) |
|
2004 |
||
2005 |
Sets the paragraph's left \a margin. Indentation can be applied separately |
|
2006 |
with setIndent(). |
|
2007 |
||
2008 |
\sa leftMargin() setRightMargin() setTopMargin() setBottomMargin() |
|
2009 |
*/ |
|
2010 |
||
2011 |
||
2012 |
/*! |
|
2013 |
\fn qreal QTextBlockFormat::leftMargin() const |
|
2014 |
||
2015 |
Returns the paragraph's left margin. |
|
2016 |
||
2017 |
\sa setLeftMargin() rightMargin() indent() |
|
2018 |
*/ |
|
2019 |
||
2020 |
||
2021 |
/*! |
|
2022 |
\fn void QTextBlockFormat::setRightMargin(qreal margin) |
|
2023 |
||
2024 |
Sets the paragraph's right \a margin. |
|
2025 |
||
2026 |
\sa rightMargin() setLeftMargin() setTopMargin() setBottomMargin() |
|
2027 |
*/ |
|
2028 |
||
2029 |
||
2030 |
/*! |
|
2031 |
\fn qreal QTextBlockFormat::rightMargin() const |
|
2032 |
||
2033 |
Returns the paragraph's right margin. |
|
2034 |
||
2035 |
\sa setRightMargin() leftMargin() |
|
2036 |
*/ |
|
2037 |
||
2038 |
||
2039 |
/*! |
|
2040 |
\fn void QTextBlockFormat::setTextIndent(qreal indent) |
|
2041 |
||
2042 |
Sets the \a indent for the first line in the block. This allows the first |
|
2043 |
line of a paragraph to be indented differently to the other lines, |
|
2044 |
enhancing the readability of the text. |
|
2045 |
||
2046 |
\sa textIndent() setLeftMargin() setRightMargin() setTopMargin() setBottomMargin() |
|
2047 |
*/ |
|
2048 |
||
2049 |
||
2050 |
/*! |
|
2051 |
\fn qreal QTextBlockFormat::textIndent() const |
|
2052 |
||
2053 |
Returns the paragraph's text indent. |
|
2054 |
||
2055 |
\sa setTextIndent() |
|
2056 |
*/ |
|
2057 |
||
2058 |
||
2059 |
/*! |
|
2060 |
\fn void QTextBlockFormat::setIndent(int indentation) |
|
2061 |
||
2062 |
Sets the paragraph's \a indentation. Margins are set independently of |
|
2063 |
indentation with setLeftMargin() and setTextIndent(). |
|
2064 |
The \a indentation is an integer that is multiplied with the document-wide |
|
2065 |
standard indent, resulting in the actual indent of the paragraph. |
|
2066 |
||
2067 |
\sa indent() QTextDocument::indentWidth() |
|
2068 |
*/ |
|
2069 |
||
2070 |
||
2071 |
/*! |
|
2072 |
\fn int QTextBlockFormat::indent() const |
|
2073 |
||
2074 |
Returns the paragraph's indent. |
|
2075 |
||
2076 |
\sa setIndent() |
|
2077 |
*/ |
|
2078 |
||
2079 |
||
2080 |
/*! |
|
2081 |
\fn void QTextBlockFormat::setNonBreakableLines(bool b) |
|
2082 |
||
2083 |
If \a b is true, the lines in the paragraph are treated as |
|
2084 |
non-breakable; otherwise they are breakable. |
|
2085 |
||
2086 |
\sa nonBreakableLines() |
|
2087 |
*/ |
|
2088 |
||
2089 |
||
2090 |
/*! |
|
2091 |
\fn bool QTextBlockFormat::nonBreakableLines() const |
|
2092 |
||
2093 |
Returns true if the lines in the paragraph are non-breakable; |
|
2094 |
otherwise returns false. |
|
2095 |
||
2096 |
\sa setNonBreakableLines() |
|
2097 |
*/ |
|
2098 |
||
2099 |
/*! |
|
2100 |
\fn QTextFormat::PageBreakFlags QTextBlockFormat::pageBreakPolicy() const |
|
2101 |
\since 4.2 |
|
2102 |
||
2103 |
Returns the currently set page break policy for the paragraph. The default is |
|
2104 |
QTextFormat::PageBreak_Auto. |
|
2105 |
||
2106 |
\sa setPageBreakPolicy() |
|
2107 |
*/ |
|
2108 |
||
2109 |
/*! |
|
2110 |
\fn void QTextBlockFormat::setPageBreakPolicy(PageBreakFlags policy) |
|
2111 |
\since 4.2 |
|
2112 |
||
2113 |
Sets the page break policy for the paragraph to \a policy. |
|
2114 |
||
2115 |
\sa pageBreakPolicy() |
|
2116 |
*/ |
|
2117 |
||
2118 |
/*! |
|
2119 |
\class QTextListFormat |
|
2120 |
\reentrant |
|
2121 |
||
2122 |
\brief The QTextListFormat class provides formatting information for |
|
2123 |
lists in a QTextDocument. |
|
2124 |
||
2125 |
\ingroup richtext-processing |
|
2126 |
||
2127 |
A list is composed of one or more items, represented as text blocks. |
|
2128 |
The list's format specifies the appearance of items in the list. |
|
2129 |
In particular, it determines the indentation and the style of each item. |
|
2130 |
||
2131 |
The indentation of the items is an integer value that causes each item to |
|
2132 |
be offset from the left margin by a certain amount. This value is read with |
|
2133 |
indent() and set with setIndent(). |
|
2134 |
||
2135 |
The style used to decorate each item is set with setStyle() and can be read |
|
2136 |
with the style() function. The style controls the type of bullet points and |
|
2137 |
numbering scheme used for items in the list. Note that lists that use the |
|
2138 |
decimal numbering scheme begin counting at 1 rather than 0. |
|
2139 |
||
2140 |
\sa QTextList |
|
2141 |
*/ |
|
2142 |
||
2143 |
/*! |
|
2144 |
\enum QTextListFormat::Style |
|
2145 |
||
2146 |
This enum describes the symbols used to decorate list items: |
|
2147 |
||
2148 |
\value ListDisc a filled circle |
|
2149 |
\value ListCircle an empty circle |
|
2150 |
\value ListSquare a filled square |
|
2151 |
\value ListDecimal decimal values in ascending order |
|
2152 |
\value ListLowerAlpha lower case Latin characters in alphabetical order |
|
2153 |
\value ListUpperAlpha upper case Latin characters in alphabetical order |
|
2154 |
\value ListLowerRoman lower case roman numerals (supports up to 4999 items only) |
|
2155 |
\value ListUpperRoman upper case roman numerals (supports up to 4999 items only) |
|
2156 |
\omitvalue ListStyleUndefined |
|
2157 |
*/ |
|
2158 |
||
2159 |
/*! |
|
2160 |
\fn QTextListFormat::QTextListFormat() |
|
2161 |
||
2162 |
Constructs a new list format object. |
|
2163 |
*/ |
|
2164 |
QTextListFormat::QTextListFormat() |
|
2165 |
: QTextFormat(ListFormat) |
|
2166 |
{ |
|
2167 |
setIndent(1); |
|
2168 |
} |
|
2169 |
||
2170 |
/*! |
|
2171 |
\internal |
|
2172 |
\fn QTextListFormat::QTextListFormat(const QTextFormat &other) |
|
2173 |
||
2174 |
Creates a new list format with the same attributes as the \a given |
|
2175 |
text format. |
|
2176 |
*/ |
|
2177 |
QTextListFormat::QTextListFormat(const QTextFormat &fmt) |
|
2178 |
: QTextFormat(fmt) |
|
2179 |
{ |
|
2180 |
} |
|
2181 |
||
2182 |
/*! |
|
2183 |
\fn bool QTextListFormat::isValid() const |
|
2184 |
||
2185 |
Returns true if this list format is valid; otherwise |
|
2186 |
returns false. |
|
2187 |
*/ |
|
2188 |
||
2189 |
/*! |
|
2190 |
\fn void QTextListFormat::setStyle(Style style) |
|
2191 |
||
2192 |
Sets the list format's \a style. |
|
2193 |
||
2194 |
\sa style() Style |
|
2195 |
*/ |
|
2196 |
||
2197 |
/*! |
|
2198 |
\fn Style QTextListFormat::style() const |
|
2199 |
||
2200 |
Returns the list format's style. |
|
2201 |
||
2202 |
\sa setStyle() Style |
|
2203 |
*/ |
|
2204 |
||
2205 |
||
2206 |
/*! |
|
2207 |
\fn void QTextListFormat::setIndent(int indentation) |
|
2208 |
||
2209 |
Sets the list format's \a indentation. |
|
2210 |
The indentation is multiplied by the QTextDocument::indentWidth |
|
2211 |
property to get the effective indent in pixels. |
|
2212 |
||
2213 |
\sa indent() |
|
2214 |
*/ |
|
2215 |
||
2216 |
||
2217 |
/*! |
|
2218 |
\fn int QTextListFormat::indent() const |
|
2219 |
||
2220 |
Returns the list format's indentation. |
|
2221 |
The indentation is multiplied by the QTextDocument::indentWidth |
|
2222 |
property to get the effective indent in pixels. |
|
2223 |
||
2224 |
\sa setIndent() |
|
2225 |
*/ |
|
2226 |
||
2227 |
||
2228 |
/*! |
|
2229 |
\class QTextFrameFormat |
|
2230 |
\reentrant |
|
2231 |
||
2232 |
\brief The QTextFrameFormat class provides formatting information for |
|
2233 |
frames in a QTextDocument. |
|
2234 |
||
2235 |
\ingroup richtext-processing |
|
2236 |
||
2237 |
A text frame groups together one or more blocks of text, providing a layer |
|
2238 |
of structure larger than the paragraph. The format of a frame specifies |
|
2239 |
how it is rendered and positioned on the screen. It does not directly |
|
2240 |
specify the behavior of the text formatting within, but provides |
|
2241 |
constraints on the layout of its children. |
|
2242 |
||
2243 |
The frame format defines the width() and height() of the frame on the |
|
2244 |
screen. Each frame can have a border() that surrounds its contents with |
|
2245 |
a rectangular box. The border is surrounded by a margin() around the frame, |
|
2246 |
and the contents of the frame are kept separate from the border by the |
|
2247 |
frame's padding(). This scheme is similar to the box model used by Cascading |
|
2248 |
Style Sheets for HTML pages. |
|
2249 |
||
2250 |
\img qtextframe-style.png |
|
2251 |
||
2252 |
The position() of a frame is set using setPosition() and determines how it |
|
2253 |
is located relative to the surrounding text. |
|
2254 |
||
2255 |
The validity of a QTextFrameFormat object can be determined with the |
|
2256 |
isValid() function. |
|
2257 |
||
2258 |
\sa QTextFrame QTextBlockFormat |
|
2259 |
*/ |
|
2260 |
||
2261 |
/*! |
|
2262 |
\enum QTextFrameFormat::Position |
|
2263 |
||
2264 |
This enum describes how a frame is located relative to the surrounding text. |
|
2265 |
||
2266 |
\value InFlow |
|
2267 |
\value FloatLeft |
|
2268 |
\value FloatRight |
|
2269 |
||
2270 |
\sa position() CssFloat |
|
2271 |
*/ |
|
2272 |
||
2273 |
/*! |
|
2274 |
\enum QTextFrameFormat::BorderStyle |
|
2275 |
\since 4.3 |
|
2276 |
||
2277 |
This enum describes different border styles for the text frame. |
|
2278 |
||
2279 |
\value BorderStyle_None |
|
2280 |
\value BorderStyle_Dotted |
|
2281 |
\value BorderStyle_Dashed |
|
2282 |
\value BorderStyle_Solid |
|
2283 |
\value BorderStyle_Double |
|
2284 |
\value BorderStyle_DotDash |
|
2285 |
\value BorderStyle_DotDotDash |
|
2286 |
\value BorderStyle_Groove |
|
2287 |
\value BorderStyle_Ridge |
|
2288 |
\value BorderStyle_Inset |
|
2289 |
\value BorderStyle_Outset |
|
2290 |
||
2291 |
\sa borderStyle() FrameBorderStyle |
|
2292 |
*/ |
|
2293 |
||
2294 |
/*! |
|
2295 |
\fn QTextFrameFormat::QTextFrameFormat() |
|
2296 |
||
2297 |
Constructs a text frame format object with the default properties. |
|
2298 |
*/ |
|
2299 |
QTextFrameFormat::QTextFrameFormat() : QTextFormat(FrameFormat) |
|
2300 |
{ |
|
2301 |
setBorderStyle(BorderStyle_Outset); |
|
2302 |
setBorderBrush(Qt::darkGray); |
|
2303 |
} |
|
2304 |
||
2305 |
/*! |
|
2306 |
\internal |
|
2307 |
\fn QTextFrameFormat::QTextFrameFormat(const QTextFormat &other) |
|
2308 |
||
2309 |
Creates a new frame format with the same attributes as the \a given |
|
2310 |
text format. |
|
2311 |
*/ |
|
2312 |
QTextFrameFormat::QTextFrameFormat(const QTextFormat &fmt) |
|
2313 |
: QTextFormat(fmt) |
|
2314 |
{ |
|
2315 |
} |
|
2316 |
||
2317 |
/*! |
|
2318 |
\fn QTextFrameFormat::isValid() const |
|
2319 |
||
2320 |
Returns true if the format description is valid; otherwise returns false. |
|
2321 |
*/ |
|
2322 |
||
2323 |
/*! |
|
2324 |
\fn QTextFrameFormat::setPosition(Position policy) |
|
2325 |
||
2326 |
Sets the \a policy for positioning frames with this frame format. |
|
2327 |
||
2328 |
*/ |
|
2329 |
||
2330 |
/*! |
|
2331 |
\fn Position QTextFrameFormat::position() const |
|
2332 |
||
2333 |
Returns the positioning policy for frames with this frame format. |
|
2334 |
*/ |
|
2335 |
||
2336 |
/*! |
|
2337 |
\fn QTextFrameFormat::setBorder(qreal width) |
|
2338 |
||
2339 |
Sets the \a width (in pixels) of the frame's border. |
|
2340 |
*/ |
|
2341 |
||
2342 |
/*! |
|
2343 |
\fn qreal QTextFrameFormat::border() const |
|
2344 |
||
2345 |
Returns the width of the border in pixels. |
|
2346 |
*/ |
|
2347 |
||
2348 |
/*! |
|
2349 |
\fn QTextFrameFormat::setBorderBrush(const QBrush &brush) |
|
2350 |
\since 4.3 |
|
2351 |
||
2352 |
Sets the \a brush used for the frame's border. |
|
2353 |
*/ |
|
2354 |
||
2355 |
/*! |
|
2356 |
\fn QBrush QTextFrameFormat::borderBrush() const |
|
2357 |
\since 4.3 |
|
2358 |
||
2359 |
Returns the brush used for the frame's border. |
|
2360 |
*/ |
|
2361 |
||
2362 |
/*! |
|
2363 |
\fn QTextFrameFormat::setBorderStyle(BorderStyle style) |
|
2364 |
\since 4.3 |
|
2365 |
||
2366 |
Sets the \a style of the frame's border. |
|
2367 |
*/ |
|
2368 |
||
2369 |
/*! |
|
2370 |
\fn BorderStyle QTextFrameFormat::borderStyle() const |
|
2371 |
\since 4.3 |
|
2372 |
||
2373 |
Returns the style of the frame's border. |
|
2374 |
*/ |
|
2375 |
||
2376 |
/*! |
|
2377 |
\fn QTextFrameFormat::setMargin(qreal margin) |
|
2378 |
||
2379 |
Sets the frame's \a margin in pixels. |
|
2380 |
This method also sets the left, right, top and bottom margins |
|
2381 |
of the frame to the same value. The individual margins override |
|
2382 |
the general margin. |
|
2383 |
*/ |
|
2384 |
void QTextFrameFormat::setMargin(qreal amargin) |
|
2385 |
{ |
|
2386 |
setProperty(FrameMargin, amargin); |
|
2387 |
setProperty(FrameTopMargin, amargin); |
|
2388 |
setProperty(FrameBottomMargin, amargin); |
|
2389 |
setProperty(FrameLeftMargin, amargin); |
|
2390 |
setProperty(FrameRightMargin, amargin); |
|
2391 |
} |
|
2392 |
||
2393 |
||
2394 |
/*! |
|
2395 |
\fn qreal QTextFrameFormat::margin() const |
|
2396 |
||
2397 |
Returns the width of the frame's external margin in pixels. |
|
2398 |
*/ |
|
2399 |
||
2400 |
/*! |
|
2401 |
\fn QTextFrameFormat::setTopMargin(qreal margin) |
|
2402 |
\since 4.3 |
|
2403 |
||
2404 |
Sets the frame's top \a margin in pixels. |
|
2405 |
*/ |
|
2406 |
||
2407 |
/*! |
|
2408 |
\fn qreal QTextFrameFormat::topMargin() const |
|
2409 |
\since 4.3 |
|
2410 |
||
2411 |
Returns the width of the frame's top margin in pixels. |
|
2412 |
*/ |
|
2413 |
qreal QTextFrameFormat::topMargin() const |
|
2414 |
{ |
|
2415 |
if (!hasProperty(FrameTopMargin)) |
|
2416 |
return margin(); |
|
2417 |
return doubleProperty(FrameTopMargin); |
|
2418 |
} |
|
2419 |
||
2420 |
/*! |
|
2421 |
\fn QTextFrameFormat::setBottomMargin(qreal margin) |
|
2422 |
\since 4.3 |
|
2423 |
||
2424 |
Sets the frame's bottom \a margin in pixels. |
|
2425 |
*/ |
|
2426 |
||
2427 |
/*! |
|
2428 |
\fn qreal QTextFrameFormat::bottomMargin() const |
|
2429 |
\since 4.3 |
|
2430 |
||
2431 |
Returns the width of the frame's bottom margin in pixels. |
|
2432 |
*/ |
|
2433 |
qreal QTextFrameFormat::bottomMargin() const |
|
2434 |
{ |
|
2435 |
if (!hasProperty(FrameBottomMargin)) |
|
2436 |
return margin(); |
|
2437 |
return doubleProperty(FrameBottomMargin); |
|
2438 |
} |
|
2439 |
||
2440 |
/*! |
|
2441 |
\fn QTextFrameFormat::setLeftMargin(qreal margin) |
|
2442 |
\since 4.3 |
|
2443 |
||
2444 |
Sets the frame's left \a margin in pixels. |
|
2445 |
*/ |
|
2446 |
||
2447 |
/*! |
|
2448 |
\fn qreal QTextFrameFormat::leftMargin() const |
|
2449 |
\since 4.3 |
|
2450 |
||
2451 |
Returns the width of the frame's left margin in pixels. |
|
2452 |
*/ |
|
2453 |
qreal QTextFrameFormat::leftMargin() const |
|
2454 |
{ |
|
2455 |
if (!hasProperty(FrameLeftMargin)) |
|
2456 |
return margin(); |
|
2457 |
return doubleProperty(FrameLeftMargin); |
|
2458 |
} |
|
2459 |
||
2460 |
/*! |
|
2461 |
\fn QTextFrameFormat::setRightMargin(qreal margin) |
|
2462 |
\since 4.3 |
|
2463 |
||
2464 |
Sets the frame's right \a margin in pixels. |
|
2465 |
*/ |
|
2466 |
||
2467 |
/*! |
|
2468 |
\fn qreal QTextFrameFormat::rightMargin() const |
|
2469 |
\since 4.3 |
|
2470 |
||
2471 |
Returns the width of the frame's right margin in pixels. |
|
2472 |
*/ |
|
2473 |
qreal QTextFrameFormat::rightMargin() const |
|
2474 |
{ |
|
2475 |
if (!hasProperty(FrameRightMargin)) |
|
2476 |
return margin(); |
|
2477 |
return doubleProperty(FrameRightMargin); |
|
2478 |
} |
|
2479 |
||
2480 |
/*! |
|
2481 |
\fn QTextFrameFormat::setPadding(qreal width) |
|
2482 |
||
2483 |
Sets the \a width of the frame's internal padding in pixels. |
|
2484 |
*/ |
|
2485 |
||
2486 |
/*! |
|
2487 |
\fn qreal QTextFrameFormat::padding() const |
|
2488 |
||
2489 |
Returns the width of the frame's internal padding in pixels. |
|
2490 |
*/ |
|
2491 |
||
2492 |
/*! |
|
2493 |
\fn QTextFrameFormat::setWidth(const QTextLength &width) |
|
2494 |
||
2495 |
Sets the frame's border rectangle's \a width. |
|
2496 |
||
2497 |
\sa QTextLength |
|
2498 |
*/ |
|
2499 |
||
2500 |
/*! |
|
2501 |
\fn QTextFrameFormat::setWidth(qreal width) |
|
2502 |
\overload |
|
2503 |
||
2504 |
Convenience method that sets the width of the frame's border |
|
2505 |
rectangle's width to the specified fixed \a width. |
|
2506 |
*/ |
|
2507 |
||
2508 |
/*! |
|
2509 |
\fn QTextFormat::PageBreakFlags QTextFrameFormat::pageBreakPolicy() const |
|
2510 |
\since 4.2 |
|
2511 |
||
2512 |
Returns the currently set page break policy for the frame/table. The default is |
|
2513 |
QTextFormat::PageBreak_Auto. |
|
2514 |
||
2515 |
\sa setPageBreakPolicy() |
|
2516 |
*/ |
|
2517 |
||
2518 |
/*! |
|
2519 |
\fn void QTextFrameFormat::setPageBreakPolicy(PageBreakFlags policy) |
|
2520 |
\since 4.2 |
|
2521 |
||
2522 |
Sets the page break policy for the frame/table to \a policy. |
|
2523 |
||
2524 |
\sa pageBreakPolicy() |
|
2525 |
*/ |
|
2526 |
||
2527 |
/*! |
|
2528 |
\fn QTextLength QTextFrameFormat::width() const |
|
2529 |
||
2530 |
Returns the width of the frame's border rectangle. |
|
2531 |
||
2532 |
\sa QTextLength |
|
2533 |
*/ |
|
2534 |
||
2535 |
/*! |
|
2536 |
\fn void QTextFrameFormat::setHeight(const QTextLength &height) |
|
2537 |
||
2538 |
Sets the frame's \a height. |
|
2539 |
*/ |
|
2540 |
||
2541 |
/*! |
|
2542 |
\fn void QTextFrameFormat::setHeight(qreal height) |
|
2543 |
\overload |
|
2544 |
||
2545 |
Sets the frame's \a height. |
|
2546 |
*/ |
|
2547 |
||
2548 |
/*! |
|
2549 |
\fn qreal QTextFrameFormat::height() const |
|
2550 |
||
2551 |
Returns the height of the frame's border rectangle. |
|
2552 |
*/ |
|
2553 |
||
2554 |
/*! |
|
2555 |
\class QTextTableFormat |
|
2556 |
\reentrant |
|
2557 |
||
2558 |
\brief The QTextTableFormat class provides formatting information for |
|
2559 |
tables in a QTextDocument. |
|
2560 |
||
2561 |
\ingroup richtext-processing |
|
2562 |
||
2563 |
A table is a group of cells ordered into rows and columns. Each table |
|
2564 |
contains at least one row and one column. Each cell contains a block. |
|
2565 |
Tables in rich text documents are formatted using the properties |
|
2566 |
defined in this class. |
|
2567 |
||
2568 |
Tables are horizontally justified within their parent frame according to the |
|
2569 |
table's alignment. This can be read with the alignment() function and set |
|
2570 |
with setAlignment(). |
|
2571 |
||
2572 |
Cells within the table are separated by cell spacing. The number of pixels |
|
2573 |
between cells is set with setCellSpacing() and read with cellSpacing(). |
|
2574 |
The contents of each cell is surrounded by cell padding. The number of pixels |
|
2575 |
between each cell edge and its contents is set with setCellPadding() and read |
|
2576 |
with cellPadding(). |
|
2577 |
||
2578 |
\image qtexttableformat-cell.png |
|
2579 |
||
2580 |
The table's background color can be read with the background() function, |
|
2581 |
and can be specified with setBackground(). The background color of each |
|
2582 |
cell can be set independently, and will control the color of the cell within |
|
2583 |
the padded area. |
|
2584 |
||
2585 |
The table format also provides a way to constrain the widths of the columns |
|
2586 |
in the table. Columns can be assigned a fixed width, a variable width, or |
|
2587 |
a percentage of the available width (see QTextLength). The columns() function |
|
2588 |
returns the number of columns with constraints, and the |
|
2589 |
columnWidthConstraints() function returns the constraints defined for the |
|
2590 |
table. These quantities can also be set by calling setColumnWidthConstraints() |
|
2591 |
with a vector containing new constraints. If no constraints are |
|
2592 |
required, clearColumnWidthConstraints() can be used to remove them. |
|
2593 |
||
2594 |
\sa QTextTable QTextTableCell QTextLength |
|
2595 |
*/ |
|
2596 |
||
2597 |
/*! |
|
2598 |
\fn QTextTableFormat::QTextTableFormat() |
|
2599 |
||
2600 |
Constructs a new table format object. |
|
2601 |
*/ |
|
2602 |
QTextTableFormat::QTextTableFormat() |
|
2603 |
: QTextFrameFormat() |
|
2604 |
{ |
|
2605 |
setObjectType(TableObject); |
|
2606 |
setCellSpacing(2); |
|
2607 |
setBorder(1); |
|
2608 |
} |
|
2609 |
||
2610 |
/*! |
|
2611 |
\internal |
|
2612 |
\fn QTextTableFormat::QTextTableFormat(const QTextFormat &other) |
|
2613 |
||
2614 |
Creates a new table format with the same attributes as the \a given |
|
2615 |
text format. |
|
2616 |
*/ |
|
2617 |
QTextTableFormat::QTextTableFormat(const QTextFormat &fmt) |
|
2618 |
: QTextFrameFormat(fmt) |
|
2619 |
{ |
|
2620 |
} |
|
2621 |
||
2622 |
/*! |
|
2623 |
\fn bool QTextTableFormat::isValid() const |
|
2624 |
||
2625 |
Returns true if this table format is valid; otherwise |
|
2626 |
returns false. |
|
2627 |
*/ |
|
2628 |
||
2629 |
||
2630 |
/*! |
|
2631 |
\fn int QTextTableFormat::columns() const |
|
2632 |
||
2633 |
Returns the number of columns specified by the table format. |
|
2634 |
*/ |
|
2635 |
||
2636 |
||
2637 |
/*! |
|
2638 |
\internal |
|
2639 |
\fn void QTextTableFormat::setColumns(int columns) |
|
2640 |
||
2641 |
Sets the number of \a columns required by the table format. |
|
2642 |
||
2643 |
\sa columns() |
|
2644 |
*/ |
|
2645 |
||
2646 |
/*! |
|
2647 |
\fn void QTextTableFormat::clearColumnWidthConstraints() |
|
2648 |
||
2649 |
Clears the column width constraints for the table. |
|
2650 |
||
2651 |
\sa columnWidthConstraints() setColumnWidthConstraints() |
|
2652 |
*/ |
|
2653 |
||
2654 |
/*! |
|
2655 |
\fn void QTextTableFormat::setColumnWidthConstraints(const QVector<QTextLength> &constraints) |
|
2656 |
||
2657 |
Sets the column width \a constraints for the table. |
|
2658 |
||
2659 |
\sa columnWidthConstraints() clearColumnWidthConstraints() |
|
2660 |
*/ |
|
2661 |
||
2662 |
/*! |
|
2663 |
\fn QVector<QTextLength> QTextTableFormat::columnWidthConstraints() const |
|
2664 |
||
2665 |
Returns a list of constraints used by this table format to control the |
|
2666 |
appearance of columns in a table. |
|
2667 |
||
2668 |
\sa setColumnWidthConstraints() |
|
2669 |
*/ |
|
2670 |
||
2671 |
/*! |
|
2672 |
\fn qreal QTextTableFormat::cellSpacing() const |
|
2673 |
||
2674 |
Returns the table's cell spacing. This describes the distance between |
|
2675 |
adjacent cells. |
|
2676 |
*/ |
|
2677 |
||
2678 |
/*! |
|
2679 |
\fn void QTextTableFormat::setCellSpacing(qreal spacing) |
|
2680 |
||
2681 |
Sets the cell \a spacing for the table. This determines the distance |
|
2682 |
between adjacent cells. |
|
2683 |
*/ |
|
2684 |
||
2685 |
/*! |
|
2686 |
\fn qreal QTextTableFormat::cellPadding() const |
|
2687 |
||
2688 |
Returns the table's cell padding. This describes the distance between |
|
2689 |
the border of a cell and its contents. |
|
2690 |
*/ |
|
2691 |
||
2692 |
/*! |
|
2693 |
\fn void QTextTableFormat::setCellPadding(qreal padding) |
|
2694 |
||
2695 |
Sets the cell \a padding for the table. This determines the distance |
|
2696 |
between the border of a cell and its contents. |
|
2697 |
*/ |
|
2698 |
||
2699 |
/*! |
|
2700 |
\fn void QTextTableFormat::setAlignment(Qt::Alignment alignment) |
|
2701 |
||
2702 |
Sets the table's \a alignment. |
|
2703 |
||
2704 |
\sa alignment() |
|
2705 |
*/ |
|
2706 |
||
2707 |
/*! |
|
2708 |
\fn Qt::Alignment QTextTableFormat::alignment() const |
|
2709 |
||
2710 |
Returns the table's alignment. |
|
2711 |
||
2712 |
\sa setAlignment() |
|
2713 |
*/ |
|
2714 |
||
2715 |
/*! |
|
2716 |
\fn void QTextTableFormat::setHeaderRowCount(int count) |
|
2717 |
\since 4.2 |
|
2718 |
||
2719 |
Declares the first \a count rows of the table as table header. |
|
2720 |
The table header rows get repeated when a table is broken |
|
2721 |
across a page boundary. |
|
2722 |
*/ |
|
2723 |
||
2724 |
/*! |
|
2725 |
\fn int QTextTableFormat::headerRowCount() const |
|
2726 |
\since 4.2 |
|
2727 |
||
2728 |
Returns the number of rows in the table that define the header. |
|
2729 |
||
2730 |
\sa setHeaderRowCount() |
|
2731 |
*/ |
|
2732 |
||
2733 |
/*! |
|
2734 |
\fn void QTextFormat::setBackground(const QBrush &brush) |
|
2735 |
||
2736 |
Sets the brush use to paint the document's background to the |
|
2737 |
\a brush specified. |
|
2738 |
||
2739 |
\sa background() clearBackground() setForeground() |
|
2740 |
*/ |
|
2741 |
||
2742 |
/*! |
|
2743 |
\fn QColor QTextFormat::background() const |
|
2744 |
||
2745 |
Returns the brush used to paint the document's background. |
|
2746 |
||
2747 |
\sa setBackground() clearBackground() foreground() |
|
2748 |
*/ |
|
2749 |
||
2750 |
/*! |
|
2751 |
\fn void QTextFormat::clearBackground() |
|
2752 |
||
2753 |
Clears the brush used to paint the document's background. The default |
|
2754 |
brush will be used. |
|
2755 |
||
2756 |
\sa background() setBackground() clearForeground() |
|
2757 |
*/ |
|
2758 |
||
2759 |
||
2760 |
/*! |
|
2761 |
\class QTextImageFormat |
|
2762 |
\reentrant |
|
2763 |
||
2764 |
\brief The QTextImageFormat class provides formatting information for |
|
2765 |
images in a QTextDocument. |
|
2766 |
||
2767 |
\ingroup richtext-processing |
|
2768 |
||
2769 |
Inline images are represented by an object replacement character |
|
2770 |
(0xFFFC in Unicode) which has an associated QTextImageFormat. The |
|
2771 |
image format specifies a name with setName() that is used to |
|
2772 |
locate the image. The size of the rectangle that the image will |
|
2773 |
occupy is specified using setWidth() and setHeight(). |
|
2774 |
||
2775 |
Images can be supplied in any format for which Qt has an image |
|
2776 |
reader, so SVG drawings can be included alongside PNG, TIFF and |
|
2777 |
other bitmap formats. |
|
2778 |
||
2779 |
\sa QImage, QImageReader |
|
2780 |
*/ |
|
2781 |
||
2782 |
/*! |
|
2783 |
\fn QTextImageFormat::QTextImageFormat() |
|
2784 |
||
2785 |
Creates a new image format object. |
|
2786 |
*/ |
|
2787 |
QTextImageFormat::QTextImageFormat() : QTextCharFormat() { setObjectType(ImageObject); } |
|
2788 |
||
2789 |
/*! |
|
2790 |
\internal |
|
2791 |
\fn QTextImageFormat::QTextImageFormat(const QTextFormat &other) |
|
2792 |
||
2793 |
Creates a new image format with the same attributes as the \a given |
|
2794 |
text format. |
|
2795 |
*/ |
|
2796 |
QTextImageFormat::QTextImageFormat(const QTextFormat &fmt) |
|
2797 |
: QTextCharFormat(fmt) |
|
2798 |
{ |
|
2799 |
} |
|
2800 |
||
2801 |
/*! |
|
2802 |
\fn bool QTextImageFormat::isValid() const |
|
2803 |
||
2804 |
Returns true if this image format is valid; otherwise returns false. |
|
2805 |
*/ |
|
2806 |
||
2807 |
||
2808 |
/*! |
|
2809 |
\fn void QTextImageFormat::setName(const QString &name) |
|
2810 |
||
2811 |
Sets the \a name of the image. The \a name is used to locate the image |
|
2812 |
in the application's resources. |
|
2813 |
||
2814 |
\sa name() |
|
2815 |
*/ |
|
2816 |
||
2817 |
||
2818 |
/*! |
|
2819 |
\fn QString QTextImageFormat::name() const |
|
2820 |
||
2821 |
Returns the name of the image. The name refers to an entry in the |
|
2822 |
application's resources file. |
|
2823 |
||
2824 |
\sa setName() |
|
2825 |
*/ |
|
2826 |
||
2827 |
/*! |
|
2828 |
\fn void QTextImageFormat::setWidth(qreal width) |
|
2829 |
||
2830 |
Sets the \a width of the rectangle occupied by the image. |
|
2831 |
||
2832 |
\sa width() setHeight() |
|
2833 |
*/ |
|
2834 |
||
2835 |
||
2836 |
// ### Qt5 qreal replace with a QTextLength |
|
2837 |
/*! |
|
2838 |
\fn qreal QTextImageFormat::width() const |
|
2839 |
||
2840 |
Returns the width of the rectangle occupied by the image. |
|
2841 |
||
2842 |
\sa height() setWidth() |
|
2843 |
*/ |
|
2844 |
||
2845 |
||
2846 |
/*! |
|
2847 |
\fn void QTextImageFormat::setHeight(qreal height) |
|
2848 |
||
2849 |
Sets the \a height of the rectangle occupied by the image. |
|
2850 |
||
2851 |
\sa height() setWidth() |
|
2852 |
*/ |
|
2853 |
||
2854 |
||
2855 |
// ### Qt5 qreal replace with a QTextLength |
|
2856 |
/*! |
|
2857 |
\fn qreal QTextImageFormat::height() const |
|
2858 |
||
2859 |
Returns the height of the rectangle occupied by the image. |
|
2860 |
||
2861 |
\sa width() setHeight() |
|
2862 |
*/ |
|
2863 |
||
2864 |
/*! |
|
2865 |
\fn void QTextCharFormat::setFontCapitalization(QFont::Capitalization capitalization) |
|
2866 |
\since 4.4 |
|
2867 |
||
2868 |
Sets the capitalization of the text that apppears in this font to \a capitalization. |
|
2869 |
||
2870 |
A font's capitalization makes the text appear in the selected capitalization mode. |
|
2871 |
||
2872 |
\sa fontCapitalization() |
|
2873 |
*/ |
|
2874 |
||
2875 |
/*! |
|
2876 |
\fn Capitalization QTextCharFormat::fontCapitalization() const |
|
2877 |
\since 4.4 |
|
2878 |
||
2879 |
Returns the current capitalization type of the font. |
|
2880 |
*/ |
|
2881 |
||
2882 |
/*! |
|
2883 |
\fn void QTextCharFormat::setFontLetterSpacing(qreal spacing) |
|
2884 |
\since 4.4 |
|
2885 |
||
2886 |
Sets the letter spacing of this format to the given \a spacing, in percent. |
|
2887 |
A value of 100 indicates default spacing; a value of 200 doubles the amount |
|
2888 |
of space a letter takes. |
|
2889 |
||
2890 |
\sa fontLetterSpacing() |
|
2891 |
*/ |
|
2892 |
||
2893 |
/*! |
|
2894 |
\fn qreal QTextCharFormat::fontLetterSpacing() const |
|
2895 |
\since 4.4 |
|
2896 |
||
2897 |
Returns the current letter spacing percentage. |
|
2898 |
*/ |
|
2899 |
||
2900 |
/*! |
|
2901 |
\fn void QTextCharFormat::setFontWordSpacing(qreal spacing) |
|
2902 |
\since 4.4 |
|
2903 |
||
2904 |
Sets the word spacing of this format to the given \a spacing, in pixels. |
|
2905 |
||
2906 |
\sa fontWordSpacing() |
|
2907 |
*/ |
|
2908 |
||
2909 |
/*! |
|
2910 |
\fn qreal QTextCharFormat::fontWordSpacing() const |
|
2911 |
\since 4.4 |
|
2912 |
||
2913 |
Returns the current word spacing value. |
|
2914 |
*/ |
|
2915 |
||
2916 |
/*! |
|
2917 |
\fn qreal QTextTableCellFormat::topPadding() const |
|
2918 |
\since 4.4 |
|
2919 |
||
2920 |
Gets the top padding of the table cell. |
|
2921 |
||
2922 |
\sa setTopPadding(), leftPadding(), rightPadding(), bottomPadding() |
|
2923 |
*/ |
|
2924 |
||
2925 |
/*! |
|
2926 |
\fn qreal QTextTableCellFormat::bottomPadding() const |
|
2927 |
\since 4.4 |
|
2928 |
||
2929 |
Gets the bottom padding of the table cell. |
|
2930 |
||
2931 |
\sa setBottomPadding(), leftPadding(), rightPadding(), topPadding() |
|
2932 |
*/ |
|
2933 |
||
2934 |
/*! |
|
2935 |
\fn qreal QTextTableCellFormat::leftPadding() const |
|
2936 |
\since 4.4 |
|
2937 |
||
2938 |
Gets the left padding of the table cell. |
|
2939 |
||
2940 |
\sa setLeftPadding(), rightPadding(), topPadding(), bottomPadding() |
|
2941 |
*/ |
|
2942 |
||
2943 |
/*! |
|
2944 |
\fn qreal QTextTableCellFormat::rightPadding() const |
|
2945 |
\since 4.4 |
|
2946 |
||
2947 |
Gets the right padding of the table cell. |
|
2948 |
||
2949 |
\sa setRightPadding(), leftPadding(), topPadding(), bottomPadding() |
|
2950 |
*/ |
|
2951 |
||
2952 |
/*! |
|
2953 |
\fn void QTextTableCellFormat::setTopPadding(qreal padding) |
|
2954 |
\since 4.4 |
|
2955 |
||
2956 |
Sets the top \a padding of the table cell. |
|
2957 |
||
2958 |
\sa topPadding(), setLeftPadding(), setRightPadding(), setBottomPadding() |
|
2959 |
*/ |
|
2960 |
||
2961 |
/*! |
|
2962 |
\fn void QTextTableCellFormat::setBottomPadding(qreal padding) |
|
2963 |
\since 4.4 |
|
2964 |
||
2965 |
Sets the bottom \a padding of the table cell. |
|
2966 |
||
2967 |
\sa bottomPadding(), setLeftPadding(), setRightPadding(), setTopPadding() |
|
2968 |
*/ |
|
2969 |
||
2970 |
/*! |
|
2971 |
\fn void QTextTableCellFormat::setLeftPadding(qreal padding) |
|
2972 |
\since 4.4 |
|
2973 |
||
2974 |
Sets the left \a padding of the table cell. |
|
2975 |
||
2976 |
\sa leftPadding(), setRightPadding(), setTopPadding(), setBottomPadding() |
|
2977 |
*/ |
|
2978 |
||
2979 |
/*! |
|
2980 |
\fn void QTextTableCellFormat::setRightPadding(qreal padding) |
|
2981 |
\since 4.4 |
|
2982 |
||
2983 |
Sets the right \a padding of the table cell. |
|
2984 |
||
2985 |
\sa rightPadding(), setLeftPadding(), setTopPadding(), setBottomPadding() |
|
2986 |
*/ |
|
2987 |
||
2988 |
/*! |
|
2989 |
\fn void QTextTableCellFormat::setPadding(qreal padding) |
|
2990 |
\since 4.4 |
|
2991 |
||
2992 |
Sets the left, right, top, and bottom \a padding of the table cell. |
|
2993 |
||
2994 |
\sa setLeftPadding(), setRightPadding(), setTopPadding(), setBottomPadding() |
|
2995 |
*/ |
|
2996 |
||
2997 |
/*! |
|
2998 |
\fn bool QTextTableCellFormat::isValid() const |
|
2999 |
\since 4.4 |
|
3000 |
||
3001 |
Returns true if this table cell format is valid; otherwise returns false. |
|
3002 |
*/ |
|
3003 |
||
3004 |
/*! |
|
3005 |
\fn QTextTableCellFormat::QTextTableCellFormat() |
|
3006 |
\since 4.4 |
|
3007 |
||
3008 |
Constructs a new table cell format object. |
|
3009 |
*/ |
|
3010 |
QTextTableCellFormat::QTextTableCellFormat() |
|
3011 |
: QTextCharFormat() |
|
3012 |
{ |
|
3013 |
setObjectType(TableCellObject); |
|
3014 |
} |
|
3015 |
||
3016 |
/*! |
|
3017 |
\internal |
|
3018 |
\fn QTextTableCellFormat::QTextTableCellFormat(const QTextFormat &other) |
|
3019 |
||
3020 |
Creates a new table cell format with the same attributes as the \a given |
|
3021 |
text format. |
|
3022 |
*/ |
|
3023 |
QTextTableCellFormat::QTextTableCellFormat(const QTextFormat &fmt) |
|
3024 |
: QTextCharFormat(fmt) |
|
3025 |
{ |
|
3026 |
} |
|
3027 |
||
3028 |
/*! |
|
3029 |
\class QTextTableCellFormat |
|
3030 |
\reentrant |
|
3031 |
\since 4.4 |
|
3032 |
||
3033 |
\brief The QTextTableCellFormat class provides formatting information for |
|
3034 |
table cells in a QTextDocument. |
|
3035 |
||
3036 |
\ingroup richtext-processing |
|
3037 |
||
3038 |
The table cell format of a table cell in a document specifies the visual |
|
3039 |
properties of the table cell. |
|
3040 |
||
3041 |
The padding properties of a table cell are controlled by setLeftPadding(), |
|
3042 |
setRightPadding(), setTopPadding(), and setBottomPadding(). All the paddings |
|
3043 |
can be set at once using setPadding(). |
|
3044 |
||
3045 |
\sa QTextFormat QTextBlockFormat QTextTableFormat QTextCharFormat |
|
3046 |
*/ |
|
3047 |
||
3048 |
// ------------------------------------------------------ |
|
3049 |
||
3050 |
||
3051 |
QTextFormatCollection::QTextFormatCollection(const QTextFormatCollection &rhs) |
|
3052 |
{ |
|
3053 |
formats = rhs.formats; |
|
3054 |
objFormats = rhs.objFormats; |
|
3055 |
} |
|
3056 |
||
3057 |
QTextFormatCollection &QTextFormatCollection::operator=(const QTextFormatCollection &rhs) |
|
3058 |
{ |
|
3059 |
formats = rhs.formats; |
|
3060 |
objFormats = rhs.objFormats; |
|
3061 |
return *this; |
|
3062 |
} |
|
3063 |
||
3064 |
QTextFormatCollection::~QTextFormatCollection() |
|
3065 |
{ |
|
3066 |
} |
|
3067 |
||
3068 |
int QTextFormatCollection::indexForFormat(const QTextFormat &format) |
|
3069 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3070 |
uint hash = getHash(format.d, format.format_type); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3071 |
QMultiHash<uint, int>::const_iterator i = hashes.find(hash); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3072 |
while (i != hashes.end() && i.key() == hash) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3073 |
if (formats.value(i.value()) == format) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3074 |
return i.value(); |
0 | 3075 |
} |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3076 |
++i; |
0 | 3077 |
} |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3078 |
|
0 | 3079 |
int idx = formats.size(); |
3080 |
formats.append(format); |
|
3081 |
||
3082 |
QT_TRY{ |
|
3083 |
QTextFormat &f = formats.last(); |
|
3084 |
if (!f.d) |
|
3085 |
f.d = new QTextFormatPrivate; |
|
3086 |
f.d->resolveFont(defaultFnt); |
|
3087 |
||
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
3088 |
if (!hashes.contains(hash, idx)) |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
3089 |
hashes.insert(hash, idx); |
0 | 3090 |
|
3091 |
} QT_CATCH(...) { |
|
3092 |
formats.pop_back(); |
|
3093 |
QT_RETHROW; |
|
3094 |
} |
|
3095 |
return idx; |
|
3096 |
} |
|
3097 |
||
3098 |
bool QTextFormatCollection::hasFormatCached(const QTextFormat &format) const |
|
3099 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3100 |
uint hash = getHash(format.d, format.format_type); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3101 |
QMultiHash<uint, int>::const_iterator i = hashes.find(hash); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3102 |
while (i != hashes.end() && i.key() == hash) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3103 |
if (formats.value(i.value()) == format) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3104 |
return true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3105 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3106 |
++i; |
0 | 3107 |
} |
3108 |
return false; |
|
3109 |
} |
|
3110 |
||
3111 |
QTextFormat QTextFormatCollection::objectFormat(int objectIndex) const |
|
3112 |
{ |
|
3113 |
if (objectIndex == -1) |
|
3114 |
return QTextFormat(); |
|
3115 |
return format(objFormats.at(objectIndex)); |
|
3116 |
} |
|
3117 |
||
3118 |
void QTextFormatCollection::setObjectFormat(int objectIndex, const QTextFormat &f) |
|
3119 |
{ |
|
3120 |
const int formatIndex = indexForFormat(f); |
|
3121 |
objFormats[objectIndex] = formatIndex; |
|
3122 |
} |
|
3123 |
||
3124 |
int QTextFormatCollection::objectFormatIndex(int objectIndex) const |
|
3125 |
{ |
|
3126 |
if (objectIndex == -1) |
|
3127 |
return -1; |
|
3128 |
return objFormats.at(objectIndex); |
|
3129 |
} |
|
3130 |
||
3131 |
void QTextFormatCollection::setObjectFormatIndex(int objectIndex, int formatIndex) |
|
3132 |
{ |
|
3133 |
objFormats[objectIndex] = formatIndex; |
|
3134 |
} |
|
3135 |
||
3136 |
int QTextFormatCollection::createObjectIndex(const QTextFormat &f) |
|
3137 |
{ |
|
3138 |
const int objectIndex = objFormats.size(); |
|
3139 |
objFormats.append(indexForFormat(f)); |
|
3140 |
return objectIndex; |
|
3141 |
} |
|
3142 |
||
3143 |
QTextFormat QTextFormatCollection::format(int idx) const |
|
3144 |
{ |
|
3145 |
if (idx < 0 || idx >= formats.count()) |
|
3146 |
return QTextFormat(); |
|
3147 |
||
3148 |
return formats.at(idx); |
|
3149 |
} |
|
3150 |
||
3151 |
void QTextFormatCollection::setDefaultFont(const QFont &f) |
|
3152 |
{ |
|
3153 |
defaultFnt = f; |
|
3154 |
for (int i = 0; i < formats.count(); ++i) |
|
3155 |
if (formats[i].d) |
|
3156 |
formats[i].d->resolveFont(defaultFnt); |
|
3157 |
} |
|
3158 |
||
3159 |
QT_END_NAMESPACE |