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