author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 16 Apr 2010 15:50:13 +0300 | |
changeset 18 | 2f34d5167611 |
parent 0 | 1918ee327afb |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
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 Qt3Support 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 "q3stylesheet.h" |
|
43 |
||
44 |
#ifndef QT_NO_RICHTEXT |
|
45 |
||
46 |
#include "qlayout.h" |
|
47 |
#include "qpainter.h" |
|
48 |
#include "q3cleanuphandler.h" |
|
49 |
#include <qtextdocument.h> |
|
50 |
||
51 |
#include <stdio.h> |
|
52 |
||
53 |
QT_BEGIN_NAMESPACE |
|
54 |
||
55 |
class Q3StyleSheetItemData |
|
56 |
{ |
|
57 |
public: |
|
58 |
Q3StyleSheetItem::DisplayMode disp; |
|
59 |
int fontitalic; |
|
60 |
int fontunderline; |
|
61 |
int fontstrikeout; |
|
62 |
int fontweight; |
|
63 |
int fontsize; |
|
64 |
int fontsizelog; |
|
65 |
int fontsizestep; |
|
66 |
int lineSpacing; |
|
67 |
QString fontfamily; |
|
68 |
Q3StyleSheetItem *parentstyle; |
|
69 |
QString stylename; |
|
70 |
int ncolumns; |
|
71 |
QColor col; |
|
72 |
bool anchor; |
|
73 |
int align; |
|
74 |
Q3StyleSheetItem::VerticalAlignment valign; |
|
75 |
int margin[5]; |
|
76 |
Q3StyleSheetItem::ListStyle list; |
|
77 |
Q3StyleSheetItem::WhiteSpaceMode whitespacemode; |
|
78 |
QString contxt; |
|
79 |
bool selfnest; |
|
80 |
Q3StyleSheet* sheet; |
|
81 |
}; |
|
82 |
||
83 |
/*! |
|
84 |
\class Q3StyleSheetItem |
|
85 |
\brief The Q3StyleSheetItem class provides an encapsulation of a set of text styles. |
|
86 |
||
87 |
\compat |
|
88 |
||
89 |
A style sheet item consists of a name and a set of attributes that |
|
90 |
specify its font, color, etc. When used in a \link Q3StyleSheet |
|
91 |
style sheet\endlink (see styleSheet()), items define the name() of |
|
92 |
a rich text tag and the display property changes associated with |
|
93 |
it. |
|
94 |
||
95 |
The \link Q3StyleSheetItem::DisplayMode display mode\endlink |
|
96 |
attribute indicates whether the item is a block, an inline element |
|
97 |
or a list element; see setDisplayMode(). The treatment of |
|
98 |
whitespace is controlled by the \link |
|
99 |
Q3StyleSheetItem::WhiteSpaceMode white space mode\endlink; see |
|
100 |
setWhiteSpaceMode(). An item's margins are set with setMargin(), |
|
101 |
In the case of list items, the list style is set with |
|
102 |
setListStyle(). An item may be a hypertext link anchor; see |
|
103 |
setAnchor(). Other attributes are set with setAlignment(), |
|
104 |
setVerticalAlignment(), setFontFamily(), setFontSize(), |
|
105 |
setFontWeight(), setFontItalic(), setFontUnderline(), |
|
106 |
setFontStrikeOut and setColor(). |
|
107 |
*/ |
|
108 |
||
109 |
/*! \enum Q3StyleSheetItem::AdditionalStyleValues |
|
110 |
\internal |
|
111 |
*/ |
|
112 |
||
113 |
/*! |
|
114 |
\enum Q3StyleSheetItem::WhiteSpaceMode |
|
115 |
||
116 |
This enum defines the ways in which Q3StyleSheet can treat |
|
117 |
whitespace. |
|
118 |
||
119 |
\value WhiteSpaceNormal any sequence of whitespace (including |
|
120 |
line-breaks) is equivalent to a single space. |
|
121 |
||
122 |
\value WhiteSpacePre whitespace must be output exactly as given |
|
123 |
in the input. |
|
124 |
||
125 |
\value WhiteSpaceNoWrap multiple spaces are collapsed as with |
|
126 |
WhiteSpaceNormal, but no automatic line-breaks occur. To break |
|
127 |
lines manually, use the \c{<br>} tag. |
|
128 |
||
129 |
\omitvalue WhiteSpaceModeUndefined |
|
130 |
*/ |
|
131 |
||
132 |
/*! |
|
133 |
\enum Q3StyleSheetItem::Margin |
|
134 |
||
135 |
\value MarginLeft left margin |
|
136 |
\value MarginRight right margin |
|
137 |
\value MarginTop top margin |
|
138 |
\value MarginBottom bottom margin |
|
139 |
\value MarginAll all margins (left, right, top and bottom) |
|
140 |
\value MarginVertical top and bottom margins |
|
141 |
\value MarginHorizontal left and right margins |
|
142 |
\value MarginFirstLine margin (indentation) of the first line of |
|
143 |
a paragarph (in addition to the MarginLeft of the paragraph) |
|
144 |
\value MarginUndefined |
|
145 |
*/ |
|
146 |
||
147 |
/*! |
|
148 |
Constructs a new style called \a name for the stylesheet \a |
|
149 |
parent. |
|
150 |
||
151 |
All properties in Q3StyleSheetItem are initially in the "do not |
|
152 |
change" state, except \link Q3StyleSheetItem::DisplayMode display |
|
153 |
mode\endlink, which defaults to \c DisplayInline. |
|
154 |
*/ |
|
155 |
Q3StyleSheetItem::Q3StyleSheetItem(Q3StyleSheet* parent, const QString& name) |
|
156 |
{ |
|
157 |
d = new Q3StyleSheetItemData; |
|
158 |
d->stylename = name.toLower(); |
|
159 |
d->sheet = parent; |
|
160 |
init(); |
|
161 |
if (parent) |
|
162 |
parent->insert(this); |
|
163 |
} |
|
164 |
||
165 |
/*! |
|
166 |
Copy constructor. Constructs a copy of \a other that is not bound |
|
167 |
to any style sheet. |
|
168 |
*/ |
|
169 |
Q3StyleSheetItem::Q3StyleSheetItem(const Q3StyleSheetItem & other) |
|
170 |
{ |
|
171 |
d = new Q3StyleSheetItemData; |
|
172 |
*d = *other.d; |
|
173 |
} |
|
174 |
||
175 |
||
176 |
/*! |
|
177 |
Destroys the style. Note that Q3StyleSheetItem objects become |
|
178 |
owned by Q3StyleSheet when they are created. |
|
179 |
*/ |
|
180 |
Q3StyleSheetItem::~Q3StyleSheetItem() |
|
181 |
{ |
|
182 |
delete d; |
|
183 |
} |
|
184 |
||
185 |
/*! |
|
186 |
Assignment. Assings a copy of \a other that is not bound to any style sheet. |
|
187 |
Unbounds first from previous style sheet. |
|
188 |
*/ |
|
189 |
Q3StyleSheetItem& Q3StyleSheetItem::operator=(const Q3StyleSheetItem& other) |
|
190 |
{ |
|
191 |
if (&other == this) |
|
192 |
return *this; |
|
193 |
delete d; |
|
194 |
d = new Q3StyleSheetItemData; |
|
195 |
*d = *other.d; |
|
196 |
return *this; |
|
197 |
} |
|
198 |
||
199 |
/*! |
|
200 |
Returns the style sheet this item is in. |
|
201 |
*/ |
|
202 |
Q3StyleSheet* Q3StyleSheetItem::styleSheet() |
|
203 |
{ |
|
204 |
return d->sheet; |
|
205 |
} |
|
206 |
||
207 |
/*! |
|
208 |
\overload |
|
209 |
||
210 |
Returns the style sheet this item is in. |
|
211 |
*/ |
|
212 |
const Q3StyleSheet* Q3StyleSheetItem::styleSheet() const |
|
213 |
{ |
|
214 |
return d->sheet; |
|
215 |
} |
|
216 |
||
217 |
/*! |
|
218 |
\internal |
|
219 |
Internal initialization |
|
220 |
*/ |
|
221 |
void Q3StyleSheetItem::init() |
|
222 |
{ |
|
223 |
d->disp = DisplayInline; |
|
224 |
||
225 |
d->fontitalic = Undefined; |
|
226 |
d->fontunderline = Undefined; |
|
227 |
d->fontstrikeout = Undefined; |
|
228 |
d->fontweight = Undefined; |
|
229 |
d->fontsize = Undefined; |
|
230 |
d->fontsizelog = Undefined; |
|
231 |
d->fontsizestep = 0; |
|
232 |
d->ncolumns = Undefined; |
|
233 |
d->col = QColor(); // !isValid() |
|
234 |
d->anchor = false; |
|
235 |
d->align = Undefined; |
|
236 |
d->valign = VAlignBaseline; |
|
237 |
d->margin[0] = Undefined; |
|
238 |
d->margin[1] = Undefined; |
|
239 |
d->margin[2] = Undefined; |
|
240 |
d->margin[3] = Undefined; |
|
241 |
d->margin[4] = Undefined; |
|
242 |
d->list = ListStyleUndefined; |
|
243 |
d->whitespacemode = WhiteSpaceModeUndefined; |
|
244 |
d->selfnest = true; |
|
245 |
d->lineSpacing = Undefined; |
|
246 |
} |
|
247 |
||
248 |
/*! |
|
249 |
Returns the name of the style item. |
|
250 |
*/ |
|
251 |
QString Q3StyleSheetItem::name() const |
|
252 |
{ |
|
253 |
return d->stylename; |
|
254 |
} |
|
255 |
||
256 |
/*! |
|
257 |
Returns the \link Q3StyleSheetItem::DisplayMode display |
|
258 |
mode\endlink of the style. |
|
259 |
||
260 |
\sa setDisplayMode() |
|
261 |
*/ |
|
262 |
Q3StyleSheetItem::DisplayMode Q3StyleSheetItem::displayMode() const |
|
263 |
{ |
|
264 |
return d->disp; |
|
265 |
} |
|
266 |
||
267 |
/*! |
|
268 |
\enum Q3StyleSheetItem::DisplayMode |
|
269 |
||
270 |
This enum type defines the way adjacent elements are displayed. |
|
271 |
||
272 |
\value DisplayBlock elements are displayed as a rectangular block |
|
273 |
(e.g. \c{<p>...</p>}). |
|
274 |
||
275 |
\value DisplayInline elements are displayed in a horizontally |
|
276 |
flowing sequence (e.g. \c{<em>...</em>}). |
|
277 |
||
278 |
\value DisplayListItem elements are displayed in a vertical |
|
279 |
sequence (e.g. \c{<li>...</li>}). |
|
280 |
||
281 |
\value DisplayNone elements are not displayed at all. |
|
282 |
||
283 |
\omitvalue DisplayModeUndefined |
|
284 |
*/ |
|
285 |
||
286 |
/*! |
|
287 |
Sets the display mode of the style to \a m. |
|
288 |
||
289 |
\sa displayMode() |
|
290 |
*/ |
|
291 |
void Q3StyleSheetItem::setDisplayMode(DisplayMode m) |
|
292 |
{ |
|
293 |
d->disp=m; |
|
294 |
} |
|
295 |
||
296 |
||
297 |
/*! |
|
298 |
Returns the alignment of this style. Possible values are |
|
299 |
Qt::AlignAuto, Qt::AlignLeft, Qt::AlignRight, Qt::AlignCenter or |
|
300 |
Qt::AlignJustify. |
|
301 |
||
302 |
\sa setAlignment(), Qt::Alignment |
|
303 |
*/ |
|
304 |
int Q3StyleSheetItem::alignment() const |
|
305 |
{ |
|
306 |
return d->align; |
|
307 |
} |
|
308 |
||
309 |
/*! |
|
310 |
Sets the alignment to \a f. This only makes sense for styles with |
|
311 |
a \link Q3StyleSheetItem::DisplayMode display mode\endlink of |
|
312 |
DisplayBlock. Possible values are Qt::AlignAuto, Qt::AlignLeft, |
|
313 |
Qt::AlignRight, Qt::AlignCenter or Qt::AlignJustify. |
|
314 |
||
315 |
\sa alignment(), displayMode(), Qt::Alignment |
|
316 |
*/ |
|
317 |
void Q3StyleSheetItem::setAlignment(int f) |
|
318 |
{ |
|
319 |
d->align = f; |
|
320 |
} |
|
321 |
||
322 |
||
323 |
/*! |
|
324 |
Returns the vertical alignment of the style. Possible values are |
|
325 |
VAlignBaseline, VAlignSub or VAlignSuper. |
|
326 |
||
327 |
\sa setVerticalAlignment() |
|
328 |
*/ |
|
329 |
Q3StyleSheetItem::VerticalAlignment Q3StyleSheetItem::verticalAlignment() const |
|
330 |
{ |
|
331 |
return d->valign; |
|
332 |
} |
|
333 |
||
334 |
/*! |
|
335 |
\enum Q3StyleSheetItem::VerticalAlignment |
|
336 |
||
337 |
This enum type defines the way elements are aligned vertically. |
|
338 |
This is only supported for text elements. |
|
339 |
||
340 |
\value VAlignBaseline align the baseline of the element (or the |
|
341 |
bottom, if the element doesn't have a baseline) with the |
|
342 |
baseline of the parent |
|
343 |
||
344 |
\value VAlignSub subscript the element |
|
345 |
||
346 |
\value VAlignSuper superscript the element |
|
347 |
||
348 |
*/ |
|
349 |
||
350 |
||
351 |
/*! |
|
352 |
Sets the vertical alignment to \a valign. Possible values are |
|
353 |
VAlignBaseline, VAlignSub or VAlignSuper. |
|
354 |
||
355 |
The vertical alignment property is not inherited. |
|
356 |
||
357 |
\sa verticalAlignment() |
|
358 |
*/ |
|
359 |
void Q3StyleSheetItem::setVerticalAlignment(VerticalAlignment valign) |
|
360 |
{ |
|
361 |
d->valign = valign; |
|
362 |
} |
|
363 |
||
364 |
||
365 |
/*! |
|
366 |
Returns true if the style sets an italic font; otherwise returns |
|
367 |
false. |
|
368 |
||
369 |
\sa setFontItalic(), definesFontItalic() |
|
370 |
*/ |
|
371 |
bool Q3StyleSheetItem::fontItalic() const |
|
372 |
{ |
|
373 |
return d->fontitalic > 0; |
|
374 |
} |
|
375 |
||
376 |
/*! |
|
377 |
If \a italic is true sets italic for the style; otherwise sets |
|
378 |
upright. |
|
379 |
||
380 |
\sa fontItalic(), definesFontItalic() |
|
381 |
*/ |
|
382 |
void Q3StyleSheetItem::setFontItalic(bool italic) |
|
383 |
{ |
|
384 |
d->fontitalic = italic?1:0; |
|
385 |
} |
|
386 |
||
387 |
/*! |
|
388 |
Returns true if the style defines a font shape; otherwise returns |
|
389 |
false. A style does not define any shape until setFontItalic() is |
|
390 |
called. |
|
391 |
||
392 |
\sa setFontItalic(), fontItalic() |
|
393 |
*/ |
|
394 |
bool Q3StyleSheetItem::definesFontItalic() const |
|
395 |
{ |
|
396 |
return d->fontitalic != Undefined; |
|
397 |
} |
|
398 |
||
399 |
/*! |
|
400 |
Returns true if the style sets an underlined font; otherwise |
|
401 |
returns false. |
|
402 |
||
403 |
\sa setFontUnderline(), definesFontUnderline() |
|
404 |
*/ |
|
405 |
bool Q3StyleSheetItem::fontUnderline() const |
|
406 |
{ |
|
407 |
return d->fontunderline > 0; |
|
408 |
} |
|
409 |
||
410 |
/*! |
|
411 |
If \a underline is true, sets underline for the style; otherwise |
|
412 |
sets no underline. |
|
413 |
||
414 |
\sa fontUnderline(), definesFontUnderline() |
|
415 |
*/ |
|
416 |
void Q3StyleSheetItem::setFontUnderline(bool underline) |
|
417 |
{ |
|
418 |
d->fontunderline = underline?1:0; |
|
419 |
} |
|
420 |
||
421 |
/*! |
|
422 |
Returns true if the style defines a setting for the underline |
|
423 |
property of the font; otherwise returns false. A style does not |
|
424 |
define this until setFontUnderline() is called. |
|
425 |
||
426 |
\sa setFontUnderline(), fontUnderline() |
|
427 |
*/ |
|
428 |
bool Q3StyleSheetItem::definesFontUnderline() const |
|
429 |
{ |
|
430 |
return d->fontunderline != Undefined; |
|
431 |
} |
|
432 |
||
433 |
||
434 |
/*! |
|
435 |
Returns true if the style sets a strike out font; otherwise |
|
436 |
returns false. |
|
437 |
||
438 |
\sa setFontStrikeOut(), definesFontStrikeOut() |
|
439 |
*/ |
|
440 |
bool Q3StyleSheetItem::fontStrikeOut() const |
|
441 |
{ |
|
442 |
return d->fontstrikeout > 0; |
|
443 |
} |
|
444 |
||
445 |
/*! |
|
446 |
If \a strikeOut is true, sets strike out for the style; otherwise |
|
447 |
sets no strike out. |
|
448 |
||
449 |
\sa fontStrikeOut(), definesFontStrikeOut() |
|
450 |
*/ |
|
451 |
void Q3StyleSheetItem::setFontStrikeOut(bool strikeOut) |
|
452 |
{ |
|
453 |
d->fontstrikeout = strikeOut?1:0; |
|
454 |
} |
|
455 |
||
456 |
/*! |
|
457 |
Returns true if the style defines a setting for the strikeOut |
|
458 |
property of the font; otherwise returns false. A style does not |
|
459 |
define this until setFontStrikeOut() is called. |
|
460 |
||
461 |
\sa setFontStrikeOut(), fontStrikeOut() |
|
462 |
*/ |
|
463 |
bool Q3StyleSheetItem::definesFontStrikeOut() const |
|
464 |
{ |
|
465 |
return d->fontstrikeout != Undefined; |
|
466 |
} |
|
467 |
||
468 |
||
469 |
/*! |
|
470 |
Returns the font weight setting of the style. This is either a |
|
471 |
valid QFont::Weight or the value Q3StyleSheetItem::Undefined. |
|
472 |
||
473 |
\sa setFontWeight(), QFont |
|
474 |
*/ |
|
475 |
int Q3StyleSheetItem::fontWeight() const |
|
476 |
{ |
|
477 |
return d->fontweight; |
|
478 |
} |
|
479 |
||
480 |
/*! |
|
481 |
Sets the font weight setting of the style to \a w. Valid values |
|
482 |
are those defined by QFont::Weight. |
|
483 |
||
484 |
\sa QFont, fontWeight() |
|
485 |
*/ |
|
486 |
void Q3StyleSheetItem::setFontWeight(int w) |
|
487 |
{ |
|
488 |
d->fontweight = w; |
|
489 |
} |
|
490 |
||
491 |
/*! |
|
492 |
Returns the logical font size setting of the style. This is either |
|
493 |
a valid size between 1 and 7 or Q3StyleSheetItem::Undefined. |
|
494 |
||
495 |
\sa setLogicalFontSize(), setLogicalFontSizeStep(), QFont::pointSize(), QFont::setPointSize() |
|
496 |
*/ |
|
497 |
int Q3StyleSheetItem::logicalFontSize() const |
|
498 |
{ |
|
499 |
return d->fontsizelog; |
|
500 |
} |
|
501 |
||
502 |
||
503 |
/*! |
|
504 |
Sets the logical font size setting of the style to \a s. Valid |
|
505 |
logical sizes are 1 to 7. |
|
506 |
||
507 |
\sa logicalFontSize(), QFont::pointSize(), QFont::setPointSize() |
|
508 |
*/ |
|
509 |
void Q3StyleSheetItem::setLogicalFontSize(int s) |
|
510 |
{ |
|
511 |
d->fontsizelog = s; |
|
512 |
} |
|
513 |
||
514 |
/*! |
|
515 |
Returns the logical font size step of this style. |
|
516 |
||
517 |
The default is 0. Tags such as \c big define \c +1; \c small |
|
518 |
defines \c -1. |
|
519 |
||
520 |
\sa setLogicalFontSizeStep() |
|
521 |
*/ |
|
522 |
int Q3StyleSheetItem::logicalFontSizeStep() const |
|
523 |
{ |
|
524 |
return d->fontsizestep; |
|
525 |
} |
|
526 |
||
527 |
/*! |
|
528 |
Sets the logical font size step of this style to \a s. |
|
529 |
||
530 |
\sa logicalFontSizeStep() |
|
531 |
*/ |
|
532 |
void Q3StyleSheetItem::setLogicalFontSizeStep(int s) |
|
533 |
{ |
|
534 |
d->fontsizestep = s; |
|
535 |
} |
|
536 |
||
537 |
||
538 |
||
539 |
/*! |
|
540 |
Sets the font size setting of the style to \a s points. |
|
541 |
||
542 |
\sa fontSize(), QFont::pointSize(), QFont::setPointSize() |
|
543 |
*/ |
|
544 |
void Q3StyleSheetItem::setFontSize(int s) |
|
545 |
{ |
|
546 |
d->fontsize = s; |
|
547 |
} |
|
548 |
||
549 |
/*! |
|
550 |
Returns the font size setting of the style. This is either a valid |
|
551 |
point size or Q3StyleSheetItem::Undefined. |
|
552 |
||
553 |
\sa setFontSize(), QFont::pointSize(), QFont::setPointSize() |
|
554 |
*/ |
|
555 |
int Q3StyleSheetItem::fontSize() const |
|
556 |
{ |
|
557 |
return d->fontsize; |
|
558 |
} |
|
559 |
||
560 |
||
561 |
/*! |
|
562 |
Returns the style's font family setting. This is either a valid |
|
563 |
font family or an empty string if no family has been set. |
|
564 |
||
565 |
\sa setFontFamily(), QFont::family(), QFont::setFamily() |
|
566 |
*/ |
|
567 |
QString Q3StyleSheetItem::fontFamily() const |
|
568 |
{ |
|
569 |
return d->fontfamily; |
|
570 |
} |
|
571 |
||
572 |
/*! |
|
573 |
Sets the font family setting of the style to \a fam. |
|
574 |
||
575 |
\sa fontFamily(), QFont::family(), QFont::setFamily() |
|
576 |
*/ |
|
577 |
void Q3StyleSheetItem::setFontFamily(const QString& fam) |
|
578 |
{ |
|
579 |
d->fontfamily = fam; |
|
580 |
} |
|
581 |
||
582 |
||
583 |
/*! |
|
584 |
Returns the number of columns for this style. |
|
585 |
||
586 |
\sa setNumberOfColumns(), displayMode(), setDisplayMode() |
|
587 |
||
588 |
*/ |
|
589 |
int Q3StyleSheetItem::numberOfColumns() const |
|
590 |
{ |
|
591 |
return d->ncolumns; |
|
592 |
} |
|
593 |
||
594 |
||
595 |
/*! |
|
596 |
Sets the number of columns for this style to \a ncols. Elements in the style |
|
597 |
are divided into columns. |
|
598 |
||
599 |
This makes sense only if the style uses a block display mode |
|
600 |
(see Q3StyleSheetItem::DisplayMode). |
|
601 |
||
602 |
\sa numberOfColumns() |
|
603 |
*/ |
|
604 |
void Q3StyleSheetItem::setNumberOfColumns(int ncols) |
|
605 |
{ |
|
606 |
if (ncols > 0) |
|
607 |
d->ncolumns = ncols; |
|
608 |
} |
|
609 |
||
610 |
||
611 |
/*! |
|
612 |
Returns the text color of this style or an invalid color if no |
|
613 |
color has been set. |
|
614 |
||
615 |
\sa setColor() QColor::isValid() |
|
616 |
*/ |
|
617 |
QColor Q3StyleSheetItem::color() const |
|
618 |
{ |
|
619 |
return d->col; |
|
620 |
} |
|
621 |
||
622 |
/*! |
|
623 |
Sets the text color of this style to \a c. |
|
624 |
||
625 |
\sa color() |
|
626 |
*/ |
|
627 |
void Q3StyleSheetItem::setColor(const QColor &c) |
|
628 |
{ |
|
629 |
d->col = c; |
|
630 |
} |
|
631 |
||
632 |
/*! |
|
633 |
Returns whether this style is an anchor. |
|
634 |
||
635 |
\sa setAnchor() |
|
636 |
*/ |
|
637 |
bool Q3StyleSheetItem::isAnchor() const |
|
638 |
{ |
|
639 |
return d->anchor; |
|
640 |
} |
|
641 |
||
642 |
/*! |
|
643 |
If \a anc is true, sets this style to be an anchor (hypertext |
|
644 |
link); otherwise sets it to not be an anchor. Elements in this |
|
645 |
style link to other documents or anchors. |
|
646 |
||
647 |
\sa isAnchor() |
|
648 |
*/ |
|
649 |
void Q3StyleSheetItem::setAnchor(bool anc) |
|
650 |
{ |
|
651 |
d->anchor = anc; |
|
652 |
} |
|
653 |
||
654 |
||
655 |
/*! |
|
656 |
Returns the whitespace mode. |
|
657 |
||
658 |
\sa setWhiteSpaceMode() WhiteSpaceMode |
|
659 |
*/ |
|
660 |
Q3StyleSheetItem::WhiteSpaceMode Q3StyleSheetItem::whiteSpaceMode() const |
|
661 |
{ |
|
662 |
return d->whitespacemode; |
|
663 |
} |
|
664 |
||
665 |
/*! |
|
666 |
Sets the whitespace mode to \a m. |
|
667 |
||
668 |
\sa WhiteSpaceMode |
|
669 |
*/ |
|
670 |
void Q3StyleSheetItem::setWhiteSpaceMode(WhiteSpaceMode m) |
|
671 |
{ |
|
672 |
d->whitespacemode = m; |
|
673 |
} |
|
674 |
||
675 |
||
676 |
/*! |
|
677 |
Returns the width of margin \a m in pixels. |
|
678 |
||
679 |
The margin, \a m, can be MarginLeft, MarginRight, |
|
680 |
MarginTop, MarginBottom, or MarginFirstLine |
|
681 |
||
682 |
\sa setMargin() Margin |
|
683 |
*/ |
|
684 |
int Q3StyleSheetItem::margin(Margin m) const |
|
685 |
{ |
|
686 |
if (m == MarginAll) { |
|
687 |
return d->margin[MarginLeft]; |
|
688 |
} else if (m == MarginVertical) { |
|
689 |
return d->margin[MarginTop]; |
|
690 |
} else if (m == MarginHorizontal) { |
|
691 |
return d->margin[MarginLeft]; |
|
692 |
} else { |
|
693 |
return d->margin[m]; |
|
694 |
} |
|
695 |
} |
|
696 |
||
697 |
||
698 |
/*! |
|
699 |
Sets the width of margin \a m to \a v pixels. |
|
700 |
||
701 |
The margin, \a m, can be \c MarginLeft, \c MarginRight, \c |
|
702 |
MarginTop, \c MarginBottom, MarginFirstLine, \c MarginAll, |
|
703 |
\c MarginVertical or \c MarginHorizontal. The value \a v must |
|
704 |
be >= 0. |
|
705 |
||
706 |
\sa margin() |
|
707 |
*/ |
|
708 |
void Q3StyleSheetItem::setMargin(Margin m, int v) |
|
709 |
{ |
|
710 |
if (m == MarginAll) { |
|
711 |
d->margin[MarginLeft] = v; |
|
712 |
d->margin[MarginRight] = v; |
|
713 |
d->margin[MarginTop] = v; |
|
714 |
d->margin[MarginBottom] = v; |
|
715 |
} else if (m == MarginVertical) { |
|
716 |
d->margin[MarginTop] = v; |
|
717 |
d->margin[MarginBottom] = v; |
|
718 |
} else if (m == MarginHorizontal) { |
|
719 |
d->margin[MarginLeft] = v; |
|
720 |
d->margin[MarginRight] = v; |
|
721 |
} else { |
|
722 |
d->margin[m] = v; |
|
723 |
} |
|
724 |
} |
|
725 |
||
726 |
||
727 |
/*! |
|
728 |
Returns the list style of the style. |
|
729 |
||
730 |
\sa setListStyle() ListStyle |
|
731 |
*/ |
|
732 |
Q3StyleSheetItem::ListStyle Q3StyleSheetItem::listStyle() const |
|
733 |
{ |
|
734 |
return d->list; |
|
735 |
} |
|
736 |
||
737 |
/*! |
|
738 |
\enum Q3StyleSheetItem::ListStyle |
|
739 |
||
740 |
This enum type defines how the items in a list are prefixed when |
|
741 |
displayed. |
|
742 |
||
743 |
\value ListDisc a filled circle (i.e. a bullet) |
|
744 |
\value ListCircle an unfilled circle |
|
745 |
\value ListSquare a filled square |
|
746 |
\value ListDecimal an integer in base 10: \e 1, \e 2, \e 3, ... |
|
747 |
\value ListLowerAlpha a lowercase letter: \e a, \e b, \e c, ... |
|
748 |
\value ListUpperAlpha an uppercase letter: \e A, \e B, \e C, ... |
|
749 |
\omitvalue ListStyleUndefined |
|
750 |
*/ |
|
751 |
||
752 |
/*! |
|
753 |
Sets the list style of the style to \a s. |
|
754 |
||
755 |
This is used by nested elements that have a display mode of \c |
|
756 |
DisplayListItem. |
|
757 |
||
758 |
\sa listStyle() DisplayMode ListStyle |
|
759 |
*/ |
|
760 |
void Q3StyleSheetItem::setListStyle(ListStyle s) |
|
761 |
{ |
|
762 |
d->list=s; |
|
763 |
} |
|
764 |
||
765 |
||
766 |
/*! |
|
767 |
Returns a space-separated list of names of styles that may contain |
|
768 |
elements of this style. If nothing has been set, contexts() |
|
769 |
returns an empty string, which indicates that this style can be |
|
770 |
nested everywhere. |
|
771 |
||
772 |
\sa setContexts() |
|
773 |
*/ |
|
774 |
QString Q3StyleSheetItem::contexts() const |
|
775 |
{ |
|
776 |
return d->contxt; |
|
777 |
} |
|
778 |
||
779 |
/*! |
|
780 |
Sets a space-separated list of names of styles that may contain |
|
781 |
elements of this style. If \a c is empty, the style can be nested |
|
782 |
everywhere. |
|
783 |
||
784 |
\sa contexts() |
|
785 |
*/ |
|
786 |
void Q3StyleSheetItem::setContexts(const QString& c) |
|
787 |
{ |
|
788 |
d->contxt = QLatin1Char(' ') + c + QLatin1Char(' '); |
|
789 |
} |
|
790 |
||
791 |
/*! |
|
792 |
Returns true if this style can be nested into an element of style |
|
793 |
\a s; otherwise returns false. |
|
794 |
||
795 |
\sa contexts(), setContexts() |
|
796 |
*/ |
|
797 |
bool Q3StyleSheetItem::allowedInContext(const Q3StyleSheetItem* s) const |
|
798 |
{ |
|
799 |
if (d->contxt.isEmpty()) |
|
800 |
return true; |
|
801 |
return d->contxt.contains(QLatin1Char(' ')+s->name()+QLatin1Char(' ')); |
|
802 |
} |
|
803 |
||
804 |
||
805 |
/*! |
|
806 |
Returns true if this style has self-nesting enabled; otherwise |
|
807 |
returns false. |
|
808 |
||
809 |
\sa setSelfNesting() |
|
810 |
*/ |
|
811 |
bool Q3StyleSheetItem::selfNesting() const |
|
812 |
{ |
|
813 |
return d->selfnest; |
|
814 |
} |
|
815 |
||
816 |
/*! |
|
817 |
Sets the self-nesting property for this style to \a nesting. |
|
818 |
||
819 |
In order to support "dirty" HTML, paragraphs \c{<p>} and list |
|
820 |
items \c{<li>} are not self-nesting. This means that starting a |
|
821 |
new paragraph or list item automatically closes the previous one. |
|
822 |
||
823 |
\sa selfNesting() |
|
824 |
*/ |
|
825 |
void Q3StyleSheetItem::setSelfNesting(bool nesting) |
|
826 |
{ |
|
827 |
d->selfnest = nesting; |
|
828 |
} |
|
829 |
||
830 |
/*! |
|
831 |
\internal |
|
832 |
Sets the linespacing to be at least \a ls pixels. |
|
833 |
||
834 |
For compatibility with previous Qt releases, small values get |
|
835 |
treated differently: If \a ls is smaller than the default font |
|
836 |
line spacing in pixels at parse time, the resulting line spacing |
|
837 |
is the sum of the default line spacing plus \a ls. We recommend |
|
838 |
not relying on this behavior. |
|
839 |
*/ |
|
840 |
||
841 |
void Q3StyleSheetItem::setLineSpacing(int ls) |
|
842 |
{ |
|
843 |
d->lineSpacing = ls; |
|
844 |
} |
|
845 |
||
846 |
/*! |
|
847 |
Returns the line spacing. |
|
848 |
*/ |
|
849 |
||
850 |
int Q3StyleSheetItem::lineSpacing() const |
|
851 |
{ |
|
852 |
return d->lineSpacing; |
|
853 |
} |
|
854 |
||
855 |
//************************************************************************ |
|
856 |
||
857 |
||
858 |
||
859 |
||
860 |
//************************************************************************ |
|
861 |
||
862 |
||
863 |
/*! |
|
864 |
\class Q3StyleSheet |
|
865 |
\brief The Q3StyleSheet class is a collection of styles for rich text |
|
866 |
rendering and a generator of tags. |
|
867 |
||
868 |
\compat |
|
869 |
||
870 |
By creating Q3StyleSheetItem objects for a style sheet you build a |
|
871 |
definition of a set of tags. This definition will be used by the |
|
872 |
internal rich text rendering system to parse and display text |
|
873 |
documents to which the style sheet applies. Rich text is normally |
|
874 |
visualized in a QTextEdit or a QTextBrowser. However, QLabel, |
|
875 |
QWhatsThis and QMessageBox also support it, and other classes are |
|
876 |
likely to follow. With QSimpleRichText it is possible to use the |
|
877 |
rich text renderer for custom widgets as well. |
|
878 |
||
879 |
The default Q3StyleSheet object has the following style bindings, |
|
880 |
sorted by structuring bindings, anchors, character style bindings |
|
881 |
(i.e. inline styles), special elements such as horizontal lines or |
|
882 |
images, and other tags. In addition, rich text supports simple |
|
883 |
HTML tables. |
|
884 |
||
885 |
The structuring tags are |
|
886 |
\table |
|
887 |
\header \i Structuring tags \i Notes |
|
888 |
\row \i \c{<qt>}...\c{</qt>} |
|
889 |
\i A Qt rich text document. It understands the following |
|
890 |
attributes: |
|
891 |
\list |
|
892 |
\i \c title -- The caption of the document. This attribute is |
|
893 |
easily accessible with QTextEdit::documentTitle(). |
|
894 |
\i \c type -- The type of the document. The default type is \c |
|
895 |
page. It indicates that the document is displayed in a |
|
896 |
page of its own. Another style is \c detail, which can be |
|
897 |
used to explain certain expressions in more detail in a |
|
898 |
few sentences. For \c detail, QTextBrowser will then keep |
|
899 |
the current page and display the new document in a small |
|
900 |
popup similar to QWhatsThis. Note that links will not work |
|
901 |
in documents with \c{<qt type="detail">...</qt>}. |
|
902 |
\i \c bgcolor -- The background color, for example \c |
|
903 |
bgcolor="yellow" or \c bgcolor="#0000FF". |
|
904 |
\i \c background -- The background pixmap, for example \c |
|
905 |
background="granite.xpm". The pixmap name will be resolved |
|
906 |
by a Q3MimeSourceFactory(). |
|
907 |
\i \c text -- The default text color, for example \c text="red". |
|
908 |
\i \c link -- The link color, for example \c link="green". |
|
909 |
\endlist |
|
910 |
\row \i \c{<h1>...</h1>} |
|
911 |
\i A top-level heading. |
|
912 |
\row \i \c{<h2>...</h2>} |
|
913 |
\i A sublevel heading. |
|
914 |
\row \i \c{<h3>...</h3>} |
|
915 |
\i A sub-sublevel heading. |
|
916 |
\row \i \c{<p>...</p>} |
|
917 |
\i A left-aligned paragraph. Adjust the alignment with the \c |
|
918 |
align attribute. Possible values are \c left, \c right and |
|
919 |
\c center. |
|
920 |
\row \i \c{<center>...}<br>\c{</center>} |
|
921 |
\i A centered paragraph. |
|
922 |
\row \i \c{<blockquote>...}<br>\c{</blockquote>} |
|
923 |
\i An indented paragraph that is useful for quotes. |
|
924 |
\row \i \c{<ul>...</ul>} |
|
925 |
\i An unordered list. You can also pass a type argument to |
|
926 |
define the bullet style. The default is \c type=disc; |
|
927 |
other types are \c circle and \c square. |
|
928 |
\row \i \c{<ol>...</ol>} |
|
929 |
\i An ordered list. You can also pass a type argument to |
|
930 |
define the enumeration label style. The default is \c |
|
931 |
type="1"; other types are \c "a" and \c "A". |
|
932 |
\row \i \c{<li>...</li>} |
|
933 |
\i A list item. This tag can be used only within the context |
|
934 |
of \c{<ol>} or \c{<ul>}. |
|
935 |
\row \i \c{<pre>...</pre>} |
|
936 |
\i For larger chunks of code. Whitespaces in the contents are |
|
937 |
preserved. For small bits of code use the inline-style \c |
|
938 |
code. |
|
939 |
\endtable |
|
940 |
||
941 |
Anchors and links are done with a single tag: |
|
942 |
\table |
|
943 |
\header \i Anchor tags \i Notes |
|
944 |
\row \i \c{<a>...</a>} |
|
945 |
\i An anchor or link. |
|
946 |
\list |
|
947 |
\i A link is created by using an \c href |
|
948 |
attribute, for example |
|
949 |
<br>\c{<a href="target.qml">Link Text</a>}. Links to |
|
950 |
targets within a document are achieved in the same way |
|
951 |
as for HTML, e.g. |
|
952 |
<br>\c{<a href="target.qml#subtitle">Link Text</a>}. |
|
953 |
\i A target is created by using a \c name |
|
954 |
attribute, for example |
|
955 |
<br>\c{<a name="subtitle"><h2>Sub Title</h2></a>}. |
|
956 |
\endlist |
|
957 |
\endtable |
|
958 |
||
959 |
The default character style bindings are |
|
960 |
\table |
|
961 |
\header \i Style tags \i Notes |
|
962 |
\row \i \c{<em>...</em>} |
|
963 |
\i Emphasized. By default this is the same as \c{<i>...</i>} |
|
964 |
(italic). |
|
965 |
\row \i \c{<strong>...</strong>} |
|
966 |
\i Strong. By default this is the same as \c{<b>...</b>} |
|
967 |
(bold). |
|
968 |
\row \i \c{<i>...</i>} |
|
969 |
\i Italic font style. |
|
970 |
\row \i \c{<b>...</b>} |
|
971 |
\i Bold font style. |
|
972 |
\row \i \c{<u>...</u>} |
|
973 |
\i Underlined font style. |
|
974 |
\row \i \c{<s>...</s>} |
|
975 |
\i Strike out font style. |
|
976 |
\row \i \c{<big>...</big>} |
|
977 |
\i A larger font size. |
|
978 |
\row \i \c{<small>...</small>} |
|
979 |
\i A smaller font size. |
|
980 |
\row \i \c{<sub>...</sub>} |
|
981 |
\i Subscripted text |
|
982 |
\row \i \c{<sup>...</sup>} |
|
983 |
\i Superscripted text |
|
984 |
\row \i \c{<code>...</code>} |
|
985 |
\i Indicates code. By default this is the same as |
|
986 |
\c{<tt>...</tt>} (typewriter). For larger chunks of code |
|
987 |
use the block-tag \c{<}\c{pre>}. |
|
988 |
\row \i \c{<tt>...</tt>} |
|
989 |
\i Typewriter font style. |
|
990 |
\row \i \c{<font>...</font>} |
|
991 |
\i Customizes the font size, family and text color. The tag |
|
992 |
understands the following attributes: |
|
993 |
\list |
|
994 |
\i \c color -- The text color, for example \c color="red" or |
|
995 |
\c color="#FF0000". |
|
996 |
\i \c size -- The logical size of the font. Logical sizes 1 |
|
997 |
to 7 are supported. The value may either be absolute |
|
998 |
(for example, \c size=3) or relative (\c size=-2). In |
|
999 |
the latter case the sizes are simply added. |
|
1000 |
\i \c face -- The family of the font, for example \c face=times. |
|
1001 |
\endlist |
|
1002 |
\endtable |
|
1003 |
||
1004 |
Special elements are: |
|
1005 |
\table |
|
1006 |
\header \i Special tags \i Notes |
|
1007 |
\row \i \c{<img>} |
|
1008 |
\i An image. The image name for the mime source factory is |
|
1009 |
given in the source attribute, for example |
|
1010 |
\c{<img src="qt.xpm">} The image tag also understands the |
|
1011 |
attributes \c width and \c height that determine the size |
|
1012 |
of the image. If the pixmap does not fit the specified |
|
1013 |
size it will be scaled automatically (by using |
|
1014 |
QImage::smoothScale()). |
|
1015 |
||
1016 |
The \c align attribute determines where the image is |
|
1017 |
placed. By default, an image is placed inline just like a |
|
1018 |
normal character. Specify \c left or \c right to place the |
|
1019 |
image at the respective side. |
|
1020 |
\row \i \c{<hr>} |
|
1021 |
\i A horizontal line. |
|
1022 |
\row \i \c{<br>} |
|
1023 |
\i A line break. |
|
1024 |
\row \i \c{<nobr>...</nobr>} |
|
1025 |
\i No break. Prevents word wrap. |
|
1026 |
\endtable |
|
1027 |
||
1028 |
In addition, rich text supports simple HTML tables. A table |
|
1029 |
consists of one or more rows each of which contains one or more |
|
1030 |
cells. Cells are either data cells or header cells, depending on |
|
1031 |
their content. Cells which span rows and columns are supported. |
|
1032 |
||
1033 |
\table |
|
1034 |
\header \i Table tags \i Notes |
|
1035 |
\row \i \c{<table>...</table>} |
|
1036 |
\i A table. Tables support the following attributes: |
|
1037 |
\list |
|
1038 |
\i \c bgcolor -- The background color. |
|
1039 |
\i \c width -- The table width. This is either an absolute |
|
1040 |
pixel width or a relative percentage of the table's |
|
1041 |
width, for example \c width=80%. |
|
1042 |
\i \c border -- The width of the table border. The default is |
|
1043 |
0 (= no border). |
|
1044 |
\i \c cellspacing -- Additional space around the table cells. |
|
1045 |
The default is 2. |
|
1046 |
\i \c cellpadding -- Additional space around the contents of |
|
1047 |
table cells. The default is 1. |
|
1048 |
\endlist |
|
1049 |
\row \i \c{<tr>...</tr>} |
|
1050 |
\i A table row. This is only valid within a \c table. Rows |
|
1051 |
support the following attribute: |
|
1052 |
\list |
|
1053 |
\i \c bgcolor -- The background color. |
|
1054 |
\endlist |
|
1055 |
\row \i \c{<th>...</th>} |
|
1056 |
\i A table header cell. Similar to \c td, but defaults to |
|
1057 |
center alignment and a bold font. |
|
1058 |
\row \i \c{<td>...</td>} |
|
1059 |
\i A table data cell. This is only valid within a \c tr. |
|
1060 |
Cells support the following attributes: |
|
1061 |
\list |
|
1062 |
\i \c bgcolor -- The background color. |
|
1063 |
\i \c width -- The cell width. This is either an absolute |
|
1064 |
pixel width or a relative percentage of table's width, |
|
1065 |
for example \c width=50%. |
|
1066 |
\i \c colspan -- Specifies how many columns this cell spans. |
|
1067 |
The default is 1. |
|
1068 |
\i \c rowspan -- Specifies how many rows this cell spans. The |
|
1069 |
default is 1. |
|
1070 |
\i \c align -- Qt::Alignment; possible values are \c left, \c |
|
1071 |
right, and \c center. The default is \c left. |
|
1072 |
\i \c valign -- Qt::Vertical alignment; possible values are \c |
|
1073 |
top, \c middle, and \c bottom. The default is \c middle. |
|
1074 |
\endlist |
|
1075 |
\endtable |
|
1076 |
*/ |
|
1077 |
||
1078 |
/*! |
|
1079 |
Creates a style sheet called \a name, with parent \a parent. Like |
|
1080 |
any QObject it will be deleted when its parent is destroyed (if |
|
1081 |
the child still exists). |
|
1082 |
||
1083 |
By default the style sheet has the tag definitions defined above. |
|
1084 |
*/ |
|
1085 |
Q3StyleSheet::Q3StyleSheet(QObject *parent, const char *name) |
|
1086 |
: QObject(parent) |
|
1087 |
{ |
|
1088 |
setObjectName(QLatin1String(name)); |
|
1089 |
init(); |
|
1090 |
} |
|
1091 |
||
1092 |
/*! |
|
1093 |
Destroys the style sheet. All styles inserted into the style sheet |
|
1094 |
will be deleted. |
|
1095 |
*/ |
|
1096 |
Q3StyleSheet::~Q3StyleSheet() |
|
1097 |
{ |
|
1098 |
QHash<QString, Q3StyleSheetItem *>::iterator it = styles.begin(); |
|
1099 |
while (it != styles.end()) { |
|
1100 |
delete it.value(); |
|
1101 |
++it; |
|
1102 |
} |
|
1103 |
} |
|
1104 |
||
1105 |
/*! |
|
1106 |
\internal |
|
1107 |
Initialized the style sheet to the basic Qt style. |
|
1108 |
*/ |
|
1109 |
void Q3StyleSheet::init() |
|
1110 |
{ |
|
1111 |
nullstyle = new Q3StyleSheetItem(this, QString::fromLatin1("")); |
|
1112 |
||
1113 |
Q3StyleSheetItem *style; |
|
1114 |
||
1115 |
style = new Q3StyleSheetItem(this, QLatin1String("qml")); // compatibility |
|
1116 |
style->setDisplayMode(Q3StyleSheetItem::DisplayBlock); |
|
1117 |
||
1118 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("qt")); |
|
1119 |
style->setDisplayMode(Q3StyleSheetItem::DisplayBlock); |
|
1120 |
||
1121 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("a")); |
|
1122 |
style->setAnchor(true); |
|
1123 |
||
1124 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("em")); |
|
1125 |
style->setFontItalic(true); |
|
1126 |
||
1127 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("i")); |
|
1128 |
style->setFontItalic(true); |
|
1129 |
||
1130 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("big")); |
|
1131 |
style->setLogicalFontSizeStep(1); |
|
1132 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("large")); // compatibility |
|
1133 |
style->setLogicalFontSizeStep(1); |
|
1134 |
||
1135 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("small")); |
|
1136 |
style->setLogicalFontSizeStep(-1); |
|
1137 |
||
1138 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("strong")); |
|
1139 |
style->setFontWeight(QFont::Bold); |
|
1140 |
||
1141 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("b")); |
|
1142 |
style->setFontWeight(QFont::Bold); |
|
1143 |
||
1144 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("h1")); |
|
1145 |
style->setFontWeight(QFont::Bold); |
|
1146 |
style->setLogicalFontSize(6); |
|
1147 |
style->setDisplayMode(Q3StyleSheetItem::DisplayBlock); |
|
1148 |
style-> setMargin(Q3StyleSheetItem::MarginTop, 18); |
|
1149 |
style-> setMargin(Q3StyleSheetItem::MarginBottom, 12); |
|
1150 |
||
1151 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("h2")); |
|
1152 |
style->setFontWeight(QFont::Bold); |
|
1153 |
style->setLogicalFontSize(5); |
|
1154 |
style->setDisplayMode(Q3StyleSheetItem::DisplayBlock); |
|
1155 |
style-> setMargin(Q3StyleSheetItem::MarginTop, 16); |
|
1156 |
style-> setMargin(Q3StyleSheetItem::MarginBottom, 12); |
|
1157 |
||
1158 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("h3")); |
|
1159 |
style->setFontWeight(QFont::Bold); |
|
1160 |
style->setLogicalFontSize(4); |
|
1161 |
style->setDisplayMode(Q3StyleSheetItem::DisplayBlock); |
|
1162 |
style-> setMargin(Q3StyleSheetItem::MarginTop, 14); |
|
1163 |
style-> setMargin(Q3StyleSheetItem::MarginBottom, 12); |
|
1164 |
||
1165 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("h4")); |
|
1166 |
style->setFontWeight(QFont::Bold); |
|
1167 |
style->setLogicalFontSize(3); |
|
1168 |
style->setDisplayMode(Q3StyleSheetItem::DisplayBlock); |
|
1169 |
style-> setMargin(Q3StyleSheetItem::MarginVertical, 12); |
|
1170 |
||
1171 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("h5")); |
|
1172 |
style->setFontWeight(QFont::Bold); |
|
1173 |
style->setLogicalFontSize(2); |
|
1174 |
style->setDisplayMode(Q3StyleSheetItem::DisplayBlock); |
|
1175 |
style-> setMargin(Q3StyleSheetItem::MarginTop, 12); |
|
1176 |
style-> setMargin(Q3StyleSheetItem::MarginBottom, 4); |
|
1177 |
||
1178 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("p")); |
|
1179 |
style->setDisplayMode(Q3StyleSheetItem::DisplayBlock); |
|
1180 |
style-> setMargin(Q3StyleSheetItem::MarginVertical, 12); |
|
1181 |
style->setSelfNesting(false); |
|
1182 |
||
1183 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("center")); |
|
1184 |
style->setDisplayMode(Q3StyleSheetItem::DisplayBlock); |
|
1185 |
style->setAlignment(Qt::AlignCenter); |
|
1186 |
||
1187 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("twocolumn")); |
|
1188 |
style->setDisplayMode(Q3StyleSheetItem::DisplayBlock); |
|
1189 |
style->setNumberOfColumns(2); |
|
1190 |
||
1191 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("multicol")); |
|
1192 |
style->setDisplayMode(Q3StyleSheetItem::DisplayBlock); |
|
1193 |
(void) new Q3StyleSheetItem(this, QString::fromLatin1("font")); |
|
1194 |
||
1195 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("ul")); |
|
1196 |
style->setDisplayMode(Q3StyleSheetItem::DisplayBlock); |
|
1197 |
style->setListStyle(Q3StyleSheetItem::ListDisc); |
|
1198 |
style-> setMargin(Q3StyleSheetItem::MarginVertical, 12); |
|
1199 |
style->setMargin(Q3StyleSheetItem::MarginLeft, 40); |
|
1200 |
||
1201 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("ol")); |
|
1202 |
style->setDisplayMode(Q3StyleSheetItem::DisplayBlock); |
|
1203 |
style->setListStyle(Q3StyleSheetItem::ListDecimal); |
|
1204 |
style-> setMargin(Q3StyleSheetItem::MarginVertical, 12); |
|
1205 |
style->setMargin(Q3StyleSheetItem::MarginLeft, 40); |
|
1206 |
||
1207 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("li")); |
|
1208 |
style->setDisplayMode(Q3StyleSheetItem::DisplayListItem); |
|
1209 |
style->setSelfNesting(false); |
|
1210 |
||
1211 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("code")); |
|
1212 |
style->setFontFamily(QString::fromLatin1("Courier New,courier")); |
|
1213 |
||
1214 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("tt")); |
|
1215 |
style->setFontFamily(QString::fromLatin1("Courier New,courier")); |
|
1216 |
||
1217 |
new Q3StyleSheetItem(this, QString::fromLatin1("img")); |
|
1218 |
new Q3StyleSheetItem(this, QString::fromLatin1("br")); |
|
1219 |
new Q3StyleSheetItem(this, QString::fromLatin1("hr")); |
|
1220 |
||
1221 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("sub")); |
|
1222 |
style->setVerticalAlignment(Q3StyleSheetItem::VAlignSub); |
|
1223 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("sup")); |
|
1224 |
style->setVerticalAlignment(Q3StyleSheetItem::VAlignSuper); |
|
1225 |
||
1226 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("pre")); |
|
1227 |
style->setFontFamily(QString::fromLatin1("Courier New,courier")); |
|
1228 |
style->setDisplayMode(Q3StyleSheetItem::DisplayBlock); |
|
1229 |
style->setWhiteSpaceMode(Q3StyleSheetItem::WhiteSpacePre); |
|
1230 |
style-> setMargin(Q3StyleSheetItem::MarginVertical, 12); |
|
1231 |
||
1232 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("blockquote")); |
|
1233 |
style->setDisplayMode(Q3StyleSheetItem::DisplayBlock); |
|
1234 |
style->setMargin(Q3StyleSheetItem::MarginHorizontal, 40); |
|
1235 |
||
1236 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("head")); |
|
1237 |
style->setDisplayMode(Q3StyleSheetItem::DisplayNone); |
|
1238 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("body")); |
|
1239 |
style->setDisplayMode(Q3StyleSheetItem::DisplayBlock); |
|
1240 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("div")); |
|
1241 |
style->setDisplayMode(Q3StyleSheetItem::DisplayBlock) ; |
|
1242 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("span")); |
|
1243 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("dl")); |
|
1244 |
style-> setMargin(Q3StyleSheetItem::MarginVertical, 8); |
|
1245 |
style->setDisplayMode(Q3StyleSheetItem::DisplayBlock); |
|
1246 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("dt")); |
|
1247 |
style->setDisplayMode(Q3StyleSheetItem::DisplayBlock); |
|
1248 |
style->setContexts(QString::fromLatin1("dl")); |
|
1249 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("dd")); |
|
1250 |
style->setDisplayMode(Q3StyleSheetItem::DisplayBlock); |
|
1251 |
style->setMargin(Q3StyleSheetItem::MarginLeft, 30); |
|
1252 |
style->setContexts(QString::fromLatin1("dt dl")); |
|
1253 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("u")); |
|
1254 |
style->setFontUnderline(true); |
|
1255 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("s")); |
|
1256 |
style->setFontStrikeOut(true); |
|
1257 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("nobr")); |
|
1258 |
style->setWhiteSpaceMode(Q3StyleSheetItem::WhiteSpaceNoWrap); |
|
1259 |
||
1260 |
// compatibily with some minor 3.0.x Qt versions that had an |
|
1261 |
// undocumented <wsp> tag. ### Remove 3.1 |
|
1262 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("wsp")); |
|
1263 |
style->setWhiteSpaceMode(Q3StyleSheetItem::WhiteSpacePre); |
|
1264 |
||
1265 |
// tables |
|
1266 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("table")); |
|
1267 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("tr")); |
|
1268 |
style->setContexts(QString::fromLatin1("table")); |
|
1269 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("td")); |
|
1270 |
style->setContexts(QString::fromLatin1("tr")); |
|
1271 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("th")); |
|
1272 |
style->setFontWeight(QFont::Bold); |
|
1273 |
style->setAlignment(Qt::AlignCenter); |
|
1274 |
style->setContexts(QString::fromLatin1("tr")); |
|
1275 |
||
1276 |
style = new Q3StyleSheetItem(this, QString::fromLatin1("html")); |
|
1277 |
} |
|
1278 |
||
1279 |
||
1280 |
||
1281 |
static Q3StyleSheet* defaultsheet = 0; |
|
1282 |
static Q3SingleCleanupHandler<Q3StyleSheet> qt_cleanup_stylesheet; |
|
1283 |
||
1284 |
/*! |
|
1285 |
Returns the application-wide default style sheet. This style sheet |
|
1286 |
is used by rich text rendering classes such as QSimpleRichText, |
|
1287 |
QWhatsThis and QMessageBox to define the rendering style and |
|
1288 |
available tags within rich text documents. It also serves as the |
|
1289 |
initial style sheet for the more complex render widgets, QTextEdit |
|
1290 |
and QTextBrowser. |
|
1291 |
||
1292 |
\sa setDefaultSheet() |
|
1293 |
*/ |
|
1294 |
Q3StyleSheet* Q3StyleSheet::defaultSheet() |
|
1295 |
{ |
|
1296 |
if (!defaultsheet) { |
|
1297 |
defaultsheet = new Q3StyleSheet(); |
|
1298 |
qt_cleanup_stylesheet.set(&defaultsheet); |
|
1299 |
} |
|
1300 |
return defaultsheet; |
|
1301 |
} |
|
1302 |
||
1303 |
/*! |
|
1304 |
Sets the application-wide default style sheet to \a sheet, |
|
1305 |
deleting any style sheet previously set. The ownership is |
|
1306 |
transferred to Q3StyleSheet. |
|
1307 |
||
1308 |
\sa defaultSheet() |
|
1309 |
*/ |
|
1310 |
void Q3StyleSheet::setDefaultSheet(Q3StyleSheet* sheet) |
|
1311 |
{ |
|
1312 |
if (defaultsheet != sheet) { |
|
1313 |
if (defaultsheet) |
|
1314 |
qt_cleanup_stylesheet.reset(); |
|
1315 |
delete defaultsheet; |
|
1316 |
} |
|
1317 |
defaultsheet = sheet; |
|
1318 |
if (defaultsheet) |
|
1319 |
qt_cleanup_stylesheet.set(&defaultsheet); |
|
1320 |
} |
|
1321 |
||
1322 |
/*!\internal |
|
1323 |
Inserts \a style. Any tags generated after this time will be |
|
1324 |
bound to this style. Note that \a style becomes owned by the |
|
1325 |
style sheet and will be deleted when the style sheet is destroyed. |
|
1326 |
*/ |
|
1327 |
void Q3StyleSheet::insert(Q3StyleSheetItem* style) |
|
1328 |
{ |
|
1329 |
styles.insert(style->name(), style); |
|
1330 |
} |
|
1331 |
||
1332 |
||
1333 |
/*! |
|
1334 |
Returns the style called \a name or 0 if there is no such style. |
|
1335 |
*/ |
|
1336 |
Q3StyleSheetItem* Q3StyleSheet::item(const QString& name) |
|
1337 |
{ |
|
1338 |
if (name.isNull()) |
|
1339 |
return 0; |
|
1340 |
return styles.value(name); |
|
1341 |
} |
|
1342 |
||
1343 |
/*! |
|
1344 |
\overload |
|
1345 |
||
1346 |
Returns the style called \a name or 0 if there is no such style |
|
1347 |
(const version) |
|
1348 |
*/ |
|
1349 |
const Q3StyleSheetItem* Q3StyleSheet::item(const QString& name) const |
|
1350 |
{ |
|
1351 |
if (name.isNull()) |
|
1352 |
return 0; |
|
1353 |
return styles.value(name); |
|
1354 |
} |
|
1355 |
||
1356 |
/*! Auxiliary function. Converts the plain text string \a plain to a |
|
1357 |
rich text formatted paragraph while preserving most of its look. |
|
1358 |
||
1359 |
\a mode defines the whitespace mode. Possible values are \c |
|
1360 |
Q3StyleSheetItem::WhiteSpacePre (no wrapping, all whitespaces |
|
1361 |
preserved) and Q3StyleSheetItem::WhiteSpaceNormal (wrapping, |
|
1362 |
simplified whitespaces). |
|
1363 |
||
1364 |
\sa escape() |
|
1365 |
*/ |
|
1366 |
QString Q3StyleSheet::convertFromPlainText(const QString& plain, Q3StyleSheetItem::WhiteSpaceMode mode) |
|
1367 |
{ |
|
1368 |
return Qt::convertFromPlainText(plain, Qt::WhiteSpaceMode(mode)); |
|
1369 |
} |
|
1370 |
||
1371 |
/*! |
|
1372 |
Auxiliary function. Converts the plain text string \a plain to a |
|
1373 |
rich text formatted string with any HTML meta-characters escaped. |
|
1374 |
||
1375 |
\sa convertFromPlainText() |
|
1376 |
*/ |
|
1377 |
QString Q3StyleSheet::escape(const QString& plain) |
|
1378 |
{ |
|
1379 |
return Qt::escape(plain); |
|
1380 |
} |
|
1381 |
||
1382 |
// Must doc this enum somewhere, and it is logically related to Q3StyleSheet |
|
1383 |
||
1384 |
/*! |
|
1385 |
Returns true if the string \a text is likely to be rich text; |
|
1386 |
otherwise returns false. |
|
1387 |
||
1388 |
This function uses a fast and therefore simple heuristic. It |
|
1389 |
mainly checks whether there is something that looks like a tag |
|
1390 |
before the first line break. Although the result may be correct |
|
1391 |
for common cases, there is no guarantee. |
|
1392 |
*/ |
|
1393 |
bool Q3StyleSheet::mightBeRichText(const QString& text) |
|
1394 |
{ |
|
1395 |
return Qt::mightBeRichText(text); |
|
1396 |
} |
|
1397 |
||
1398 |
||
1399 |
/*! |
|
1400 |
\fn void Q3StyleSheet::error(const QString& msg) const |
|
1401 |
||
1402 |
This virtual function is called when an error occurs when |
|
1403 |
processing rich text. Reimplement it if you need to catch error |
|
1404 |
messages. |
|
1405 |
||
1406 |
Errors might occur if some rich text strings contain tags that are |
|
1407 |
not understood by the stylesheet, if some tags are nested |
|
1408 |
incorrectly, or if tags are not closed properly. |
|
1409 |
||
1410 |
\a msg is the error message. |
|
1411 |
*/ |
|
1412 |
void Q3StyleSheet::error(const QString&) const |
|
1413 |
{ |
|
1414 |
} |
|
1415 |
||
1416 |
||
1417 |
/*! |
|
1418 |
Scales the font \a font to the appropriate physical point size |
|
1419 |
corresponding to the logical font size \a logicalSize. |
|
1420 |
||
1421 |
When calling this function, \a font has a point size corresponding |
|
1422 |
to the logical font size 3. |
|
1423 |
||
1424 |
Logical font sizes range from 1 to 7, with 1 being the smallest. |
|
1425 |
||
1426 |
\sa Q3StyleSheetItem::logicalFontSize(), Q3StyleSheetItem::logicalFontSizeStep(), QFont::setPointSize() |
|
1427 |
*/ |
|
1428 |
void Q3StyleSheet::scaleFont(QFont& font, int logicalSize) const |
|
1429 |
{ |
|
1430 |
if (logicalSize < 1) |
|
1431 |
logicalSize = 1; |
|
1432 |
if (logicalSize > 7) |
|
1433 |
logicalSize = 7; |
|
1434 |
int baseSize = font.pointSize(); |
|
1435 |
bool pixel = false; |
|
1436 |
if (baseSize == -1) { |
|
1437 |
baseSize = font.pixelSize(); |
|
1438 |
pixel = true; |
|
1439 |
} |
|
1440 |
int s; |
|
1441 |
switch (logicalSize) { |
|
1442 |
case 1: |
|
1443 |
s = 7*baseSize/10; |
|
1444 |
break; |
|
1445 |
case 2: |
|
1446 |
s = (8 * baseSize) / 10; |
|
1447 |
break; |
|
1448 |
case 4: |
|
1449 |
s = (12 * baseSize) / 10; |
|
1450 |
break; |
|
1451 |
case 5: |
|
1452 |
s = (15 * baseSize) / 10; |
|
1453 |
break; |
|
1454 |
case 6: |
|
1455 |
s = 2 * baseSize; |
|
1456 |
break; |
|
1457 |
case 7: |
|
1458 |
s = (24 * baseSize) / 10; |
|
1459 |
break; |
|
1460 |
default: |
|
1461 |
s = baseSize; |
|
1462 |
} |
|
1463 |
if (pixel) |
|
1464 |
font.setPixelSize(qMax(1, s)); |
|
1465 |
else |
|
1466 |
font.setPointSize(qMax(1, s)); |
|
1467 |
} |
|
1468 |
||
1469 |
QT_END_NAMESPACE |
|
1470 |
||
1471 |
#endif // QT_NO_RICHTEXT |