1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the QtGui module of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:LGPL$
9
** Commercial License Usage
10
** Licensees holding valid commercial Qt licenses may use this file in
11
** accordance with the commercial license agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and Digia. For licensing terms and
14
** conditions see http://qt.digia.com/licensing. For further information
15
** use the contact form at http://qt.digia.com/contact-us.
17
** GNU Lesser General Public License Usage
18
** Alternatively, this file may be used under the terms of the GNU Lesser
19
** General Public License version 2.1 as published by the Free Software
20
** Foundation and appearing in the file LICENSE.LGPL included in the
21
** packaging of this file. Please review the following information to
22
** ensure the GNU Lesser General Public License version 2.1 requirements
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25
** In addition, as a special exception, Digia gives you certain additional
26
** rights. These rights are described in the Digia Qt LGPL Exception
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29
** GNU General Public License Usage
30
** Alternatively, this file may be used under the terms of the GNU
31
** General Public License version 3.0 as published by the Free Software
32
** Foundation and appearing in the file LICENSE.GPL included in the
33
** packaging of this file. Please review the following information to
34
** ensure the GNU General Public License version 3.0 requirements will be
35
** met: http://www.gnu.org/copyleft/gpl.html.
40
****************************************************************************/
42
#include "qwindowscestyle_p.h"
44
#if !defined(QT_NO_STYLE_WINDOWSCE) || defined(QT_PLUGIN)
46
#include "qpainterpath.h"
47
#include "qapplication.h"
48
#include "qdockwidget.h"
50
#include "qpaintengine.h"
52
#include "qstyleoption.h"
53
#include "qwindowscestyle_p_p.h"
55
#include "qdrawutil.h"
59
static const int windowsItemFrame = 2; // menu item frame width
60
static const int windowsItemHMargin = 3; // menu item hor text margin
61
static const int windowsItemVMargin = 2; // menu item ver text margin
62
static const int windowsArrowHMargin = 6; // arrow horizontal margin
63
static const int windowsRightBorder = 15; // right border on windows
64
static const int windowsCheckMarkWidth = 14; // checkmarks width on windows
66
static const int windowsCEitemViewCheckBoxSize = 14;
67
static const int windowsCEFrameGroupBoxOffset = 9;
68
static const int windowsCEIndicatorSize = 14;
69
static const int windowsCEExclusiveIndicatorSize = 14;
70
static const int windowsCESliderThickness = 24;
71
static const int windowsCEIconSize = 16;
73
static const QColor windowsCECheckBoxGradientColorBegin = QColor(222, 224, 214);
74
static const QColor windowsCECheckBoxGradientColorEnd = QColor(255, 255, 255);
76
enum QSliderDirection { SlUp, SlDown, SlLeft, SlRight };
78
QWindowsCEStyle::QWindowsCEStyle() : QWindowsStyle() {
79
qApp->setEffectEnabled(Qt::UI_FadeMenu, false);
80
qApp->setEffectEnabled(Qt::UI_AnimateMenu, false);
83
QWindowsCEStyle::~QWindowsCEStyle()
87
void QWindowsCEStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option,
88
QPainter *painter, const QWidget *widget) const {
90
bool doRestore = false;
91
QRect rect = option->rect;
94
case PE_PanelButtonTool: {
97
(widget && qobject_cast<QToolBar*>(widget->parentWidget())) ||
99
#ifndef QT_NO_DOCKWIDGET
100
(widget && widget->inherits("QDockWidgetTitleButton")) ||
102
(option->state & (State_Sunken | State_On)))
103
QWindowsCEStylePrivate::drawWinCEButton(painter, option->rect.adjusted(0, 0, 0, 0),
104
option->palette, option->state & (State_Sunken | State_On),
105
&option->palette.button());
106
if (option->state & (State_On)){
107
QBrush fill = QBrush(option->palette.midlight().color(), Qt::Dense4Pattern);
108
painter->fillRect(option->rect.adjusted(windowsItemFrame , windowsItemFrame ,
109
-windowsItemFrame , -windowsItemFrame ), fill);
112
case PE_IndicatorButtonDropDown:
113
QWindowsCEStylePrivate::drawWinCEButton(painter, option->rect, option->palette,
114
option->state & (State_Sunken | State_On),
115
&option->palette.brush(QPalette::Button));
118
case PE_IndicatorTabTear:
119
if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
120
bool rtl = tab->direction == Qt::RightToLeft;
121
QRect rect = tab->rect;
123
rect.setTop(rect.top() + ((tab->state & State_Selected) ? 1 : 3));
124
rect.setBottom(rect.bottom() - ((tab->state & State_Selected) ? 0 : 2));
125
path.moveTo(QPoint(rtl ? rect.right() : rect.left(), rect.top()));
127
for(int jags = 1; jags <= count; ++jags, rtl = !rtl)
128
path.lineTo(QPoint(rtl ? rect.left() : rect.right(), rect.top() + jags * rect.height()/count));
130
painter->setPen(QPen(tab->palette.light(), qreal(.8)));
131
painter->setBrush(tab->palette.background());
132
painter->setRenderHint(QPainter::Antialiasing);
133
painter->drawPath(path);
136
#endif //QT_NO_TABBAR
137
#ifndef QT_NO_TOOLBAR
138
case PE_IndicatorToolBarSeparator:
139
//nothing to draw on WindowsCE
141
case PE_IndicatorToolBarHandle:
143
painter->translate(option->rect.x(), option->rect.y());
144
if (option->state & State_Horizontal) {
145
int x = option->rect.width() / 2 - 4;
146
if (QApplication::layoutDirection() == Qt::RightToLeft)
148
if (option->rect.height() > 4) {
149
QWindowsCEStylePrivate::drawWinCEButton(painter,x - 1, 0, 7, option->rect.height(),
150
option->palette, false, 0);
151
QWindowsCEStylePrivate::drawWinCEPanel(painter, x, 1, 3, option->rect.height() - 1,
152
option->palette, false, 0);
153
QWindowsCEStylePrivate::drawWinCEPanel(painter, x + 3, 1, 3, option->rect.height() - 1,
154
option->palette, false, 0);
155
painter->setPen(option->palette.button().color());
156
painter->drawLine(x + 4, 2, x + 4,option->rect.height() - 2);
159
if (option->rect.width() > 4) {
160
int y = option->rect.height() / 2 - 4;
161
QWindowsCEStylePrivate::drawWinCEPanel(painter, 2, y, option->rect.width() - 2, 3,
162
option->palette, false, 0);
163
QWindowsCEStylePrivate::drawWinCEPanel(painter, 2, y + 3, option->rect.width() - 2, 3,
164
option->palette, false, 0);
170
#endif // QT_NO_TOOLBAR
171
case PE_FrameButtonTool: {
172
#ifndef QT_NO_DOCKWIDGET
173
if (widget && widget->inherits("QDockWidgetTitleButton")) {
174
if (const QDockWidget *dw = qobject_cast<const QDockWidget *>(widget->parent()))
175
if (dw->isFloating()){
176
QWindowsCEStylePrivate::drawWinCEButton(painter, option->rect.adjusted(1, 1, 0, 0),
177
option->palette, option->state & (State_Sunken | State_On),
178
&option->palette.button());
182
#endif // QT_NO_DOCKWIDGET
185
bool panel = (element == PE_PanelButtonTool);
186
if ((!(option->state & State_Sunken ))
187
&& (!(option->state & State_Enabled)
188
|| ((option->state & State_Enabled ) && !(option->state & State_MouseOver)))
189
&& (option->state & State_On)) {
190
fill = QBrush(option->palette.light().color(), Qt::Dense4Pattern);
193
fill = option->palette.brush(QPalette::Button);
196
if (option->state & (State_Raised | State_Sunken | State_On)) {
197
if (option->state & State_AutoRaise) {
198
if(option->state & (State_Enabled | State_Sunken | State_On)){
200
QWindowsCEStylePrivate::drawWinCEPanel(painter, option->rect, option->palette,
201
option->state & (State_Sunken | State_On), &fill);
203
qDrawShadeRect(painter, option->rect, option->palette,
204
option->state & (State_Sunken | State_On), 1);
207
painter->setPen(option->palette.button().color());
208
painter->drawRect(option->rect.adjusted(1, 1, -2, -2));
211
QWindowsCEStylePrivate::drawWinCEButton(painter, option->rect, option->palette,
212
option->state & (State_Sunken | State_On), panel ? &fill : 0);
215
painter->fillRect(option->rect, fill);
219
case PE_PanelButtonBevel: {
221
bool panel = element != PE_FrameButtonBevel;
222
painter->setBrushOrigin(option->rect.topLeft());
223
if (!(option->state & State_Sunken) && (option->state & State_On))
224
fill = QBrush(option->palette.light().color(), Qt::Dense4Pattern);
226
fill = option->palette.brush(QPalette::Button);
228
if (option->state & (State_Raised | State_On | State_Sunken)) {
229
QWindowsCEStylePrivate::drawWinCEButton(painter, option->rect, option->palette,
230
option->state & (State_Sunken | State_On),
231
panel ? &fill : 0); ;
234
painter->fillRect(option->rect, fill);
236
painter->drawRect(option->rect);
240
case PE_FrameGroupBox:
241
if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
242
QRect fr = frame->rect;
243
painter->setPen(frame->palette.shadow().color());
244
painter->drawRect(fr.x(), fr.y(), fr.x() + fr.width() - 1,
245
fr.y() + fr.height() - windowsCEFrameGroupBoxOffset);
249
case PE_IndicatorCheckBox: {
251
if (option->state & State_NoChange)
252
fill = QBrush(option->palette.base().color(), Qt::Dense4Pattern);
253
else if (option->state & State_Sunken)
254
fill = option->palette.button();
255
else if (option->state & State_Enabled)
256
fill = option->palette.base();
258
fill = option->palette.background();
261
painter->fillRect(option->rect,fill);
262
painter->setPen(option->palette.dark().color());
263
painter->drawRect(option->rect);
264
painter->setPen(option->palette.shadow().color());
265
painter->drawLine(option->rect.x() + 1,option->rect.y() + 1,
266
option->rect.x() + option->rect.width() - 1, option->rect.y() + 1);
267
painter->drawLine(option->rect.x() + 1,option->rect.y() + 1,
268
option->rect.x() + 1, option->rect.y() + option->rect.height() - 1);
271
case PE_IndicatorViewItemCheck: {
277
if (element == PE_IndicatorViewItemCheck) {
278
QLinearGradient linearGradient(QPoint(option->rect.x(),option->rect.y()), QPoint(option->rect.x()+option->rect.width(),
279
option->rect.y()+option->rect.height()));
280
linearGradient.setColorAt(0, windowsCECheckBoxGradientColorBegin);
281
linearGradient.setColorAt(1, windowsCECheckBoxGradientColorEnd);
282
painter->setBrush(linearGradient);
283
painter->setPen(Qt::NoPen);
284
if (option->state & State_NoChange)
285
painter->setBrush(option->palette.brush(QPalette::Button));
286
painter->setPen(option->palette.link().color());
287
painter->drawRect(option->rect.x(), option->rect.y(), windowsCEitemViewCheckBoxSize, windowsCEitemViewCheckBoxSize);
288
painter->setPen(option->palette.brightText().color());
291
if (!(option->state & State_Off)) {
294
xx = option->rect.x() + 4;
295
yy = option->rect.y() + 6;
296
for (i = 0; i < 4; ++i) {
297
lines[i] = QLineF(xx, yy, xx, yy + arrowSize);
302
for (i = 4; i < 9; ++i) {
303
lines[i] = QLineF(xx, yy, xx, yy + arrowSize);
307
painter->drawLines(lines, 9);
313
case PE_IndicatorRadioButton: {
314
QRect ir = option->rect;
316
painter->setPen(Qt::NoPen);
317
painter->setBrush(option->palette.light());
318
painter->drawEllipse(option->rect);
319
painter->setPen(option->palette.shadow().color());
320
painter->setBrush(option->palette.shadow().color());
321
painter->drawArc(option->rect, 0, 360 * 16);
322
painter->drawArc(option->rect.x() + 1, option->rect.y() + 1, option->rect.width() - 2,
323
option->rect.height() - 2, 40 * 16, 180 * 16);
324
painter->setPen(option->palette.light().color());
325
painter->drawPoint(option->rect.x() + 11, option->rect.y() + 3);
326
painter->drawPoint(option->rect.x() + 3,option->rect.y() + 3);
327
painter->setPen(option->palette.shadow().color());
328
painter->drawPoint(option->rect.x() +3,option->rect.y() + 12);
329
if (option->state & (State_Sunken | State_On)) {
330
painter->setPen(Qt::NoPen);
331
painter->setBrush(option->palette.text());
332
painter->drawEllipse(option->rect.x() +3,option->rect.y()+ 2,9,10);
336
case PE_PanelMenuBar:
338
painter->setPen(option->palette.shadow().color());
339
painter->drawRect(option->rect);
342
case PE_PanelButtonCommand:
343
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
345
State flags = option->state;
346
QPalette pal = option->palette;
347
QRect r = option->rect;
348
if (! (flags & State_Sunken) && (flags & State_On))
349
fill = QBrush(pal.light().color(), Qt::Dense4Pattern);
351
fill = pal.brush(QPalette::Button);
352
if (btn->features & QStyleOptionButton::DefaultButton && flags & State_Sunken) {
353
painter->setPen(pal.dark().color());
354
painter->setBrush(fill);
355
painter->drawRect(r.adjusted(0, 0, -1, -1));
356
} else if (flags & (State_Raised | State_Sunken | State_On | State_Sunken)) {
357
QWindowsCEStylePrivate::drawWinCEButton(painter, r, pal, flags & (State_Sunken | State_On),
360
painter->fillRect(r, fill);
365
case PE_FrameDefaultButton: {
366
painter->setPen(option->palette.shadow().color());
367
QRect rect = option->rect;
368
rect.adjust(0, 0, -1, -1);
369
painter->drawRect(rect);
371
case PE_IndicatorSpinPlus:
372
case PE_IndicatorSpinMinus: {
373
QRect r = option->rect;
374
int fw = pixelMetric(PM_DefaultFrameWidth, option, widget)+2;
375
QRect br = r.adjusted(fw, fw, -fw, -fw);
376
int offset = (option->state & State_Sunken) ? 1 : 0;
377
int step = (br.width() + 4) / 5;
378
painter->fillRect(br.x() + offset, br.y() + offset +br.height() / 2 - step / 2,
380
option->palette.buttonText());
381
if (element == PE_IndicatorSpinPlus)
382
painter->fillRect(br.x() + br.width() / 2 - step / 2 + offset, br.y() + offset+4,
384
option->palette.buttonText());
386
case PE_IndicatorSpinUp:
387
case PE_IndicatorSpinDown: {
391
case PE_IndicatorSpinUp:
392
points[0] = QPoint(-2, -4);
393
points[1] = QPoint(-2, 2);
394
points[2] = QPoint(-1, -3);
395
points[3] = QPoint(-1, 1);
396
points[4] = QPoint(0, -2);
397
points[5] = QPoint(0, 0);
398
points[6] = QPoint(1, -1);
400
case PE_IndicatorSpinDown:
401
points[0] = QPoint(0, -4);
402
points[1] = QPoint(0, 2);
403
points[2] = QPoint(-1, -3);
404
points[3] = QPoint(-1, 1);
405
points[4] = QPoint(-2, -2);
406
points[5] = QPoint(-2, 0);
407
points[6] = QPoint(-3, -1);
412
if (option->state & State_Sunken)
413
painter->translate(pixelMetric(PM_ButtonShiftHorizontal),
414
pixelMetric(PM_ButtonShiftVertical));
415
if (option->state & State_Enabled) {
416
painter->translate(option->rect.x() + option->rect.width() / 2,
417
option->rect.y() + option->rect.height() / 2);
418
painter->setPen(option->palette.buttonText().color());
419
painter->drawLine(points[0], points[1]);
420
painter->drawLine(points[2], points[3]);
421
painter->drawLine(points[4], points[5]);
422
painter->drawPoint(points[6]);
424
painter->translate(option->rect.x() + option->rect.width() / 2 + 1,
425
option->rect.y() + option->rect.height() / 2 + 1);
426
painter->setPen(option->palette.light().color());
427
painter->drawLine(points[0], points[1]);
428
painter->drawLine(points[2], points[3]);
429
painter->drawLine(points[4], points[5]);
430
painter->drawPoint(points[6]);
431
painter->translate(-1, -1);
432
painter->setPen(option->palette.mid().color());
433
painter->drawLine(points[0], points[1]);
434
painter->drawLine(points[2], points[3]);
435
painter->drawLine(points[4], points[5]);
436
painter->drawPoint(points[6]);
441
case PE_IndicatorArrowUp:
442
case PE_IndicatorArrowDown:
443
case PE_IndicatorArrowRight:
444
case PE_IndicatorArrowLeft: {
448
case PE_IndicatorArrowUp:
450
points[0] = QPoint(-4, 2);
451
points[1] = QPoint(4, 2);
452
points[2] = QPoint(-3, 1);
453
points[3] = QPoint(3, 1);
454
points[4] = QPoint(-2, 0);
455
points[5] = QPoint(2, 0);
456
points[6] = QPoint(-1, -1);
457
points[7] = QPoint(1, -1);
458
points[8] = QPoint(0, -2);
460
case PE_IndicatorArrowDown:
462
points[0] = QPoint(-4, -2);
463
points[1] = QPoint(4, -2);
464
points[2] = QPoint(-3, -1);
465
points[3] = QPoint(3, -1);
466
points[4] = QPoint(-2, 0);
467
points[5] = QPoint(2, 0);
468
points[6] = QPoint(-1, 1);
469
points[7] = QPoint(1, 1);
470
points[8] = QPoint(0, 2);
472
case PE_IndicatorArrowRight:
473
points[0] = QPoint(-3, -4);
474
points[1] = QPoint(-3, 4);
475
points[2] = QPoint(-2, -3);
476
points[3] = QPoint(-2, 3);
477
points[4] = QPoint(-1, -2);
478
points[5] = QPoint(-1, 2);
479
points[6] = QPoint(0, -1);
480
points[7] = QPoint(0, 1);
481
points[8] = QPoint(1, 0);
483
case PE_IndicatorArrowLeft:
484
points[0] = QPoint(1, -4);
485
points[1] = QPoint(1, 4);
486
points[2] = QPoint(0, -3);
487
points[3] = QPoint(0, 3);
488
points[4] = QPoint(-1, -2);
489
points[5] = QPoint(-1, 2);
490
points[6] = QPoint(-2, -1);
491
points[7] = QPoint(-2, 1);
492
points[8] = QPoint(-3, 0);
497
if (option->state & State_Sunken)
498
painter->translate(pixelMetric(PM_ButtonShiftHorizontal),
499
pixelMetric(PM_ButtonShiftVertical));
500
if (option->state & State_Enabled) {
501
painter->translate(option->rect.x() + option->rect.width() / 2,
502
option->rect.y() + option->rect.height() / 2);
503
painter->setPen(option->palette.buttonText().color());
504
painter->drawLine(points[0], points[1]);
505
painter->drawLine(points[2], points[3]);
506
painter->drawLine(points[4], points[5]);
507
painter->drawLine(points[6], points[7]);
508
painter->drawPoint(points[8]);
510
painter->translate(option->rect.x() + option->rect.width() / 2 + 1,
511
option->rect.y() + option->rect.height() / 2 + 1);
512
painter->setPen(option->palette.light().color());
513
painter->drawLine(points[0], points[1]);
514
painter->drawLine(points[2], points[3]);
515
painter->drawLine(points[4], points[5]);
516
painter->drawLine(points[6], points[7]);
517
painter->drawPoint(points[8]);
518
painter->translate(-1, -1);
519
painter->setPen(option->palette.mid().color());
520
painter->drawLine(points[0], points[1]);
521
painter->drawLine(points[2], points[3]);
522
painter->drawLine(points[4], points[5]);
523
painter->drawLine(points[6], points[7]);
524
painter->drawPoint(points[8]);
529
case PE_FrameWindow: {
530
QPalette popupPal = option->palette;
531
popupPal.setColor(QPalette::Light, option->palette.background().color());
532
popupPal.setColor(QPalette::Midlight, option->palette.light().color());
533
QWindowsCEStylePrivate::drawWinCEPanel(painter, option->rect, popupPal, option->state & State_Sunken);
538
if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
539
QPalette popupPal = frame->palette;
540
QRect r = frame->rect;
541
qDrawPlainRect(painter, r, frame->palette.shadow().color(),1);
544
case PE_FrameStatusBar:
545
QWindowsCEStylePrivate::drawWinCEPanel(painter, option->rect, option->palette, true, 0);
548
case PE_FrameTabWidget: {
549
QRect rect = option->rect;
550
QPalette pal = option->palette;
551
QWindowsCEStylePrivate::drawWinCEButton(painter, option->rect, option->palette, false, 0);
554
QWindowsStyle::drawPrimitive(element, option, painter, widget);
559
void QWindowsCEStyle::drawControl(ControlElement element, const QStyleOption *option,
560
QPainter *painter, const QWidget *widget) const {
563
case CE_MenuTearoff: {
564
if(option->state & State_Selected) {
565
if(pixelMetric(PM_MenuPanelWidth, option, widget) > 1)
566
qDrawShadePanel(painter, option->rect.x(), option->rect.y(), option->rect.width(),
567
option->rect.height(), option->palette, false, 2,
568
&option->palette.brush(QPalette::Button));
570
qDrawShadePanel(painter, option->rect.x() + 1, option->rect.y() + 1, option->rect.width() - 2,
571
option->rect.height() - 2, option->palette, true, 1, &option->palette.brush(QPalette::Button));
573
painter->fillRect(option->rect, option->palette.brush(QPalette::Button));
575
painter->setPen(QPen(option->palette.dark().color(), 1, Qt::DashLine));
576
painter->drawLine(option->rect.x()+2, option->rect.y()+option->rect.height()/2-1, option->rect.x()+option->rect.width()-4,
577
option->rect.y()+option->rect.height()/2-1);
578
painter->setPen(QPen(option->palette.light().color(), 1, Qt::DashLine));
579
painter->drawLine(option->rect.x()+2, option->rect.y()+option->rect.height()/2, option->rect.x()+option->rect.width()-4,
580
option->rect.y()+option->rect.height()/2);
585
if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
586
bool active = mbi->state & State_Selected;
587
bool hasFocus = mbi->state & State_HasFocus;
588
bool down = mbi->state & State_Sunken;
589
QStyleOptionMenuItem newMbi = *mbi;
590
if (active || hasFocus) {
591
QBrush b = mbi->palette.brush(QPalette::Highlight);
592
if (active && down) {
593
painter->fillRect(mbi->rect.adjusted(0, 1, 0, -1), b);
596
uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip
597
| Qt::TextSingleLine;
598
if (!styleHint(SH_UnderlineShortcut, mbi, widget))
599
alignment |= Qt::TextHideMnemonic;
602
QFont f = painter->font();
605
QPixmap pix = mbi->icon.pixmap(pixelMetric(PM_SmallIconSize),
606
(mbi->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled);
608
drawItemPixmap(painter,mbi->rect, alignment, pix);
611
drawItemText(painter, mbi->rect, alignment, mbi->palette, mbi->state & State_Enabled,
612
mbi->text, QPalette::Light);
614
drawItemText(painter, mbi->rect, alignment, mbi->palette, mbi->state & State_Enabled,
615
mbi->text, QPalette::ButtonText);
620
case CE_MenuBarEmptyArea:
622
painter->setPen(option->palette.shadow().color());
623
if (widget && !widget->testAttribute(Qt::WA_NoSystemBackground)) {
624
painter->eraseRect(option->rect);
625
QRect r = option->rect;
626
painter->drawLine(r.x() + 1, r.y() + 1, r.x()+ 1, r.y()+ r.height() - 2);
627
painter->drawLine(r.x() - 2 + r.width(), r.y() + 1, r.x() - 2 + r.width(), r.y() + r.height() - 2);
628
painter->drawLine(r.x() + 1, r.y() +1, r.x() - 1 + r.width(), r.y() + 1);
629
painter->drawLine(r.x() + 1, r.y() + r.height()-2 , r.x() - 2 + r.width(), r.y() + r.height() - 2);
635
if (const QStyleOptionMenuItem *menuitem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
637
menuitem->rect.getRect(&x, &y, &w, &h);
638
int tab = menuitem->tabWidth;
639
bool dis = !(menuitem->state & State_Enabled);
640
bool checked = menuitem->checkType != QStyleOptionMenuItem::NotCheckable
641
? menuitem->checked : false;
642
bool act = menuitem->state & State_Selected;
644
// windows always has a check column, regardless whether we have an icon or not
645
int checkcol = qMax(menuitem->maxIconWidth, windowsCheckMarkWidth);
646
QBrush fill = menuitem->palette.brush(act ? QPalette::Highlight : QPalette::Button);
647
painter->fillRect(menuitem->rect.adjusted(1, 1, 0, 0), fill);
649
if (menuitem->menuItemType == QStyleOptionMenuItem::Separator) {
650
int yoff = y-1 + h / 2;
651
painter->setPen(menuitem->palette.shadow().color());
652
painter->drawLine(x + 4, yoff + 1, x + w - 8, yoff + 1);
656
QRect vCheckRect = visualRect(option->direction, menuitem->rect, QRect(menuitem->rect.x(),
657
menuitem->rect.y(), checkcol, menuitem->rect.height()));
660
qDrawPlainRect(painter, vCheckRect,
661
menuitem->palette.button().color(), 1,
662
&menuitem->palette.brush(QPalette::Button));
664
QBrush fill(menuitem->palette.button().color(), Qt::Dense4Pattern);
665
qDrawPlainRect(painter, vCheckRect,menuitem->palette.button().color(), 1, &fill);
668
painter->fillRect(vCheckRect, menuitem->palette.brush(QPalette::Button));
670
// On Windows Style, if we have a checkable item and an icon we
671
// draw the icon recessed to indicate an item is checked. If we
672
// have no icon, we draw a checkmark instead.
673
if (!menuitem->icon.isNull()) {
674
QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
676
mode = QIcon::Active;
679
pixmap = menuitem->icon.pixmap(pixelMetric(PM_SmallIconSize), mode, QIcon::On);
681
pixmap = menuitem->icon.pixmap(pixelMetric(PM_SmallIconSize), mode);
682
int pixw = pixmap.width();
683
int pixh = pixmap.height();
684
if (act && !dis && !checked)
685
qDrawPlainRect(painter, vCheckRect, menuitem->palette.button().color(), 1,
686
&menuitem->palette.brush(QPalette::Button));
687
QRect pmr(0, 0, pixw, pixh);
688
pmr.moveCenter(vCheckRect.center());
689
painter->setPen(menuitem->palette.text().color());
690
painter->drawPixmap(pmr.topLeft(), pixmap);
691
} else if (checked) {
692
QStyleOptionMenuItem newMi = *menuitem;
693
newMi.state = State_None;
695
newMi.state |= State_Enabled;
697
newMi.state |= State_On;
698
newMi.rect = visualRect(option->direction, menuitem->rect, QRect(menuitem->rect.x()
699
+ windowsItemFrame, menuitem->rect.y() + windowsItemFrame,
700
checkcol - 2 * windowsItemFrame, menuitem->rect.height() - 2*windowsItemFrame));
701
drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, painter, widget);
703
painter->setPen(act ? menuitem->palette.highlightedText().color() : menuitem->palette.buttonText().color());
707
discol = menuitem->palette.text().color();
708
painter->setPen(discol);
710
int xm = windowsItemFrame + checkcol + windowsItemHMargin;
711
int xpos = menuitem->rect.x() + xm;
712
QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
713
QRect vTextRect = visualRect(option->direction, menuitem->rect, textRect);
714
QString s = menuitem->text;
715
if (!s.isEmpty()) { // draw text
717
int t = s.indexOf(QLatin1Char('\t'));
718
int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
719
if (!styleHint(SH_UnderlineShortcut, menuitem, widget))
720
text_flags |= Qt::TextHideMnemonic;
721
text_flags |= Qt::AlignLeft;
723
QRect vShortcutRect = visualRect(option->direction, menuitem->rect,
724
QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
726
painter->setPen(discol);
727
painter->drawText(vShortcutRect, text_flags, s.mid(t + 1));
730
QFont font = menuitem->font;
731
if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
733
painter->setFont(font);
735
painter->setPen(discol);
736
painter->drawText(vTextRect, text_flags, s.left(t));
739
if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow
740
int dim = (h - 2 * windowsItemFrame) / 2;
741
PrimitiveElement arrow;
742
arrow = (option->direction == Qt::RightToLeft) ? PE_IndicatorSpinDown : PE_IndicatorSpinUp;
743
xpos = x + w - windowsArrowHMargin - windowsItemFrame - dim;
744
QRect vSubMenuRect = visualRect(option->direction, menuitem->rect, QRect(xpos, y + h / 2 - dim / 2, dim, dim));
745
QStyleOptionMenuItem newMI = *menuitem;
746
newMI.rect = vSubMenuRect;
747
newMI.state = dis ? State_None : State_Enabled;
749
newMI.palette.setColor(QPalette::ButtonText,
750
newMI.palette.highlightedText().color());
751
drawPrimitive(arrow, &newMI, painter, widget);
757
painter->fillRect(option->rect, Qt::white);
759
case CE_MenuEmptyArea:
760
QWindowsStyle::drawControl(element,option, painter, widget);
765
if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
766
drawControl(CE_TabBarTabShape, tab, painter, widget);
767
drawControl(CE_TabBarTabLabel, tab, painter, widget);
770
case CE_TabBarTabShape:
771
if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
772
bool rtlHorTabs = (tab->direction == Qt::RightToLeft
773
&& (tab->shape == QTabBar::RoundedNorth
774
|| tab->shape == QTabBar::RoundedSouth));
775
bool selected = tab->state & State_Selected;
776
bool lastTab = ((!rtlHorTabs && tab->position == QStyleOptionTab::End)
778
&& tab->position == QStyleOptionTab::Beginning));
779
bool firstTab = ((!rtlHorTabs
780
&& tab->position == QStyleOptionTab::Beginning)
782
&& tab->position == QStyleOptionTab::End));
783
bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab;
784
bool previousSelected =
786
&& tab->selectedPosition == QStyleOptionTab::PreviousIsSelected)
788
&& tab->selectedPosition == QStyleOptionTab::NextIsSelected));
791
&& tab->selectedPosition == QStyleOptionTab::NextIsSelected)
793
&& tab->selectedPosition
794
== QStyleOptionTab::PreviousIsSelected));
795
int tabBarAlignment = styleHint(SH_TabBar_Alignment, tab, widget);
796
bool leftAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignLeft)
798
&& tabBarAlignment == Qt::AlignRight);
800
bool rightAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignRight)
802
&& tabBarAlignment == Qt::AlignLeft);
803
QColor light = tab->palette.light().color();
804
QColor midlight = tab->palette.midlight().color();
805
QColor dark = tab->palette.dark().color();
806
QColor shadow = tab->palette.shadow().color();
807
QColor background = tab->palette.background().color();
808
int borderThinkness = pixelMetric(PM_TabBarBaseOverlap, tab, widget);
810
borderThinkness /= 2;
811
QRect r2(option->rect);
815
int y2 = r2.bottom();
816
switch (tab->shape) {
818
QCommonStyle::drawControl(element, tab, painter, widget);
820
case QTabBar::RoundedNorth: {
823
x1 += firstTab ? borderThinkness : 0;
824
x2 -= lastTab ? borderThinkness : 0;
827
painter->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 2), tab->palette.background());
831
painter->setPen(background);
832
painter->drawLine(x1, y2 - 1, x2, y2 - 1);
833
painter->drawLine(x1, y2 + 1, x2, y2 + 1);
834
painter->drawLine(x1, y2, x2, y2);
837
if (firstTab || selected || onlyOne || !previousSelected) {
838
painter->setPen(dark);
839
painter->drawLine(x1, y1 + 2, x1, y2 - ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness));
840
painter->drawPoint(x1 + 1, y1 + 1);
841
painter->setPen(midlight);
842
painter->drawLine(x1 + 1, y1 + 2, x1 + 1, y2 -
843
((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness));
848
int beg = x1 + (previousSelected ? 0 : 2);
849
int end = x2 - (nextSelected ? 0 : 2);
850
painter->setPen(dark);
851
painter->drawLine(beg, y1, end, y1);
853
painter->setPen(midlight);
854
painter->drawLine(beg, y1 + 1, end, y1 + 1);
858
if (lastTab || selected || onlyOne || !nextSelected) {
859
painter->setPen(shadow);
860
painter->drawLine(x2, y1 + 2, x2, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
861
painter->drawPoint(x2 - 1, y1 + 1);
862
painter->setPen(dark);
863
painter->drawLine(x2 - 1, y1 + 2, x2 - 1, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
866
case QTabBar::RoundedSouth: {
869
x1 += firstTab ? borderThinkness : 0;
870
x2 -= lastTab ? borderThinkness : 0;
873
painter->fillRect(QRect(x1 + 1, y1 + 2, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.background());
877
painter->setPen(background);
878
painter->drawLine(x1, y1 + 1, x2 - 1, y1 + 1);
879
painter->drawLine(x1, y1 - 1, x2 - 1, y1 - 1);
880
painter->drawLine(x1, y1, x2 - 1, y1);
883
if (firstTab || selected || onlyOne || !previousSelected) {
884
painter->setPen(dark);
885
painter->drawLine(x1, y2 - 2, x1, y1 + ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness));
886
painter->drawPoint(x1 + 1, y2 - 1);
887
painter->setPen(midlight);
888
painter->drawLine(x1 + 1, y2 - 2, x1 + 1, y1 + ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness));
892
int beg = x1 + (previousSelected ? 0 : 2);
893
int end = x2 - (nextSelected ? 0 : 2);
894
painter->setPen(shadow);
895
painter->drawLine(beg, y2, end, y2);
896
painter->setPen(dark);
897
painter->drawLine(beg, y2 - 1, end, y2 - 1);
900
if (lastTab || selected || onlyOne || !nextSelected) {
901
painter->setPen(shadow);
902
painter->drawLine(x2, y2 - 2, x2, y1 + ((onlyOne || lastTab) && selected &&
903
rightAligned ? 0 : borderThinkness));
904
painter->drawPoint(x2 - 1, y2 - 1);
905
painter->setPen(dark);
906
painter->drawLine(x2 - 1, y2 - 2, x2 - 1, y1 + ((onlyOne || lastTab) && selected &&
907
rightAligned ? 0 : borderThinkness));
910
case QTabBar::RoundedWest: {
913
y1 += firstTab ? borderThinkness : 0;
914
y2 -= lastTab ? borderThinkness : 0;
917
painter->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 2, (y2 - y1) - 1), tab->palette.background());
921
painter->setPen(background);
922
painter->drawLine(x2 - 1, y1, x2 - 1, y2);
923
painter->drawLine(x2, y1, x2, y2);
926
if (firstTab || selected || onlyOne || !previousSelected) {
927
painter->setPen(dark);
928
painter->drawLine(x1 + 2, y1, x2 - ((onlyOne || firstTab) && selected &&
929
leftAligned ? 0 : borderThinkness), y1);
930
painter->drawPoint(x1 + 1, y1 + 1);
931
painter->setPen(midlight);
932
painter->drawLine(x1 + 2, y1 + 1, x2 - ((onlyOne || firstTab) && selected &&
933
leftAligned ? 0 : borderThinkness), y1 + 1);
937
int beg = y1 + (previousSelected ? 0 : 2);
938
int end = y2 - (nextSelected ? 0 : 2);
939
painter->setPen(dark);
940
painter->drawLine(x1, beg, x1, end);
941
painter->setPen(midlight);
942
painter->drawLine(x1 + 1, beg, x1 + 1, end);
945
if (lastTab || selected || onlyOne || !nextSelected) {
946
painter->setPen(shadow);
947
painter->drawLine(x1 + 3, y2, x2 - ((onlyOne || lastTab) && selected &&
948
rightAligned ? 0 : borderThinkness), y2);
949
painter->drawPoint(x1 + 2, y2 - 1);
950
painter->setPen(dark);
951
painter->drawLine(x1 + 3, y2 - 1, x2 - ((onlyOne || lastTab) && selected &&
952
rightAligned ? 0 : borderThinkness), y2 - 1);
953
painter->drawPoint(x1 + 1, y2 - 1);
954
painter->drawPoint(x1 + 2, y2);
957
case QTabBar::RoundedEast: {
960
y1 += firstTab ? borderThinkness : 0;
961
y2 -= lastTab ? borderThinkness : 0;
964
painter->fillRect(QRect(x1 + 2, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.background());
968
painter->setPen(background);
969
painter->drawLine(x1 + 1, y1, x1 + 1, y2 - 1);
970
painter->drawLine(x1, y1, x1, y2 - 1);
973
if (firstTab || selected || onlyOne || !previousSelected) {
974
painter->setPen(dark);
975
painter->drawLine(x2 - 2, y1, x1 + ((onlyOne || firstTab) && selected &&
976
leftAligned ? 0 : borderThinkness), y1);
977
painter->drawPoint(x2 - 1, y1 + 1);
978
painter->setPen(midlight);
979
painter->drawLine(x2 - 3, y1 + 1, x1 + ((onlyOne || firstTab) &&
980
selected && leftAligned ? 0 : borderThinkness), y1 + 1);
981
painter->drawPoint(x2 - 1, y1);
986
int beg = y1 + (previousSelected ? 0 : 2);
987
int end = y2 - (nextSelected ? 0 : 2);
988
painter->setPen(shadow);
989
painter->drawLine(x2, beg, x2, end);
990
painter->setPen(dark);
991
painter->drawLine(x2 - 1, beg, x2 - 1, end);
994
if (lastTab || selected || onlyOne || !nextSelected) {
995
painter->setPen(shadow);
996
painter->drawLine(x2 - 2, y2, x1 + ((onlyOne || lastTab) &&
997
selected && rightAligned ? 0 : borderThinkness), y2);
998
painter->drawPoint(x2 - 1, y2 - 1);
999
painter->setPen(dark);
1000
painter->drawLine(x2 - 2, y2 - 1, x1 + ((onlyOne || lastTab) &&
1001
selected && rightAligned ? 0 : borderThinkness), y2 - 1);
1007
#endif // QT_NO_TABBAR
1010
QRect rect = option->rect;
1011
painter->setPen(QPen(option->palette.dark().color()));
1012
painter->drawLine(rect.topRight().x()-1,
1013
rect.topRight().y(),
1014
rect.bottomRight().x()-1,
1015
rect.bottomRight().y());
1016
painter->drawLine(rect.bottomLeft().x(),
1017
rect.bottomLeft().y(),
1018
rect.bottomRight().x(),
1019
rect.bottomRight().y());
1020
painter->setPen(QPen(option->palette.light().color()));
1021
painter->drawLine(rect.topRight().x(),
1022
rect.topRight().y(),
1023
rect.bottomRight().x(),
1024
rect.bottomRight().y());
1025
painter->drawLine(rect.topLeft().x(),
1027
rect.topRight().x(),
1028
rect.topRight().y());
1031
#ifndef QT_NO_SCROLLBAR
1032
case CE_ScrollBarSubLine:
1033
case CE_ScrollBarAddLine: {
1034
if (option->state & State_Sunken) {
1035
QStyleOption buttonOpt = *option;
1037
drawPrimitive(PE_PanelButtonBevel, &buttonOpt, painter, widget);
1039
QStyleOption buttonOpt = *option;
1040
if (!(buttonOpt.state & State_Sunken))
1041
buttonOpt.state |= State_Raised;
1042
drawPrimitive(PE_PanelButtonBevel, &buttonOpt, painter, widget);
1044
PrimitiveElement arrow;
1045
if (option->state & State_Horizontal) {
1046
if (element == CE_ScrollBarAddLine)
1047
arrow = option->direction == Qt::LeftToRight ? PE_IndicatorArrowRight : PE_IndicatorArrowLeft;
1049
arrow = option->direction == Qt::LeftToRight ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
1051
if (element == CE_ScrollBarAddLine)
1052
arrow = PE_IndicatorArrowDown;
1054
arrow = PE_IndicatorArrowUp;
1056
drawPrimitive(arrow, option, painter, widget);
1058
case CE_ScrollBarAddPage:
1059
case CE_ScrollBarSubPage: {
1061
QBrush bg = painter->background();
1062
Qt::BGMode bg_mode = painter->backgroundMode();
1063
painter->setPen(Qt::NoPen);
1064
painter->setBackgroundMode(Qt::OpaqueMode);
1066
if (option->state & State_Sunken) {
1067
br = QBrush(option->palette.shadow().color(), Qt::Dense4Pattern);
1068
painter->setBackground(option->palette.dark().color());
1069
painter->setBrush(br);
1071
QPixmap pm = option->palette.brush(QPalette::Light).texture();
1072
if (option->state & State_Enabled)
1073
br = !pm.isNull() ? QBrush(pm) : QBrush(option->palette.button().color(), Qt::Dense4Pattern);
1075
br = !pm.isNull() ? QBrush(pm) : QBrush(option->palette.light().color(), Qt::Dense4Pattern);
1076
painter->setBackground(option->palette.base().color());
1077
painter->setBrush(br);
1079
painter->drawRect(option->rect);
1080
painter->setBackground(bg);
1081
painter->setBackgroundMode(bg_mode);
1083
case CE_ScrollBarSlider:
1084
if (!(option->state & State_Enabled)) {
1085
QStyleOptionButton buttonOpt;
1086
buttonOpt.QStyleOption::operator=(*option);
1087
buttonOpt.state = State_Enabled | State_Raised;
1088
drawPrimitive(PE_PanelButtonBevel, &buttonOpt, painter, widget);
1089
QPixmap pm = option->palette.brush(QPalette::Light).texture();
1090
QBrush br = !pm.isNull() ? QBrush(pm) : QBrush(option->palette.light().color(), Qt::Dense4Pattern);
1091
painter->setPen(Qt::NoPen);
1092
painter->setBrush(br);
1093
painter->setBackgroundMode(Qt::OpaqueMode);
1094
painter->drawRect(option->rect.adjusted(2, 2, -2, -2));
1096
QStyleOptionButton buttonOpt;
1097
buttonOpt.QStyleOption::operator=(*option);
1098
buttonOpt.state = State_Enabled | State_Raised;
1099
drawPrimitive(PE_PanelButtonBevel, &buttonOpt, painter, widget);
1102
#endif // QT_NO_SCROLLBAR
1103
case CE_HeaderSection: {
1105
if (option->state & State_On)
1106
fill = QBrush(option->palette.light().color(), Qt::Dense4Pattern);
1108
fill = option->palette.brush(QPalette::Button);
1110
if (option->state & (State_Raised | State_Sunken)) {
1111
QWindowsCEStylePrivate::drawWinCEButton(painter, option->rect, option->palette,
1112
option->state & State_Sunken, &fill);
1114
painter->fillRect(option->rect, fill);
1118
case CE_DockWidgetTitle:
1119
QWindowsStyle::drawControl(element,option, painter, widget);
1122
case CE_PushButtonLabel:
1123
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
1125
QFont f = painter->font();
1127
painter->setFont(f);
1128
QRect ir = btn->rect;
1129
uint tf = Qt::AlignVCenter | Qt::TextShowMnemonic;
1130
if (!styleHint(SH_UnderlineShortcut, btn, widget))
1131
tf |= Qt::TextHideMnemonic;
1133
if (btn->state & (State_On | State_Sunken))
1134
ir.translate(pixelMetric(PM_ButtonShiftHorizontal, option, widget),
1135
pixelMetric(PM_ButtonShiftVertical, option, widget));
1136
if (!btn->icon.isNull()) {
1137
QIcon::Mode mode = btn->state & State_Enabled ? QIcon::Normal
1139
if (mode == QIcon::Normal && btn->state & State_HasFocus)
1140
mode = QIcon::Active;
1141
QIcon::State state = QIcon::Off;
1142
if (btn->state & State_On)
1144
QPixmap pixmap = btn->icon.pixmap(btn->iconSize, mode, state);
1145
int pixw = pixmap.width();
1146
int pixh = pixmap.height();
1147
//Center the icon if there is no text
1150
if (btn->text.isEmpty()) {
1151
point = QPoint(ir.x() + ir.width() / 2 - pixw / 2,
1152
ir.y() + ir.height() / 2 - pixh / 2);
1154
point = QPoint(ir.x() + 2, ir.y() + ir.height() / 2 - pixh / 2);
1156
if (btn->direction == Qt::RightToLeft)
1159
if ((btn->state & (State_On | State_Sunken)) && btn->direction == Qt::RightToLeft)
1160
point.rx() -= pixelMetric(PM_ButtonShiftHorizontal, option, widget) * 2;
1162
painter->drawPixmap(visualPos(btn->direction, btn->rect, point), pixmap);
1164
if (btn->direction == Qt::RightToLeft)
1165
ir.translate(-4, 0);
1167
ir.translate(pixw + 4, 0);
1168
ir.setWidth(ir.width() - (pixw + 4));
1169
// left-align text if there is
1170
if (!btn->text.isEmpty())
1171
tf |= Qt::AlignLeft;
1173
tf |= Qt::AlignHCenter;
1175
drawItemText(painter, ir, tf, btn->palette, (btn->state & State_Enabled),
1176
btn->text, QPalette::ButtonText);
1181
QWindowsStyle::drawControl(element, option, painter, widget);
1186
void QWindowsCEStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
1187
QPainter *painter, const QWidget *widget) const {
1189
#ifndef QT_NO_SLIDER
1191
if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
1192
int thickness = pixelMetric(PM_SliderControlThickness, slider, widget);
1193
int len = pixelMetric(PM_SliderLength, slider, widget);
1194
int ticks = slider->tickPosition;
1195
QRect groove = subControlRect(CC_Slider, slider, SC_SliderGroove, widget);
1196
QRect handle = subControlRect(CC_Slider, slider, SC_SliderHandle, widget);
1198
if ((slider->subControls & SC_SliderGroove) && groove.isValid()) {
1199
int mid = thickness / 2;
1200
if (ticks & QSlider::TicksAbove)
1202
if (ticks & QSlider::TicksBelow)
1205
painter->setPen(slider->palette.shadow().color());
1206
if (slider->orientation == Qt::Horizontal) {
1207
QWindowsCEStylePrivate::drawWinCEPanel(painter, groove.x(), groove.y() + mid - 2,
1208
groove.width(), 4, option->palette, true);
1209
painter->drawLine(groove.x() + 1, groove.y() + mid - 1,
1210
groove.x() + groove.width() - 3, groove.y() + mid - 1);
1212
QWindowsCEStylePrivate::drawWinCEPanel(painter, groove.x() + mid - 2, groove.y(),
1213
4, groove.height(), option->palette, true);
1214
painter->drawLine(groove.x() + mid - 1, groove.y() + 1,
1215
groove.x() + mid - 1, groove.y() + groove.height() - 3);
1218
if (slider->subControls & SC_SliderTickmarks) {
1219
QStyleOptionSlider tmpSlider = *slider;
1220
tmpSlider.subControls = SC_SliderTickmarks;
1221
QCommonStyle::drawComplexControl(control, &tmpSlider, painter, widget);
1224
if (slider->subControls & SC_SliderHandle) {
1234
const QColor c0 = slider->palette.shadow().color();
1235
const QColor c1 = slider->palette.dark().color();
1236
// const QColor c2 = g.button();
1237
const QColor c3 = slider->palette.midlight().color();
1238
const QColor c4 = slider->palette.dark().color();
1241
if (slider->state & State_Enabled) {
1242
handleBrush = slider->palette.color(QPalette::Button);
1244
handleBrush = QBrush(slider->palette.color(QPalette::Button),
1248
int x = handle.x(), y = handle.y(),
1249
wi = handle.width(), he = handle.height();
1252
int x2 = x + wi - 1;
1254
int y2 = y + he - 1;
1256
Qt::Orientation orient = slider->orientation;
1257
bool tickAbove = slider->tickPosition == QSlider::TicksAbove;
1258
bool tickBelow = slider->tickPosition == QSlider::TicksBelow;
1260
if (slider->state & State_HasFocus) {
1261
QStyleOptionFocusRect fropt;
1262
fropt.QStyleOption::operator=(*slider);
1263
fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
1264
drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
1266
if ((tickAbove && tickBelow) || (!tickAbove && !tickBelow)) {
1267
Qt::BGMode oldMode = painter->backgroundMode();
1268
painter->setBackgroundMode(Qt::OpaqueMode);
1269
QWindowsCEStylePrivate::drawWinCEButton(painter, QRect(x, y, wi, he), slider->palette, false,
1271
painter->setBackgroundMode(oldMode);
1272
QBrush fill = QBrush(option->palette.light().color(), Qt::Dense4Pattern);
1273
if (slider->state & State_Sunken)
1274
painter->fillRect(QRectF(x1 + 2, y1 + 2, x2 - x1 - 3, y2 - y1 - 3),fill);
1277
QSliderDirection dir;
1278
if (orient == Qt::Horizontal)
1294
d = (wi + 1) / 2 - 1;
1295
a.setPoints(5, x1, y1, x1, y2, x2, y2, x2, y1, x1 + d, y1 - d);
1300
d = (wi + 1) / 2 - 1;
1301
a.setPoints(5, x1, y1, x1, y2, x1 + d, y2+d, x2, y2, x2, y1);
1304
d = (he + 1) / 2 - 1;
1306
a.setPoints(5, x1, y1, x1 - d, y1 + d, x1, y2, x2, y2, x2, y1);
1310
d = (he + 1) / 2 - 1;
1312
a.setPoints(5, x1, y1, x1, y2, x2, y2, x2 + d, y1 + d, x2, y1);
1316
QBrush oldBrush = painter->brush();
1317
painter->setPen(Qt::NoPen);
1318
painter->setBrush(handleBrush);
1319
Qt::BGMode oldMode = painter->backgroundMode();
1320
painter->setBackgroundMode(Qt::OpaqueMode);
1321
painter->drawRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
1322
painter->drawPolygon(a);
1323
QBrush fill = QBrush(option->palette.light().color(), Qt::Dense4Pattern);
1324
if (slider->state & State_Sunken)
1325
painter->fillRect(QRectF(x1, y1, x2 - x1 + 1, y2 - y1 + 1),fill);
1326
painter->setBrush(oldBrush);
1327
painter->setBackgroundMode(oldMode);
1330
painter->setPen(c4);
1331
painter->drawLine(x1, y1, x2, y1);
1332
painter->setPen(c3);
1333
painter->drawLine(x1, y1 + 1, x2, y1 + 1);
1335
if (dir != SlLeft) {
1336
painter->setPen(c3);
1337
painter->drawLine(x1 + 1, y1 + 1, x1 + 1, y2);
1338
painter->setPen(c4);
1339
painter->drawLine(x1, y1, x1, y2);
1341
if (dir != SlRight) {
1342
painter->setPen(c0);
1343
painter->drawLine(x2, y1, x2, y2);
1344
painter->setPen(c1);
1345
painter->drawLine(x2 - 1, y1 + 1, x2 - 1, y2 - 1);
1347
if (dir != SlDown) {
1348
painter->setPen(c0);
1349
painter->drawLine(x1, y2, x2, y2);
1350
painter->setPen(c1);
1351
painter->drawLine(x1+1, y2 - 1, x2 - 1, y2 - 1);
1356
if (slider->state & State_Sunken)
1357
painter->fillRect(QRectF(x1 + 3, y1 - d + 2, x2 - x1 - 4,y1), fill);
1358
painter->setPen(c4);
1359
painter->drawLine(x1, y1, x1 + d, y1 - d);
1360
painter->setPen(c0);
1362
painter->drawLine(x2, y1, x2 - d, y1 - d);
1364
painter->setPen(c3);
1365
painter->drawLine(x1 + 1, y1, x1 + 1 + d-1, y1 - d + 1);
1366
painter->setPen(c1);
1367
painter->drawLine(x2 - 1, y1, x2-1 - d, y1 - d);
1370
if (slider->state & State_Sunken)
1371
painter->fillRect(QRectF(x1 + 3, y2 - d, x2 - x1 - 4,y2 - 8), fill);
1372
painter->setPen(c4);
1373
painter->drawLine(x1, y2, x1 + d, y2 + d);
1374
painter->setPen(c0);
1376
painter->drawLine(x2, y2, x2 - d, y2 + d);
1378
painter->setPen(c3);
1379
painter->drawLine(x1 + 1, y2, x1 + 1 + d - 1, y2 + d - 1);
1380
painter->setPen(c1);
1381
painter->drawLine(x2 - 1, y2, x2 - 1 - d, y2 + d);
1384
if (slider->state & State_Sunken)
1385
painter->fillRect(QRectF(x1 - d + 2, y1 + 2, x1,y2 - y1 - 3), fill);
1386
painter->setPen(c4);
1387
painter->drawLine(x1, y1, x1 - d, y1 + d);
1388
painter->setPen(c0);
1390
painter->drawLine(x1, y2, x1 - d, y2 - d);
1392
painter->setPen(c3);
1393
painter->drawLine(x1, y1 + 1, x1 - d + 1, y1 + 1 + d - 1);
1394
painter->setPen(c1);
1395
painter->drawLine(x1, y2 - 1, x1 - d, y2 - 1 - d);
1398
if (slider->state & State_Sunken)
1399
painter->fillRect(QRectF(x2 - d - 4, y1 + 2, x2 - 4, y2 - y1 - 3), fill);
1400
painter->setPen(c4);
1401
painter->drawLine(x2, y1, x2 + d, y1 + d);
1402
painter->setPen(c0);
1404
painter->drawLine(x2, y2, x2 + d, y2 - d);
1406
painter->setPen(c3);
1407
painter->drawLine(x2, y1 + 1, x2 + d - 1, y1 + 1 + d - 1);
1408
painter->setPen(c1);
1409
painter->drawLine(x2, y2 - 1, x2 + d, y2 - 1 - d);
1415
#endif // QT_NO_SLIDER
1417
if (const QStyleOptionToolButton *toolbutton
1418
= qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
1419
QRect button, menuarea;
1421
#ifndef QT_NO_TOOLBAR
1422
bool flat = !(widget ? qobject_cast<QToolBar*>(widget->parentWidget()) : 0);
1427
button = subControlRect(control, toolbutton, SC_ToolButton, widget);
1428
menuarea = subControlRect(control, toolbutton, SC_ToolButtonMenu, widget);
1430
if (flat && (toolbutton->subControls & SC_ToolButtonMenu)) {
1431
menuarea.setLeft(menuarea.left() - 4);
1432
button.setRight(button.right() - 4);
1435
State bflags = toolbutton->state;
1437
if (bflags & State_AutoRaise)
1438
if (!(bflags & State_MouseOver)) {
1439
bflags &= ~State_Raised;
1441
State mflags = bflags;
1443
if (toolbutton->activeSubControls & SC_ToolButton)
1444
bflags |= State_Sunken;
1445
if (toolbutton->activeSubControls & SC_ToolButtonMenu)
1446
mflags |= State_Sunken;
1448
QStyleOption tool(0);
1449
tool.palette = toolbutton->palette;
1450
if (toolbutton->subControls & SC_ToolButton) {
1452
tool.state = bflags;
1453
drawPrimitive(PE_PanelButtonTool, &tool, painter, widget);
1456
if (toolbutton->subControls & SC_ToolButtonMenu) {
1457
tool.rect = menuarea;
1458
tool.state = mflags;
1459
tool.state = bflags;
1460
drawPrimitive(PE_IndicatorButtonDropDown, &tool, painter, widget);
1466
painter->setPen(tool.palette.button().color());
1467
painter->drawLine(tool.rect.x() - 2, tool.rect.y(), tool.rect.x() - 2, tool.rect.y() + tool.rect.height());
1468
painter->drawLine(tool.rect.x() - 1, tool.rect.y(), tool.rect.x() - 1, tool.rect.y() + tool.rect.height());
1469
painter->drawLine(tool.rect.x(), tool.rect.y(), tool.rect.x(), tool.rect.y() + tool.rect.height());
1470
painter->drawLine(tool.rect.x() + 1, tool.rect.y(), tool.rect.x() + 1, tool.rect.y() + tool.rect.height());
1472
if (tool.state & State_Sunken)
1474
painter->setPen(tool.palette.midlight().color());
1475
painter->drawLine(tool.rect.x() - 2, tool.rect.y() + tool.rect.height() - 2,
1476
tool.rect.x() + 1, tool.rect.y() + tool.rect.height() -2 );
1477
painter->setPen(tool.palette.shadow().color());
1478
painter->drawLine(tool.rect.x() - 2, tool.rect.y() + 1,tool.rect.x() + 1, tool.rect.y() + 1);
1479
painter->drawLine(tool.rect.x() - 2, tool.rect.y(), tool.rect.x() + 1, tool.rect.y());
1480
painter->setPen(tool.palette.light().color());
1481
painter->drawLine(tool.rect.x() - 2, tool.rect.y() + tool.rect.height() - 1,
1482
tool.rect.x() + 1, tool.rect.y() + tool.rect.height() - 1);
1486
painter->setPen(tool.palette.dark().color());
1487
painter->drawLine(tool.rect.x() - 2, tool.rect.y(),tool.rect.x() + 1, tool.rect.y());
1488
painter->drawLine(tool.rect.x() - 2, tool.rect.y()+tool.rect.height() - 2,tool.rect.x() + 1,
1489
tool.rect.y() + tool.rect.height() - 2);
1490
painter->setPen(tool.palette.midlight().color());
1491
painter->drawLine(tool.rect.x() - 2, tool.rect.y() + 1,tool.rect.x() + 1, tool.rect.y() + 1);
1492
painter->setPen(tool.palette.shadow().color());
1493
painter->drawLine(tool.rect.x() - 2, tool.rect.y() + tool.rect.height() - 1,
1494
tool.rect.x() + 1, tool.rect.y() + tool.rect.height() - 1);
1501
tool.rect.adjust(-3,0,-3,0);
1503
painter->setPen(tool.palette.button().color());
1504
if (tool.state & State_Sunken)
1505
painter->drawLine(tool.rect.x() + 2, tool.rect.y() + 10,
1506
tool.rect.x() + tool.rect.width(), tool.rect.y() + 10);
1508
painter->drawLine(tool.rect.x() + 1, tool.rect.y() + 9, tool.rect.x() +
1509
tool.rect.width() - 1, tool.rect.y() + 9);
1512
tool.rect.adjust(-1,0,-1,0);
1515
drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget);
1518
if (toolbutton->state & State_HasFocus) {
1519
QStyleOptionFocusRect fr;
1520
fr.QStyleOption::operator=(*toolbutton);
1521
fr.rect.adjust(3, 3, -3, -3);
1522
if (toolbutton->features & QStyleOptionToolButton::Menu)
1523
fr.rect.adjust(0, 0, -pixelMetric(QStyle::PM_MenuButtonIndicator,
1524
toolbutton, widget), 0);
1525
drawPrimitive(PE_FrameFocusRect, &fr, painter, widget);
1527
QStyleOptionToolButton label = *toolbutton;
1528
int fw = pixelMetric(PM_DefaultFrameWidth, option, widget);
1529
label.rect = button.adjusted(fw, fw, -fw, -fw);
1530
drawControl(CE_ToolButtonLabel, &label, painter, widget);
1534
#ifndef QT_NO_GROUPBOX
1536
if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
1539
QFont f = painter->font();
1541
painter->setFont(f);
1542
QStyleOptionGroupBox groupBoxFont = *groupBox;
1543
groupBoxFont.fontMetrics = QFontMetrics(f);
1544
QRect textRect = subControlRect(CC_GroupBox, &groupBoxFont, SC_GroupBoxLabel, widget);
1545
QRect checkBoxRect = subControlRect(CC_GroupBox, option, SC_GroupBoxCheckBox, widget);
1546
if (groupBox->subControls & QStyle::SC_GroupBoxFrame) {
1547
QStyleOptionFrameV2 frame;
1548
frame.QStyleOption::operator=(*groupBox);
1549
frame.features = groupBox->features;
1550
frame.lineWidth = groupBox->lineWidth;
1551
frame.midLineWidth = groupBox->midLineWidth;
1552
frame.rect = subControlRect(CC_GroupBox, option, SC_GroupBoxFrame, widget);
1555
QRegion region(groupBox->rect);
1556
if (!groupBox->text.isEmpty()) {
1557
bool ltr = groupBox->direction == Qt::LeftToRight;
1558
QRect finalRect = checkBoxRect.united(textRect);
1559
if (groupBox->subControls & QStyle::SC_GroupBoxCheckBox)
1560
finalRect.adjust(ltr ? -4 : 0, 0, ltr ? 0 : 4, 0);
1561
region -= finalRect;
1563
painter->setClipRegion(region);
1564
drawPrimitive(PE_FrameGroupBox, &frame, painter, widget);
1569
if ((groupBox->subControls & QStyle::SC_GroupBoxLabel) && !groupBox->text.isEmpty()) {
1570
QColor textColor = groupBox->textColor;
1571
if (textColor.isValid())
1572
painter->setPen(textColor);
1573
int alignment = int(groupBox->textAlignment);
1574
if (!styleHint(QStyle::SH_UnderlineShortcut, option, widget))
1575
alignment |= Qt::TextHideMnemonic;
1577
drawItemText(painter, textRect, Qt::TextShowMnemonic | Qt::AlignHCenter | alignment,
1578
groupBox->palette, groupBox->state & State_Enabled, groupBox->text,
1579
textColor.isValid() ? QPalette::NoRole : QPalette::WindowText);
1581
if (groupBox->state & State_HasFocus) {
1582
QStyleOptionFocusRect fropt;
1583
fropt.QStyleOption::operator=(*groupBox);
1584
fropt.rect = textRect;
1585
drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
1589
if (groupBox->subControls & SC_GroupBoxCheckBox) {
1590
QStyleOptionButton box;
1591
box.QStyleOption::operator=(*groupBox);
1592
box.rect = checkBoxRect;
1593
drawPrimitive(PE_IndicatorCheckBox, &box, painter, widget);
1598
#endif //QT_NO_GROUPBOX
1599
#ifndef QT_NO_COMBOBOX
1601
if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
1602
QBrush editBrush = cmb->palette.brush(QPalette::Base);
1603
if ((cmb->subControls & SC_ComboBoxFrame) && cmb->frame)
1604
QWindowsCEStylePrivate::drawWinCEPanel(painter, option->rect, option->palette, true, &editBrush);
1606
painter->fillRect(option->rect, editBrush);
1608
if (cmb->subControls & SC_ComboBoxArrow) {
1609
State flags = State_None;
1611
QRect ar = subControlRect(CC_ComboBox, cmb, SC_ComboBoxArrow, widget);
1612
if (cmb->activeSubControls == SC_ComboBoxArrow) {
1613
painter->setPen(cmb->palette.dark().color());
1614
painter->setBrush(cmb->palette.brush(QPalette::Button));
1615
painter->drawRect(ar.adjusted(0, 0, -1, -1));
1616
QWindowsCEStylePrivate::drawWinCEButton(painter, ar.adjusted(0, 0, -1, -1), option->palette, true,
1617
&cmb->palette.brush(QPalette::Button));
1619
// Make qDrawWinButton use the right colors for drawing the shade of the button
1621
QWindowsCEStylePrivate::drawWinCEButton(painter, ar, option->palette, false,
1622
&cmb->palette.brush(QPalette::Button));
1625
ar.adjust(2, 2, -2, -2);
1626
if (option->state & State_Enabled)
1627
flags |= State_Enabled;
1629
if (cmb->activeSubControls == SC_ComboBoxArrow)
1630
flags |= State_Sunken;
1631
QStyleOption arrowOpt(0);
1633
arrowOpt.palette = cmb->palette;
1634
arrowOpt.state = flags;
1635
drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget);
1637
if (cmb->subControls & SC_ComboBoxEditField) {
1638
QRect re = subControlRect(CC_ComboBox, cmb, SC_ComboBoxEditField, widget);
1639
if (cmb->state & State_HasFocus && !cmb->editable)
1640
painter->fillRect(re.x(), re.y(), re.width(), re.height(),
1641
cmb->palette.brush(QPalette::Highlight));
1642
if (cmb->state & State_HasFocus) {
1643
painter->setPen(cmb->palette.highlightedText().color());
1644
painter->setBackground(cmb->palette.highlight());
1646
painter->setPen(cmb->palette.text().color());
1647
painter->setBackground(cmb->palette.background());
1649
if (cmb->state & State_HasFocus && !cmb->editable) {
1650
QStyleOptionFocusRect focus;
1651
focus.QStyleOption::operator=(*cmb);
1652
focus.rect = subElementRect(SE_ComboBoxFocusRect, cmb, widget);
1653
focus.state |= State_FocusAtBorder;
1654
focus.backgroundColor = cmb->palette.highlight().color();
1655
drawPrimitive(PE_FrameFocusRect, &focus, painter, widget);
1660
#endif // QT_NO_COMBOBOX
1661
#ifndef QT_NO_SPINBOX
1663
if (const QStyleOptionSpinBox *sb = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
1664
QStyleOptionSpinBox copy = *sb;
1665
PrimitiveElement pe;
1667
if (sb->frame && (sb->subControls & SC_SpinBoxFrame)) {
1668
QRect r = subControlRect(CC_SpinBox, sb, SC_SpinBoxFrame, widget);
1669
QWindowsCEStylePrivate::drawWinCEPanel(painter, r, option->palette, true);
1671
QPalette shadePal(option->palette);
1672
shadePal.setColor(QPalette::Button, option->palette.light().color());
1673
shadePal.setColor(QPalette::Light, option->palette.button().color());
1675
bool reverse = QApplication::layoutDirection() == Qt::RightToLeft;
1677
if (sb->subControls & SC_SpinBoxUp) {
1678
copy.subControls = SC_SpinBoxUp;
1679
QPalette pal2 = sb->palette;
1680
if (!(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled)) {
1681
pal2.setCurrentColorGroup(QPalette::Disabled);
1682
copy.state &= ~State_Enabled;
1684
copy.palette = pal2;
1685
if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken)) {
1686
copy.state |= State_On;
1687
copy.state |= State_Sunken;
1689
copy.state |= State_Raised;
1690
copy.state &= ~State_Sunken;
1693
pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinMinus
1694
: PE_IndicatorSpinDown);
1696
pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinPlus
1697
: PE_IndicatorSpinUp);
1698
copy.rect = subControlRect(CC_SpinBox, sb, SC_SpinBoxUp, widget);
1699
QWindowsCEStylePrivate::drawWinCEButton(painter, copy.rect, option->palette, copy.state & (State_Sunken | State_On),
1700
©.palette.brush(QPalette::Button));
1701
copy.rect.adjust(3, 0, -4, 0);
1702
drawPrimitive(pe, ©, painter, widget);
1704
if (sb->subControls & SC_SpinBoxDown) {
1705
copy.subControls = SC_SpinBoxDown;
1706
copy.state = sb->state;
1707
QPalette pal2 = sb->palette;
1708
if (!(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled)) {
1709
pal2.setCurrentColorGroup(QPalette::Disabled);
1710
copy.state &= ~State_Enabled;
1712
copy.palette = pal2;
1714
if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken)) {
1715
copy.state |= State_On;
1716
copy.state |= State_Sunken;
1718
copy.state |= State_Raised;
1719
copy.state &= ~State_Sunken;
1722
pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinPlus
1723
: PE_IndicatorSpinUp);
1725
pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinMinus
1726
: PE_IndicatorSpinDown);
1727
copy.rect = subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget);
1728
QWindowsCEStylePrivate::drawWinCEButton(painter, copy.rect, shadePal, copy.state & (State_Sunken | State_On),
1729
©.palette.brush(QPalette::Button));
1731
copy.rect.adjust(3, 0, -4, 0);
1732
if (pe == PE_IndicatorArrowUp || pe == PE_IndicatorArrowDown) {
1733
copy.rect = copy.rect.adjusted(1, 1, -1, -1);
1734
drawPrimitive(pe, ©, painter, widget);
1737
drawPrimitive(pe, ©, painter, widget);
1739
if (sb->frame && (sb->subControls & SC_SpinBoxFrame)) {
1740
QRect r = subControlRect(CC_SpinBox, sb, SC_SpinBoxEditField, widget);
1742
painter->setPen(option->palette.light().color());
1743
painter->drawLine(r.x() + 1 + r.width(), r.y() - 2, r.x() + 1 + r.width(), r.y() + r.height() + 1);
1744
painter->setPen(option->palette.midlight().color());
1745
painter->drawLine(r.x() + r.width(), r.y() - 1, r.x() + r.width(), r.y() + r.height());
1751
#endif // QT_NO_SPINBOX
1754
QWindowsStyle::drawComplexControl(control, option, painter, widget);
1759
void QWindowsCEStyle::drawItemText(QPainter *painter, const QRect &rect, int alignment, const QPalette &pal,
1760
bool enabled, const QString& text, QPalette::ColorRole textRole) const {
1764
if (textRole != QPalette::NoRole) {
1765
savedPen = painter->pen();
1766
painter->setPen(pal.color(textRole));
1769
QPen pen = painter->pen();
1770
painter->setPen(pal.light().color());
1771
//painter->drawText(rect.adjusted(1, 1, 1, 1), alignment, text);
1772
painter->setPen(pen);
1774
painter->drawText(rect, alignment, text);
1775
if (textRole != QPalette::NoRole)
1776
painter->setPen(savedPen);
1780
QSize QWindowsCEStyle::sizeFromContents(ContentsType type, const QStyleOption *option,
1781
const QSize &size, const QWidget *widget) const {
1782
QSize newSize = QWindowsStyle::sizeFromContents(type, option, size, widget);
1785
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
1786
newSize = QWindowsStyle::sizeFromContents(type, option, size, widget);
1787
int w = newSize.width(),
1788
h = newSize.height();
1790
if (btn->features & QStyleOptionButton::AutoDefaultButton)
1791
defwidth = 2 * pixelMetric(PM_ButtonDefaultIndicator, btn, widget);
1792
if (w < 75 + defwidth && btn->icon.isNull())
1794
if (h < 23 + defwidth)
1796
newSize = QSize(w+14, h);
1800
case CT_RadioButton:
1802
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
1803
bool isRadio = (type == CT_RadioButton);
1804
QRect irect = visualRect(btn->direction, btn->rect,
1805
subElementRect(isRadio ? SE_RadioButtonIndicator
1806
: SE_CheckBoxIndicator, btn, widget));
1807
int h = pixelMetric(isRadio ? PM_ExclusiveIndicatorHeight
1808
: PM_IndicatorHeight, btn, widget);
1809
int margins = (!btn->icon.isNull() && btn->text.isEmpty()) ? 0 : 10;
1810
newSize += QSize(irect.right() + margins, 4);
1811
newSize.setHeight(qMax(newSize.height(), h));
1815
if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
1816
int fw = cmb->frame ? pixelMetric(PM_ComboBoxFrameWidth, option, widget) * 2 : 0;
1817
newSize = QSize(newSize.width() + fw -1, qMax(24, newSize.height() + fw-1));
1820
#ifndef QT_NO_SPINBOX
1822
if (const QStyleOptionSpinBox *spnb = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
1823
int fw = spnb->frame ? pixelMetric(PM_SpinBoxFrameWidth, option, widget) * 2 : 0;
1824
newSize = QSize(newSize.width() + fw - 5, newSize.height() + fw - 6);
1829
newSize += QSize(0,1);
1831
case CT_MenuBarItem:
1832
newSize += QSize(5, 1);
1835
newSize += QSize(0, -2);
1838
newSize += QSize(0, -1);
1841
if (const QStyleOptionToolButton *b = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
1842
if (b->toolButtonStyle != Qt::ToolButtonIconOnly)
1843
newSize = QSize(newSize.width() + 1, newSize.height() - 1);
1845
newSize = QSize(newSize.width() + 1, newSize.height());
1855
QRect QWindowsCEStyle::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const {
1856
QRect rect = QWindowsStyle::subElementRect(element, option, widget);
1858
#ifndef QT_NO_COMBOBOX
1859
case SE_ComboBoxFocusRect:
1860
if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
1861
int margin = cb->frame ? 3 : 0;
1862
rect.setRect(margin, margin, option->rect.width() - 2*margin - 20, option->rect.height() - 2*margin);
1863
rect = visualRect(option->direction, option->rect, rect);
1866
#endif // QT_NO_COMBOBOX
1873
QRect QWindowsCEStyle::subControlRect(ComplexControl control, const QStyleOptionComplex *option,
1874
SubControl subControl, const QWidget *widget) const {
1875
QRect rect = QWindowsStyle::subControlRect(control, option, subControl, widget);
1877
#ifndef QT_NO_SLIDER
1879
if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
1880
int tickOffset = pixelMetric(PM_SliderTickmarkOffset, slider, widget);
1881
int thickness = pixelMetric(PM_SliderControlThickness, slider, widget);
1883
switch (subControl) {
1884
case SC_SliderHandle: {
1886
int len = pixelMetric(PM_SliderLength, slider, widget);
1887
bool horizontal = slider->orientation == Qt::Horizontal;
1888
sliderPos = sliderPositionFromValue(slider->minimum, slider->maximum,
1889
slider->sliderPosition,
1890
(horizontal ? slider->rect.width()
1891
: slider->rect.height()) - len,
1892
slider->upsideDown);
1894
rect.setRect(slider->rect.x() + sliderPos, slider->rect.y() + tickOffset, len, thickness);
1896
rect.setRect(slider->rect.x() + tickOffset, slider->rect.y() + sliderPos, thickness, len);
1901
rect = visualRect(slider->direction, slider->rect, rect);
1904
#endif //QT_NO_SLIDER
1905
#ifndef QT_NO_COMBOBOX
1907
if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
1908
int x = cb->rect.x(),
1910
wi = cb->rect.width(),
1911
he = cb->rect.height();
1913
int margin = cb->frame ? 3 : 0;
1914
int bmarg = cb->frame ? 2 : 0;
1915
xpos += wi - (he - 2*bmarg) - bmarg;
1916
switch (subControl) {
1917
case SC_ComboBoxArrow:
1918
rect.setRect(xpos, y + bmarg, he - 2*bmarg, he - 2*bmarg);
1920
case SC_ComboBoxEditField:
1921
rect.setRect(x + margin, y + margin, wi - 2 * margin - (he - 2*bmarg), he - 2 * margin);
1923
case SC_ComboBoxListBoxPopup:
1926
case SC_ComboBoxFrame:
1932
rect = visualRect(cb->direction, cb->rect, rect);
1934
#endif //QT_NO_COMBOBOX
1935
#ifndef QT_NO_SPINBOX
1937
if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
1939
int fw = spinbox->frame ? pixelMetric(PM_SpinBoxFrameWidth, spinbox, widget) : 0;
1940
bs.setWidth(qMax(18, (spinbox->rect.height() / 2 - fw + 1)));
1941
// 1.6 -approximate golden mean
1942
bs.setHeight(qMax(18, qMin((bs.height() * 8 / 5), (spinbox->rect.width() / 4))));
1943
bs = bs.expandedTo(QApplication::globalStrut());
1946
x = spinbox->rect.width() - y - bs.width() * 2;
1949
switch (subControl) {
1951
rect = QRect(x + bs.width(), y, bs.width(), bs.height());
1953
case SC_SpinBoxDown:
1954
rect = QRect(x, y , bs.width(), bs.height());
1956
case SC_SpinBoxEditField:
1957
if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons) {
1958
rect = QRect(lx, fw, spinbox->rect.width() - 2*fw - 2, spinbox->rect.height() - 2*fw);
1960
rect = QRect(lx, fw, rx-2, spinbox->rect.height() - 2*fw);
1963
case SC_SpinBoxFrame:
1964
rect = spinbox->rect;
1968
rect = visualRect(spinbox->direction, spinbox->rect, rect);
1971
#endif // Qt_NO_SPINBOX
1972
#ifndef QT_NO_GROUPBOX
1974
if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
1975
switch (subControl) {
1976
case SC_GroupBoxFrame:
1978
case SC_GroupBoxContents: {
1981
int bottomMargin = 0;
1982
int noLabelMargin = 0;
1983
QRect frameRect = groupBox->rect;
1984
int verticalAlignment = styleHint(SH_GroupBox_TextLabelVerticalAlignment, groupBox, widget);
1985
if (groupBox->text.size()) {
1986
topHeight = groupBox->fontMetrics.height();
1987
if (verticalAlignment & Qt::AlignVCenter)
1988
topMargin = topHeight / 2;
1989
else if (verticalAlignment & Qt::AlignTop)
1990
topMargin = -topHeight/2;
1993
topHeight = groupBox->fontMetrics.height();
1994
noLabelMargin = topHeight / 2;
1995
if (verticalAlignment & Qt::AlignVCenter) {
1996
topMargin = topHeight / 4 - 4;
1997
bottomMargin = topHeight / 4 - 4;
1999
else if (verticalAlignment & Qt::AlignTop) {
2000
topMargin = topHeight/2 - 4;
2001
bottomMargin = topHeight/2 - 4;
2005
if (subControl == SC_GroupBoxFrame) {
2006
frameRect.setTop(topMargin);
2007
frameRect.setBottom(frameRect.height() + bottomMargin);
2013
if ((groupBox->features & QStyleOptionFrameV2::Flat) == 0)
2014
frameWidth = pixelMetric(PM_DefaultFrameWidth, groupBox, widget);
2015
rect = frameRect.adjusted(frameWidth, frameWidth + topHeight, -frameWidth, -frameWidth - noLabelMargin);
2018
case SC_GroupBoxCheckBox:
2020
case SC_GroupBoxLabel: {
2021
QFontMetrics fontMetrics = groupBox->fontMetrics;
2022
int h = fontMetrics.height();
2023
int tw = fontMetrics.size(Qt::TextShowMnemonic, groupBox->text + QLatin1Char(' ')).width();
2024
int marg = (groupBox->features & QStyleOptionFrameV2::Flat) ? 0 : 8;
2025
rect = groupBox->rect.adjusted(marg, 0, -marg, 0);
2028
int indicatorWidth = pixelMetric(PM_IndicatorWidth, option, widget);
2029
int indicatorSpace = pixelMetric(PM_CheckBoxLabelSpacing, option, widget) - 1;
2030
bool hasCheckBox = groupBox->subControls & QStyle::SC_GroupBoxCheckBox;
2031
int checkBoxSize = hasCheckBox ? (indicatorWidth + indicatorSpace) : 0;
2033
// Adjusted rect for label + indicatorWidth + indicatorSpace
2034
QRect totalRect = alignedRect(groupBox->direction, groupBox->textAlignment,
2035
QSize(tw + checkBoxSize, h), rect);
2037
// Adjust totalRect if checkbox is set
2039
bool ltr = groupBox->direction == Qt::LeftToRight;
2041
// Adjust for check box
2042
if (subControl == SC_GroupBoxCheckBox) {
2043
int indicatorHeight = pixelMetric(PM_IndicatorHeight, option, widget);
2044
left = ltr ? totalRect.left() : (totalRect.right() - indicatorWidth);
2045
int top = totalRect.top() + (fontMetrics.height() - indicatorHeight) / 2;
2046
totalRect.setRect(left, top, indicatorWidth, indicatorHeight);
2049
left = ltr ? (totalRect.left() + checkBoxSize - 2) : totalRect.left();
2050
totalRect.setRect(left, totalRect.top(),
2051
totalRect.width() - checkBoxSize, totalRect.height());
2063
#endif // QT_NO_GROUPBOX
2070
QStyle::SubControl QWindowsCEStyle::hitTestComplexControl(ComplexControl control, const QStyleOptionComplex *option,
2071
const QPoint &pos, const QWidget *widget) const {
2072
/*switch (control) {
2076
return QWindowsStyle::hitTestComplexControl(control, option, pos, widget);
2080
QPalette QWindowsCEStyle::standardPalette() const {
2081
QPalette palette (Qt::black,QColor(198, 195, 198), QColor(222, 223, 222 ),
2082
QColor(132, 130, 132), QColor(198, 195, 198) , Qt::black, Qt::white, Qt::white, QColor(198, 195, 198));
2083
palette.setColor(QPalette::Window, QColor(198, 195, 198));
2084
palette.setColor(QPalette::Base, Qt::white);
2085
palette.setColor(QPalette::Button, QColor(198, 195, 198));
2086
palette.setColor(QPalette::Highlight, QColor(0, 0, 132));
2087
palette.setColor(QPalette::Light, Qt::white);
2088
palette.setColor(QPalette::Midlight, QColor(222, 223, 222 ));
2089
palette.setColor(QPalette::Dark, QColor(132, 130, 132));
2090
palette.setColor(QPalette::Mid, QColor(132, 130, 132));
2091
palette.setColor(QPalette::Shadow, QColor(0, 0, 0));
2092
palette.setColor(QPalette::BrightText, QColor(33, 162, 33)); //color for ItemView checked indicator (arrow)
2093
palette.setColor(QPalette::Link, QColor(24,81,132)); // color for the box around the ItemView indicator
2098
void QWindowsCEStyle::polish(QApplication *app) {
2099
QWindowsStyle::polish(app);
2102
void QWindowsCEStyle::polish(QWidget *widget) {
2103
QWindowsStyle::polish(widget);
2106
void QWindowsCEStyle::polish(QPalette &palette) {
2107
QWindowsStyle::polish(palette);
2110
int QWindowsCEStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt, const QWidget *widget) const {
2114
case PM_DefaultFrameWidth:
2118
case PM_MenuBarHMargin:
2121
case PM_MenuBarVMargin:
2124
/*case PM_MenuBarItemSpacing:
2128
case PM_MenuButtonIndicator:
2132
case PM_SpinBoxFrameWidth:
2135
case PM_ButtonDefaultIndicator:
2136
case PM_ButtonShiftHorizontal:
2137
case PM_ButtonShiftVertical:
2140
#ifndef QT_NO_TABBAR
2141
case PM_TabBarTabShiftHorizontal:
2144
case PM_TabBarTabShiftVertical:
2148
case PM_MaximumDragDistance:
2152
case PM_IndicatorWidth:
2153
ret = windowsCEIndicatorSize;
2156
case PM_IndicatorHeight:
2157
ret = windowsCEIndicatorSize;
2160
case PM_ExclusiveIndicatorWidth:
2161
ret = windowsCEExclusiveIndicatorSize;
2164
case PM_ExclusiveIndicatorHeight:
2165
ret = windowsCEExclusiveIndicatorSize;;
2168
#ifndef QT_NO_SLIDER
2169
case PM_SliderLength:
2172
case PM_SliderThickness:
2173
ret = windowsCESliderThickness;
2176
case PM_TabBarScrollButtonWidth:
2180
// Returns the number of pixels to use for the business part of the
2181
// slider (i.e., the non-tickmark portion). The remaining space is shared
2182
// equally between the tickmark regions.
2183
case PM_SliderControlThickness:
2184
if (const QStyleOptionSlider *sl = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
2185
int space = (sl->orientation == Qt::Horizontal) ? sl->rect.height() : sl->rect.width();
2186
int ticks = sl->tickPosition;
2188
if (ticks & QSlider::TicksAbove)
2190
if (ticks & QSlider::TicksBelow)
2197
if (ticks != QSlider::TicksBothSides && ticks != QSlider::NoTicks)
2198
thick += pixelMetric(PM_SliderLength, sl, widget) / 4;
2202
thick += (space * 2) / (n + 2);
2208
#endif // QT_NO_SLIDER
2212
case PM_SmallIconSize:
2213
ret = windowsCEIconSize;
2215
case PM_ButtonMargin:
2219
case PM_LargeIconSize:
2223
case PM_IconViewIconSize:
2224
ret = pixelMetric(PM_LargeIconSize, opt, widget);
2227
case PM_ToolBarIconSize:
2228
ret = windowsCEIconSize;
2230
case PM_DockWidgetTitleMargin:
2233
#if defined(Q_WS_WIN)
2234
// case PM_DockWidgetFrameWidth:
2235
// ret = GetSystemMetrics(SM_CXFRAME);
2238
case PM_DockWidgetFrameWidth:
2244
#endif // QT_NO_MENU
2246
case PM_TitleBarHeight:
2249
case PM_ScrollBarExtent:
2252
case PM_SplitterWidth:
2253
ret = qMax(4, QApplication::globalStrut().width());
2256
#if defined(Q_WS_WIN)
2257
case PM_MDIFrameWidth:
2261
case PM_ToolBarItemMargin:
2264
case PM_ToolBarItemSpacing:
2267
case PM_ToolBarHandleExtent:
2270
case PM_ButtonIconSize:
2274
ret = QWindowsStyle::pixelMetric(pm, opt, widget);
2280
QPixmap QWindowsCEStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt,
2281
const QWidget *widget) const {
2282
#ifndef QT_NO_IMAGEFORMAT_XPM
2283
/*switch (standardPixmap) {
2288
#endif //QT_NO_IMAGEFORMAT_XPM
2289
return QWindowsStyle::standardPixmap(standardPixmap, opt, widget);
2292
int QWindowsCEStyle::styleHint(StyleHint hint, const QStyleOption *opt, const QWidget *widget,
2293
QStyleHintReturn *returnData) const {
2296
case SH_TabBar_ElideMode:
2297
ret = Qt::ElideMiddle;
2299
case SH_EtchDisabledText:
2302
case SH_RequestSoftwareInputPanel:
2303
ret = RSIP_OnMouseClick;
2306
ret = QWindowsStyle::styleHint(hint, opt, widget, returnData);
2312
void QWindowsCEStylePrivate::drawWinShades(QPainter *p,
2313
int x, int y, int w, int h,
2314
const QColor &c1, const QColor &c2,
2315
const QColor &c3, const QColor &c4,
2316
const QBrush *fill) {
2317
if (w < 2 || h < 2) // can't do anything with that
2319
QPen oldPen = p->pen();
2320
QPoint a[3] = { QPoint(x, y+h-2), QPoint(x, y), QPoint(x+w-2, y) };
2322
p->drawPolyline(a, 3);
2323
QPoint b[3] = { QPoint(x, y+h-1), QPoint(x+w-1, y+h-1), QPoint(x+w-1, y) };
2325
p->drawPolyline(b, 3);
2326
if (w > 4 && h > 4) {
2327
QPoint c[3] = { QPoint(x+1, y+h-3), QPoint(x+1, y+1), QPoint(x+w-3, y+1) };
2329
p->drawPolyline(c, 3);
2330
QPoint d[3] = { QPoint(x+1, y+h-2), QPoint(x+w-2, y+h-2), QPoint(x+w-2, y+1) };
2332
p->drawPolyline(d, 3);
2334
p->fillRect(QRect(x+2, y+2, w-4, h-4), *fill);
2339
void QWindowsCEStylePrivate::drawWinCEShades(QPainter *p,
2340
int x, int y, int w, int h,
2341
const QColor &c1, const QColor &c2,
2342
const QColor &c3, const QColor &c4,
2343
const QBrush *fill) {
2344
if (w < 2 || h < 2) // can't do anything with that
2346
QPen oldPen = p->pen();
2347
QPoint b[3] = { QPoint(x, y+h-1), QPoint(x+w-1, y+h-1), QPoint(x+w-1, y) };
2349
p->drawPolyline(b, 3);
2350
if (w > 4 && h > 4) {
2351
QPoint c[3] = { QPoint(x+1, y+h-3), QPoint(x+1, y+1), QPoint(x+w-3, y+1) };
2353
p->drawPolyline(c, 3);
2354
QPoint d[5] = { QPoint(x, y+h-2), QPoint(x+w-2, y+h-2), QPoint(x+w-2, y), QPoint(x, y), QPoint(x, y+h-2) };
2356
p->drawPolyline(d, 5);
2358
p->fillRect(QRect(x+2, y+2, w-4, h-4), *fill);
2360
QPoint a[3] = { QPoint(x+1, y+h-3), QPoint(x+1, y+1), QPoint(x+w-3, y+1) };
2362
p->drawPolyline(a, 3);
2366
void QWindowsCEStylePrivate::drawWinCEShadesSunken(QPainter *p,
2367
int x, int y, int w, int h,
2368
const QColor &c1, const QColor &c2,
2369
const QColor &c3, const QColor &c4,
2370
const QBrush *fill) {
2371
if (w < 2 || h < 2) // can't do anything with that
2373
QPen oldPen = p->pen();
2375
QPoint b[3] = { QPoint(x, y+h-1), QPoint(x+w-1, y+h-1), QPoint(x+w-1, y) };
2377
p->drawPolyline(b, 3);
2378
if (w > 4 && h > 4) {
2379
QPoint d[3] = { QPoint(x, y+h-2), QPoint(x+w-2, y+h-2), QPoint(x+w-2, y) };
2381
p->drawPolyline(d, 3);
2382
QPoint c[3] = { QPoint(x, y+h-2), QPoint(x, y), QPoint(x+w-2, y) };
2384
p->drawPolyline(c, 3);
2386
p->fillRect(QRect(x+2, y+2, w-4, h-4), *fill);
2388
QPoint a[3] = { QPoint(x+1, y+h-3), QPoint(x+1, y+1), QPoint(x+w-3, y+1) };
2390
p->drawPolyline(a, 3);
2395
void QWindowsCEStylePrivate::drawWinCEButton(QPainter *p, int x, int y, int w, int h,
2396
const QPalette &pal, bool sunken,
2397
const QBrush *fill) {
2399
drawWinCEShadesSunken(p, x, y, w, h,
2400
pal.shadow().color(), pal.light().color(), pal.shadow().color(),
2401
pal.midlight().color(), fill);
2403
drawWinCEShades(p, x, y, w, h,
2404
pal.midlight().color(), pal.shadow().color(), pal.button().color(),
2405
pal.dark().color(), fill);
2408
void QWindowsCEStylePrivate::drawWinCEPanel(QPainter *p, int x, int y, int w, int h,
2409
const QPalette &pal, bool sunken,
2410
const QBrush *fill) {
2412
drawWinShades(p, x, y, w, h,
2413
pal.dark().color(), pal.light().color(), pal.shadow().color(),
2414
pal.midlight().color(), fill);
2416
drawWinShades(p, x, y, w, h,
2417
pal.light().color(), pal.shadow().color(), pal.button().color(),
2418
pal.midlight().color(), fill);
2421
void QWindowsCEStylePrivate::drawWinCEButton(QPainter *p, const QRect &r,
2422
const QPalette &pal, bool sunken, const QBrush *fill) {
2423
drawWinCEButton(p, r.x(), r.y(), r.width(), r.height(), pal, sunken, fill);
2426
void QWindowsCEStylePrivate::drawWinCEPanel(QPainter *p, const QRect &r,
2427
const QPalette &pal, bool sunken, const QBrush *fill) {
2428
drawWinCEPanel(p, r.x(), r.y(), r.width(), r.height(), pal, sunken, fill);
2433
#endif // QT_NO_STYLE_WINDOWSCE