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