summaryrefslogtreecommitdiffstats
path: root/styles/dotnet/dotnet.cpp
blob: 6eeb7c4144789bf8a89e6c434542bfa3b6c747ba (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
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
/*
 *	KDE3 dotNET Style (version 1.5)
 *	Copyright (C) 2001-2002, Chris Lee <clee@kde.org>
 *	                         Carsten Pfeiffer <pfeiffer@kde.org>
 *                           Karol Szwed <gallium@kde.org>
 *
 *	Drawing routines completely reimplemented from KDE3 HighColor, which was
 *	originally based on some stuff from the KDE2 HighColor.
 *	Includes portions of framework code from KDE3 HighColor,
 *          (C) 2001-2002 Karol Szwed <gallium@kde.org>,
 *          (C) 2001-2002 Fredrik H�lund  <fredrik@kde.org>
 *
 *	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 <qstyleplugin.h>
#include <qstylefactory.h>
#include <qpointarray.h>
#include <qpainter.h>
#include <qtabbar.h>
#include <qtabwidget.h>
#include <qprogressbar.h>
#include <qcombobox.h>
#include <qlistbox.h>
#include <qscrollbar.h>
#include <qpushbutton.h>
#include <qtoolbutton.h>
#include <qtoolbar.h>
#include <qmenubar.h>
#include <qpopupmenu.h>
#include <qdrawutil.h>
#include <qapplication.h>
#include <qvariant.h>
#include <qpixmapcache.h>
#include <qslider.h>
#include <qsettings.h>
#include <kpixmap.h>

#include "dotnet.h"
#include "dotnet.moc"

/*	This code registers the style with QStyleFactory, which makes it possible
 *	for any code that uses QStyle to find out about it. */
// -- Style Plugin Interface -------------------------
class dotNETstylePlugin : public QStylePlugin
{
	public:
		dotNETstylePlugin() {}
		~dotNETstylePlugin() {}

		QStringList keys() const {
			return QStringList() << "dotNET";
		}

		QStyle* create( const QString& key ) {
			if (key == "dotnet")
				return new dotNETstyle;
			return 0;
		}
};

KDE_Q_EXPORT_PLUGIN( dotNETstylePlugin )

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

dotNETstyle::dotNETstyle() : KStyle( AllowMenuTransparency ), kickerMode(false)
{
	winstyle = 0L;
	winstyle = QStyleFactory::create("Windows");
	if (winstyle == 0L) {
	//	We don't have the Windows style, neither builtin nor as a plugin.
	//	Use any style rather than crashing.
		winstyle = QStyleFactory::create("B3");
	}

	if (qApp->inherits("KApplication")) {
		connect( qApp, SIGNAL( kdisplayPaletteChanged() ), SLOT( paletteChanged() ));
	}

	QSettings settings;
	pseudo3D = settings.readBoolEntry("/KStyle/Settings/Pseudo3D", true);
	roundedCorners = settings.readBoolEntry("/KStyle/Settings/RoundedCorners", true);
	useTextShadows = settings.readBoolEntry("/KStyle/Settings/UseTextShadows", false);
	reverseLayout = QApplication::QApplication::reverseLayout();
}


dotNETstyle::~dotNETstyle()
{
}

bool dotNETstyle::inheritsKHTML(const QWidget* w) const
{
	if (w->parentWidget(true) && w->parentWidget(true)->parentWidget(true) && w->parentWidget(true)->parentWidget(true)->parentWidget(true) &&  w->parentWidget(true)->parentWidget(true)->parentWidget(true)->inherits("KHTMLView")) {
		return true;
	} else {
		return false;
	}
}

void dotNETstyle::polish(QWidget* widget)
{
	if (!qstrcmp(qApp->argv()[0], "kicker") || widget->inherits("Kicker"))
		kickerMode = true;

	if (widget->isTopLevel())
		return;

// we can't simply set a palette -- upon color-theme changes, we have
// to update the palette again.
	bool extraPalette = false;

	if (widget->inherits("QComboBox") && !inheritsKHTML(widget)) {
		widget->installEventFilter (this);
		updatePalette( (QComboBox*) widget );
		extraPalette = true;
	} else {
		winstyle->polish(widget);
	}

//	This code is disabled until Carsten explains to me why it's supposed to
//	be here. It breaks dynamically changing the color from KControl and does
//	other bad things (see bug #54569)
/*
	if (!widget->ownPalette()) {
		if (widget->inherits("QToolBar")) {
			updatePalette( (QToolBar*) widget );
			extraPalette = true;
		} else if (widget->inherits("QMenuBar")) {
			updatePalette( (QMenuBar*) widget );
			extraPalette = true;
		}
	}
*/
}

void dotNETstyle::unPolish(QWidget* widget)
{
	winstyle->unPolish(widget);

	if (widget->inherits("QComboBox") && !inheritsKHTML(widget)) {
		widget->removeEventFilter (this);
	}
}

void dotNETstyle::renderMenuBlendPixmap(KPixmap &pix,
                                        const QColorGroup &cg,
                                        const QPopupMenu *popup) const
{
	QPainter p( &pix );
	if (QApplication::reverseLayout()) {
		p.fillRect( popup->frameRect().width()-22, 0, 22, pix.height(), cg.mid() );
		p.fillRect( 0, 0, popup->frameRect().width()-22, pix.height(), cg.background().light() );
	} else {
		p.fillRect( 0, 0, pix.width(), pix.height(), cg.background().light() );
		p.fillRect( popup->frameRect().left() + 1, 0, 22, pix.height(), cg.mid() );
	}
}

/*	This is the code that renders 90+% of the buttons in dotNET.
 *	Changing the code here will most likely affect EVERYTHING.
 *	If you want to modify the style, this is a good place to start.
 *	Also, take a look at the sizeMetric function and play with the
 *	widths that things return for different Frame elements.
 */
void dotNETstyle::renderButton(QPainter *p,
                               const QRect &r,
                               const QColorGroup &g,
                               bool sunken,
                               bool corners) const
{
	if (sunken) {
		p->setPen(g.highlight().dark());
		p->setBrush(g.highlight());
		p->drawRect(r);
	} else {
		int x, y, w, h;
		r.rect(&x, &y, &w, &h);

		if (pseudo3D) {
			if (roundedCorners) {
				const QCOORD iCorners[] = { x, y + h - 2, x, y + 1, x + 1, y, x + w - 2, y, x + w - 1, y + 1, x + w - 1, y + h - 2, x + w - 2, y + h - 1, x + 1, y + h - 1 };
				p->fillRect(x+1, y+1, w-2, h-2, g.button());
				p->setPen(g.button().dark());
				p->drawLineSegments(QPointArray(8, iCorners));
				if (corners) {
					const QCOORD cPixels[] = { x, y, x + w - 1, y, x + w - 1, y + h - 1, x, y + h - 1 };
					p->setPen(g.button());
					p->drawPoints(QPointArray(4, cPixels));
				}
			} else {
				p->setPen(g.button().dark());
				p->setBrush(g.button());
				p->drawRect(r);
			}

			const QCOORD oCorners[] = { x + 1, y + h - 2, x + 1, y + 1, x + w - 2, y + 1, x + w - 2, y + h - 2 };
			const QPointArray outline(4, oCorners);
			p->setPen(g.button().dark(115));
			p->setBrush(QBrush::NoBrush);
			p->drawConvexPolygon(outline);
			p->setPen(g.button().light());
			p->drawPolyline(outline, 0, 3);
		} else {
			p->setPen(g.button().dark());
			p->setBrush(g.button());
			p->drawRect(r);
			p->setPen(g.button().light());
			p->drawLine(x, y + h - 1, x, y);
			p->drawLine(x, y, x + w - 1, y);
		}
	}
}

/*	This is the code that renders the slider handles on scrollbars. It draws
 *	them just like normal buttons, by calling renderButton, but it also adds
 *	very subtle grips to the slider handle.
 */
void dotNETstyle::renderSlider(QPainter *p,
                               const QRect &r,
                               const QColorGroup &g) const
{
	int x, y, w, h;
	int offset = 6;
	int llx, lly, urx, ury;

	r.rect(&x,&y,&w,&h);

	llx = (x + (w/2) - 4);
	lly = (y + (h/2) + 3);
	urx = (x + (w/2) + 2);
	ury = (y + (h/2) - 3);

	renderButton(p, r, g, false, true);

	p->save();

	if (h > 15 && w > 15) {
		p->setPen(g.background().dark(120));
		p->drawLine(llx, lly, urx, ury);
		if (h > 35) {
			p->translate(0, offset);
			p->drawLine(llx, lly, urx, ury);
			p->translate(0, -(offset * 2));
			p->drawLine(llx, lly, urx, ury);
			p->translate(0, offset);
		}

		if (w > 35) {
			p->translate(offset, 0);
			p->drawLine(llx, lly, urx, ury);
			p->translate(-(offset * 2), 0);
			p->drawLine(llx, lly, urx, ury);
			p->translate(offset, 0);
		}

		p->setPen(g.background().light());
		p->translate(0, 1);
		p->drawLine(llx, lly, urx, ury);
		if (h > 35) {
			p->translate(0, offset);
			p->drawLine(llx, lly, urx, ury);
			p->translate(0, -(offset * 2));
			p->drawLine(llx, lly, urx, ury);
			p->translate(0, offset);
		}

		if (w > 35) {
			p->translate(offset, 0);
			p->drawLine(llx, lly, urx, ury);
			p->translate(-(offset * 2), 0);
			p->drawLine(llx, lly, urx, ury);
			p->translate(offset, 0);
		}
	}

	p->restore();
}

/*	This function does the rendering for most of the panels in dotNET.
 *	The QCOORD stuff is used to provide the slightly-rounded corners.
 *	Changing this function will have pretty widespread effects. Also a good
 *	place to start if you're looking to make your own style.
 */
void dotNETstyle::renderPanel(QPainter *p,
                              const QRect &r,
                              const QColorGroup &g,
                              bool sunken,
                              bool thick) const
{
	int x, x2, y, y2, w, h;
	r.rect(&x,&y,&w,&h);
	r.coords(&x, &y, &x2, &y2);

	p->save();

	if (pseudo3D) {
		const QCOORD oCorners[] = { x, y2, x, y, x2, y, x2, y2 };
		const QCOORD iCorners[] = { x+1, y2-1, x+1, y+1, x2-1, y+1, x2-1, y2-1 };
		p->setPen(g.background().dark());
		p->drawConvexPolygon(QPointArray(4, oCorners));

		if (thick) {
			p->setPen(g.background().dark(115));
			p->drawConvexPolygon(QPointArray(4, iCorners));
			p->setPen(g.background().light());

			if (sunken) {
				p->drawLine(w-2, h-2, x+1, h-2);
				p->drawLine(w-2, h-2, w-2, y+1);
			} else {
				p->drawLine(x+1, y+1, x+1, h-2);
				p->drawLine(x+1, y+1, w-2, y+1);
			}
		}

		if (roundedCorners) {
			p->setPen(g.background());
			p->drawPoints(QPointArray(4, oCorners));
		}
	} else {
		if (sunken) {
			const QCOORD corners[] = { x2, y, x2, y2, x, y2, x, y };
			p->setPen(g.background().dark());
			p->drawConvexPolygon(QPointArray(4, corners));
			p->setPen(g.background().light());
			p->drawPolyline(QPointArray(4, corners), 0, 3);
		} else {
			const QCOORD corners[] = { x, y2, x, y, x2, y, x2, y2 };
			p->setPen(g.background().dark());
			p->drawPolygon(QPointArray(4, corners));
			p->setPen(g.background().light());
			p->drawPolyline(QPointArray(4, corners), 0, 3);
		}
	}

	if (kickerMode) {
	//	Stolen wholesale from Keramik. I don't like it, but oh well.
		if (!thick) {
			if (sunken) {
				const QCOORD corners[] = { x2, y, x2, y2, x, y2, x, y };
				p->setPen(g.background().dark());
				p->drawConvexPolygon(QPointArray(4, corners));
				p->setPen(g.background().light());
				p->drawPolyline(QPointArray(4, corners), 0, 3);
			} else {
				const QCOORD corners[] = { x, y2, x, y, x2, y, x2, y2 };
				p->setPen(g.background().dark());
				p->drawPolygon(QPointArray(4, corners));
				p->setPen(g.background().light());
				p->drawPolyline(QPointArray(4, corners), 0, 3);
			}
		}
	}

	p->restore();
}


void dotNETstyle::drawKStylePrimitive(KStylePrimitive kpe,
                                      QPainter *p,
                                      const QWidget* widget,
                                      const QRect &r,
                                      const QColorGroup &cg,
                                      SFlags flags,
                                      const QStyleOption& opt) const
{
//  SLIDER
//  ------
	switch( kpe ) {
		case KPE_SliderGroove: {
			const QSlider* slider = (const QSlider*)widget;
			int x, y, w, h;
			r.rect(&x, &y, &w, &h);
			bool horizontal = slider->orientation() == Horizontal;
			int gcenter = (horizontal ? h : w) / 2;

			if (horizontal) {
				gcenter += y;
				p->setPen (cg.background().dark());
				p->drawLine(x, gcenter, x+w, gcenter);
				gcenter++;
				p->setPen (cg.background().light());
				p->drawLine(x, gcenter, x + w, gcenter);
			} else {
				gcenter += x;
				p->setPen (cg.background().dark());
				p->drawLine(gcenter, y, gcenter, y + h);
				gcenter++;
				p->setPen (cg.background().light());
				p->drawLine(gcenter, y, gcenter, y + h);
			}
			break;
		}

		case KPE_SliderHandle: {
			renderButton(p, r, cg);
			break;
		}

		default:
			KStyle::drawKStylePrimitive(kpe, p, widget, r, cg, flags, opt);
	}
}


// This function draws primitive elements as well as their masks.
void dotNETstyle::drawPrimitive(PrimitiveElement pe,
                                QPainter *p,
                                const QRect &r,
                                const QColorGroup &cg,
                                SFlags flags,
                                const QStyleOption &opt ) const
{
	bool down   = flags & Style_Down;
	bool on     = flags & Style_On;
	bool sunken = flags & Style_Sunken;
	bool horiz  = flags & Style_Horizontal;

	int x, x2, y, y2, w, h;
	r.rect(&x, &y, &w, &h);
	r.coords(&x, &y, &x2, &y2);

	switch(pe) {
	//	BUTTONS
	//	-------
		case PE_ButtonBevel:
		case PE_ButtonTool:
		case PE_ButtonDropDown:
		case PE_HeaderSection:
		case PE_ButtonCommand: {

			if (on || down) {
				renderButton(p, r, cg, true);
				p->setPen( cg.highlightedText() );
			} else {
				renderButton(p, r, cg, false, true);
			}

			break;
		}

		case PE_ButtonDefault: {
			QRect sr = r;
			p->setPen(QPen::NoPen);
			p->setBrush(cg.background().dark(105));
			p->drawRoundRect(sr, 25, 25);
			p->setBrush(cg.background().dark(110));
			sr.setCoords(sr.x() + 1, sr.y() + 1, sr.width() - 2, sr.height() - 2);
			p->drawRoundRect(sr, 25, 25);
			p->setBrush(cg.background().dark(115));
			sr.setCoords(sr.x() + 1, sr.y() + 1, sr.width() - 2, sr.height() - 2);
			p->drawRoundRect(sr, 25, 25);
			break;
		}

		case PE_ScrollBarSlider: {
			renderSlider(p, r, cg);
			break;
		}

		case PE_ScrollBarAddPage:
		case PE_ScrollBarSubPage: {
			// draw double buffered to avoid flicker...
			QPixmap buffer(2,2);
			QRect br(buffer.rect() );
			QPainter bp(&buffer);

			if (on || down) {
				bp.fillRect(br, QBrush(cg.mid().dark()));
			} else {
				bp.fillRect(br, QBrush(cg.background()));
			}
			bp.fillRect(br, QBrush(cg.background().light(), Dense4Pattern));

			bp.end();
			p->drawTiledPixmap(r, buffer);

			break;
		}

	//	SCROLLBAR BUTTONS
	//	-----------------
		case PE_ScrollBarSubLine: {
			drawPrimitive(PE_ButtonBevel, p, r, cg, flags);
			p->setPen(down ? cg.highlightedText() : cg.foreground());
			drawPrimitive((horiz ? PE_ArrowLeft : PE_ArrowUp), p, r, cg, flags);
			break;
		}

		case PE_ScrollBarAddLine: {
			drawPrimitive(PE_ButtonBevel, p, r, cg, flags);
			p->setPen(down ? cg.highlightedText() : cg.foreground());
			drawPrimitive((horiz ? PE_ArrowRight : PE_ArrowDown), p, r, cg, flags);
			break;
		}

	//	CHECKBOXES
	//	----------
		case PE_Indicator: {
			p->setPen(cg.background().dark());
			p->setBrush(flags & Style_Enabled ? cg.light() : cg.background());
			p->drawRect(r);
			p->setPen(cg.background().dark(115));
			p->drawLine(x + 1, y + 1, w - 2, y + 1);
			p->drawLine(x + 1, y + 1, x + 1, h - 2);

			if (pseudo3D && roundedCorners) {
				const QCOORD corners[] = { x, y, x, y2, x2, y, x2, y2 };
				p->setPen(cg.background());
				p->drawPoints(QPointArray(4, corners));
			}

			break;
		}

		case PE_IndicatorMask: {
			p->fillRect (r, color1);

			if (roundedCorners) {
				p->setPen (color0);
				p->drawPoint(r.topLeft());
				p->drawPoint(r.topRight());
				p->drawPoint(r.bottomLeft());
				p->drawPoint(r.bottomRight());
			}
			break;
		}

	//	RADIOBUTTONS
	//	------------
		case PE_ExclusiveIndicator: {
			const QCOORD outline[] = { 0, 7, 0, 5, 1, 4, 1, 3, 2, 2, 3, 1, 4, 1, 5, 0, 7, 0, 8, 1, 9, 1, 10, 2, 11, 3, 11, 4, 12, 5, 12, 7, 11, 8, 11, 9, 10, 10, 9, 11, 8, 11, 7, 12, 5, 12, 4, 11, 3, 11, 2, 10, 1, 9, 1, 8 };
			const QCOORD indark[] = { 1, 7, 1, 6, 1, 5, 2, 4, 2, 3, 3, 2, 4, 2, 5, 1, 6, 1, 7, 1 };

			p->fillRect(r, cg.background());
			p->setPen(cg.background().dark());
			p->setBrush(flags & Style_Enabled ? cg.light() : cg.background());
			p->drawPolygon(QPointArray(28, outline));
			p->setPen(cg.background().dark(115));
			p->drawPoints(QPointArray(10, indark));
			break;
		}

		case PE_ExclusiveIndicatorMask: {
			const QCOORD outline[] = { 0, 7, 0, 5, 1, 4, 1, 3, 2, 2, 3, 1, 4, 1, 5, 0, 7, 0, 8, 1, 9, 1, 10, 2, 11, 3, 11, 4, 12, 5, 12, 7, 11, 8, 11, 9, 10, 10, 9, 11, 8, 11, 7, 12, 5, 12, 4, 11, 3, 11, 2, 10, 1, 9, 1, 8 };
			p->fillRect(r, color0);
			p->setPen(color1);
			p->setBrush(color1);
			p->translate(r.x(), r.y());
			p->drawPolygon(QPointArray(28, outline));
			p->translate(-r.x(), -r.y());
			break;
		}

	//	GENERAL PANELS
	//	--------------
		case PE_Splitter: {
			int k;
			p->fillRect(r, cg.background());
			p->setBrush(cg.background().dark());

			if (horiz) {
				for (k = r.center().y() - 9; k < r.center().y() + 9; k += 3) {
					p->drawLine(x + 2, k, w - 2, k);
				}
			} else {
				for (k = r.center().x() - 9; k < r.center().x() + 9; k += 3) {
					p->drawLine(k, y + 2, k, h - 2);
				}
			}

			break;
		}

		case PE_PanelGroupBox:
		case PE_GroupBoxFrame: {
			p->setPen(cg.background().dark());
			p->setBrush(cg.background());
			p->drawRect(r);

			if (pseudo3D && roundedCorners) {
				const QCOORD corners[] = { x, y, x, y2, x2, y, x2, y2 };
				p->setPen(cg.background());
				p->drawPoints(QPointArray(4, corners));
			}
			break;
		}

		case PE_WindowFrame:
		case PE_Panel: {
			renderPanel(p, r, cg, sunken, false);
			break;
		}

		case PE_PanelLineEdit: {
			renderPanel(p, r, cg, true, true);
			break;
		}

		case PE_StatusBarSection: {
			renderPanel(p, r, cg, true, false);
			break;
		}

		case PE_TabBarBase:	// Still not sure what this one does
		case PE_PanelTabWidget: {
			renderPanel(p, r, cg, sunken);
			break;
		}

		case PE_PanelPopup: {
			p->setPen(cg.shadow());
			p->drawRect(r);
			break;
		}

	//	MENU / TOOLBAR PANEL
	//	--------------------
		case PE_PanelMenuBar: 			// Menu
		case PE_PanelDockWindow: {		// Toolbar
			p->setPen(cg.button());
			p->drawRect(r);
			break;
		}

	//	TOOLBAR/DOCK WINDOW HANDLE
	//	--------------------------
		case PE_DockWindowResizeHandle: {
			renderButton(p, r, cg);
			break;
		}

		case PE_DockWindowHandle: {
			int k;

			p->fillRect(r, cg.button());
			p->setPen(cg.button().dark());

			if (horiz) {
				for (k = r.center().y() - 9; k < r.center().y() + 9; k += 3) {
					p->drawLine(x + 2, k, w - 2, k);
				}
			} else {
				for (k = r.center().x() - 9; k < r.center().x() + 9; k += 3) {
					p->drawLine(k, y + 2, k, h - 2);
				}
			}

			break;
		}

	//	TOOLBAR SEPARATOR
	//	-----------------
		case PE_DockWindowSeparator: {
			break;
		}

		case PE_CheckMark: {
			int x = r.center().x() - 3, y = r.center().y() - 3;
			const QCOORD check[] = { x, y + 2, x, y + 4, x + 2, y + 6, x + 6, y + 2, x + 6, y, x + 2, y + 4 };
			const QPointArray a(6, check);

			p->setPen(flags & Style_Down ? cg.highlight() : p->pen());
			p->setBrush(flags & Style_Down ? cg.highlight() : p->pen().color());
			p->drawPolygon(a);

			break;
		}

		case PE_SpinWidgetUp:
		case PE_SpinWidgetDown:
		case PE_HeaderArrow:
		case PE_ArrowUp:
		case PE_ArrowDown:
		case PE_ArrowLeft:
		case PE_ArrowRight: {
			QPointArray a;

			switch (pe) {
				case PE_SpinWidgetUp:
				case PE_ArrowUp: {
					a.setPoints(7, u_arrow);
					break;
				}
				case PE_SpinWidgetDown:
				case PE_ArrowDown: {
					a.setPoints(7, d_arrow);
					break;
				}
				case PE_ArrowLeft: {
					a.setPoints(7, l_arrow);
					break;
				}
				case PE_ArrowRight: {
					a.setPoints(7, r_arrow);
					break;
				}
				default: {
					if (flags & Style_Up) {
						a.setPoints(7, u_arrow);
					} else {
						a.setPoints(7, d_arrow);
					}
				}
			}

			p->save();

			if (flags & Style_Down) {
				p->translate(pixelMetric(PM_ButtonShiftHorizontal),
				             pixelMetric(PM_ButtonShiftVertical));
			}

			if (flags & Style_Enabled) {
				a.translate((r.x() + r.width()/2), (r.y() + r.height()/2));
				if (p->pen() == QPen::NoPen) {
					p->setPen(cg.buttonText());
				}
				p->drawLineSegments(a, 0, 3);
				p->drawPoint(a[6]);
			} else {
				a.translate((r.x() + r.width()/2)+1, (r.y() + r.height()/2)+1);
				if (p->pen() == QPen::NoPen) {
					p->setPen(cg.highlightedText());
				}
				p->drawLineSegments(a, 0, 3);
				p->drawPoint(a[6]);

				a.translate(-1,-1);
				if (p->pen() == QPen::NoPen) {
					p->setPen(cg.mid());
				}
				p->drawLineSegments(a, 0, 3);
				p->drawPoint(a[6]);
			}

			p->restore();
			break;
		}

		default: {
			return KStyle::drawPrimitive(pe, p, r, cg, flags, opt);
		}
	}
}


void dotNETstyle::drawControl(ControlElement element,
                              QPainter *p,
                              const QWidget *widget,
                              const QRect &r,
                              const QColorGroup &cg,
                              SFlags flags,
                              const QStyleOption& opt) const
{
	switch (element) {
	//	CHECKBOXES
	//	----------
		case CE_CheckBox: {
			drawPrimitive(PE_Indicator, p, r, cg, flags);
			if (flags & Style_On || flags & Style_Down) {
				p->setPen(cg.foreground());
				drawPrimitive(PE_CheckMark, p, r, cg, flags);
			}
			break;
		}

	//	PROGRESSBAR
	//	-----------
		case CE_ProgressBarGroove: {
			renderPanel(p, r, cg, true, false);
			break;
		}

		case CE_ProgressBarContents: {
			const QProgressBar *pb = (const QProgressBar *)widget;

			if (pb->totalSteps()) {
				int x, y, w, h;
				double percent = (double)pb->progress() / (double)pb->totalSteps();

				r.rect(&x, &y, &w, &h);

				p->fillRect(x + 1, y + 1, w - 2, h - 2, cg.background().light());

				if (QApplication::reverseLayout()) {
					x += w - ((int)(w * percent));
					y += 1; h -= 2;
					w = ((int)(w * percent)) - 2;
				} else {
					x += 1; y += 1; h -= 2;
					w = (int)(w * percent) - 2;
				}

				p->fillRect(x, y, w, h, cg.highlight());

				if (pb->progress() < pb->totalSteps()) {
					p->setPen(cg.background().dark(115));
					if (QApplication::reverseLayout()) {
						p->drawLine(x - 1, y, x - 1, h);
					} else {
						p->drawLine(x + w, y, x + w, h);
					}
				}

				if (pseudo3D) {
					QPointArray corners;
					if (QApplication::reverseLayout()) {
						const QCOORD c[] = { x, h, x, y, x + w, y, x + w, h };
						corners = QPointArray(4, c);
					} else {
						const QCOORD c[] = { x, h, x, y, w, y, w, h };
						corners = QPointArray(4, c);
					}
					p->setPen(cg.highlight().dark(120));
					p->drawConvexPolygon(corners);
					p->setPen(cg.highlight().light(120));
					p->drawPolyline(corners, 0, 3);
					if (roundedCorners) {
						p->setPen(cg.background().dark());
						p->drawPoints(corners);
					}
				}
			}
			break;
		}

	//	RADIOBUTTONS
	//	------------
		case CE_RadioButton: {
			drawPrimitive(PE_ExclusiveIndicator, p, r, cg, flags);

			if (flags & Style_On || flags & Style_Down) {
				QCOORD center[] = { 4, 5, 4, 7, 5, 8, 7, 8, 8, 7, 8, 5, 7, 4, 5, 4 };
				QPointArray c(8, center);
				p->setPen(flags & Style_Down ? cg.highlight() : cg.text());
				p->setBrush(flags & Style_Down ? cg.highlight() : cg.text());
				p->drawPolygon(c);
			}
			break;
		}

	//	TABS
	//	----
		case CE_TabBarTab: {
			const QTabBar *tb = (const QTabBar *) widget;
			bool cornerWidget = false;
			QTabBar::Shape tbs = tb->shape();
			bool selected = flags & Style_Selected;
			int x, x2, y, y2, w, h;
			r.rect(&x, &y, &w, &h);
			r.coords(&x, &y, &x2, &y2);

			if (tb->parent()->inherits("QTabWidget")) {
				const QTabWidget *tw = (const QTabWidget *)tb->parent();
				QWidget *cw = tw->cornerWidget(Qt::TopLeft);
				if (cw) {
					cornerWidget = true;
				}
			}

			switch (tbs) {
				case QTabBar::RoundedAbove: {
					y2 -= 1;
					if (pseudo3D) {
						p->setPen(cg.background().dark());
						if (selected) {
							const QCOORD oCorners[] = { x, y2, x, y, x2, y, x2, y2 };
							p->drawPolyline(QPointArray(4, oCorners));

							if (roundedCorners) {
								p->setPen(cg.background());
								p->drawPoints(QPointArray(4, oCorners), 1, 2);
							}

							p->setPen(cg.background().dark(115));
						/*	Right inner border */
							p->drawLine(x + w - 2, y + 1, x + w - 2, y + h - 2);
							p->setPen(cg.background().light());
						/* Top inner border */
							p->drawLine(x + 1, y + 1, x + w - 2, y + 1);
						/* Left inner border */
							p->drawLine(x + 1, y + 1, x + 1, y + h - 1);
						} else {
							QRect r2(x+1, y+3, w-2, h-5);
							p->fillRect(r2, cg.mid().light(105));

							const QCOORD oCorners[] = { x, y2, x, y + 2, x2, y + 2, x2, y2 };
							p->drawPolyline(QPointArray(4, oCorners));

							p->setPen(cg.background());

						/*	hack where the rounded corners sometimes go away */
							if (roundedCorners) {
								p->drawPoint(x + w - 1, y + 2);
							}

							p->setPen(cg.background().light());
						/* Top of underlying tabbar-widget */
							p->drawLine(x, y + h - 1, x + w - 1, y + h - 1);
							p->setPen(cg.background().dark());
						/*	Top of underlying tabbar-widget */
							p->drawLine(x, y + h - 2, x + w - 1, y + h - 2);
						/*	Outer right border */
							p->drawLine(x + w - 1, y + 3, x + w - 1, y + h - 2);
    					}

						if (opt.tab()->identifier() == 0 && !cornerWidget) {
							p->setPen(cg.background().dark());
							p->drawPoint(x, y + h - 1);
						}
					} else {
						p->setPen(cg.background().dark());
						if (selected) {
							p->drawLine(x + w - 1, y, x + w - 1, y + h - 2);
							p->setPen(cg.background().light());
							p->drawLine(x, y, x + w - 1, y);
							p->drawLine(x, y, x, y + h - 1);
							p->setPen(cg.background().dark(115));
							p->drawLine(x + w - 2, y + 1, x + w - 2, y + h - 3);
						} else {
							QRect r2(x + 1, y + 3, w - 2, h - 4);
							p->fillRect(r2, cg.mid());

							p->setPen(cg.background().light());
							p->drawLine(x, y + 2, x + w - 1, y + 2);
							p->drawLine(x, y + 2, x, y + h - 1);
							p->drawLine(x, y + h - 1, x + w - 1, y + h - 1);

							p->setPen(cg.mid().dark(115));
							p->drawLine(x + w - 2, y + 3, x + w - 2, y + h - 3);
						}
					}

					break;
				}

				case QTabBar::RoundedBelow: {
					if (pseudo3D) {
						p->setPen(cg.background().dark());
						if (selected) {
							const QCOORD oCorners[] = { x, y + 1, x, y2, x2, y2, x2, y + 1 };
							p->drawPolyline(QPointArray(4, oCorners));

							p->setPen(cg.background().dark(115));
							p->drawLine(x + 1, y + h - 2, x + w - 2, y + h - 2);
						/*	Right inner border */
							p->drawLine(x + w - 2, y + 1, x + w - 2, y + h - 2);
							p->setPen(cg.background().light());
						/* Left inner border */
							p->drawLine(x + 1, y, x + 1, y + h - 2);
						} else {
							y2 -= 2;
							const QCOORD oCorners[] = { x, y, x, y2, x2, y2, x2, y };
							QRect r2(x + 1, y + 2, w - 2, h - 5);
							p->fillRect(r2, cg.mid().light(105));

							p->drawPolyline(QPointArray(4, oCorners));

							p->setPen(cg.mid().dark(115));
						/*	Inner right border */
							p->drawLine(x + w - 2, y + 2, x + w - 2, y + h - 4);
							p->drawLine(x + 1, y + h - 4, x + w - 2, y + h - 4);

							p->setPen(cg.background().dark(115));
						/* Top of underlying tabbar-widget */
							p->drawLine(x, y, x + w - 1, y);
							p->setPen(cg.background().dark());
						/*	Top of underlying tabbar-widget */
							p->drawLine(x, y + 1, x + w - 1, y + 1);
						/*	Outer right border */
							p->drawLine(x + w - 1, y + 3, x + w - 1, y + h - 2);

						/*	hack where the rounded corners sometimes go away */
							if (roundedCorners) {
								p->setPen(cg.background());
								p->drawPoint(x + w - 1, y + h - 3);
								p->drawPoint(x + w - 1, y + h - 2);
							}
    					}

						if (opt.tab()->identifier() == 0 && !cornerWidget) {
							p->setPen(cg.background().dark());
							p->drawPoint(x, y);
						}
					} else {
						if (selected) {
							p->setPen(cg.background().light());
							p->drawLine(x, y, x, y + h - 1);

							p->setPen(cg.background().dark());
							p->drawLine(x + w - 1, y, x + w - 1, y + h - 1);
							p->drawLine(x, y + h-1, x + w - 1, y + h - 1);
						} else {
							QRect r2(x, y + 1, w - 1, h - 4);
							p->fillRect(r2, cg.mid());

							p->setPen(cg.background().dark());
							p->drawLine(x, y, x + w - 1, y);

							p->setPen(cg.mid().dark(115));
							p->drawLine(x + w - 2, y + 1, x + w - 2, y + h - 5);
							p->drawLine(x, y + h - 4, x + w - 1, y + h - 4);
						}
					}
					break;
				}

				default:
					winstyle->drawControl(element, p, widget, r, cg, flags, opt);
			}

			break;
		}

		case CE_TabBarLabel: {
			const int text_flags = AlignVCenter | AlignHCenter | ShowPrefix |
			                       DontClip | SingleLine;

			p->save();

			if (useTextShadows) {
				p->setPen(cg.background().dark(115));
				p->drawText(r.x()+1, r.y()+1, r.width(), r.height(), text_flags, opt.tab()->text());
			}

			p->setPen(flags & Style_Enabled ? cg.foreground() : cg.mid().dark());

			if (!flags & Style_Selected) {
				p->translate(pixelMetric(PM_ButtonShiftHorizontal),
				             pixelMetric(PM_ButtonShiftVertical));
			}

			p->drawText(r, text_flags, opt.tab()->text());

			if (flags & Style_HasFocus)
				drawPrimitive(PE_FocusRect, p, r, cg);

			p->restore();
			break;
		}

		case CE_PushButton: {
			QPushButton *button = (QPushButton *)widget;
			QRect br = r;
			bool btnDefault = button->isDefault();

			static int di = pixelMetric(PM_ButtonDefaultIndicator);
			br.addCoords(di, di, -di, -di);

			if (btnDefault) {
				drawPrimitive(PE_ButtonDefault, p, r, cg, flags);
			}

			drawPrimitive(PE_ButtonBevel, p, br, cg, flags);
			break;
		}

		case CE_PushButtonLabel: {
			const QPushButton *pb = (const QPushButton *)widget;
			const bool enabled = flags & Style_Enabled;
			const int text_flags = AlignVCenter | AlignHCenter | ShowPrefix |
			                       DontClip | SingleLine;
			QRect ur(r);

			if (flags & Style_Down) {
				p->translate(pixelMetric(PM_ButtonShiftHorizontal),
				             pixelMetric(PM_ButtonShiftVertical));
			}

			if (!pb->text().isEmpty() && (flags & Style_ButtonDefault)) {
				p->setFont(QFont(p->font().family(), p->font().pointSize(), 75));
			}

			if (pb->iconSet() && !pb->iconSet()->isNull()) {
				QIconSet::Mode mode = enabled ? QIconSet::Normal : QIconSet::Disabled;
				QPixmap pixmap = pb->iconSet()->pixmap(QIconSet::Small, mode);

				if (!pb->text().isEmpty())
				{
					const int TextToIconMargin = 3;
					int length = pixmap.width() + TextToIconMargin
					              + p->fontMetrics().size(ShowPrefix, pb->text()).width();
					int offset = (r.width() - length)/2;

					p->drawPixmap( r.x() + offset, r.y() + r.height() / 2 - pixmap.height() / 2, pixmap );
					ur.addCoords(offset + pixmap.width() + TextToIconMargin, 0, -offset, 0);
				}
				else
				{
					if (!pb->pixmap())
						p->drawPixmap(r.x() + r.width()/2 - pixmap.width()/2, r.y() + r.height() / 2 - pixmap.height() / 2,
										pixmap);
					else  //icon + pixmap. Ugh.
						p->drawPixmap(r.x() + pb->isDefault() ? 8 : 4 , r.y() + r.height() / 2 - pixmap.height() / 2, pixmap);
				}
			}

			if (pb->pixmap() && !pb->text()) {
				QRect pr(0, 0, pb->pixmap()->width(), pb->pixmap()->height());
				pr.moveCenter(r.center());
				p->drawPixmap(pr.topLeft(), *pb->pixmap());
			}

			if (useTextShadows && !pb->text().isEmpty() && enabled) {
				p->setPen((flags & Style_Down ? cg.highlight().dark(135) : cg.background().dark(115)));
				p->drawText(ur.x()+1, ur.y()+1, ur.width(), ur.height(), text_flags, pb->text());
			}

			if (!pb->text().isEmpty()) {
				p->setPen(enabled ? cg.foreground() : pb->palette().disabled().buttonText());
				p->drawText(ur, text_flags, pb->text());
			}

			if ( flags & Style_HasFocus )
				drawPrimitive( PE_FocusRect, p,
				               visualRect( subRect( SR_PushButtonFocusRect, widget ), widget ),
				               cg, flags );

			break;
		}

	//	MENUBAR ITEM (sunken panel on mouse over)
	//	-----------------------------------------
		case CE_MenuBarItem: {
			QMenuItem *mi = opt.menuItem();
			bool active  = flags & Style_Active;
			bool focused = flags & Style_HasFocus;
			bool down = flags & Style_Down;
			const int text_flags =
				AlignVCenter | AlignHCenter | ShowPrefix | DontClip | SingleLine;
			int x, x2, y, y2;
			r.coords(&x, &y, &x2, &y2);

			if (active && focused) {
				p->setBrush(cg.highlight());
				p->setPen(down ? cg.highlight().light() : cg.highlight().dark());
				p->drawRect(r);
				if (pseudo3D && roundedCorners && !down) {
					const QCOORD corners[] = { x, y2, x, y, x2, y, x2, y2 };
					p->setPen(cg.background());
					p->drawPoints(QPointArray(4, corners));
				}

				if (down) {
					p->setBrush(cg.background().light());
					p->setPen(cg.background().dark());
					p->drawRect(r);
					p->setPen(cg.background().light());
					p->drawLine(x+1, y2, x2-1, y2);
					if (pseudo3D && roundedCorners) {
						p->setPen(cg.background());
						p->drawPoint(x, y);
						p->drawPoint(x2, y);
					}
				}
			}

			if (useTextShadows) {
				p->setPen((active && focused && !down ? cg.highlight().dark(135) : cg.background().dark(115)));
				p->drawText(r.x() + 1, r.y() + 1, r.width(), r.height(), text_flags, mi->text());
			}
			p->setPen((active && focused && !down ? cg.highlightedText() : cg.foreground()));
			p->drawText(r, text_flags, mi->text());
			break;
		}

	//	POPUPMENU ITEM (highlighted on mouseover)
	//	------------------------------------------
		case CE_PopupMenuItem: {
			QMenuItem *mi = opt.menuItem();

			if (!mi) {
				return;
			}

			const QPopupMenu *pum = (const QPopupMenu *) widget;
			static const int itemFrame = 2;
			static const int itemHMargin = 3;
			static const int itemVMargin = 3;
			static const int arrowHMargin = 6;
			static const int rightBorder = 20;
			const int tab = opt.tabWidth();

			int checkcol = QMAX(opt.maxIconWidth(), 26);
			int x, x2, y, y2, w, h;
			r.rect(&x, &y, &w, &h);
			r.coords(&x, &y, &x2, &y2);

			bool active = flags & Style_Active;
			bool disabled = !mi->isEnabled();
			bool checkable = pum->isCheckable();

			int xpos = x;
			int xm = itemFrame + checkcol + itemHMargin;

			if (pum->erasePixmap() && !pum->erasePixmap()->isNull()) {
				p->drawPixmap( x, y, *pum->erasePixmap(), x, y, w, h );
			} else {
				if (!QApplication::reverseLayout()) {
					p->fillRect( x, y, 22, h, cg.mid() );
					p->fillRect( x + 22, y, w - 22, h, cg.background().light() );
				} else { // i wonder why exactly +1 (diego)
					p->fillRect( w-22, y, 22+1, h, cg.mid() );
					p->fillRect( x, y, w - 22, h, cg.background().light() );
				}
			}

			if (mi->isSeparator()) {
				p->setPen(cg.mid());
				if (!QApplication::reverseLayout())
					p->drawLine(x + opt.maxIconWidth() + 6, y, x + w, y);
				else
					p->drawLine(w - (x + opt.maxIconWidth() + 6), y,
					            x, y);
				return;
			}

			if (active && !disabled) {
				p->setBrush(cg.highlight());
				p->fillRect(x + 2, y + 2, w - 4, h - 4, cg.highlight());
				p->setPen(cg.highlight().dark());
				if (pseudo3D && roundedCorners) {
					const QCOORD segments[] = { x+2, y+1, x2-2, y+1, x2-1, y+2, x2-1, y2-2, x2-2, y2-1, x+2, y2-1, x+1, y2-2, x+1, y+2 };
					const QCOORD icorners[] = { x+2, y+2, x2-2, y+2, x2-2,y2-2, x+2, y2-2 };
					p->drawLineSegments(QPointArray(8, segments));
					p->drawPoints(QPointArray(4, icorners));
				} else {
					const QCOORD corners[] = { x+1, y2-1, x+1, y+1, x2-1, y+1, x2-1, y2-1 };
					p->drawConvexPolygon(QPointArray(4, corners));
				}
				p->setPen(cg.highlightedText());
			}

			if (mi->iconSet()) {
				p->save();
				QIconSet::Mode mode =
					disabled ? QIconSet::Disabled : QIconSet::Normal;
				QPixmap pixmap = mi->iconSet()->pixmap(QIconSet::Small, mode);
				int pixw = pixmap.width();
				int pixh = pixmap.height();

				QRect cr(xpos, y, opt.maxIconWidth(), h);
				QRect pmr(0, 0, pixw, pixh);
				pmr.moveCenter(cr.center());

				if (QApplication::reverseLayout())
					pmr = visualRect( pmr, r );

				p->setPen(cg.highlightedText());
				p->drawPixmap(pmr.topLeft(), pixmap);
				p->restore();
			}

			p->setPen(active ? cg.highlightedText() : cg.buttonText());

			xpos += xm;

			if (mi->custom()) {
				int m = itemVMargin;
				p->setPen(cg.foreground());
				mi->custom()->paint(p, cg, active, !disabled, x+xm, y+m, w-xm-tab+1, h-2*m);
				return;
			} else {
				QString s = mi->text();
				if(!s.isNull()) {
					int t = s.find('\t');
					int m = itemVMargin;

					int text_flags = AlignVCenter | ShowPrefix | DontClip | SingleLine;

					if (active && !disabled) {
						p->setPen(cg.highlightedText());
					} else if (disabled) {
						p->setPen(cg.mid().light(110));
					} else {
						p->setPen(cg.text());
					}

					if (t >= 0) {
						int xp;
						xp = x + w - tab - rightBorder - itemHMargin - itemFrame + 1;

						QRect rr = QRect(xp, y+m, tab, h-(2*m));
						if (QApplication::reverseLayout())
							rr = visualRect(rr, r);

						if (useTextShadows) {
							QPen op = p->pen();
							p->setPen(active && !disabled ? cg.highlight().dark(130) : cg.background().dark(115));
							p->drawText(rr.x() + 1, rr.y() + 1, rr.width(), rr.height(), text_flags, s.mid(t+1));
							p->setPen(op);
						}

						p->drawText(rr, text_flags, s.mid(t+1));
						s = s.left(t);
					}

					QRect rr = QRect(xpos, y+m, w-xm-tab+1, h-(2*m));
					if (QApplication::reverseLayout()) {
						rr = visualRect(rr, r);
						text_flags |= AlignRight;
					}

					if (useTextShadows) {
						QPen op = p->pen();
						p->setPen(active && !disabled ? cg.highlight().dark(130) : cg.background().dark(115));
						p->drawText(rr.x() + 1, rr.y() + 1, rr.width(), rr.height(), text_flags, s);
						p->setPen(op);
					}

					p->drawText(rr, text_flags, s);
				} else if (mi->pixmap()) {
					QPixmap *pixmap = mi->pixmap();
					if (pixmap->depth() == 1) {
						p->setBackgroundMode(OpaqueMode);
					}
					p->drawPixmap(xpos, y, *pixmap);
					if (pixmap->depth() == 1) {
						p->setBackgroundMode(TransparentMode);
					}
				}
			}

			if (mi->popup()) {
				int dim = pixelMetric(PM_MenuButtonIndicator);

				xpos = x+w - arrowHMargin - 2*itemFrame - dim;

				if (active && !disabled)
					p->setPen(cg.highlightedText());
				else
					p->setPen(cg.text());


				QRect rr = QRect(xpos, y + h/2 - dim/2, dim, dim);
				if (QApplication::reverseLayout())
					rr = visualRect( rr, r );
				drawPrimitive((QApplication::reverseLayout() ? PE_ArrowLeft : PE_ArrowRight), p, rr, cg, Style_Enabled);
			}

			if (checkable) {
				if (mi->isChecked()) {
					int xp = x;

					SFlags cflags = Style_Default;

					if (!disabled)
						cflags |= Style_Enabled;
					else
						cflags |= Style_On;

					QRect rr = QRect( xp + 6, y + 6, 16, h - 6 );
					if (QApplication::reverseLayout())
						rr = visualRect( rr, r );

					drawPrimitive(PE_CheckMark, p, rr, cg, cflags);
				}
			}

			break;
		}

	// Menu and dockwindow empty space
	//
		case CE_DockWindowEmptyArea:
		case CE_MenuBarEmptyArea:
			p->fillRect(r, cg.button());
			break;
		default:
			winstyle->drawControl(element, p, widget, r, cg, flags, opt);
	}
}

void dotNETstyle::drawControlMask(ControlElement element,
                                  QPainter *p,
                                  const QWidget *w,
                                  const QRect &r,
                                  const QStyleOption &opt) const
{
	switch (element) {
		case CE_PushButton: {
			if (pseudo3D && roundedCorners) {
				int x1, y1, x2, y2;
				r.coords (&x1, &y1, &x2, &y2);
				QCOORD corners[] = { x1, y1, x2, y1, x1, y2, x2, y2 };
				p->fillRect (r, color1);
				p->setPen (color0);
				p->drawPoints (QPointArray (4, corners));
			} else {
			//	Just fill the entire thing
				p->fillRect (r, color1);
			}
			break;
		}

		default: {
			KStyle::drawControlMask (element, p, w, r, opt);
		}
	}
}

void dotNETstyle::drawComplexControlMask(ComplexControl c,
                                         QPainter *p,
                                         const QWidget *w,
                                         const QRect &r,
                                         const QStyleOption &o) const
{
	switch (c) {
		case CC_ComboBox: {
			if (pseudo3D && roundedCorners) {
				int x1, y1, x2, y2;
				r.coords (&x1, &y1, &x2, &y2);
				QCOORD corners[] = { x1, y1, x2, y1, x1, y2, x2, y2 };
				p->fillRect (r, color1);
				p->setPen (color0);
				p->drawPoints (QPointArray (4, corners));
			} else {
			//	Just fill the entire thing
				p->fillRect (r, color1);
			}
			break;
		}
		default: {
			KStyle::drawComplexControlMask (c, p, w, r, o);
		}
	}
}

void dotNETstyle::drawComplexControl(ComplexControl control,
                                     QPainter *p,
                                     const QWidget *widget,
                                     const QRect &r,
                                     const QColorGroup &cg,
                                     SFlags flags,
                                     SCFlags controls,
                                     SCFlags active,
                                     const QStyleOption& opt) const
{
	switch(control) {
	//	COMBOBOX
	//	--------
		case CC_ComboBox: {
			int x, y, w, h;
			const QComboBox *cb = (const QComboBox *)widget;
			r.rect(&x, &y, &w, &h);

			if (active & Style_Sunken)
				flags |= Style_Sunken;

			static const unsigned char downarrow_bits[] = {
				0x7f, 0xbe, 0x9c, 0x08, 0x00, 0x00, 0x00, 0x28,
				0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0xb8
			};

			static const unsigned int handle_width = 15;
			static const unsigned int handle_offset = handle_width + 1;

			QBitmap downArrow = QBitmap(7, 4, downarrow_bits, true);
			downArrow.setMask(downArrow);

			cb->editable() ? p->fillRect(x + 1, y + 1, w - 2, h - 2, cg.base()) : p->fillRect(x + 1, y + 1, w - 2, h - 2, cg.light());

			renderPanel(p, r, cg, true, true);

			p->save();
		//	Draw the box on the right.
			if (cb->listBox() && cb->listBox()->isVisible()) {
				p->setPen(cg.highlight());
				p->setBrush(cg.highlight().light());
			} else if (flags & Style_HasFocus) {
				p->setPen(cg.highlight().dark());
				p->setBrush(cg.highlight());
			} else {
				p->setPen(cg.dark());
				p->setBrush(cg.midlight());
			}

			QRect hr = (pseudo3D ? QRect(w - handle_offset - 1, y, handle_width + 2, h) : QRect(w - handle_offset - 1, y + 1, handle_width + 2, h - 1));
			if (QApplication::reverseLayout()) { hr = visualRect(hr, r); }

			p->drawRect(hr);
			p->setBrush(NoBrush);
			QRect rr = (pseudo3D ? QRect(x + 1, y + 1, w - 2, h - 2) : QRect(x + 1, y + 1, w - 1, h - 1));

			if (QApplication::reverseLayout()) { rr = visualRect( rr, r ); }

			if (flags & Style_HasFocus || cg.highlight() == cg.midlight() ||
			    (cb->listBox() && cb->listBox()->isVisible())) {
				p->drawRect(rr);
			}

			if (pseudo3D && !((active & Style_Sunken) ||
			   (cb->listBox() && cb->listBox()->isVisible()))) {
				p->save();
				p->setBrush(NoBrush);
				QColor test = ((flags & Style_HasFocus) ? cg.highlight() : cg.midlight());
				p->setPen(test.dark());
				p->drawRect(hr);
				hr.moveBy(1,1);
				hr.setSize(QSize(hr.width() -2, hr.height() -2));
				QPointArray ca(3);
				ca.setPoint(0, hr.topRight());
				ca.setPoint(1, hr.bottomRight());
				ca.setPoint(2, hr.bottomLeft());
				p->setPen(test.dark(120));
				p->drawPolyline(ca);
				p->setPen(test.light(120));
				ca.setPoint(1, hr.topLeft());
				p->drawPolyline(ca);
				p->restore();
			}

			if (pseudo3D && roundedCorners) {
				p->setPen(cg.background());
				p->drawPoint(r.topRight());
				p->drawPoint(r.bottomRight());
				p->setPen(cg.background().dark());
				hr.moveBy(-1,-1);
				hr.setSize(QSize(hr.width() + 2, hr.height() + 2));
				p->drawPoint(hr.topLeft());
				p->drawPoint(hr.bottomLeft());
			}

			if ((active && cb->hasFocus()) || (cb->listBox() && cb->listBox()->isVisible())) {
				p->setPen(cg.highlightedText());
			} else {
				p->setPen(cg.text());
			}

			QRect cr(w - handle_offset, y, handle_width, h - 2);
			QRect pmr(0, 0, 7, 4);
			pmr.moveCenter(cr.center());
			if (QApplication::reverseLayout()) {
				pmr = visualRect( pmr, r );
			}

			p->drawPixmap(pmr.topLeft(), downArrow);

			p->restore();
			break;
		}

	//	TOOLBUTTON
	//	----------
		case CC_ToolButton: {
			const QToolButton *tb = (const QToolButton *) widget;

			QRect button, menuarea;
			button   = querySubControlMetrics(control, widget, SC_ToolButton, opt);
			menuarea = querySubControlMetrics(control, widget, SC_ToolButtonMenu, opt);

			SFlags bflags = flags,
			       mflags = flags;

			if (active & SC_ToolButton)
				bflags |= Style_Down;

			if (active & SC_ToolButtonMenu)
				mflags |= Style_Down;

			if (controls & SC_ToolButton) {
			//	If we're pressed, on, or raised...
				if (bflags & (Style_Down | Style_On | Style_Raised)) {
					drawPrimitive(PE_ButtonTool, p, button, cg, bflags, opt);
				} else if (tb->parentWidget() &&
				           tb->parentWidget()->backgroundPixmap() &&
				           !tb->parentWidget()->backgroundPixmap()->isNull()) {
					QPixmap pixmap = *(tb->parentWidget()->backgroundPixmap());
					p->drawTiledPixmap( r, pixmap, tb->pos() );
				}
			}

			// Draw a toolbutton menu indicator if required
			if (controls & SC_ToolButtonMenu) {
				if (mflags & (Style_Down | Style_On | Style_Raised)) {
					drawPrimitive(PE_ButtonDropDown, p, menuarea, cg, mflags, opt);
				}
				drawPrimitive(PE_ArrowDown, p, menuarea, cg, mflags, opt);
			}

			if (tb->hasFocus() && !tb->focusProxy()) {
				QRect fr = tb->rect();
				fr.addCoords(2, 2, -2, -2);
				drawPrimitive(PE_FocusRect, p, fr, cg);
			}

			break;
		}

	//	SPINWIDGETS
	//	-----------
		case CC_SpinWidget: {
			const QSpinWidget *sw = (const QSpinWidget *) widget;
			SFlags flags;
			PrimitiveElement pe;

			QRect swf = querySubControlMetrics(control, sw, SC_SpinWidgetFrame);
			swf = visualRect( swf, sw );

			if (controls & SC_SpinWidgetFrame) {
			// Don't draw the WindowsStyle thick frame.
				renderPanel(p, swf, cg, true, false);
			}

			if (controls & SC_SpinWidgetUp) {
				flags = Style_Default | Style_Enabled;
				if (active == SC_SpinWidgetUp) {
					flags |= Style_On;
					flags |= Style_Sunken;
				} else
					flags |= Style_Raised;

				if (sw->buttonSymbols() == QSpinWidget::PlusMinus)
					pe = PE_SpinWidgetPlus;
				else
					pe = PE_SpinWidgetUp;

				QRect re = sw->upRect();
				QColorGroup ucg = sw->isUpEnabled() ? cg : sw->palette().disabled();
				p->fillRect(re.x() + 1, re.y() + 1, re.width() - 2, re.height() - 1, flags & Style_Raised ? ucg.background() : ucg.highlight());
				if (pseudo3D) {
					const QCOORD corners[] = { re.x(), re.bottom(), re.x(), re.y() + 1, re.x() + 1, re.y(), re.right() - 1, re.y(), re.right(), re.y() + 1, re.right(), re.bottom() };
					p->setPen(flags & Style_Raised ? ucg.background().dark() : ucg.highlight());
					p->drawLineSegments(QPointArray(6, corners));
					p->setPen(flags & Style_Raised ? ucg.background().light() : ucg.highlight());
					p->drawLine(re.x() + 1, re.y() + 1, re.x() + 1, re.bottom());
					p->drawLine(re.x() + 1, re.y() + 1, re.right()-1, re.y() + 1);
					p->setPen(flags & Style_Raised ? ucg.background().dark(115) : ucg.highlight());
					p->drawLine(re.right()-1, re.y() + 2, re.right()-1, re.bottom());
				} else {
				}
				re.setX(re.x() + 1);
				p->setPen(flags & Style_Raised ? ucg.foreground() : ucg.highlightedText());
				drawPrimitive(pe, p, re, ucg, flags);
			}

			if (controls & SC_SpinWidgetDown) {
				flags = Style_Default | Style_Enabled;
				if (active == SC_SpinWidgetDown) {
					flags |= Style_On;
					flags |= Style_Sunken;
				} else
					flags |= Style_Raised;

				if (sw->buttonSymbols() == QSpinWidget::PlusMinus)
					pe = PE_SpinWidgetMinus;
				else
					pe = PE_SpinWidgetDown;

				QRect re = sw->downRect();
				QColorGroup dcg = sw->isDownEnabled() ? cg : sw->palette().disabled();
				p->fillRect(re.x() + 1, re.y(), re.width() - 2, re.height() - 1, flags & Style_Raised ? dcg.background() : dcg.highlight());
				if (pseudo3D) {
					const QCOORD corners[] = {
						re.x(), re.top(),
						re.x(), re.bottom(),
						re.x() + 1, re.y() + re.height(),
						re.right() - 1, re.y() + re.height(),
						re.right(), re.bottom(),
						re.right(), re.y()
					};
					p->setPen(flags & Style_Raised ? dcg.background().dark() : dcg.highlight());
					p->drawLineSegments(QPointArray(6, corners));
					p->setPen(flags & Style_Raised ? dcg.background().light() : dcg.highlight());
					p->drawLine(re.x() + 1, re.y(), re.x() + 1, re.bottom());
					p->setPen(flags & Style_Raised ? dcg.background().dark(115) : dcg.highlight());
					p->drawLine(re.x() + 2, re.bottom(), re.right()-1, re.bottom());
					p->drawLine(re.right()-1, re.y(), re.right()-1, re.bottom());
				} else {
				}
				p->setPen(flags & Style_Raised ? dcg.foreground() : dcg.highlightedText());
				re.setX(re.x() + 1);
				drawPrimitive(pe, p, re, dcg, flags);
			}

			break;
		}

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


QRect dotNETstyle::subRect(SubRect r, const QWidget *widget) const
{
// Don't use KStyles progressbar subrect
	switch (r) {
		case SR_ComboBoxFocusRect: {
			return querySubControlMetrics( CC_ComboBox, widget, SC_ComboBoxEditField );
		}

		case SR_PushButtonFocusRect: {
			QRect rect = widget->rect();
			int margin = pixelMetric(PM_ButtonDefaultIndicator, widget) + pixelMetric(PM_DefaultFrameWidth, widget) + 2;

			rect.addCoords(margin, margin, -margin, -margin);
			return rect;
		}

		case SR_ProgressBarGroove:
		case SR_ProgressBarContents:
		case SR_ProgressBarLabel: {
			return winstyle->subRect(r, widget);
		}
		default: {
			return KStyle::subRect(r, widget);
		}
	}
}

QRect dotNETstyle::querySubControlMetrics(ComplexControl control,
                                          const QWidget *widget,
                                          SubControl subcontrol,
                                          const QStyleOption &opt) const
{
	if (!widget) {
		return QRect();
	}

	QRect r(widget->rect());
	switch (control) {
		case CC_ComboBox: {
			switch (subcontrol) {
				case SC_ComboBoxEditField: {
					return QRect(r.x() + 2, r.y() + 2, r.width() - 19, r.height() - 4);
				}
				default: {
					return KStyle::querySubControlMetrics(control, widget, subcontrol, opt);
				}
			}
			break;
		}

		case CC_SpinWidget: {
			int fw = pixelMetric(PM_SpinBoxFrameWidth, widget);
			QSize bs;
			bs.setHeight(QMAX(8, widget->height()/2));
			bs.setWidth(QMIN(bs.height() * 8 / 5, widget->width() / 4));

			int y = fw;
			int x, lx, rx;
			x = widget->width() - y - bs.width();
			lx = fw;
			rx = x - fw;

			switch (subcontrol) {
				case SC_SpinWidgetUp: {
					return QRect(x, y-1, bs.width(), bs.height());
				}
				case SC_SpinWidgetDown: {
					return QRect(x, y + bs.height()-1, bs.width(), bs.height());
				}
				case SC_SpinWidgetFrame: {
					return QRect(0, 0, widget->width() - (bs.width() + 2), widget->height());
				}
				case SC_SpinWidgetEditField: {
					return QRect(lx, fw, widget->width() - (bs.width() + 4), widget->height() - 2 * fw);
				}
				case SC_SpinWidgetButtonField: {
					return QRect(x, y, bs.width(), widget->height() - 2 * fw);
				}
				default: {
				}
			}
			break;
		}
		default: {
		}
	}
	return KStyle::querySubControlMetrics(control, widget, subcontrol, opt);
}

int dotNETstyle::pixelMetric(PixelMetric m, const QWidget *widget) const
{
	switch(m) {
	//	TABS
	//	----
		case PM_TabBarTabVSpace: {
			const QTabBar * tb = (const QTabBar *) widget;
			if (tb->shape() == QTabBar::RoundedAbove ||
			    tb->shape() == QTabBar::RoundedBelow)
				return 12;
			else
				return 0;
		}

		case PM_TabBarTabOverlap: {
			const QTabBar* tb = (const QTabBar*)widget;
			if (tb->shape() != QTabBar::RoundedAbove &&
			    tb->shape() != QTabBar::RoundedBelow)
				return 3;                   // Leave standard size alone
			else
				return 1;                   // Change size for our tabs only
		}

	//	SPLITTERS
	//	---------
		case PM_SplitterWidth: {
			return 6;
		}

	//	PROGRESSBARS
	//	------------
		case PM_ProgressBarChunkWidth:
			return 9;

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

	//	MENU INDICATOR
	//	--------------
		case PM_MenuButtonIndicator:
			return 8;

	//	HEADER INDICATOR
	//	----------------
		case PM_HeaderMarkSize:
			return 1;

	//	CHECKBOXES / RADIO BUTTONS
	//	--------------------------
		case PM_ExclusiveIndicatorWidth:    // Radiobutton size
		case PM_ExclusiveIndicatorHeight:   // 13x13
		case PM_IndicatorWidth:             // Checkbox size
		case PM_IndicatorHeight:            // 13x13
			return 13;

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

		case PM_MenuBarFrameWidth:
			return 0;

		case PM_DefaultFrameWidth: {
			if (!pseudo3D) {
				return 1;
			} else {
				if (widget &&
				   (widget->inherits("QPopupMenu") ||
				    widget->inherits("QMenuBar") ||
				    widget->inherits("QRangeControl") ||
				    widget->inherits("QScrollView"))) {
					return 1;
				} else {
					return 2;
				}
			}
		}

		case PM_ButtonDefaultIndicator: {
			return 3;
		}

		case PM_ButtonShiftVertical:
		case PM_ButtonShiftHorizontal: {
			return 1;
		}

		default:
			return KStyle::pixelMetric(m, widget);
	}
}


QSize dotNETstyle::sizeFromContents(ContentsType t,
                                    const QWidget *widget,
                                    const QSize &s,
                                    const QStyleOption &opt) const
{
	switch (t) {

		case CT_PopupMenuItem: {
			if (!widget || opt.isDefault())
				break;

			const QPopupMenu *popup = (const QPopupMenu *)widget;
			QMenuItem *mi = opt.menuItem();
			int maxpmw = opt.maxIconWidth();
			int w = s.width(), h = s.height();
			bool checkable = popup->isCheckable();

			if (mi->custom()) {
				w = mi->custom()->sizeHint().width();
				h = mi->custom()->sizeHint().height();
			} else if (mi->widget()) {
			// don't change the size in this case.
			} else if (mi->isSeparator()) {
				w = 10;
				h = 1;
			} else {
				if (mi->pixmap()) {
					h = QMAX(h, mi->pixmap()->height() + 8);
				}

				h = QMAX(h, widget->fontMetrics().height() + 10);

				if (mi->iconSet()) {
					h = QMAX(h, mi->iconSet()->pixmap(QIconSet::Small, QIconSet::Normal).height() + 8);
				}
			}

			if (!mi->text().isNull()) {
				if ((mi->text().find('\t') >= 0) || mi->popup()) {
					w += 20;
				}
			}

			if (maxpmw) {
				w += maxpmw;
			}
			if (checkable && maxpmw < 20) {
				w += 20 - maxpmw;
			}
			if (checkable || maxpmw > 0) {
				w += 2;
			}

			w += 20;

			return QSize(w, h);
		}

		case CT_PushButton: {
			const QPushButton* button = (const QPushButton*) widget;
			int w  = s.width();
			int h  = s.height();
			int bm = pixelMetric( PM_ButtonMargin, widget );
			int fw = pixelMetric( PM_DefaultFrameWidth, widget ) * 2;

			//We use bold font sometimes, so that make take more space than Qt allocated.
			QFontMetrics origFM = button->fontMetrics();
			QFontMetrics boldFM = QFontMetrics(QFont(button->font().family(), button->font().pointSize(), 75));
			int origTextWidth = origFM.size(ShowPrefix, button->text()).width();
			int boldTextWidth = boldFM.size(ShowPrefix, button->text()).width();

			if (boldTextWidth > origTextWidth) //this might not happen in particular when text is empty
				w += boldTextWidth - origTextWidth;

			w += bm + fw;
			h += bm + fw;

			// Ensure we stick to standard width and heights.
			if ( button->isDefault() || button->autoDefault() ) {
				if ( w < 80 && !button->pixmap() )
					w = 80;
			}

			// Compensate for default indicator. Doing it for all widgets lets us
			// workaround changes in auto-default behavior in KDialogBase in 3.3
			int di = pixelMetric( PM_ButtonDefaultIndicator );
			w += di * 2;
			h += di * 2;

			if ( h < 22 )
				h = 22;
			return QSize( w, h );
		}

		case CT_ComboBox: {
			int arrow = 21;
			return QSize(s.width() + arrow, QMAX(s.height() + 4, 16));
		}

		default:
			return KStyle::sizeFromContents (t, widget, s, opt);
	}

	return KStyle::sizeFromContents (t, widget, s, opt);
//	return winstyle->sizeFromContents(t, widget, s, opt);
}

void dotNETstyle::paletteChanged()
{
	QComboBox *combo  = 0L;
	QMenuBar *menuBar = 0L;
	QToolBar *toolBar = 0L;
   QWidget  *widget  = 0L;

	QValueListIterator<QWidget*> it = m_widgets.begin();
	for ( ; it != m_widgets.end(); ++it ) {
		widget = *it;
		if ((combo = dynamic_cast<QComboBox*>( widget )))
			updatePalette( combo );
		else if ((toolBar = dynamic_cast<QToolBar*>( widget )))
			updatePalette( toolBar );
		else if ((menuBar = dynamic_cast<QMenuBar*>( widget )))
			updatePalette( menuBar );
	}
}

void dotNETstyle::updatePalette( QComboBox *combo )
{
	QPalette pal = QApplication::palette();
	pal.setColor(QColorGroup::Dark,
	             pal.active().color(QColorGroup::Base));
	pal.setColor(QColorGroup::Midlight,
	             pal.active().color(QColorGroup::Background));
	combo->setPalette(pal);
}

void dotNETstyle::updatePalette( QToolBar *bar )
{
	QPalette pal = QApplication::palette();
	pal.setColor(QColorGroup::Button,
	             pal.active().color(QColorGroup::Background));
	bar->setPalette(pal);
}

void dotNETstyle::updatePalette( QMenuBar *bar )
{
	QPalette pal = QApplication::palette();
	pal.setColor(QColorGroup::Button,
	             pal.active().color(QColorGroup::Background));
	bar->setPalette(pal);
}

void dotNETstyle::slotDestroyed()
{
	m_widgets.remove( (QWidget*) sender() );
}

bool dotNETstyle::eventFilter(QObject *obj, QEvent *ev)
{
	if (obj->inherits("QComboBox")) {
		if (ev->type() == QEvent::Enter) {
			QWidget *btn = (QWidget *)obj;
			if (btn->isEnabled()) {
				QPalette pal = btn->palette();
				pal.setColor(QColorGroup::Dark,
				             pal.active().color(QColorGroup::Highlight).dark());
				pal.setColor(QColorGroup::Midlight,
				             pal.active().color(QColorGroup::Highlight));
				btn->setPalette(pal);
			}
		} else if (ev->type() == QEvent::Leave) {
			QWidget *btn = (QWidget *)obj;
			QPalette pal = btn->palette();
			pal.setColor(QColorGroup::Dark,
			             pal.active().color(QColorGroup::Base));
			pal.setColor(QColorGroup::Midlight,
			             pal.active().color(QColorGroup::Background));
			btn->setPalette(pal);
		}
	} else if (obj->inherits("QButton")) {
		QWidget *btn = (QWidget *)obj;
		QPalette pal = btn->palette();
		pal.setColor(QColorGroup::Button,
		             pal.active().color(QColorGroup::Background));
		btn->setPalette(pal);
	}

	return false;
}

// vim: noet ts=4 sw=4