summaryrefslogtreecommitdiffstats
path: root/src/styles/qmotifplusstyle.cpp
blob: 86a25589536c54d737bd83eb00dff1133c5c74c9 (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
/****************************************************************************
**
** Implementation of QMotifPlusStyle class
**
** Created : 000727
**
** Copyright (C) 2005-2008 Trolltech ASA.  All rights reserved.
**
** This file is part of the widgets module of the Qt GUI Toolkit.
**
** This file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free
** Software Foundation and appearing in the files LICENSE.GPL2
** and LICENSE.GPL3 included in the packaging of this file.
** Alternatively you may (at your option) use any later version
** of the GNU General Public License if such license has been
** publicly approved by Trolltech ASA (or its successors, if any)
** and the KDE Free Qt Foundation.
**
** Please review the following information to ensure GNU General
** Public Licensing requirements will be met:
** http://trolltech.com/products/qt/licenses/licensing/opensource/.
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
** or contact the sales department at [email protected].
**
** This file may be used under the terms of the Q Public License as
** defined by Trolltech ASA and appearing in the file LICENSE.QPL
** included in the packaging of this file.  Licensees holding valid Qt
** Commercial licenses may use this file in accordance with the Qt
** Commercial License Agreement provided with the Software.
**
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
** herein.
**
**********************************************************************/

#include "qmotifplusstyle.h"

#if !defined(QT_NO_STYLE_MOTIFPLUS) || defined(QT_PLUGIN)

#include "qmenubar.h"
#include "qapplication.h"
#include "qpainter.h"
#include "qpalette.h"
#include "qframe.h"
#include "qpushbutton.h"
#include "qcheckbox.h"
#include "qradiobutton.h"
#include "qcombobox.h"
#include "qlineedit.h"
#include "qspinbox.h"
#include "qslider.h"
#include "qdrawutil.h"
#include "qscrollbar.h"
#include "qtabbar.h"
#include "qtoolbar.h"
#include "qguardedptr.h"
#include "qlayout.h"


struct QMotifPlusStylePrivate
{
    QMotifPlusStylePrivate()
        : hoverWidget(0), hovering(FALSE), sliderActive(FALSE), mousePressed(FALSE),
          scrollbarElement(0), lastElement(0), ref(1)
    { ; }

    void* hoverWidget;
    QStyleControlElementData hoverWidgetData;
    QStyle::ControlElementFlags hoverWidgetFlags;
    bool hovering, sliderActive, mousePressed;
    int scrollbarElement, lastElement, ref;
    QPoint mousePos;
};

static QMotifPlusStylePrivate * singleton = 0;


static void drawMotifPlusShade(QPainter *p,
			       const QRect &r,
			       const QColorGroup &g,
			       bool sunken, bool mouseover,
			       const QBrush *fill = 0)
{
    QPen oldpen = p->pen();
    QPointArray a(4);
    QColor button =
	mouseover ? g.midlight() : g.button();
    QBrush brush =
	mouseover ? g.brush(QColorGroup::Midlight) : g.brush(QColorGroup::Button);
    int x, y, w, h;

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

    if (sunken) p->setPen(g.dark()); else p->setPen(g.light());
    a.setPoint(0, x, y + h - 1);
    a.setPoint(1, x, y);
    a.setPoint(2, x, y);
    a.setPoint(3, x + w - 1, y);
    p->drawLineSegments(a);

    if (sunken) p->setPen(Qt::black); else p->setPen(button);
    a.setPoint(0, x + 1, y + h - 2);
    a.setPoint(1, x + 1, y + 1);
    a.setPoint(2, x + 1, y + 1);
    a.setPoint(3, x + w - 2, y + 1);
    p->drawLineSegments(a);

    if (sunken) p->setPen(button); else p->setPen(g.dark());
    a.setPoint(0, x + 2, y + h - 2);
    a.setPoint(1, x + w - 2, y + h - 2);
    a.setPoint(2, x + w - 2, y + h - 2);
    a.setPoint(3, x + w - 2, y + 2);
    p->drawLineSegments(a);

    if (sunken) p->setPen(g.light()); else p->setPen(Qt::black);
    a.setPoint(0, x + 1, y + h - 1);
    a.setPoint(1, x + w - 1, y + h - 1);
    a.setPoint(2, x + w - 1, y + h - 1);
    a.setPoint(3, x + w - 1, y);
    p->drawLineSegments(a);

    if (fill)
	p->fillRect(x + 2, y + 2, w - 4, h - 4, *fill);
    else
	p->fillRect(x + 2, y + 2, w - 4, h - 4, brush);

    p->setPen(oldpen);
}


/*!
    \class QMotifPlusStyle qmotifplusstyle.h
    \brief The QMotifPlusStyle class provides a more sophisticated Motif-ish look and feel.

    \ingroup appearance

    This class implements a Motif-ish look and feel with the more
    sophisticated bevelling as used by the GIMP Toolkit (GTK+) for
    Unix/X11.
*/

/*!
    Constructs a QMotifPlusStyle

    If \a hoveringHighlight is TRUE (the default), then the style will
    not highlight push buttons, checkboxes, radiobuttons, comboboxes,
    scrollbars or sliders.
*/
QMotifPlusStyle::QMotifPlusStyle(bool hoveringHighlight) : QMotifStyle(TRUE)
{
    if ( !singleton )
        singleton = new QMotifPlusStylePrivate;
    else
        singleton->ref++;

    useHoveringHighlight = hoveringHighlight;
}

/*! \reimp */
QMotifPlusStyle::~QMotifPlusStyle()
{
    if ( singleton && singleton->ref-- <= 0) {
        delete singleton;
        singleton = 0;
    }
}


/*! \reimp */
void QMotifPlusStyle::polish(QPalette &)
{
}


/*! \reimp */
void QMotifPlusStyle::polish(QStyleControlElementData ceData, ControlElementFlags elementFlags, void *ptr)
{
    if (ceData.widgetObjectTypes.contains("QWidget")) {
#ifndef QT_NO_FRAME
        if ((ceData.widgetObjectTypes.contains("QFrame")) && (ceData.frameStyle == QFrame::Panel)) {
            widgetActionRequest(ceData, elementFlags, ptr, WAR_FrameSetStyle, QStyleWidgetActionRequestData(QFrame::WinPanel));
        }
#endif

#ifndef QT_NO_MENUBAR
        if ((ceData.widgetObjectTypes.contains("QMenuBar")) && (ceData.frameStyle != QFrame::NoFrame)) {
            widgetActionRequest(ceData, elementFlags, ptr, WAR_FrameSetStyle, QStyleWidgetActionRequestData(QFrame::StyledPanel | QFrame::Raised));
        }
#endif

#ifndef QT_NO_TOOLBAR
        if (ceData.widgetObjectTypes.contains("QToolBar")) {
            widgetActionRequest(ceData, elementFlags, ptr, WAR_SetLayoutMargin, QStyleWidgetActionRequestData(2));
        }
#endif
    }
    if (useHoveringHighlight) {
	if ((ceData.widgetObjectTypes.contains("QButton")) || (ceData.widgetObjectTypes.contains("QComboBox"))) {
	    installObjectEventHandler(ceData, elementFlags, ptr, this);
	}

	if ((ceData.widgetObjectTypes.contains("QScrollBar")) || (ceData.widgetObjectTypes.contains("QSlider"))) {
	    widgetActionRequest(ceData, elementFlags, ptr, WAR_EnableMouseTracking);
	    installObjectEventHandler(ceData, elementFlags, ptr, this);
	}
    }

    QMotifStyle::polish(ceData, elementFlags, ptr);
}


/*! \reimp */
void QMotifPlusStyle::unPolish(QStyleControlElementData ceData, ControlElementFlags elementFlags, void *ptr)
{
    removeObjectEventHandler(ceData, elementFlags, ptr, this);
    QMotifStyle::unPolish(ceData, elementFlags, ptr);
}


/*! \reimp */
void QMotifPlusStyle::applicationPolish(QStyleControlElementData, ControlElementFlags, void *)
{
}


/*! \reimp */
void QMotifPlusStyle::applicationUnPolish(QStyleControlElementData, ControlElementFlags, void *)
{
}


/*! \reimp */
int QMotifPlusStyle::pixelMetric(PixelMetric metric, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *widget) const
{
    int ret;

    switch (metric) {
    case PM_ScrollBarExtent:
	ret = 15;
	break;

    case PM_ButtonDefaultIndicator:
	ret = 5;
	break;

    case PM_ButtonMargin:
	ret = 4;
	break;

    case PM_SliderThickness:
	ret = 15;
	break;

    case PM_IndicatorWidth:
    case PM_IndicatorHeight:
	ret = 10;
	break;

    case PM_ExclusiveIndicatorWidth:
    case PM_ExclusiveIndicatorHeight:
	ret = 11;
	break;

    default:
	ret = QMotifStyle::pixelMetric(metric, ceData, elementFlags, widget);
	break;
    }

    return ret;
}


/*! \reimp */
void QMotifPlusStyle::drawPrimitive( PrimitiveElement pe,
				     QPainter *p,
				     QStyleControlElementData ceData,
				     ControlElementFlags elementFlags,
				     const QRect &r,
				     const QColorGroup &cg,
				     SFlags flags,
				     const QStyleOption& opt ) const
{
    switch (pe) {
    case PE_HeaderSection:

    case PE_ButtonCommand:
    case PE_ButtonBevel:
    case PE_ButtonTool:
	if (flags & (Style_Down | Style_On | Style_Raised | Style_Sunken))
	    drawMotifPlusShade( p, r, cg, bool(flags & (Style_Down | Style_On)),
				bool(flags & Style_MouseOver));
	else if (flags & Style_MouseOver)
	    p->fillRect(r, cg.brush(QColorGroup::Midlight));
	else
	    p->fillRect(r, cg.brush(QColorGroup::Button));
	break;

    case PE_Panel:
    case PE_PanelPopup:
    case PE_PanelMenuBar:
    case PE_PanelDockWindow:
	if ( opt.lineWidth() )
	    drawMotifPlusShade( p, r, cg, (flags & Style_Sunken), (flags & Style_MouseOver));
	else if ( flags & Style_MouseOver )
	    p->fillRect(r, cg.brush(QColorGroup::Midlight));
	else
	    p->fillRect(r, cg.brush(QColorGroup::Button));
	break;

    case PE_SpinWidgetUp:
	drawPrimitive(PE_ArrowUp, p, ceData, elementFlags, r, cg, flags, opt);
	break;

    case PE_SpinWidgetDown:
	drawPrimitive(PE_ArrowDown, p, ceData, elementFlags, r, cg, flags, opt);
	break;

    case PE_Indicator:
	{
	    QBrush fill;
	    if (flags & Style_On)
		fill = cg.brush(QColorGroup::Mid);
	    else if (flags & Style_MouseOver)
		fill = cg.brush(QColorGroup::Midlight);
	    else
		fill = cg.brush(QColorGroup::Button);

	    if (flags & Style_NoChange) {
		qDrawPlainRect(p, r, cg.text(), 1, &fill);
		p->drawLine(r.topRight(), r.bottomLeft());
	    } else
		drawMotifPlusShade(p, r, cg, (flags & Style_On),
				   (flags & Style_MouseOver), &fill);
	    break;
	}

    case PE_ExclusiveIndicator:
	{
	    QPen oldpen =  p->pen();
	    QPointArray thick(8);
	    QPointArray thin(4);
	    QColor button = ((flags & Style_MouseOver) ? cg.midlight() : cg.button());
	    QBrush brush = ((flags & Style_MouseOver) ?
			    cg.brush(QColorGroup::Midlight) :
			    cg.brush(QColorGroup::Button));
	    int x, y, w, h;
	    r.rect(&x, &y, &w, &h);

	    p->fillRect(x, y, w, h, brush);


	    if (flags & Style_On) {
		thick.setPoint(0, x, y + (h / 2));
		thick.setPoint(1, x + (w / 2), y);
		thick.setPoint(2, x + 1, y + (h / 2));
		thick.setPoint(3, x + (w / 2), y + 1);
		thick.setPoint(4, x + (w / 2), y);
		thick.setPoint(5, x + w - 1, y + (h / 2));
		thick.setPoint(6, x + (w / 2), y + 1);
		thick.setPoint(7, x + w - 2, y + (h / 2));
		p->setPen(cg.dark());
		p->drawLineSegments(thick);

		thick.setPoint(0, x + 1, y + (h / 2) + 1);
		thick.setPoint(1, x + (w / 2), y + h - 1);
		thick.setPoint(2, x + 2, y + (h / 2) + 1);
		thick.setPoint(3, x + (w / 2), y + h - 2);
		thick.setPoint(4, x + (w / 2), y + h - 1);
		thick.setPoint(5, x + w - 2, y + (h / 2) + 1);
		thick.setPoint(6, x + (w / 2), y + h - 2);
		thick.setPoint(7, x + w - 3, y + (h / 2) + 1);
		p->setPen(cg.light());
		p->drawLineSegments(thick);

		thin.setPoint(0, x + 2, y + (h / 2));
		thin.setPoint(1, x + (w / 2), y + 2);
		thin.setPoint(2, x + (w / 2), y + 2);
		thin.setPoint(3, x + w - 3, y + (h / 2));
		p->setPen(Qt::black);
		p->drawLineSegments(thin);

		thin.setPoint(0, x + 3, y + (h / 2) + 1);
		thin.setPoint(1, x + (w / 2), y + h - 3);
		thin.setPoint(2, x + (w / 2), y + h - 3);
		thin.setPoint(3, x + w - 4, y + (h / 2) + 1);
		p->setPen(cg.mid());
		p->drawLineSegments(thin);
	    } else {
		thick.setPoint(0, x, y + (h / 2));
		thick.setPoint(1, x + (w / 2), y);
		thick.setPoint(2, x + 1, y + (h / 2));
		thick.setPoint(3, x + (w / 2), y + 1);
		thick.setPoint(4, x + (w / 2), y);
		thick.setPoint(5, x + w - 1, y + (h / 2));
		thick.setPoint(6, x + (w / 2), y + 1);
		thick.setPoint(7, x + w - 2, y + (h / 2));
		p->setPen(cg.light());
		p->drawLineSegments(thick);

		thick.setPoint(0, x + 2, y + (h / 2) + 1);
		thick.setPoint(1, x + (w / 2), y + h - 2);
		thick.setPoint(2, x + 3, y + (h / 2) + 1);
		thick.setPoint(3, x + (w / 2), y + h - 3);
		thick.setPoint(4, x + (w / 2), y + h - 2);
		thick.setPoint(5, x + w - 3, y + (h / 2) + 1);
		thick.setPoint(6, x + (w / 2), y + h - 3);
		thick.setPoint(7, x + w - 4, y + (h / 2) + 1);
		p->setPen(cg.dark());
		p->drawLineSegments(thick);

		thin.setPoint(0, x + 2, y + (h / 2));
		thin.setPoint(1, x + (w / 2), y + 2);
		thin.setPoint(2, x + (w / 2), y + 2);
		thin.setPoint(3, x + w - 3, y + (h / 2));
		p->setPen(button);
		p->drawLineSegments(thin);

		thin.setPoint(0, x + 1, y + (h / 2) + 1);
		thin.setPoint(1, x + (w / 2), y + h - 1);
		thin.setPoint(2, x + (w / 2), y + h - 1);
		thin.setPoint(3, x + w - 2, y + (h / 2) + 1);
		p->setPen(Qt::black);
		p->drawLineSegments(thin);
	    }

	    p->setPen(oldpen);
	    break;
	}



    case PE_ArrowDown:
    case PE_ArrowLeft:
    case PE_ArrowRight:
    case PE_ArrowUp:
	{
	    QPen oldpen = p->pen();
	    QBrush oldbrush = p->brush();
	    QPointArray poly(3);
	    QColor button = (flags & Style_MouseOver) ? cg.midlight() : cg.button();
	    bool down = (flags & Style_Down);
	    int x, y, w, h;
	    r.rect(&x, &y, &w, &h);

	    p->save();
	    p->setBrush(button);

	    switch (pe) {
	    case PE_ArrowUp:
		{
		    poly.setPoint(0, x + (w / 2), y );
		    poly.setPoint(1, x, y + h - 1);
		    poly.setPoint(2, x + w - 1, y + h - 1);
		    p->drawPolygon(poly);

		    if (down)
			p->setPen(button);
		    else
			p->setPen(cg.dark());
		    p->drawLine(x + 1, y + h - 2, x + w - 2, y + h - 2);

		    if (down)
			p->setPen(cg.light());
		    else
			p->setPen(black);
		    p->drawLine(x, y + h - 1, x + w - 1, y + h - 1);

		    if (down)
			p->setPen(button);
		    else
			p->setPen(cg.dark());
		    p->drawLine(x + w - 2, y + h - 1, x + (w / 2), y + 1);

		    if (down)
			p->setPen(cg.light());
		    else
			p->setPen(black);
		    p->drawLine(x + w - 1, y + h - 1, x + (w / 2), y);

		    if (down)
			p->setPen(black);
		    else
			p->setPen(button);
		    p->drawLine(x + (w / 2), y + 1, x + 1, y + h - 1);

		    if (down)
			p->setPen(cg.dark());
		    else
			p->setPen(cg.light());
		    p->drawLine(x + (w / 2), y, x, y + h - 1);
		    break;
		}

	    case PE_ArrowDown:
		{
		    poly.setPoint(0, x + w - 1, y);
		    poly.setPoint(1, x, y);
		    poly.setPoint(2, x + (w / 2), y + h - 1);
		    p->drawPolygon(poly);

		    if (down)
			p->setPen(black);
		    else
			p->setPen(button);
		    p->drawLine(x + w - 2, y + 1, x + 1, y + 1);

		    if (down)
			p->setPen(cg.dark());
		    else
			p->setPen(cg.light());
		    p->drawLine(x + w - 1, y, x, y);

		    if (down)
			p->setPen(black);
		    else
			p->setPen(button);
		    p->drawLine(x + 1, y, x + (w / 2), y + h - 2);

		    if (down)
			p->setPen(cg.dark());
		    else
			p->setPen(cg.light());
		    p->drawLine(x, y, x + (w / 2), y + h - 1);

		    if (down)
			p->setPen(button);
		    else
			p->setPen(cg.dark());
		    p->drawLine(x + (w / 2), y + h - 2, x + w - 2, y);

		    if (down)
			p->setPen(cg.light());
		    else
			p->setPen(black);
		    p->drawLine(x + (w / 2), y + h - 1, x + w - 1, y);
		    break;
		}

	    case PE_ArrowLeft:
		{
		    poly.setPoint(0, x, y + (h / 2));
		    poly.setPoint(1, x + w - 1, y + h - 1);
		    poly.setPoint(2, x + w - 1, y);
		    p->drawPolygon(poly);

		    if (down)
			p->setPen(button);
		    else
			p->setPen(cg.dark());
		    p->drawLine(x + 1, y + (h / 2), x + w - 1, y + h - 1);

		    if (down)
			p->setPen(cg.light());
		    else
			p->setPen(black);
		    p->drawLine(x, y + (h / 2), x + w - 1, y + h - 1);

		    if (down)
			p->setPen(button);
		    else
			p->setPen(cg.dark());
		    p->drawLine(x + w - 2, y + h - 1, x + w - 2, y + 1);

		    if (down)
			p->setPen(cg.light());
		    else
			p->setPen(black);
		    p->drawLine(x + w - 1, y + h - 1, x + w - 1, y);

		    if (down)
			p->setPen(black);
		    else
			p->setPen(button);
		    p->drawLine(x + w - 1, y + 1, x + 1, y + (h / 2));

		    if (down)
			p->setPen(cg.dark());
		    else
			p->setPen(cg.light());
		    p->drawLine(x + w - 1, y, x, y + (h / 2));
		    break;
		}

	    case PE_ArrowRight:
		{
		    poly.setPoint(0, x + w - 1, y + (h / 2));
		    poly.setPoint(1, x, y);
		    poly.setPoint(2, x, y + h - 1);
		    p->drawPolygon(poly);

		    if (down)
			p->setPen(black);
		    else
			p->setPen(button);
		    p->drawLine( x + w - 1, y + (h / 2), x + 1, y + 1);

		    if (down)
			p->setPen(cg.dark());
		    else
			p->setPen(cg.light());
		    p->drawLine(x + w - 1, y + (h / 2), x, y);

		    if (down)
			p->setPen(black);
		    else
			p->setPen(button);
		    p->drawLine(x + 1, y + 1, x + 1, y + h - 2);

		    if (down)
			p->setPen(cg.dark());
		    else
			p->setPen(cg.light());
		    p->drawLine(x, y, x, y + h - 1);

		    if (down)
			p->setPen(button);
		    else
			p->setPen(cg.dark());
		    p->drawLine(x + 1, y + h - 2, x + w - 1, y + (h / 2));

		    if (down)
			p->setPen(cg.light());
		    else
			p->setPen(black);
		    p->drawLine(x, y + h - 1, x + w - 1, y + (h / 2));
		    break;
		}

	    default:
		break;
	    }

	    p->restore();
	    p->setBrush(oldbrush);
	    p->setPen(oldpen);
   	    break;
	}

    default:
	QMotifStyle::drawPrimitive(pe, p, ceData, elementFlags, r, cg, flags, opt);
	break;
    }
}


/*! \reimp
*/
void QMotifPlusStyle::drawControl( ControlElement element,
				   QPainter *p,
				   QStyleControlElementData ceData,
				   ControlElementFlags elementFlags,
				   const QRect &r,
				   const QColorGroup &cg,
				   SFlags flags,
				   const QStyleOption& opt,
				   const QWidget *widget) const
{
    if (widget == singleton->hoverWidget)
	flags |= Style_MouseOver;

    switch (element) {
    case CE_PushButton:
	{
#ifndef QT_NO_PUSHBUTTON
	    QRect br = r;
	    int dbi = pixelMetric(PM_ButtonDefaultIndicator, ceData, elementFlags, widget);

	    if ((elementFlags & CEF_IsDefault) || (elementFlags & CEF_AutoDefault)) {
		if (elementFlags & CEF_IsDefault)
		    drawMotifPlusShade(p, br, cg, TRUE, FALSE,
				       &cg.brush(QColorGroup::Background));

		br.setCoords(br.left()   + dbi,
			     br.top()    + dbi,
			     br.right()  - dbi,
			     br.bottom() - dbi);
	    }

	    if (flags & Style_HasFocus)
		br.addCoords(1, 1, -1, -1);
	    p->save();
	    p->setBrushOrigin( -ceData.bgOffset.x(),
			       -ceData.bgOffset.y() );
	    drawPrimitive(PE_ButtonCommand, p, ceData, elementFlags, br, cg, flags);
	    p->restore();
#endif
	    break;
	}

    case CE_CheckBoxLabel:
	{
#ifndef QT_NO_CHECKBOX
	    if (flags & Style_MouseOver) {
		QRegion r(ceData.rect);
		r -= visualRect(subRect(SR_CheckBoxIndicator, ceData, elementFlags, widget), ceData, elementFlags);
		p->setClipRegion(r);
		p->fillRect(ceData.rect, cg.brush(QColorGroup::Midlight));
		p->setClipping(FALSE);
	    }

	    int alignment = QApplication::reverseLayout() ? AlignRight : AlignLeft;
	    drawItem(p, r, alignment | AlignVCenter | ShowPrefix, cg,
		     flags & Style_Enabled, (ceData.fgPixmap.isNull())?NULL:&ceData.fgPixmap, ceData.text);

	    if (elementFlags & CEF_HasFocus) {
		QRect fr = visualRect(subRect(SR_CheckBoxFocusRect, ceData, elementFlags, widget), ceData, elementFlags);
		drawPrimitive(PE_FocusRect, p, ceData, elementFlags, fr, cg, flags);
	    }
#endif
	    break;
	}

    case CE_RadioButtonLabel:
	{
#ifndef QT_NO_RADIOBUTTON
	    if (flags & Style_MouseOver) {
		QRegion r(ceData.rect);
		r -= visualRect(subRect(SR_RadioButtonIndicator, ceData, elementFlags, widget), ceData, elementFlags);
		p->setClipRegion(r);
		p->fillRect(ceData.rect, cg.brush(QColorGroup::Midlight));
		p->setClipping(FALSE);
	    }

	    int alignment = QApplication::reverseLayout() ? AlignRight : AlignLeft;
	    drawItem(p, r, alignment | AlignVCenter | ShowPrefix, cg,
		     flags & Style_Enabled, (ceData.fgPixmap.isNull())?NULL:&ceData.fgPixmap, ceData.text);

	    if (elementFlags & CEF_HasFocus) {
		QRect fr = visualRect(subRect(SR_RadioButtonFocusRect, ceData, elementFlags, widget), ceData, elementFlags);
		drawPrimitive(PE_FocusRect, p, ceData, elementFlags, fr, cg, flags);
	    }
#endif
	    break;
	}

    case CE_MenuBarItem:
	{
#ifndef QT_NO_MENUDATA
	    if (opt.isDefault())
		break;

	    QMenuItem *mi = opt.menuItem();
	    if ((flags & Style_Enabled) && (flags & Style_Active))
		drawMotifPlusShade(p, r, cg, FALSE, TRUE);
	    else
		p->fillRect(r, cg.button());

	    drawItem(p, r, AlignCenter | ShowPrefix | DontClip | SingleLine,
		     cg, flags & Style_Enabled, mi->pixmap(), mi->text(), -1,
		     &cg.buttonText());
#endif
	    break;
	}


#ifndef QT_NO_POPUPMENU
    case CE_PopupMenuItem:
	{
	    if (! widget || opt.isDefault())
		break;

	    QMenuItem *mi = opt.menuItem();
	    if ( !mi )
		break;

	    int tab = opt.tabWidth();
	    int maxpmw = opt.maxIconWidth();
	    bool dis = ! (flags & Style_Enabled);
	    bool checkable = (elementFlags & CEF_IsCheckable);
	    bool act = flags & Style_Active;
	    int x, y, w, h;

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

	    if (checkable)
		maxpmw = QMAX(maxpmw, 15);

	    int checkcol = maxpmw;

	    if (mi && mi->isSeparator()) {
		p->setPen( cg.dark() );
		p->drawLine( x, y, x+w, y );
		p->setPen( cg.light() );
		p->drawLine( x, y+1, x+w, y+1 );
		return;
	    }

	    if ( act && !dis )
		drawMotifPlusShade(p, QRect(x, y, w, h), cg, FALSE, TRUE);
	    else
		p->fillRect(x, y, w, h, cg.brush( QColorGroup::Button ));

	    if ( !mi )
		return;

	    QRect vrect = visualRect( QRect( x+2, y+2, checkcol, h-2 ), r );
	    if ( mi->isChecked() ) {
		if ( mi->iconSet() ) {
		    qDrawShadePanel( p, vrect.x(), y+2, checkcol, h-2*2,
				     cg, TRUE, 1, &cg.brush( QColorGroup::Midlight ) );
		}
	    } else if ( !act ) {
		p->fillRect(vrect,
			    cg.brush( QColorGroup::Button ));
	    }

	    if ( mi->iconSet() ) {              // draw iconset
		QIconSet::Mode mode = (!dis) ? QIconSet::Normal : QIconSet::Disabled;

		if (act && !dis)
		    mode = QIconSet::Active;

		QPixmap pixmap;
		if ( checkable && mi->isChecked() )
		    pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode,
						    QIconSet::On );
		else
		    pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode );

		int pixw = pixmap.width();
		int pixh = pixmap.height();

		QRect pmr( 0, 0, pixw, pixh );

		pmr.moveCenter(vrect.center());

		p->setPen( cg.text() );
		p->drawPixmap( pmr.topLeft(), pixmap );

	    } else if (checkable) {
		if (mi->isChecked()) {
		    SFlags cflags = Style_Default;
		    if (! dis)
			cflags |= Style_Enabled;
		    if (act)
			cflags |= Style_On;

		    drawPrimitive(PE_CheckMark, p, ceData, elementFlags, vrect, cg, cflags);
		}
	    }

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

	    QColor discol;
	    if (dis) {
		discol = cg.text();
		p->setPen( discol );
	    }

	    vrect = visualRect( QRect(x + checkcol + 4, y + 2,
				      w - checkcol - tab - 3, h - 4), r );
	    if (mi->custom()) {
		p->save();
		mi->custom()->paint(p, cg, act, !dis, vrect.x(), y + 2,
				    w - checkcol - tab - 3, h - 4);
		p->restore();
	    }

	    QString s = mi->text();
	    if ( !s.isNull() ) {                        // draw text
		int t = s.find( '\t' );
		int m = 2;
		int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine;
		text_flags |= (QApplication::reverseLayout() ? AlignRight : AlignLeft );
		if ( t >= 0 ) {                         // draw tab text
		    QRect vr = visualRect( QRect(x+w-tab-2-2,
						 y+m, tab, h-2*m), r );
		    p->drawText( vr.x(),
				 y+m, tab, h-2*m, text_flags, s.mid( t+1 ) );
		}
		p->drawText(vrect.x(), y + 2, w - checkcol -tab - 3, h - 4,
			    text_flags, s, t);
	    } else if (mi->pixmap()) {
		QPixmap *pixmap = mi->pixmap();

		if (pixmap->depth() == 1) p->setBackgroundMode(OpaqueMode);
		QRect vr = visualRect( QRect( x + checkcol + 2, y + 2, w - checkcol - 1, h - 4 ), r );
		p->drawPixmap(vr.x(), y + 2, *pixmap);
		if (pixmap->depth() == 1) p->setBackgroundMode(TransparentMode);
	    }

	    if (mi->popup()) {
		int hh = h / 2;
		QStyle::PrimitiveElement arrow = (QApplication::reverseLayout() ? PE_ArrowLeft : PE_ArrowRight);
		vrect = visualRect( QRect(x + w - hh - 6, y + (hh / 2), hh, hh), r );
		drawPrimitive(arrow, p,
			      ceData, elementFlags,
			      vrect, cg,
			      ((act && !dis) ?
			       Style_Down : Style_Default) |
			      ((!dis) ? Style_Enabled : Style_Default));
	    }
	    break;
	}
#endif // QT_NO_POPUPMENU

    case CE_TabBarTab:
	{
#ifndef QT_NO_TABBAR
	    bool selected = flags & Style_Selected;

	    QColorGroup g = ceData.colorGroup;
	    QPen oldpen = p->pen();
	    QRect fr(r);

	    if (! selected) {
		if (ceData.tabBarData.shape == QTabBar::RoundedAbove ||
		    ceData.tabBarData.shape == QTabBar::TriangularAbove) {
		    fr.setTop(fr.top() + 2);
		} else {
		    fr.setBottom(fr.bottom() - 2);
		}
	    }

	    fr.setWidth(fr.width() - 3);

	    p->fillRect(fr.left() + 1, fr.top() + 1, fr.width() - 2, fr.height() - 2,
			(selected) ? cg.brush(QColorGroup::Button)
			: cg.brush(QColorGroup::Mid));

	    if (ceData.tabBarData.shape == QTabBar::RoundedAbove) {
		// "rounded" tabs on top
		fr.setBottom(fr.bottom() - 1);

		p->setPen(g.light());
		p->drawLine(fr.left(), fr.top() + 1,
			    fr.left(), fr.bottom() - 1);
		p->drawLine(fr.left() + 1, fr.top(),
			    fr.right() - 1, fr.top());
		if (! selected)
		    p->drawLine(fr.left(), fr.bottom(),
				fr.right() + 3, fr.bottom());

		if (fr.left() == 0)
		    p->drawLine(fr.left(), fr.bottom(),
				fr.left(), fr.bottom() + 1);

		p->setPen(g.dark());
		p->drawLine(fr.right() - 1, fr.top() + 2,
			    fr.right() - 1, fr.bottom() - 1);

		p->setPen(black);
		p->drawLine(fr.right(), fr.top() + 1,
			    fr.right(), fr.bottom() - 1);
	    } else if (ceData.tabBarData.shape == QTabBar::RoundedBelow) {
		// "rounded" tabs on bottom
		fr.setTop(fr.top() + 1);

		p->setPen(g.dark());
		p->drawLine(fr.right() + 3, fr.top() - 1,
			    fr.right() - 1, fr.top() - 1);
		p->drawLine(fr.right() - 1, fr.top(),
			    fr.right() - 1, fr.bottom() - 2);
		p->drawLine(fr.right() - 1, fr.bottom() - 2,
			    fr.left() + 2,  fr.bottom() - 2);
		if (! selected) {
		    p->drawLine(fr.right(), fr.top() - 1,
				fr.left() + 1,  fr.top() - 1);

		    if (fr.left() != 0)
			p->drawPoint(fr.left(), fr.top() - 1);
		}

		p->setPen(black);
		p->drawLine(fr.right(), fr.top(),
			    fr.right(), fr.bottom() - 2);
		p->drawLine(fr.right() - 1, fr.bottom() - 1,
			    fr.left(), fr.bottom() - 1);
		if (! selected)
		    p->drawLine(fr.right() + 3, fr.top(),
				fr.left(), fr.top());
		else
		    p->drawLine(fr.right() + 3, fr.top(),
				fr.right(), fr.top());

		p->setPen(g.light());
		p->drawLine(fr.left(), fr.top() + 1,
			    fr.left(), fr.bottom() - 2);

		if (selected) {
		    p->drawPoint(fr.left(), fr.top());
		    if (fr.left() == 0)
			p->drawPoint(fr.left(), fr.top() - 1);

		    p->setPen(g.button());
		    p->drawLine(fr.left() + 2, fr.top() - 1,
				fr.left() + 1, fr.top() - 1);
		}
	    } else
		// triangular drawing code
		QMotifStyle::drawControl(element, p, ceData, elementFlags, r, cg, flags, opt, widget);

	    p->setPen(oldpen);
#endif
	    break;
	}

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


/*! \reimp
*/
QRect QMotifPlusStyle::subRect(SubRect r, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *widget) const
{
    QRect rect;

    switch (r) {
    case SR_PushButtonFocusRect:
	{
#ifndef QT_NO_PUSHBUTTON
	    int dfi = pixelMetric(PM_ButtonDefaultIndicator, ceData, elementFlags, widget);

	    rect = ceData.rect;
	    if ((elementFlags & CEF_IsDefault) || (elementFlags & CEF_AutoDefault))
		rect.addCoords(dfi, dfi, -dfi, -dfi);
#endif
	    break;
	}

    case SR_CheckBoxIndicator:
	{
	    int h = pixelMetric( PM_IndicatorHeight, ceData, elementFlags );
	    rect.setRect(( ceData.rect.height() - h ) / 2,
			 ( ceData.rect.height() - h ) / 2,
			 pixelMetric( PM_IndicatorWidth, ceData, elementFlags ), h );
	    break;
	}

    case SR_RadioButtonIndicator:
	{
	    int h = pixelMetric( PM_ExclusiveIndicatorHeight, ceData, elementFlags );
	    rect.setRect( ( ceData.rect.height() - h ) / 2,
			  ( ceData.rect.height() - h ) / 2,
			  pixelMetric( PM_ExclusiveIndicatorWidth, ceData, elementFlags ), h );
	    break;
	}

    case SR_CheckBoxFocusRect:
    case SR_RadioButtonFocusRect:
       	rect = ceData.rect;
	break;

    case SR_ComboBoxFocusRect:
	{
#ifndef QT_NO_COMBOBOX
	    if (elementFlags & CEF_IsEditable) {
		rect = querySubControlMetrics(CC_ComboBox, ceData, elementFlags,
					      SC_ComboBoxEditField, QStyleOption::Default, widget);
		rect.addCoords(-3, -3, 3, 3);
	    } else
		rect = ceData.rect;
#endif
	    break;
	}

    case SR_SliderFocusRect:
	{
#ifndef QT_NO_SLIDER
	    int tickOffset = pixelMetric( PM_SliderTickmarkOffset, ceData, elementFlags, widget );
	    int thickness = pixelMetric( PM_SliderControlThickness, ceData, elementFlags, widget );
	    int x, y, wi, he;

	    if ( ceData.orientation == Horizontal ) {
		x = 0;
		y = tickOffset;
		wi = ceData.rect.width();
		he = thickness;
	    } else {
		x = tickOffset;
		y = 0;
		wi = thickness;
		he = ceData.rect.height();
	    }

	    rect.setRect(x, y, wi, he);
#endif
	    break;
	}

    default:
	rect = QMotifStyle::subRect(r, ceData, elementFlags, widget);
	break;
    }

    return rect;
}


/*! \reimp */
void QMotifPlusStyle::drawComplexControl(ComplexControl control,
			    QPainter *p,
			    QStyleControlElementData ceData,
			    ControlElementFlags elementFlags,
			    const QRect &r,
			    const QColorGroup &cg,
			    SFlags flags,
			    SCFlags controls,
			    SCFlags active,
			    const QStyleOption& opt,
			    const QWidget *widget ) const
{
    if (widget == singleton->hoverWidget)
	flags |= Style_MouseOver;

    switch (control) {
    case CC_ScrollBar:
	{
#ifndef QT_NO_SCROLLBAR
	    QRect addline, subline, addpage, subpage, slider, first, last;
	    bool maxedOut = (ceData.minSteps == ceData.maxSteps);

	    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);

	    bool skipUpdate = FALSE;
	    if (singleton->hovering) {
		if (addline.contains(singleton->mousePos)) {
		    skipUpdate =
			(singleton->scrollbarElement == SC_ScrollBarAddLine);
		    singleton->scrollbarElement = SC_ScrollBarAddLine;
		} else if (subline.contains(singleton->mousePos)) {
		    skipUpdate =
			(singleton->scrollbarElement == SC_ScrollBarSubLine);
		    singleton->scrollbarElement = SC_ScrollBarSubLine;
		} else if (slider.contains(singleton->mousePos)) {
		    skipUpdate =
			(singleton->scrollbarElement == SC_ScrollBarSlider);
		    singleton->scrollbarElement = SC_ScrollBarSlider;
		} else {
		    skipUpdate =
			(singleton->scrollbarElement == 0);
		    singleton->scrollbarElement = 0;
		}
	    } else
		singleton->scrollbarElement = 0;

	    if (skipUpdate && singleton->scrollbarElement == singleton->lastElement)
		break;

	    singleton->lastElement = singleton->scrollbarElement;

	    if (controls == (SC_ScrollBarAddLine | SC_ScrollBarSubLine |
			     SC_ScrollBarAddPage | SC_ScrollBarSubPage |
			     SC_ScrollBarFirst | SC_ScrollBarLast | SC_ScrollBarSlider))
		drawMotifPlusShade(p, widget->rect(), cg, TRUE, FALSE,
				   &cg.brush(QColorGroup::Mid));

	    if ((controls & SC_ScrollBarSubLine) && subline.isValid())
		drawPrimitive(PE_ScrollBarSubLine, p, ceData, elementFlags, subline, cg,
			      ((active == SC_ScrollBarSubLine ||
				singleton->scrollbarElement == SC_ScrollBarSubLine) ?
			       Style_MouseOver: Style_Default) |
			      ((maxedOut) ? Style_Default : Style_Enabled) |
			      ((active == SC_ScrollBarSubLine) ?
			       Style_Down : Style_Default) |
			      ((ceData.orientation == Qt::Horizontal) ?
			       Style_Horizontal : Style_Default));
	    if ((controls & SC_ScrollBarAddLine) && addline.isValid())
		drawPrimitive(PE_ScrollBarAddLine, p, ceData, elementFlags, addline, cg,
			      ((active == SC_ScrollBarAddLine ||
				singleton->scrollbarElement == SC_ScrollBarAddLine) ?
			       Style_MouseOver: Style_Default) |
			      ((maxedOut) ? Style_Default : Style_Enabled) |
			      ((active == SC_ScrollBarAddLine) ?
			       Style_Down : Style_Default) |
			      ((ceData.orientation == Qt::Horizontal) ?
			       Style_Horizontal : Style_Default));
	    if ((controls & SC_ScrollBarSubPage) && subpage.isValid())
		drawPrimitive(PE_ScrollBarSubPage, p, ceData, elementFlags, subpage, cg,
			      ((maxedOut) ? Style_Default : Style_Enabled) |
			      ((active == SC_ScrollBarSubPage) ?
			       Style_Down : Style_Default) |
			      ((ceData.orientation == Qt::Horizontal) ?
			       Style_Horizontal : Style_Default));
	    if ((controls & SC_ScrollBarAddPage) && addpage.isValid())
		drawPrimitive(PE_ScrollBarAddPage, p, ceData, elementFlags, addpage, cg,
			      ((maxedOut) ? Style_Default : Style_Enabled) |
			      ((active == SC_ScrollBarAddPage) ?
			       Style_Down : Style_Default) |
			      ((ceData.orientation == Qt::Horizontal) ?
			       Style_Horizontal : Style_Default));
	    if ((controls & SC_ScrollBarFirst) && first.isValid())
		drawPrimitive(PE_ScrollBarFirst, p, ceData, elementFlags, first, cg,
			      ((maxedOut) ? Style_Default : Style_Enabled) |
			      ((active == SC_ScrollBarFirst) ?
			       Style_Down : Style_Default) |
			      ((ceData.orientation == Qt::Horizontal) ?
			       Style_Horizontal : Style_Default));
	    if ((controls & SC_ScrollBarLast) && last.isValid())
		drawPrimitive(PE_ScrollBarLast, p, ceData, elementFlags, last, cg,
			      ((maxedOut) ? Style_Default : Style_Enabled) |
			      ((active == SC_ScrollBarLast) ?
			       Style_Down : Style_Default) |
			      ((ceData.orientation == Qt::Horizontal) ?
			       Style_Horizontal : Style_Default));
	    if ((controls & SC_ScrollBarSlider) && slider.isValid()) {
		drawPrimitive(PE_ScrollBarSlider, p, ceData, elementFlags, slider, cg,
			      ((active == SC_ScrollBarSlider ||
				singleton->scrollbarElement == SC_ScrollBarSlider) ?
			       Style_MouseOver: Style_Default) |
			      ((maxedOut) ? Style_Default : Style_Enabled) |
			      ((ceData.orientation == Qt::Horizontal) ?
			       Style_Horizontal : Style_Default));

		// ### perhaps this should not be able to accept focus if maxedOut?
		if (elementFlags & CEF_HasFocus) {
		    QRect fr(slider.x() + 2, slider.y() + 2,
			     slider.width() - 5, slider.height() - 5);
		    drawPrimitive(PE_FocusRect, p, ceData, elementFlags, fr, cg, Style_Default);
		}
	    }
#endif
	    break;
	}

    case CC_ComboBox:
	{
#ifndef QT_NO_COMBOBOX
	    QRect editfield, arrow;
	    editfield =
		visualRect(querySubControlMetrics(CC_ComboBox,
						  ceData, elementFlags,
						  SC_ComboBoxEditField,
						  opt, widget), ceData, elementFlags);
	    arrow =
		visualRect(querySubControlMetrics(CC_ComboBox,
						  ceData, elementFlags,
						  SC_ComboBoxArrow,
						  opt, widget), ceData, elementFlags);

	    if (elementFlags & CEF_IsEditable) {
		if (controls & SC_ComboBoxEditField && editfield.isValid()) {
		    editfield.addCoords(-3, -3, 3, 3);
		    if (elementFlags & CEF_HasFocus)
			editfield.addCoords(1, 1, -1, -1);
		    drawMotifPlusShade(p, editfield, cg, TRUE, FALSE,
				       ((elementFlags & CEF_IsEnabled) ?
					&cg.brush(QColorGroup::Base) :
					&cg.brush(QColorGroup::Background)));
		}

		if (controls & SC_ComboBoxArrow && arrow.isValid()) {
		    drawMotifPlusShade(p, arrow, cg, (active == SC_ComboBoxArrow),
				       (flags & Style_MouseOver));

		    int space = (r.height() - 13) / 2;
		    arrow.addCoords(space, space, -space, -space);

		    if (active == SC_ComboBoxArrow)
			flags |= Style_Sunken;
		    drawPrimitive(PE_ArrowDown, p, ceData, elementFlags, arrow, cg, flags);
		}
	    } else {
		if (controls & SC_ComboBoxEditField && editfield.isValid()) {
		    editfield.addCoords(-3, -3, 3, 3);
		    if (elementFlags & CEF_HasFocus)
			editfield.addCoords(1, 1, -1, -1);
		    drawMotifPlusShade(p, editfield, cg, FALSE,
				       (flags & Style_MouseOver));
		}

		if (controls & SC_ComboBoxArrow && arrow.isValid())
		    drawMotifPlusShade(p, arrow, cg, FALSE, (flags & Style_MouseOver));
	    }

	    if ((elementFlags & CEF_HasFocus) ||
		((elementFlags & CEF_IsEditable) && (ceData.comboBoxLineEditFlags & CEF_HasFocus))) {
		QRect fr = visualRect(subRect(SR_ComboBoxFocusRect, ceData, elementFlags, widget), ceData, elementFlags);
		drawPrimitive(PE_FocusRect, p, ceData, elementFlags, fr, cg, flags);
	    }
#endif
	    break;
	}

    case CC_SpinWidget:
	{
#ifndef QT_NO_SPINWIDGET
	    SFlags flags = Style_Default;

	    if (controls & SC_SpinWidgetFrame)
		drawMotifPlusShade(p, r, cg, TRUE, FALSE, &cg.brush(QColorGroup::Base));

	    if (controls & SC_SpinWidgetUp) {
		flags = Style_Enabled;
		if (active == SC_SpinWidgetUp )
		    flags |= Style_Down;

		PrimitiveElement pe;
		if ( ceData.spinWidgetData.buttonSymbols == QSpinWidget::PlusMinus )
		    pe = PE_SpinWidgetPlus;
		else
		    pe = PE_SpinWidgetUp;

		QRect re = ceData.spinWidgetData.upRect;
		QColorGroup ucg = ceData.spinWidgetData.upEnabled ? cg : ceData.palette.disabled();
		drawPrimitive(pe, p, ceData, elementFlags, re, ucg, flags);
	    }

	    if (controls & SC_SpinWidgetDown) {
		flags = Style_Enabled;
		if (active == SC_SpinWidgetDown )
		    flags |= Style_Down;

		PrimitiveElement pe;
		if ( ceData.spinWidgetData.buttonSymbols == QSpinWidget::PlusMinus )
		    pe = PE_SpinWidgetMinus;
		else
		    pe = PE_SpinWidgetDown;

		QRect re = ceData.spinWidgetData.downRect;
		QColorGroup dcg = ceData.spinWidgetData.downEnabled ? cg : ceData.palette.disabled();
		drawPrimitive(pe, p, ceData, elementFlags, re, dcg, flags);
	    }
#endif
	    break;
	}

    case CC_Slider:
	{
#ifndef QT_NO_SLIDER
	    bool mouseover = (flags & Style_MouseOver);

	    QRect groove = querySubControlMetrics(CC_Slider, ceData, elementFlags, SC_SliderGroove,
						  opt, widget),
		  handle = querySubControlMetrics(CC_Slider, ceData, elementFlags, SC_SliderHandle,
						  opt, widget);

	    if ((controls & SC_SliderGroove) && groove.isValid()) {
		drawMotifPlusShade(p, groove, cg, TRUE, FALSE,
				   &cg.brush(QColorGroup::Mid));

		if ( flags & Style_HasFocus ) {
		    QRect fr = subRect( SR_SliderFocusRect, ceData, elementFlags, widget );
		    drawPrimitive( PE_FocusRect, p, ceData, elementFlags, fr, cg, flags );
		}
	    }

	    if ((controls & SC_SliderHandle) && handle.isValid()) {
		if ((mouseover && handle.contains(singleton->mousePos)) ||
		    singleton->sliderActive)
		    flags |= Style_MouseOver;
		else
		    flags &= ~Style_MouseOver;
		drawPrimitive(PE_ButtonBevel, p, ceData, elementFlags, handle, cg, flags | Style_Raised);

		if ( ceData.orientation == Horizontal ) {
		    QCOORD mid = handle.x() + handle.width() / 2;
		    qDrawShadeLine( p, mid,  handle.y() + 1, mid ,
				    handle.y() + handle.height() - 3,
				    cg, TRUE, 1);
		} else {
		    QCOORD mid = handle.y() + handle.height() / 2;
		    qDrawShadeLine( p, handle.x() + 1, mid,
				    handle.x() + handle.width() - 3, mid,
				    cg, TRUE, 1);
		}
	    }

	    if (controls & SC_SliderTickmarks)
		QMotifStyle::drawComplexControl(control, p, ceData, elementFlags, r, cg, flags,
						SC_SliderTickmarks, active, opt, widget);
#endif
	    break;
	}

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


/*! \reimp
*/
QRect QMotifPlusStyle::querySubControlMetrics(ComplexControl control,
					      QStyleControlElementData ceData,
					      ControlElementFlags elementFlags,
					      SubControl subcontrol,
					      const QStyleOption& opt,
					      const QWidget *widget) const
{
    switch (control) {
    case CC_SpinWidget: {
	    int fw = pixelMetric( PM_SpinBoxFrameWidth, ceData, elementFlags, 0 );
	    QSize bs;
	    bs.setHeight( (ceData.rect.height() + 1)/2 );
	    if ( bs.height() < 10 )
		bs.setHeight( 10 );
	    bs.setWidth( bs.height() ); // 1.6 -approximate golden mean
	    bs = bs.expandedTo( QApplication::globalStrut() );
	    int y = 0;
	    int x, lx, rx, h;
	    x = ceData.rect.width() - y - bs.width();
	    lx = fw;
	    rx = x - fw * 2;
	    h = bs.height() * 2;

	    switch ( subcontrol ) {
	    case SC_SpinWidgetUp:
		return QRect(x + 1, y, bs.width(), bs.height() - 1);
	    case SC_SpinWidgetDown:
		return QRect(x + 1, y + bs.height() + 1, bs.width(), bs.height());
	    case SC_SpinWidgetButtonField:
		return QRect(x, y, bs.width(), h - 2*fw);
	    case SC_SpinWidgetEditField:
		return QRect(lx, fw, rx, h - 2*fw);
	    case SC_SpinWidgetFrame:
		return QRect( 0, 0, ceData.rect.width() - bs.width(), h);
	    default:
		break;
	    }
	    break; }

#ifndef QT_NO_COMBOBOX
    case CC_ComboBox: {
	if (elementFlags & CEF_IsEditable) {
	    int space = (ceData.rect.height() - 13) / 2;
	    switch (subcontrol) {
	    case SC_ComboBoxFrame:
		return QRect();
	    case SC_ComboBoxEditField: {
		QRect rect = ceData.rect;
		rect.setWidth(rect.width() - 13 - space * 2);
		rect.addCoords(3, 3, -3, -3);
		return rect; }
	    case SC_ComboBoxArrow:
		return QRect(ceData.rect.width() - 13 - space * 2, 0,
			     13 + space * 2, ceData.rect.height());
	    default: break;		// shouldn't get here
	    }

	} else {
	    int space = (ceData.rect.height() - 7) / 2;
	    switch (subcontrol) {
	    case SC_ComboBoxFrame:
		return QRect();
	    case SC_ComboBoxEditField: {
		QRect rect = ceData.rect;
		rect.addCoords(3, 3, -3, -3);
		return rect; }
	    case SC_ComboBoxArrow:		// 12 wide, 7 tall
		return QRect(ceData.rect.width() - 12 - space, space, 12, 7);
	    default: break;		// shouldn't get here
	    }
	}
	break; }
#endif

#ifndef QT_NO_SLIDER
    case CC_Slider: {

	if (subcontrol == SC_SliderHandle) {
	    int tickOffset  = pixelMetric( PM_SliderTickmarkOffset, ceData, elementFlags, widget );
	    int thickness   = pixelMetric( PM_SliderControlThickness, ceData, elementFlags, widget );
	    int len         = pixelMetric( PM_SliderLength, ceData, elementFlags, widget ) + 2;
	    int sliderPos   = ceData.startStep;
	    int motifBorder = 2;

	    if ( ceData.orientation == Horizontal )
		return QRect( sliderPos + motifBorder, tickOffset + motifBorder, len,
			      thickness - 2*motifBorder );
	    return QRect( tickOffset + motifBorder, sliderPos + motifBorder,
			  thickness - 2*motifBorder, len);
	}
	break; }
#endif
    default: break;
    }
    return QMotifStyle::querySubControlMetrics(control, ceData, elementFlags, subcontrol, opt, widget);
}


/*! \reimp */
bool QMotifPlusStyle::objectEventHandler( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QEvent *event )
{
    switch(event->type()) {
    case QEvent::MouseButtonPress:
        {
	    singleton->mousePressed = TRUE;

            if (!ceData.widgetObjectTypes.contains("QSlider"))
		break;

	    singleton->sliderActive = TRUE;
            break;
        }

    case QEvent::MouseButtonRelease:
        {
	    singleton->mousePressed = FALSE;

            if (!ceData.widgetObjectTypes.contains("QSlider"))
		break;

	    singleton->sliderActive = FALSE;
	    widgetActionRequest(ceData, elementFlags, source, WAR_Repaint);
	    break;
        }

    case QEvent::Enter:
        {
            if (!ceData.widgetObjectTypes.contains("QWidget"))
		break;

	    singleton->hoverWidget = source;
	    singleton->hoverWidgetData = ceData;
	    singleton->hoverWidgetFlags = elementFlags;
	    if (!(singleton->hoverWidgetFlags & CEF_IsEnabled)) {
		singleton->hoverWidget = 0;
		break;
	    }
	    widgetActionRequest(singleton->hoverWidgetData, singleton->hoverWidgetFlags, singleton->hoverWidget, WAR_Repaint);
	    break;
	}

    case QEvent::Leave:
	{
	    if (source != singleton->hoverWidget)
		break;
	    void *w = singleton->hoverWidget;
	    singleton->hoverWidget = 0;
	    widgetActionRequest(singleton->hoverWidgetData, singleton->hoverWidgetFlags, w, WAR_Repaint);
	    break;
	}

    case QEvent::MouseMove:
	{
	    if ((!ceData.widgetObjectTypes.contains("QWidget")) || source != singleton->hoverWidget)
		break;

	    if ((!ceData.widgetObjectTypes.contains("QScrollBar")) && (!ceData.widgetObjectTypes.contains("QSlider")))
		break;

	    singleton->mousePos = ((QMouseEvent *) event)->pos();
	    if (! singleton->mousePressed) {
		singleton->hovering = TRUE;
		widgetActionRequest(singleton->hoverWidgetData, singleton->hoverWidgetFlags, singleton->hoverWidget, WAR_Repaint);
		singleton->hovering = FALSE;
	    }

	    break;
	}

    default:
	break;
    }

    return QMotifStyle::objectEventHandler(ceData, elementFlags, source, event);
}


/*! \reimp */
int QMotifPlusStyle::styleHint(StyleHint hint,
			       QStyleControlElementData ceData,
			       ControlElementFlags elementFlags,
			       const QStyleOption &opt,
			       QStyleHintReturn *returnData,
			       const QWidget *widget) const
{
    int ret;
    switch (hint) {
    case SH_PopupMenu_MouseTracking:
	ret = 1;
	break;
    default:
	ret = QMotifStyle::styleHint(hint, ceData, elementFlags, opt, returnData, widget);
	break;
    }
    return ret;
}


#endif // QT_NO_STYLE_MOTIFPLUS