source: trunk/src/gui/styles/qwindowscestyle.cpp@ 5

Last change on this file since 5 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 106.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information (qt-info@nokia.com)
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at qt-sales@nokia.com.
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qwindowscestyle.h"
43
44#if !defined(QT_NO_STYLE_WINDOWSCE) || defined(QT_PLUGIN)
45
46#include "qpainterpath.h"
47#include "qapplication.h"
48#include "qdockwidget.h"
49#include "qtoolbar.h"
50#include "qpaintengine.h"
51#include "qpainter.h"
52#include "qstyleoption.h"
53#include "qwindowscestyle_p.h"
54#include "qdebug.h"
55
56QT_BEGIN_NAMESPACE
57
58static const int windowsItemFrame = 2; // menu item frame width
59static const int windowsSepHeight = 9; // separator item height
60static const int windowsItemHMargin = 3; // menu item hor text margin
61static const int windowsItemVMargin = 2; // menu item ver text margin
62static const int windowsArrowHMargin = 6; // arrow horizontal margin
63static const int windowsRightBorder = 15; // right border on windows
64static const int windowsCheckMarkWidth = 14; // checkmarks width on windows
65
66static const int windowsCEitemViewCheckBoxSize = 14;
67static const int windowsCEFrameGroupBoxOffset = 9;
68static const int windowsCEIndicatorSize = 14;
69static const int windowsCEExclusiveIndicatorSize = 14;
70static const int windowsCESliderThickness = 24;
71static const int windowsCEIconSize = 16;
72
73static const QColor windowsCECheckBoxGradientColorBegin = QColor(222, 224, 214);
74static const QColor windowsCECheckBoxGradientColorEnd = QColor(255, 255, 255);
75
76enum QSliderDirection { SlUp, SlDown, SlLeft, SlRight };
77
78QWindowsCEStyle::QWindowsCEStyle() : QWindowsStyle() {
79 qApp->setEffectEnabled(Qt::UI_FadeMenu, false);
80 qApp->setEffectEnabled(Qt::UI_AnimateMenu, false);
81}
82
83void QWindowsCEStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option,
84 QPainter *painter, const QWidget *widget) const {
85
86 bool doRestore = false;
87 QRect rect = option->rect;
88
89 switch (element) {
90 case PE_PanelButtonTool: {
91 if (
92#ifndef QT_NO_TOOLBAR
93 (widget && qobject_cast<QToolBar*>(widget->parentWidget())) ||
94#endif
95#ifndef QT_NO_DOCKWIDGET
96 (widget && widget->inherits("QDockWidgetTitleButton")) ||
97#endif
98 (option->state & (State_Sunken | State_On)))
99 QWindowsCEStylePrivate::drawWinCEButton(painter, option->rect.adjusted(0, 0, 0, 0),
100 option->palette, option->state & (State_Sunken | State_On),
101 &option->palette.button());
102 if (option->state & (State_On)){
103 QBrush fill = QBrush(option->palette.midlight().color(), Qt::Dense4Pattern);
104 painter->fillRect(option->rect.adjusted(windowsItemFrame , windowsItemFrame ,
105 -windowsItemFrame , -windowsItemFrame ), fill);
106 }
107 break; }
108 case PE_IndicatorButtonDropDown:
109 QWindowsCEStylePrivate::drawWinCEButton(painter, option->rect, option->palette,
110 option->state & (State_Sunken | State_On),
111 &option->palette.brush(QPalette::Button));
112 break;
113#ifndef QT_NO_TABBAR
114 case PE_IndicatorTabTear:
115 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
116 bool rtl = tab->direction == Qt::RightToLeft;
117 QRect rect = tab->rect;
118 QPainterPath path;
119 rect.setTop(rect.top() + ((tab->state & State_Selected) ? 1 : 3));
120 rect.setBottom(rect.bottom() - ((tab->state & State_Selected) ? 0 : 2));
121 path.moveTo(QPoint(rtl ? rect.right() : rect.left(), rect.top()));
122 int count = 3;
123 for(int jags = 1; jags <= count; ++jags, rtl = !rtl)
124 path.lineTo(QPoint(rtl ? rect.left() : rect.right(), rect.top() + jags * rect.height()/count));
125
126 painter->setPen(QPen(tab->palette.light(), qreal(.8)));
127 painter->setBrush(tab->palette.background());
128 painter->setRenderHint(QPainter::Antialiasing);
129 painter->drawPath(path);
130 }
131 break;
132#endif //QT_NO_TABBAR
133#ifndef QT_NO_TOOLBAR
134 case PE_IndicatorToolBarSeparator:
135 //nothing to draw on WindowsCE
136 break;
137 case PE_IndicatorToolBarHandle:
138 painter->save();
139 painter->translate(option->rect.x(), option->rect.y());
140 if (option->state & State_Horizontal) {
141 int x = option->rect.width() / 2 - 4;
142 if (QApplication::layoutDirection() == Qt::RightToLeft)
143 x -= 2;
144 if (option->rect.height() > 4) {
145 QWindowsCEStylePrivate::drawWinCEButton(painter,x - 1, 0, 7, option->rect.height(),
146 option->palette, false, 0);
147 QWindowsCEStylePrivate::drawWinCEPanel(painter, x, 1, 3, option->rect.height() - 1,
148 option->palette, false, 0);
149 QWindowsCEStylePrivate::drawWinCEPanel(painter, x + 3, 1, 3, option->rect.height() - 1,
150 option->palette, false, 0);
151 painter->setPen(option->palette.button().color());
152 painter->drawLine(x + 4, 2, x + 4,option->rect.height() - 2);
153 }
154 } else {
155 if (option->rect.width() > 4) {
156 int y = option->rect.height() / 2 - 4;
157 QWindowsCEStylePrivate::drawWinCEPanel(painter, 2, y, option->rect.width() - 2, 3,
158 option->palette, false, 0);
159 QWindowsCEStylePrivate::drawWinCEPanel(painter, 2, y + 3, option->rect.width() - 2, 3,
160 option->palette, false, 0);
161 }
162 }
163 painter->restore();
164 break;
165
166#endif // QT_NO_TOOLBAR
167 case PE_FrameButtonTool: {
168#ifndef QT_NO_DOCKWIDGET
169 if (widget && widget->inherits("QDockWidgetTitleButton")) {
170 if (const QDockWidget *dw = qobject_cast<const QDockWidget *>(widget->parent()))
171 if (dw->isFloating()){
172 QWindowsCEStylePrivate::drawWinCEButton(painter, option->rect.adjusted(1, 1, 0, 0),
173 option->palette, option->state & (State_Sunken | State_On),
174 &option->palette.button());
175 return;
176 }
177 }
178#endif // QT_NO_DOCKWIDGET
179 QBrush fill;
180 bool stippled;
181 bool panel = (element == PE_PanelButtonTool);
182 if ((!(option->state & State_Sunken ))
183 && (!(option->state & State_Enabled)
184 || ((option->state & State_Enabled ) && !(option->state & State_MouseOver)))
185 && (option->state & State_On)) {
186 fill = QBrush(option->palette.light().color(), Qt::Dense4Pattern);
187 stippled = true;
188 } else {
189 fill = option->palette.brush(QPalette::Button);
190 stippled = false;
191 }
192 if (option->state & (State_Raised | State_Sunken | State_On)) {
193 if (option->state & State_AutoRaise) {
194 if(option->state & (State_Enabled | State_Sunken | State_On)){
195 if (panel)
196 QWindowsCEStylePrivate::drawWinCEPanel(painter, option->rect, option->palette,
197 option->state & (State_Sunken | State_On), &fill);
198 else
199 qDrawShadeRect(painter, option->rect, option->palette,
200 option->state & (State_Sunken | State_On), 1);
201 }
202 if (stippled) {
203 painter->setPen(option->palette.button().color());
204 painter->drawRect(option->rect.adjusted(1, 1, -2, -2));
205 }
206 } else {
207 QWindowsCEStylePrivate::drawWinCEButton(painter, option->rect, option->palette,
208 option->state & (State_Sunken | State_On), panel ? &fill : 0);
209 }
210 } else {
211 painter->fillRect(option->rect, fill);
212 }
213 break; }
214
215 case PE_PanelButtonBevel: {
216 QBrush fill;
217 bool panel = element != PE_FrameButtonBevel;
218 painter->setBrushOrigin(option->rect.topLeft());
219 if (!(option->state & State_Sunken) && (option->state & State_On))
220 fill = QBrush(option->palette.light().color(), Qt::Dense4Pattern);
221 else
222 fill = option->palette.brush(QPalette::Button);
223
224 if (option->state & (State_Raised | State_On | State_Sunken)) {
225 QWindowsCEStylePrivate::drawWinCEButton(painter, option->rect, option->palette,
226 option->state & (State_Sunken | State_On),
227 panel ? &fill : 0); ;
228 } else {
229 if (panel)
230 painter->fillRect(option->rect, fill);
231 else
232 painter->drawRect(option->rect);
233 }
234 break; }
235
236 case PE_FrameGroupBox:
237 if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
238 QRect fr = frame->rect;
239 painter->setPen(frame->palette.shadow().color());
240 painter->drawRect(fr.x(), fr.y(), fr.x() + fr.width() - 1,
241 fr.y() + fr.height() - windowsCEFrameGroupBoxOffset);
242 }
243 break;
244
245 case PE_IndicatorCheckBox: {
246 QBrush fill;
247 if (option->state & State_NoChange)
248 fill = QBrush(option->palette.base().color(), Qt::Dense4Pattern);
249 else if (option->state & State_Sunken)
250 fill = option->palette.button();
251 else if (option->state & State_Enabled)
252 fill = option->palette.base();
253 else
254 fill = option->palette.background();
255 painter->save();
256 doRestore = true;
257 painter->fillRect(option->rect,fill);
258 painter->setPen(option->palette.dark().color());
259 painter->drawRect(option->rect);
260 painter->setPen(option->palette.shadow().color());
261 painter->drawLine(option->rect.x() + 1,option->rect.y() + 1,
262 option->rect.x() + option->rect.width() - 1, option->rect.y() + 1);
263 painter->drawLine(option->rect.x() + 1,option->rect.y() + 1,
264 option->rect.x() + 1, option->rect.y() + option->rect.height() - 1);
265 //fall through...
266 }
267 case PE_IndicatorViewItemCheck:
268 case PE_Q3CheckListIndicator: {
269 if (!doRestore) {
270 painter->save();
271 doRestore = true;
272 }
273 int arrowSize= 2;
274 if (element == PE_Q3CheckListIndicator || element == PE_IndicatorViewItemCheck) {
275 QLinearGradient linearGradient(QPoint(option->rect.x(),option->rect.y()), QPoint(option->rect.x()+option->rect.width(),
276 option->rect.y()+option->rect.height()));
277 linearGradient.setColorAt(0, windowsCECheckBoxGradientColorBegin);
278 linearGradient.setColorAt(1, windowsCECheckBoxGradientColorEnd);
279 painter->setBrush(linearGradient);
280 painter->setPen(Qt::NoPen);
281 if (option->state & State_NoChange)
282 painter->setBrush(option->palette.brush(QPalette::Button));
283 painter->setPen(option->palette.link().color());
284 painter->drawRect(option->rect.x(), option->rect.y(), windowsCEitemViewCheckBoxSize, windowsCEitemViewCheckBoxSize);
285 painter->setPen(option->palette.brightText().color());
286 arrowSize= 3;
287 }
288 if (!(option->state & State_Off)) {
289 QLineF lines[9];
290 int i, xx, yy;
291 xx = option->rect.x() + 4;
292 yy = option->rect.y() + 6;
293 for (i = 0; i < 4; ++i) {
294 lines[i] = QLineF(xx, yy, xx, yy + arrowSize);
295 ++xx;
296 ++yy;
297 }
298 yy -= 2;
299 for (i = 4; i < 9; ++i) {
300 lines[i] = QLineF(xx, yy, xx, yy + arrowSize);
301 ++xx;
302 --yy;
303 }
304 painter->drawLines(lines, 9);
305 }
306 if (doRestore)
307 painter->restore();
308
309 break; }
310 case PE_IndicatorRadioButton: {
311 QRect ir = option->rect;
312 painter->save();
313 painter->setPen(Qt::NoPen);
314 painter->setBrush(option->palette.light());
315 painter->drawEllipse(option->rect);
316 painter->setPen(option->palette.shadow().color());
317 painter->setBrush(option->palette.shadow().color());
318 painter->drawArc(option->rect, 0, 360 * 16);
319 painter->drawArc(option->rect.x() + 1, option->rect.y() + 1, option->rect.width() - 2,
320 option->rect.height() - 2, 40 * 16, 180 * 16);
321 painter->setPen(option->palette.light().color());
322 painter->drawPoint(option->rect.x() + 11, option->rect.y() + 3);
323 painter->drawPoint(option->rect.x() + 3,option->rect.y() + 3);
324 painter->setPen(option->palette.shadow().color());
325 painter->drawPoint(option->rect.x() +3,option->rect.y() + 12);
326 if (option->state & (State_Sunken | State_On)) {
327 painter->setPen(Qt::NoPen);
328 painter->setBrush(option->palette.text());
329 painter->drawEllipse(option->rect.x() +3,option->rect.y()+ 2,9,10);
330 }
331 painter->restore();
332 break; }
333 case PE_PanelMenuBar:
334 painter->save();
335 painter->setPen(option->palette.shadow().color());
336 painter->drawRect(option->rect);
337 painter->restore();
338 break;
339 case PE_PanelButtonCommand:
340 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
341 QBrush fill;
342 State flags = option->state;
343 QPalette pal = option->palette;
344 QRect r = option->rect;
345 if (! (flags & State_Sunken) && (flags & State_On))
346 fill = QBrush(pal.light().color(), Qt::Dense4Pattern);
347 else
348 fill = pal.brush(QPalette::Button);
349 if (btn->features & QStyleOptionButton::DefaultButton && flags & State_Sunken) {
350 painter->setPen(pal.dark().color());
351 painter->setBrush(fill);
352 painter->drawRect(r.adjusted(0, 0, -1, -1));
353 } else if (flags & (State_Raised | State_Sunken | State_On | State_Sunken)) {
354 QWindowsCEStylePrivate::drawWinCEButton(painter, r, pal, flags & (State_Sunken | State_On),
355 &fill);
356 } else {
357 painter->fillRect(r, fill);
358 }
359
360 }
361 break;
362 case PE_FrameDefaultButton: {
363 painter->setPen(option->palette.shadow().color());
364 QRect rect = option->rect;
365 rect.adjust(0, 0, -1, -1);
366 painter->drawRect(rect);
367 break; }
368 case PE_IndicatorSpinPlus:
369 case PE_IndicatorSpinMinus: {
370 QRect r = option->rect;
371 int fw = pixelMetric(PM_DefaultFrameWidth, option, widget)+2;
372 QRect br = r.adjusted(fw, fw, -fw, -fw);
373 int offset = (option->state & State_Sunken) ? 1 : 0;
374 int step = (br.width() + 4) / 5;
375 painter->fillRect(br.x() + offset, br.y() + offset +br.height() / 2 - step / 2,
376 br.width(), step,
377 option->palette.buttonText());
378 if (element == PE_IndicatorSpinPlus)
379 painter->fillRect(br.x() + br.width() / 2 - step / 2 + offset, br.y() + offset+4,
380 step, br.height()-7,
381 option->palette.buttonText());
382 break; }
383 case PE_IndicatorSpinUp:
384 case PE_IndicatorSpinDown: {
385 painter->save();
386 QPoint points[7];
387 switch (element) {
388 case PE_IndicatorSpinUp:
389 points[0] = QPoint(-2, -4);
390 points[1] = QPoint(-2, 2);
391 points[2] = QPoint(-1, -3);
392 points[3] = QPoint(-1, 1);
393 points[4] = QPoint(0, -2);
394 points[5] = QPoint(0, 0);
395 points[6] = QPoint(1, -1);
396 break;
397 case PE_IndicatorSpinDown:
398 points[0] = QPoint(0, -4);
399 points[1] = QPoint(0, 2);
400 points[2] = QPoint(-1, -3);
401 points[3] = QPoint(-1, 1);
402 points[4] = QPoint(-2, -2);
403 points[5] = QPoint(-2, 0);
404 points[6] = QPoint(-3, -1);
405 break;
406 default:
407 break;
408 }
409 if (option->state & State_Sunken)
410 painter->translate(pixelMetric(PM_ButtonShiftHorizontal),
411 pixelMetric(PM_ButtonShiftVertical));
412 if (option->state & State_Enabled) {
413 painter->translate(option->rect.x() + option->rect.width() / 2,
414 option->rect.y() + option->rect.height() / 2);
415 painter->setPen(option->palette.buttonText().color());
416 painter->drawLine(points[0], points[1]);
417 painter->drawLine(points[2], points[3]);
418 painter->drawLine(points[4], points[5]);
419 painter->drawPoint(points[6]);
420 } else {
421 painter->translate(option->rect.x() + option->rect.width() / 2 + 1,
422 option->rect.y() + option->rect.height() / 2 + 1);
423 painter->setPen(option->palette.light().color());
424 painter->drawLine(points[0], points[1]);
425 painter->drawLine(points[2], points[3]);
426 painter->drawLine(points[4], points[5]);
427 painter->drawPoint(points[6]);
428 painter->translate(-1, -1);
429 painter->setPen(option->palette.mid().color());
430 painter->drawLine(points[0], points[1]);
431 painter->drawLine(points[2], points[3]);
432 painter->drawLine(points[4], points[5]);
433 painter->drawPoint(points[6]);
434 }
435
436 painter->restore();
437 break; }
438 case PE_IndicatorArrowUp:
439 case PE_IndicatorArrowDown:
440 case PE_IndicatorArrowRight:
441 case PE_IndicatorArrowLeft: {
442 painter->save();
443 QPoint points[9];
444 switch (element) {
445 case PE_IndicatorArrowUp:
446
447 points[0] = QPoint(-4, 2);
448 points[1] = QPoint(4, 2);
449 points[2] = QPoint(-3, 1);
450 points[3] = QPoint(3, 1);
451 points[4] = QPoint(-2, 0);
452 points[5] = QPoint(2, 0);
453 points[6] = QPoint(-1, -1);
454 points[7] = QPoint(1, -1);
455 points[8] = QPoint(0, -2);
456 break;
457 case PE_IndicatorArrowDown:
458
459 points[0] = QPoint(-4, -2);
460 points[1] = QPoint(4, -2);
461 points[2] = QPoint(-3, -1);
462 points[3] = QPoint(3, -1);
463 points[4] = QPoint(-2, 0);
464 points[5] = QPoint(2, 0);
465 points[6] = QPoint(-1, 1);
466 points[7] = QPoint(1, 1);
467 points[8] = QPoint(0, 2);
468 break;
469 case PE_IndicatorArrowRight:
470 points[0] = QPoint(-3, -4);
471 points[1] = QPoint(-3, 4);
472 points[2] = QPoint(-2, -3);
473 points[3] = QPoint(-2, 3);
474 points[4] = QPoint(-1, -2);
475 points[5] = QPoint(-1, 2);
476 points[6] = QPoint(0, -1);
477 points[7] = QPoint(0, 1);
478 points[8] = QPoint(1, 0);
479 break;
480 case PE_IndicatorArrowLeft:
481 points[0] = QPoint(1, -4);
482 points[1] = QPoint(1, 4);
483 points[2] = QPoint(0, -3);
484 points[3] = QPoint(0, 3);
485 points[4] = QPoint(-1, -2);
486 points[5] = QPoint(-1, 2);
487 points[6] = QPoint(-2, -1);
488 points[7] = QPoint(-2, 1);
489 points[8] = QPoint(-3, 0);
490 break;
491 default:
492 break;
493 }
494 if (option->state & State_Sunken)
495 painter->translate(pixelMetric(PM_ButtonShiftHorizontal),
496 pixelMetric(PM_ButtonShiftVertical));
497 if (option->state & State_Enabled) {
498 painter->translate(option->rect.x() + option->rect.width() / 2,
499 option->rect.y() + option->rect.height() / 2);
500 painter->setPen(option->palette.buttonText().color());
501 painter->drawLine(points[0], points[1]);
502 painter->drawLine(points[2], points[3]);
503 painter->drawLine(points[4], points[5]);
504 painter->drawLine(points[6], points[7]);
505 painter->drawPoint(points[8]);
506 } else {
507 painter->translate(option->rect.x() + option->rect.width() / 2 + 1,
508 option->rect.y() + option->rect.height() / 2 + 1);
509 painter->setPen(option->palette.light().color());
510 painter->drawLine(points[0], points[1]);
511 painter->drawLine(points[2], points[3]);
512 painter->drawLine(points[4], points[5]);
513 painter->drawLine(points[6], points[7]);
514 painter->drawPoint(points[8]);
515 painter->translate(-1, -1);
516 painter->setPen(option->palette.mid().color());
517 painter->drawLine(points[0], points[1]);
518 painter->drawLine(points[2], points[3]);
519 painter->drawLine(points[4], points[5]);
520 painter->drawLine(points[6], points[7]);
521 painter->drawPoint(points[8]);
522 }
523 painter->restore();
524 break; }
525
526 case PE_FrameWindow: {
527 QPalette popupPal = option->palette;
528 popupPal.setColor(QPalette::Light, option->palette.background().color());
529 popupPal.setColor(QPalette::Midlight, option->palette.light().color());
530 QWindowsCEStylePrivate::drawWinCEPanel(painter, option->rect, popupPal, option->state & State_Sunken);
531 break; }
532
533 case PE_Frame:
534 case PE_FrameMenu:
535 if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
536 QPalette popupPal = frame->palette;
537 QRect r = frame->rect;
538 qDrawPlainRect(painter, r, frame->palette.shadow().color(),1);
539 }
540 break;
541 case PE_FrameStatusBar:
542 QWindowsCEStylePrivate::drawWinCEPanel(painter, option->rect, option->palette, true, 0);
543 break;
544
545 case PE_FrameTabWidget: {
546 QRect rect = option->rect;
547 QPalette pal = option->palette;
548 QWindowsCEStylePrivate::drawWinCEButton(painter, option->rect, option->palette, false, 0);
549 break; }
550 default:
551 QWindowsStyle::drawPrimitive(element, option, painter, widget);
552 break;
553 }
554}
555
556void QWindowsCEStyle::drawControl(ControlElement element, const QStyleOption *option,
557 QPainter *painter, const QWidget *widget) const {
558 switch (element) {
559 #ifndef QT_NO_MENU
560 case CE_MenuTearoff: {
561 if(option->state & State_Selected) {
562 if(pixelMetric(PM_MenuPanelWidth, option, widget) > 1)
563 qDrawShadePanel(painter, option->rect.x(), option->rect.y(), option->rect.width(),
564 option->rect.height(), option->palette, false, 2,
565 &option->palette.brush(QPalette::Button));
566 else
567 qDrawShadePanel(painter, option->rect.x() + 1, option->rect.y() + 1, option->rect.width() - 2,
568 option->rect.height() - 2, option->palette, true, 1, &option->palette.brush(QPalette::Button));
569 } else {
570 painter->fillRect(option->rect, option->palette.brush(QPalette::Button));
571 }
572 painter->setPen(QPen(option->palette.dark().color(), 1, Qt::DashLine));
573 painter->drawLine(option->rect.x()+2, option->rect.y()+option->rect.height()/2-1, option->rect.x()+option->rect.width()-4,
574 option->rect.y()+option->rect.height()/2-1);
575 painter->setPen(QPen(option->palette.light().color(), 1, Qt::DashLine));
576 painter->drawLine(option->rect.x()+2, option->rect.y()+option->rect.height()/2, option->rect.x()+option->rect.width()-4,
577 option->rect.y()+option->rect.height()/2);
578 break; }
579
580
581 case CE_MenuBarItem:
582 if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
583 bool active = mbi->state & State_Selected;
584 bool hasFocus = mbi->state & State_HasFocus;
585 bool down = mbi->state & State_Sunken;
586 QStyleOptionMenuItem newMbi = *mbi;
587 if (active || hasFocus) {
588 QBrush b = mbi->palette.brush(QPalette::Highlight);
589 if (active && down) {
590 painter->fillRect(mbi->rect.adjusted(0, 1, 0, -1), b);
591 }
592 }
593 uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip
594 | Qt::TextSingleLine;
595 if (!styleHint(SH_UnderlineShortcut, mbi, widget))
596 alignment |= Qt::TextHideMnemonic;
597
598 painter->save();
599 QFont f = painter->font();
600 f.setBold(true);
601 painter->setFont(f);
602 QPixmap pix = mbi->icon.pixmap(pixelMetric(PM_SmallIconSize),
603 (mbi->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled);
604 if (!pix.isNull())
605 drawItemPixmap(painter,mbi->rect, alignment, pix);
606 else
607 if (active && down)
608 drawItemText(painter, mbi->rect, alignment, mbi->palette, mbi->state & State_Enabled,
609 mbi->text, QPalette::Light);
610 else
611 drawItemText(painter, mbi->rect, alignment, mbi->palette, mbi->state & State_Enabled,
612 mbi->text, QPalette::ButtonText);
613 painter->restore();
614 }
615 break;
616
617 case CE_MenuBarEmptyArea:
618 painter->save();
619 painter->setPen(option->palette.shadow().color());
620 if (widget && !widget->testAttribute(Qt::WA_NoSystemBackground)) {
621 painter->eraseRect(option->rect);
622 QRect r = option->rect;
623 painter->drawLine(r.x() + 1, r.y() + 1, r.x()+ 1, r.y()+ r.height() - 2);
624 painter->drawLine(r.x() - 2 + r.width(), r.y() + 1, r.x() - 2 + r.width(), r.y() + r.height() - 2);
625 painter->drawLine(r.x() + 1, r.y() +1, r.x() - 1 + r.width(), r.y() + 1);
626 painter->drawLine(r.x() + 1, r.y() + r.height()-2 , r.x() - 2 + r.width(), r.y() + r.height() - 2);
627 }
628 painter->restore();
629 break;
630
631 case CE_MenuItem:
632 if (const QStyleOptionMenuItem *menuitem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
633 int x, y, w, h;
634 menuitem->rect.getRect(&x, &y, &w, &h);
635 int tab = menuitem->tabWidth;
636 bool dis = !(menuitem->state & State_Enabled);
637 bool checked = menuitem->checkType != QStyleOptionMenuItem::NotCheckable
638 ? menuitem->checked : false;
639 bool act = menuitem->state & State_Selected;
640
641 // windows always has a check column, regardless whether we have an icon or not
642 int checkcol = qMax(menuitem->maxIconWidth, windowsCheckMarkWidth);
643 QBrush fill = menuitem->palette.brush(act ? QPalette::Highlight : QPalette::Button);
644 painter->fillRect(menuitem->rect.adjusted(1, 1, 0, 0), fill);
645
646 if (menuitem->menuItemType == QStyleOptionMenuItem::Separator) {
647 int yoff = y-1 + h / 2;
648 painter->setPen(menuitem->palette.shadow().color());
649 painter->drawLine(x + 4, yoff + 1, x + w - 8, yoff + 1);
650 return;
651 }
652
653 QRect vCheckRect = visualRect(option->direction, menuitem->rect, QRect(menuitem->rect.x(),
654 menuitem->rect.y(), checkcol, menuitem->rect.height()));
655 if (checked) {
656 if (act && !dis) {
657 qDrawPlainRect(painter, vCheckRect,
658 menuitem->palette.button().color(), 1,
659 &menuitem->palette.brush(QPalette::Button));
660 } else {
661 QBrush fill(menuitem->palette.button().color(), Qt::Dense4Pattern);
662 qDrawPlainRect(painter, vCheckRect,menuitem->palette.button().color(), 1, &fill);
663 }
664 } else if (!act) {
665 painter->fillRect(vCheckRect, menuitem->palette.brush(QPalette::Button));
666 }
667 // On Windows Style, if we have a checkable item and an icon we
668 // draw the icon recessed to indicate an item is checked. If we
669 // have no icon, we draw a checkmark instead.
670 if (!menuitem->icon.isNull()) {
671 QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
672 if (act && !dis)
673 mode = QIcon::Active;
674 QPixmap pixmap;
675 if (checked)
676 pixmap = menuitem->icon.pixmap(pixelMetric(PM_SmallIconSize), mode, QIcon::On);
677 else
678 pixmap = menuitem->icon.pixmap(pixelMetric(PM_SmallIconSize), mode);
679 int pixw = pixmap.width();
680 int pixh = pixmap.height();
681 if (act && !dis && !checked)
682 qDrawPlainRect(painter, vCheckRect, menuitem->palette.button().color(), 1,
683 &menuitem->palette.brush(QPalette::Button));
684 QRect pmr(0, 0, pixw, pixh);
685 pmr.moveCenter(vCheckRect.center());
686 painter->setPen(menuitem->palette.text().color());
687 painter->drawPixmap(pmr.topLeft(), pixmap);
688 } else if (checked) {
689 QStyleOptionMenuItem newMi = *menuitem;
690 newMi.state = State_None;
691 if (!dis)
692 newMi.state |= State_Enabled;
693 if (act)
694 newMi.state |= State_On;
695 newMi.rect = visualRect(option->direction, menuitem->rect, QRect(menuitem->rect.x()
696 + windowsItemFrame, menuitem->rect.y() + windowsItemFrame,
697 checkcol - 2 * windowsItemFrame, menuitem->rect.height() - 2*windowsItemFrame));
698 drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, painter, widget);
699 }
700 painter->setPen(act ? menuitem->palette.highlightedText().color() : menuitem->palette.buttonText().color());
701
702 QColor discol;
703 if (dis) {
704 discol = menuitem->palette.text().color();
705 painter->setPen(discol);
706 }
707 int xm = windowsItemFrame + checkcol + windowsItemHMargin;
708 int xpos = menuitem->rect.x() + xm;
709 QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
710 QRect vTextRect = visualRect(option->direction, menuitem->rect, textRect);
711 QString s = menuitem->text;
712 if (!s.isEmpty()) { // draw text
713 painter->save();
714 int t = s.indexOf(QLatin1Char('\t'));
715 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
716 if (!styleHint(SH_UnderlineShortcut, menuitem, widget))
717 text_flags |= Qt::TextHideMnemonic;
718 text_flags |= Qt::AlignLeft;
719 if (t >= 0) {
720 QRect vShortcutRect = visualRect(option->direction, menuitem->rect,
721 QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
722 if (dis && !act)
723 painter->setPen(discol);
724 painter->drawText(vShortcutRect, text_flags, s.mid(t + 1));
725 s = s.left(t);
726 }
727 QFont font = menuitem->font;
728 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
729 font.setBold(true);
730 painter->setFont(font);
731 if (dis && !act)
732 painter->setPen(discol);
733 painter->drawText(vTextRect, text_flags, s.left(t));
734 painter->restore();
735 }
736 if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow
737 int dim = (h - 2 * windowsItemFrame) / 2;
738 PrimitiveElement arrow;
739 arrow = (option->direction == Qt::RightToLeft) ? PE_IndicatorSpinDown : PE_IndicatorSpinUp;
740 xpos = x + w - windowsArrowHMargin - windowsItemFrame - dim;
741 QRect vSubMenuRect = visualRect(option->direction, menuitem->rect, QRect(xpos, y + h / 2 - dim / 2, dim, dim));
742 QStyleOptionMenuItem newMI = *menuitem;
743 newMI.rect = vSubMenuRect;
744 newMI.state = dis ? State_None : State_Enabled;
745 if (act)
746 newMI.palette.setColor(QPalette::ButtonText,
747 newMI.palette.highlightedText().color());
748 drawPrimitive(arrow, &newMI, painter, widget);
749 }
750 }
751 break;
752#endif // QT_NO_MENU
753 case CE_MenuVMargin:
754 painter->fillRect(option->rect, Qt::white);
755 break;
756 case CE_MenuEmptyArea:
757 QWindowsStyle::drawControl(element,option, painter, widget);
758 break;
759
760#ifndef QT_NO_TABBAR
761 case CE_TabBarTab:
762 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
763 drawControl(CE_TabBarTabShape, tab, painter, widget);
764 drawControl(CE_TabBarTabLabel, tab, painter, widget);
765 }
766 break;
767 case CE_TabBarTabShape:
768 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
769 bool rtlHorTabs = (tab->direction == Qt::RightToLeft
770 && (tab->shape == QTabBar::RoundedNorth
771 || tab->shape == QTabBar::RoundedSouth));
772 bool selected = tab->state & State_Selected;
773 bool lastTab = ((!rtlHorTabs && tab->position == QStyleOptionTab::End)
774 || (rtlHorTabs
775 && tab->position == QStyleOptionTab::Beginning));
776 bool firstTab = ((!rtlHorTabs
777 && tab->position == QStyleOptionTab::Beginning)
778 || (rtlHorTabs
779 && tab->position == QStyleOptionTab::End));
780 bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab;
781 bool previousSelected =
782 ((!rtlHorTabs
783 && tab->selectedPosition == QStyleOptionTab::PreviousIsSelected)
784 || (rtlHorTabs
785 && tab->selectedPosition == QStyleOptionTab::NextIsSelected));
786 bool nextSelected =
787 ((!rtlHorTabs
788 && tab->selectedPosition == QStyleOptionTab::NextIsSelected)
789 || (rtlHorTabs
790 && tab->selectedPosition
791 == QStyleOptionTab::PreviousIsSelected));
792 int tabBarAlignment = styleHint(SH_TabBar_Alignment, tab, widget);
793 bool leftAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignLeft)
794 || (rtlHorTabs
795 && tabBarAlignment == Qt::AlignRight);
796
797 bool rightAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignRight)
798 || (rtlHorTabs
799 && tabBarAlignment == Qt::AlignLeft);
800 QColor light = tab->palette.light().color();
801 QColor midlight = tab->palette.midlight().color();
802 QColor dark = tab->palette.dark().color();
803 QColor shadow = tab->palette.shadow().color();
804 QColor background = tab->palette.background().color();
805 int borderThinkness = pixelMetric(PM_TabBarBaseOverlap, tab, widget);
806 if (selected)
807 borderThinkness /= 2;
808 QRect r2(option->rect);
809 int x1 = r2.left();
810 int x2 = r2.right();
811 int y1 = r2.top();
812 int y2 = r2.bottom();
813 switch (tab->shape) {
814 default:
815 QCommonStyle::drawControl(element, tab, painter, widget);
816 break;
817 case QTabBar::RoundedNorth: {
818 if (!selected) {
819 y1 += 2;
820 x1 += firstTab ? borderThinkness : 0;
821 x2 -= lastTab ? borderThinkness : 0;
822 }
823
824 painter->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 2), tab->palette.background());
825
826 // Delete border
827 if (selected) {
828 painter->setPen(background);
829 painter->drawLine(x1, y2 - 1, x2, y2 - 1);
830 painter->drawLine(x1, y2 + 1, x2, y2 + 1);
831 painter->drawLine(x1, y2, x2, y2);
832 }
833 // Left
834 if (firstTab || selected || onlyOne || !previousSelected) {
835 painter->setPen(dark);
836 painter->drawLine(x1, y1 + 2, x1, y2 - ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness));
837 painter->drawPoint(x1 + 1, y1 + 1);
838 painter->setPen(midlight);
839 painter->drawLine(x1 + 1, y1 + 2, x1 + 1, y2 -
840 ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness));
841
842 }
843 // Top
844 {
845 int beg = x1 + (previousSelected ? 0 : 2);
846 int end = x2 - (nextSelected ? 0 : 2);
847 painter->setPen(dark);
848 painter->drawLine(beg, y1, end, y1);
849
850 painter->setPen(midlight);
851 painter->drawLine(beg, y1 + 1, end, y1 + 1);
852
853 }
854 // Right
855 if (lastTab || selected || onlyOne || !nextSelected) {
856 painter->setPen(shadow);
857 painter->drawLine(x2, y1 + 2, x2, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
858 painter->drawPoint(x2 - 1, y1 + 1);
859 painter->setPen(dark);
860 painter->drawLine(x2 - 1, y1 + 2, x2 - 1, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
861 }
862 break; }
863 case QTabBar::RoundedSouth: {
864 if (!selected) {
865 y2 -= 2;
866 x1 += firstTab ? borderThinkness : 0;
867 x2 -= lastTab ? borderThinkness : 0;
868 }
869
870 painter->fillRect(QRect(x1 + 1, y1 + 2, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.background());
871
872 // Delete border
873 if (selected) {
874 painter->setPen(background);
875 painter->drawLine(x1, y1 + 1, x2 - 1, y1 + 1);
876 painter->drawLine(x1, y1 - 1, x2 - 1, y1 - 1);
877 painter->drawLine(x1, y1, x2 - 1, y1);
878 }
879 // Left
880 if (firstTab || selected || onlyOne || !previousSelected) {
881 painter->setPen(dark);
882 painter->drawLine(x1, y2 - 2, x1, y1 + ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness));
883 painter->drawPoint(x1 + 1, y2 - 1);
884 painter->setPen(midlight);
885 painter->drawLine(x1 + 1, y2 - 2, x1 + 1, y1 + ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness));
886 }
887 // Bottom
888 {
889 int beg = x1 + (previousSelected ? 0 : 2);
890 int end = x2 - (nextSelected ? 0 : 2);
891 painter->setPen(shadow);
892 painter->drawLine(beg, y2, end, y2);
893 painter->setPen(dark);
894 painter->drawLine(beg, y2 - 1, end, y2 - 1);
895 }
896 // Right
897 if (lastTab || selected || onlyOne || !nextSelected) {
898 painter->setPen(shadow);
899 painter->drawLine(x2, y2 - 2, x2, y1 + ((onlyOne || lastTab) && selected &&
900 rightAligned ? 0 : borderThinkness));
901 painter->drawPoint(x2 - 1, y2 - 1);
902 painter->setPen(dark);
903 painter->drawLine(x2 - 1, y2 - 2, x2 - 1, y1 + ((onlyOne || lastTab) && selected &&
904 rightAligned ? 0 : borderThinkness));
905 }
906 break; }
907 case QTabBar::RoundedWest: {
908 if (!selected) {
909 x1 += 2;
910 y1 += firstTab ? borderThinkness : 0;
911 y2 -= lastTab ? borderThinkness : 0;
912 }
913
914 painter->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 2, (y2 - y1) - 1), tab->palette.background());
915
916 // Delete border
917 if (selected) {
918 painter->setPen(background);
919 painter->drawLine(x2 - 1, y1, x2 - 1, y2);
920 painter->drawLine(x2, y1, x2, y2);
921 }
922 // Top
923 if (firstTab || selected || onlyOne || !previousSelected) {
924 painter->setPen(dark);
925 painter->drawLine(x1 + 2, y1, x2 - ((onlyOne || firstTab) && selected &&
926 leftAligned ? 0 : borderThinkness), y1);
927 painter->drawPoint(x1 + 1, y1 + 1);
928 painter->setPen(midlight);
929 painter->drawLine(x1 + 2, y1 + 1, x2 - ((onlyOne || firstTab) && selected &&
930 leftAligned ? 0 : borderThinkness), y1 + 1);
931 }
932 // Left
933 {
934 int beg = y1 + (previousSelected ? 0 : 2);
935 int end = y2 - (nextSelected ? 0 : 2);
936 painter->setPen(dark);
937 painter->drawLine(x1, beg, x1, end);
938 painter->setPen(midlight);
939 painter->drawLine(x1 + 1, beg, x1 + 1, end);
940 }
941 // Bottom
942 if (lastTab || selected || onlyOne || !nextSelected) {
943 painter->setPen(shadow);
944 painter->drawLine(x1 + 3, y2, x2 - ((onlyOne || lastTab) && selected &&
945 rightAligned ? 0 : borderThinkness), y2);
946 painter->drawPoint(x1 + 2, y2 - 1);
947 painter->setPen(dark);
948 painter->drawLine(x1 + 3, y2 - 1, x2 - ((onlyOne || lastTab) && selected &&
949 rightAligned ? 0 : borderThinkness), y2 - 1);
950 painter->drawPoint(x1 + 1, y2 - 1);
951 painter->drawPoint(x1 + 2, y2);
952 }
953 break; }
954 case QTabBar::RoundedEast: {
955 if (!selected) {
956 x2 -= 2;
957 y1 += firstTab ? borderThinkness : 0;
958 y2 -= lastTab ? borderThinkness : 0;
959 }
960
961 painter->fillRect(QRect(x1 + 2, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.background());
962
963 // Delete border
964 if (selected) {
965 painter->setPen(background);
966 painter->drawLine(x1 + 1, y1, x1 + 1, y2 - 1);
967 painter->drawLine(x1, y1, x1, y2 - 1);
968 }
969 // Top
970 if (firstTab || selected || onlyOne || !previousSelected) {
971 painter->setPen(dark);
972 painter->drawLine(x2 - 2, y1, x1 + ((onlyOne || firstTab) && selected &&
973 leftAligned ? 0 : borderThinkness), y1);
974 painter->drawPoint(x2 - 1, y1 + 1);
975 painter->setPen(midlight);
976 painter->drawLine(x2 - 3, y1 + 1, x1 + ((onlyOne || firstTab) &&
977 selected && leftAligned ? 0 : borderThinkness), y1 + 1);
978 painter->drawPoint(x2 - 1, y1);
979
980 }
981 // Right
982 {
983 int beg = y1 + (previousSelected ? 0 : 2);
984 int end = y2 - (nextSelected ? 0 : 2);
985 painter->setPen(shadow);
986 painter->drawLine(x2, beg, x2, end);
987 painter->setPen(dark);
988 painter->drawLine(x2 - 1, beg, x2 - 1, end);
989 }
990 // Bottom
991 if (lastTab || selected || onlyOne || !nextSelected) {
992 painter->setPen(shadow);
993 painter->drawLine(x2 - 2, y2, x1 + ((onlyOne || lastTab) &&
994 selected && rightAligned ? 0 : borderThinkness), y2);
995 painter->drawPoint(x2 - 1, y2 - 1);
996 painter->setPen(dark);
997 painter->drawLine(x2 - 2, y2 - 1, x1 + ((onlyOne || lastTab) &&
998 selected && rightAligned ? 0 : borderThinkness), y2 - 1);
999 }
1000 break; }
1001 }
1002 }
1003 break;
1004#endif // QT_NO_TABBAR
1005
1006 case CE_ToolBar: {
1007 QRect rect = option->rect;
1008 painter->setPen(QPen(option->palette.dark().color()));
1009 painter->drawLine(rect.topRight().x()-1,
1010 rect.topRight().y(),
1011 rect.bottomRight().x()-1,
1012 rect.bottomRight().y());
1013 painter->drawLine(rect.bottomLeft().x(),
1014 rect.bottomLeft().y(),
1015 rect.bottomRight().x(),
1016 rect.bottomRight().y());
1017 painter->setPen(QPen(option->palette.light().color()));
1018 painter->drawLine(rect.topRight().x(),
1019 rect.topRight().y(),
1020 rect.bottomRight().x(),
1021 rect.bottomRight().y());
1022 painter->drawLine(rect.topLeft().x(),
1023 rect.topLeft().y(),
1024 rect.topRight().x(),
1025 rect.topRight().y());
1026
1027 break; }
1028#ifndef QT_NO_SCROLLBAR
1029 case CE_ScrollBarSubLine:
1030 case CE_ScrollBarAddLine: {
1031 if (option->state & State_Sunken) {
1032 QStyleOption buttonOpt = *option;
1033
1034 drawPrimitive(PE_PanelButtonBevel, &buttonOpt, painter, widget);
1035 } else {
1036 QStyleOption buttonOpt = *option;
1037 if (!(buttonOpt.state & State_Sunken))
1038 buttonOpt.state |= State_Raised;
1039 drawPrimitive(PE_PanelButtonBevel, &buttonOpt, painter, widget);
1040 }
1041 PrimitiveElement arrow;
1042 if (option->state & State_Horizontal) {
1043 if (element == CE_ScrollBarAddLine)
1044 arrow = option->direction == Qt::LeftToRight ? PE_IndicatorArrowRight : PE_IndicatorArrowLeft;
1045 else
1046 arrow = option->direction == Qt::LeftToRight ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
1047 } else {
1048 if (element == CE_ScrollBarAddLine)
1049 arrow = PE_IndicatorArrowDown;
1050 else
1051 arrow = PE_IndicatorArrowUp;
1052 }
1053 drawPrimitive(arrow, option, painter, widget);
1054 break; }
1055 case CE_ScrollBarAddPage:
1056 case CE_ScrollBarSubPage: {
1057 QBrush br;
1058 QBrush bg = painter->background();
1059 Qt::BGMode bg_mode = painter->backgroundMode();
1060 painter->setPen(Qt::NoPen);
1061 painter->setBackgroundMode(Qt::OpaqueMode);
1062
1063 if (option->state & State_Sunken) {
1064 br = QBrush(option->palette.shadow().color(), Qt::Dense4Pattern);
1065 painter->setBackground(option->palette.dark().color());
1066 painter->setBrush(br);
1067 } else {
1068 QPixmap pm = option->palette.brush(QPalette::Light).texture();
1069 if (option->state & State_Enabled)
1070 br = !pm.isNull() ? QBrush(pm) : QBrush(option->palette.button().color(), Qt::Dense4Pattern);
1071 else
1072 br = !pm.isNull() ? QBrush(pm) : QBrush(option->palette.light().color(), Qt::Dense4Pattern);
1073 painter->setBackground(option->palette.base().color());
1074 painter->setBrush(br);
1075 }
1076 painter->drawRect(option->rect);
1077 painter->setBackground(bg);
1078 painter->setBackgroundMode(bg_mode);
1079 break; }
1080 case CE_ScrollBarSlider:
1081 if (!(option->state & State_Enabled)) {
1082 QStyleOptionButton buttonOpt;
1083 buttonOpt.QStyleOption::operator=(*option);
1084 buttonOpt.state = State_Enabled | State_Raised;
1085 drawPrimitive(PE_PanelButtonBevel, &buttonOpt, painter, widget);
1086 QPixmap pm = option->palette.brush(QPalette::Light).texture();
1087 QBrush br = !pm.isNull() ? QBrush(pm) : QBrush(option->palette.light().color(), Qt::Dense4Pattern);
1088 painter->setPen(Qt::NoPen);
1089 painter->setBrush(br);
1090 painter->setBackgroundMode(Qt::OpaqueMode);
1091 painter->drawRect(option->rect.adjusted(2, 2, -2, -2));
1092 } else {
1093 QStyleOptionButton buttonOpt;
1094 buttonOpt.QStyleOption::operator=(*option);
1095 buttonOpt.state = State_Enabled | State_Raised;
1096 drawPrimitive(PE_PanelButtonBevel, &buttonOpt, painter, widget);
1097 }
1098 break;
1099#endif // QT_NO_SCROLLBAR
1100 case CE_HeaderSection: {
1101 QBrush fill;
1102 if (option->state & State_On)
1103 fill = QBrush(option->palette.light().color(), Qt::Dense4Pattern);
1104 else
1105 fill = option->palette.brush(QPalette::Button);
1106
1107 if (option->state & (State_Raised | State_Sunken)) {
1108 QWindowsCEStylePrivate::drawWinCEButton(painter, option->rect, option->palette,
1109 option->state & State_Sunken, &fill);
1110 } else {
1111 painter->fillRect(option->rect, fill);
1112 }
1113 break; }
1114
1115 case CE_DockWidgetTitle:
1116 QWindowsStyle::drawControl(element,option, painter, widget);
1117 break;
1118
1119 case CE_PushButtonLabel:
1120 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
1121 painter->save();
1122 QFont f = painter->font();
1123 f.setBold(true);
1124 painter->setFont(f);
1125 QRect ir = btn->rect;
1126 uint tf = Qt::AlignVCenter | Qt::TextShowMnemonic;
1127 if (!styleHint(SH_UnderlineShortcut, btn, widget))
1128 tf |= Qt::TextHideMnemonic;
1129
1130 if (btn->state & (State_On | State_Sunken))
1131 ir.translate(pixelMetric(PM_ButtonShiftHorizontal, option, widget),
1132 pixelMetric(PM_ButtonShiftVertical, option, widget));
1133 if (!btn->icon.isNull()) {
1134 QIcon::Mode mode = btn->state & State_Enabled ? QIcon::Normal
1135 : QIcon::Disabled;
1136 if (mode == QIcon::Normal && btn->state & State_HasFocus)
1137 mode = QIcon::Active;
1138 QIcon::State state = QIcon::Off;
1139 if (btn->state & State_On)
1140 state = QIcon::On;
1141 QPixmap pixmap = btn->icon.pixmap(btn->iconSize, mode, state);
1142 int pixw = pixmap.width();
1143 int pixh = pixmap.height();
1144 //Center the icon if there is no text
1145
1146 QPoint point;
1147 if (btn->text.isEmpty()) {
1148 point = QPoint(ir.x() + ir.width() / 2 - pixw / 2,
1149 ir.y() + ir.height() / 2 - pixh / 2);
1150 } else {
1151 point = QPoint(ir.x() + 2, ir.y() + ir.height() / 2 - pixh / 2);
1152 }
1153 if (btn->direction == Qt::RightToLeft)
1154 point.rx() += pixw;
1155
1156 if ((btn->state & (State_On | State_Sunken)) && btn->direction == Qt::RightToLeft)
1157 point.rx() -= pixelMetric(PM_ButtonShiftHorizontal, option, widget) * 2;
1158
1159 painter->drawPixmap(visualPos(btn->direction, btn->rect, point), pixmap);
1160
1161 if (btn->direction == Qt::RightToLeft)
1162 ir.translate(-4, 0);
1163 else
1164 ir.translate(pixw + 4, 0);
1165 ir.setWidth(ir.width() - (pixw + 4));
1166 // left-align text if there is
1167 if (!btn->text.isEmpty())
1168 tf |= Qt::AlignLeft;
1169 } else {
1170 tf |= Qt::AlignHCenter;
1171 }
1172 drawItemText(painter, ir, tf, btn->palette, (btn->state & State_Enabled),
1173 btn->text, QPalette::ButtonText);
1174 painter->restore();
1175 }
1176 break;
1177 default:
1178 QWindowsStyle::drawControl(element, option, painter, widget);
1179 break;
1180 }
1181}
1182
1183void QWindowsCEStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
1184 QPainter *painter, const QWidget *widget) const {
1185 switch (control) {
1186 #ifndef QT_NO_SLIDER
1187 case CC_Slider:
1188 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
1189 int thickness = pixelMetric(PM_SliderControlThickness, slider, widget);
1190 int len = pixelMetric(PM_SliderLength, slider, widget);
1191 int ticks = slider->tickPosition;
1192 QRect groove = subControlRect(CC_Slider, slider, SC_SliderGroove, widget);
1193 QRect handle = subControlRect(CC_Slider, slider, SC_SliderHandle, widget);
1194
1195 if ((slider->subControls & SC_SliderGroove) && groove.isValid()) {
1196 int mid = thickness / 2;
1197 if (ticks & QSlider::TicksAbove)
1198 mid += len / 8;
1199 if (ticks & QSlider::TicksBelow)
1200 mid -= len / 8;
1201
1202 painter->setPen(slider->palette.shadow().color());
1203 if (slider->orientation == Qt::Horizontal) {
1204 QWindowsCEStylePrivate::drawWinCEPanel(painter, groove.x(), groove.y() + mid - 2,
1205 groove.width(), 4, option->palette, true);
1206 painter->drawLine(groove.x() + 1, groove.y() + mid - 1,
1207 groove.x() + groove.width() - 3, groove.y() + mid - 1);
1208 } else {
1209 QWindowsCEStylePrivate::drawWinCEPanel(painter, groove.x() + mid - 2, groove.y(),
1210 4, groove.height(), option->palette, true);
1211 painter->drawLine(groove.x() + mid - 1, groove.y() + 1,
1212 groove.x() + mid - 1, groove.y() + groove.height() - 3);
1213 }
1214 }
1215 if (slider->subControls & SC_SliderTickmarks) {
1216 QStyleOptionSlider tmpSlider = *slider;
1217 tmpSlider.subControls = SC_SliderTickmarks;
1218 QCommonStyle::drawComplexControl(control, &tmpSlider, painter, widget);
1219 }
1220
1221 if (slider->subControls & SC_SliderHandle) {
1222 // 4444440
1223 // 4333310
1224 // 4322210
1225 // 4322210
1226 // 4322210
1227 // 4322210
1228 // *43210*
1229 // **440**
1230 // ***0***
1231 const QColor c0 = slider->palette.shadow().color();
1232 const QColor c1 = slider->palette.dark().color();
1233 // const QColor c2 = g.button();
1234 const QColor c3 = slider->palette.midlight().color();
1235 const QColor c4 = slider->palette.dark().color();
1236 QBrush handleBrush;
1237
1238 if (slider->state & State_Enabled) {
1239 handleBrush = slider->palette.color(QPalette::Button);
1240 } else {
1241 handleBrush = QBrush(slider->palette.color(QPalette::Button),
1242 Qt::Dense4Pattern);
1243 }
1244
1245 int x = handle.x(), y = handle.y(),
1246 wi = handle.width(), he = handle.height();
1247
1248 int x1 = x;
1249 int x2 = x + wi - 1;
1250 int y1 = y;
1251 int y2 = y + he - 1;
1252
1253 Qt::Orientation orient = slider->orientation;
1254 bool tickAbove = slider->tickPosition == QSlider::TicksAbove;
1255 bool tickBelow = slider->tickPosition == QSlider::TicksBelow;
1256
1257 if (slider->state & State_HasFocus) {
1258 QStyleOptionFocusRect fropt;
1259 fropt.QStyleOption::operator=(*slider);
1260 fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
1261 drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
1262 }
1263 if ((tickAbove && tickBelow) || (!tickAbove && !tickBelow)) {
1264 Qt::BGMode oldMode = painter->backgroundMode();
1265 painter->setBackgroundMode(Qt::OpaqueMode);
1266 QWindowsCEStylePrivate::drawWinCEButton(painter, QRect(x, y, wi, he), slider->palette, false,
1267 &handleBrush);
1268 painter->setBackgroundMode(oldMode);
1269 QBrush fill = QBrush(option->palette.light().color(), Qt::Dense4Pattern);
1270 if (slider->state & State_Sunken)
1271 painter->fillRect(QRectF(x1 + 2, y1 + 2, x2 - x1 - 3, y2 - y1 - 3),fill);
1272 return;
1273 }
1274 QSliderDirection dir;
1275 if (orient == Qt::Horizontal)
1276 if (tickAbove)
1277 dir = SlUp;
1278 else
1279 dir = SlDown;
1280 else
1281 if (tickAbove)
1282 dir = SlLeft;
1283 else
1284 dir = SlRight;
1285 QPolygon a;
1286 int d = 0;
1287 switch (dir) {
1288 case SlUp:
1289 x2++;
1290 y1 = y1 + wi / 2;
1291 d = (wi + 1) / 2 - 1;
1292 a.setPoints(5, x1, y1, x1, y2, x2, y2, x2, y1, x1 + d, y1 - d);
1293 break;
1294 case SlDown:
1295 x2++;
1296 y2 = y2 - wi / 2;
1297 d = (wi + 1) / 2 - 1;
1298 a.setPoints(5, x1, y1, x1, y2, x1 + d, y2+d, x2, y2, x2, y1);
1299 break;
1300 case SlLeft:
1301 d = (he + 1) / 2 - 1;
1302 x1 = x1 + he / 2;
1303 a.setPoints(5, x1, y1, x1 - d, y1 + d, x1, y2, x2, y2, x2, y1);
1304 y1--;
1305 break;
1306 case SlRight:
1307 d = (he + 1) / 2 - 1;
1308 x2 = x2 - he / 2;
1309 a.setPoints(5, x1, y1, x1, y2, x2, y2, x2 + d, y1 + d, x2, y1);
1310 y1--;
1311 break;
1312 }
1313 QBrush oldBrush = painter->brush();
1314 painter->setPen(Qt::NoPen);
1315 painter->setBrush(handleBrush);
1316 Qt::BGMode oldMode = painter->backgroundMode();
1317 painter->setBackgroundMode(Qt::OpaqueMode);
1318 painter->drawRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
1319 painter->drawPolygon(a);
1320 QBrush fill = QBrush(option->palette.light().color(), Qt::Dense4Pattern);
1321 if (slider->state & State_Sunken)
1322 painter->fillRect(QRectF(x1, y1, x2 - x1 + 1, y2 - y1 + 1),fill);
1323 painter->setBrush(oldBrush);
1324 painter->setBackgroundMode(oldMode);
1325
1326 if (dir != SlUp) {
1327 painter->setPen(c4);
1328 painter->drawLine(x1, y1, x2, y1);
1329 painter->setPen(c3);
1330 painter->drawLine(x1, y1 + 1, x2, y1 + 1);
1331 }
1332 if (dir != SlLeft) {
1333 painter->setPen(c3);
1334 painter->drawLine(x1 + 1, y1 + 1, x1 + 1, y2);
1335 painter->setPen(c4);
1336 painter->drawLine(x1, y1, x1, y2);
1337 }
1338 if (dir != SlRight) {
1339 painter->setPen(c0);
1340 painter->drawLine(x2, y1, x2, y2);
1341 painter->setPen(c1);
1342 painter->drawLine(x2 - 1, y1 + 1, x2 - 1, y2 - 1);
1343 }
1344 if (dir != SlDown) {
1345 painter->setPen(c0);
1346 painter->drawLine(x1, y2, x2, y2);
1347 painter->setPen(c1);
1348 painter->drawLine(x1+1, y2 - 1, x2 - 1, y2 - 1);
1349 }
1350
1351 switch (dir) {
1352 case SlUp:
1353 if (slider->state & State_Sunken)
1354 painter->fillRect(QRectF(x1 + 3, y1 - d + 2, x2 - x1 - 4,y1), fill);
1355 painter->setPen(c4);
1356 painter->drawLine(x1, y1, x1 + d, y1 - d);
1357 painter->setPen(c0);
1358 d = wi - d - 1;
1359 painter->drawLine(x2, y1, x2 - d, y1 - d);
1360 d--;
1361 painter->setPen(c3);
1362 painter->drawLine(x1 + 1, y1, x1 + 1 + d-1, y1 - d + 1);
1363 painter->setPen(c1);
1364 painter->drawLine(x2 - 1, y1, x2-1 - d, y1 - d);
1365 break;
1366 case SlDown:
1367 if (slider->state & State_Sunken)
1368 painter->fillRect(QRectF(x1 + 3, y2 - d, x2 - x1 - 4,y2 - 8), fill);
1369 painter->setPen(c4);
1370 painter->drawLine(x1, y2, x1 + d, y2 + d);
1371 painter->setPen(c0);
1372 d = wi - d - 1;
1373 painter->drawLine(x2, y2, x2 - d, y2 + d);
1374 d--;
1375 painter->setPen(c3);
1376 painter->drawLine(x1 + 1, y2, x1 + 1 + d - 1, y2 + d - 1);
1377 painter->setPen(c1);
1378 painter->drawLine(x2 - 1, y2, x2 - 1 - d, y2 + d);
1379 break;
1380 case SlLeft:
1381 if (slider->state & State_Sunken)
1382 painter->fillRect(QRectF(x1 - d + 2, y1 + 2, x1,y2 - y1 - 3), fill);
1383 painter->setPen(c4);
1384 painter->drawLine(x1, y1, x1 - d, y1 + d);
1385 painter->setPen(c0);
1386 d = he - d - 1;
1387 painter->drawLine(x1, y2, x1 - d, y2 - d);
1388 d--;
1389 painter->setPen(c3);
1390 painter->drawLine(x1, y1 + 1, x1 - d + 1, y1 + 1 + d - 1);
1391 painter->setPen(c1);
1392 painter->drawLine(x1, y2 - 1, x1 - d, y2 - 1 - d);
1393 break;
1394 case SlRight:
1395 if (slider->state & State_Sunken)
1396 painter->fillRect(QRectF(x2 - d - 4, y1 + 2, x2 - 4, y2 - y1 - 3), fill);
1397 painter->setPen(c4);
1398 painter->drawLine(x2, y1, x2 + d, y1 + d);
1399 painter->setPen(c0);
1400 d = he - d - 1;
1401 painter->drawLine(x2, y2, x2 + d, y2 - d);
1402 d--;
1403 painter->setPen(c3);
1404 painter->drawLine(x2, y1 + 1, x2 + d - 1, y1 + 1 + d - 1);
1405 painter->setPen(c1);
1406 painter->drawLine(x2, y2 - 1, x2 + d, y2 - 1 - d);
1407 break;
1408 }
1409 }
1410 }
1411 break;
1412#endif // QT_NO_SLIDER
1413 case CC_ToolButton:
1414 if (const QStyleOptionToolButton *toolbutton
1415 = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
1416 QRect button, menuarea;
1417
1418#ifndef QT_NO_TOOLBAR
1419 bool flat = !(widget ? qobject_cast<QToolBar*>(widget->parentWidget()) : 0);
1420#else
1421 bool flat = true;
1422#endif
1423
1424 button = subControlRect(control, toolbutton, SC_ToolButton, widget);
1425 menuarea = subControlRect(control, toolbutton, SC_ToolButtonMenu, widget);
1426
1427 if (flat && (toolbutton->subControls & SC_ToolButtonMenu)) {
1428 menuarea.setLeft(menuarea.left() - 4);
1429 button.setRight(button.right() - 4);
1430 }
1431
1432 State bflags = toolbutton->state;
1433
1434 if (bflags & State_AutoRaise)
1435 if (!(bflags & State_MouseOver)) {
1436 bflags &= ~State_Raised;
1437 }
1438 State mflags = bflags;
1439
1440 if (toolbutton->activeSubControls & SC_ToolButton)
1441 bflags |= State_Sunken;
1442 if (toolbutton->activeSubControls & SC_ToolButtonMenu)
1443 mflags |= State_Sunken;
1444
1445 QStyleOption tool(0);
1446 tool.palette = toolbutton->palette;
1447 if (toolbutton->subControls & SC_ToolButton) {
1448 tool.rect = button;
1449 tool.state = bflags;
1450 drawPrimitive(PE_PanelButtonTool, &tool, painter, widget);
1451 }
1452
1453 if (toolbutton->subControls & SC_ToolButtonMenu) {
1454 tool.rect = menuarea;
1455 tool.state = mflags;
1456 tool.state = bflags;
1457 drawPrimitive(PE_IndicatorButtonDropDown, &tool, painter, widget);
1458
1459 if (!flat) {
1460
1461 //connect buttons
1462 painter->save();
1463 painter->setPen(tool.palette.button().color());
1464 painter->drawLine(tool.rect.x() - 2, tool.rect.y(), tool.rect.x() - 2, tool.rect.y() + tool.rect.height());
1465 painter->drawLine(tool.rect.x() - 1, tool.rect.y(), tool.rect.x() - 1, tool.rect.y() + tool.rect.height());
1466 painter->drawLine(tool.rect.x(), tool.rect.y(), tool.rect.x(), tool.rect.y() + tool.rect.height());
1467 painter->drawLine(tool.rect.x() + 1, tool.rect.y(), tool.rect.x() + 1, tool.rect.y() + tool.rect.height());
1468
1469 if (tool.state & State_Sunken)
1470 {
1471 painter->setPen(tool.palette.midlight().color());
1472 painter->drawLine(tool.rect.x() - 2, tool.rect.y() + tool.rect.height() - 2,
1473 tool.rect.x() + 1, tool.rect.y() + tool.rect.height() -2 );
1474 painter->setPen(tool.palette.shadow().color());
1475 painter->drawLine(tool.rect.x() - 2, tool.rect.y() + 1,tool.rect.x() + 1, tool.rect.y() + 1);
1476 painter->drawLine(tool.rect.x() - 2, tool.rect.y(), tool.rect.x() + 1, tool.rect.y());
1477 painter->setPen(tool.palette.light().color());
1478 painter->drawLine(tool.rect.x() - 2, tool.rect.y() + tool.rect.height() - 1,
1479 tool.rect.x() + 1, tool.rect.y() + tool.rect.height() - 1);
1480 }
1481 else
1482 {
1483 painter->setPen(tool.palette.dark().color());
1484 painter->drawLine(tool.rect.x() - 2, tool.rect.y(),tool.rect.x() + 1, tool.rect.y());
1485 painter->drawLine(tool.rect.x() - 2, tool.rect.y()+tool.rect.height() - 2,tool.rect.x() + 1,
1486 tool.rect.y() + tool.rect.height() - 2);
1487 painter->setPen(tool.palette.midlight().color());
1488 painter->drawLine(tool.rect.x() - 2, tool.rect.y() + 1,tool.rect.x() + 1, tool.rect.y() + 1);
1489 painter->setPen(tool.palette.shadow().color());
1490 painter->drawLine(tool.rect.x() - 2, tool.rect.y() + tool.rect.height() - 1,
1491 tool.rect.x() + 1, tool.rect.y() + tool.rect.height() - 1);
1492 }
1493 painter->restore();
1494 }
1495
1496
1497 if (!flat) {
1498 tool.rect.adjust(-3,0,-3,0);
1499 painter->save();
1500 painter->setPen(tool.palette.button().color());
1501 if (tool.state & State_Sunken)
1502 painter->drawLine(tool.rect.x() + 2, tool.rect.y() + 10,
1503 tool.rect.x() + tool.rect.width(), tool.rect.y() + 10);
1504 else
1505 painter->drawLine(tool.rect.x() + 1, tool.rect.y() + 9, tool.rect.x() +
1506 tool.rect.width() - 1, tool.rect.y() + 9);
1507 painter->restore();
1508 } else {
1509 tool.rect.adjust(-1,0,-1,0);
1510 }
1511
1512 drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget);
1513 }
1514
1515 if (toolbutton->state & State_HasFocus) {
1516 QStyleOptionFocusRect fr;
1517 fr.QStyleOption::operator=(*toolbutton);
1518 fr.rect.adjust(3, 3, -3, -3);
1519 if (toolbutton->features & QStyleOptionToolButton::Menu)
1520 fr.rect.adjust(0, 0, -pixelMetric(QStyle::PM_MenuButtonIndicator,
1521 toolbutton, widget), 0);
1522 drawPrimitive(PE_FrameFocusRect, &fr, painter, widget);
1523 }
1524 QStyleOptionToolButton label = *toolbutton;
1525 int fw = pixelMetric(PM_DefaultFrameWidth, option, widget);
1526 label.rect = button.adjusted(fw, fw, -fw, -fw);
1527 drawControl(CE_ToolButtonLabel, &label, painter, widget);
1528 }
1529 break;
1530
1531#ifndef QT_NO_GROUPBOX
1532 case CC_GroupBox:
1533 if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
1534 // Draw frame
1535 painter->save();
1536 QFont f = painter->font();
1537 f.setBold(true);
1538 painter->setFont(f);
1539 QStyleOptionGroupBox groupBoxFont = *groupBox;
1540 groupBoxFont.fontMetrics = QFontMetrics(f);
1541 QRect textRect = subControlRect(CC_GroupBox, &groupBoxFont, SC_GroupBoxLabel, widget);
1542 QRect checkBoxRect = subControlRect(CC_GroupBox, option, SC_GroupBoxCheckBox, widget);
1543 if (groupBox->subControls & QStyle::SC_GroupBoxFrame) {
1544 QStyleOptionFrameV2 frame;
1545 frame.QStyleOption::operator=(*groupBox);
1546 frame.features = groupBox->features;
1547 frame.lineWidth = groupBox->lineWidth;
1548 frame.midLineWidth = groupBox->midLineWidth;
1549 frame.rect = subControlRect(CC_GroupBox, option, SC_GroupBoxFrame, widget);
1550 painter->save();
1551
1552 QRegion region(groupBox->rect);
1553 if (!groupBox->text.isEmpty()) {
1554 bool ltr = groupBox->direction == Qt::LeftToRight;
1555 QRect finalRect = checkBoxRect.united(textRect);
1556 if (groupBox->subControls & QStyle::SC_GroupBoxCheckBox)
1557 finalRect.adjust(ltr ? -4 : 0, 0, ltr ? 0 : 4, 0);
1558 region -= finalRect;
1559 }
1560 painter->setClipRegion(region);
1561 drawPrimitive(PE_FrameGroupBox, &frame, painter, widget);
1562 painter->restore();
1563 }
1564
1565 // Draw title
1566 if ((groupBox->subControls & QStyle::SC_GroupBoxLabel) && !groupBox->text.isEmpty()) {
1567 QColor textColor = groupBox->textColor;
1568 if (textColor.isValid())
1569 painter->setPen(textColor);
1570 int alignment = int(groupBox->textAlignment);
1571 if (!styleHint(QStyle::SH_UnderlineShortcut, option, widget))
1572 alignment |= Qt::TextHideMnemonic;
1573
1574 drawItemText(painter, textRect, Qt::TextShowMnemonic | Qt::AlignHCenter | alignment,
1575 groupBox->palette, groupBox->state & State_Enabled, groupBox->text,
1576 textColor.isValid() ? QPalette::NoRole : QPalette::WindowText);
1577
1578 if (groupBox->state & State_HasFocus) {
1579 QStyleOptionFocusRect fropt;
1580 fropt.QStyleOption::operator=(*groupBox);
1581 fropt.rect = textRect;
1582 drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
1583 }
1584 }
1585 // Draw checkbox
1586 if (groupBox->subControls & SC_GroupBoxCheckBox) {
1587 QStyleOptionButton box;
1588 box.QStyleOption::operator=(*groupBox);
1589 box.rect = checkBoxRect;
1590 drawPrimitive(PE_IndicatorCheckBox, &box, painter, widget);
1591 }
1592 painter->restore();
1593 }
1594 break;
1595#endif //QT_NO_GROUPBOX
1596#ifndef QT_NO_COMBOBOX
1597 case CC_ComboBox:
1598 if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
1599 QBrush editBrush = cmb->palette.brush(QPalette::Base);
1600 if ((cmb->subControls & SC_ComboBoxFrame) && cmb->frame)
1601 QWindowsCEStylePrivate::drawWinCEPanel(painter, option->rect, option->palette, true, &editBrush);
1602 else
1603 painter->fillRect(option->rect, editBrush);
1604
1605 if (cmb->subControls & SC_ComboBoxArrow) {
1606 State flags = State_None;
1607
1608 QRect ar = subControlRect(CC_ComboBox, cmb, SC_ComboBoxArrow, widget);
1609 if (cmb->activeSubControls == SC_ComboBoxArrow) {
1610 painter->setPen(cmb->palette.dark().color());
1611 painter->setBrush(cmb->palette.brush(QPalette::Button));
1612 painter->drawRect(ar.adjusted(0, 0, -1, -1));
1613 QWindowsCEStylePrivate::drawWinCEButton(painter, ar.adjusted(0, 0, -1, -1), option->palette, true,
1614 &cmb->palette.brush(QPalette::Button));
1615 } else {
1616 // Make qDrawWinButton use the right colors for drawing the shade of the button
1617
1618 QWindowsCEStylePrivate::drawWinCEButton(painter, ar, option->palette, false,
1619 &cmb->palette.brush(QPalette::Button));
1620 }
1621
1622 ar.adjust(2, 2, -2, -2);
1623 if (option->state & State_Enabled)
1624 flags |= State_Enabled;
1625
1626 if (cmb->activeSubControls == SC_ComboBoxArrow)
1627 flags |= State_Sunken;
1628 QStyleOption arrowOpt(0);
1629 arrowOpt.rect = ar;
1630 arrowOpt.palette = cmb->palette;
1631 arrowOpt.state = flags;
1632 drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget);
1633 }
1634 if (cmb->subControls & SC_ComboBoxEditField) {
1635 QRect re = subControlRect(CC_ComboBox, cmb, SC_ComboBoxEditField, widget);
1636 if (cmb->state & State_HasFocus && !cmb->editable)
1637 painter->fillRect(re.x(), re.y(), re.width(), re.height(),
1638 cmb->palette.brush(QPalette::Highlight));
1639 if (cmb->state & State_HasFocus) {
1640 painter->setPen(cmb->palette.highlightedText().color());
1641 painter->setBackground(cmb->palette.highlight());
1642 } else {
1643 painter->setPen(cmb->palette.text().color());
1644 painter->setBackground(cmb->palette.background());
1645 }
1646 if (cmb->state & State_HasFocus && !cmb->editable) {
1647 QStyleOptionFocusRect focus;
1648 focus.QStyleOption::operator=(*cmb);
1649 focus.rect = subElementRect(SE_ComboBoxFocusRect, cmb, widget);
1650 focus.state |= State_FocusAtBorder;
1651 focus.backgroundColor = cmb->palette.highlight().color();
1652 drawPrimitive(PE_FrameFocusRect, &focus, painter, widget);
1653 }
1654 }
1655 }
1656 break;
1657#endif // QT_NO_COMBOBOX
1658#ifndef QT_NO_SPINBOX
1659 case CC_SpinBox:
1660 if (const QStyleOptionSpinBox *sb = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
1661 QStyleOptionSpinBox copy = *sb;
1662 PrimitiveElement pe;
1663
1664 if (sb->frame && (sb->subControls & SC_SpinBoxFrame)) {
1665 QRect r = subControlRect(CC_SpinBox, sb, SC_SpinBoxFrame, widget);
1666 QWindowsCEStylePrivate::drawWinCEPanel(painter, r, option->palette, true);
1667 }
1668 QPalette shadePal(option->palette);
1669 shadePal.setColor(QPalette::Button, option->palette.light().color());
1670 shadePal.setColor(QPalette::Light, option->palette.button().color());
1671
1672 bool reverse = QApplication::layoutDirection() == Qt::RightToLeft;
1673
1674 if (sb->subControls & SC_SpinBoxUp) {
1675 copy.subControls = SC_SpinBoxUp;
1676 QPalette pal2 = sb->palette;
1677 if (!(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled)) {
1678 pal2.setCurrentColorGroup(QPalette::Disabled);
1679 copy.state &= ~State_Enabled;
1680 }
1681 copy.palette = pal2;
1682 if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken)) {
1683 copy.state |= State_On;
1684 copy.state |= State_Sunken;
1685 } else {
1686 copy.state |= State_Raised;
1687 copy.state &= ~State_Sunken;
1688 }
1689 if (reverse)
1690 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinMinus
1691 : PE_IndicatorSpinDown);
1692 else
1693 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinPlus
1694 : PE_IndicatorSpinUp);
1695 copy.rect = subControlRect(CC_SpinBox, sb, SC_SpinBoxUp, widget);
1696 QWindowsCEStylePrivate::drawWinCEButton(painter, copy.rect, option->palette, copy.state & (State_Sunken | State_On),
1697 &copy.palette.brush(QPalette::Button));
1698 copy.rect.adjust(3, 0, -4, 0);
1699 drawPrimitive(pe, &copy, painter, widget);
1700 }
1701 if (sb->subControls & SC_SpinBoxDown) {
1702 copy.subControls = SC_SpinBoxDown;
1703 copy.state = sb->state;
1704 QPalette pal2 = sb->palette;
1705 if (!(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled)) {
1706 pal2.setCurrentColorGroup(QPalette::Disabled);
1707 copy.state &= ~State_Enabled;
1708 }
1709 copy.palette = pal2;
1710
1711 if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken)) {
1712 copy.state |= State_On;
1713 copy.state |= State_Sunken;
1714 } else {
1715 copy.state |= State_Raised;
1716 copy.state &= ~State_Sunken;
1717 }
1718 if (reverse)
1719 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinPlus
1720 : PE_IndicatorSpinUp);
1721 else
1722 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinMinus
1723 : PE_IndicatorSpinDown);
1724 copy.rect = subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget);
1725 QWindowsCEStylePrivate::drawWinCEButton(painter, copy.rect, shadePal, copy.state & (State_Sunken | State_On),
1726 &copy.palette.brush(QPalette::Button));
1727
1728 copy.rect.adjust(3, 0, -4, 0);
1729 if (pe == PE_IndicatorArrowUp || pe == PE_IndicatorArrowDown) {
1730 copy.rect = copy.rect.adjusted(1, 1, -1, -1);
1731 drawPrimitive(pe, &copy, painter, widget);
1732 }
1733 else {
1734 drawPrimitive(pe, &copy, painter, widget);
1735 }
1736 if (sb->frame && (sb->subControls & SC_SpinBoxFrame)) {
1737 QRect r = subControlRect(CC_SpinBox, sb, SC_SpinBoxEditField, widget);
1738 painter->save();
1739 painter->setPen(option->palette.light().color());
1740 painter->drawLine(r.x() + 1 + r.width(), r.y() - 2, r.x() + 1 + r.width(), r.y() + r.height() + 1);
1741 painter->setPen(option->palette.midlight().color());
1742 painter->drawLine(r.x() + r.width(), r.y() - 1, r.x() + r.width(), r.y() + r.height());
1743 painter->restore();
1744 }
1745 }
1746 }
1747 break;
1748#endif // QT_NO_SPINBOX
1749
1750 default:
1751 QWindowsStyle::drawComplexControl(control, option, painter, widget);
1752 break;
1753 }
1754}
1755
1756void QWindowsCEStyle::drawItemText(QPainter *painter, const QRect &rect, int alignment, const QPalette &pal,
1757 bool enabled, const QString& text, QPalette::ColorRole textRole) const {
1758 if (text.isEmpty())
1759 return;
1760 QPen savedPen;
1761 if (textRole != QPalette::NoRole) {
1762 savedPen = painter->pen();
1763 painter->setPen(pal.color(textRole));
1764 }
1765 if (!enabled) {
1766 QPen pen = painter->pen();
1767 painter->setPen(pal.light().color());
1768 //painter->drawText(rect.adjusted(1, 1, 1, 1), alignment, text);
1769 painter->setPen(pen);
1770 }
1771 painter->drawText(rect, alignment, text);
1772 if (textRole != QPalette::NoRole)
1773 painter->setPen(savedPen);
1774}
1775
1776
1777QSize QWindowsCEStyle::sizeFromContents(ContentsType type, const QStyleOption *option,
1778 const QSize &size, const QWidget *widget) const {
1779 QSize newSize = QWindowsStyle::sizeFromContents(type, option, size, widget);
1780 switch (type) {
1781 case CT_PushButton:
1782 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
1783 newSize = QWindowsStyle::sizeFromContents(type, option, size, widget);
1784 int w = newSize.width(),
1785 h = newSize.height();
1786 int defwidth = 0;
1787 if (btn->features & QStyleOptionButton::AutoDefaultButton)
1788 defwidth = 2 * pixelMetric(PM_ButtonDefaultIndicator, btn, widget);
1789 if (w < 75 + defwidth && btn->icon.isNull())
1790 w = 75 + defwidth;
1791 if (h < 23 + defwidth)
1792 h = 23 + defwidth;
1793 newSize = QSize(w+14, h);
1794 }
1795 break;
1796
1797 case CT_RadioButton:
1798 case CT_CheckBox:
1799 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
1800 bool isRadio = (type == CT_RadioButton);
1801 QRect irect = visualRect(btn->direction, btn->rect,
1802 subElementRect(isRadio ? SE_RadioButtonIndicator
1803 : SE_CheckBoxIndicator, btn, widget));
1804 int h = pixelMetric(isRadio ? PM_ExclusiveIndicatorHeight
1805 : PM_IndicatorHeight, btn, widget);
1806 int margins = (!btn->icon.isNull() && btn->text.isEmpty()) ? 0 : 10;
1807 newSize += QSize(irect.right() + margins, 4);
1808 newSize.setHeight(qMax(newSize.height(), h));
1809 }
1810 break;
1811 case CT_ComboBox:
1812 if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
1813 int fw = cmb->frame ? pixelMetric(PM_ComboBoxFrameWidth, option, widget) * 2 : 0;
1814 newSize = QSize(newSize.width() + fw -1, qMax(24, newSize.height() + fw-1));
1815 }
1816 break;
1817#ifndef QT_NO_SPINBOX
1818 case CT_SpinBox:
1819 if (const QStyleOptionSpinBox *spnb = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
1820 int fw = spnb->frame ? pixelMetric(PM_SpinBoxFrameWidth, option, widget) * 2 : 0;
1821 newSize = QSize(newSize.width() + fw - 5, newSize.height() + fw - 6);
1822 }
1823 break;
1824#endif
1825 case CT_LineEdit:
1826 newSize += QSize(0,1);
1827 break;
1828 case CT_MenuBarItem:
1829 newSize += QSize(5, 1);
1830 break;
1831 case CT_MenuItem:
1832 newSize += QSize(0, -2);
1833 break;
1834 case CT_MenuBar:
1835 newSize += QSize(0, -1);
1836 break;
1837 case CT_ToolButton:
1838 if (const QStyleOptionToolButton *b = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
1839 if (b->toolButtonStyle != Qt::ToolButtonIconOnly)
1840 newSize = QSize(newSize.width() + 1, newSize.height() - 1);
1841 else
1842 newSize = QSize(newSize.width() + 1, newSize.height());
1843 }
1844 break;
1845
1846 default:
1847 break;
1848 }
1849 return newSize;
1850}
1851
1852QRect QWindowsCEStyle::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const {
1853 QRect rect = QWindowsStyle::subElementRect(element, option, widget);
1854 switch (element) {
1855#ifndef QT_NO_COMBOBOX
1856 case SE_ComboBoxFocusRect:
1857 if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
1858 int margin = cb->frame ? 3 : 0;
1859 rect.setRect(margin, margin, option->rect.width() - 2*margin - 20, option->rect.height() - 2*margin);
1860 rect = visualRect(option->direction, option->rect, rect);
1861 }
1862 break;
1863#endif // QT_NO_COMBOBOX
1864 default:
1865 break;
1866 }
1867 return rect;
1868}
1869
1870QRect QWindowsCEStyle::subControlRect(ComplexControl control, const QStyleOptionComplex *option,
1871 SubControl subControl, const QWidget *widget) const {
1872 QRect rect = QWindowsStyle::subControlRect(control, option, subControl, widget);
1873 switch (control) {
1874#ifndef QT_NO_SLIDER
1875 case CC_Slider:
1876 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
1877 int tickOffset = pixelMetric(PM_SliderTickmarkOffset, slider, widget);
1878 int thickness = pixelMetric(PM_SliderControlThickness, slider, widget);
1879
1880 switch (subControl) {
1881 case SC_SliderHandle: {
1882 int sliderPos = 0;
1883 int len = pixelMetric(PM_SliderLength, slider, widget);
1884 bool horizontal = slider->orientation == Qt::Horizontal;
1885 sliderPos = sliderPositionFromValue(slider->minimum, slider->maximum,
1886 slider->sliderPosition,
1887 (horizontal ? slider->rect.width()
1888 : slider->rect.height()) - len,
1889 slider->upsideDown);
1890 if (horizontal)
1891 rect.setRect(slider->rect.x() + sliderPos, slider->rect.y() + tickOffset, len, thickness);
1892 else
1893 rect.setRect(slider->rect.x() + tickOffset, slider->rect.y() + sliderPos, thickness, len);
1894 break; }
1895 default:
1896 break;
1897 }
1898 rect = visualRect(slider->direction, slider->rect, rect);
1899 }
1900 break;
1901#endif //QT_NO_SLIDER
1902#ifndef QT_NO_COMBOBOX
1903 case CC_ComboBox:
1904 if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
1905 int x = cb->rect.x(),
1906 y = cb->rect.y(),
1907 wi = cb->rect.width(),
1908 he = cb->rect.height();
1909 int xpos = x;
1910 int margin = cb->frame ? 3 : 0;
1911 int bmarg = cb->frame ? 2 : 0;
1912 xpos += wi - (he - 2*bmarg) - bmarg;
1913 switch (subControl) {
1914 case SC_ComboBoxArrow:
1915 rect.setRect(xpos, y + bmarg, he - 2*bmarg, he - 2*bmarg);
1916 break;
1917 case SC_ComboBoxEditField:
1918 rect.setRect(x + margin, y + margin, wi - 2 * margin - (he - 2*bmarg), he - 2 * margin);
1919 break;
1920 case SC_ComboBoxListBoxPopup:
1921 rect = cb->rect;
1922 break;
1923 case SC_ComboBoxFrame:
1924 rect = cb->rect;
1925 break;
1926 default:
1927 break;
1928 }
1929 rect = visualRect(cb->direction, cb->rect, rect);
1930 }
1931#endif //QT_NO_COMBOBOX
1932#ifndef QT_NO_SPINBOX
1933 case CC_SpinBox:
1934 if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
1935 QSize bs;
1936 int fw = spinbox->frame ? pixelMetric(PM_SpinBoxFrameWidth, spinbox, widget) : 0;
1937 bs.setWidth(qMax(18, (spinbox->rect.height() / 2 - fw + 1)));
1938 // 1.6 -approximate golden mean
1939 bs.setHeight(qMax(18, qMin((bs.height() * 8 / 5), (spinbox->rect.width() / 4))));
1940 bs = bs.expandedTo(QApplication::globalStrut());
1941 int y = fw;
1942 int x, lx, rx;
1943 x = spinbox->rect.width() - y - bs.width() * 2;
1944 lx = fw;
1945 rx = x - fw;
1946 switch (subControl) {
1947 case SC_SpinBoxUp:
1948 rect = QRect(x + bs.width(), y, bs.width(), bs.height());
1949 break;
1950 case SC_SpinBoxDown:
1951 rect = QRect(x, y , bs.width(), bs.height());
1952 break;
1953 case SC_SpinBoxEditField:
1954 rect = QRect(lx, fw, rx-2, spinbox->rect.height() - 2*fw);
1955 break;
1956 case SC_SpinBoxFrame:
1957 rect = spinbox->rect;
1958 default:
1959 break;
1960 }
1961 rect = visualRect(spinbox->direction, spinbox->rect, rect);
1962 }
1963 break;
1964#endif // Qt_NO_SPINBOX
1965#ifndef QT_NO_GROUPBOX
1966 case CC_GroupBox: {
1967 if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
1968 switch (subControl) {
1969 case SC_GroupBoxFrame:
1970 // FALL THROUGH
1971 case SC_GroupBoxContents: {
1972 int topMargin = 0;
1973 int topHeight = 0;
1974 int bottomMargin = 0;
1975 int noLabelMargin = 0;
1976 QRect frameRect = groupBox->rect;
1977 int verticalAlignment = styleHint(SH_GroupBox_TextLabelVerticalAlignment, groupBox, widget);
1978 if (groupBox->text.size()) {
1979 topHeight = groupBox->fontMetrics.height();
1980 if (verticalAlignment & Qt::AlignVCenter)
1981 topMargin = topHeight / 2;
1982 else if (verticalAlignment & Qt::AlignTop)
1983 topMargin = -topHeight/2;
1984 }
1985 else {
1986 topHeight = groupBox->fontMetrics.height();
1987 noLabelMargin = topHeight / 2;
1988 if (verticalAlignment & Qt::AlignVCenter) {
1989 topMargin = topHeight / 4 - 4;
1990 bottomMargin = topHeight / 4 - 4;
1991 }
1992 else if (verticalAlignment & Qt::AlignTop) {
1993 topMargin = topHeight/2 - 4;
1994 bottomMargin = topHeight/2 - 4;
1995 }
1996 }
1997
1998 if (subControl == SC_GroupBoxFrame) {
1999 frameRect.setTop(topMargin);
2000 frameRect.setBottom(frameRect.height() + bottomMargin);
2001 rect = frameRect;
2002 break;
2003 }
2004
2005 int frameWidth = 0;
2006 if ((groupBox->features & QStyleOptionFrameV2::Flat) == 0)
2007 frameWidth = pixelMetric(PM_DefaultFrameWidth, groupBox, widget);
2008 rect = frameRect.adjusted(frameWidth, frameWidth + topHeight, -frameWidth, -frameWidth - noLabelMargin);
2009 break;
2010 }
2011 case SC_GroupBoxCheckBox:
2012 // FALL THROUGH
2013 case SC_GroupBoxLabel: {
2014 QFontMetrics fontMetrics = groupBox->fontMetrics;
2015 int h = fontMetrics.height();
2016 int tw = fontMetrics.size(Qt::TextShowMnemonic, groupBox->text + QLatin1Char(' ')).width();
2017 int marg = (groupBox->features & QStyleOptionFrameV2::Flat) ? 0 : 8;
2018 rect = groupBox->rect.adjusted(marg, 0, -marg, 0);
2019 rect.setHeight(h);
2020
2021 int indicatorWidth = pixelMetric(PM_IndicatorWidth, option, widget);
2022 int indicatorSpace = pixelMetric(PM_CheckBoxLabelSpacing, option, widget) - 1;
2023 bool hasCheckBox = groupBox->subControls & QStyle::SC_GroupBoxCheckBox;
2024 int checkBoxSize = hasCheckBox ? (indicatorWidth + indicatorSpace) : 0;
2025
2026 // Adjusted rect for label + indicatorWidth + indicatorSpace
2027 QRect totalRect = alignedRect(groupBox->direction, groupBox->textAlignment,
2028 QSize(tw + checkBoxSize, h), rect);
2029
2030 // Adjust totalRect if checkbox is set
2031 if (hasCheckBox) {
2032 bool ltr = groupBox->direction == Qt::LeftToRight;
2033 int left = 0;
2034 // Adjust for check box
2035 if (subControl == SC_GroupBoxCheckBox) {
2036 int indicatorHeight = pixelMetric(PM_IndicatorHeight, option, widget);
2037 left = ltr ? totalRect.left() : (totalRect.right() - indicatorWidth);
2038 int top = totalRect.top() + (fontMetrics.height() - indicatorHeight) / 2;
2039 totalRect.setRect(left, top, indicatorWidth, indicatorHeight);
2040 // Adjust for label
2041 } else {
2042 left = ltr ? (totalRect.left() + checkBoxSize - 2) : totalRect.left();
2043 totalRect.setRect(left, totalRect.top(),
2044 totalRect.width() - checkBoxSize, totalRect.height());
2045 }
2046 }
2047 rect = totalRect;
2048 break;
2049 }
2050 default:
2051 break;
2052 }
2053 }
2054 break;
2055 }
2056#endif // QT_NO_GROUPBOX
2057 default:
2058 break;
2059 }
2060 return rect;
2061}
2062
2063QStyle::SubControl QWindowsCEStyle::hitTestComplexControl(ComplexControl control, const QStyleOptionComplex *option,
2064 const QPoint &pos, const QWidget *widget) const {
2065 /*switch (control) {
2066 default:
2067 break;
2068 }*/
2069 return QWindowsStyle::hitTestComplexControl(control, option, pos, widget);
2070}
2071
2072
2073QPalette QWindowsCEStyle::standardPalette() const {
2074 QPalette palette (Qt::black,QColor(198, 195, 198), QColor(222, 223, 222 ),
2075 QColor(132, 130, 132), QColor(198, 195, 198) , Qt::black, Qt::white, Qt::white, QColor(198, 195, 198));
2076 palette.setColor(QPalette::Window, QColor(198, 195, 198));
2077 palette.setColor(QPalette::Base, Qt::white);
2078 palette.setColor(QPalette::Button, QColor(198, 195, 198));
2079 palette.setColor(QPalette::Highlight, QColor(0, 0, 132));
2080 palette.setColor(QPalette::Light, Qt::white);
2081 palette.setColor(QPalette::Midlight, QColor(222, 223, 222 ));
2082 palette.setColor(QPalette::Dark, QColor(132, 130, 132));
2083 palette.setColor(QPalette::Mid, QColor(132, 130, 132));
2084 palette.setColor(QPalette::Shadow, QColor(0, 0, 0));
2085 palette.setColor(QPalette::BrightText, QColor(33, 162, 33)); //color for ItemView checked indicator (arrow)
2086 palette.setColor(QPalette::Link, QColor(24,81,132)); // color for the box around the ItemView indicator
2087
2088 return palette;
2089}
2090
2091void QWindowsCEStyle::polish(QApplication *app) {
2092 QWindowsStyle::polish(app);
2093}
2094
2095void QWindowsCEStyle::polish(QWidget *widget) {
2096 QWindowsStyle::polish(widget);
2097}
2098
2099void QWindowsCEStyle::polish(QPalette &palette) {
2100 QWindowsStyle::polish(palette);
2101}
2102
2103int QWindowsCEStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt, const QWidget *widget) const {
2104 int ret;
2105
2106 switch (pm) {
2107 case PM_DefaultFrameWidth:
2108 ret = 1;
2109 break;
2110
2111 case PM_MenuBarHMargin:
2112 ret = 2;
2113 break;
2114 case PM_MenuBarVMargin:
2115 ret = 2;
2116 break;
2117 /*case PM_MenuBarItemSpacing:
2118 ret = 2;
2119 break;*/
2120
2121 case PM_MenuButtonIndicator:
2122 ret = 10;
2123 break;
2124
2125 case PM_SpinBoxFrameWidth:
2126 ret = 2;
2127 break;
2128 case PM_ButtonDefaultIndicator:
2129 case PM_ButtonShiftHorizontal:
2130 case PM_ButtonShiftVertical:
2131 ret = 1;
2132 break;
2133#ifndef QT_NO_TABBAR
2134 case PM_TabBarTabShiftHorizontal:
2135 ret = 0;
2136 break;
2137 case PM_TabBarTabShiftVertical:
2138 ret = 6;
2139 break;
2140#endif
2141 case PM_MaximumDragDistance:
2142 ret = 60;
2143 break;
2144
2145 case PM_IndicatorWidth:
2146 ret = windowsCEIndicatorSize;
2147 break;
2148
2149 case PM_IndicatorHeight:
2150 ret = windowsCEIndicatorSize;
2151 break;
2152
2153 case PM_ExclusiveIndicatorWidth:
2154 ret = windowsCEExclusiveIndicatorSize;
2155 break;
2156
2157 case PM_ExclusiveIndicatorHeight:
2158 ret = windowsCEExclusiveIndicatorSize;;
2159 break;
2160
2161#ifndef QT_NO_SLIDER
2162 case PM_SliderLength:
2163 ret = 12;
2164 break;
2165 case PM_SliderThickness:
2166 ret = windowsCESliderThickness;
2167 break;
2168
2169 case PM_TabBarScrollButtonWidth:
2170 ret = 18;
2171 break;
2172
2173 // Returns the number of pixels to use for the business part of the
2174 // slider (i.e., the non-tickmark portion). The remaining space is shared
2175 // equally between the tickmark regions.
2176 case PM_SliderControlThickness:
2177 if (const QStyleOptionSlider *sl = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
2178 int space = (sl->orientation == Qt::Horizontal) ? sl->rect.height() : sl->rect.width();
2179 int ticks = sl->tickPosition;
2180 int n = 0;
2181 if (ticks & QSlider::TicksAbove)
2182 ++n;
2183 if (ticks & QSlider::TicksBelow)
2184 ++n;
2185 if (!n) {
2186 ret = space;
2187 break;
2188 }
2189 int thick = 12;
2190 if (ticks != QSlider::TicksBothSides && ticks != QSlider::NoTicks)
2191 thick += pixelMetric(PM_SliderLength, sl, widget) / 4;
2192
2193 space -= thick;
2194 if (space > 0)
2195 thick += (space * 2) / (n + 2);
2196 ret = thick;
2197 } else {
2198 ret = 0;
2199 }
2200 break;
2201#endif // QT_NO_SLIDER
2202
2203#ifndef QT_NO_MENU
2204
2205 case PM_SmallIconSize:
2206 ret = windowsCEIconSize;
2207 break;
2208 case PM_ButtonMargin:
2209 ret = 6;
2210 break;
2211
2212 case PM_LargeIconSize:
2213 ret = 32;
2214 break;
2215
2216 case PM_IconViewIconSize:
2217 ret = pixelMetric(PM_LargeIconSize, opt, widget);
2218 break;
2219
2220 case PM_ToolBarIconSize:
2221 ret = windowsCEIconSize;
2222 break;
2223 case PM_DockWidgetTitleMargin:
2224 ret = 2;
2225 break;
2226#if defined(Q_WS_WIN)
2227// case PM_DockWidgetFrameWidth:
2228// ret = GetSystemMetrics(SM_CXFRAME);
2229// break;
2230#else
2231 case PM_DockWidgetFrameWidth:
2232 ret = 4;
2233 break;
2234#endif // Q_WS_WIN
2235 break;
2236
2237#endif // QT_NO_MENU
2238
2239 case PM_TitleBarHeight:
2240 ret = 30;
2241 break;
2242 case PM_ScrollBarExtent:
2243 ret = 19;
2244 break;
2245 case PM_SplitterWidth:
2246 ret = qMax(4, QApplication::globalStrut().width());
2247 break;
2248
2249#if defined(Q_WS_WIN)
2250 case PM_MDIFrameWidth:
2251 ret = 3;
2252 break;
2253#endif
2254 case PM_ToolBarItemMargin:
2255 ret = 1;
2256 break;
2257 case PM_ToolBarItemSpacing:
2258 ret = 0;
2259 break;
2260 case PM_ToolBarHandleExtent:
2261 ret = 10;
2262 break;
2263 case PM_ButtonIconSize:
2264 ret = 22;
2265 break;
2266 default:
2267 ret = QWindowsStyle::pixelMetric(pm, opt, widget);
2268 break;
2269 }
2270 return ret;
2271}
2272
2273QPixmap QWindowsCEStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt,
2274 const QWidget *widget) const {
2275#ifndef QT_NO_IMAGEFORMAT_XPM
2276 /*switch (standardPixmap) {
2277
2278 default:
2279 break;
2280 }*/
2281#endif //QT_NO_IMAGEFORMAT_XPM
2282 return QWindowsStyle::standardPixmap(standardPixmap, opt, widget);
2283}
2284
2285int QWindowsCEStyle::styleHint(StyleHint hint, const QStyleOption *opt, const QWidget *widget,
2286 QStyleHintReturn *returnData) const {
2287 int ret;
2288 switch (hint) {
2289 case SH_TabBar_ElideMode:
2290 ret = Qt::ElideMiddle;
2291 break;
2292 case SH_EtchDisabledText:
2293 ret = false;
2294 default:
2295 ret = QWindowsStyle::styleHint(hint, opt, widget, returnData);
2296 break;
2297 }
2298 return ret;
2299}
2300
2301void QWindowsCEStylePrivate::drawWinShades(QPainter *p,
2302 int x, int y, int w, int h,
2303 const QColor &c1, const QColor &c2,
2304 const QColor &c3, const QColor &c4,
2305 const QBrush *fill) {
2306 if (w < 2 || h < 2) // can't do anything with that
2307 return;
2308 QPen oldPen = p->pen();
2309 QPoint a[3] = { QPoint(x, y+h-2), QPoint(x, y), QPoint(x+w-2, y) };
2310 p->setPen(c1);
2311 p->drawPolyline(a, 3);
2312 QPoint b[3] = { QPoint(x, y+h-1), QPoint(x+w-1, y+h-1), QPoint(x+w-1, y) };
2313 p->setPen(c2);
2314 p->drawPolyline(b, 3);
2315 if (w > 4 && h > 4) {
2316 QPoint c[3] = { QPoint(x+1, y+h-3), QPoint(x+1, y+1), QPoint(x+w-3, y+1) };
2317 p->setPen(c3);
2318 p->drawPolyline(c, 3);
2319 QPoint d[3] = { QPoint(x+1, y+h-2), QPoint(x+w-2, y+h-2), QPoint(x+w-2, y+1) };
2320 p->setPen(c4);
2321 p->drawPolyline(d, 3);
2322 if (fill)
2323 p->fillRect(QRect(x+2, y+2, w-4, h-4), *fill);
2324 }
2325 p->setPen(oldPen);
2326}
2327
2328void QWindowsCEStylePrivate::drawWinCEShades(QPainter *p,
2329 int x, int y, int w, int h,
2330 const QColor &c1, const QColor &c2,
2331 const QColor &c3, const QColor &c4,
2332 const QBrush *fill) {
2333 if (w < 2 || h < 2) // can't do anything with that
2334 return;
2335 QPen oldPen = p->pen();
2336 QPoint b[3] = { QPoint(x, y+h-1), QPoint(x+w-1, y+h-1), QPoint(x+w-1, y) };
2337 p->setPen(c2);
2338 p->drawPolyline(b, 3);
2339 if (w > 4 && h > 4) {
2340 QPoint c[3] = { QPoint(x+1, y+h-3), QPoint(x+1, y+1), QPoint(x+w-3, y+1) };
2341 p->setPen(c3);
2342 p->drawPolyline(c, 3);
2343 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) };
2344 p->setPen(c4);
2345 p->drawPolyline(d, 5);
2346 if (fill)
2347 p->fillRect(QRect(x+2, y+2, w-4, h-4), *fill);
2348 }
2349 QPoint a[3] = { QPoint(x+1, y+h-3), QPoint(x+1, y+1), QPoint(x+w-3, y+1) };
2350 p->setPen(c1);
2351 p->drawPolyline(a, 3);
2352 p->setPen(oldPen);
2353}
2354
2355void QWindowsCEStylePrivate::drawWinCEShadesSunken(QPainter *p,
2356 int x, int y, int w, int h,
2357 const QColor &c1, const QColor &c2,
2358 const QColor &c3, const QColor &c4,
2359 const QBrush *fill) {
2360 if (w < 2 || h < 2) // can't do anything with that
2361 return;
2362 QPen oldPen = p->pen();
2363
2364 QPoint b[3] = { QPoint(x, y+h-1), QPoint(x+w-1, y+h-1), QPoint(x+w-1, y) };
2365 p->setPen(c2);
2366 p->drawPolyline(b, 3);
2367 if (w > 4 && h > 4) {
2368 QPoint d[3] = { QPoint(x, y+h-2), QPoint(x+w-2, y+h-2), QPoint(x+w-2, y) };
2369 p->setPen(c4);
2370 p->drawPolyline(d, 3);
2371 QPoint c[3] = { QPoint(x, y+h-2), QPoint(x, y), QPoint(x+w-2, y) };
2372 p->setPen(c3);
2373 p->drawPolyline(c, 3);
2374 if (fill)
2375 p->fillRect(QRect(x+2, y+2, w-4, h-4), *fill);
2376 }
2377 QPoint a[3] = { QPoint(x+1, y+h-3), QPoint(x+1, y+1), QPoint(x+w-3, y+1) };
2378 p->setPen(c1);
2379 p->drawPolyline(a, 3);
2380 p->setPen(oldPen);
2381}
2382
2383
2384void QWindowsCEStylePrivate::drawWinCEButton(QPainter *p, int x, int y, int w, int h,
2385 const QPalette &pal, bool sunken,
2386 const QBrush *fill) {
2387 if (sunken)
2388 drawWinCEShadesSunken(p, x, y, w, h,
2389 pal.shadow().color(), pal.light().color(), pal.shadow().color(),
2390 pal.midlight().color(), fill);
2391 else
2392 drawWinCEShades(p, x, y, w, h,
2393 pal.midlight().color(), pal.shadow().color(), pal.button().color(),
2394 pal.dark().color(), fill);
2395}
2396
2397void QWindowsCEStylePrivate::drawWinCEPanel(QPainter *p, int x, int y, int w, int h,
2398 const QPalette &pal, bool sunken,
2399 const QBrush *fill) {
2400 if (sunken)
2401 drawWinShades(p, x, y, w, h,
2402 pal.dark().color(), pal.light().color(), pal.shadow().color(),
2403 pal.midlight().color(), fill);
2404 else
2405 drawWinShades(p, x, y, w, h,
2406 pal.light().color(), pal.shadow().color(), pal.button().color(),
2407 pal.midlight().color(), fill);
2408}
2409
2410void QWindowsCEStylePrivate::drawWinCEButton(QPainter *p, const QRect &r,
2411 const QPalette &pal, bool sunken, const QBrush *fill) {
2412 drawWinCEButton(p, r.x(), r.y(), r.width(), r.height(), pal, sunken, fill);
2413}
2414
2415void QWindowsCEStylePrivate::drawWinCEPanel(QPainter *p, const QRect &r,
2416 const QPalette &pal, bool sunken, const QBrush *fill) {
2417 drawWinCEPanel(p, r.x(), r.y(), r.width(), r.height(), pal, sunken, fill);
2418}
2419
2420QT_END_NAMESPACE
2421
2422#endif // QT_NO_STYLE_WINDOWSCE
Note: See TracBrowser for help on using the repository browser.