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