summaryrefslogtreecommitdiffstats
path: root/style/qtc_kstyle.cpp
blob: d29451bb262bcadc3c0bdec75585f1a34566909a (plain)
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
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
/*
 *
 * TQtCKStyle
 * Copyright (C) 2001-2002 Karol Szwed <gallium@kde.org>
 *
 * TQWindowsStyle CC_ListView and style images were kindly donated by TrollTech,
 * Copyright (C) 1998-2000 TrollTech AS.
 *
 * Many thanks to Bradley T. Hughes for the 3 button scrollbar code.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License version 2 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include "qtc_kstyle.h"

#include <tqapplication.h>
#include <tqbitmap.h>
#include <tqcleanuphandler.h>
#include <tqmap.h>
#include <tqimage.h>
#include <tqlistview.h>
#include <tqmenubar.h>
#include <tqpainter.h>
#include <tqpixmap.h>
#include <tqpopupmenu.h>
#include <tqprogressbar.h>
#include <tqscrollbar.h>
#include <tqsettings.h>
#include <tqslider.h>
#include <tqstylefactory.h>
#include <tqtabbar.h>
#include <tqtoolbar.h>

#ifdef TQ_WS_X11
# include <X11/Xlib.h>
# ifdef HAVE_XRENDER
#  include <X11/extensions/Xrender.h> // schroder
   extern bool tqt_use_xrender;
# endif
#else
#undef HAVE_XRENDER
#endif


#include <limits.h>

struct TQtCKStylePrivate
{
	bool  highcolor                : 1;
	bool  useFilledFrameWorkaround : 1;
	bool  etchDisabledText         : 1;
	bool  scrollablePopupmenus     : 1;
	bool  menuAltKeyNavigation     : 1;
	bool  menuDropShadow           : 1;
	bool  sloppySubMenus           : 1;
	int   popupMenuDelay;
	float menuOpacity;

	TQtCKStyle::KStyleScrollBarType  scrollbarType;
	TQtCKStyle::KStyleFlags flags;
	
	//For KPE_ListViewBranch
	TQBitmap *verticalLine;
	TQBitmap *horizontalLine;
};

// -----------------------------------------------------------------------------


TQtCKStyle::TQtCKStyle( KStyleFlags flags, KStyleScrollBarType sbtype )
	: TQCommonStyle(), d(new TQtCKStylePrivate)
{
	d->flags = flags;
	d->useFilledFrameWorkaround = (flags & FilledFrameWorkaround);
	d->scrollbarType = sbtype;
	d->highcolor = TQPixmap::defaultDepth() > 8;

	// Read style settings
	TQSettings settings;
	d->popupMenuDelay       = settings.readNumEntry ("/TQtCKStyle/Settings/PopupMenuDelay", 256);
	d->sloppySubMenus       = settings.readBoolEntry("/TQtCKStyle/Settings/SloppySubMenus", false);
	d->etchDisabledText     = settings.readBoolEntry("/TQtCKStyle/Settings/EtchDisabledText", true);
	d->menuAltKeyNavigation = settings.readBoolEntry("/TQtCKStyle/Settings/MenuAltKeyNavigation", true);
	d->scrollablePopupmenus = settings.readBoolEntry("/TQtCKStyle/Settings/ScrollablePopupMenus", false);
	d->menuDropShadow       = settings.readBoolEntry("/TQtCKStyle/Settings/MenuDropShadow", false);
	
	d->verticalLine   = 0;
	d->horizontalLine = 0;
}


TQtCKStyle::~TQtCKStyle()
{
	delete d->verticalLine;
	delete d->horizontalLine;

	delete d;
}


TQString TQtCKStyle::defaultStyle()
{
	if (TQPixmap::defaultDepth() > 8)
	   return TQString("plastik");
	else
	   return TQString("light, 3rd revision");
}


void TQtCKStyle::polish( TQStyleControlElementData ceData, ControlElementFlags elementFlags, void *ptr )
{
    if (ceData.widgetObjectTypes.contains(TQWIDGET_OBJECT_NAME_STRING)) {
		TQWidget *widget = reinterpret_cast<TQWidget*>(ptr);

		if ( d->useFilledFrameWorkaround )
		{
			if ( TQFrame *frame = ::tqqt_cast< TQFrame* >( widget ) ) {
				TQFrame::Shape shape = frame->frameShape();
				if (shape == TQFrame::ToolBarPanel || shape == TQFrame::MenuBarPanel)
					installObjectEventHandler(ceData, elementFlags, ptr, this);
			} 
		}
	}
}


void TQtCKStyle::unPolish( TQStyleControlElementData ceData, ControlElementFlags elementFlags, void *ptr )
{
    if (ceData.widgetObjectTypes.contains(TQWIDGET_OBJECT_NAME_STRING)) {
		TQWidget *widget = reinterpret_cast<TQWidget*>(ptr);

		if ( d->useFilledFrameWorkaround )
		{
			if ( TQFrame *frame = ::tqqt_cast< TQFrame* >( widget ) ) {
				TQFrame::Shape shape = frame->frameShape();
				if (shape == TQFrame::ToolBarPanel || shape == TQFrame::MenuBarPanel)
					removeObjectEventHandler(ceData, elementFlags, ptr, this);
			} 
		}
	}
}


// Style changes (should) always re-polish popups.
void TQtCKStyle::polishPopupMenu( TQStyleControlElementData ceData, ControlElementFlags elementFlags, void *ptr )
{
    if ( !(ceData.windowState & WState_Polished ) ) {
        widgetActionRequest(ceData, elementFlags, ptr, WAR_SetCheckable);
    }
}


// -----------------------------------------------------------------------------
// TQtCKStyle extensions
// -----------------------------------------------------------------------------

void TQtCKStyle::setScrollBarType(KStyleScrollBarType sbtype)
{
	d->scrollbarType = sbtype;
}

TQtCKStyle::KStyleFlags TQtCKStyle::styleFlags() const
{
	return d->flags;
}

void TQtCKStyle::drawKStylePrimitive( KStylePrimitive kpe,
								  TQPainter* p,
								  TQStyleControlElementData ceData,
								  ControlElementFlags elementFlags,
								  const TQRect &r,
								  const TQColorGroup &cg,
								  SFlags flags,
								  const TQStyleOption& /* opt */,
								  const TQWidget* widget ) const
{
	switch( kpe )
	{
		// Dock / Toolbar / General handles.
		// ---------------------------------

		case KPE_DockWindowHandle: {

			// Draws a nice DockWindow handle including the dock title.
			TQWidget* wid = const_cast<TQWidget*>(widget);
			bool horizontal = flags & Style_Horizontal;
			int x,y,w,h,x2,y2;

			r.rect( &x, &y, &w, &h );
			if ((w <= 2) || (h <= 2)) {
				p->fillRect(r, cg.highlight());
				return;
			}

			
			x2 = x + w - 1;
			y2 = y + h - 1;

			TQFont fnt;
			fnt = TQApplication::font(wid);
			fnt.setPointSize( fnt.pointSize()-2 );

			// Draw the item on an off-screen pixmap
			// to preserve Xft antialiasing for
			// vertically oriented handles.
			TQPixmap pix;
			if (horizontal)
				pix.resize( h-2, w-2 );
			else
				pix.resize( w-2, h-2 );

			TQString title = wid->parentWidget()->caption();
			TQPainter p2;
			p2.begin(&pix);
			p2.fillRect(pix.rect(), cg.brush(TQColorGroup::Highlight));
			p2.setPen(cg.highlightedText());
			p2.setFont(fnt);
			p2.drawText(pix.rect(), AlignCenter, title);
			p2.end();

			// Draw a sunken bevel
			p->setPen(cg.dark());
			p->drawLine(x, y, x2, y);
			p->drawLine(x, y, x, y2);
			p->setPen(cg.light());
			p->drawLine(x+1, y2, x2, y2);
			p->drawLine(x2, y+1, x2, y2);

			if (horizontal) {
				TQWMatrix m;
				m.rotate(-90.0);
				TQPixmap vpix = pix.xForm(m);
				bitBlt(wid, r.x()+1, r.y()+1, &vpix);
			} else
				bitBlt(wid, r.x()+1, r.y()+1, &pix);

			break;
		}


		/*
		 * KPE_ListViewExpander and KPE_ListViewBranch are based on code from
		 * TQWindowStyle's CC_ListView, kindly donated by TrollTech.
		 * CC_ListView code is Copyright (C) 1998-2000 TrollTech AS.
		 */

		case KPE_ListViewExpander: {
			// Typical Windows style expand/collapse element.
			int radius = (r.width() - 4) / 2;
			int centerx = r.x() + r.width()/2;
			int centery = r.y() + r.height()/2;

			// Outer box
			p->setPen( cg.mid() );
			p->drawRect( r );

			// plus or minus
			p->setPen( cg.text() );
			p->drawLine( centerx - radius, centery, centerx + radius, centery );
			if ( flags & Style_On )	// Collapsed = On
				p->drawLine( centerx, centery - radius, centerx, centery + radius );
			break;
		}

		case KPE_ListViewBranch: {
			// Typical Windows style listview branch element (dotted line).

			// Create the dotline pixmaps if not already created
			if ( !d->verticalLine )
			{
				// make 128*1 and 1*128 bitmaps that can be used for
				// drawing the right sort of lines.
				d->verticalLine   = new TQBitmap( 1, 129, true );
				d->horizontalLine = new TQBitmap( 128, 1, true );
				TQPointArray a( 64 );
				TQPainter p2;
				p2.begin( d->verticalLine );

				int i;
				for( i=0; i < 64; i++ )
					a.setPoint( i, 0, i*2+1 );
				p2.setPen( color1 );
				p2.drawPoints( a );
				p2.end();
				TQApplication::flushX();
				d->verticalLine->setMask( *d->verticalLine );

				p2.begin( d->horizontalLine );
				for( i=0; i < 64; i++ )
					a.setPoint( i, i*2+1, 0 );
				p2.setPen( color1 );
				p2.drawPoints( a );
				p2.end();
				TQApplication::flushX();
				d->horizontalLine->setMask( *d->horizontalLine );
			}

			p->setPen( cg.text() );		// cg.dark() is bad for dark color schemes.

			if (flags & Style_Horizontal)
			{
				int point = r.x();
				int other = r.y();
				int end = r.x()+r.width();
				int thickness = r.height();

				while( point < end )
				{
					int i = 128;
					if ( i+point > end )
						i = end-point;
					p->drawPixmap( point, other, *d->horizontalLine, 0, 0, i, thickness );
					point += i;
				}

			} else {
				int point = r.y();
				int other = r.x();
				int end = r.y()+r.height();
				int thickness = r.width();
				int pixmapoffset = (flags & Style_NoChange) ? 0 : 1;	// ### Hackish

				while( point < end )
				{
					int i = 128;
					if ( i+point > end )
						i = end-point;
					p->drawPixmap( other, point, *d->verticalLine, 0, pixmapoffset, thickness, i );
					point += i;
				}
			}

			break;
		}

		// Reimplement the other primitives in your styles.
		// The current implementation just paints something visibly different.
		case KPE_ToolBarHandle:
		case KPE_GeneralHandle:
		case KPE_SliderHandle:
			p->fillRect(r, cg.light());
			break;

		case KPE_SliderGroove:
			p->fillRect(r, cg.dark());
			break;

		default:
			p->fillRect(r, TQt::yellow);	// Something really bad happened - highlight.
			break;
	}
}


int TQtCKStyle::kPixelMetric( KStylePixelMetric kpm, TQStyleControlElementData ceData, ControlElementFlags elementFlags, const TQWidget* /* widget */) const
{
	int value;
	switch(kpm)
	{
		case KPM_ListViewBranchThickness:
			value = 1;
			break;

		case KPM_MenuItemSeparatorHeight:
		case KPM_MenuItemHMargin:
		case KPM_MenuItemVMargin:
		case KPM_MenuItemHFrame:
		case KPM_MenuItemVFrame:
		case KPM_MenuItemCheckMarkHMargin:
		case KPM_MenuItemArrowHMargin:
		case KPM_MenuItemTabSpacing:
		default:
			value = 0;
	}

	return value;
}


// -----------------------------------------------------------------------------

void TQtCKStyle::drawPrimitive( PrimitiveElement pe,
							TQPainter* p,
							TQStyleControlElementData ceData,
							ControlElementFlags elementFlags,
							const TQRect &r,
							const TQColorGroup &cg,
							SFlags flags,
							const TQStyleOption& opt ) const
{
	// TOOLBAR/DOCK WINDOW HANDLE
	// ------------------------------------------------------------------------
	if (pe == PE_DockWindowHandle)
	{
		// Wild workarounds are here. Beware.
		TQWidget *widget, *parent;

		if (p && p->device()->devType() == TQInternal::Widget) {
			widget = static_cast<TQWidget*>(p->device());
			parent = widget->parentWidget();
		} else
			return;		// Don't paint on non-widgets

		// Check if we are a normal toolbar or a hidden dockwidget.
		if ( parent &&
			(parent->inherits(TQTOOLBAR_OBJECT_NAME_STRING) ||		// Normal toolbar
			(parent->inherits(TQMAINWINDOW_OBJECT_NAME_STRING)) ))	// Collapsed dock

			// Draw a toolbar handle
			drawKStylePrimitive( KPE_ToolBarHandle, p, ceData, elementFlags, r, cg, flags, opt, widget );

		else if ( widget->inherits(TQDOCKWINDOWHANDLE_OBJECT_NAME_STRING) )

			// Draw a dock window handle
			drawKStylePrimitive( KPE_DockWindowHandle, p, ceData, elementFlags, r, cg, flags, opt, widget );

		else
			// General handle, probably a kicker applet handle.
			drawKStylePrimitive( KPE_GeneralHandle, p, ceData, elementFlags, r, cg, flags, opt, widget );

	} else
		TQCommonStyle::drawPrimitive( pe, p, ceData, elementFlags, r, cg, flags, opt );
}



void TQtCKStyle::drawControl( ControlElement element,
						  TQPainter* p,
						  TQStyleControlElementData ceData,
						  ControlElementFlags elementFlags,
						  const TQRect &r,
						  const TQColorGroup &cg,
						  SFlags flags,
						  const TQStyleOption &opt,
						  const TQWidget* widget ) const
{
	switch (element)
	{
		// TABS
		// ------------------------------------------------------------------------
		case CE_TabBarTab: {
			const TQTabBar* tb  = (const TQTabBar*) widget;
			TQTabBar::Shape tbs = tb->shape();
			bool selected      = flags & Style_Selected;
			int x = r.x(), y=r.y(), bottom=r.bottom(), right=r.right();

			switch (tbs) {

				case TQTabBar::RoundedAbove: {
					if (!selected)
						p->translate(0,1);
					p->setPen(selected ? cg.light() : cg.shadow());
					p->drawLine(x, y+4, x, bottom);
					p->drawLine(x, y+4, x+4, y);
					p->drawLine(x+4, y, right-1, y);
					if (selected)
						p->setPen(cg.shadow());
					p->drawLine(right, y+1, right, bottom);

					p->setPen(cg.midlight());
					p->drawLine(x+1, y+4, x+1, bottom);
					p->drawLine(x+1, y+4, x+4, y+1);
					p->drawLine(x+5, y+1, right-2, y+1);

					if (selected) {
						p->setPen(cg.mid());
						p->drawLine(right-1, y+1, right-1, bottom);
					} else {
						p->setPen(cg.mid());
						p->drawPoint(right-1, y+1);
						p->drawLine(x+4, y+2, right-1, y+2);
						p->drawLine(x+3, y+3, right-1, y+3);
						p->fillRect(x+2, y+4, r.width()-3, r.height()-6, cg.mid());

						p->setPen(cg.light());
						p->drawLine(x, bottom-1, right, bottom-1);
						p->translate(0,-1);
					}
					break;
				}

				case TQTabBar::RoundedBelow: {
					if (!selected)
						p->translate(0,-1);
					p->setPen(selected ? cg.light() : cg.shadow());
					p->drawLine(x, bottom-4, x, y);
					if (selected)
						p->setPen(cg.mid());
					p->drawLine(x, bottom-4, x+4, bottom);
					if (selected)
						p->setPen(cg.shadow());
					p->drawLine(x+4, bottom, right-1, bottom);
					p->drawLine(right, bottom-1, right, y);

					p->setPen(cg.midlight());
					p->drawLine(x+1, bottom-4, x+1, y);
					p->drawLine(x+1, bottom-4, x+4, bottom-1);
					p->drawLine(x+5, bottom-1, right-2, bottom-1);

					if (selected) {
						p->setPen(cg.mid());
						p->drawLine(right-1, y, right-1, bottom-1);
					} else {
						p->setPen(cg.mid());
						p->drawPoint(right-1, bottom-1);
						p->drawLine(x+4, bottom-2, right-1, bottom-2);
						p->drawLine(x+3, bottom-3, right-1, bottom-3);
						p->fillRect(x+2, y+2, r.width()-3, r.height()-6, cg.mid());
						p->translate(0,1);
						p->setPen(cg.dark());
						p->drawLine(x, y, right, y);
					}
					break;
				}

				case TQTabBar::TriangularAbove: {
					if (!selected)
						p->translate(0,1);
					p->setPen(selected ? cg.light() : cg.shadow());
					p->drawLine(x, bottom, x, y+6);
					p->drawLine(x, y+6, x+6, y);
					p->drawLine(x+6, y, right-6, y);
					if (selected)
						p->setPen(cg.mid());
					p->drawLine(right-5, y+1, right-1, y+5);
					p->setPen(cg.shadow());
					p->drawLine(right, y+6, right, bottom);

					p->setPen(cg.midlight());
					p->drawLine(x+1, bottom, x+1, y+6);
					p->drawLine(x+1, y+6, x+6, y+1);
					p->drawLine(x+6, y+1, right-6, y+1);
					p->drawLine(right-5, y+2, right-2, y+5);
					p->setPen(cg.mid());
					p->drawLine(right-1, y+6, right-1, bottom);

					TQPointArray a(6);
					a.setPoint(0, x+2, bottom);
					a.setPoint(1, x+2, y+7);
					a.setPoint(2, x+7, y+2);
					a.setPoint(3, right-7, y+2);
					a.setPoint(4, right-2, y+7);
					a.setPoint(5, right-2, bottom);
					p->setPen  (selected ? cg.background() : cg.mid());
					p->setBrush(selected ? cg.background() : cg.mid());
					p->drawPolygon(a);
					p->setBrush(NoBrush);
					if (!selected) {
						p->translate(0,-1);
						p->setPen(cg.light());
						p->drawLine(x, bottom, right, bottom);
					}
					break;
				}

				default: { // TQTabBar::TriangularBelow
					if (!selected)
						p->translate(0,-1);
					p->setPen(selected ? cg.light() : cg.shadow());
					p->drawLine(x, y, x, bottom-6);
					if (selected)
						p->setPen(cg.mid());
					p->drawLine(x, bottom-6, x+6, bottom);
					if (selected)
						p->setPen(cg.shadow());
					p->drawLine(x+6, bottom, right-6, bottom);
					p->drawLine(right-5, bottom-1, right-1, bottom-5);
					if (!selected)
						p->setPen(cg.shadow());
					p->drawLine(right, bottom-6, right, y);

					p->setPen(cg.midlight());
					p->drawLine(x+1, y, x+1, bottom-6);
					p->drawLine(x+1, bottom-6, x+6, bottom-1);
					p->drawLine(x+6, bottom-1, right-6, bottom-1);
					p->drawLine(right-5, bottom-2, right-2, bottom-5);
					p->setPen(cg.mid());
					p->drawLine(right-1, bottom-6, right-1, y);

					TQPointArray a(6);
					a.setPoint(0, x+2, y);
					a.setPoint(1, x+2, bottom-7);
					a.setPoint(2, x+7, bottom-2);
					a.setPoint(3, right-7, bottom-2);
					a.setPoint(4, right-2, bottom-7);
					a.setPoint(5, right-2, y);
					p->setPen  (selected ? cg.background() : cg.mid());
					p->setBrush(selected ? cg.background() : cg.mid());
					p->drawPolygon(a);
					p->setBrush(NoBrush);
					if (!selected) {
						p->translate(0,1);
						p->setPen(cg.dark());
						p->drawLine(x, y, right, y);
					}
					break;
				}
			};

			break;
		}
		
		// Popup menu scroller
		// ------------------------------------------------------------------------
		case CE_PopupMenuScroller: {
			p->fillRect(r, cg.background());
			drawPrimitive(PE_ButtonTool, p, ceData, elementFlags, r, cg, Style_Enabled);
			drawPrimitive((flags & Style_Up) ? PE_ArrowUp : PE_ArrowDown, p, ceData, elementFlags, r, cg, Style_Enabled);
			break;
		}


		// PROGRESSBAR
		// ------------------------------------------------------------------------
		case CE_ProgressBarGroove: {
			TQRect fr = subRect(SR_ProgressBarGroove, ceData, elementFlags, widget);
			drawPrimitive(PE_Panel, p, ceData, elementFlags, fr, cg, Style_Sunken, TQStyleOption::Default);
			break;
		}

		case CE_ProgressBarContents: {
			// ### Take into account totalSteps() for busy indicator
			const TQProgressBar* pb = (const TQProgressBar*)widget;
			TQRect cr = subRect(SR_ProgressBarContents, ceData, elementFlags, widget);
			double progress = pb->progress();
			bool reverse = TQApplication::reverseLayout();
			int steps = pb->totalSteps();

			if (!cr.isValid())
				return;

			// Draw progress bar
			if (progress > 0 || steps == 0) {
				double pg = (steps == 0) ? 0.1 : progress / steps;
				int width = TQMIN(cr.width(), (int)(pg * cr.width()));
				if (steps == 0) { //Busy indicator

					if (width < 1) width = 1; //A busy indicator with width 0 is kind of useless

					int remWidth = cr.width() - width; //Never disappear completely
					if (remWidth <= 0) remWidth = 1; //Do something non-crashy when too small...

					int pstep =  int(progress) % ( 2 *  remWidth );

					if ( pstep > remWidth ) {
						//Bounce about.. We're remWidth + some delta, we want to be remWidth - delta...
						// - ( (remWidth + some delta) - 2* remWidth )  = - (some deleta - remWidth) = remWidth - some delta..
						pstep = - (pstep - 2 * remWidth );
					}

					if (reverse)
						p->fillRect(cr.x() + cr.width() - width - pstep, cr.y(), width, cr.height(),
									cg.brush(TQColorGroup::Highlight));
					else
						p->fillRect(cr.x() + pstep, cr.y(), width, cr.height(),
									cg.brush(TQColorGroup::Highlight));

					return;
				}


				// Do fancy gradient for highcolor displays
// 				if (d->highcolor) {
// 					TQColor c(cg.highlight());
// 					KPixmap pix;
// 					pix.resize(cr.width(), cr.height());
// 					KPixmapEffect::gradient(pix, reverse ? c.light(150) : c.dark(150),
// 											reverse ? c.dark(150) : c.light(150),
// 											KPixmapEffect::HorizontalGradient);
// 					if (reverse)
// 						p->drawPixmap(cr.x()+(cr.width()-width), cr.y(), pix,
// 									  cr.width()-width, 0, width, cr.height());
// 					else
// 						p->drawPixmap(cr.x(), cr.y(), pix, 0, 0, width, cr.height());
// 				} else
					if (reverse)
						p->fillRect(cr.x()+(cr.width()-width), cr.y(), width, cr.height(),
									cg.brush(TQColorGroup::Highlight));
					else
						p->fillRect(cr.x(), cr.y(), width, cr.height(),
									cg.brush(TQColorGroup::Highlight));
			}
			break;
		}

		case CE_ProgressBarLabel: {
			const TQProgressBar* pb = (const TQProgressBar*)widget;
			TQRect cr = subRect(SR_ProgressBarContents, ceData, elementFlags, widget);
			double progress = pb->progress();
			bool reverse = TQApplication::reverseLayout();
			int steps = pb->totalSteps();

			if (!cr.isValid())
				return;

			TQFont font = p->font();
			font.setBold(true);
			p->setFont(font);

			// Draw label
			if (progress > 0 || steps == 0) {
				double pg = (steps == 0) ? 1.0 : progress / steps;
				int width = TQMIN(cr.width(), (int)(pg * cr.width()));
				TQRect crect;
				if (reverse)
					crect.setRect(cr.x()+(cr.width()-width), cr.y(), cr.width(), cr.height());
				else
					crect.setRect(cr.x()+width, cr.y(), cr.width(), cr.height());
					
				p->save();
				p->setPen(pb->isEnabled() ? (reverse ? cg.text() : cg.highlightedText()) : cg.text());
				p->drawText(r, AlignCenter, pb->progressString());
				p->setClipRect(crect);
				p->setPen(reverse ? cg.highlightedText() : cg.text());
				p->drawText(r, AlignCenter, pb->progressString());
				p->restore();

			} else {
				p->setPen(cg.text());
				p->drawText(r, AlignCenter, pb->progressString());
			}

			break;
		}

		default:
			TQCommonStyle::drawControl(element, p, ceData, elementFlags, r, cg, flags, opt, widget);
	}
}


TQRect TQtCKStyle::subRect(SubRect r, const TQStyleControlElementData ceData, const ControlElementFlags elementFlags, const TQWidget* widget) const
{
	switch(r)
	{
		// KDE2 look smooth progress bar
		// ------------------------------------------------------------------------
		case SR_ProgressBarGroove:
			return widget->rect();

		case SR_ProgressBarContents:
		case SR_ProgressBarLabel: {
			// ### take into account indicatorFollowsStyle()
			TQRect rt = widget->rect();
			return TQRect(rt.x()+2, rt.y()+2, rt.width()-4, rt.height()-4);
		}

		default:
			return TQCommonStyle::subRect(r, ceData, elementFlags, widget);
	}
}


int TQtCKStyle::pixelMetric(PixelMetric m, TQStyleControlElementData ceData, ControlElementFlags elementFlags, const TQWidget* widget) const
{
	switch(m)
	{
		// BUTTONS
		// ------------------------------------------------------------------------
		case PM_ButtonShiftHorizontal:		// Offset by 1
		case PM_ButtonShiftVertical:		// ### Make configurable
			return 1;

		case PM_DockWindowHandleExtent:
		{
			TQWidget* parent = 0;
			// Check that we are not a normal toolbar or a hidden dockwidget,
			// in which case we need to adjust the height for font size
			if (widget && (parent = widget->parentWidget() )
				&& !parent->inherits(TQTOOLBAR_OBJECT_NAME_STRING)
				&& !parent->inherits(TQMAINWINDOW_OBJECT_NAME_STRING)
				&& widget->inherits(TQDOCKWINDOWHANDLE_OBJECT_NAME_STRING) )
					return widget->fontMetrics().lineSpacing();
			else
				return TQCommonStyle::pixelMetric(m, ceData, elementFlags, widget);
		}

		// TABS
		// ------------------------------------------------------------------------
		case PM_TabBarTabHSpace:
			return 24;

		case PM_TabBarTabVSpace: {
			const TQTabBar * tb = (const TQTabBar *) widget;
			if ( tb->shape() == TQTabBar::RoundedAbove ||
				 tb->shape() == TQTabBar::RoundedBelow )
				return 10;
			else
				return 4;
		}

		case PM_TabBarTabOverlap: {
			const TQTabBar* tb = (const TQTabBar*)widget;
			TQTabBar::Shape tbs = tb->shape();

			if ( (tbs == TQTabBar::RoundedAbove) ||
				 (tbs == TQTabBar::RoundedBelow) )
				return 0;
			else
				return 2;
		}

		// SLIDER
		// ------------------------------------------------------------------------
		case PM_SliderLength:
			return 18;

		case PM_SliderThickness:
			return 24;

		// Determines how much space to leave for the actual non-tickmark
		// portion of the slider.
		case PM_SliderControlThickness: {
			const TQSlider* slider   = (const TQSlider*)widget;
			TQSlider::TickSetting ts = slider->tickmarks();
			int thickness = (slider->orientation() == Qt::Horizontal) ?
							 slider->height() : slider->width();
			switch (ts) {
				case TQSlider::NoMarks:				// Use total area.
					break;
				case TQSlider::Both:
					thickness = (thickness/2) + 3;	// Use approx. 1/2 of area.
					break;
				default:							// Use approx. 2/3 of area
					thickness = ((thickness*2)/3) + 3;
					break;
			};
			return thickness;
		}

		// SPLITTER
		// ------------------------------------------------------------------------
		case PM_SplitterWidth:
			if (widget && widget->inherits("TQDockWindowResizeHandle"))
				return 8;	// ### why do we need 2pix extra?
			else
				return 6;

		// FRAMES
		// ------------------------------------------------------------------------
		case PM_MenuBarFrameWidth:
			return 1;

		case PM_DockWindowFrameWidth:
			return 1;

		// GENERAL
		// ------------------------------------------------------------------------
		case PM_MaximumDragDistance:
			return -1;

		case PM_MenuBarItemSpacing:
			return 5;

		case PM_ToolBarItemSpacing:
			return 0;

		case PM_PopupMenuScrollerHeight:
			return pixelMetric( PM_ScrollBarExtent, ceData, elementFlags, 0);

		default:
			return TQCommonStyle::pixelMetric( m, ceData, elementFlags, widget );
	}
}

//Helper to find the next sibling that's not hidden
static TQListViewItem* nextVisibleSibling(TQListViewItem* item)
{
    TQListViewItem* sibling = item;
    do
    {
        sibling = sibling->nextSibling();
    }
    while (sibling && !sibling->isVisible());
    
    return sibling;
}

void TQtCKStyle::drawComplexControl( ComplexControl control,
								 TQPainter* p,
								 TQStyleControlElementData ceData,
								 ControlElementFlags elementFlags,
								 const TQRect &r,
								 const TQColorGroup &cg,
								 SFlags flags,
								 SCFlags controls,
								 SCFlags active,
								 const TQStyleOption &opt,
								 const TQWidget* widget ) const
{
	switch(control)
	{
		// 3 BUTTON SCROLLBAR
		// ------------------------------------------------------------------------
		case CC_ScrollBar: {
			// Many thanks to Brad Hughes for contributing this code.
			bool useThreeButtonScrollBar = (d->scrollbarType & ThreeButtonScrollBar);

			const TQScrollBar *sb = (const TQScrollBar*)widget;
			bool   maxedOut   = (sb->minValue()    == sb->maxValue());
			bool   horizontal = (sb->orientation() == Qt::Horizontal);
			SFlags sflags     = ((horizontal ? Style_Horizontal : Style_Default) |
								 (maxedOut   ? Style_Default : Style_Enabled));

			TQRect  addline, subline, subline2, addpage, subpage, slider, first, last;
			subline = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarSubLine, opt, widget);
			addline = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarAddLine, opt, widget);
			subpage = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarSubPage, opt, widget);
			addpage = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarAddPage, opt, widget);
			slider  = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarSlider,  opt, widget);
			first   = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarFirst,   opt, widget);
			last    = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarLast,    opt, widget);
			subline2 = addline;

			if ( useThreeButtonScrollBar )
				if (horizontal)
					subline2.moveBy(-addline.width(), 0);
				else
					subline2.moveBy(0, -addline.height());

			// Draw the up/left button set
			if ((controls & SC_ScrollBarSubLine) && subline.isValid()) {
				drawPrimitive(PE_ScrollBarSubLine, p, ceData, elementFlags, subline, cg,
							sflags | (active == SC_ScrollBarSubLine ?
								Style_Down : Style_Default));

				if (useThreeButtonScrollBar && subline2.isValid())
					drawPrimitive(PE_ScrollBarSubLine, p, ceData, elementFlags, subline2, cg,
							sflags | (active == SC_ScrollBarSubLine ?
								Style_Down : Style_Default));
			}

			if ((controls & SC_ScrollBarAddLine) && addline.isValid())
				drawPrimitive(PE_ScrollBarAddLine, p, ceData, elementFlags, addline, cg,
							sflags | ((active == SC_ScrollBarAddLine) ?
										Style_Down : Style_Default));

			if ((controls & SC_ScrollBarSubPage) && subpage.isValid())
				drawPrimitive(PE_ScrollBarSubPage, p, ceData, elementFlags, subpage, cg,
							sflags | ((active == SC_ScrollBarSubPage) ?
										Style_Down : Style_Default));

			if ((controls & SC_ScrollBarAddPage) && addpage.isValid())
				drawPrimitive(PE_ScrollBarAddPage, p, ceData, elementFlags, addpage, cg,
							sflags | ((active == SC_ScrollBarAddPage) ?
										Style_Down : Style_Default));

			if ((controls & SC_ScrollBarFirst) && first.isValid())
				drawPrimitive(PE_ScrollBarFirst, p, ceData, elementFlags, first, cg,
							sflags | ((active == SC_ScrollBarFirst) ?
										Style_Down : Style_Default));

			if ((controls & SC_ScrollBarLast) && last.isValid())
				drawPrimitive(PE_ScrollBarLast, p, ceData, elementFlags, last, cg,
							sflags | ((active == SC_ScrollBarLast) ?
										Style_Down : Style_Default));

			if ((controls & SC_ScrollBarSlider) && slider.isValid()) {
				drawPrimitive(PE_ScrollBarSlider, p, ceData, elementFlags, slider, cg,
							sflags | ((active == SC_ScrollBarSlider) ?
										Style_Down : Style_Default));
				// Draw focus rect
				if (sb->hasFocus()) {
					TQRect fr(slider.x() + 2, slider.y() + 2,
							 slider.width() - 5, slider.height() - 5);
					drawPrimitive(PE_FocusRect, p, ceData, elementFlags, fr, cg, Style_Default);
				}
			}
			break;
		}


		// SLIDER
		// -------------------------------------------------------------------
		case CC_Slider: {
			const TQSlider* slider = (const TQSlider*)widget;
			TQRect groove = querySubControlMetrics(CC_Slider, ceData, elementFlags, SC_SliderGroove, opt, widget);
			TQRect handle = querySubControlMetrics(CC_Slider, ceData, elementFlags, SC_SliderHandle, opt, widget);

			// Double-buffer slider for no flicker
			TQPixmap pix(widget->size());
			TQPainter p2;
			p2.begin(&pix);

			if ( slider->parentWidget() &&
				 slider->parentWidget()->backgroundPixmap() &&
				 !slider->parentWidget()->backgroundPixmap()->isNull() ) {
				TQPixmap pixmap = *(slider->parentWidget()->backgroundPixmap());
				p2.drawTiledPixmap(r, pixmap, slider->pos());
			} else
				pix.fill(cg.background());

			// Draw slider groove
			if ((controls & SC_SliderGroove) && groove.isValid()) {
				drawKStylePrimitive( KPE_SliderGroove, &p2, ceData, elementFlags, groove, cg, flags, opt, widget );

				// Draw the focus rect around the groove
				if (slider->hasFocus())
					drawPrimitive(PE_FocusRect, &p2, ceData, elementFlags, groove, cg);
			}

			// Draw the tickmarks
			if (controls & SC_SliderTickmarks)
				TQCommonStyle::drawComplexControl(control, &p2, ceData, elementFlags,
						r, cg, flags, SC_SliderTickmarks, active, opt, widget);

			// Draw the slider handle
			if ((controls & SC_SliderHandle) && handle.isValid()) {
				if (active == SC_SliderHandle)
					flags |= Style_Active;
				drawKStylePrimitive( KPE_SliderHandle, &p2, ceData, elementFlags, handle, cg, flags, opt, widget );
			}

			p2.end();
			bitBlt((TQWidget*)widget, r.x(), r.y(), &pix);
			break;
		}

		// LISTVIEW
		// -------------------------------------------------------------------
		case CC_ListView: {

			/*
			 * Many thanks to TrollTech AS for donating CC_ListView from TQWindowsStyle.
			 * CC_ListView code is Copyright (C) 1998-2000 TrollTech AS.
			 */

			// Paint the icon and text.
			if ( controls & SC_ListView )
				TQCommonStyle::drawComplexControl( control, p, ceData, elementFlags, r, cg, flags, controls, active, opt, widget );

			// If we're have a branch or are expanded...
			if ( controls & (SC_ListViewBranch | SC_ListViewExpand) )
			{
				// If no list view item was supplied, break
				if (opt.isDefault())
					break;

				TQListViewItem *item  = opt.listViewItem();
				TQListViewItem *child = item->firstChild();

				int y = r.y();
				int c;	// dotline vertice count
				int dotoffset = 0;
				TQPointArray dotlines;

				if ( active == SC_All && controls == SC_ListViewExpand ) {
					// We only need to draw a vertical line
					c = 2;
					dotlines.resize(2);
					dotlines[0] = TQPoint( r.right(), r.top() );
					dotlines[1] = TQPoint( r.right(), r.bottom() );

				} else {

					int linetop = 0, linebot = 0;
					// each branch needs at most two lines, ie. four end points
					dotoffset = (item->itemPos() + item->height() - y) % 2;
					dotlines.resize( item->childCount() * 4 );
					c = 0;

					// skip the stuff above the exposed rectangle
					while ( child && y + child->height() <= 0 )
					{
						y += child->totalHeight();
						child = nextVisibleSibling(child);
					}

					int bx = r.width() / 2;

					// paint stuff in the magical area
					TQListView* v = item->listView();
					int lh = TQMAX( p->fontMetrics().height() + 2 * v->itemMargin(),
								   TQApplication::globalStrut().height() );
					if ( lh % 2 > 0 )
						lh++;

					// Draw all the expand/close boxes...
					TQRect boxrect;
					TQStyle::StyleFlags boxflags;
					while ( child && y < r.height() )
					{
						linebot = y + lh/2;
						if ( (child->isExpandable() || child->childCount()) &&
							 (child->height() > 0) )
						{
							// The primitive requires a rect.
							boxrect = TQRect( bx-4, linebot-4, 9, 9 );
							boxflags = child->isOpen() ? TQStyle::Style_Off : TQStyle::Style_On;

							// TQtCKStyle extension: Draw the box and expand/collapse indicator
							drawKStylePrimitive( KPE_ListViewExpander, p, ceData, elementFlags, boxrect, cg, boxflags, opt, NULL );

							// dotlinery
							p->setPen( cg.mid() );
							dotlines[c++] = TQPoint( bx, linetop );
							dotlines[c++] = TQPoint( bx, linebot - 5 );
							dotlines[c++] = TQPoint( bx + 5, linebot );
							dotlines[c++] = TQPoint( r.width(), linebot );
							linetop = linebot + 5;
						} else {
							// just dotlinery
							dotlines[c++] = TQPoint( bx+1, linebot );
							dotlines[c++] = TQPoint( r.width(), linebot );
						}

						y += child->totalHeight();
						child = nextVisibleSibling(child);
					}

					if ( child ) // there's a child to draw, so move linebot to edge of rectangle
						linebot = r.height();

					if ( linetop < linebot )
					{
						dotlines[c++] = TQPoint( bx, linetop );
						dotlines[c++] = TQPoint( bx, linebot );
					}
				}

				// Draw all the branches...
				static int thickness = kPixelMetric( KPM_ListViewBranchThickness, ceData, elementFlags );
				int line; // index into dotlines
				TQRect branchrect;
				TQStyle::StyleFlags branchflags;
				for( line = 0; line < c; line += 2 )
				{
					// assumptions here: lines are horizontal or vertical.
					// lines always start with the numerically lowest
					// coordinate.

					// point ... relevant coordinate of current point
					// end ..... same coordinate of the end of the current line
					// other ... the other coordinate of the current point/line
					if ( dotlines[line].y() == dotlines[line+1].y() )
					{
						// Horizontal branch
						int end = dotlines[line+1].x();
						int point = dotlines[line].x();
						int other = dotlines[line].y();

						branchrect  = TQRect( point, other-(thickness/2), end-point, thickness );
						branchflags = TQStyle::Style_Horizontal;

						// TQtCKStyle extension: Draw the horizontal branch
						drawKStylePrimitive( KPE_ListViewBranch, p, ceData, elementFlags, branchrect, cg, branchflags, opt, NULL );

					} else {
						// Vertical branch
						int end = dotlines[line+1].y();
						int point = dotlines[line].y();
						int other = dotlines[line].x();
						int pixmapoffset = ((point & 1) != dotoffset ) ? 1 : 0;

						branchrect  = TQRect( other-(thickness/2), point, thickness, end-point );
						if (!pixmapoffset)	// ### Hackish - used to hint the offset
							branchflags = TQStyle::Style_NoChange;
						else
							branchflags = TQStyle::Style_Default;

						// TQtCKStyle extension: Draw the vertical branch
						drawKStylePrimitive( KPE_ListViewBranch, p, ceData, elementFlags, branchrect, cg, branchflags, opt, NULL );
					}
				}
			}
			break;
		}

		default:
			TQCommonStyle::drawComplexControl( control, p, ceData, elementFlags, r, cg,
											  flags, controls, active, opt, widget );
			break;
	}
}


TQStyle::SubControl TQtCKStyle::querySubControl( ComplexControl control,
											TQStyleControlElementData ceData,
											ControlElementFlags elementFlags,
											const TQPoint &pos,
											const TQStyleOption &opt,
											const TQWidget* widget ) const
{
	TQStyle::SubControl ret = TQCommonStyle::querySubControl(control, ceData, elementFlags, pos, opt, widget);

	if (d->scrollbarType == ThreeButtonScrollBar) {
		// Enable third button
		if (control == CC_ScrollBar && ret == SC_None)
			ret = SC_ScrollBarSubLine;
	}
	return ret;
}


TQRect TQtCKStyle::querySubControlMetrics( ComplexControl control,
									  TQStyleControlElementData ceData,
									  ControlElementFlags elementFlags,
									  SubControl sc,
									  const TQStyleOption &opt,
									  const TQWidget* widget ) const
{
    TQRect ret;

	if (control == CC_ScrollBar)
	{
		bool threeButtonScrollBar = d->scrollbarType & ThreeButtonScrollBar;
		bool platinumScrollBar    = d->scrollbarType & PlatinumStyleScrollBar;
		bool nextScrollBar        = d->scrollbarType & NextStyleScrollBar;

		const TQScrollBar *sb = (const TQScrollBar*)widget;
		bool horizontal = sb->orientation() == Qt::Horizontal;
		int sliderstart = sb->sliderStart();
		int sbextent    = pixelMetric(PM_ScrollBarExtent, ceData, elementFlags, widget);
		int maxlen      = (horizontal ? sb->width() : sb->height())
						  - (sbextent * (threeButtonScrollBar ? 3 : 2));
		int sliderlen;

		// calculate slider length
		if (sb->maxValue() != sb->minValue())
		{
			uint range = sb->maxValue() - sb->minValue();
			sliderlen = (sb->pageStep() * maxlen) /	(range + sb->pageStep());

			int slidermin = pixelMetric( PM_ScrollBarSliderMin, ceData, elementFlags, widget );
			if ( sliderlen < slidermin || range > INT_MAX / 2 )
				sliderlen = slidermin;
			if ( sliderlen > maxlen )
				sliderlen = maxlen;
		} else
			sliderlen = maxlen;

		// Subcontrols
		switch (sc)
		{
			case SC_ScrollBarSubLine: {
				// top/left button
				if (platinumScrollBar) {
					if (horizontal)
						ret.setRect(sb->width() - 2 * sbextent, 0, sbextent, sbextent);
					else
						ret.setRect(0, sb->height() - 2 * sbextent, sbextent, sbextent);
				} else
					ret.setRect(0, 0, sbextent, sbextent);
				break;
			}

			case SC_ScrollBarAddLine: {
				// bottom/right button
				if (nextScrollBar) {
					if (horizontal)
						ret.setRect(sbextent, 0, sbextent, sbextent);
					else
						ret.setRect(0, sbextent, sbextent, sbextent);
				} else {
					if (horizontal)
						ret.setRect(sb->width() - sbextent, 0, sbextent, sbextent);
					else
						ret.setRect(0, sb->height() - sbextent, sbextent, sbextent);
				}
				break;
			}

			case SC_ScrollBarSubPage: {
				// between top/left button and slider
				if (platinumScrollBar) {
					if (horizontal)
						ret.setRect(0, 0, sliderstart, sbextent);
					else
						ret.setRect(0, 0, sbextent, sliderstart);
				} else if (nextScrollBar) {
					if (horizontal)
						ret.setRect(sbextent*2, 0, sliderstart-2*sbextent, sbextent);
					else
						ret.setRect(0, sbextent*2, sbextent, sliderstart-2*sbextent);
				} else {
					if (horizontal)
						ret.setRect(sbextent, 0, sliderstart - sbextent, sbextent);
					else
						ret.setRect(0, sbextent, sbextent, sliderstart - sbextent);
				}
				break;
			}

			case SC_ScrollBarAddPage: {
				// between bottom/right button and slider
				int fudge;

				if (platinumScrollBar)
					fudge = 0;
				else if (nextScrollBar)
					fudge = 2*sbextent;
				else
					fudge = sbextent;

				if (horizontal)
					ret.setRect(sliderstart + sliderlen, 0,
							maxlen - sliderstart - sliderlen + fudge, sbextent);
				else
					ret.setRect(0, sliderstart + sliderlen, sbextent,
							maxlen - sliderstart - sliderlen + fudge);
				break;
			}

			case SC_ScrollBarGroove: {
				int multi = threeButtonScrollBar ? 3 : 2;
				int fudge;

				if (platinumScrollBar)
					fudge = 0;
				else if (nextScrollBar)
					fudge = 2*sbextent;
				else
					fudge = sbextent;

				if (horizontal)
					ret.setRect(fudge, 0, sb->width() - sbextent * multi, sb->height());
				else
					ret.setRect(0, fudge, sb->width(), sb->height() - sbextent * multi);
				break;
			}

			case SC_ScrollBarSlider: {
				if (horizontal)
					ret.setRect(sliderstart, 0, sliderlen, sbextent);
				else
					ret.setRect(0, sliderstart, sbextent, sliderlen);
				break;
			}

			default:
				ret = TQCommonStyle::querySubControlMetrics(control, ceData, elementFlags, sc, opt, widget);
				break;
		}
	} else
		ret = TQCommonStyle::querySubControlMetrics(control, ceData, elementFlags, sc, opt, widget);

	return ret;
}

static const char * const kstyle_close_xpm[] = {
"12 12 2 1",
"# c #000000",
". c None",
"............",
"............",
"..##....##..",
"...##..##...",
"....####....",
".....##.....",
"....####....",
"...##..##...",
"..##....##..",
"............",
"............",
"............"};

static const char * const kstyle_maximize_xpm[]={
"12 12 2 1",
"# c #000000",
". c None",
"............",
"............",
".##########.",
".##########.",
".#........#.",
".#........#.",
".#........#.",
".#........#.",
".#........#.",
".#........#.",
".##########.",
"............"};


static const char * const kstyle_minimize_xpm[] = {
"12 12 2 1",
"# c #000000",
". c None",
"............",
"............",
"............",
"............",
"............",
"............",
"............",
"...######...",
"...######...",
"............",
"............",
"............"};

static const char * const kstyle_normalizeup_xpm[] = {
"12 12 2 1",
"# c #000000",
". c None",
"............",
"...#######..",
"...#######..",
"...#.....#..",
".#######.#..",
".#######.#..",
".#.....#.#..",
".#.....###..",
".#.....#....",
".#.....#....",
".#######....",
"............"};


static const char * const kstyle_shade_xpm[] = {
"12 12 2 1",
"# c #000000",
". c None",
"............",
"............",
"............",
"............",
"............",
".....#......",
"....###.....",
"...#####....",
"..#######...",
"............",
"............",
"............"};

static const char * const kstyle_unshade_xpm[] = {
"12 12 2 1",
"# c #000000",
". c None",
"............",
"............",
"............",
"............",
"..#######...",
"...#####....",
"....###.....",
".....#......",
"............",
"............",
"............",
"............"};

static const char * const dock_window_close_xpm[] = {
"8 8 2 1",
"# c #000000",
". c None",
"##....##",
".##..##.",
"..####..",
"...##...",
"..####..",
".##..##.",
"##....##",
"........"};

// Message box icons, from page 210 of the Windows style guide.

// Hand-drawn to resemble Microsoft's icons, but in the Mac/Netscape
// palette.  The "question mark" icon, which Microsoft recommends not
// using but a lot of people still use, is left out.

/* XPM */
static const char * const information_xpm[]={
"32 32 5 1",
". c None",
"c c #000000",
"* c #999999",
"a c #ffffff",
"b c #0000ff",
"...........********.............",
"........***aaaaaaaa***..........",
"......**aaaaaaaaaaaaaa**........",
".....*aaaaaaaaaaaaaaaaaa*.......",
"....*aaaaaaaabbbbaaaaaaaac......",
"...*aaaaaaaabbbbbbaaaaaaaac.....",
"..*aaaaaaaaabbbbbbaaaaaaaaac....",
".*aaaaaaaaaaabbbbaaaaaaaaaaac...",
".*aaaaaaaaaaaaaaaaaaaaaaaaaac*..",
"*aaaaaaaaaaaaaaaaaaaaaaaaaaaac*.",
"*aaaaaaaaaabbbbbbbaaaaaaaaaaac*.",
"*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
"*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
"*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
"*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
"*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
".*aaaaaaaaaaabbbbbaaaaaaaaaac***",
".*aaaaaaaaaaabbbbbaaaaaaaaaac***",
"..*aaaaaaaaaabbbbbaaaaaaaaac***.",
"...caaaaaaabbbbbbbbbaaaaaac****.",
"....caaaaaaaaaaaaaaaaaaaac****..",
".....caaaaaaaaaaaaaaaaaac****...",
"......ccaaaaaaaaaaaaaacc****....",
".......*cccaaaaaaaaccc*****.....",
"........***cccaaaac*******......",
"..........****caaac*****........",
".............*caaac**...........",
"...............caac**...........",
"................cac**...........",
".................cc**...........",
"..................***...........",
"...................**..........."};
/* XPM */
static const char* const warning_xpm[]={
"32 32 4 1",
". c None",
"a c #ffff00",
"* c #000000",
"b c #999999",
".............***................",
"............*aaa*...............",
"...........*aaaaa*b.............",
"...........*aaaaa*bb............",
"..........*aaaaaaa*bb...........",
"..........*aaaaaaa*bb...........",
".........*aaaaaaaaa*bb..........",
".........*aaaaaaaaa*bb..........",
"........*aaaaaaaaaaa*bb.........",
"........*aaaa***aaaa*bb.........",
".......*aaaa*****aaaa*bb........",
".......*aaaa*****aaaa*bb........",
"......*aaaaa*****aaaaa*bb.......",
"......*aaaaa*****aaaaa*bb.......",
".....*aaaaaa*****aaaaaa*bb......",
".....*aaaaaa*****aaaaaa*bb......",
"....*aaaaaaaa***aaaaaaaa*bb.....",
"....*aaaaaaaa***aaaaaaaa*bb.....",
"...*aaaaaaaaa***aaaaaaaaa*bb....",
"...*aaaaaaaaaa*aaaaaaaaaa*bb....",
"..*aaaaaaaaaaa*aaaaaaaaaaa*bb...",
"..*aaaaaaaaaaaaaaaaaaaaaaa*bb...",
".*aaaaaaaaaaaa**aaaaaaaaaaa*bb..",
".*aaaaaaaaaaa****aaaaaaaaaa*bb..",
"*aaaaaaaaaaaa****aaaaaaaaaaa*bb.",
"*aaaaaaaaaaaaa**aaaaaaaaaaaa*bb.",
"*aaaaaaaaaaaaaaaaaaaaaaaaaaa*bbb",
"*aaaaaaaaaaaaaaaaaaaaaaaaaaa*bbb",
".*aaaaaaaaaaaaaaaaaaaaaaaaa*bbbb",
"..*************************bbbbb",
"....bbbbbbbbbbbbbbbbbbbbbbbbbbb.",
".....bbbbbbbbbbbbbbbbbbbbbbbbb.."};
/* XPM */
static const char* const critical_xpm[]={
"32 32 4 1",
". c None",
"a c #999999",
"* c #ff0000",
"b c #ffffff",
"...........********.............",
".........************...........",
".......****************.........",
"......******************........",
".....********************a......",
"....**********************a.....",
"...************************a....",
"..*******b**********b*******a...",
"..******bbb********bbb******a...",
".******bbbbb******bbbbb******a..",
".*******bbbbb****bbbbb*******a..",
"*********bbbbb**bbbbb*********a.",
"**********bbbbbbbbbb**********a.",
"***********bbbbbbbb***********aa",
"************bbbbbb************aa",
"************bbbbbb************aa",
"***********bbbbbbbb***********aa",
"**********bbbbbbbbbb**********aa",
"*********bbbbb**bbbbb*********aa",
".*******bbbbb****bbbbb*******aa.",
".******bbbbb******bbbbb******aa.",
"..******bbb********bbb******aaa.",
"..*******b**********b*******aa..",
"...************************aaa..",
"....**********************aaa...",
"....a********************aaa....",
".....a******************aaa.....",
"......a****************aaa......",
".......aa************aaaa.......",
".........aa********aaaaa........",
"...........aaaaaaaaaaa..........",
".............aaaaaaa............"};

TQPixmap TQtCKStyle::stylePixmap( StylePixmap stylepixmap,
						  TQStyleControlElementData ceData,
						  ControlElementFlags elementFlags,
						  const TQStyleOption& opt,
						  const TQWidget* widget) const
{
	switch (stylepixmap) {
		case SP_TitleBarShadeButton:
			return TQPixmap(const_cast<const char**>(kstyle_shade_xpm));
		case SP_TitleBarUnshadeButton:
			return TQPixmap(const_cast<const char**>(kstyle_unshade_xpm));
		case SP_TitleBarNormalButton:
			return TQPixmap(const_cast<const char**>(kstyle_normalizeup_xpm));
		case SP_TitleBarMinButton:
			return TQPixmap(const_cast<const char**>(kstyle_minimize_xpm));
		case SP_TitleBarMaxButton:
			return TQPixmap(const_cast<const char**>(kstyle_maximize_xpm));
		case SP_TitleBarCloseButton:
			return TQPixmap(const_cast<const char**>(kstyle_close_xpm));
		case SP_DockWindowCloseButton:
			return TQPixmap(const_cast<const char**>(dock_window_close_xpm ));
		case SP_MessageBoxInformation:
			return TQPixmap(const_cast<const char**>(information_xpm));
		case SP_MessageBoxWarning:
			return TQPixmap(const_cast<const char**>(warning_xpm));
		case SP_MessageBoxCritical:
			return TQPixmap(const_cast<const char**>(critical_xpm));
		default:
			break;
    }
    return TQCommonStyle::stylePixmap(stylepixmap, ceData, elementFlags, opt, widget);
}


int TQtCKStyle::styleHint( StyleHint sh, TQStyleControlElementData ceData, ControlElementFlags elementFlags,
					   const TQStyleOption &opt, TQStyleHintReturn* shr, const TQWidget* w) const
{
	switch (sh)
	{
		case SH_EtchDisabledText:
			return d->etchDisabledText ? 1 : 0;

		case SH_PopupMenu_Scrollable:
			return d->scrollablePopupmenus ? 1 : 0;

		case SH_MenuBar_AltKeyNavigation:
			return d->menuAltKeyNavigation ? 1 : 0;

		case SH_PopupMenu_SubMenuPopupDelay:
			if ( styleHint( SH_PopupMenu_SloppySubMenus, ceData, elementFlags, TQStyleOption::Default, 0, w ) )
				return TQMIN( 100, d->popupMenuDelay );
			else
				return d->popupMenuDelay;

		case SH_PopupMenu_SloppySubMenus:
			return d->sloppySubMenus;

		case SH_ItemView_ChangeHighlightOnFocus:
		case SH_Slider_SloppyKeyEvents:
		case SH_MainWindow_SpaceBelowMenuBar:
		case SH_PopupMenu_AllowActiveAndDisabled:
			return 0;

		case SH_Slider_SnapToValue:
		case SH_PrintDialog_RightAlignButtons:
		case SH_FontDialog_SelectAssociatedText:
		case SH_MenuBar_MouseTracking:
		case SH_PopupMenu_MouseTracking:
		case SH_ComboBox_ListMouseTracking:
		case SH_ScrollBar_MiddleClickAbsolutePosition:
			return 1;
		case SH_LineEdit_PasswordCharacter:
		{
			if (w) {
				const TQFontMetrics &fm = w->fontMetrics();
				if (fm.inFont(TQChar(0x25CF))) {
					return 0x25CF;
				} else if (fm.inFont(TQChar(0x2022))) {
					return 0x2022;
				}
			}
			return '*';
		}

		default:
			return TQCommonStyle::styleHint(sh, ceData, elementFlags, opt, shr, w);
	}
}

bool TQtCKStyle::objectEventHandler( TQStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, TQEvent *event )
{
	if (ceData.widgetObjectTypes.contains(TQOBJECT_OBJECT_NAME_STRING)) {
		TQObject* object = reinterpret_cast<TQObject*>(source);

		if ( d->useFilledFrameWorkaround )
		{
			// Make the TQMenuBar/TQToolBar paintEvent() cover a larger area to
			// ensure that the filled frame contents are properly painted.
			// We essentially modify the paintEvent's rect to include the
			// panel border, which also paints the widget's interior.
			// This is nasty, but I see no other way to properly repaint
			// filled frames in all TQMenuBars and TQToolBars.
			// -- Karol.
			TQFrame *frame = 0;
			if ( event->type() == TQEvent::Paint
					&& (frame = ::tqqt_cast<TQFrame*>(object)) )
			{
				if (frame->frameShape() != TQFrame::ToolBarPanel && frame->frameShape() != TQFrame::MenuBarPanel)
					return false;
					
				bool horizontal = true;
				TQPaintEvent* pe = (TQPaintEvent*)event;
				TQToolBar *toolbar = ::tqqt_cast< TQToolBar *>( frame );
				TQRect r = pe->rect();
	
				if (toolbar && toolbar->orientation() == Qt::Vertical)
					horizontal = false;
	
				if (horizontal) {
					if ( r.height() == frame->height() )
						return false;	// Let TQFrame handle the painting now.
	
					// Else, send a new paint event with an updated paint rect.
					TQPaintEvent dummyPE( TQRect( r.x(), 0, r.width(), frame->height()) );
					TQApplication::sendEvent( frame, &dummyPE );
				}
				else {	// Vertical
					if ( r.width() == frame->width() )
						return false;
	
					TQPaintEvent dummyPE( TQRect( 0, r.y(), frame->width(), r.height()) );
					TQApplication::sendEvent( frame, &dummyPE );
				}
	
				// Discard this event as we sent a new paintEvent.
				return true;
			}
		}
	}

	return false;
}

void TQtCKStyle::virtual_hook( int, void* )
{ /*BASE::virtual_hook( id, data );*/ }

// vim: set noet ts=4 sw=4:
// kate: indent-width 4; replace-tabs off; tab-width 4; space-indent off;

#include "qtc_kstyle.moc"