1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the style module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include "qwindowsstyle.h"
31
#if !defined(QT_NO_STYLE_WINDOWS) || defined(QT_PLUGIN)
33
#include "qapplication.h"
35
#include "qdrawutil.h" // for now
39
#include "qpaintengine.h"
41
#include "qrubberband.h"
42
#include "qstyleoption.h"
48
#include "qt_windows.h"
53
static const int windowsItemFrame = 2; // menu item frame width
54
static const int windowsSepHeight = 2; // separator item height
55
static const int windowsItemHMargin = 3; // menu item hor text margin
56
static const int windowsItemVMargin = 2; // menu item ver text margin
57
static const int windowsArrowHMargin = 6; // arrow horizontal margin
58
static const int windowsTabSpacing = 12; // space between text and tab
59
static const int windowsCheckMarkHMargin = 2; // horiz. margins of check mark
60
static const int windowsRightBorder = 15; // right border on windows
61
static const int windowsCheckMarkWidth = 12; // checkmarks width on windows
63
static bool use2000style = true;
65
enum QSliderDirection { SlUp, SlDown, SlLeft, SlRight };
68
class QWindowsStyle::Private : public QObject
71
Private(QWindowsStyle *parent);
73
bool hasSeenAlt(const QWidget *widget) const;
74
bool altDown() const { return alt_down; }
77
bool eventFilter(QObject *o, QEvent *e);
80
QList<const QWidget *> seenAlt;
85
QWindowsStyle::Private::Private(QWindowsStyle *parent)
87
alt_down(false), menuBarTimer(0)
91
// Returns true if the toplevel parent of \a widget has seen the Alt-key
92
bool QWindowsStyle::Private::hasSeenAlt(const QWidget *widget) const
94
widget = widget->window();
95
return seenAlt.contains(widget);
98
// Records Alt- and Focus events
99
bool QWindowsStyle::Private::eventFilter(QObject *o, QEvent *e)
101
if (!o->isWidgetType())
102
return QObject::eventFilter(o, e);
104
QWidget *widget = ::qobject_cast<QWidget*>(o);
107
case QEvent::KeyPress:
108
if (static_cast<QKeyEvent *>(e)->key() == Qt::Key_Alt) {
109
widget = widget->window();
111
// Alt has been pressed - find all widgets that care
112
QList<QWidget *> l = qFindChildren<QWidget *>(widget);
113
for (int pos=0; pos<l.size(); ++pos) {
114
QWidget *w = l.at(pos);
115
if (w->isWindow() || !w->isVisible() ||
116
w->style()->styleHint(SH_UnderlineShortcut, 0, w))
119
// Update states before repainting
120
seenAlt.append(widget);
123
// Repaint all relevant widgets
124
for (int pos = 0; pos<l.size(); ++pos)
125
l.at(pos)->repaint();
128
case QEvent::KeyRelease:
129
if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_Alt) {
130
widget = widget->window();
132
// Update state and repaint the menubars.
134
QList<QMenuBar *> l = qFindChildren<QMenuBar *>(widget);
135
for (int i = 0; i < l.size(); ++i)
140
// Reset widget when closing
141
seenAlt.removeAll(widget);
142
seenAlt.removeAll(widget->window());
148
return QObject::eventFilter(o, e);
152
\class QWindowsStyle qwindowsstyle.h
153
\brief The QWindowsStyle class provides a Microsoft Windows-like look and feel.
157
This style is Qt's default GUI style on Windows.
159
\img qwindowsstyle.png
160
\sa QWindowsXPStyle, QMacStyle, QPlastiqueStyle, QCDEStyle, QMotifStyle
164
Constructs a QWindowsStyle object.
166
QWindowsStyle::QWindowsStyle() : QCommonStyle(), d(0)
168
#if defined(Q_OS_WIN32)
169
use2000style = QSysInfo::WindowsVersion != QSysInfo::WV_NT && QSysInfo::WindowsVersion != QSysInfo::WV_95;
173
/*! Destroys the QWindowsStyle object. */
174
QWindowsStyle::~QWindowsStyle()
180
void QWindowsStyle::polish(QApplication *app)
182
// We only need the overhead when shortcuts are sometimes hidden
183
if (!styleHint(SH_UnderlineShortcut, 0)) {
184
d = new Private(this);
185
app->installEventFilter(d);
190
void QWindowsStyle::unpolish(QApplication *)
197
void QWindowsStyle::polish(QWidget *widget)
199
QCommonStyle::polish(widget);
200
if (qobject_cast<QRubberBand*>(widget)) {
201
widget->setWindowOpacity(0.7f);
202
widget->setAttribute(Qt::WA_PaintOnScreen);
207
void QWindowsStyle::unpolish(QWidget *widget)
209
QCommonStyle::polish(widget);
210
if (qobject_cast<QRubberBand*>(widget)) {
211
widget->setWindowOpacity(1.0);
212
widget->setAttribute(Qt::WA_PaintOnScreen, false);
217
void QWindowsStyle::polish(QPalette &pal)
219
QCommonStyle::polish(pal);
225
int QWindowsStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt, const QWidget *widget) const
230
case PM_ButtonDefaultIndicator:
231
case PM_ButtonShiftHorizontal:
232
case PM_ButtonShiftVertical:
235
case PM_TabBarTabShiftHorizontal:
238
case PM_TabBarTabShiftVertical:
241
case PM_MaximumDragDistance:
246
case PM_SliderLength:
250
// Returns the number of pixels to use for the business part of the
251
// slider (i.e., the non-tickmark portion). The remaining space is shared
252
// equally between the tickmark regions.
253
case PM_SliderControlThickness:
254
if (const QStyleOptionSlider *sl = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
255
int space = (sl->orientation == Qt::Horizontal) ? sl->rect.height() : sl->rect.width();
256
int ticks = sl->tickPosition;
258
if (ticks & QSlider::TicksAbove)
260
if (ticks & QSlider::TicksBelow)
267
int thick = 6; // Magic constant to get 5 + 16 + 5
268
if (ticks != QSlider::TicksBothSides && ticks != QSlider::NoTicks)
269
thick += pixelMetric(PM_SliderLength, sl, widget) / 4;
273
thick += (space * 2) / (n + 2);
279
#endif // QT_NO_SLIDER
281
case PM_MenuBarHMargin:
285
case PM_MenuBarVMargin:
289
case PM_MenuBarPanelWidth:
294
#if defined(Q_WS_WIN)
295
case PM_TitleBarHeight:
297
#if defined(Q_OS_TEMP)
298
ret = GetSystemMetrics(SM_CYCAPTION) - 1;
300
ret = GetSystemMetrics(SM_CYSMCAPTION) - 1;
306
case PM_ScrollBarExtent:
309
NONCLIENTMETRICS ncm;
310
ncm.cbSize = sizeof(NONCLIENTMETRICS);
311
if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0))
312
ret = qMax(ncm.iScrollHeight, ncm.iScrollWidth);
315
ret = QCommonStyle::pixelMetric(pm, opt, widget);
320
case PM_SplitterWidth:
321
ret = qMax(6, QApplication::globalStrut().width());
324
#if defined(Q_WS_WIN)
325
case PM_MDIFrameWidth:
326
ret = GetSystemMetrics(SM_CYFRAME);
331
ret = QCommonStyle::pixelMetric(pm, opt, widget);
338
#ifndef QT_NO_IMAGEIO_XPM
340
static const char * const qt_menu_xpm[] = {
370
static const char * const qt_close_xpm[] = {
385
static const char * const qt_maximize_xpm[]={
400
static const char * const qt_minimize_xpm[] = {
415
static const char * const qt_normalizeup_xpm[] = {
430
static const char * const qt_help_xpm[] = {
445
static const char * const qt_shade_xpm[] = {
460
static const char * const qt_unshade_xpm[] = {
475
static const char * dock_widget_close_xpm[] = {
489
static const char * const information_xpm[]={
496
"...........********.............",
497
"........***aaaaaaaa***..........",
498
"......**aaaaaaaaaaaaaa**........",
499
".....*aaaaaaaaaaaaaaaaaa*.......",
500
"....*aaaaaaaabbbbaaaaaaaac......",
501
"...*aaaaaaaabbbbbbaaaaaaaac.....",
502
"..*aaaaaaaaabbbbbbaaaaaaaaac....",
503
".*aaaaaaaaaaabbbbaaaaaaaaaaac...",
504
".*aaaaaaaaaaaaaaaaaaaaaaaaaac*..",
505
"*aaaaaaaaaaaaaaaaaaaaaaaaaaaac*.",
506
"*aaaaaaaaaabbbbbbbaaaaaaaaaaac*.",
507
"*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
508
"*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
509
"*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
510
"*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
511
"*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
512
".*aaaaaaaaaaabbbbbaaaaaaaaaac***",
513
".*aaaaaaaaaaabbbbbaaaaaaaaaac***",
514
"..*aaaaaaaaaabbbbbaaaaaaaaac***.",
515
"...caaaaaaabbbbbbbbbaaaaaac****.",
516
"....caaaaaaaaaaaaaaaaaaaac****..",
517
".....caaaaaaaaaaaaaaaaaac****...",
518
"......ccaaaaaaaaaaaaaacc****....",
519
".......*cccaaaaaaaaccc*****.....",
520
"........***cccaaaac*******......",
521
"..........****caaac*****........",
522
".............*caaac**...........",
523
"...............caac**...........",
524
"................cac**...........",
525
".................cc**...........",
526
"..................***...........",
527
"...................**..........."};
529
static const char* const warning_xpm[]={
535
".............***................",
536
"............*aaa*...............",
537
"...........*aaaaa*b.............",
538
"...........*aaaaa*bb............",
539
"..........*aaaaaaa*bb...........",
540
"..........*aaaaaaa*bb...........",
541
".........*aaaaaaaaa*bb..........",
542
".........*aaaaaaaaa*bb..........",
543
"........*aaaaaaaaaaa*bb.........",
544
"........*aaaa***aaaa*bb.........",
545
".......*aaaa*****aaaa*bb........",
546
".......*aaaa*****aaaa*bb........",
547
"......*aaaaa*****aaaaa*bb.......",
548
"......*aaaaa*****aaaaa*bb.......",
549
".....*aaaaaa*****aaaaaa*bb......",
550
".....*aaaaaa*****aaaaaa*bb......",
551
"....*aaaaaaaa***aaaaaaaa*bb.....",
552
"....*aaaaaaaa***aaaaaaaa*bb.....",
553
"...*aaaaaaaaa***aaaaaaaaa*bb....",
554
"...*aaaaaaaaaa*aaaaaaaaaa*bb....",
555
"..*aaaaaaaaaaa*aaaaaaaaaaa*bb...",
556
"..*aaaaaaaaaaaaaaaaaaaaaaa*bb...",
557
".*aaaaaaaaaaaa**aaaaaaaaaaa*bb..",
558
".*aaaaaaaaaaa****aaaaaaaaaa*bb..",
559
"*aaaaaaaaaaaa****aaaaaaaaaaa*bb.",
560
"*aaaaaaaaaaaaa**aaaaaaaaaaaa*bb.",
561
"*aaaaaaaaaaaaaaaaaaaaaaaaaaa*bbb",
562
"*aaaaaaaaaaaaaaaaaaaaaaaaaaa*bbb",
563
".*aaaaaaaaaaaaaaaaaaaaaaaaa*bbbb",
564
"..*************************bbbbb",
565
"....bbbbbbbbbbbbbbbbbbbbbbbbbbb.",
566
".....bbbbbbbbbbbbbbbbbbbbbbbbb.."};
568
static const char* const critical_xpm[]={
574
"...........********.............",
575
".........************...........",
576
".......****************.........",
577
"......******************........",
578
".....********************a......",
579
"....**********************a.....",
580
"...************************a....",
581
"..*******b**********b*******a...",
582
"..******bbb********bbb******a...",
583
".******bbbbb******bbbbb******a..",
584
".*******bbbbb****bbbbb*******a..",
585
"*********bbbbb**bbbbb*********a.",
586
"**********bbbbbbbbbb**********a.",
587
"***********bbbbbbbb***********aa",
588
"************bbbbbb************aa",
589
"************bbbbbb************aa",
590
"***********bbbbbbbb***********aa",
591
"**********bbbbbbbbbb**********aa",
592
"*********bbbbb**bbbbb*********aa",
593
".*******bbbbb****bbbbb*******aa.",
594
".******bbbbb******bbbbb******aa.",
595
"..******bbb********bbb******aaa.",
596
"..*******b**********b*******aa..",
597
"...************************aaa..",
598
"....**********************aaa...",
599
"....a********************aaa....",
600
".....a******************aaa.....",
601
"......a****************aaa......",
602
".......aa************aaaa.......",
603
".........aa********aaaaa........",
604
"...........aaaaaaaaaaa..........",
605
".............aaaaaaa............"};
607
static const char *const question_xpm[] = {
614
"...........********.............",
615
"........***aaaaaaaa***..........",
616
"......**aaaaaaaaaaaaaa**........",
617
".....*aaaaaaaaaaaaaaaaaa*.......",
618
"....*aaaaaaaaaaaaaaaaaaaac......",
619
"...*aaaaaaaabbbbbbaaaaaaaac.....",
620
"..*aaaaaaaabaaabbbbaaaaaaaac....",
621
".*aaaaaaaabbaaaabbbbaaaaaaaac...",
622
".*aaaaaaaabbbbaabbbbaaaaaaaac*..",
623
"*aaaaaaaaabbbbaabbbbaaaaaaaaac*.",
624
"*aaaaaaaaaabbaabbbbaaaaaaaaaac*.",
625
"*aaaaaaaaaaaaabbbbaaaaaaaaaaac**",
626
"*aaaaaaaaaaaaabbbaaaaaaaaaaaac**",
627
"*aaaaaaaaaaaaabbaaaaaaaaaaaaac**",
628
"*aaaaaaaaaaaaabbaaaaaaaaaaaaac**",
629
"*aaaaaaaaaaaaaaaaaaaaaaaaaaaac**",
630
".*aaaaaaaaaaaabbaaaaaaaaaaaac***",
631
".*aaaaaaaaaaabbbbaaaaaaaaaaac***",
632
"..*aaaaaaaaaabbbbaaaaaaaaaac***.",
633
"...caaaaaaaaaabbaaaaaaaaaac****.",
634
"....caaaaaaaaaaaaaaaaaaaac****..",
635
".....caaaaaaaaaaaaaaaaaac****...",
636
"......ccaaaaaaaaaaaaaacc****....",
637
".......*cccaaaaaaaaccc*****.....",
638
"........***cccaaaac*******......",
639
"..........****caaac*****........",
640
".............*caaac**...........",
641
"...............caac**...........",
642
"................cac**...........",
643
".................cc**...........",
644
"..................***...........",
645
"...................**..........."};
647
static const char* const dir_open_xpm[]={
673
static const char * const dir_closed_xpm[]={
699
static const char * const dir_link_xpm[]={
728
static const char* const file_xpm[]={
752
static const char * const file_link_xpm[]={
783
#endif //QT_NO_IMAGEIO_XPM
788
QPixmap QWindowsStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt,
789
const QWidget *widget) const
791
#ifndef QT_NO_IMAGEIO_XPM
792
switch (standardPixmap) {
793
case SP_TitleBarMenuButton:
794
return QPixmap((const char **)qt_menu_xpm);
795
case SP_TitleBarShadeButton:
796
return QPixmap((const char **)qt_shade_xpm);
797
case SP_TitleBarUnshadeButton:
798
return QPixmap((const char **)qt_unshade_xpm);
799
case SP_TitleBarNormalButton:
800
return QPixmap((const char **)qt_normalizeup_xpm);
801
case SP_TitleBarMinButton:
802
return QPixmap((const char **)qt_minimize_xpm);
803
case SP_TitleBarMaxButton:
804
return QPixmap((const char **)qt_maximize_xpm);
805
case SP_TitleBarCloseButton:
806
return QPixmap((const char **)qt_close_xpm);
807
case SP_TitleBarContextHelpButton:
808
return QPixmap((const char **)qt_help_xpm);
809
case SP_DockWidgetCloseButton:
810
return QPixmap((const char **)dock_widget_close_xpm);
811
case SP_MessageBoxInformation:
812
return QPixmap((const char **)information_xpm);
813
case SP_MessageBoxWarning:
814
return QPixmap((const char **)warning_xpm);
815
case SP_MessageBoxCritical:
816
return QPixmap((const char **)critical_xpm);
817
case SP_MessageBoxQuestion:
818
return QPixmap((const char **)question_xpm);
822
#endif //QT_NO_IMAGEIO_XPM
823
return QCommonStyle::standardPixmap(standardPixmap, opt, widget);
827
int QWindowsStyle::styleHint(StyleHint hint, const QStyleOption *opt, const QWidget *widget,
828
QStyleHintReturn *returnData) const
833
case SH_EtchDisabledText:
834
case SH_Slider_SnapToValue:
835
case SH_PrintDialog_RightAlignButtons:
836
case SH_MainWindow_SpaceBelowMenuBar:
837
case SH_FontDialog_SelectAssociatedText:
838
case SH_Menu_AllowActiveAndDisabled:
839
case SH_MenuBar_AltKeyNavigation:
840
case SH_MenuBar_MouseTracking:
841
case SH_Menu_MouseTracking:
842
case SH_ComboBox_ListMouseTracking:
843
case SH_ScrollBar_StopMouseOverSlider:
846
case SH_ItemView_ChangeHighlightOnFocus:
847
#if defined(Q_WS_WIN)
848
if (QSysInfo::WindowsVersion != QSysInfo::WV_95 && QSysInfo::WindowsVersion != QSysInfo::WV_NT)
854
case SH_ToolBox_SelectedPageTitleBold:
858
#if defined(Q_WS_WIN)
859
case SH_UnderlineShortcut:
861
if (QSysInfo::WindowsVersion != QSysInfo::WV_95
862
&& QSysInfo::WindowsVersion != QSysInfo::WV_98
863
&& QSysInfo::WindowsVersion != QSysInfo::WV_NT) {
865
SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &cues, 0);
867
// Do nothing if we always paint underlines
868
if (!ret && widget && d) {
869
const QMenuBar *menuBar = ::qobject_cast<const QMenuBar*>(widget);
870
if (!menuBar && ::qobject_cast<const QMenu *>(widget)) {
871
QWidget *w = QApplication::activeWindow();
872
if (w && w != widget)
873
menuBar = qFindChild<QMenuBar *>(w);
875
// If we paint a menubar draw underlines if it has focus, or if alt is down,
876
// or if a popup menu belonging to the menubar is active and paints underlines
878
if (menuBar->hasFocus() || d->altDown())
880
// Otherwise draw underlines if the toplevel widget has seen an alt-press
881
} else if (d->hasSeenAlt(widget)) {
889
ret = QCommonStyle::styleHint(hint, opt, widget, returnData);
896
void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p,
897
const QWidget *w) const
899
// Used to restore across fallthrough cases. Currently only used in PE_IndicatorCheckBox
900
bool doRestore = false;
903
case PE_FrameButtonTool:
904
case PE_PanelButtonTool: {
907
bool panel = (pe == PE_PanelButtonTool);
908
if (!(opt->state & (State_Sunken | State_MouseOver)) && (opt->state & State_On)
910
fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
913
fill = opt->palette.brush(QPalette::Button);
917
if (opt->state & (State_Raised | State_Sunken | State_On)) {
918
if (opt->state & State_AutoRaise) {
920
qDrawShadePanel(p, opt->rect, opt->palette,
921
opt->state & (State_Sunken | State_On), 1, &fill);
923
qDrawShadeRect(p, opt->rect, opt->palette,
924
opt->state & (State_Sunken | State_On), 1);
926
p->setPen(opt->palette.button().color());
927
p->drawRect(opt->rect.adjusted(1,1,-2,-2));
930
qDrawWinButton(p, opt->rect, opt->palette,
931
opt->state & (State_Sunken | State_On), panel ? &fill : 0);
934
p->fillRect(opt->rect, fill);
937
case PE_PanelButtonCommand:
938
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
940
State flags = opt->state;
941
QPalette pal = opt->palette;
943
if (! (flags & State_Sunken) && (flags & State_On))
944
fill = QBrush(pal.light().color(), Qt::Dense4Pattern);
946
fill = pal.brush(QPalette::Button);
948
if (btn->features & QStyleOptionButton::DefaultButton && flags & State_Sunken) {
949
p->setPen(pal.dark().color());
952
} else if (flags & (State_Raised | State_Sunken | State_On | State_Sunken)) {
953
qDrawWinButton(p, r, pal, flags & (State_Sunken | State_On),
956
p->fillRect(r, fill);
960
case PE_FrameDefaultButton: {
961
p->setPen(opt->palette.shadow().color());
962
QRect rect = opt->rect;
963
rect.adjust(0, 0, -1, -1);
967
case PE_IndicatorArrowUp:
968
case PE_IndicatorArrowDown:
969
case PE_IndicatorArrowRight:
970
case PE_IndicatorArrowLeft: {
973
case PE_IndicatorArrowUp:
974
points[0] = QPoint(-4, 1);
975
points[1] = QPoint(2, 1);
976
points[2] = QPoint(-3, 0);
977
points[3] = QPoint(1, 0);
978
points[4] = QPoint(-2, -1);
979
points[5] = QPoint(0, -1);
980
points[6] = QPoint(-1, -2);
982
case PE_IndicatorArrowDown:
983
points[0] = QPoint(-4, -2);
984
points[1] = QPoint(2, -2);
985
points[2] = QPoint(-3, -1);
986
points[3] = QPoint(1, -1);
987
points[4] = QPoint(-2, 0);
988
points[5] = QPoint(0, 0);
989
points[6] = QPoint(-1, 1);
991
case PE_IndicatorArrowRight:
992
points[0] = QPoint(-2, -3);
993
points[1] = QPoint(-2, 3);
994
points[2] = QPoint(-1, -2);
995
points[3] = QPoint(-1, 2);
996
points[4] = QPoint(0, -1);
997
points[5] = QPoint(0, 1);
998
points[6] = QPoint(1, 0);
1000
case PE_IndicatorArrowLeft:
1001
points[0] = QPoint(0, -3);
1002
points[1] = QPoint(0, 3);
1003
points[2] = QPoint(-1, -2);
1004
points[3] = QPoint(-1, 2);
1005
points[4] = QPoint(-2, -1);
1006
points[5] = QPoint(-2, 1);
1007
points[6] = QPoint(-3, 0);
1013
if (opt->state & State_Sunken)
1014
p->translate(pixelMetric(PM_ButtonShiftHorizontal),
1015
pixelMetric(PM_ButtonShiftVertical));
1016
if (opt->state & State_Enabled) {
1017
p->translate(opt->rect.x() + opt->rect.width() / 2,
1018
opt->rect.y() + opt->rect.height() / 2);
1019
p->setPen(opt->palette.buttonText().color());
1020
p->drawLine(points[0], points[1]);
1021
p->drawLine(points[2], points[3]);
1022
p->drawLine(points[4], points[5]);
1023
p->drawPoint(points[6]);
1025
p->translate(opt->rect.x() + opt->rect.width() / 2 + 1,
1026
opt->rect.y() + opt->rect.height() / 2 + 1);
1027
p->setPen(opt->palette.light().color());
1028
p->drawLine(points[0], points[1]);
1029
p->drawLine(points[2], points[3]);
1030
p->drawLine(points[4], points[5]);
1031
p->drawPoint(points[6]);
1032
p->translate(-1, -1);
1033
p->setPen(opt->palette.mid().color());
1034
p->drawLine(points[0], points[1]);
1035
p->drawLine(points[2], points[3]);
1036
p->drawLine(points[4], points[5]);
1037
p->drawPoint(points[6]);
1041
case PE_IndicatorCheckBox: {
1043
if (opt->state & State_NoChange)
1044
fill = QBrush(opt->palette.base().color(), Qt::Dense4Pattern);
1045
else if (opt->state & State_Sunken)
1046
fill = opt->palette.button();
1047
else if (opt->state & State_Enabled)
1048
fill = opt->palette.base();
1050
fill = opt->palette.background();
1053
qDrawWinPanel(p, opt->rect, opt->palette, true, &fill);
1054
if (opt->state & State_NoChange)
1055
p->setPen(opt->palette.dark().color());
1057
p->setPen(opt->palette.text().color());
1059
case PE_IndicatorViewItemCheck:
1060
case PE_Q3CheckListIndicator:
1065
if (pe == PE_Q3CheckListIndicator || pe == PE_IndicatorViewItemCheck) {
1066
if (opt->state & State_Enabled)
1067
p->setPen(QPen(opt->palette.text().color(), 1));
1069
p->setPen(QPen(opt->palette.dark().color(), 1));
1070
if (opt->state & State_NoChange)
1071
p->setBrush(opt->palette.brush(QPalette::Button));
1072
p->drawRect(opt->rect.x() + 1, opt->rect.y() + 1, 11, 11);
1074
if (!(opt->state & State_Off)) {
1077
xx = opt->rect.x() + 3;
1078
yy = opt->rect.y() + 5;
1079
for (i = 0; i < 3; ++i) {
1080
lines[i] = QLineF(xx, yy, xx, yy + 2);
1085
for (i = 3; i < 7; ++i) {
1086
lines[i] = QLineF(xx, yy, xx, yy + 2);
1090
p->drawLines(lines, 7);
1095
case PE_FrameFocusRect:
1096
if (const QStyleOptionFocusRect *fropt = qstyleoption_cast<const QStyleOptionFocusRect *>(opt)) {
1097
if (!(fropt->state & State_KeyboardFocusChange))
1099
QRect r = opt->rect;
1101
p->setBackgroundMode(Qt::TransparentMode);
1102
QColor bg_col = fropt->backgroundColor;
1103
if (!bg_col.isValid())
1104
bg_col = p->background().color();
1105
// Create an "XOR" color.
1106
QColor patternCol((bg_col.red() ^ 0xff) & 0xff,
1107
(bg_col.green() ^ 0xff) & 0xff,
1108
(bg_col.blue() ^ 0xff) & 0xff);
1109
p->setBrush(QBrush(patternCol, Qt::Dense4Pattern));
1110
p->setBrushOrigin(r.topLeft());
1111
p->setPen(Qt::NoPen);
1112
p->drawRect(r.left(), r.top(), r.width(), 1); // Top
1113
p->drawRect(r.left(), r.bottom(), r.width(), 1); // Bottom
1114
p->drawRect(r.left(), r.top(), 1, r.height()); // Left
1115
p->drawRect(r.right(), r.top(), 1, r.height()); // Right
1119
case PE_IndicatorRadioButton:
1121
#define PTSARRLEN(x) sizeof(x)/(sizeof(QPoint))
1122
static const QPoint pts1[] = { // dark lines
1123
QPoint(1, 9), QPoint(1, 8), QPoint(0, 7), QPoint(0, 4), QPoint(1, 3), QPoint(1, 2),
1124
QPoint(2, 1), QPoint(3, 1), QPoint(4, 0), QPoint(7, 0), QPoint(8, 1), QPoint(9, 1)
1126
static const QPoint pts2[] = { // black lines
1127
QPoint(2, 8), QPoint(1, 7), QPoint(1, 4), QPoint(2, 3), QPoint(2, 2), QPoint(3, 2),
1128
QPoint(4, 1), QPoint(7, 1), QPoint(8, 2), QPoint(9, 2)
1130
static const QPoint pts3[] = { // background lines
1131
QPoint(2, 9), QPoint(3, 9), QPoint(4, 10), QPoint(7, 10), QPoint(8, 9), QPoint(9, 9),
1132
QPoint(9, 8), QPoint(10, 7), QPoint(10, 4), QPoint(9, 3)
1134
static const QPoint pts4[] = { // white lines
1135
QPoint(2, 10), QPoint(3, 10), QPoint(4, 11), QPoint(7, 11), QPoint(8, 10),
1136
QPoint(9, 10), QPoint(10, 9), QPoint(10, 8), QPoint(11, 7), QPoint(11, 4),
1137
QPoint(10, 3), QPoint(10, 2)
1139
static const QPoint pts5[] = { // inner fill
1140
QPoint(4, 2), QPoint(7, 2), QPoint(9, 4), QPoint(9, 7), QPoint(7, 9), QPoint(4, 9),
1141
QPoint(2, 7), QPoint(2, 4)
1144
// make sure the indicator is square
1145
QRect ir = opt->rect;
1147
if (opt->rect.width() < opt->rect.height()) {
1148
ir.setTop(opt->rect.top() + (opt->rect.height() - opt->rect.width()) / 2);
1149
ir.setHeight(opt->rect.width());
1150
} else if (opt->rect.height() < opt->rect.width()) {
1151
ir.setLeft(opt->rect.left() + (opt->rect.width() - opt->rect.height()) / 2);
1152
ir.setWidth(opt->rect.height());
1156
bool down = opt->state & State_Sunken;
1157
bool enabled = opt->state & State_Enabled;
1158
bool on = opt->state & State_On;
1160
p->translate(ir.x(), ir.y());
1162
p->setPen(opt->palette.dark().color());
1163
p->drawPolyline(pts1, PTSARRLEN(pts1));
1165
p->setPen(opt->palette.shadow().color());
1166
p->drawPolyline(pts2, PTSARRLEN(pts2));
1168
p->setPen(opt->palette.midlight().color());
1169
p->drawPolyline(pts3, PTSARRLEN(pts3));
1171
p->setPen(opt->palette.light().color());
1172
p->drawPolyline(pts4, PTSARRLEN(pts4));
1174
QColor fillColor = (down || !enabled)
1175
? opt->palette.button().color()
1176
: opt->palette.base().color();
1177
p->setPen(fillColor);
1178
p->setBrush(fillColor) ;
1179
p->drawPolygon(pts5, PTSARRLEN(pts5));
1181
p->translate(-ir.x(), -ir.y()); // restore translate
1184
p->setPen(Qt::NoPen);
1185
p->setBrush(opt->palette.text());
1186
p->drawRect(ir.x() + 5, ir.y() + 4, 2, 4);
1187
p->drawRect(ir.x() + 4, ir.y() + 5, 4, 2);
1194
if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
1195
if (frame->lineWidth == 2) {
1196
QPalette popupPal = frame->palette;
1197
if (pe == PE_FrameMenu) {
1198
popupPal.setColor(QPalette::Light, frame->palette.background().color());
1199
popupPal.setColor(QPalette::Midlight, frame->palette.light().color());
1201
qDrawWinPanel(p, frame->rect, popupPal, frame->state & State_Sunken);
1203
QCommonStyle::drawPrimitive(pe, opt, p, w);
1207
case PE_IndicatorBranch: {
1208
// This is _way_ too similar to the common style.
1209
static const int decoration_size = 9;
1210
int mid_h = opt->rect.x() + opt->rect.width() / 2;
1211
int mid_v = opt->rect.y() + opt->rect.height() / 2;
1216
if (opt->state & State_Children) {
1217
int delta = decoration_size / 2;
1222
p->drawLine(bef_h + 2, bef_v + 4, bef_h + 6, bef_v + 4);
1223
if (!(opt->state & State_Open))
1224
p->drawLine(bef_h + 4, bef_v + 2, bef_h + 4, bef_v + 6);
1225
QPen oldPen = p->pen();
1226
p->setPen(opt->palette.dark().color());
1227
p->drawRect(bef_h, bef_v, decoration_size - 1, decoration_size - 1);
1230
QBrush brush(opt->palette.dark().color(), Qt::Dense4Pattern);
1231
if (opt->state & State_Item) {
1232
if (QApplication::isRightToLeft())
1233
p->fillRect(opt->rect.left(), mid_v, bef_h - opt->rect.left(), 1, brush);
1235
p->fillRect(aft_h, mid_v, opt->rect.right() - aft_h + 1, 1, brush);
1237
if (opt->state & State_Sibling)
1238
p->fillRect(mid_h, aft_v, 1, opt->rect.bottom() - aft_v + 1, brush);
1239
if (opt->state & (State_Open | State_Children | State_Item | State_Sibling))
1240
p->fillRect(mid_h, opt->rect.y(), 1, bef_v - opt->rect.y(), brush);
1242
case PE_FrameButtonBevel:
1243
case PE_PanelButtonBevel: {
1245
bool panel = pe != PE_FrameButtonBevel;
1246
p->setBrushOrigin(opt->rect.topLeft());
1247
if (!(opt->state & State_Sunken) && (opt->state & State_On))
1248
fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
1250
fill = opt->palette.brush(QPalette::Button);
1252
if (opt->state & (State_Raised | State_On | State_Sunken)) {
1253
qDrawWinButton(p, opt->rect, opt->palette, opt->state & (State_Sunken | State_On),
1257
p->fillRect(opt->rect, fill);
1259
p->drawRect(opt->rect);
1262
case PE_FrameWindow: {
1263
QPalette popupPal = opt->palette;
1264
popupPal.setColor(QPalette::Light, opt->palette.background().color());
1265
popupPal.setColor(QPalette::Midlight, opt->palette.light().color());
1266
qDrawWinPanel(p, opt->rect, popupPal, opt->state & State_Sunken);
1268
case PE_IndicatorDockWidgetResizeHandle: {
1269
QPen oldPen = p->pen();
1270
p->setPen(opt->palette.light().color());
1271
if (opt->state & State_Horizontal) {
1272
p->drawLine(opt->rect.left(), opt->rect.top(),
1273
opt->rect.right(), opt->rect.top());
1274
p->setPen(opt->palette.dark().color());
1275
p->drawLine(opt->rect.left(), opt->rect.bottom() - 1,
1276
opt->rect.right(), opt->rect.bottom() - 1);
1277
p->setPen(opt->palette.shadow().color());
1278
p->drawLine(opt->rect.left(), opt->rect.bottom(),
1279
opt->rect.right(), opt->rect.bottom());
1281
p->drawLine(opt->rect.left(), opt->rect.top(),
1282
opt->rect.left(), opt->rect.bottom());
1283
p->setPen(opt->palette.dark().color());
1284
p->drawLine(opt->rect.right() - 1, opt->rect.top(),
1285
opt->rect.right() - 1, opt->rect.bottom());
1286
p->setPen(opt->palette.shadow().color());
1287
p->drawLine(opt->rect.right(), opt->rect.top(),
1288
opt->rect.right(), opt->rect.bottom());
1293
QCommonStyle::drawPrimitive(pe, opt, p, w);
1298
void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter *p,
1299
const QWidget *widget) const
1303
if (const QStyleOptionMenuItem *menuitem = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
1305
menuitem->rect.getRect(&x, &y, &w, &h);
1306
int tab = menuitem->tabWidth;
1307
bool dis = !(menuitem->state & State_Enabled);
1308
bool checked = menuitem->checkType != QStyleOptionMenuItem::NotCheckable
1309
? menuitem->checked : false;
1310
bool act = menuitem->state & State_Selected;
1312
// windows always has a check column, regardless whether we have an icon or not
1313
int checkcol = qMax(menuitem->maxIconWidth, use2000style ? 20 : windowsCheckMarkWidth);
1315
if (menuitem->menuItemType == QStyleOptionMenuItem::Separator) {
1316
p->setPen(menuitem->palette.dark().color());
1317
p->drawLine(x, y, x + w, y);
1318
p->setPen(menuitem->palette.light().color());
1319
p->drawLine(x, y + 1, x + w, y + 1);
1323
QBrush fill = menuitem->palette.brush(act ? QPalette::Highlight : QPalette::Button);
1324
p->fillRect(menuitem->rect, fill);
1326
QRect vCheckRect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x(), menuitem->rect.y(), checkcol, menuitem->rect.height()));
1329
qDrawShadePanel(p, vCheckRect,
1330
menuitem->palette, true, 1,
1331
&menuitem->palette.brush(QPalette::Button));
1333
QBrush fill(menuitem->palette.light().color(), Qt::Dense4Pattern);
1334
qDrawShadePanel(p, vCheckRect, menuitem->palette, true, 1, &fill);
1337
p->fillRect(vCheckRect, menuitem->palette.brush(QPalette::Button));
1340
// On Windows Style, if we have a checkable item and an icon we
1341
// draw the icon recessed to indicate an item is checked. If we
1342
// have no icon, we draw a checkmark instead.
1343
if (!menuitem->icon.isNull()) {
1344
QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
1346
mode = QIcon::Active;
1349
pixmap = menuitem->icon.pixmap(pixelMetric(PM_SmallIconSize), mode, QIcon::On);
1351
pixmap = menuitem->icon.pixmap(pixelMetric(PM_SmallIconSize), mode);
1352
int pixw = pixmap.width();
1353
int pixh = pixmap.height();
1354
if (act && !dis && !checked)
1355
qDrawShadePanel(p, vCheckRect, menuitem->palette, false, 1,
1356
&menuitem->palette.brush(QPalette::Button));
1357
QRect pmr(0, 0, pixw, pixh);
1358
pmr.moveCenter(vCheckRect.center());
1359
p->setPen(menuitem->palette.text().color());
1360
p->drawPixmap(pmr.topLeft(), pixmap);
1361
} else if (checked) {
1362
QStyleOptionMenuItem newMi = *menuitem;
1363
newMi.state = State_None;
1365
newMi.state |= State_Enabled;
1367
newMi.state |= State_On;
1368
newMi.rect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x() + windowsItemFrame, menuitem->rect.y() + windowsItemFrame,
1369
checkcol - 2 * windowsItemFrame, menuitem->rect.height() - 2*windowsItemFrame));
1370
drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, widget);
1372
p->setPen(act ? menuitem->palette.highlightedText().color() : menuitem->palette.buttonText().color());
1376
discol = menuitem->palette.text().color();
1380
int xm = windowsItemFrame + checkcol + windowsItemHMargin;
1381
int xpos = menuitem->rect.x() + xm;
1382
QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
1383
QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
1384
QString s = menuitem->text;
1385
if (!s.isEmpty()) { // draw text
1387
int t = s.indexOf('\t');
1388
int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
1389
if (!styleHint(SH_UnderlineShortcut, menuitem, widget))
1390
text_flags |= Qt::TextHideMnemonic;
1391
text_flags |= Qt::AlignLeft;
1393
QRect vShortcutRect = visualRect(opt->direction, menuitem->rect, QRect(textRect.topRight(), menuitem->rect.bottomRight()));
1395
p->setPen(menuitem->palette.light().color());
1396
p->drawText(vShortcutRect.adjusted(1,1,1,1), text_flags, s.mid(t + 1));
1399
p->drawText(vShortcutRect, text_flags, s.mid(t + 1));
1402
QFont font = menuitem->font;
1403
if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
1407
p->setPen(menuitem->palette.light().color());
1408
p->drawText(vTextRect.adjusted(1,1,1,1), text_flags, s.left(t));
1411
p->drawText(vTextRect, text_flags, s.left(t));
1414
if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow
1415
int dim = (h - 2 * windowsItemFrame) / 2;
1416
PrimitiveElement arrow;
1417
arrow = QApplication::isRightToLeft() ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
1418
xpos = x + w - windowsArrowHMargin - windowsItemFrame - dim;
1419
QRect vSubMenuRect = visualRect(opt->direction, menuitem->rect, QRect(xpos, y + h / 2 - dim / 2, dim, dim));
1420
QStyleOptionMenuItem newMI = *menuitem;
1421
newMI.rect = vSubMenuRect;
1422
newMI.state = dis ? State_None : State_Enabled;
1424
newMI.palette.setColor(QPalette::ButtonText,
1425
newMI.palette.highlightedText().color());
1426
drawPrimitive(arrow, &newMI, p, widget);
1431
case CE_MenuBarItem:
1432
if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
1433
bool active = mbi->state & State_Selected;
1434
bool hasFocus = mbi->state & State_HasFocus;
1435
bool down = mbi->state & State_Sunken;
1436
QStyleOptionMenuItem newMbi = *mbi;
1437
p->fillRect(mbi->rect, mbi->palette.brush(QPalette::Button));
1438
if (active || hasFocus) {
1439
QBrush b = mbi->palette.brush(QPalette::Button);
1441
p->setBrushOrigin(p->brushOrigin() + QPoint(1, 1));
1442
if (active && hasFocus)
1443
qDrawShadeRect(p, mbi->rect.x(), mbi->rect.y(), mbi->rect.width(),
1444
mbi->rect.height(), mbi->palette, active && down, 1, 0, &b);
1445
if (active && down) {
1446
newMbi.rect.translate(pixelMetric(PM_ButtonShiftHorizontal, mbi, widget),
1447
pixelMetric(PM_ButtonShiftVertical, mbi, widget));
1448
p->setBrushOrigin(p->brushOrigin() - QPoint(1, 1));
1451
QCommonStyle::drawControl(ce, &newMbi, p, widget);
1454
case CE_TabBarTabShape:
1455
if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
1456
bool rtlHorTabs = (tab->direction == Qt::RightToLeft
1457
&& (tab->shape == QTabBar::RoundedNorth
1458
|| tab->shape == QTabBar::RoundedSouth));
1459
bool selected = tab->state & State_Selected;
1460
bool lastTab = ((!rtlHorTabs && tab->position == QStyleOptionTab::End)
1462
&& tab->position == QStyleOptionTab::Beginning));
1463
bool firstTab = ((!rtlHorTabs
1464
&& tab->position == QStyleOptionTab::Beginning)
1466
&& tab->position == QStyleOptionTab::End));
1467
bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab;
1468
bool previousSelected =
1470
&& tab->selectedPosition == QStyleOptionTab::PreviousIsSelected)
1472
&& tab->selectedPosition == QStyleOptionTab::NextIsSelected));
1475
&& tab->selectedPosition == QStyleOptionTab::NextIsSelected)
1477
&& tab->selectedPosition
1478
== QStyleOptionTab::PreviousIsSelected));
1479
int tabBarAlignment = styleHint(SH_TabBar_Alignment, tab, widget);
1480
bool leftAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignLeft)
1482
&& tabBarAlignment == Qt::AlignRight);
1484
bool rightAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignRight)
1486
&& tabBarAlignment == Qt::AlignLeft);
1488
QColor light = tab->palette.light().color();
1489
QColor midlight = tab->palette.midlight().color();
1490
QColor dark = tab->palette.dark().color();
1491
QColor shadow = tab->palette.shadow().color();
1492
QColor background = tab->palette.background().color();
1493
int borderThinkness = pixelMetric(PM_TabBarBaseOverlap, tab, widget);
1495
borderThinkness /= 2;
1496
QRect r2(opt->rect);
1498
int x2 = r2.right();
1500
int y2 = r2.bottom();
1501
switch (tab->shape) {
1503
QCommonStyle::drawControl(ce, tab, p, widget);
1505
case QTabBar::RoundedNorth: {
1508
x1 += firstTab ? borderThinkness : 0;
1509
x2 -= lastTab ? borderThinkness : 0;
1513
p->setPen(background);
1514
p->drawLine(x1, y2 - 1, x2, y2 - 1);
1515
p->drawLine(x1, y2, x2, y2);
1518
if (firstTab || selected || onlyOne || !previousSelected) {
1520
p->drawLine(x1, y1 + 2, x1, y2 - (firstTab && selected && leftAligned ? 0 : borderThinkness));
1521
p->drawPoint(x1 + 1, y1 + 1);
1522
p->setPen(midlight);
1523
p->drawLine(x1 + 1, y1 + 2, x1 + 1, y2 - (firstTab && selected && leftAligned ? 0 : borderThinkness));
1527
int beg = x1 + (previousSelected ? 0 : 2);
1528
int end = x2 - (nextSelected ? 0 : 2);
1530
p->drawLine(beg, y1, end, y1);
1531
p->setPen(midlight);
1532
p->drawLine(beg, y1 + 1, end, y1 + 1);
1535
if (lastTab || selected || onlyOne || !nextSelected) {
1537
p->drawLine(x2, y1 + 2, x2, y2 - (lastTab && selected && rightAligned ? 0 : borderThinkness));
1538
p->drawPoint(x2 - 1, y1 + 1);
1540
p->drawLine(x2 - 1, y1 + 2, x2 - 1, y2 - (lastTab && selected && rightAligned ? 0 : borderThinkness));
1543
case QTabBar::RoundedSouth: {
1546
x1 += firstTab ? borderThinkness : 0;
1547
x2 -= lastTab ? borderThinkness : 0;
1551
p->setPen(background);
1552
p->drawLine(x1, y1 + 1, x2, y1 + 1);
1553
p->drawLine(x1, y1, x2, y1);
1556
if (firstTab || selected || onlyOne || !previousSelected) {
1558
p->drawLine(x1, y2 - 2, x1, y1 + (firstTab && selected && leftAligned ? 0 : borderThinkness));
1559
p->drawPoint(x1 + 1, y2 - 1);
1560
p->setPen(midlight);
1561
p->drawLine(x1 + 1, y2 - 2, x1 + 1, y1 + (firstTab && selected && leftAligned ? 0 : borderThinkness));
1565
int beg = x1 + (previousSelected ? 0 : 2);
1566
int end = x2 - (nextSelected ? 0 : 2);
1568
p->drawLine(beg, y2, end, y2);
1570
p->drawLine(beg, y2 - 1, end, y2 - 1);
1573
if (lastTab || selected || onlyOne || !nextSelected) {
1575
p->drawLine(x2, y2 - 2, x2, y1 + (lastTab && selected && rightAligned ? 0 : borderThinkness));
1576
p->drawPoint(x2 - 1, y2 - 1);
1578
p->drawLine(x2 - 1, y2 - 2, x2 - 1, y1 + (lastTab && selected && rightAligned ? 0 : borderThinkness));
1581
case QTabBar::RoundedWest: {
1584
y1 += firstTab ? borderThinkness : 0;
1585
y2 -= lastTab ? borderThinkness : 0;
1589
p->setPen(background);
1590
p->drawLine(x2 - 1, y1, x2 - 1, y2);
1591
p->drawLine(x2, y1, x2, y2);
1594
if (firstTab || selected || onlyOne || !previousSelected) {
1596
p->drawLine(x1 + 2, y1, x2 - (firstTab && selected && leftAligned ? 0 : borderThinkness), y1);
1597
p->drawPoint(x1 + 1, y1 + 1);
1598
p->setPen(midlight);
1599
p->drawLine(x1 + 2, y1 + 1, x2 - (firstTab && selected && leftAligned ? 0 : borderThinkness), y1 + 1);
1603
int beg = y1 + (previousSelected ? 0 : 2);
1604
int end = y2 - (nextSelected ? 0 : 2);
1606
p->drawLine(x1, beg, x1, end);
1607
p->setPen(midlight);
1608
p->drawLine(x1 + 1, beg, x1 + 1, end);
1611
if (lastTab || selected || onlyOne || !nextSelected) {
1613
p->drawLine(x1 + 3, y2, x2 - (lastTab && selected && rightAligned ? 0 : borderThinkness), y2);
1614
p->drawPoint(x1 + 2, y2 - 1);
1616
p->drawLine(x1 + 3, y2 - 1, x2 - (lastTab && selected && rightAligned ? 0 : borderThinkness), y2 - 1);
1617
p->drawPoint(x1 + 1, y2 - 1);
1618
p->drawPoint(x1 + 2, y2);
1621
case QTabBar::RoundedEast: {
1624
y1 += firstTab ? borderThinkness : 0;
1625
y2 -= lastTab ? borderThinkness : 0;
1629
p->setPen(background);
1630
p->drawLine(x1 + 1, y1, x1 + 1, y2);
1631
p->drawLine(x1, y1, x1, y2);
1634
if (firstTab || selected || onlyOne || !previousSelected) {
1636
p->drawLine(x2 - 2, y1, x1 + (firstTab && selected && leftAligned ? 0 : borderThinkness), y1);
1637
p->drawPoint(x2 - 1, y1 + 1);
1638
p->setPen(midlight);
1639
p->drawLine(x2 - 3, y1 + 1, x1 + (firstTab && selected && leftAligned ? 0 : borderThinkness), y1 + 1);
1640
p->drawPoint(x2 - 1, y1);
1644
int beg = y1 + (previousSelected ? 0 : 2);
1645
int end = y2 - (nextSelected ? 0 : 2);
1647
p->drawLine(x2, beg, x2, end);
1649
p->drawLine(x2 - 1, beg, x2 - 1, end);
1652
if (lastTab || selected || onlyOne || !nextSelected) {
1654
p->drawLine(x2 - 2, y2, x1 + (lastTab && selected && rightAligned ? 0 : borderThinkness), y2);
1655
p->drawPoint(x2 - 1, y2 - 1);
1657
p->drawLine(x2 - 2, y2 - 1, x1 + (lastTab && selected && rightAligned ? 0 : borderThinkness), y2 - 1);
1664
qDrawShadePanel(p, opt->rect, opt->palette,
1665
opt->state & (State_Sunken | State_On), 1,
1666
&opt->palette.brush(QPalette::Button));
1669
QPen oldPen = p->pen();
1670
p->setPen(opt->palette.light().color());
1671
if (opt->state & State_Horizontal) {
1672
p->drawLine(opt->rect.x() + 1, opt->rect.y(), opt->rect.x() + 1, opt->rect.height());
1673
p->setPen(opt->palette.dark().color());
1674
p->drawLine(opt->rect.x(), opt->rect.y(), opt->rect.x(), opt->rect.height());
1675
p->drawLine(opt->rect.right() - 1, opt->rect.y(), opt->rect.right() - 1,
1676
opt->rect.height());
1677
p->setPen(opt->palette.shadow().color());
1678
p->drawLine(opt->rect.right(), opt->rect.y(), opt->rect.right(), opt->rect.height());
1680
p->drawLine(opt->rect.x(), opt->rect.y() + 1, opt->rect.width(), opt->rect.y() + 1);
1681
p->setPen(opt->palette.dark().color());
1682
p->drawLine(opt->rect.x(), opt->rect.bottom() - 1, opt->rect.width(),
1683
opt->rect.bottom() - 1);
1684
p->setPen(opt->palette.shadow().color());
1685
p->drawLine(opt->rect.x(), opt->rect.bottom(), opt->rect.width(), opt->rect.bottom());
1689
case CE_ScrollBarSubLine:
1690
case CE_ScrollBarAddLine: {
1691
if (use2000style && (opt->state & State_Sunken)) {
1692
p->setPen(opt->palette.dark().color());
1693
p->setBrush(opt->palette.brush(QPalette::Button));
1694
p->drawRect(opt->rect.adjusted(0, 0, -1, -1));
1696
QStyleOption buttonOpt = *opt;
1697
if (!(buttonOpt.state & State_Sunken))
1698
buttonOpt.state |= State_Raised;
1699
drawPrimitive(PE_PanelButtonBevel, &buttonOpt, p, widget);
1701
PrimitiveElement arrow;
1702
if (opt->state & State_Horizontal) {
1703
if (ce == CE_ScrollBarAddLine)
1704
arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowRight : PE_IndicatorArrowLeft;
1706
arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
1708
if (ce == CE_ScrollBarAddLine)
1709
arrow = PE_IndicatorArrowDown;
1711
arrow = PE_IndicatorArrowUp;
1713
drawPrimitive(arrow, opt, p, widget);
1715
case CE_ScrollBarAddPage:
1716
case CE_ScrollBarSubPage: {
1718
QBrush bg = p->background();
1719
Qt::BGMode bg_mode = p->backgroundMode();
1720
p->setPen(Qt::NoPen);
1721
p->setBackgroundMode(Qt::OpaqueMode);
1723
if (opt->state & State_Sunken) {
1724
br = QBrush(opt->palette.shadow().color(), Qt::Dense4Pattern);
1725
p->setBackground(opt->palette.dark().color());
1726
p->setBrush(QBrush(opt->palette.shadow().color(), Qt::Dense4Pattern));
1728
QPixmap pm = opt->palette.brush(QPalette::Light).texture();
1729
br = !pm.isNull() ? QBrush(pm) : QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
1730
p->setBackground(opt->palette.background().color());
1733
p->drawRect(opt->rect);
1734
p->setBackground(bg);
1735
p->setBackgroundMode(bg_mode);
1737
case CE_ScrollBarSlider:
1738
if (!(opt->state & State_Enabled)) {
1739
QPixmap pm = opt->palette.brush(QPalette::Light).texture();
1740
QBrush br = !pm.isNull() ? QBrush(pm) : QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
1741
p->setPen(Qt::NoPen);
1743
p->setBackgroundMode(Qt::OpaqueMode);
1744
p->drawRect(opt->rect);
1746
QStyleOptionButton buttonOpt;
1747
buttonOpt.QStyleOption::operator=(*opt);
1748
buttonOpt.state = State_Enabled | State_Raised;
1749
drawPrimitive(PE_PanelButtonBevel, &buttonOpt, p, widget);
1752
case CE_HeaderSection: {
1754
if (opt->state & State_On)
1755
fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
1757
fill = opt->palette.brush(QPalette::Button);
1759
if (opt->state & (State_Raised | State_Sunken)) {
1760
qDrawWinButton(p, opt->rect, opt->palette, opt->state & State_Sunken, &fill);
1762
p->fillRect(opt->rect, fill);
1766
QCommonStyle::drawControl(ce, opt, p, widget);
1771
QRect QWindowsStyle::subElementRect(SubElement sr, const QStyleOption *opt, const QWidget *w) const
1775
case SE_SliderFocusRect:
1776
case SE_ToolBoxTabContents:
1777
r = visualRect(opt->direction, opt->rect, opt->rect);
1780
r = QCommonStyle::subElementRect(sr, opt, w);
1785
Q_GLOBAL_STATIC_WITH_ARGS(QBitmap, globalVerticalLine, (1, 129))
1786
Q_GLOBAL_STATIC_WITH_ARGS(QBitmap, globalHorizontalLine, (128, 1))
1789
void QWindowsStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt,
1790
QPainter *p, const QWidget *widget) const
1794
if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
1795
int thickness = pixelMetric(PM_SliderControlThickness, slider, widget);
1796
int len = pixelMetric(PM_SliderLength, slider, widget);
1797
int ticks = slider->tickPosition;
1798
QRect groove = QCommonStyle::subControlRect(CC_Slider, slider,
1799
SC_SliderGroove, widget);
1800
QRect handle = QCommonStyle::subControlRect(CC_Slider, slider,
1801
SC_SliderHandle, widget);
1803
if ((slider->subControls & SC_SliderGroove) && groove.isValid()) {
1804
int mid = thickness / 2;
1806
if (ticks & QSlider::TicksAbove)
1808
if (ticks & QSlider::TicksBelow)
1811
p->setPen(slider->palette.shadow().color());
1812
if (slider->orientation == Qt::Horizontal) {
1813
qDrawWinPanel(p, groove.x(), groove.y() + mid - 2,
1814
groove.width(), 4, slider->palette, true);
1815
p->drawLine(groove.x() + 1, groove.y() + mid - 1,
1816
groove.x() + groove.width() - 3, groove.y() + mid - 1);
1818
qDrawWinPanel(p, groove.x() + mid - 2, groove.y(),
1819
4, groove.height(), slider->palette, true);
1820
p->drawLine(groove.x() + mid - 1, groove.y() + 1,
1821
groove.x() + mid - 1, groove.y() + groove.height() - 3);
1825
if (slider->subControls & SC_SliderTickmarks) {
1826
QStyleOptionSlider tmpSlider = *slider;
1827
tmpSlider.subControls = SC_SliderTickmarks;
1828
QCommonStyle::drawComplexControl(cc, &tmpSlider, p, widget);
1831
if (slider->subControls & SC_SliderHandle) {
1841
const QColor c0 = slider->palette.shadow().color();
1842
const QColor c1 = slider->palette.dark().color();
1843
// const QColor c2 = g.button();
1844
const QColor c3 = slider->palette.midlight().color();
1845
const QColor c4 = slider->palette.light().color();
1847
int x = handle.x(), y = handle.y(),
1848
wi = handle.width(), he = handle.height();
1855
Qt::Orientation orient = slider->orientation;
1856
bool tickAbove = slider->tickPosition == QSlider::TicksAbove;
1857
bool tickBelow = slider->tickPosition == QSlider::TicksBelow;
1859
if (slider->state & State_HasFocus) {
1860
QStyleOptionFocusRect fropt;
1861
fropt.QStyleOption::operator=(*slider);
1862
fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
1863
drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
1866
if ((tickAbove && tickBelow) || (!tickAbove && !tickBelow)) {
1867
qDrawWinButton(p, QRect(x, y, wi, he), slider->palette, false,
1868
&slider->palette.brush(QPalette::Button));
1872
QSliderDirection dir;
1874
if (orient == Qt::Horizontal)
1891
d = (wi + 1) / 2 - 1;
1892
a.setPoints(5, x1,y1, x1,y2, x2,y2, x2,y1, x1+d,y1-d);
1896
d = (wi + 1) / 2 - 1;
1897
a.setPoints(5, x1,y1, x1,y2, x1+d,y2+d, x2,y2, x2,y1);
1900
d = (he + 1) / 2 - 1;
1902
a.setPoints(5, x1,y1, x1-d,y1+d, x1,y2, x2,y2, x2,y1);
1905
d = (he + 1) / 2 - 1;
1907
a.setPoints(5, x1,y1, x1,y2, x2,y2, x2+d,y1+d, x2,y1);
1911
QBrush oldBrush = p->brush();
1912
p->setBrush(slider->palette.brush(QPalette::Button));
1913
p->setPen(Qt::NoPen);
1914
p->drawRect(x1, y1, x2-x1+1, y2-y1+1);
1916
p->setBrush(oldBrush);
1920
p->drawLine(x1, y1, x2, y1);
1922
p->drawLine(x1, y1+1, x2, y1+1);
1924
if (dir != SlLeft) {
1926
p->drawLine(x1+1, y1+1, x1+1, y2);
1928
p->drawLine(x1, y1, x1, y2);
1930
if (dir != SlRight) {
1932
p->drawLine(x2, y1, x2, y2);
1934
p->drawLine(x2-1, y1+1, x2-1, y2-1);
1936
if (dir != SlDown) {
1938
p->drawLine(x1, y2, x2, y2);
1940
p->drawLine(x1+1, y2-1, x2-1, y2-1);
1946
p->drawLine(x1, y1, x1+d, y1-d);
1949
p->drawLine(x2, y1, x2-d, y1-d);
1952
p->drawLine(x1+1, y1, x1+1+d, y1-d);
1954
p->drawLine(x2-1, y1, x2-1-d, y1-d);
1958
p->drawLine(x1, y2, x1+d, y2+d);
1961
p->drawLine(x2, y2, x2-d, y2+d);
1964
p->drawLine(x1+1, y2, x1+1+d, y2+d);
1966
p->drawLine(x2-1, y2, x2-1-d, y2+d);
1970
p->drawLine(x1, y1, x1-d, y1+d);
1973
p->drawLine(x1, y2, x1-d, y2-d);
1976
p->drawLine(x1, y1+1, x1-d, y1+1+d);
1978
p->drawLine(x1, y2-1, x1-d, y2-1-d);
1982
p->drawLine(x2, y1, x2+d, y1+d);
1985
p->drawLine(x2, y2, x2+d, y2-d);
1988
p->drawLine(x2, y1+1, x2+d, y1+1+d);
1990
p->drawLine(x2, y2-1, x2+d, y2-1-d);
1997
if (const QStyleOptionQ3ListView *lv = qstyleoption_cast<const QStyleOptionQ3ListView *>(opt)) {
1999
if (lv->subControls & SC_Q3ListView)
2000
QCommonStyle::drawComplexControl(cc, lv, p, widget);
2001
if (lv->subControls & (SC_Q3ListViewBranch | SC_Q3ListViewExpand)) {
2002
if (lv->items.isEmpty())
2004
QStyleOptionQ3ListViewItem item = lv->items.at(0);
2005
int y = lv->rect.y();
2009
if ((lv->activeSubControls & SC_All) && (lv->subControls & SC_Q3ListViewExpand)) {
2012
dotlines[0] = QPoint(lv->rect.right(), lv->rect.top());
2013
dotlines[1] = QPoint(lv->rect.right(), lv->rect.bottom());
2015
int linetop = 0, linebot = 0;
2016
// each branch needs at most two lines, ie. four end points
2017
dotoffset = (item.itemY + item.height - y) % 2;
2018
dotlines.resize(item.childCount * 4);
2021
// skip the stuff above the exposed rectangle
2022
for (i = 1; i < lv->items.size(); ++i) {
2023
QStyleOptionQ3ListViewItem child = lv->items.at(i);
2024
if (child.height + y > 0)
2026
y += child.totalHeight;
2028
int bx = lv->rect.width() / 2;
2030
// paint stuff in the magical area
2031
while (i < lv->items.size() && y < lv->rect.height()) {
2032
QStyleOptionQ3ListViewItem child = lv->items.at(i);
2033
if (child.features & QStyleOptionQ3ListViewItem::Visible) {
2035
if (!(item.features & QStyleOptionQ3ListViewItem::MultiLine))
2038
lh = p->fontMetrics().height() + 2 * lv->itemMargin;
2039
lh = qMax(lh, QApplication::globalStrut().height());
2042
linebot = y + lh / 2;
2043
if (child.features & QStyleOptionQ3ListViewItem::Expandable
2044
|| child.childCount > 0 && child.height > 0) {
2046
p->setPen(lv->palette.mid().color());
2047
p->drawRect(bx - 4, linebot - 4, 8, 8);
2049
p->setPen(lv->palette.text().color());
2050
p->drawLine(bx - 2, linebot, bx + 2, linebot);
2051
if (!(child.state & State_Open))
2052
p->drawLine(bx, linebot - 2, bx, linebot + 2);
2054
p->setPen(lv->palette.mid().color());
2055
dotlines[c++] = QPoint(bx, linetop);
2056
dotlines[c++] = QPoint(bx, linebot - 4);
2057
dotlines[c++] = QPoint(bx + 5, linebot);
2058
dotlines[c++] = QPoint(lv->rect.width(), linebot);
2059
linetop = linebot + 5;
2062
dotlines[c++] = QPoint(bx+1, linebot -1);
2063
dotlines[c++] = QPoint(lv->rect.width(), linebot -1);
2065
y += child.totalHeight;
2070
// Expand line height to edge of rectangle if there's any
2071
// visible child below
2072
while (i < lv->items.size() && lv->items.at(i).height <= 0)
2074
if (i < lv->items.size())
2075
linebot = lv->rect.height();
2077
if (linetop < linebot) {
2078
dotlines[c++] = QPoint(bx, linetop);
2079
dotlines[c++] = QPoint(bx, linebot);
2082
p->setPen(lv->palette.text().color());
2083
QBitmap *verticalLine = globalVerticalLine();
2084
QBitmap *horizontalLine = globalHorizontalLine();
2085
static bool isInit = false;
2088
// make 128*1 and 1*128 bitmaps that can be used for
2089
// drawing the right sort of lines.
2090
verticalLine->clear();
2091
horizontalLine->clear();
2094
p.begin(verticalLine);
2095
for(i = 0; i < 64; ++i)
2096
a.setPoint(i, 0, i * 2 + 1);
2097
p.setPen(Qt::color1);
2100
QApplication::flush();
2101
verticalLine->setMask(*verticalLine);
2102
p.begin(horizontalLine);
2103
for(i = 0; i < 64; ++i)
2104
a.setPoint(i, i * 2 + 1, 0);
2105
p.setPen(Qt::color1);
2108
QApplication::flush();
2109
horizontalLine->setMask(*horizontalLine);
2112
int line; // index into dotlines
2113
if (lv->subControls & SC_Q3ListViewBranch) for(line = 0; line < c; line += 2) {
2114
// assumptions here: lines are horizontal or vertical.
2115
// lines always start with the numerically lowest
2118
// point ... relevant coordinate of current point
2119
// end ..... same coordinate of the end of the current line
2120
// other ... the other coordinate of the current point/line
2121
if (dotlines[line].y() == dotlines[line+1].y()) {
2122
int end = dotlines[line + 1].x();
2123
int point = dotlines[line].x();
2124
int other = dotlines[line].y();
2125
while (point < end) {
2127
if (i + point > end)
2129
p->drawPixmap(point, other, *horizontalLine, 0, 0, i, 1);
2133
int end = dotlines[line + 1].y();
2134
int point = dotlines[line].y();
2135
int other = dotlines[line].x();
2136
int pixmapoffset = ((point & 1) != dotoffset) ? 1 : 0;
2137
while(point < end) {
2139
if (i + point > end)
2141
p->drawPixmap(other, point, *verticalLine, 0, pixmapoffset, 1, i);
2150
if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
2151
if (cmb->subControls & SC_ComboBoxArrow) {
2152
State flags = State_None;
2154
QBrush editBrush = (cmb->state & State_Enabled) ? cmb->palette.brush(QPalette::Base)
2155
: cmb->palette.brush(QPalette::Background);
2157
qDrawWinPanel(p, opt->rect, opt->palette, true, &editBrush);
2159
p->fillRect(opt->rect, editBrush);
2161
QRect ar = subControlRect(CC_ComboBox, cmb, SC_ComboBoxArrow, widget);
2162
if (cmb->activeSubControls == SC_ComboBoxArrow) {
2163
p->setPen(cmb->palette.dark().color());
2164
p->setBrush(cmb->palette.brush(QPalette::Button));
2165
p->drawRect(ar.adjusted(0,0,-1,-1));
2167
qDrawWinPanel(p, ar, cmb->palette, false,
2168
&cmb->palette.brush(QPalette::Button));
2171
ar.adjust(2, 2, -2, -2);
2172
if (opt->state & State_Enabled)
2173
flags |= State_Enabled;
2175
if (cmb->activeSubControls == SC_ComboBoxArrow)
2176
flags |= State_Sunken;
2177
QStyleOption arrowOpt(0);
2179
arrowOpt.palette = cmb->palette;
2180
arrowOpt.state = flags;
2181
drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, widget);
2183
if (cmb->subControls & SC_ComboBoxEditField) {
2184
QRect re = subControlRect(CC_ComboBox, cmb, SC_ComboBoxEditField, widget);
2185
if (cmb->state & State_HasFocus && !cmb->editable)
2186
p->fillRect(re.x(), re.y(), re.width(), re.height(),
2187
cmb->palette.brush(QPalette::Highlight));
2189
if (cmb->state & State_HasFocus) {
2190
p->setPen(cmb->palette.highlightedText().color());
2191
p->setBackground(cmb->palette.highlight());
2194
p->setPen(cmb->palette.text().color());
2195
p->setBackground(cmb->palette.background());
2198
if (cmb->state & State_HasFocus && !cmb->editable) {
2199
QStyleOptionFocusRect focus;
2200
focus.QStyleOption::operator=(*cmb);
2201
focus.rect = subElementRect(SE_ComboBoxFocusRect, cmb, widget);
2202
focus.state |= State_FocusAtBorder;
2203
focus.backgroundColor = cmb->palette.highlight().color();
2204
drawPrimitive(PE_FrameFocusRect, &focus, p, widget);
2210
QCommonStyle::drawComplexControl(cc, opt, p, widget);
2215
QSize QWindowsStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
2216
const QSize &csz, const QWidget *widget) const
2221
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
2222
sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
2226
if (btn->features & QStyleOptionButton::AutoDefaultButton)
2227
defwidth = 2 * pixelMetric(PM_ButtonDefaultIndicator, btn, widget);
2228
if (w < 75 + defwidth && btn->icon.isNull())
2230
if (h < 23 + defwidth)
2236
if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
2238
sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
2239
if (mi->menuItemType != QStyleOptionMenuItem::Separator && !mi->icon.isNull())
2240
sz.setHeight(qMax(sz.height(),
2241
mi->icon.pixmap(pixelMetric(PM_SmallIconSize), QIcon::Normal).height()
2242
+ 2 * windowsItemFrame));
2243
int maxpmw = mi->maxIconWidth;
2244
int tabSpacing = use2000style ? 20 :windowsTabSpacing;
2245
if (mi->text.contains('\t'))
2247
else if (mi->menuItemType == QStyleOptionMenuItem::SubMenu)
2248
w += 2 * windowsArrowHMargin;
2249
else if (mi->menuItemType == QStyleOptionMenuItem::DefaultItem) {
2250
// adjust the font and add the difference in size.
2251
// it would be better if the font could be adjusted in the getStyleOptions qmenu func!!
2252
QFontMetrics fm(mi->font);
2253
QFont fontBold = mi->font;
2254
fontBold.setBold(true);
2255
QFontMetrics fmBold(fontBold);
2256
w += fmBold.width(mi->text) - fm.width(mi->text);
2259
int checkcol = qMax(maxpmw, use2000style ? 20 : windowsCheckMarkWidth); // Windows always shows a check column
2261
w += windowsRightBorder + 10;
2265
case CT_MenuBarItem:
2267
sz += QSize(windowsItemHMargin * 5 + 1, windowsItemVMargin * 2);
2270
sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);