1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
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 The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
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 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file. Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qplastiquestyle.h"
43
44 #if !defined(QT_NO_STYLE_PLASTIQUE) || defined(QT_PLUGIN)
45
46 static const bool AnimateBusyProgressBar = true;
47 static const bool AnimateProgressBar = false;
48 // #define QPlastique_MaskButtons
49 static const int ProgressBarFps = 25;
50 static const int blueFrameWidth = 2; // with of line edit focus frame
51
52 #include "qwindowsstyle_p.h"
53 #include <qapplication.h>
54 #include <qbitmap.h>
55 #include <qabstractitemview.h>
56 #include <qcheckbox.h>
57 #include <qcombobox.h>
58 #include <qdebug.h>
59 #include <qdialogbuttonbox.h>
60 #include <qformlayout.h>
61 #include <qgroupbox.h>
62 #include <qimage.h>
63 #include <qlineedit.h>
64 #include <qmainwindow.h>
65 #include <qmenu.h>
66 #include <qmenubar.h>
67 #include <qpainter.h>
68 #include <qpaintengine.h>
69 #include <qpainterpath.h>
70 #include <qpalette.h>
71 #include <qpen.h>
72 #include <qpixmap.h>
73 #include <qpixmapcache.h>
74 #include <qprogressbar.h>
75 #include <qpushbutton.h>
76 #include <qradiobutton.h>
77 #include <qscrollbar.h>
78 #include <qspinbox.h>
79 #include <qsplitter.h>
80 #include <qstyleoption.h>
81 #include <qtextedit.h>
82 #include <qelapsedtimer.h>
83 #include <qtoolbar.h>
84 #include <qtoolbox.h>
85 #include <qtoolbutton.h>
86 #include <qworkspace.h>
87 #include <qprocess.h>
88 #include <qvarlengtharray.h>
89 #include <limits.h>
90 #include <private/qstylehelper_p.h>
91
92 QT_BEGIN_NAMESPACE
93
94 // from windows style
95 static const int windowsItemFrame = 2; // menu item frame width
96 static const int windowsSepHeight = 2; // separator item height
97 static const int windowsItemHMargin = 3; // menu item hor text margin
98 static const int windowsItemVMargin = 2; // menu item ver text margin
99 static const int windowsArrowHMargin = 6; // arrow horizontal margin
100 static const int windowsTabSpacing = 12; // space between text and tab
101 static const int windowsRightBorder = 15; // right border on windows
102 static const int windowsCheckMarkWidth = 12; // checkmarks width on windows
103
104 static const char * const qt_plastique_slider_verticalhandle[] = {
105 "15 11 6 1",
106 " c None",
107 "+ c #979797",
108 "@ c #C9C9C9",
109 "$ c #C1C1C1",
110 "b c None",
111 "d c None",
112 " $++++++++$ ",
113 "$+bbbbbbbb+$ ",
114 "+b $$ +$ ",
115 "+b $@ +$ ",
116 "+b +$",
117 "+b d+",
118 "+b d+$",
119 "+b $$ d+$ ",
120 "+b $@ d+$ ",
121 "$+dddddddd+$ ",
122 " $++++++++$ "};
123
124 static const char * const qt_plastique_slider_verticalhandle_left[] = {
125 "15 11 6 1",
126 " c None",
127 "+ c #979797",
128 "@ c #C9C9C9",
129 "$ c #C1C1C1",
130 "b c None",
131 "d c None",
132 " $++++++++$ ",
133 " $+bbbbbbbb+$",
134 " $+b $$ d+",
135 " $+b $@ d+",
136 "$+b d+",
137 "+b d+",
138 "$+ d+",
139 " $+ $$ d+",
140 " $+ $@ d+",
141 " $+dddddddd+$",
142 " $++++++++$ "};
143
144 static const char * const qt_plastique_slider_horizontalhandle[] = {
145 "11 15 6 1",
146 " c None",
147 "+ c #979797",
148 "@ c #C9C9C9",
149 "$ c #C1C1C1",
150 "b c None",
151 "d c None",
152 " $+++++++$ ",
153 "$+bbbbbbb+$",
154 "+b d+",
155 "+b$$ $$d+",
156 "+b$@ $@d+",
157 "+b d+",
158 "+b d+",
159 "+b d+",
160 "+b d+",
161 "+b d+",
162 "$+ d+$",
163 " $+ d+$ ",
164 " $+ d+$ ",
165 " $+d+$ ",
166 " $+$ "};
167
168 static const char * const qt_plastique_slider_horizontalhandle_up[] = {
169 "11 15 6 1",
170 " c None",
171 "+ c #979797",
172 "@ c #C9C9C9",
173 "$ c #C1C1C1",
174 "b c None",
175 "d c None",
176 " $+$ ",
177 " $+b+$ ",
178 " $+b +$ ",
179 " $+b +$ ",
180 "$+b +$",
181 "+b d+",
182 "+b d+",
183 "+b d+",
184 "+b d+",
185 "+b d+",
186 "+b$$ $$d+",
187 "+b$@ $@d+",
188 "+b d+",
189 "$+ddddddd+$",
190 " $+++++++$ "};
191
192 static const char * const qt_scrollbar_button_arrow_left[] = {
193 "4 7 2 1",
194 " c None",
195 "* c #BFBFBF",
196 " *",
197 " **",
198 " ***",
199 "****",
200 " ***",
201 " **",
202 " *"};
203
204 static const char * const qt_scrollbar_button_arrow_right[] = {
205 "4 7 2 1",
206 " c None",
207 "* c #BFBFBF",
208 "* ",
209 "** ",
210 "*** ",
211 "****",
212 "*** ",
213 "** ",
214 "* "};
215
216 static const char * const qt_scrollbar_button_arrow_up[] = {
217 "7 4 2 1",
218 " c None",
219 "* c #BFBFBF",
220 " * ",
221 " *** ",
222 " ***** ",
223 "*******"};
224
225 static const char * const qt_scrollbar_button_arrow_down[] = {
226 "7 4 2 1",
227 " c None",
228 "* c #BFBFBF",
229 "*******",
230 " ***** ",
231 " *** ",
232 " * "};
233
234 static const char * const qt_scrollbar_button_left[] = {
235 "16 16 6 1",
236 " c None",
237 ". c #BFBFBF",
238 "+ c #979797",
239 "# c #FAFAFA",
240 "< c #FAFAFA",
241 "* c #FAFAFA",
242 " .+++++++++++++.",
243 ".+#############+",
244 "+# <+",
245 "+# <+",
246 "+# <+",
247 "+# <+",
248 "+# <+",
249 "+# <+",
250 "+# <+",
251 "+# <+",
252 "+# <+",
253 "+# <+",
254 "+# <+",
255 "+# <+",
256 ".+<<<<<<<<<<<<<+",
257 " .+++++++++++++."};
258
259 static const char * const qt_scrollbar_button_right[] = {
260 "16 16 6 1",
261 " c None",
262 ". c #BFBFBF",
263 "+ c #979797",
264 "# c #FAFAFA",
265 "< c #FAFAFA",
266 "* c #FAFAFA",
267 ".+++++++++++++. ",
268 "+#############+.",
269 "+# <+",
270 "+# <+",
271 "+# <+",
272 "+# <+",
273 "+# <+",
274 "+# <+",
275 "+# <+",
276 "+# <+",
277 "+# <+",
278 "+# <+",
279 "+# <+",
280 "+# <+",
281 "+<<<<<<<<<<<<<+.",
282 ".+++++++++++++. "};
283
284 static const char * const qt_scrollbar_button_up[] = {
285 "16 16 6 1",
286 " c None",
287 ". c #BFBFBF",
288 "+ c #979797",
289 "# c #FAFAFA",
290 "< c #FAFAFA",
291 "* c #FAFAFA",
292 " .++++++++++++. ",
293 ".+############+.",
294 "+# <+",
295 "+# <+",
296 "+# <+",
297 "+# <+",
298 "+# <+",
299 "+# <+",
300 "+# <+",
301 "+# <+",
302 "+# <+",
303 "+# <+",
304 "+# <+",
305 "+# <+",
306 "+<<<<<<<<<<<<<<+",
307 ".++++++++++++++."};
308
309 static const char * const qt_scrollbar_button_down[] = {
310 "16 16 6 1",
311 " c None",
312 ". c #BFBFBF",
313 "+ c #979797",
314 "# c #FAFAFA",
315 "< c #FAFAFA",
316 "* c #FAFAFA",
317 "++++++++++++++++",
318 "+##############+",
319 "+# <+",
320 "+# <+",
321 "+# <+",
322 "+# <+",
323 "+# <+",
324 "+# <+",
325 "+# <+",
326 "+# <+",
327 "+# <+",
328 "+# <+",
329 "+# <+",
330 "+# <+",
331 ".+<<<<<<<<<<<<+.",
332 " .++++++++++++. "};
333
334 static const char * const qt_scrollbar_slider_pattern_vertical[] = {
335 "10 18 3 1",
336 " c None",
337 ". c #BFBFBF",
338 "+ c #979797",
339 ".. .. ..",
340 ".+ .+ .+",
341 " ",
342 " ",
343 ".. .. ..",
344 ".+ .+ .+",
345 " ",
346 " ",
347 ".. .. ..",
348 ".+ .+ .+",
349 " ",
350 " ",
351 ".. .. ..",
352 ".+ .+ .+",
353 " ",
354 " ",
355 ".. .. ..",
356 ".+ .+ .+"};
357
358 static const char * const qt_scrollbar_slider_pattern_horizontal[] = {
359 "18 10 3 1",
360 " c None",
361 ". c #BFBFBF",
362 "+ c #979797",
363 ".. .. .. .. ..",
364 ".+ .+ .+ .+ .+",
365 " ",
366 " ",
367 ".. .. .. .. ..",
368 ".+ .+ .+ .+ .+",
369 " ",
370 " ",
371 ".. .. .. .. ..",
372 ".+ .+ .+ .+ .+"};
373
374 static const char * const qt_toolbarhandle[] = {
375 "6 6 4 1",
376 " c None",
377 ". c #C5C5C5",
378 "+ c #EEEEEE",
379 "@ c #FAFAFA",
380 ".. ",
381 ".+@ ",
382 " @@ ",
383 " .. ",
384 " .+@",
385 " @@"};
386
387 static const char * const qt_simple_toolbarhandle[] = {
388 "3 3 4 1",
389 " c None",
390 ". c #C5C5C5",
391 "+ c #EEEEEE",
392 "@ c #FAFAFA",
393 ".. ",
394 ".+@",
395 " @@"};
396
397 static const char * const qt_titlebar_context_help[] = {
398 "27 27 5 1",
399 " c None",
400 ". c #0A0C12",
401 "+ c #1B202D",
402 "@ c #293144",
403 "# c #3C435D",
404 " ",
405 " ",
406 " ",
407 " ",
408 " ",
409 " ",
410 " ",
411 " ",
412 " +@##@+ ",
413 " .@@@.+@@.. ",
414 " .##+ +@@+. ",
415 " .##@ @#@+. ",
416 " .... +@+.. ",
417 " .@+@@.. ",
418 " +#@@+ ",
419 " .##. ",
420 " .++. ",
421 " .++. ",
422 " +##+ ",
423 " .@@. ",
424 " ",
425 " ",
426 " ",
427 " ",
428 " ",
429 " ",
430 " "};
431
qMapGradientToRect(const QLinearGradient & gradient,const QRectF & rect)432 static QLinearGradient qMapGradientToRect(const QLinearGradient &gradient, const QRectF &rect)
433 {
434 QLinearGradient tmpGrad(rect.center().x(), rect.top(),
435 rect.center().x(), rect.bottom());
436 tmpGrad.setStops(gradient.stops());
437 return tmpGrad;
438 }
439
qMapBrushToRect(const QBrush & brush,const QRectF & rect)440 static QBrush qMapBrushToRect(const QBrush &brush, const QRectF &rect)
441 {
442 if (!brush.gradient())
443 return brush;
444
445 // ### Ugly assumption that it's a linear gradient
446 QBrush tmp(qMapGradientToRect(*static_cast<const QLinearGradient *>(brush.gradient()), rect));
447 return tmp;
448 }
449
qBrushSetAlphaF(QBrush * brush,qreal alpha)450 static void qBrushSetAlphaF(QBrush *brush, qreal alpha)
451 {
452 if (const QGradient *gradient = brush->gradient()) {
453 // Use the gradient. Call QColor::setAlphaF() on all color stops.
454 QGradientStops stops = gradient->stops();
455 QMutableVectorIterator<QGradientStop> it(stops);
456 QColor tmpColor;
457 while (it.hasNext()) {
458 it.next();
459 tmpColor = it.value().second;
460 tmpColor.setAlphaF(alpha * tmpColor.alphaF());
461 it.setValue(QPair<qreal, QColor>(it.value().first, tmpColor));
462 }
463
464 switch (gradient->type()) {
465 case QGradient::RadialGradient: {
466 QRadialGradient grad = *static_cast<const QRadialGradient *>(gradient);
467 grad.setStops(stops);
468 *brush = QBrush(grad);
469 break;
470 }
471 case QGradient::ConicalGradient: {
472 QConicalGradient grad = *static_cast<const QConicalGradient *>(gradient);
473 grad.setStops(stops);
474 *brush = QBrush(grad);
475 break;
476 }
477 default:
478 qWarning("QPlastiqueStyle::qBrushLight() - unknown gradient type"
479 " - falling back to QLinearGradient");
480 case QGradient::LinearGradient: {
481 QLinearGradient grad = *static_cast<const QLinearGradient *>(gradient);
482 grad.setStops(stops);
483 *brush = QBrush(grad);
484 break;
485 }
486 }
487 } else if (!brush->texture().isNull()) {
488 // Modify the texture - ridiculously expensive.
489 QPixmap texture = brush->texture();
490 QPixmap pixmap;
491 QString name = QLatin1Literal("qbrushtexture-alpha")
492 % HexString<qreal>(alpha)
493 % HexString<qint64>(texture.cacheKey());
494 if (!QPixmapCache::find(name, pixmap)) {
495 QImage image = texture.toImage();
496 QRgb *rgb = reinterpret_cast<QRgb *>(image.bits());
497 int pixels = image.width() * image.height();
498 QColor tmpColor;
499 while (pixels--) {
500 tmpColor.setRgb(*rgb);
501 tmpColor.setAlphaF(alpha * tmpColor.alphaF());
502 *rgb++ = tmpColor.rgba();
503 }
504 pixmap = QPixmap::fromImage(image);
505 QPixmapCache::insert(name, pixmap);
506 }
507 brush->setTexture(pixmap);
508 } else {
509 // Use the color
510 QColor tmpColor = brush->color();
511 tmpColor.setAlphaF(alpha * tmpColor.alphaF());
512 brush->setColor(tmpColor);
513 }
514 }
515
qBrushLight(QBrush brush,int light)516 static QBrush qBrushLight(QBrush brush, int light)
517 {
518 if (const QGradient *gradient = brush.gradient()) {
519 // Use the gradient. Call QColor::lighter() on all color stops.
520 QGradientStops stops = gradient->stops();
521 QMutableVectorIterator<QGradientStop> it(stops);
522 while (it.hasNext()) {
523 it.next();
524 it.setValue(QPair<qreal, QColor>(it.value().first, it.value().second.lighter(light)));
525 }
526
527 switch (gradient->type()) {
528 case QGradient::RadialGradient: {
529 QRadialGradient grad = *static_cast<const QRadialGradient *>(gradient);
530 grad.setStops(stops);
531 brush = QBrush(grad);
532 break;
533 }
534 case QGradient::ConicalGradient: {
535 QConicalGradient grad = *static_cast<const QConicalGradient *>(gradient);
536 grad.setStops(stops);
537 brush = QBrush(grad);
538 break;
539 }
540 default:
541 qWarning("QPlastiqueStyle::qBrushLight() - unknown gradient type"
542 " - falling back to QLinearGradient");
543 case QGradient::LinearGradient: {
544 QLinearGradient grad = *static_cast<const QLinearGradient *>(gradient);
545 grad.setStops(stops);
546 brush = QBrush(grad);
547 break;
548 }
549 }
550 } else if (!brush.texture().isNull()) {
551 // Modify the texture - ridiculously expensive.
552 QPixmap texture = brush.texture();
553 QPixmap pixmap;
554 QString name = QLatin1Literal("qbrushtexture-light")
555 % HexString<int>(light)
556 % HexString<qint64>(texture.cacheKey());
557
558 if (!QPixmapCache::find(name, pixmap)) {
559 QImage image = texture.toImage();
560 QRgb *rgb = reinterpret_cast<QRgb *>(image.bits());
561 int pixels = image.width() * image.height();
562 QColor tmpColor;
563 while (pixels--) {
564 tmpColor.setRgb(*rgb);
565 *rgb++ = tmpColor.lighter(light).rgba();
566 }
567 pixmap = QPixmap::fromImage(image);
568 QPixmapCache::insert(name, pixmap);
569 }
570 brush.setTexture(pixmap);
571 } else {
572 // Use the color
573 brush.setColor(brush.color().lighter(light));
574 }
575 return brush;
576 }
577
qBrushDark(QBrush brush,int dark)578 static QBrush qBrushDark(QBrush brush, int dark)
579 {
580 if (const QGradient *gradient = brush.gradient()) {
581 // Use the gradient. Call QColor::darker() on all color stops.
582 QGradientStops stops = gradient->stops();
583 QMutableVectorIterator<QGradientStop> it(stops);
584 while (it.hasNext()) {
585 it.next();
586 it.setValue(QPair<qreal, QColor>(it.value().first, it.value().second.darker(dark)));
587 }
588
589 switch (gradient->type()) {
590 case QGradient::RadialGradient: {
591 QRadialGradient grad = *static_cast<const QRadialGradient *>(gradient);
592 grad.setStops(stops);
593 brush = QBrush(grad);
594 break;
595 }
596 case QGradient::ConicalGradient: {
597 QConicalGradient grad = *static_cast<const QConicalGradient *>(gradient);
598 grad.setStops(stops);
599 brush = QBrush(grad);
600 break;
601 }
602 default:
603 qWarning("QPlastiqueStyle::qBrushDark() - unknown gradient type"
604 " - falling back to QLinearGradient");
605 case QGradient::LinearGradient: {
606 QLinearGradient grad = *static_cast<const QLinearGradient *>(gradient);
607 grad.setStops(stops);
608 brush = QBrush(grad);
609 break;
610 }
611 }
612 } else if (!brush.texture().isNull()) {
613 // Modify the texture - ridiculously expensive.
614 QPixmap texture = brush.texture();
615 QPixmap pixmap;
616 QString name = QLatin1Literal("qbrushtexture-dark")
617 % HexString<int>(dark)
618 % HexString<qint64>(texture.cacheKey());
619
620 if (!QPixmapCache::find(name, pixmap)) {
621 QImage image = texture.toImage();
622 QRgb *rgb = reinterpret_cast<QRgb *>(image.bits());
623 int pixels = image.width() * image.height();
624 QColor tmpColor;
625 while (pixels--) {
626 tmpColor.setRgb(*rgb);
627 *rgb++ = tmpColor.darker(dark).rgba();
628 }
629 pixmap = QPixmap::fromImage(image);
630 QPixmapCache::insert(name, pixmap);
631 }
632 brush.setTexture(pixmap);
633 } else {
634 // Use the color
635 brush.setColor(brush.color().darker(dark));
636 }
637 return brush;
638 }
639
640 /*
641 Draws a rounded frame using the provided brush for 1, and adds 0.5 alpha
642 for 0.
643
644 0111111110
645 01 10
646 1 1
647 1 1
648 1 1
649 01 10
650 0111111110
651 */
qt_plastique_draw_frame(QPainter * painter,const QRect & rect,const QStyleOption * option,QFrame::Shadow shadow=QFrame::Plain)652 static void qt_plastique_draw_frame(QPainter *painter, const QRect &rect, const QStyleOption *option,
653 QFrame::Shadow shadow = QFrame::Plain)
654 {
655 QPen oldPen = painter->pen();
656 QBrush border;
657 QBrush corner;
658 QBrush innerTopLeft;
659 QBrush innerBottomRight;
660
661 if (shadow != QFrame::Plain && (option->state & QStyle::State_HasFocus)) {
662 border = option->palette.highlight();
663 qBrushSetAlphaF(&border, qreal(0.8));
664 corner = option->palette.highlight();
665 qBrushSetAlphaF(&corner, 0.5);
666 innerTopLeft = qBrushDark(option->palette.highlight(), 125);
667 innerBottomRight = option->palette.highlight();
668 qBrushSetAlphaF(&innerBottomRight, qreal(0.65));
669 } else {
670 border = option->palette.shadow();
671 qBrushSetAlphaF(&border, qreal(0.4));
672 corner = option->palette.shadow();
673 qBrushSetAlphaF(&corner, 0.25);
674 innerTopLeft = option->palette.shadow();
675 innerBottomRight = option->palette.shadow();
676 if (shadow == QFrame::Sunken) {
677 qBrushSetAlphaF(&innerTopLeft, qreal(0.23));
678 qBrushSetAlphaF(&innerBottomRight, qreal(0.075));
679 } else {
680 qBrushSetAlphaF(&innerTopLeft, qreal(0.075));
681 qBrushSetAlphaF(&innerBottomRight, qreal(0.23));
682 }
683 }
684
685 QLine lines[4];
686 QPoint points[8];
687
688 // Opaque corner lines
689 painter->setPen(QPen(border, 0));
690 lines[0] = QLine(rect.left() + 2, rect.top(), rect.right() - 2, rect.top());
691 lines[1] = QLine(rect.left() + 2, rect.bottom(), rect.right() - 2, rect.bottom());
692 lines[2] = QLine(rect.left(), rect.top() + 2, rect.left(), rect.bottom() - 2);
693 lines[3] = QLine(rect.right(), rect.top() + 2, rect.right(), rect.bottom() - 2);
694 painter->drawLines(lines, 4);
695
696 // Opaque corner dots
697 points[0] = QPoint(rect.left() + 1, rect.top() + 1);
698 points[1] = QPoint(rect.left() + 1, rect.bottom() - 1);
699 points[2] = QPoint(rect.right() - 1, rect.top() + 1);
700 points[3] = QPoint(rect.right() - 1, rect.bottom() - 1);
701 painter->drawPoints(points, 4);
702
703 // Shaded corner dots
704 painter->setPen(QPen(corner, 0));
705 points[0] = QPoint(rect.left(), rect.top() + 1);
706 points[1] = QPoint(rect.left(), rect.bottom() - 1);
707 points[2] = QPoint(rect.left() + 1, rect.top());
708 points[3] = QPoint(rect.left() + 1, rect.bottom());
709 points[4] = QPoint(rect.right(), rect.top() + 1);
710 points[5] = QPoint(rect.right(), rect.bottom() - 1);
711 points[6] = QPoint(rect.right() - 1, rect.top());
712 points[7] = QPoint(rect.right() - 1, rect.bottom());
713 painter->drawPoints(points, 8);
714
715 // Shadows
716 if (shadow != QFrame::Plain) {
717 painter->setPen(QPen(innerTopLeft, 0));
718 lines[0] = QLine(rect.left() + 2, rect.top() + 1, rect.right() - 2, rect.top() + 1);
719 lines[1] = QLine(rect.left() + 1, rect.top() + 2, rect.left() + 1, rect.bottom() - 2);
720 painter->drawLines(lines, 2);
721 painter->setPen(QPen(innerBottomRight, 0));
722 lines[0] = QLine(rect.left() + 2, rect.bottom() - 1, rect.right() - 2, rect.bottom() - 1);
723 lines[1] = QLine(rect.right() - 1, rect.top() + 2, rect.right() - 1, rect.bottom() - 2);
724 painter->drawLines(lines, 2);
725 }
726
727 painter->setPen(oldPen);
728 }
729
mergedColors(const QColor & colorA,const QColor & colorB,int factor=50)730 static QColor mergedColors(const QColor &colorA, const QColor &colorB, int factor = 50)
731 {
732 const int maxFactor = 100;
733 QColor tmp = colorA;
734 tmp.setRed((tmp.red() * factor) / maxFactor + (colorB.red() * (maxFactor - factor)) / maxFactor);
735 tmp.setGreen((tmp.green() * factor) / maxFactor + (colorB.green() * (maxFactor - factor)) / maxFactor);
736 tmp.setBlue((tmp.blue() * factor) / maxFactor + (colorB.blue() * (maxFactor - factor)) / maxFactor);
737 return tmp;
738 }
739
qt_plastique_draw_gradient(QPainter * painter,const QRect & rect,const QColor & gradientStart,const QColor & gradientStop)740 static void qt_plastique_draw_gradient(QPainter *painter, const QRect &rect, const QColor &gradientStart,
741 const QColor &gradientStop)
742 {
743 QString gradientName = QLatin1Literal("qplastique-g")
744 % HexString<int>(rect.width())
745 % HexString<int>(rect.height())
746 % HexString<QRgb>(gradientStart.rgba())
747 % HexString<QRgb>(gradientStop.rgba());
748
749 QPixmap cache;
750 QPainter *p = painter;
751 QRect r = rect;
752
753 bool doPixmapCache = painter->deviceTransform().isIdentity()
754 && painter->worldMatrix().isIdentity();
755 if (doPixmapCache && QPixmapCache::find(gradientName, cache)) {
756 painter->drawPixmap(rect, cache);
757 } else {
758 if (doPixmapCache) {
759 cache = QPixmap(rect.size());
760 cache.fill(Qt::transparent);
761 p = new QPainter(&cache);
762 r = QRect(0, 0, rect.width(), rect.height());
763 }
764
765 int x = r.center().x();
766 QLinearGradient gradient(x, r.top(), x, r.bottom());
767 gradient.setColorAt(0, gradientStart);
768 gradient.setColorAt(1, gradientStop);
769 p->fillRect(r, gradient);
770
771 if (doPixmapCache) {
772 p->end();
773 delete p;
774 painter->drawPixmap(rect, cache);
775 QPixmapCache::insert(gradientName, cache);
776 }
777 }
778 }
779
qt_plastique_drawFrame(QPainter * painter,const QStyleOption * option,const QWidget * widget)780 static void qt_plastique_drawFrame(QPainter *painter, const QStyleOption *option, const QWidget *widget)
781 {
782 QRect rect = option->rect;
783 QPen oldPen = painter->pen();
784
785 QColor borderColor = option->palette.background().color().darker(178);
786 QColor gradientStartColor = option->palette.button().color().lighter(104);
787 QColor gradientStopColor = option->palette.button().color().darker(105);
788 QColor alphaCornerColor;
789 if (widget) {
790 // ### backgroundrole/foregroundrole should be part of the style option
791 alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), borderColor);
792 } else {
793 alphaCornerColor = mergedColors(option->palette.background().color(), borderColor);
794 }
795
796 QLine lines[4];
797 QPoint points[8];
798
799 // outline / border
800 painter->setPen(borderColor);
801 lines[0] = QLine(rect.left() + 2, rect.top(), rect.right() - 2, rect.top());
802 lines[1] = QLine(rect.left() + 2, rect.bottom(), rect.right() - 2, rect.bottom());
803 lines[2] = QLine(rect.left(), rect.top() + 2, rect.left(), rect.bottom() - 2);
804 lines[3] = QLine(rect.right(), rect.top() + 2, rect.right(), rect.bottom() - 2);
805 painter->drawLines(lines, 4);
806
807 points[0] = QPoint(rect.left() + 1, rect.top() + 1);
808 points[1] = QPoint(rect.right() - 1, rect.top() + 1);
809 points[2] = QPoint(rect.left() + 1, rect.bottom() - 1);
810 points[3] = QPoint(rect.right() - 1, rect.bottom() - 1);
811 painter->drawPoints(points, 4);
812
813 painter->setPen(alphaCornerColor);
814
815 points[0] = QPoint(rect.left() + 1, rect.top());
816 points[1] = QPoint(rect.right() - 1, rect.top());
817 points[2] = QPoint(rect.left() + 1, rect.bottom());
818 points[3] = QPoint(rect.right() - 1, rect.bottom());
819 points[4] = QPoint(rect.left(), rect.top() + 1);
820 points[5] = QPoint(rect.right(), rect.top() + 1);
821 points[6] = QPoint(rect.left(), rect.bottom() - 1);
822 points[7] = QPoint(rect.right(), rect.bottom() - 1);
823 painter->drawPoints(points, 8);
824
825 // inner border
826 if ((option->state & QStyle::State_Sunken) || (option->state & QStyle::State_On))
827 painter->setPen(option->palette.button().color().darker(118));
828 else
829 painter->setPen(gradientStartColor);
830
831 lines[0] = QLine(rect.left() + 2, rect.top() + 1, rect.right() - 2, option->rect.top() + 1);
832 lines[1] = QLine(rect.left() + 1, rect.top() + 2, rect.left() + 1, option->rect.bottom() - 2);
833 painter->drawLines(lines, 2);
834
835 if ((option->state & QStyle::State_Sunken) || (option->state & QStyle::State_On))
836 painter->setPen(option->palette.button().color().darker(110));
837 else
838 painter->setPen(gradientStopColor.darker(102));
839
840 lines[0] = QLine(rect.left() + 2, rect.bottom() - 1, rect.right() - 2, rect.bottom() - 1);
841 lines[1] = QLine(rect.right() - 1, rect.top() + 2, rect.right() - 1, rect.bottom() - 2);
842 painter->drawLines(lines, 2);
843
844 painter->setPen(oldPen);
845 }
846
qt_plastique_drawShadedPanel(QPainter * painter,const QStyleOption * option,bool base,const QWidget * widget)847 static void qt_plastique_drawShadedPanel(QPainter *painter, const QStyleOption *option, bool base,
848 const QWidget *widget)
849 {
850 QRect rect = option->rect;
851 QPen oldPen = painter->pen();
852
853 QColor gradientStartColor = option->palette.button().color().lighter(104);
854 QColor gradientStopColor = option->palette.button().color().darker(105);
855
856 // gradient fill
857 if ((option->state & QStyle::State_Enabled) || !(option->state & QStyle::State_AutoRaise)) {
858 if ((option->state & QStyle::State_Sunken) || (option->state & QStyle::State_On)) {
859 qt_plastique_draw_gradient(painter, rect.adjusted(1, 1, -1, -1),
860 option->palette.button().color().darker(114),
861 option->palette.button().color().darker(106));
862 } else {
863 qt_plastique_draw_gradient(painter, rect.adjusted(1, 1, -1, -1),
864 base ? option->palette.background().color().lighter(105) : gradientStartColor,
865 base ? option->palette.background().color().darker(102) : gradientStopColor);
866 }
867 }
868
869 qt_plastique_drawFrame(painter, option, widget);
870
871 painter->setPen(oldPen);
872 }
873
qt_plastique_draw_mdibutton(QPainter * painter,const QStyleOptionTitleBar * option,const QRect & tmp,bool hover,bool sunken)874 static void qt_plastique_draw_mdibutton(QPainter *painter, const QStyleOptionTitleBar *option, const QRect &tmp, bool hover, bool sunken)
875 {
876 if (tmp.isNull())
877 return;
878 bool active = (option->titleBarState & QStyle::State_Active);
879
880 // ### use palette colors instead
881 QColor mdiButtonGradientStartColor;
882 QColor mdiButtonGradientStopColor;
883 if (active) {
884 mdiButtonGradientStartColor = QColor((hover || sunken) ? 0x7d8bb1 : 0x55689a);
885 mdiButtonGradientStopColor = QColor((hover || sunken) ? 0x939ebe : 0x7381ab);
886 } else {
887 mdiButtonGradientStartColor = QColor((hover || sunken) ? 0x9e9e9e : 0x818181);
888 mdiButtonGradientStopColor = QColor((hover || sunken) ? 0xababab : 0x929292);
889 }
890
891 qt_plastique_draw_gradient(painter, tmp.adjusted(1, 1, -1, -1),
892 mdiButtonGradientStartColor, mdiButtonGradientStopColor);
893
894 QColor mdiButtonBorderColor;
895 if (active) {
896 mdiButtonBorderColor = (hover || sunken) ? QColor(0x627097) : QColor(0x324577);
897 } else {
898 mdiButtonBorderColor = (hover || sunken) ? QColor(0x838383) : QColor(0x5e5e5e);
899 }
900 painter->setPen(QPen(mdiButtonBorderColor, 1));
901
902 const QLine lines[4] = {
903 QLine(tmp.left() + 2, tmp.top(), tmp.right() - 2, tmp.top()),
904 QLine(tmp.left() + 2, tmp.bottom(), tmp.right() - 2, tmp.bottom()),
905 QLine(tmp.left(), tmp.top() + 2, tmp.left(), tmp.bottom() - 2),
906 QLine(tmp.right(), tmp.top() + 2, tmp.right(), tmp.bottom() - 2) };
907 painter->drawLines(lines, 4);
908
909 const QPoint points[4] = {
910 QPoint(tmp.left() + 1, tmp.top() + 1),
911 QPoint(tmp.right() - 1, tmp.top() + 1),
912 QPoint(tmp.left() + 1, tmp.bottom() - 1),
913 QPoint(tmp.right() - 1, tmp.bottom() - 1) };
914 painter->drawPoints(points, 4);
915 }
916
917 #ifndef QT_NO_DOCKWIDGET
elliditide(const QString & text,const QFontMetrics & fontMetrics,const QRect & rect,int * textWidth=0)918 static QString elliditide(const QString &text, const QFontMetrics &fontMetrics, const QRect &rect, int *textWidth = 0)
919 {
920 // Chop and insert ellide into title if text is too wide
921 QString title = text;
922 int width = textWidth ? *textWidth : fontMetrics.width(text);
923 QString ellipsis = QLatin1String("...");
924 if (width > rect.width()) {
925 QString leftHalf = title.left(title.size() / 2);
926 QString rightHalf = title.mid(leftHalf.size() + 1);
927 while (!leftHalf.isEmpty() && !rightHalf.isEmpty()) {
928 leftHalf.chop(1);
929 int width = fontMetrics.width(leftHalf + ellipsis + rightHalf);
930 if (width < rect.width()) {
931 title = leftHalf + ellipsis + rightHalf;
932 width = width;
933 break;
934 }
935 rightHalf.remove(0, 1);
936 width = fontMetrics.width(leftHalf + ellipsis + rightHalf);
937 if (width < rect.width()) {
938 title = leftHalf + ellipsis + rightHalf;
939 width = width;
940 break;
941 }
942 }
943 }
944 if (textWidth)
945 *textWidth = width;
946 return title;
947 }
948 #endif
949
950 #if !defined(QT_NO_DOCKWIDGET) || !defined(QT_NO_SPLITTER)
qt_plastique_draw_handle(QPainter * painter,const QStyleOption * option,const QRect & rect,Qt::Orientation orientation,const QWidget * widget)951 static void qt_plastique_draw_handle(QPainter *painter, const QStyleOption *option,
952 const QRect &rect, Qt::Orientation orientation,
953 const QWidget *widget)
954 {
955 QColor borderColor = option->palette.background().color().darker(178);
956 QColor alphaCornerColor;
957 if (widget) {
958 // ### backgroundrole/foregroundrole should be part of the style option
959 alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), borderColor);
960 } else {
961 alphaCornerColor = mergedColors(option->palette.background().color(), borderColor);
962 }
963 QImage handle(qt_simple_toolbarhandle);
964 alphaCornerColor.setAlpha(170);
965 handle.setColor(1, alphaCornerColor.rgba());
966 handle.setColor(2, mergedColors(alphaCornerColor, option->palette.light().color()).rgba());
967 handle.setColor(3, option->palette.light().color().rgba());
968
969 const int spacing = 2;
970
971 if (orientation == Qt::Vertical) {
972 int nchunks = rect.width() / (handle.width() + spacing);
973 for (int i = 0; i < nchunks; ++i)
974 painter->drawImage(QPoint(rect.left() + i * (handle.width() + spacing), rect.top()), handle);
975 } else {
976 int nchunks = rect.height() / (handle.height() + spacing);
977 for (int i = 0; i < nchunks; ++i)
978 painter->drawImage(QPoint(rect.left(), rect.top() + i * (handle.height() + spacing)), handle);
979 }
980 }
981 #endif
982
983 class QPlastiqueStylePrivate : public QWindowsStylePrivate
984 {
985 Q_DECLARE_PUBLIC(QPlastiqueStyle)
986 public:
987 QPlastiqueStylePrivate();
988 virtual ~QPlastiqueStylePrivate();
989 void drawPartialFrame(QPainter *painter, const QStyleOptionComplex *option,
990 const QRect &rect, const QWidget *widget) const;
991
992 #ifndef QT_NO_PROGRESSBAR
993 QList<QProgressBar *> bars;
994 int progressBarAnimateTimer;
995 QElapsedTimer timer;
996 #endif
997 };
998
999 /*!
1000 \internal
1001 */
QPlastiqueStylePrivate()1002 QPlastiqueStylePrivate::QPlastiqueStylePrivate() :
1003 QWindowsStylePrivate()
1004 #ifndef QT_NO_PROGRESSBAR
1005 , progressBarAnimateTimer(0)
1006 #endif
1007 {
1008 }
1009
1010 /*!
1011 \internal
1012 */
~QPlastiqueStylePrivate()1013 QPlastiqueStylePrivate::~QPlastiqueStylePrivate()
1014 {
1015 }
1016
1017 /*!
1018 \class QPlastiqueStyle
1019 \brief The QPlastiqueStyle class provides a widget style similar to the
1020 Plastik style available in KDE.
1021
1022 The Plastique style provides a default look and feel for widgets on X11
1023 that closely resembles the Plastik style, introduced by Sandro Giessl in
1024 KDE 3.2.
1025
1026 \img qplastiquestyle.png
1027 \sa QWindowsXPStyle, QMacStyle, QWindowsStyle, QCDEStyle, QMotifStyle
1028 */
1029
1030 /*!
1031 Constructs a QPlastiqueStyle object.
1032 */
QPlastiqueStyle()1033 QPlastiqueStyle::QPlastiqueStyle()
1034 : QWindowsStyle(*new QPlastiqueStylePrivate)
1035 {
1036 setObjectName(QLatin1String("Plastique"));
1037 }
1038
1039 /*!
1040 Destructs the QPlastiqueStyle object.
1041 */
~QPlastiqueStyle()1042 QPlastiqueStyle::~QPlastiqueStyle()
1043 {
1044 }
1045
1046 /*
1047 Used by spin- and combo box.
1048 Draws a rounded frame around rect but omits the right hand edge
1049 */
drawPartialFrame(QPainter * painter,const QStyleOptionComplex * option,const QRect & rect,const QWidget * widget) const1050 void QPlastiqueStylePrivate::drawPartialFrame(QPainter *painter, const QStyleOptionComplex *option,
1051 const QRect &rect, const QWidget *widget) const
1052 {
1053 Q_Q(const QPlastiqueStyle);
1054 bool reverse = option->direction == Qt::RightToLeft;
1055 QStyleOptionFrame frameOpt;
1056 #ifndef QT_NO_LINEEDIT
1057 if (QLineEdit *lineedit = widget->findChild<QLineEdit *>())
1058 frameOpt.initFrom(lineedit);
1059 #else
1060 Q_UNUSED(widget)
1061 #endif // QT_NO_LINEEDIT
1062
1063 frameOpt.rect = rect;
1064 painter->save();
1065 frameOpt.rect.adjust(-blueFrameWidth + (reverse ? 1 : 0), -blueFrameWidth,
1066 blueFrameWidth + (reverse ? 0 : -1), blueFrameWidth);
1067 painter->setClipRect(frameOpt.rect);
1068 frameOpt.rect.adjust(reverse ? -2 : 0, 0, reverse ? 0 : 2, 0);
1069 frameOpt.lineWidth = q->pixelMetric(QStyle::PM_DefaultFrameWidth);
1070 frameOpt.midLineWidth = 0;
1071 frameOpt.state = option->state | QStyle::State_Sunken;
1072 frameOpt.palette = option->palette;
1073 q->drawPrimitive(QStyle::PE_PanelLineEdit, &frameOpt, painter, widget);
1074 painter->restore();
1075
1076 // Draw a two pixel highlight on the flat edge
1077 if (option->state & QStyle::State_HasFocus) {
1078 painter->setPen(QPen(option->palette.highlight(), 0));
1079 QBrush focusBorder = option->palette.highlight();
1080 qBrushSetAlphaF(&focusBorder, qreal(0.65));
1081 if (!reverse) {
1082 painter->drawLine(rect.topRight() + QPoint(1, -1),
1083 rect.bottomRight() + QPoint(1, 1));
1084 painter->setPen(QPen(focusBorder, 0));
1085 painter->drawLine(rect.topRight(),
1086 rect.bottomRight());
1087 }
1088 else {
1089 painter->drawLine(rect.topLeft() + QPoint(-1, -1),
1090 rect.bottomLeft() + QPoint(-1, 1));
1091 painter->setPen(QPen(focusBorder, 0));
1092 painter->drawLine(rect.topLeft(),
1093 rect.bottomLeft());
1094 }
1095 }
1096 }
1097
1098 /*!
1099 \reimp
1100 */
drawPrimitive(PrimitiveElement element,const QStyleOption * option,QPainter * painter,const QWidget * widget) const1101 void QPlastiqueStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option,
1102 QPainter *painter, const QWidget *widget) const
1103 {
1104 Q_ASSERT(option);
1105
1106 QColor borderColor = option->palette.background().color().darker(178);
1107 QColor alphaCornerColor;
1108 if (widget) {
1109 // ### backgroundrole/foregroundrole should be part of the style option
1110 alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), borderColor);
1111 } else {
1112 alphaCornerColor = mergedColors(option->palette.background().color(), borderColor);
1113 }
1114 QColor alphaTextColor = mergedColors(option->palette.background().color(), option->palette.text().color());
1115
1116 switch (element) {
1117 case PE_IndicatorButtonDropDown:
1118 proxy()->drawPrimitive(PE_PanelButtonTool, option, painter, widget);
1119 break;
1120 case PE_FrameDefaultButton: {
1121 if (!(option->state & QStyle::State_Enabled))
1122 break;
1123 painter->setPen(QPen(QColor(0, 0, 0, 127), 0));
1124 const QLine lines[4] = {
1125 QLine(option->rect.left() + 2, option->rect.top(),
1126 option->rect.right() - 2, option->rect.top()),
1127 QLine(option->rect.left() + 2, option->rect.bottom(),
1128 option->rect.right() - 2, option->rect.bottom()),
1129 QLine(option->rect.left(), option->rect.top() + 2,
1130 option->rect.left(), option->rect.bottom() - 2),
1131 QLine(option->rect.right(), option->rect.top() + 2,
1132 option->rect.right(), option->rect.bottom() - 2) };
1133 painter->drawLines(lines, 4);
1134
1135 QPoint points[8];
1136 points[0] = QPoint(option->rect.left() + 1, option->rect.top() + 1);
1137 points[1] = QPoint(option->rect.right() - 1, option->rect.top() + 1);
1138 points[2] = QPoint(option->rect.left() + 1, option->rect.bottom() - 1);
1139 points[3] = QPoint(option->rect.right() - 1, option->rect.bottom() - 1);
1140 painter->drawPoints(points, 4);
1141
1142 painter->setPen(QPen(QColor(0, 0, 0, 63), 0));
1143 points[0] = QPoint(option->rect.left() + 1, option->rect.top());
1144 points[1] = QPoint(option->rect.right() - 1, option->rect.top());
1145 points[2] = QPoint(option->rect.left(), option->rect.top() + 1);
1146 points[3] = QPoint(option->rect.right(), option->rect.top() + 1);
1147 points[4] = QPoint(option->rect.left() + 1, option->rect.bottom());
1148 points[5] = QPoint(option->rect.right() - 1, option->rect.bottom());
1149 points[6] = QPoint(option->rect.left(), option->rect.bottom() - 1);
1150 points[7] = QPoint(option->rect.right(), option->rect.bottom() - 1);
1151 painter->drawPoints(points, 8);
1152
1153 break;
1154 }
1155 #ifndef QT_NO_TABWIDGET
1156 case PE_FrameTabWidget:
1157 if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(option)) {
1158 if (twf->shape != QTabBar::RoundedNorth && twf->shape != QTabBar::RoundedWest &&
1159 twf->shape != QTabBar::RoundedSouth && twf->shape != QTabBar::RoundedEast) {
1160 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1161 break;
1162 }
1163
1164 int borderThickness = proxy()->pixelMetric(PM_TabBarBaseOverlap, twf, widget);
1165 bool reverse = (twf->direction == Qt::RightToLeft);
1166
1167 painter->save();
1168
1169 // Start by filling the contents of the tab widget frame (which is
1170 // actually a panel).
1171 painter->fillRect(option->rect.adjusted(1, 1, -1, -1), option->palette.window());
1172
1173 QRect tabBarRect;
1174 switch (twf->shape) {
1175 case QTabBar::RoundedNorth:
1176 if (reverse)
1177 tabBarRect = QRect(twf->rect.right() - twf->leftCornerWidgetSize.width() - twf->tabBarSize.width() + 1, twf->rect.top(), twf->tabBarSize.width(), borderThickness);
1178 else
1179 tabBarRect = QRect(twf->rect.left() + twf->leftCornerWidgetSize.width(), twf->rect.top(), twf->tabBarSize.width(), borderThickness);
1180 break ;
1181 case QTabBar::RoundedWest:
1182 tabBarRect = QRect(twf->rect.left(), twf->rect.top() + twf->leftCornerWidgetSize.height(), borderThickness, twf->tabBarSize.height());
1183 break ;
1184 case QTabBar::RoundedEast:
1185 tabBarRect = QRect(twf->rect.right() - borderThickness + 1, twf->rect.top() + twf->leftCornerWidgetSize.height(),
1186 borderThickness, twf->tabBarSize.height());
1187 break ;
1188 case QTabBar::RoundedSouth:
1189 if (reverse)
1190 tabBarRect = QRect(twf->rect.right() - twf->leftCornerWidgetSize.width() - twf->tabBarSize.width() + 1,
1191 twf->rect.bottom() - borderThickness + 1, twf->tabBarSize.width(), borderThickness);
1192 else
1193 tabBarRect = QRect(twf->rect.left() + twf->leftCornerWidgetSize.width(),
1194 twf->rect.bottom() - borderThickness + 1, twf->tabBarSize.width(), borderThickness);
1195 break ;
1196 default:
1197 break;
1198 }
1199
1200 QRegion region(twf->rect);
1201 region -= tabBarRect;
1202 painter->setClipRegion(region);
1203
1204 // Outer border
1205 QLine leftLine = QLine(twf->rect.topLeft() + QPoint(0, 2), twf->rect.bottomLeft() - QPoint(0, 2));
1206 QLine rightLine = QLine(twf->rect.topRight() + QPoint(0, 2), twf->rect.bottomRight() - QPoint(0, 2));
1207 QLine bottomLine = QLine(twf->rect.bottomLeft() + QPoint(2, 0), twf->rect.bottomRight() - QPoint(2, 0));
1208 QLine topLine = QLine(twf->rect.topLeft() + QPoint(2, 0), twf->rect.topRight() - QPoint(2, 0));
1209
1210 QBrush border = option->palette.shadow();
1211 qBrushSetAlphaF(&border, qreal(0.4));
1212 painter->setPen(QPen(border, 0));
1213
1214 QVarLengthArray<QLine, 4> lines;
1215 QVarLengthArray<QPoint, 8> points;
1216
1217 lines.append(topLine);
1218
1219 // Inner border
1220 QLine innerLeftLine = QLine(leftLine.p1() + QPoint(1, 0), leftLine.p2() + QPoint(1, 0));
1221 QLine innerRightLine = QLine(rightLine.p1() - QPoint(1, 0), rightLine.p2() - QPoint(1, 0));
1222 QLine innerBottomLine = QLine(bottomLine.p1() - QPoint(0, 1), bottomLine.p2() - QPoint(0, 1));
1223 QLine innerTopLine = QLine(topLine.p1() + QPoint(0, 1), topLine.p2() + QPoint(0, 1));
1224
1225 // Rounded Corner
1226 QPoint leftBottomOuterCorner = QPoint(innerLeftLine.p2() + QPoint(0, 1));
1227 QPoint leftBottomInnerCorner1 = QPoint(leftLine.p2() + QPoint(0, 1));
1228 QPoint leftBottomInnerCorner2 = QPoint(bottomLine.p1() - QPoint(1, 0));
1229 QPoint rightBottomOuterCorner = QPoint(innerRightLine.p2() + QPoint(0, 1));
1230 QPoint rightBottomInnerCorner1 = QPoint(rightLine.p2() + QPoint(0, 1));
1231 QPoint rightBottomInnerCorner2 = QPoint(bottomLine.p2() + QPoint(1, 0));
1232 QPoint rightTopOuterCorner = QPoint(innerRightLine.p1() - QPoint(0, 1));
1233 QPoint rightTopInnerCorner1 = QPoint(rightLine.p1() - QPoint(0, 1));
1234 QPoint rightTopInnerCorner2 = QPoint(topLine.p2() + QPoint(1, 0));
1235 QPoint leftTopOuterCorner = QPoint(innerLeftLine.p1() - QPoint(0, 1));
1236 QPoint leftTopInnerCorner1 = QPoint(leftLine.p1() - QPoint(0, 1));
1237 QPoint leftTopInnerCorner2 = QPoint(topLine.p1() - QPoint(1, 0));
1238
1239 lines.append(leftLine);
1240 lines.append(rightLine);
1241 lines.append(bottomLine);
1242
1243 painter->drawLines(lines.constData(), lines.size());
1244 lines.clear();
1245
1246 points.append(leftBottomOuterCorner);
1247 points.append(rightBottomOuterCorner);
1248 points.append(rightTopOuterCorner);
1249 points.append(leftTopOuterCorner);
1250
1251 painter->drawPoints(points.constData(), points.size());
1252 points.clear();
1253
1254 QBrush innerTopLeft = option->palette.shadow();
1255 qBrushSetAlphaF(&innerTopLeft, qreal(0.075));
1256 painter->setPen(QPen(innerTopLeft, 0));
1257
1258 lines.append(innerLeftLine);
1259 lines.append(innerTopLine);
1260 painter->drawLines(lines.constData(), lines.size());
1261 lines.clear();
1262
1263 QBrush innerBottomRight = option->palette.shadow();
1264 qBrushSetAlphaF(&innerBottomRight, qreal(0.23));
1265 painter->setPen(QPen(innerBottomRight, 0));
1266 lines.append(innerRightLine);
1267 lines.append(innerBottomLine);
1268 painter->drawLines(lines.constData(), lines.size());
1269 lines.clear();
1270
1271 QBrush corner = option->palette.shadow();
1272 qBrushSetAlphaF(&corner, 0.25);
1273 painter->setPen(QPen(corner, 0));
1274 points.append(leftBottomInnerCorner1);
1275 points.append(leftBottomInnerCorner2);
1276 points.append(rightBottomInnerCorner1);
1277 points.append(rightBottomInnerCorner2);
1278 points.append(rightTopInnerCorner1);
1279 points.append(rightTopInnerCorner2);
1280 points.append(leftTopInnerCorner1);
1281 points.append(leftTopInnerCorner2);
1282 painter->drawPoints(points.constData(), points.size());
1283 points.clear();
1284
1285 painter->restore();
1286 }
1287 break ;
1288 #endif // QT_NO_TABWIDGET
1289 #ifndef QT_NO_TABBAR
1290 case PE_FrameTabBarBase:
1291 if (const QStyleOptionTabBarBase *tbb = qstyleoption_cast<const QStyleOptionTabBarBase *>(option)) {
1292 if (tbb->shape != QTabBar::RoundedNorth && tbb->shape != QTabBar::RoundedWest &&
1293 tbb->shape != QTabBar::RoundedSouth && tbb->shape != QTabBar::RoundedEast) {
1294 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1295 break;
1296 }
1297
1298 painter->save();
1299
1300 QRegion region(tbb->rect);
1301 region -= tbb->tabBarRect;
1302 painter->setClipRegion(region);
1303
1304 QLine topLine = QLine(tbb->rect.bottomLeft() - QPoint(0, 1), tbb->rect.bottomRight() - QPoint(0, 1));
1305 QLine bottomLine = QLine(tbb->rect.bottomLeft(), tbb->rect.bottomRight());
1306
1307 QBrush border = option->palette.shadow();
1308 qBrushSetAlphaF(&border, qreal(0.4));
1309 QBrush innerTopLeft = option->palette.shadow();
1310 qBrushSetAlphaF(&innerTopLeft, qreal(0.075));
1311 QBrush innerBottomRight = option->palette.shadow();
1312 qBrushSetAlphaF(&innerBottomRight, qreal(0.23));
1313 QBrush corner = option->palette.shadow();
1314 qBrushSetAlphaF(&corner, 0.25);
1315
1316 if (tbb->shape == QTabBar::RoundedSouth)
1317 painter->setPen(QPen(corner, 0));
1318 else
1319 painter->setPen(QPen(border, 0));
1320 painter->drawLine(topLine);
1321
1322 if (tbb->shape != QTabBar::RoundedSouth)
1323 painter->setPen(QPen(innerTopLeft, 0));
1324 else
1325 painter->setPen(QPen(border, 0));
1326 painter->drawLine(bottomLine);
1327
1328 painter->restore();
1329 }
1330 break ;
1331 #endif // QT_NO_TABBAR
1332 #ifndef QT_NO_GROUPBOX
1333 case PE_FrameGroupBox:
1334 if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
1335 QStyleOptionFrameV2 frameV2(*frame);
1336 if (frameV2.features & QStyleOptionFrameV2::Flat) {
1337 QPen oldPen = painter->pen();
1338 painter->setPen(borderColor);
1339 painter->drawLine(frameV2.rect.topLeft(), frameV2.rect.topRight());
1340 painter->setPen(oldPen);
1341 } else {
1342 frameV2.state &= ~(State_Sunken | State_HasFocus);
1343 proxy()->drawPrimitive(PE_Frame, &frameV2, painter, widget);
1344 }
1345 }
1346 break;
1347 #endif // QT_NO_GROUPBOX
1348 case PE_Frame: {
1349 QFrame::Shadow shadow = QFrame::Plain;
1350 if (option->state & State_Sunken)
1351 shadow = QFrame::Sunken;
1352 else if (option->state & State_Raised)
1353 shadow = QFrame::Raised;
1354 qt_plastique_draw_frame(painter, option->rect, option, shadow);
1355 break;
1356 }
1357 #ifndef QT_NO_LINEEDIT
1358 case PE_FrameLineEdit:
1359 qt_plastique_draw_frame(painter, option->rect, option, QFrame::Sunken);
1360 break;
1361 case PE_PanelLineEdit:
1362 if (const QStyleOptionFrame *lineEdit = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
1363 // Panel of a line edit inside combo box or spin box is drawn in CC_ComboBox and CC_SpinBox
1364 if (widget) {
1365 #ifndef QT_NO_SPINBOX
1366 // Spinbox doesn't need a separate palette for the lineedit
1367 if (qobject_cast<const QAbstractSpinBox *>(widget->parentWidget()))
1368 break;
1369 #endif
1370 }
1371
1372 painter->save();
1373
1374 // Fill the line edit insides
1375 QRect filledRect = lineEdit->rect.adjusted(1, 1, -1, -1);
1376 QBrush baseBrush = qMapBrushToRect(lineEdit->palette.base(), filledRect);
1377 painter->setBrushOrigin(filledRect.topLeft());
1378 painter->fillRect(filledRect.adjusted(1, 1, -1, -1), baseBrush);
1379
1380 painter->setPen(QPen(baseBrush, 0));
1381 const QLine lines[4] = {
1382 QLine(filledRect.left(), filledRect.top() + 1,
1383 filledRect.left(), filledRect.bottom() - 1),
1384 QLine(filledRect.right(), filledRect.top() + 1,
1385 filledRect.right(), filledRect.bottom() - 1),
1386 QLine(filledRect.left() + 1, filledRect.top(),
1387 filledRect.right() - 1, filledRect.top()),
1388 QLine(filledRect.left() + 1, filledRect.bottom(),
1389 filledRect.right() - 1, filledRect.bottom()) };
1390 painter->drawLines(lines, 4);
1391
1392 if (lineEdit->lineWidth != 0)
1393 qt_plastique_draw_frame(painter, option->rect, option, QFrame::Sunken);
1394
1395 painter->restore();
1396 break;
1397 }
1398 #endif // QT_NO_LINEEDIT
1399 case PE_FrameDockWidget:
1400 case PE_FrameMenu:
1401 case PE_FrameStatusBarItem: {
1402 // Draws the frame around a popup menu.
1403 QPen oldPen = painter->pen();
1404 painter->setPen(borderColor);
1405 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
1406 painter->setPen(alphaCornerColor);
1407 const QPoint points[4] = {
1408 QPoint(option->rect.topLeft()),
1409 QPoint(option->rect.topRight()),
1410 QPoint(option->rect.bottomLeft()),
1411 QPoint(option->rect.bottomRight()) };
1412 painter->drawPoints(points, 4);
1413 painter->setPen(oldPen);
1414 break;
1415 }
1416 #ifdef QT3_SUPPORT
1417 case PE_Q3DockWindowSeparator: {
1418 QPen oldPen = painter->pen();
1419 painter->setPen(alphaCornerColor);
1420 QRect rect = option->rect;
1421 if (option->state & State_Horizontal) {
1422 painter->drawLine(rect.right(), rect.top() + 2, rect.right(), rect.bottom() - 1);
1423 } else {
1424 painter->drawLine(rect.left() + 2, rect.bottom(), rect.right() - 1, rect.bottom());
1425 }
1426 painter->setPen(oldPen);
1427 break;
1428 }
1429 case PE_Q3Separator: {
1430 QPen oldPen = painter->pen();
1431 painter->setPen(alphaCornerColor);
1432 if ((option->state & State_Horizontal) == 0)
1433 painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
1434 else
1435 painter->drawLine(option->rect.topRight(), option->rect.bottomRight());
1436 painter->setPen(option->palette.background().color().lighter(104));
1437 if ((option->state & State_Horizontal) == 0)
1438 painter->drawLine(option->rect.topLeft(), option->rect.topRight());
1439 else
1440 painter->drawLine(option->rect.topLeft(), option->rect.bottomLeft());
1441 painter->setPen(oldPen);
1442 break;
1443 }
1444 #endif // QT3_SUPPORT
1445 #ifndef QT_NO_MAINWINDOW
1446 case PE_PanelMenuBar:
1447 if ((widget && qobject_cast<const QMainWindow *>(widget->parentWidget()))
1448 #ifdef QT3_SUPPORT
1449 || (widget && widget->parentWidget() && widget->parentWidget()->inherits("Q3MainWindow"))
1450 #endif
1451 ) {
1452 // Draws the light line above and the dark line below menu bars and
1453 // tool bars.
1454 QPen oldPen = painter->pen();
1455 if (element == PE_PanelMenuBar || (option->state & State_Horizontal)) {
1456 painter->setPen(alphaCornerColor);
1457 painter->drawLine(option->rect.left(), option->rect.bottom(),
1458 option->rect.right(), option->rect.bottom());
1459 painter->setPen(option->palette.background().color().lighter(104));
1460 painter->drawLine(option->rect.left(), option->rect.top(),
1461 option->rect.right(), option->rect.top());
1462 } else {
1463 painter->setPen(option->palette.background().color().lighter(104));
1464 painter->drawLine(option->rect.left(), option->rect.top(),
1465 option->rect.left(), option->rect.bottom());
1466 painter->setPen(alphaCornerColor);
1467 painter->drawLine(option->rect.right(), option->rect.top(),
1468 option->rect.right(), option->rect.bottom());
1469 }
1470 painter->setPen(oldPen);
1471 }
1472 break;
1473 #endif // QT_NO_MAINWINDOW
1474 case PE_IndicatorHeaderArrow: {
1475 bool usedAntialiasing = painter->renderHints() & QPainter::Antialiasing;
1476 if (!usedAntialiasing)
1477 painter->setRenderHint(QPainter::Antialiasing);
1478 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1479 if (!usedAntialiasing)
1480 painter->setRenderHint(QPainter::Antialiasing, false);
1481 break;
1482 }
1483 case PE_PanelButtonTool:
1484 // Draws a tool button (f.ex., in QToolBar and QTabBar)
1485 if ((option->state & State_Enabled || option->state & State_On) || !(option->state & State_AutoRaise))
1486 qt_plastique_drawShadedPanel(painter, option, true, widget);
1487 break;
1488 #ifndef QT_NO_TOOLBAR
1489 case PE_IndicatorToolBarHandle: {
1490 QPixmap cache;
1491 QRect rect = option->rect;
1492 #ifdef QT3_SUPPORT
1493 if (widget && widget->inherits("Q3DockWindowHandle") && widget->parentWidget()->inherits("Q3DockWindow")) {
1494 if (!(option->state & State_Horizontal))
1495 rect.adjust(2, 0, -2, 0);
1496 }
1497 #endif
1498 QString pixmapName = QStyleHelper::uniqueName(QLatin1String("toolbarhandle"), option, rect.size());
1499 if (!QPixmapCache::find(pixmapName, cache)) {
1500 cache = QPixmap(rect.size());
1501 cache.fill(Qt::transparent);
1502 QPainter cachePainter(&cache);
1503 QRect cacheRect(QPoint(0, 0), rect.size());
1504 if (widget)
1505 cachePainter.fillRect(cacheRect, option->palette.brush(widget->backgroundRole()));
1506 else
1507 cachePainter.fillRect(cacheRect, option->palette.background());
1508
1509 QImage handle(qt_toolbarhandle);
1510 alphaCornerColor.setAlpha(170);
1511 handle.setColor(1, alphaCornerColor.rgba());
1512 handle.setColor(2, mergedColors(alphaCornerColor, option->palette.light().color()).rgba());
1513 handle.setColor(3, option->palette.light().color().rgba());
1514
1515 if (option->state & State_Horizontal) {
1516 int nchunks = cacheRect.height() / handle.height();
1517 int indent = (cacheRect.height() - (nchunks * handle.height())) / 2;
1518 for (int i = 0; i < nchunks; ++i)
1519 cachePainter.drawImage(QPoint(cacheRect.left() + 3, cacheRect.top() + indent + i * handle.height()),
1520 handle);
1521 } else {
1522 int nchunks = cacheRect.width() / handle.width();
1523 int indent = (cacheRect.width() - (nchunks * handle.width())) / 2;
1524 for (int i = 0; i < nchunks; ++i)
1525 cachePainter.drawImage(QPoint(cacheRect.left() + indent + i * handle.width(), cacheRect.top() + 3),
1526 handle);
1527 }
1528 cachePainter.end();
1529 QPixmapCache::insert(pixmapName, cache);
1530 }
1531 painter->drawPixmap(rect.topLeft(), cache);
1532 break;
1533 }
1534 case PE_IndicatorToolBarSeparator: {
1535 QPen oldPen = painter->pen();
1536 painter->setPen(alphaCornerColor);
1537 if (option->state & State_Horizontal) {
1538 painter->drawLine(option->rect.left(), option->rect.top() + 1, option->rect.left(), option->rect.bottom() - 2);
1539 painter->setPen(option->palette.base().color());
1540 painter->drawLine(option->rect.right(), option->rect.top() + 1, option->rect.right(), option->rect.bottom() - 2);
1541 } else {
1542 painter->drawLine(option->rect.left() + 1, option->rect.top(), option->rect.right() - 2, option->rect.top());
1543 painter->setPen(option->palette.base().color());
1544 painter->drawLine(option->rect.left() + 1, option->rect.bottom(), option->rect.right() - 2, option->rect.bottom());
1545 }
1546 painter->setPen(oldPen);
1547 break;
1548 }
1549 #endif // QT_NO_TOOLBAR
1550 case PE_PanelButtonCommand:
1551 if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
1552 bool sunken = (button->state & State_Sunken) || (button->state & State_On);
1553 if ((button->features & QStyleOptionButton::Flat) && !sunken)
1554 break;
1555
1556 bool defaultButton = (button->features & (QStyleOptionButton::DefaultButton
1557 | QStyleOptionButton::AutoDefaultButton));
1558
1559 BEGIN_STYLE_PIXMAPCACHE(QString::fromLatin1("pushbutton-%1").arg(defaultButton))
1560
1561 QPen oldPen = p->pen();
1562 bool hover = (button->state & State_Enabled) && (button->state & State_MouseOver);
1563
1564 // Give the painter a different brush origin for sunken buttons
1565 if (sunken) {
1566 // ### No such function
1567 // p->setPenOrigin(rect.left() + 1, rect.top() + 1);
1568 p->setBrushOrigin(rect.left() + 1, rect.top() + 1);
1569 }
1570
1571 // Draw border
1572 qt_plastique_draw_frame(p, rect, option);
1573
1574 // Fill the panel
1575 QRectF fillRect = rect.adjusted(2, 2, -2, -2);
1576
1577 // Button colors
1578 QBrush alphaCornerBrush = qMapBrushToRect(qBrushDark(option->palette.button(), 165), rect);
1579 qBrushSetAlphaF(&alphaCornerBrush, 0.5);
1580 QBrush buttonGradientBrush;
1581 QBrush leftLineGradientBrush;
1582 QBrush rightLineGradientBrush;
1583 QBrush sunkenButtonGradientBrush;
1584 QBrush sunkenLeftLineGradientBrush;
1585 QBrush sunkenRightLineGradientBrush;
1586 QBrush buttonBrush = qMapBrushToRect(option->palette.button(), rect);
1587 if (buttonBrush.gradient() || !buttonBrush.texture().isNull()) {
1588 buttonGradientBrush = buttonBrush;
1589 sunkenButtonGradientBrush = qBrushDark(buttonBrush, 108);
1590 leftLineGradientBrush = qBrushLight(buttonBrush, 105);
1591 rightLineGradientBrush = qBrushDark(buttonBrush, 105);
1592 sunkenLeftLineGradientBrush = qBrushDark(buttonBrush, 110);
1593 sunkenRightLineGradientBrush = qBrushDark(buttonBrush, 106);
1594 } else {
1595 // Generate gradients
1596 QLinearGradient buttonGradient(rect.topLeft(), rect.bottomLeft());
1597 if (hover) {
1598 buttonGradient.setColorAt(0.0, mergedColors(option->palette.highlight().color(),
1599 buttonBrush.color().lighter(104), 6));
1600 buttonGradient.setColorAt(1.0, mergedColors(option->palette.highlight().color(),
1601 buttonBrush.color().darker(110), 6));
1602 } else {
1603 buttonGradient.setColorAt(0.0, buttonBrush.color().lighter(104));
1604 buttonGradient.setColorAt(1.0, buttonBrush.color().darker(110));
1605 }
1606 buttonGradientBrush = QBrush(buttonGradient);
1607
1608 QLinearGradient buttonGradient2(rect.topLeft(), rect.bottomLeft());
1609 buttonGradient2.setColorAt(0.0, buttonBrush.color().darker(113));
1610 buttonGradient2.setColorAt(1.0, buttonBrush.color().darker(103));
1611 sunkenButtonGradientBrush = QBrush(buttonGradient2);
1612
1613 QLinearGradient buttonGradient3(rect.topLeft(), rect.bottomLeft());
1614 buttonGradient3.setColorAt(0.0, buttonBrush.color().lighter(105));
1615 buttonGradient3.setColorAt(1.0, buttonBrush.color());
1616 leftLineGradientBrush = QBrush(buttonGradient3);
1617
1618 QLinearGradient buttonGradient4(rect.topLeft(), rect.bottomLeft());
1619 buttonGradient4.setColorAt(0.0, buttonBrush.color());
1620 buttonGradient4.setColorAt(1.0, buttonBrush.color().darker(110));
1621 rightLineGradientBrush = QBrush(buttonGradient4);
1622
1623 QLinearGradient buttonGradient5(rect.topLeft(), rect.bottomLeft());
1624 buttonGradient5.setColorAt(0.0, buttonBrush.color().darker(113));
1625 buttonGradient5.setColorAt(1.0, buttonBrush.color().darker(107));
1626 sunkenLeftLineGradientBrush = QBrush(buttonGradient5);
1627
1628 QLinearGradient buttonGradient6(rect.topLeft(), rect.bottomLeft());
1629 buttonGradient6.setColorAt(0.0, buttonBrush.color().darker(108));
1630 buttonGradient6.setColorAt(1.0, buttonBrush.color().darker(103));
1631 sunkenRightLineGradientBrush = QBrush(buttonGradient6);
1632 }
1633
1634 // Main fill
1635 p->fillRect(fillRect,
1636 qMapBrushToRect(sunken ? sunkenButtonGradientBrush
1637 : buttonGradientBrush, rect));
1638
1639 // Top line
1640 p->setPen(QPen(qBrushLight(qMapBrushToRect(sunken ? sunkenButtonGradientBrush
1641 : buttonGradientBrush, rect), 105), 0));
1642 p->drawLine(QPointF(rect.left() + 2, rect.top() + 1),
1643 QPointF(rect.right() - 2, rect.top() + 1));
1644
1645 // Bottom line
1646 p->setPen(QPen(qBrushDark(qMapBrushToRect(sunken ? sunkenButtonGradientBrush
1647 : buttonGradientBrush, rect), 105), 0));
1648 p->drawLine(QPointF(rect.left() + 2, rect.bottom() - 1),
1649 QPointF(rect.right() - 2, rect.bottom() - 1));
1650
1651 // Left line
1652 p->setPen(QPen(qMapBrushToRect(sunken ? sunkenLeftLineGradientBrush
1653 : leftLineGradientBrush, rect), 1));
1654 p->drawLine(QPointF(rect.left() + 1, rect.top() + 2),
1655 QPointF(rect.left() + 1, rect.bottom() - 2));
1656
1657 // Right line
1658 p->setPen(QPen(qMapBrushToRect(sunken ? sunkenRightLineGradientBrush
1659 : rightLineGradientBrush, rect), 1));
1660 p->drawLine(QPointF(rect.right() - 1, rect.top() + 2),
1661 QPointF(rect.right() - 1, rect.bottom() - 2));
1662
1663 // Hovering
1664 if (hover && !sunken) {
1665 QBrush hover = qMapBrushToRect(option->palette.highlight(), rect);
1666 QBrush hoverOuter = hover;
1667 qBrushSetAlphaF(&hoverOuter, qreal(0.7));
1668
1669 QLine lines[2];
1670
1671 p->setPen(QPen(hoverOuter, 0));
1672 lines[0] = QLine(rect.left() + 1, rect.top() + 1, rect.right() - 1, rect.top() + 1);
1673 lines[1] = QLine(rect.left() + 1, rect.bottom() - 1, rect.right() - 1, rect.bottom() - 1);
1674 p->drawLines(lines, 2);
1675
1676 QBrush hoverInner = hover;
1677 qBrushSetAlphaF(&hoverInner, qreal(0.45));
1678 p->setPen(QPen(hoverInner, 0));
1679 lines[0] = QLine(rect.left() + 1, rect.top() + 2, rect.right() - 1, rect.top() + 2);
1680 lines[1] = QLine(rect.left() + 1, rect.bottom() - 2, rect.right() - 1, rect.bottom() - 2);
1681 p->drawLines(lines, 2);
1682
1683 QBrush hoverSide = hover;
1684 qBrushSetAlphaF(&hoverSide, qreal(0.075));
1685 p->setPen(QPen(hoverSide, 0));
1686 lines[0] = QLine(rect.left() + 1, rect.top() + 2, rect.left() + 1, rect.bottom() - 2);
1687 lines[1] = QLine(rect.right() - 1, rect.top() + 2, rect.right() - 1, rect.bottom() - 2);
1688 p->drawLines(lines, 2);
1689 }
1690
1691 p->setPen(oldPen);
1692
1693 END_STYLE_PIXMAPCACHE
1694 }
1695 break;
1696 case PE_IndicatorCheckBox:
1697 if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
1698 BEGIN_STYLE_PIXMAPCACHE(QLatin1String("checkbox"))
1699
1700 p->save();
1701
1702 // Outline
1703 QBrush border = option->palette.shadow();
1704 qBrushSetAlphaF(&border, qreal(0.4));
1705 p->setPen(QPen(border, 0));
1706 const QLine lines[4] = {
1707 QLine(rect.left() + 1, rect.top(), rect.right() - 1, rect.top()),
1708 QLine(rect.left() + 1, rect.bottom(), rect.right() - 1, rect.bottom()),
1709 QLine(rect.left(), rect.top() + 1, rect.left(), rect.bottom() - 1),
1710 QLine(rect.right(), rect.top() + 1, rect.right(), rect.bottom() - 1) };
1711 p->drawLines(lines, 4);
1712
1713 QBrush corner = option->palette.shadow();
1714 qBrushSetAlphaF(&corner, qreal(0.2));
1715 p->setPen(QPen(corner, 0));
1716 const QPoint points[4] = {
1717 rect.topLeft(), rect.topRight(),
1718 rect.bottomLeft(), rect.bottomRight() };
1719 p->drawPoints(points, 4);
1720
1721 // Fill
1722 QBrush baseBrush = qMapBrushToRect(button->palette.base(), rect);
1723 if (!baseBrush.gradient() && baseBrush.texture().isNull()) {
1724 QLinearGradient gradient(rect.center().x(), rect.top(), rect.center().x(), rect.bottom());
1725 gradient.setColorAt(0, baseBrush.color());
1726 gradient.setColorAt(1, baseBrush.color().darker(105));
1727 baseBrush = gradient;
1728 }
1729 p->fillRect(rect.adjusted(1, 1, -1, -1), baseBrush);
1730
1731 // Hover
1732 if ((button->state & State_Enabled) && (button->state & State_MouseOver)) {
1733 QBrush pen = qMapBrushToRect(button->palette.highlight(), rect);
1734 qBrushSetAlphaF(&pen, qreal(0.8));
1735 p->setPen(QPen(pen, 0));
1736 p->drawRect(rect.adjusted(1, 1, -2, -2));
1737 qBrushSetAlphaF(&pen, 0.5);
1738 p->setPen(QPen(pen, 0));
1739 p->drawRect(rect.adjusted(2, 2, -3, -3));
1740
1741 qBrushSetAlphaF(&pen, qreal(0.2));
1742 p->setBrush(pen);
1743 p->drawRect(rect.adjusted(2, 2, -3, -3));
1744 }
1745
1746 // Indicator
1747 bool on = button->state & State_On;
1748 bool sunken = button->state & State_Sunken;
1749 bool unchanged = button->state & State_NoChange;
1750 bool enabled = button->state & State_Enabled;
1751 if (on || (enabled && sunken) || unchanged) {
1752 p->setRenderHint(QPainter::Antialiasing);
1753 QBrush pointBrush = qMapBrushToRect(button->palette.text(), rect);
1754 if (sunken)
1755 qBrushSetAlphaF(&pointBrush, qreal(0.5));
1756 else if (unchanged)
1757 qBrushSetAlphaF(&pointBrush, qreal(0.3));
1758 p->setPen(QPen(pointBrush, 3));
1759 const QLine lines[2] = {
1760 QLine(rect.left() + 4, rect.top() + 4, rect.right() - 3, rect.bottom() - 3),
1761 QLine(rect.right() - 3, rect.top() + 4, rect.left() + 4, rect.bottom() - 3) };
1762 p->drawLines(lines, 2);
1763 }
1764
1765 p->restore();
1766 END_STYLE_PIXMAPCACHE
1767 }
1768 break;
1769 case PE_IndicatorRadioButton:
1770 if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
1771 BEGIN_STYLE_PIXMAPCACHE(QLatin1String("radiobutton"))
1772
1773 p->save();
1774 p->setRenderHint(QPainter::Antialiasing);
1775
1776 // The the filled ellipse
1777 QBrush border = qMapBrushToRect(option->palette.shadow(), rect);
1778 qBrushSetAlphaF(&border, qreal(0.51));
1779 p->setPen(QPen(border, 0));
1780
1781 QBrush baseBrush = qMapBrushToRect(button->palette.base(), rect);
1782 if (!baseBrush.gradient() && baseBrush.texture().isNull()) {
1783 QLinearGradient gradient(rect.center().x(), rect.top(), rect.center().x(), rect.bottom());
1784 gradient.setColorAt(0, baseBrush.color());
1785 gradient.setColorAt(1, baseBrush.color().darker(105));
1786 baseBrush = gradient;
1787 }
1788 p->setBrush(baseBrush);
1789 p->drawEllipse(QRectF(rect).adjusted(1, 1, -1, -1));
1790
1791 // Hover
1792 if ((button->state & State_Enabled) && (button->state & State_MouseOver)) {
1793 QBrush pen = qMapBrushToRect(button->palette.highlight(), rect);
1794 qBrushSetAlphaF(&pen, qreal(0.8));
1795 p->setPen(QPen(pen, 0));
1796 qBrushSetAlphaF(&pen, qreal(0.2));
1797 p->setBrush(pen);
1798 p->drawEllipse(QRectF(rect).adjusted(2, 2, -2, -2));
1799 }
1800
1801 // Indicator
1802 bool on = button->state & State_On;
1803 bool sunken = button->state & State_Sunken;
1804 bool enabled = button->state & State_Enabled;
1805 if (on || (enabled && sunken)) {
1806 p->setPen(Qt::NoPen);
1807 QBrush pointBrush = qMapBrushToRect(button->palette.text(), rect);
1808 if (sunken)
1809 qBrushSetAlphaF(&pointBrush, 0.5);
1810 p->setBrush(pointBrush);
1811 p->drawEllipse(QRectF(rect).adjusted(3, 3, -3, -3));
1812 }
1813
1814 p->restore();
1815 END_STYLE_PIXMAPCACHE
1816 }
1817 break;
1818 #ifndef QT_NO_DOCKWIDGET
1819 case PE_IndicatorDockWidgetResizeHandle:
1820 if ((option->state & State_Enabled) && (option->state & State_MouseOver))
1821 painter->fillRect(option->rect, QColor(255, 255, 255, 128));
1822 if (option->state & State_Horizontal) {
1823 int width = option->rect.width() / 3;
1824 QRect rect(option->rect.center().x() - width / 2,
1825 option->rect.top() + (option->rect.height() / 2) - 1, width, 3);
1826 qt_plastique_draw_handle(painter, option, rect, Qt::Vertical, widget);
1827 } else {
1828 int height = option->rect.height() / 3;
1829 QRect rect(option->rect.left() + (option->rect.width() / 2 - 1),
1830 option->rect.center().y() - height / 2, 3, height);
1831 qt_plastique_draw_handle(painter, option, rect, Qt::Horizontal, widget);
1832 }
1833 break;
1834 #endif // QT_NO_DOCKWIDGET
1835 case PE_IndicatorViewItemCheck: {
1836 QStyleOptionButton button;
1837 button.QStyleOption::operator=(*option);
1838 button.state &= ~State_MouseOver;
1839 proxy()->drawPrimitive(PE_IndicatorCheckBox, &button, painter, widget);
1840 break;
1841 }
1842 case PE_FrameWindow: {
1843 painter->save();
1844 bool active = (option->state & State_Active);
1845 int titleBarStop = option->rect.top() + proxy()->pixelMetric(PM_TitleBarHeight, option, widget);
1846
1847 QPalette palette = option->palette;
1848 if (!active)
1849 palette.setCurrentColorGroup(QPalette::Disabled);
1850
1851 // Frame and rounded corners
1852 painter->setPen(mergedColors(palette.highlight().color(), Qt::black, 50));
1853
1854 QLine lines[3];
1855 QPoint points[4];
1856
1857 // bottom border line
1858 lines[0] = QLine(option->rect.left() + 1, option->rect.bottom(), option->rect.right() - 1, option->rect.bottom());
1859
1860 // bottom left and right side border lines
1861 lines[1] = QLine(option->rect.left(), titleBarStop, option->rect.left(), option->rect.bottom() - 1);
1862 lines[2] = QLine(option->rect.right(), titleBarStop, option->rect.right(), option->rect.bottom() - 1);
1863 painter->drawLines(lines, 3);
1864 points[0] = QPoint(option->rect.left() + 1, option->rect.bottom() - 1);
1865 points[1] = QPoint(option->rect.right() - 1, option->rect.bottom() - 1);
1866 painter->drawPoints(points, 2);
1867
1868 #ifdef QT3_SUPPORT
1869 if (widget && widget->inherits("Q3DockWindow")) {
1870 // also draw the frame on the title bar
1871 lines[0] = QLine(option->rect.left() + 1, option->rect.top(),
1872 option->rect.right() - 1, option->rect.top());
1873 lines[1] = QLine(option->rect.left(), option->rect.top() + 1,
1874 option->rect.left(), titleBarStop);
1875 lines[2] = QLine(option->rect.right(), option->rect.top() + 1,
1876 option->rect.right(), titleBarStop);
1877 painter->drawLines(lines, 3);
1878 }
1879 #endif
1880
1881 // alpha corners
1882 painter->setPen(mergedColors(palette.highlight().color(), palette.background().color(), 55));
1883 points[0] = QPoint(option->rect.left() + 2, option->rect.bottom() - 1);
1884 points[1] = QPoint(option->rect.left() + 1, option->rect.bottom() - 2);
1885 points[2] = QPoint(option->rect.right() - 2, option->rect.bottom() - 1);
1886 points[3] = QPoint(option->rect.right() - 1, option->rect.bottom() - 2);
1887 painter->drawPoints(points, 4);
1888
1889 #ifdef QT3_SUPPORT
1890 if (widget && widget->inherits("Q3DockWindow")) {
1891 // also draw the frame on the title bar
1892 points[0] = option->rect.topLeft();
1893 points[1] = option->rect.topRight();
1894 painter->drawPoints(points, 2);
1895 }
1896 #endif
1897
1898 // upper and lower left inner
1899 painter->setPen(active ? mergedColors(palette.highlight().color(), palette.background().color()) : palette.background().color().darker(120));
1900 painter->drawLine(option->rect.left() + 1, titleBarStop, option->rect.left() + 1, option->rect.bottom() - 2);
1901
1902 #ifdef QT3_SUPPORT
1903 if (widget && widget->inherits("Q3DockWindow")) {
1904 // also draw the frame on the title bar
1905 lines[0] = QLine(option->rect.left() + 1, option->rect.top() + 1,
1906 option->rect.left() + 1, titleBarStop);
1907 lines[1] = QLine(option->rect.right() - 1, option->rect.top() + 1,
1908 option->rect.right() - 1, titleBarStop);
1909 lines[2] = QLine(option->rect.left() + 1, option->rect.top() + 1,
1910 option->rect.right() - 1, option->rect.top() + 1);
1911 painter->drawLines(lines, 3);
1912 }
1913 #endif
1914
1915 painter->setPen(active ? mergedColors(palette.highlight().color(), palette.background().color(), 57) : palette.background().color().darker(130));
1916 lines[0] = QLine(option->rect.right() - 1, titleBarStop, option->rect.right() - 1, option->rect.bottom() - 2);
1917 lines[1] = QLine(option->rect.left() + 1, option->rect.bottom() - 1, option->rect.right() - 1, option->rect.bottom() - 1);
1918 painter->drawLines(lines, 2);
1919
1920 painter->restore();
1921 }
1922 break;
1923 case PE_IndicatorBranch: {
1924 int mid_h = option->rect.x() + option->rect.width() / 2;
1925 int mid_v = option->rect.y() + option->rect.height() / 2;
1926 int bef_h = mid_h;
1927 int bef_v = mid_v;
1928 int aft_h = mid_h;
1929 int aft_v = mid_v;
1930 QBrush brush(option->palette.dark().color(), Qt::Dense4Pattern);
1931 if (option->state & State_Item) {
1932 if (option->direction == Qt::RightToLeft)
1933 painter->fillRect(option->rect.left(), mid_v, bef_h - option->rect.left(), 1, brush);
1934 else
1935 painter->fillRect(aft_h, mid_v, option->rect.right() - aft_h + 1, 1, brush);
1936 }
1937 if (option->state & State_Sibling)
1938 painter->fillRect(mid_h, aft_v, 1, option->rect.bottom() - aft_v + 1, brush);
1939 if (option->state & (State_Open | State_Children | State_Item | State_Sibling))
1940 painter->fillRect(mid_h, option->rect.y(), 1, bef_v - option->rect.y(), brush);
1941
1942 if (option->state & State_Children) {
1943 painter->save();
1944 QPoint center = option->rect.center();
1945 // border
1946 QRect fullRect(center.x() - 4, center.y() - 4, 9, 9);
1947 painter->setPen(borderColor);
1948
1949 const QLine lines[4] = {
1950 QLine(fullRect.left() + 1, fullRect.top(),
1951 fullRect.right() - 1, fullRect.top()),
1952 QLine(fullRect.left() + 1, fullRect.bottom(),
1953 fullRect.right() - 1, fullRect.bottom()),
1954 QLine(fullRect.left(), fullRect.top() + 1,
1955 fullRect.left(), fullRect.bottom() - 1),
1956 QLine(fullRect.right(), fullRect.top() + 1,
1957 fullRect.right(), fullRect.bottom() - 1) };
1958 painter->drawLines(lines, 4);
1959
1960 // "antialiased" corners
1961 painter->setPen(alphaCornerColor);
1962 const QPoint points[4] = {
1963 fullRect.topLeft(),
1964 fullRect.topRight(),
1965 fullRect.bottomLeft(),
1966 fullRect.bottomRight() };
1967 painter->drawPoints(points, 4);
1968
1969 // fill
1970 QRect adjustedRect = fullRect;
1971 QRect gradientRect(adjustedRect.left() + 1, adjustedRect.top() + 1,
1972 adjustedRect.right() - adjustedRect.left() - 1,
1973 adjustedRect.bottom() - adjustedRect.top() - 1);
1974 if (option->palette.base().style() == Qt::SolidPattern) {
1975 QColor baseGradientStartColor = option->palette.base().color().darker(101);
1976 QColor baseGradientStopColor = option->palette.base().color().darker(106);
1977 qt_plastique_draw_gradient(painter, gradientRect, baseGradientStartColor, baseGradientStopColor);
1978 } else {
1979 painter->fillRect(gradientRect, option->palette.base());
1980 }
1981 // draw "+" or "-"
1982 painter->setPen(alphaTextColor);
1983 painter->drawLine(center.x() - 2, center.y(), center.x() + 2, center.y());
1984 if (!(option->state & State_Open))
1985 painter->drawLine(center.x(), center.y() - 2, center.x(), center.y() + 2);
1986 painter->restore();
1987 }
1988 }
1989 break;
1990 default:
1991 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1992 break;
1993 }
1994 }
1995
1996 /*!
1997 \reimp
1998 */
drawControl(ControlElement element,const QStyleOption * option,QPainter * painter,const QWidget * widget) const1999 void QPlastiqueStyle::drawControl(ControlElement element, const QStyleOption *option,
2000 QPainter *painter, const QWidget *widget) const
2001 {
2002 QColor borderColor = option->palette.background().color().darker(178);
2003 QColor alphaCornerColor;
2004 if (widget) {
2005 // ### backgroundrole/foregroundrole should be part of the style option
2006 alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), borderColor);
2007 } else {
2008 alphaCornerColor = mergedColors(option->palette.background().color(), borderColor);
2009 }
2010
2011 QColor gradientStartColor = option->palette.button().color().lighter(104);
2012 QColor gradientStopColor = option->palette.button().color().darker(105);
2013
2014 QColor highlightedGradientStartColor = option->palette.button().color().lighter(101);
2015 QColor highlightedGradientStopColor = mergedColors(option->palette.button().color(), option->palette.highlight().color(), 85);
2016
2017 QColor lightShadowGradientStartColor = highlightedGradientStartColor.lighter(105);
2018 QColor lightShadowGradientStopColor = highlightedGradientStopColor.lighter(105);
2019
2020 QColor highlightedDarkInnerBorderColor = mergedColors(option->palette.button().color(), option->palette.highlight().color(), 35);
2021 QColor highlightedLightInnerBorderColor = mergedColors(option->palette.button().color(), option->palette.highlight().color(), 58);
2022
2023 QColor alphaInnerColor = mergedColors(highlightedDarkInnerBorderColor, option->palette.base().color());
2024
2025 switch (element) {
2026 #ifndef QT_NO_TABBAR
2027 case CE_TabBarTabShape:
2028 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
2029
2030 if (tab->shape != QTabBar::RoundedNorth && tab->shape != QTabBar::RoundedWest &&
2031 tab->shape != QTabBar::RoundedSouth && tab->shape != QTabBar::RoundedEast) {
2032 QWindowsStyle::drawControl(element, option, painter, widget);
2033 break;
2034 }
2035
2036 painter->save();
2037
2038 // Set up some convenience variables
2039 bool disabled = !(tab->state & State_Enabled);
2040 bool onlyTab = tab->position == QStyleOptionTab::OnlyOneTab;
2041 bool selected = tab->state & State_Selected;
2042 bool mouseOver = (tab->state & State_MouseOver) && !selected && !disabled;
2043 bool previousSelected = tab->selectedPosition == QStyleOptionTab::PreviousIsSelected;
2044 bool nextSelected = tab->selectedPosition == QStyleOptionTab::NextIsSelected;
2045 bool leftCornerWidget = (tab->cornerWidgets & QStyleOptionTab::LeftCornerWidget);
2046 bool reverse = (tab->direction == Qt::RightToLeft);
2047
2048 int lowerTop = selected ? 0 : 3; // to make the selected tab bigger than the rest
2049 bool atEnd = (tab->position == QStyleOptionTab::End) || onlyTab;
2050 bool atBeginning = ((tab->position == QStyleOptionTab::Beginning) || onlyTab)
2051 && !leftCornerWidget;
2052 bool reverseShadow = false;
2053
2054 int borderThickness = proxy()->pixelMetric(PM_TabBarBaseOverlap, tab, widget);
2055 int marginLeft = 0;
2056 if ((atBeginning && !selected) || (selected && leftCornerWidget && ((tab->position == QStyleOptionTab::Beginning) || onlyTab))) {
2057 marginLeft = 1;
2058 }
2059
2060 // I've set the names based on the natural coordinate system. Vectors are used to rotate everything
2061 // if the orientation of the tab bare is different than north.
2062 {
2063 // Coordinates of corners of rectangle for transformation
2064 QPoint topLeft;
2065 QPoint topRight;
2066 QPoint bottomLeft;
2067 QPoint bottomRight;
2068
2069 // Fill with normalized vectors in the direction of the coordinate system
2070 // (down and right should be complement of up and left, or it will look odd)
2071 QPoint vectorUp;
2072 QPoint vectorDown;
2073 QPoint vectorLeft;
2074 QPoint vectorRight;
2075
2076 QBrush border = option->palette.shadow();
2077 qBrushSetAlphaF(&border, qreal(0.4));
2078 QBrush innerTopLeft = option->palette.shadow();
2079 qBrushSetAlphaF(&innerTopLeft, qreal(0.075));
2080 QBrush innerBottomRight = option->palette.shadow();
2081 qBrushSetAlphaF(&innerBottomRight, qreal(0.23));
2082 QBrush corner = option->palette.shadow();
2083 qBrushSetAlphaF(&corner, qreal(0.25));
2084
2085 QBrush baseColor1;
2086 QBrush baseColor2;
2087
2088 switch (tab->shape) {
2089 case QTabBar::RoundedNorth:
2090 vectorUp = QPoint(0, -1);
2091 vectorDown = QPoint(0, 1);
2092
2093 if (reverse) {
2094 vectorLeft = QPoint(1, 0);
2095 vectorRight = QPoint(-1, 0);
2096 reverseShadow = true;
2097 } else {
2098 vectorLeft = QPoint(-1, 0);
2099 vectorRight = QPoint(1, 0);
2100 }
2101
2102 if (reverse) {
2103 topLeft = tab->rect.topRight();
2104 topRight = tab->rect.topLeft();
2105 bottomLeft = tab->rect.bottomRight();
2106 bottomRight = tab->rect.bottomLeft();
2107 } else {
2108 topLeft = tab->rect.topLeft();
2109 topRight = tab->rect.topRight();
2110 bottomLeft = tab->rect.bottomLeft();
2111 bottomRight = tab->rect.bottomRight();
2112 }
2113
2114
2115 baseColor1 = border;
2116 baseColor2 = innerTopLeft;
2117 break ;
2118 case QTabBar::RoundedWest:
2119 vectorUp = QPoint(-1, 0);
2120 vectorDown = QPoint(1, 0);
2121 vectorLeft = QPoint(0, -1);
2122 vectorRight = QPoint(0, 1);
2123
2124 topLeft = tab->rect.topLeft();
2125 topRight = tab->rect.bottomLeft();
2126 bottomLeft = tab->rect.topRight();
2127 bottomRight = tab->rect.bottomRight();
2128
2129 baseColor1 = border;
2130 baseColor2 = innerTopLeft;
2131 break ;
2132 case QTabBar::RoundedEast:
2133 vectorUp = QPoint(1, 0);
2134 vectorDown = QPoint(-1, 0);
2135 vectorLeft = QPoint(0, -1);
2136 vectorRight = QPoint(0, 1);
2137
2138 topLeft = tab->rect.topRight();
2139 topRight = tab->rect.bottomRight();
2140 bottomLeft = tab->rect.topLeft();
2141 bottomRight = tab->rect.bottomLeft();
2142
2143 baseColor1 = border;
2144 baseColor2 = innerBottomRight;
2145 break ;
2146 case QTabBar::RoundedSouth:
2147 vectorUp = QPoint(0, 1);
2148 vectorDown = QPoint(0, -1);
2149
2150 if (reverse) {
2151 vectorLeft = QPoint(1, 0);
2152 vectorRight = QPoint(-1, 0);
2153 reverseShadow = true;
2154
2155 topLeft = tab->rect.bottomRight();
2156 topRight = tab->rect.bottomLeft();
2157 bottomLeft = tab->rect.topRight();
2158 bottomRight = tab->rect.topLeft();
2159 } else {
2160 vectorLeft = QPoint(-1, 0);
2161 vectorRight = QPoint(1, 0);
2162
2163 topLeft = tab->rect.bottomLeft();
2164 topRight = tab->rect.bottomRight();
2165 bottomLeft = tab->rect.topLeft();
2166 bottomRight = tab->rect.topRight();
2167 }
2168
2169 baseColor1 = border;
2170 baseColor2 = innerBottomRight;
2171 break ;
2172 default:
2173 break;
2174 }
2175
2176 // Make the tab smaller when it's at the end, so that we are able to draw the corner
2177 if (atEnd) {
2178 topRight += vectorLeft;
2179 bottomRight += vectorLeft;
2180 }
2181
2182 {
2183 // Outer border
2184 QLine topLine;
2185 {
2186 QPoint adjustTopLineLeft = (vectorRight * (marginLeft + (previousSelected ? 0 : 1))) +
2187 (vectorDown * lowerTop);
2188 QPoint adjustTopLineRight = (vectorDown * lowerTop);
2189 if (atBeginning || selected)
2190 adjustTopLineLeft += vectorRight;
2191 if (atEnd || selected)
2192 adjustTopLineRight += 2 * vectorLeft;
2193
2194 topLine = QLine(topLeft + adjustTopLineLeft, topRight + adjustTopLineRight);
2195 }
2196
2197 QLine leftLine;
2198 {
2199 QPoint adjustLeftLineTop = (vectorRight * marginLeft) + (vectorDown * (lowerTop + 1));
2200 QPoint adjustLeftLineBottom = (vectorRight * marginLeft) + (vectorUp * borderThickness);
2201 if (atBeginning || selected)
2202 adjustLeftLineTop += vectorDown; // Make place for rounded corner
2203 if (atBeginning && selected)
2204 adjustLeftLineBottom += borderThickness * vectorDown;
2205 else if (selected)
2206 adjustLeftLineBottom += vectorUp;
2207
2208 leftLine = QLine(topLeft + adjustLeftLineTop, bottomLeft + adjustLeftLineBottom);
2209 }
2210
2211 QLine rightLine;
2212 {
2213 QPoint adjustRightLineTop = vectorDown * (2 + lowerTop);
2214 QPoint adjustRightLineBottom = vectorUp * borderThickness;
2215 if (selected)
2216 adjustRightLineBottom += vectorUp;
2217
2218 rightLine = QLine(topRight + adjustRightLineTop, bottomRight + adjustRightLineBottom);
2219 }
2220
2221 // Background
2222 QPoint startPoint = topLine.p1() + vectorDown + vectorLeft;
2223 if (mouseOver)
2224 startPoint += vectorDown;
2225 QPoint endPoint = rightLine.p2();
2226
2227 if (tab->state & State_Enabled) {
2228 QRect fillRect = QRect(startPoint, endPoint).normalized();
2229 if (fillRect.isValid()) {
2230 if (selected) {
2231 fillRect = QRect(startPoint, endPoint + vectorLeft + vectorDown * 3).normalized();
2232 painter->fillRect(fillRect, option->palette.window());
2233
2234 // Connect to the base
2235 painter->setPen(QPen(option->palette.window(), 0));
2236 QVarLengthArray<QPoint, 6> points;
2237 points.append(rightLine.p2() + vectorDown);
2238 points.append(rightLine.p2() + vectorDown + vectorDown);
2239 points.append(rightLine.p2() + vectorDown + vectorDown + vectorRight);
2240 if (tab->position != QStyleOptionTab::Beginning) {
2241 points.append(leftLine.p2() + vectorDown);
2242 points.append(leftLine.p2() + vectorDown + vectorDown);
2243 points.append(leftLine.p2() + vectorDown + vectorDown + vectorLeft);
2244 }
2245 painter->drawPoints(points.constData(), points.size());
2246 } else {
2247 QBrush buttonGradientBrush;
2248 QBrush buttonBrush = qMapBrushToRect(option->palette.button(), fillRect);
2249 if (buttonBrush.gradient() || !buttonBrush.texture().isNull()) {
2250 buttonGradientBrush = buttonBrush;
2251 } else {
2252 // Generate gradients
2253 QLinearGradient buttonGradient(fillRect.topLeft(), fillRect.bottomLeft());
2254 buttonGradient.setColorAt(0.0, buttonBrush.color().lighter(104));
2255 buttonGradient.setColorAt(1.0, buttonBrush.color().darker(110));
2256 buttonGradientBrush = QBrush(buttonGradient);
2257 }
2258
2259 painter->fillRect(fillRect, buttonGradientBrush);
2260 }
2261 }
2262 }
2263
2264 QPoint rightCornerDot = topRight + vectorLeft + (lowerTop + 1)*vectorDown;
2265 QPoint leftCornerDot = topLeft + (marginLeft + 1)*vectorRight + (lowerTop + 1)*vectorDown;
2266 QPoint bottomRightConnectToBase = rightLine.p2() + vectorRight + vectorDown;
2267 QPoint bottomLeftConnectToBase = leftLine.p2() + vectorLeft + vectorDown;
2268
2269 painter->setPen(QPen(border, 0));
2270
2271 QVarLengthArray<QLine, 3> lines;
2272 QVarLengthArray<QPoint, 7> points;
2273
2274 lines.append(topLine);
2275
2276 if (mouseOver) {
2277 painter->drawLines(lines.constData(), lines.count());
2278 lines.clear();
2279
2280 QLine secondHoverLine = QLine(topLine.p1() + vectorDown * 2 + vectorLeft, topLine.p2() + vectorDown * 2 + vectorRight);
2281 painter->setPen(highlightedLightInnerBorderColor);
2282 painter->drawLine(secondHoverLine);
2283 }
2284
2285 if (mouseOver)
2286 painter->setPen(QPen(border, 0));
2287
2288 if (!previousSelected)
2289 lines.append(leftLine);
2290 if (atEnd || selected) {
2291 lines.append(rightLine);
2292 points.append(rightCornerDot);
2293 }
2294 if (atBeginning || selected)
2295 points.append(leftCornerDot);
2296 if (selected) {
2297 points.append(bottomRightConnectToBase);
2298 points.append(bottomLeftConnectToBase);
2299 }
2300 if (lines.size() > 0) {
2301 painter->drawLines(lines.constData(), lines.size());
2302 lines.clear();
2303 }
2304 if (points.size() > 0) {
2305 painter->drawPoints(points.constData(), points.size());
2306 points.clear();
2307 }
2308
2309 // Antialiasing
2310 painter->setPen(QPen(corner, 0));
2311 if (atBeginning || selected)
2312 points.append(topLine.p1() + vectorLeft);
2313 if (!previousSelected)
2314 points.append(leftLine.p1() + vectorUp);
2315 if (atEnd || selected) {
2316 points.append(topLine.p2() + vectorRight);
2317 points.append(rightLine.p1() + vectorUp);
2318 }
2319
2320 if (selected) {
2321 points.append(bottomRightConnectToBase + vectorLeft);
2322 if (!atBeginning) {
2323 points.append(bottomLeftConnectToBase + vectorRight);
2324
2325 if (((tab->position == QStyleOptionTab::Beginning) || onlyTab) && leftCornerWidget) {
2326 // A special case: When the first tab is selected and
2327 // has a left corner widget, it needs to do more work
2328 // to connect to the base
2329 QPoint p1 = bottomLeftConnectToBase + vectorDown;
2330
2331 points.append(p1);
2332 }
2333 }
2334 }
2335 if (points.size() > 0) {
2336 painter->drawPoints(points.constData(), points.size());
2337 points.clear();
2338 }
2339
2340 // Inner border
2341 QLine innerTopLine = QLine(topLine.p1() + vectorDown, topLine.p2() + vectorDown);
2342 if (!selected) {
2343 QLinearGradient topLineGradient(innerTopLine.p1(),innerTopLine.p2());
2344 topLineGradient.setColorAt(0, lightShadowGradientStartColor);
2345 topLineGradient.setColorAt(1, lightShadowGradientStopColor);
2346 painter->setPen(QPen(mouseOver ? QBrush(highlightedDarkInnerBorderColor) : QBrush(topLineGradient), 1));
2347 } else {
2348 painter->setPen(QPen(innerTopLeft, 0));
2349 }
2350 painter->drawLine(innerTopLine);
2351
2352 QLine innerLeftLine = QLine(leftLine.p1() + vectorRight + vectorDown, leftLine.p2() + vectorRight);
2353 QLine innerRightLine = QLine(rightLine.p1() + vectorLeft + vectorDown, rightLine.p2() + vectorLeft);
2354
2355 if (selected) {
2356 innerRightLine = QLine(innerRightLine.p1() + vectorUp, innerRightLine.p2());
2357 innerLeftLine = QLine(innerLeftLine.p1() + vectorUp, innerLeftLine.p2());
2358 }
2359
2360 if (selected || atBeginning) {
2361 QBrush leftLineGradientBrush;
2362 QRect rect = QRect(innerLeftLine.p1(), innerLeftLine.p2()).normalized();
2363 QBrush buttonBrush = qMapBrushToRect(option->palette.button(), rect);
2364 if (buttonBrush.gradient() || !buttonBrush.texture().isNull()) {
2365 leftLineGradientBrush = qBrushLight(buttonBrush, 105);
2366 } else {
2367 QLinearGradient buttonGradient3(rect.topLeft(), rect.bottomLeft());
2368 buttonGradient3.setColorAt(0.0, buttonBrush.color().lighter(105));
2369 buttonGradient3.setColorAt(1.0, buttonBrush.color());
2370 leftLineGradientBrush = QBrush(buttonGradient3);
2371 }
2372
2373 if (!selected)
2374 painter->setPen(QPen(leftLineGradientBrush, 0));
2375
2376 // Assume the sun is on the same side in Right-To-Left layouts and draw the
2377 // light shadow on the left side always (the right line is on the left side in
2378 // reverse layouts for north and south)
2379 if (reverseShadow)
2380 painter->drawLine(innerRightLine);
2381 else
2382 painter->drawLine(innerLeftLine);
2383 }
2384
2385 if (atEnd || selected) {
2386 if (!selected) {
2387 QBrush rightLineGradientBrush;
2388 QRect rect = QRect(innerRightLine.p1(), innerRightLine.p2()).normalized();
2389 QBrush buttonBrush = qMapBrushToRect(option->palette.button(), rect);
2390 if (buttonBrush.gradient() || !buttonBrush.texture().isNull()) {
2391 rightLineGradientBrush = qBrushDark(buttonBrush, 105);
2392 } else {
2393 QLinearGradient buttonGradient4(rect.topLeft(), rect.bottomLeft());
2394 buttonGradient4.setColorAt(0.0, buttonBrush.color());
2395 buttonGradient4.setColorAt(1.0, buttonBrush.color().darker(110));
2396 rightLineGradientBrush = QBrush(buttonGradient4);
2397 }
2398
2399 painter->setPen(QPen(rightLineGradientBrush, 0));
2400 } else {
2401 painter->setPen(QPen(innerBottomRight, 0));
2402 }
2403
2404 if (reverseShadow)
2405 painter->drawLine(innerLeftLine);
2406 else
2407 painter->drawLine(innerRightLine);
2408 }
2409
2410
2411 // Base
2412 QLine baseLine = QLine(bottomLeft + marginLeft * 2 * vectorRight, bottomRight);
2413 {
2414
2415 QPoint adjustedLeft;
2416 QPoint adjustedRight;
2417
2418 if (atEnd && !selected) {
2419 baseLine = QLine(baseLine.p1(), baseLine.p2() + vectorRight);
2420 }
2421
2422 if (nextSelected) {
2423 adjustedRight += vectorLeft;
2424 baseLine = QLine(baseLine.p1(), baseLine.p2() + vectorLeft);
2425 }
2426 if (previousSelected) {
2427 adjustedLeft += vectorRight;
2428 baseLine = QLine(baseLine.p1() + vectorRight, baseLine.p2());
2429 }
2430 if (atBeginning)
2431 adjustedLeft += vectorRight;
2432
2433 painter->setPen(QPen(baseColor2, 0));
2434 if (!selected)
2435 painter->drawLine(baseLine);
2436
2437 if (atEnd && !selected)
2438 painter->drawPoint(baseLine.p2() + vectorRight);
2439
2440 if (atBeginning && !selected)
2441 adjustedLeft = vectorRight;
2442 else
2443 adjustedLeft = QPoint(0, 0);
2444 painter->setPen(QPen(baseColor1, 0));
2445 if (!selected)
2446 painter->drawLine(bottomLeft + vectorUp + adjustedLeft, baseLine.p2() + vectorUp);
2447
2448 QPoint endPoint = bottomRight + vectorUp;
2449 if (atEnd && !selected)
2450 painter->drawPoint(endPoint);
2451
2452 // For drawing a lower left "fake" corner on the base when the first tab is unselected
2453 if (atBeginning && !selected) {
2454 painter->drawPoint(baseLine.p1() + vectorLeft);
2455 }
2456
2457 painter->setPen(QPen(corner, 0));
2458 if (nextSelected)
2459 painter->drawPoint(endPoint);
2460 else if (selected)
2461 painter->drawPoint(endPoint + vectorRight);
2462
2463 // For drawing a lower left "fake" corner on the base when the first tab is unselected
2464 if (atBeginning && !selected) {
2465 painter->drawPoint(baseLine.p1() + 2 * vectorLeft);
2466 }
2467 }
2468 }
2469 }
2470
2471 // Yay we're done
2472
2473 painter->restore();
2474 }
2475 break;
2476 #endif // QT_NO_TABBAR
2477 #ifndef QT_NO_PROGRESSBAR
2478 case CE_ProgressBarGroove:
2479 if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
2480 QRect rect = bar->rect;
2481 QPen oldPen = painter->pen();
2482
2483 QLine lines[4];
2484
2485 // outline
2486 painter->setPen(borderColor);
2487 lines[0] = QLine(rect.left() + 2, rect.top(), rect.right() - 2, rect.top());
2488 lines[1] = QLine(rect.left() + 2, rect.bottom(), rect.right() - 2, rect.bottom());
2489 lines[2] = QLine(rect.left(), rect.top() + 2, rect.left(), rect.bottom() - 2);
2490 lines[3] = QLine(rect.right(), rect.top() + 2, rect.right(), rect.bottom() - 2);
2491 painter->drawLines(lines, 4);
2492
2493 QPoint points[8];
2494 points[0] = QPoint(rect.left() + 1, rect.top() + 1);
2495 points[1] = QPoint(rect.right() - 1, rect.top() + 1);
2496 points[2] = QPoint(rect.left() + 1, rect.bottom() - 1);
2497 points[3] = QPoint(rect.right() - 1, rect.bottom() - 1);
2498 painter->drawPoints(points, 4);
2499
2500 // alpha corners
2501 painter->setPen(alphaCornerColor);
2502 points[0] = QPoint(rect.left(), rect.top() + 1);
2503 points[1] = QPoint(rect.left() + 1, rect.top());
2504 points[2] = QPoint(rect.right(), rect.top() + 1);
2505 points[3] = QPoint(rect.right() - 1, rect.top());
2506 points[4] = QPoint(rect.left(), rect.bottom() - 1);
2507 points[5] = QPoint(rect.left() + 1, rect.bottom());
2508 points[6] = QPoint(rect.right(), rect.bottom() - 1);
2509 points[7] = QPoint(rect.right() - 1, rect.bottom());
2510 painter->drawPoints(points, 8);
2511
2512 // inner outline, north-west
2513 painter->setPen(gradientStartColor.darker(105));
2514 lines[0] = QLine(rect.left() + 2, rect.top() + 1, rect.right() - 2, rect.top() + 1);
2515 lines[1] = QLine(rect.left() + 1, rect.top() + 2, rect.left() + 1, rect.bottom() - 2);
2516 painter->drawLines(lines, 2);
2517
2518 // base of the groove
2519 painter->setPen(QPen());
2520 painter->fillRect(rect.adjusted(2, 2, -2, -1), QBrush(bar->palette.base().color()));
2521 painter->setPen(bar->palette.base().color());
2522 painter->drawLine(rect.right() - 1, rect.top() + 2, rect.right() - 1, rect.bottom() - 2);
2523
2524 painter->setPen(oldPen);
2525 }
2526 break;
2527 case CE_ProgressBarLabel:
2528 if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
2529 // The busy indicator doesn't draw a label
2530 if (bar->minimum == 0 && bar->maximum == 0)
2531 return;
2532
2533 painter->save();
2534
2535 QRect rect = bar->rect;
2536 QRect leftRect;
2537
2538 QFont font;
2539 font.setBold(true);
2540 painter->setFont(font);
2541 painter->setPen(bar->palette.text().color());
2542
2543 bool vertical = false;
2544 bool inverted = false;
2545 bool bottomToTop = false;
2546 // Get extra style options if version 2
2547 if (const QStyleOptionProgressBarV2 *bar2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(option)) {
2548 vertical = (bar2->orientation == Qt::Vertical);
2549 inverted = bar2->invertedAppearance;
2550 bottomToTop = bar2->bottomToTop;
2551 }
2552
2553 if (vertical) {
2554 rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height
2555 QTransform m;
2556 if (bottomToTop) {
2557 m.translate(0.0, rect.width());
2558 m.rotate(-90);
2559 } else {
2560 m.translate(rect.height(), 0.0);
2561 m.rotate(90);
2562 }
2563 painter->setTransform(m, true);
2564 }
2565
2566 int progressIndicatorPos = (bar->progress - qreal(bar->minimum)) / qMax(qreal(1.0), qreal(bar->maximum) - bar->minimum) * rect.width();
2567
2568 bool flip = (!vertical && (((bar->direction == Qt::RightToLeft) && !inverted)
2569 || ((bar->direction == Qt::LeftToRight) && inverted))) || (vertical && ((!inverted && !bottomToTop) || (inverted && bottomToTop)));
2570 if (flip) {
2571 int indicatorPos = rect.width() - progressIndicatorPos;
2572 if (indicatorPos >= 0 && indicatorPos <= rect.width()) {
2573 painter->setPen(bar->palette.base().color());
2574 leftRect = QRect(rect.left(), rect.top(), indicatorPos, rect.height());
2575 } else if (indicatorPos > rect.width()) {
2576 painter->setPen(bar->palette.text().color());
2577 } else {
2578 painter->setPen(bar->palette.base().color());
2579 }
2580 } else {
2581 if (progressIndicatorPos >= 0 && progressIndicatorPos <= rect.width()) {
2582 leftRect = QRect(rect.left(), rect.top(), progressIndicatorPos, rect.height());
2583 } else if (progressIndicatorPos > rect.width()) {
2584 painter->setPen(bar->palette.base().color());
2585 } else {
2586 painter->setPen(bar->palette.text().color());
2587 }
2588 }
2589
2590 QRegion rightRect = rect;
2591 rightRect = rightRect.subtracted(leftRect);
2592 painter->setClipRegion(rightRect);
2593 painter->drawText(rect, bar->text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter));
2594 if (!leftRect.isNull()) {
2595 painter->setPen(flip ? bar->palette.text().color() : bar->palette.base().color());
2596 painter->setClipRect(leftRect);
2597 painter->drawText(rect, bar->text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter));
2598 }
2599
2600 painter->restore();
2601 }
2602 break;
2603 case CE_ProgressBarContents:
2604 if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
2605 Q_D(const QPlastiqueStyle);
2606 QRect rect = bar->rect;
2607 bool vertical = false;
2608 bool inverted = false;
2609 bool indeterminate = (bar->minimum == 0 && bar->maximum == 0);
2610 if (!indeterminate && bar->progress == -1)
2611 break;
2612
2613 painter->save();
2614
2615 // Get extra style options if version 2
2616 if (const QStyleOptionProgressBarV2 *bar2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(option)) {
2617 vertical = (bar2->orientation == Qt::Vertical);
2618 inverted = bar2->invertedAppearance;
2619 }
2620
2621 // If the orientation is vertical, we use a transform to rotate
2622 // the progress bar 90 degrees clockwise. This way we can use the
2623 // same rendering code for both orientations.
2624 if (vertical) {
2625 rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height
2626 QTransform m = QTransform::fromTranslate(rect.height()-1, 0);
2627 m.rotate(90.0);
2628 painter->setTransform(m, true);
2629 }
2630
2631 int maxWidth = rect.width() - 4;
2632 int minWidth = 4;
2633 qint64 progress = qMax<qint64>(bar->progress, bar->minimum); // workaround for bug in QProgressBar
2634 double vc6_workaround = ((progress - qint64(bar->minimum)) / qMax(double(1.0), double(qint64(bar->maximum) - qint64(bar->minimum))) * maxWidth);
2635 int width = indeterminate ? maxWidth : qMax(int(vc6_workaround), minWidth);
2636 bool reverse = (!vertical && (bar->direction == Qt::RightToLeft)) || vertical;
2637 if (inverted)
2638 reverse = !reverse;
2639
2640 QRect progressBar;
2641 if (!indeterminate) {
2642 if (!reverse) {
2643 progressBar.setRect(rect.left() + 2, rect.top() + 2, width, rect.height() - 4);
2644 } else {
2645 progressBar.setRect(rect.right() - 1 - width, rect.top() + 2, width, rect.height() - 4);
2646 }
2647 } else {
2648 int slideWidth = ((rect.width() - 4) * 2) / 3;
2649 int step = ((d->animateStep * slideWidth) / ProgressBarFps) % slideWidth;
2650 if ((((d->animateStep * slideWidth) / ProgressBarFps) % (2 * slideWidth)) >= slideWidth)
2651 step = slideWidth - step;
2652 progressBar.setRect(rect.left() + 2 + step, rect.top() + 2,
2653 slideWidth / 2, rect.height() - 4);
2654 }
2655
2656 // outline
2657 painter->setPen(highlightedDarkInnerBorderColor);
2658
2659 QVarLengthArray<QLine, 4> lines;
2660 QVarLengthArray<QPoint, 8> points;
2661 if (!reverse) {
2662 if (width == minWidth) {
2663 points.append(QPoint(progressBar.left() + 1, progressBar.top()));
2664 points.append(QPoint(progressBar.left() + 1, progressBar.bottom()));
2665 } else {
2666 if (indeterminate) {
2667 lines.append(QLine(progressBar.left() + 2, progressBar.top(),
2668 progressBar.right() - 2, progressBar.top()));
2669 lines.append(QLine(progressBar.left() + 2, progressBar.bottom(),
2670 progressBar.right() - 2, progressBar.bottom()));
2671 } else {
2672 lines.append(QLine(progressBar.left() + 1, progressBar.top(),
2673 progressBar.right() - 2, progressBar.top()));
2674 lines.append(QLine(progressBar.left() + 1, progressBar.bottom(),
2675 progressBar.right() - 2, progressBar.bottom()));
2676 }
2677 }
2678
2679 if (indeterminate) {
2680 lines.append(QLine(progressBar.left(), progressBar.top() + 2,
2681 progressBar.left(), progressBar.bottom() - 2));
2682 } else {
2683 lines.append(QLine(progressBar.left(), progressBar.top() + 1,
2684 progressBar.left(), progressBar.bottom() - 1));
2685 }
2686 lines.append(QLine(progressBar.right(), progressBar.top() + 2,
2687 progressBar.right(), progressBar.bottom() - 2));
2688 } else {
2689 if (width == minWidth) {
2690 points.append(QPoint(progressBar.right() - 1, progressBar.top()));
2691 points.append(QPoint(progressBar.right() - 1, progressBar.bottom()));
2692 } else {
2693 if (indeterminate) {
2694 lines.append(QLine(progressBar.right() - 2, progressBar.top(),
2695 progressBar.left() + 2, progressBar.top()));
2696 lines.append(QLine(progressBar.right() - 2, progressBar.bottom(),
2697 progressBar.left() + 2, progressBar.bottom()));
2698 } else {
2699 lines.append(QLine(progressBar.right() - 1, progressBar.top(),
2700 progressBar.left() + 2, progressBar.top()));
2701 lines.append(QLine(progressBar.right() - 1, progressBar.bottom(),
2702 progressBar.left() + 2, progressBar.bottom()));
2703 }
2704 }
2705 if (indeterminate) {
2706 lines.append(QLine(progressBar.right(), progressBar.top() + 2,
2707 progressBar.right(), progressBar.bottom() - 2));
2708 } else {
2709 lines.append(QLine(progressBar.right(), progressBar.top() + 1,
2710 progressBar.right(), progressBar.bottom() - 1));
2711 }
2712 lines.append(QLine(progressBar.left(), progressBar.top() + 2,
2713 progressBar.left(), progressBar.bottom() - 2));
2714 }
2715
2716 if (points.size() > 0) {
2717 painter->drawPoints(points.constData(), points.size());
2718 points.clear();
2719 }
2720 painter->drawLines(lines.constData(), lines.size());
2721 lines.clear();
2722
2723 // alpha corners
2724 painter->setPen(alphaInnerColor);
2725 if (!reverse) {
2726 if (indeterminate) {
2727 points.append(QPoint(progressBar.left() + 1, progressBar.top()));
2728 points.append(QPoint(progressBar.left(), progressBar.top() + 1));
2729 points.append(QPoint(progressBar.left() + 1, progressBar.bottom()));
2730 points.append(QPoint(progressBar.left(), progressBar.bottom() - 1));
2731 } else {
2732 points.append(QPoint(progressBar.left(), progressBar.top()));
2733 points.append(QPoint(progressBar.left(), progressBar.bottom()));
2734 }
2735 points.append(QPoint(progressBar.right() - 1, progressBar.top()));
2736 points.append(QPoint(progressBar.right(), progressBar.top() + 1));
2737 points.append(QPoint(progressBar.right() - 1, progressBar.bottom()));
2738 points.append(QPoint(progressBar.right(), progressBar.bottom() - 1));
2739 } else {
2740 if (indeterminate) {
2741 points.append(QPoint(progressBar.right() - 1, progressBar.top()));
2742 points.append(QPoint(progressBar.right(), progressBar.top() + 1));
2743 points.append(QPoint(progressBar.right() - 1, progressBar.bottom()));
2744 points.append(QPoint(progressBar.right(), progressBar.bottom() - 1));
2745 } else {
2746 points.append(QPoint(progressBar.right(), progressBar.top()));
2747 points.append(QPoint(progressBar.right(), progressBar.bottom()));
2748 }
2749 points.append(QPoint(progressBar.left() + 1, progressBar.top()));
2750 points.append(QPoint(progressBar.left(), progressBar.top() + 1));
2751 points.append(QPoint(progressBar.left() + 1, progressBar.bottom()));
2752 points.append(QPoint(progressBar.left(), progressBar.bottom() - 1));
2753 }
2754
2755 painter->drawPoints(points.constData(), points.size());
2756 points.clear();
2757
2758 // contents
2759 painter->setPen(QPen());
2760
2761 QString progressBarName = QStyleHelper::uniqueName(QLatin1String("progressBarContents"),
2762 option, rect.size());
2763 QPixmap cache;
2764 if (!QPixmapCache::find(progressBarName, cache) && rect.height() > 7) {
2765 QSize size = rect.size();
2766 cache = QPixmap(QSize(size.width() - 6 + 30, size.height() - 6));
2767 cache.fill(Qt::white);
2768 QPainter cachePainter(&cache);
2769 QRect pixmapRect(0, 0, cache.width(), cache.height());
2770
2771 int leftEdge = 0;
2772 bool flip = false;
2773 while (leftEdge < cache.width() + 1) {
2774 QColor rectColor = option->palette.highlight().color();
2775 QColor lineColor = option->palette.highlight().color();
2776 if (flip) {
2777 flip = false;
2778 rectColor = rectColor.lighter(105);
2779 lineColor = lineColor.lighter(105);
2780 } else {
2781 flip = true;
2782 }
2783
2784 cachePainter.setPen(lineColor);
2785 const QLine cacheLines[2] = {
2786 QLine(pixmapRect.left() + leftEdge - 1, pixmapRect.top(),
2787 pixmapRect.left() + leftEdge + 9, pixmapRect.top()),
2788 QLine(pixmapRect.left() + leftEdge - 1, pixmapRect.bottom(),
2789 pixmapRect.left() + leftEdge + 9, pixmapRect.bottom()) };
2790 cachePainter.drawLines(cacheLines, 2);
2791 cachePainter.fillRect(QRect(pixmapRect.left() + leftEdge, pixmapRect.top(),
2792 10, pixmapRect.height()), rectColor);
2793
2794 leftEdge += 10;
2795 }
2796
2797 QPixmapCache::insert(progressBarName, cache);
2798 }
2799 painter->setClipRect(progressBar.adjusted(1, 0, -1, -1));
2800
2801 if (!vertical)
2802 progressBar.adjust(0, 1, 0, 1);
2803 if (!indeterminate) {
2804 int step = (AnimateProgressBar || (indeterminate && AnimateBusyProgressBar)) ? (d->animateStep % 20) : 0;
2805 if (reverse)
2806 painter->drawPixmap(progressBar.left() - 25 + step, progressBar.top(), cache);
2807 else
2808 painter->drawPixmap(progressBar.left() - 25 - step + width % 20, progressBar.top(), cache);
2809 } else {
2810 painter->drawPixmap(progressBar.left(), progressBar.top(), cache);
2811 }
2812
2813 painter->restore();
2814 }
2815 break;
2816 #endif // QT_NO_PROGRESSBAR
2817 case CE_HeaderSection:
2818 // Draws the header in tables.
2819 if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
2820 QPixmap cache;
2821 QString pixmapName = QStyleHelper::uniqueName(QLatin1String("headersection"), option, option->rect.size());
2822 pixmapName += QString::number(- int(header->position));
2823 pixmapName += QString::number(- int(header->orientation));
2824
2825 if (!QPixmapCache::find(pixmapName, cache)) {
2826 cache = QPixmap(option->rect.size());
2827 cache.fill(Qt::white);
2828 QRect pixmapRect(0, 0, option->rect.width(), option->rect.height());
2829 QPainter cachePainter(&cache);
2830
2831 bool sunken = (header->state & State_Enabled) && (header->state & State_Sunken);
2832
2833 QColor headerGradientStart = sunken ? option->palette.background().color().darker(114) : gradientStartColor;
2834 QColor headerGradientStop = sunken ? option->palette.background().color().darker(106) : gradientStopColor;
2835
2836 QColor lightLine = sunken ? option->palette.background().color().darker(118) : gradientStartColor;
2837 QColor darkLine = sunken ? option->palette.background().color().darker(110) : gradientStopColor.darker(105);
2838
2839 qt_plastique_draw_gradient(&cachePainter, pixmapRect,
2840 headerGradientStart, headerGradientStop);
2841
2842 cachePainter.setPen(borderColor);
2843 cachePainter.drawRect(pixmapRect.adjusted(0, 0, -1, -1));
2844 cachePainter.setPen(alphaCornerColor);
2845
2846 const QPoint points[4] = {
2847 pixmapRect.topLeft(), pixmapRect.topRight(),
2848 pixmapRect.bottomLeft(), pixmapRect.bottomRight() };
2849 cachePainter.drawPoints(points, 4);
2850
2851 QLine lines[2];
2852
2853 // inner lines
2854 cachePainter.setPen(lightLine);
2855 lines[0] = QLine(pixmapRect.left() + 2, pixmapRect.top() + 1,
2856 pixmapRect.right() - 2, pixmapRect.top() + 1);
2857 lines[1] = QLine(pixmapRect.left() + 1, pixmapRect.top() + 2,
2858 pixmapRect.left() + 1, pixmapRect.bottom() - 2);
2859 cachePainter.drawLines(lines, 2);
2860
2861 cachePainter.setPen(darkLine);
2862 lines[0] = QLine(pixmapRect.left() + 2, pixmapRect.bottom() - 1,
2863 pixmapRect.right() - 2, pixmapRect.bottom() - 1);
2864 lines[1] = QLine(pixmapRect.right() - 1, pixmapRect.bottom() - 2,
2865 pixmapRect.right() - 1, pixmapRect.top() + 2);
2866 cachePainter.drawLines(lines, 2);
2867
2868 cachePainter.end();
2869 QPixmapCache::insert(pixmapName, cache);
2870 }
2871 painter->drawPixmap(option->rect.topLeft(), cache);
2872
2873 }
2874 break;
2875 #ifndef QT_NO_MENU
2876 case CE_MenuItem:
2877 // Draws one item in a popup menu.
2878 if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
2879 painter->save();
2880 QBrush textBrush;
2881 if (option->palette.resolve() & (1 << QPalette::ButtonText))
2882 textBrush = option->palette.buttonText();
2883 else
2884 textBrush = option->palette.windowText(); // KDE uses windowText rather than buttonText for menus
2885
2886 if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
2887 painter->fillRect(menuItem->rect, option->palette.background().color().lighter(103));
2888
2889 int w = 0;
2890 if (!menuItem->text.isEmpty()) {
2891 painter->setFont(menuItem->font);
2892 proxy()->drawItemText(painter, menuItem->rect.adjusted(5, 0, -5, 0), Qt::AlignLeft | Qt::AlignVCenter,
2893 menuItem->palette, menuItem->state & State_Enabled, menuItem->text,
2894 QPalette::Text);
2895 w = menuItem->fontMetrics.width(menuItem->text) + 5;
2896 }
2897
2898 painter->setPen(alphaCornerColor);
2899 bool reverse = menuItem->direction == Qt::RightToLeft;
2900 painter->drawLine(menuItem->rect.left() + 5 + (reverse ? 0 : w), menuItem->rect.center().y(),
2901 menuItem->rect.right() - 5 - (reverse ? w : 0), menuItem->rect.center().y());
2902
2903 painter->restore();
2904 break;
2905 }
2906
2907 bool selected = menuItem->state & State_Selected;
2908 bool checkable = menuItem->checkType != QStyleOptionMenuItem::NotCheckable;
2909 bool checked = menuItem->checked;
2910
2911 if (selected) {
2912 qt_plastique_draw_gradient(painter, menuItem->rect,
2913 option->palette.highlight().color().lighter(105),
2914 option->palette.highlight().color().darker(110));
2915
2916 painter->setPen(option->palette.highlight().color().lighter(110));
2917 painter->drawLine(option->rect.topLeft(), option->rect.topRight());
2918 painter->setPen(option->palette.highlight().color().darker(115));
2919 painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
2920 } else {
2921 painter->fillRect(option->rect, option->palette.background().color().lighter(103));
2922 }
2923
2924 // Check
2925 QRect checkRect(option->rect.left() + 7, option->rect.center().y() - 6, 13, 13);
2926 checkRect = visualRect(menuItem->direction, menuItem->rect, checkRect);
2927 if (checkable) {
2928 if ((menuItem->checkType & QStyleOptionMenuItem::Exclusive) && menuItem->icon.isNull()) {
2929 QStyleOptionButton button;
2930 button.rect = checkRect;
2931 button.state = menuItem->state;
2932 if (checked)
2933 button.state |= State_On;
2934 button.palette = menuItem->palette;
2935 proxy()->drawPrimitive(PE_IndicatorRadioButton, &button, painter, widget);
2936 } else {
2937 if (menuItem->icon.isNull()) {
2938 QStyleOptionButton button;
2939 button.rect = checkRect;
2940 button.state = menuItem->state;
2941 if (checked)
2942 button.state |= State_On;
2943 button.palette = menuItem->palette;
2944 proxy()->drawPrimitive(PE_IndicatorCheckBox, &button, painter, widget);
2945 } else if (checked) {
2946 int iconSize = qMax(menuItem->maxIconWidth, 20);
2947 QRect sunkenRect(option->rect.left() + 1,
2948 option->rect.top() + (option->rect.height() - iconSize) / 2 + 1,
2949 iconSize, iconSize);
2950 sunkenRect = visualRect(menuItem->direction, menuItem->rect, sunkenRect);
2951
2952 QStyleOption opt = *option;
2953 opt.state |= State_Sunken;
2954 opt.rect = sunkenRect;
2955 qt_plastique_drawShadedPanel(painter, &opt, false, widget);
2956 }
2957 }
2958 }
2959
2960 // Text and icon, ripped from windows style
2961 bool dis = !(menuItem->state & State_Enabled);
2962 bool act = menuItem->state & State_Selected;
2963 const QStyleOption *opt = option;
2964 const QStyleOptionMenuItem *menuitem = menuItem;
2965 int checkcol = qMax(menuitem->maxIconWidth, 20);
2966 QPainter *p = painter;
2967 QRect vCheckRect = visualRect(opt->direction, menuitem->rect,
2968 QRect(menuitem->rect.x(), menuitem->rect.y(),
2969 checkcol, menuitem->rect.height()));
2970 if (!menuItem->icon.isNull()) {
2971 QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
2972 if (act && !dis)
2973 mode = QIcon::Active;
2974 QPixmap pixmap;
2975 if (checked)
2976 pixmap = menuItem->icon.pixmap(pixelMetric(PM_SmallIconSize, option, widget), mode, QIcon::On);
2977 else
2978 pixmap = menuItem->icon.pixmap(pixelMetric(PM_SmallIconSize, option, widget), mode);
2979 int pixw = pixmap.width();
2980 int pixh = pixmap.height();
2981
2982 QRect pmr(0, 0, pixw, pixh);
2983 pmr.moveCenter(vCheckRect.center());
2984 painter->setPen(textBrush.color());
2985 if (checkable && checked)
2986 painter->drawPixmap(QPoint(pmr.left() + 1, pmr.top() + 1), pixmap);
2987 else
2988 painter->drawPixmap(pmr.topLeft(), pixmap);
2989 }
2990
2991 if (selected) {
2992 painter->setPen(menuItem->palette.highlightedText().color());
2993 } else {
2994 painter->setPen(textBrush.color());
2995 }
2996 int x, y, w, h;
2997 menuitem->rect.getRect(&x, &y, &w, &h);
2998 int tab = menuitem->tabWidth;
2999 QColor discol;
3000 if (dis) {
3001 discol = textBrush.color();
3002 p->setPen(discol);
3003 }
3004 int xm = windowsItemFrame + checkcol + windowsItemHMargin;
3005 int xpos = menuitem->rect.x() + xm;
3006 QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
3007 QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
3008 QString s = menuitem->text;
3009 if (!s.isEmpty()) { // draw text
3010 p->save();
3011 int t = s.indexOf(QLatin1Char('\t'));
3012 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
3013 if (!styleHint(SH_UnderlineShortcut, menuitem, widget))
3014 text_flags |= Qt::TextHideMnemonic;
3015 text_flags |= Qt::AlignLeft;
3016 if (t >= 0) {
3017 QRect vShortcutRect = visualRect(opt->direction, menuitem->rect,
3018 QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
3019 if (dis && !act && styleHint(SH_EtchDisabledText, option, widget)) {
3020 p->setPen(menuitem->palette.light().color());
3021 p->drawText(vShortcutRect.adjusted(1,1,1,1), text_flags, s.mid(t + 1));
3022 p->setPen(discol);
3023 }
3024 p->drawText(vShortcutRect, text_flags, s.mid(t + 1));
3025 s = s.left(t);
3026 }
3027 QFont font = menuitem->font;
3028 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
3029 font.setBold(true);
3030 p->setFont(font);
3031 if (dis && !act && styleHint(SH_EtchDisabledText, option, widget)) {
3032 p->setPen(menuitem->palette.light().color());
3033 p->drawText(vTextRect.adjusted(1,1,1,1), text_flags, s.left(t));
3034 p->setPen(discol);
3035 }
3036 p->drawText(vTextRect, text_flags, s.left(t));
3037 p->restore();
3038 }
3039
3040 // Arrow
3041 if (menuItem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow
3042 int dim = (menuItem->rect.height() - 4) / 2;
3043 PrimitiveElement arrow;
3044 arrow = (opt->direction == Qt::RightToLeft) ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
3045 int xpos = menuItem->rect.left() + menuItem->rect.width() - 6 - 2 - dim;
3046 QRect vSubMenuRect = visualRect(option->direction, menuItem->rect,
3047 QRect(xpos, menuItem->rect.top() + menuItem->rect.height() / 2 - dim / 2, dim, dim));
3048 QStyleOptionMenuItem newMI = *menuItem;
3049 newMI.rect = vSubMenuRect;
3050 newMI.state = option->state & State_Enabled;
3051 if (selected)
3052 newMI.palette.setColor(QPalette::ButtonText,
3053 newMI.palette.highlightedText().color());
3054 else
3055 newMI.palette.setColor(QPalette::ButtonText, textBrush.color());
3056 proxy()->drawPrimitive(arrow, &newMI, painter, widget);
3057 }
3058
3059 painter->restore();
3060 }
3061 break;
3062 #endif // QT_NO_MENU
3063 #ifndef QT_NO_MENUBAR
3064 case CE_MenuBarItem:
3065 // Draws a menu bar item; File, Edit, Help etc..
3066 if ((option->state & State_Selected)) {
3067 QPixmap cache;
3068 QString pixmapName = QStyleHelper::uniqueName(QLatin1String("menubaritem"), option, option->rect.size());
3069 if (!QPixmapCache::find(pixmapName, cache)) {
3070 cache = QPixmap(option->rect.size());
3071 cache.fill(Qt::white);
3072 QRect pixmapRect(0, 0, option->rect.width(), option->rect.height());
3073 QPainter cachePainter(&cache);
3074
3075 QRect rect = pixmapRect;
3076
3077 // gradient fill
3078 if ((option->state & QStyle::State_Sunken) || (option->state & QStyle::State_On)) {
3079 qt_plastique_draw_gradient(&cachePainter, rect.adjusted(1, 1, -1, -1),
3080 option->palette.button().color().darker(114),
3081 option->palette.button().color().darker(106));
3082 } else {
3083 qt_plastique_draw_gradient(&cachePainter, rect.adjusted(1, 1, -1, -1),
3084 option->palette.background().color().lighter(105),
3085 option->palette.background().color().darker(102));
3086 }
3087
3088 // outer border and corners
3089 cachePainter.setPen(borderColor);
3090 cachePainter.drawRect(rect.adjusted(0, 0, -1, -1));
3091 cachePainter.setPen(alphaCornerColor);
3092
3093 const QPoint points[4] = {
3094 rect.topLeft(),
3095 rect.topRight(),
3096 rect.bottomLeft(),
3097 rect.bottomRight() };
3098 cachePainter.drawPoints(points, 4);
3099
3100 // inner border
3101 if ((option->state & QStyle::State_Sunken) || (option->state & QStyle::State_On))
3102 cachePainter.setPen(option->palette.button().color().darker(118));
3103 else
3104 cachePainter.setPen(gradientStartColor);
3105
3106 QLine lines[2];
3107 lines[0] = QLine(rect.left() + 1, rect.top() + 1, rect.right() - 1, rect.top() + 1);
3108 lines[1] = QLine(rect.left() + 1, rect.top() + 2, rect.left() + 1, rect.bottom() - 2);
3109 cachePainter.drawLines(lines, 2);
3110
3111 if ((option->state & QStyle::State_Sunken) || (option->state & QStyle::State_On))
3112 cachePainter.setPen(option->palette.button().color().darker(114));
3113 else
3114 cachePainter.setPen(gradientStopColor.darker(102));
3115 lines[0] = QLine(rect.left() + 1, rect.bottom() - 1, rect.right() - 1, rect.bottom() - 1);
3116 lines[1] = QLine(rect.right() - 1, rect.top() + 1, rect.right() - 1, rect.bottom() - 2);
3117 cachePainter.drawLines(lines, 2);
3118 cachePainter.end();
3119 QPixmapCache::insert(pixmapName, cache);
3120 }
3121 painter->drawPixmap(option->rect.topLeft(), cache);
3122 } else {
3123 painter->fillRect(option->rect, option->palette.background());
3124 }
3125
3126 if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
3127 QStyleOptionMenuItem newMI = *mbi;
3128 if (!(option->palette.resolve() & (1 << QPalette::ButtonText))) //KDE uses windowText rather than buttonText for menus
3129 newMI.palette.setColor(QPalette::ButtonText, newMI.palette.windowText().color());
3130 QCommonStyle::drawControl(element, &newMI, painter, widget);
3131 }
3132 break;
3133
3134 #ifndef QT_NO_MAINWINDOW
3135 case CE_MenuBarEmptyArea:
3136 if (widget && qobject_cast<const QMainWindow *>(widget->parentWidget())) {
3137 painter->fillRect(option->rect, option->palette.window());
3138 QPen oldPen = painter->pen();
3139 painter->setPen(QPen(option->palette.dark().color()));
3140 painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
3141 painter->setPen(oldPen);
3142 }
3143 break;
3144 #endif // QT_NO_MAINWINDOW
3145
3146 #endif // QT_NO_MENUBAR
3147
3148 #ifndef QT_NO_TOOLBOX
3149 case CE_ToolBoxTabShape:
3150 if (const QStyleOptionToolBox *toolBox = qstyleoption_cast<const QStyleOptionToolBox *>(option)) {
3151 painter->save();
3152
3153 int width = toolBox->rect.width();
3154 int diag = toolBox->rect.height() - 2;
3155
3156 // The essential points
3157 QPoint rightMost;
3158 QPoint rightEdge;
3159 QPoint leftEdge;
3160 QPoint leftMost;
3161 QPoint leftOne;
3162 QPoint rightOne;
3163 QPoint upOne(0, -1);
3164 QPoint downOne(0, 1);
3165
3166 if (toolBox->direction != Qt::RightToLeft) {
3167 rightMost = QPoint(toolBox->rect.right(), toolBox->rect.bottom() - 2);
3168 rightEdge = QPoint(toolBox->rect.right() - width / 10, toolBox->rect.bottom() - 2);
3169 leftEdge = QPoint(toolBox->rect.right() - width / 10 - diag, toolBox->rect.top());
3170 leftMost = QPoint(toolBox->rect.left(), toolBox->rect.top());
3171 leftOne = QPoint(-1, 0);
3172 rightOne = QPoint(1, 0);
3173 } else {
3174 rightMost = QPoint(toolBox->rect.left(), toolBox->rect.bottom() - 2);
3175 rightEdge = QPoint(toolBox->rect.left() + width / 10, toolBox->rect.bottom() - 2);
3176 leftEdge = QPoint(toolBox->rect.left() + width / 10 + diag, toolBox->rect.top());
3177 leftMost = QPoint(toolBox->rect.right(), toolBox->rect.top());
3178 leftOne = QPoint(1, 0);
3179 rightOne = QPoint(-1, 0);
3180 }
3181
3182 QLine lines[3];
3183
3184 // Draw the outline
3185 painter->setPen(borderColor);
3186 lines[0] = QLine(rightMost, rightEdge);
3187 lines[1] = QLine(rightEdge + leftOne, leftEdge);
3188 lines[2] = QLine(leftEdge + leftOne, leftMost);
3189 painter->drawLines(lines, 3);
3190 painter->setPen(toolBox->palette.base().color());
3191 lines[0] = QLine(rightMost + downOne, rightEdge + downOne);
3192 lines[1] = QLine(rightEdge + leftOne + downOne, leftEdge + downOne);
3193 lines[2] = QLine(leftEdge + leftOne + downOne, leftMost + downOne);
3194 painter->drawLines(lines, 3);
3195
3196 painter->restore();
3197 }
3198 break;
3199 #endif // QT_NO_TOOLBOX
3200 #ifndef QT_NO_SPLITTER
3201 case CE_Splitter:
3202 if ((option->state & State_Enabled) && (option->state & State_MouseOver))
3203 painter->fillRect(option->rect, QColor(255, 255, 255, 128));
3204 if (option->state & State_Horizontal) {
3205 int height = option->rect.height() / 3;
3206 QRect rect(option->rect.left() + (option->rect.width() / 2 - 1),
3207 option->rect.center().y() - height / 2, 3, height);
3208 qt_plastique_draw_handle(painter, option, rect, Qt::Horizontal, widget);
3209 } else {
3210 int width = option->rect.width() / 3;
3211 QRect rect(option->rect.center().x() - width / 2,
3212 option->rect.top() + (option->rect.height() / 2) - 1, width, 3);
3213 qt_plastique_draw_handle(painter, option, rect, Qt::Vertical, widget);
3214 }
3215 break;
3216 #endif // QT_NO_SPLITTER
3217 #ifndef QT_NO_DOCKWIDGET
3218 case CE_DockWidgetTitle:
3219 if (const QStyleOptionDockWidget *dockWidget = qstyleoption_cast<const QStyleOptionDockWidget *>(option)) {
3220 painter->save();
3221
3222 const QStyleOptionDockWidgetV2 *v2
3223 = qstyleoption_cast<const QStyleOptionDockWidgetV2*>(dockWidget);
3224 bool verticalTitleBar = v2 == 0 ? false : v2->verticalTitleBar;
3225
3226 // Find text width and title rect
3227 int textWidth = option->fontMetrics.width(dockWidget->title);
3228 int margin = 4;
3229 QRect titleRect = subElementRect(SE_DockWidgetTitleBarText, option, widget);
3230 QRect rect = dockWidget->rect;
3231
3232 if (verticalTitleBar) {
3233 QRect r = rect;
3234 QSize s = r.size();
3235 s.transpose();
3236 r.setSize(s);
3237
3238 titleRect = QRect(r.left() + rect.bottom()
3239 - titleRect.bottom(),
3240 r.top() + titleRect.left() - rect.left(),
3241 titleRect.height(), titleRect.width());
3242
3243 painter->translate(r.left(), r.top() + r.width());
3244 painter->rotate(-90);
3245 painter->translate(-r.left(), -r.top());
3246
3247 rect = r;
3248 }
3249
3250 // Chop and insert ellide into title if text is too wide
3251 QString title = elliditide(dockWidget->title, dockWidget->fontMetrics, titleRect, &textWidth);
3252
3253 // Draw the toolbar handle pattern to the left and right of the text
3254 QImage handle(qt_toolbarhandle);
3255 alphaCornerColor.setAlpha(170);
3256 handle.setColor(1, alphaCornerColor.rgba());
3257 handle.setColor(2, mergedColors(alphaCornerColor, option->palette.light().color()).rgba());
3258 handle.setColor(3, option->palette.light().color().rgba());
3259
3260 if (title.isEmpty()) {
3261 // Joint handle if there's no title
3262 QRect r;
3263 #ifdef QT3_SUPPORT
3264 // Q3DockWindow doesn't need space for buttons
3265 if (widget && widget->inherits("Q3DockWindowTitleBar")) {
3266 r = rect;
3267 } else
3268 #endif
3269 r.setRect(titleRect.left(), titleRect.top(), titleRect.width(), titleRect.bottom());
3270 int nchunks = (r.width() / handle.width()) - 1;
3271 int indent = (r.width() - (nchunks * handle.width())) / 2;
3272 for (int i = 0; i < nchunks; ++i) {
3273 painter->drawImage(QPoint(r.left() + indent + i * handle.width(),
3274 r.center().y() - handle.height() / 2),
3275 handle);
3276 }
3277 } else {
3278 // Handle pattern to the left of the title
3279 QRect leftSide(titleRect.left(), titleRect.top(),
3280 titleRect.width() / 2 - textWidth / 2 - margin, titleRect.bottom());
3281 int nchunks = leftSide.width() / handle.width();
3282 int indent = (leftSide.width() - (nchunks * handle.width())) / 2;
3283 for (int i = 0; i < nchunks; ++i) {
3284 painter->drawImage(QPoint(leftSide.left() + indent
3285 + i * handle.width(),
3286 leftSide.center().y()
3287 - handle.height() / 2),
3288 handle);
3289 }
3290
3291 // Handle pattern to the right of the title
3292 QRect rightSide = titleRect.adjusted(titleRect.width() / 2 + textWidth / 2 + margin, 0, 0, 0);
3293 nchunks = rightSide.width() / handle.width();
3294 indent = (rightSide.width() - (nchunks * handle.width())) / 2;
3295 for (int j = 0; j < nchunks; ++j) {
3296 painter->drawImage(QPoint(rightSide.left() + indent + j * handle.width(),
3297 rightSide.center().y() - handle.height() / 2),
3298 handle);
3299 }
3300 }
3301
3302 // Draw the text centered
3303 QFont font = painter->font();
3304 font.setPointSize(QFontInfo(font).pointSize() - 1);
3305 painter->setFont(font);
3306 painter->setPen(dockWidget->palette.windowText().color());
3307 painter->drawText(titleRect,
3308 int(Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextShowMnemonic),
3309 title);
3310
3311 painter->restore();
3312 }
3313
3314 break;
3315 #endif // QT_NO_DOCKWIDGET
3316 #ifndef QT_NO_TOOLBAR
3317 case CE_ToolBar:
3318 if (const QStyleOptionToolBar *toolBar = qstyleoption_cast<const QStyleOptionToolBar *>(option)) {
3319 // Draws the light line above and the dark line below menu bars and
3320 // tool bars.
3321 QPen oldPen = painter->pen();
3322 if (toolBar->toolBarArea == Qt::TopToolBarArea) {
3323 if (toolBar->positionOfLine == QStyleOptionToolBar::End
3324 || toolBar->positionOfLine == QStyleOptionToolBar::OnlyOne) {
3325 // The end and onlyone top toolbar lines draw a double
3326 // line at the bottom to blend with the central
3327 // widget.
3328 painter->setPen(option->palette.background().color().lighter(104));
3329 painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
3330 painter->setPen(alphaCornerColor);
3331 painter->drawLine(option->rect.left(), option->rect.bottom() - 1,
3332 option->rect.right(), option->rect.bottom() - 1);
3333 } else {
3334 // All others draw a single dark line at the bottom.
3335 painter->setPen(alphaCornerColor);
3336 painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
3337 }
3338 // All top toolbar lines draw a light line at the top.
3339 painter->setPen(option->palette.background().color().lighter(104));
3340 painter->drawLine(option->rect.topLeft(), option->rect.topRight());
3341 } else if (toolBar->toolBarArea == Qt::BottomToolBarArea) {
3342 if (toolBar->positionOfLine == QStyleOptionToolBar::End
3343 || toolBar->positionOfLine == QStyleOptionToolBar::Middle) {
3344 // The end and middle bottom tool bar lines draw a dark
3345 // line at the bottom.
3346 painter->setPen(alphaCornerColor);
3347 painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
3348 }
3349 if (toolBar->positionOfLine == QStyleOptionToolBar::Beginning
3350 || toolBar->positionOfLine == QStyleOptionToolBar::OnlyOne) {
3351 // The beginning and only one tool bar lines draw a
3352 // double line at the bottom to blend with the
3353 // status bar.
3354 // ### The styleoption could contain whether the
3355 // main window has a menu bar and a status bar, and
3356 // possibly dock widgets.
3357 painter->setPen(alphaCornerColor);
3358 painter->drawLine(option->rect.left(), option->rect.bottom() - 1,
3359 option->rect.right(), option->rect.bottom() - 1);
3360 painter->setPen(option->palette.background().color().lighter(104));
3361 painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
3362 }
3363 if (toolBar->positionOfLine == QStyleOptionToolBar::End) {
3364 painter->setPen(alphaCornerColor);
3365 painter->drawLine(option->rect.topLeft(), option->rect.topRight());
3366 painter->setPen(option->palette.background().color().lighter(104));
3367 painter->drawLine(option->rect.left(), option->rect.top() + 1,
3368 option->rect.right(), option->rect.top() + 1);
3369
3370 } else {
3371 // All other bottom toolbars draw a light line at the top.
3372 painter->setPen(option->palette.background().color().lighter(104));
3373 painter->drawLine(option->rect.topLeft(), option->rect.topRight());
3374 }
3375 }
3376 if (toolBar->toolBarArea == Qt::LeftToolBarArea) {
3377 if (toolBar->positionOfLine == QStyleOptionToolBar::Middle
3378 || toolBar->positionOfLine == QStyleOptionToolBar::End) {
3379 // The middle and left end toolbar lines draw a light
3380 // line to the left.
3381 painter->setPen(option->palette.background().color().lighter(104));
3382 painter->drawLine(option->rect.topLeft(), option->rect.bottomLeft());
3383 }
3384 if (toolBar->positionOfLine == QStyleOptionToolBar::End) {
3385 // All other left toolbar lines draw a dark line to the right
3386 painter->setPen(alphaCornerColor);
3387 painter->drawLine(option->rect.right() - 1, option->rect.top(),
3388 option->rect.right() - 1, option->rect.bottom());
3389 painter->setPen(option->palette.background().color().lighter(104));
3390 painter->drawLine(option->rect.topRight(), option->rect.bottomRight());
3391 } else {
3392 // All other left toolbar lines draw a dark line to the right
3393 painter->setPen(alphaCornerColor);
3394 painter->drawLine(option->rect.topRight(), option->rect.bottomRight());
3395 }
3396 } else if (toolBar->toolBarArea == Qt::RightToolBarArea) {
3397 if (toolBar->positionOfLine == QStyleOptionToolBar::Middle
3398 || toolBar->positionOfLine == QStyleOptionToolBar::End) {
3399 // Right middle and end toolbar lines draw the dark right line
3400 painter->setPen(alphaCornerColor);
3401 painter->drawLine(option->rect.topRight(), option->rect.bottomRight());
3402 }
3403 if (toolBar->positionOfLine == QStyleOptionToolBar::End
3404 || toolBar->positionOfLine == QStyleOptionToolBar::OnlyOne) {
3405 // The right end and single toolbar draws the dark
3406 // line on its left edge
3407 painter->setPen(alphaCornerColor);
3408 painter->drawLine(option->rect.topLeft(), option->rect.bottomLeft());
3409 // And a light line next to it
3410 painter->setPen(option->palette.background().color().lighter(104));
3411 painter->drawLine(option->rect.left() + 1, option->rect.top(),
3412 option->rect.left() + 1, option->rect.bottom());
3413 } else {
3414 // Other right toolbars draw a light line on its left edge
3415 painter->setPen(option->palette.background().color().lighter(104));
3416 painter->drawLine(option->rect.topLeft(), option->rect.bottomLeft());
3417 }
3418 }
3419 painter->setPen(oldPen);
3420 }
3421 break;
3422 #endif // QT_NO_TOOLBAR
3423 #ifndef QT_NO_SCROLLBAR
3424 case CE_ScrollBarAddLine:
3425 if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
3426
3427 bool horizontal = scrollBar->orientation == Qt::Horizontal;
3428 bool reverse = scrollBar->direction == Qt::RightToLeft;
3429 bool sunken = scrollBar->state & State_Sunken;
3430
3431 QString addLinePixmapName = QStyleHelper::uniqueName(QLatin1String("scrollbar_addline"), option, option->rect.size());
3432 QPixmap cache;
3433 if (!QPixmapCache::find(addLinePixmapName, cache)) {
3434 cache = QPixmap(option->rect.size());
3435 cache.fill(Qt::white);
3436 QRect pixmapRect(0, 0, cache.width(), cache.height());
3437 QPainter addLinePainter(&cache);
3438 addLinePainter.fillRect(pixmapRect, option->palette.background());
3439
3440 if (option->state & State_Enabled) {
3441 // Gradient
3442 QLinearGradient gradient(pixmapRect.center().x(), pixmapRect.top() + 2,
3443 pixmapRect.center().x(), pixmapRect.bottom() - 2);
3444 if ((scrollBar->activeSubControls & SC_ScrollBarAddLine) && sunken) {
3445 gradient.setColorAt(0, gradientStopColor);
3446 gradient.setColorAt(1, gradientStopColor);
3447 } else {
3448 gradient.setColorAt(0, gradientStartColor.lighter(105));
3449 gradient.setColorAt(1, gradientStopColor);
3450 }
3451 addLinePainter.fillRect(pixmapRect.left() + 2, pixmapRect.top() + 2,
3452 pixmapRect.right() - 3, pixmapRect.bottom() - 3,
3453 gradient);
3454 }
3455
3456 // Details
3457 QImage addButton;
3458 if (horizontal) {
3459 addButton = QImage(reverse ? qt_scrollbar_button_left : qt_scrollbar_button_right);
3460 } else {
3461 addButton = QImage(qt_scrollbar_button_down);
3462 }
3463 addButton.setColor(1, alphaCornerColor.rgba());
3464 addButton.setColor(2, borderColor.rgba());
3465 if ((scrollBar->activeSubControls & SC_ScrollBarAddLine) && sunken) {
3466 addButton.setColor(3, gradientStopColor.rgba());
3467 addButton.setColor(4, gradientStopColor.rgba());
3468 } else {
3469 addButton.setColor(3, gradientStartColor.lighter(105).rgba());
3470 addButton.setColor(4, gradientStopColor.rgba());
3471 }
3472 addButton.setColor(5, scrollBar->palette.text().color().rgba());
3473 addLinePainter.drawImage(pixmapRect, addButton);
3474
3475 // Arrow
3476 if (horizontal) {
3477 QImage arrow(reverse ? qt_scrollbar_button_arrow_left : qt_scrollbar_button_arrow_right);
3478 arrow.setColor(1, scrollBar->palette.foreground().color().rgba());
3479
3480 if ((scrollBar->activeSubControls & SC_ScrollBarAddLine) && sunken)
3481 addLinePainter.translate(1, 1);
3482 addLinePainter.drawImage(QPoint(pixmapRect.center().x() - 2, pixmapRect.center().y() - 3), arrow);
3483 } else {
3484 QImage arrow(qt_scrollbar_button_arrow_down);
3485 arrow.setColor(1, scrollBar->palette.foreground().color().rgba());
3486
3487 if ((scrollBar->activeSubControls & SC_ScrollBarAddLine) && sunken)
3488 addLinePainter.translate(1, 1);
3489 addLinePainter.drawImage(QPoint(pixmapRect.center().x() - 3, pixmapRect.center().y() - 2), arrow);
3490 }
3491 addLinePainter.end();
3492 QPixmapCache::insert(addLinePixmapName, cache);
3493 }
3494 painter->drawPixmap(option->rect.topLeft(), cache);
3495 }
3496 break;
3497 case CE_ScrollBarSubPage:
3498 case CE_ScrollBarAddPage:
3499 if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
3500 bool sunken = scrollBar->state & State_Sunken;
3501 bool horizontal = scrollBar->orientation == Qt::Horizontal;
3502
3503 QString groovePixmapName = QStyleHelper::uniqueName(QLatin1String("scrollbar_groove"), option, option->rect.size());
3504 if (sunken)
3505 groovePixmapName += QLatin1String("-sunken");
3506 if (element == CE_ScrollBarAddPage)
3507 groovePixmapName += QLatin1String("-addpage");
3508
3509 QPixmap cache;
3510 if (!QPixmapCache::find(groovePixmapName, cache)) {
3511 cache = QPixmap(option->rect.size());
3512 cache.fill(option->palette.background().color());
3513 QPainter groovePainter(&cache);
3514 QRect pixmapRect = QRect(0, 0, option->rect.width(), option->rect.height());
3515 QColor color = scrollBar->palette.base().color().darker(sunken ? 125 : 100);
3516 groovePainter.setBrushOrigin((element == CE_ScrollBarAddPage) ? pixmapRect.width() : 0,
3517 (element == CE_ScrollBarAddPage) ? pixmapRect.height() : 0);
3518 groovePainter.fillRect(pixmapRect, QBrush(color, Qt::Dense4Pattern));
3519
3520 QColor edgeColor = scrollBar->palette.base().color().darker(125);
3521 if (horizontal) {
3522 groovePainter.setBrushOrigin((element == CE_ScrollBarAddPage) ? pixmapRect.width() : 1, 0);
3523 groovePainter.fillRect(QRect(pixmapRect.topLeft(), QSize(pixmapRect.width(), 1)),
3524 QBrush(edgeColor, Qt::Dense4Pattern));
3525 groovePainter.fillRect(QRect(pixmapRect.bottomLeft(), QSize(pixmapRect.width(), 1)),
3526 QBrush(edgeColor, Qt::Dense4Pattern));
3527 } else {
3528 groovePainter.setBrushOrigin(0, (element == CE_ScrollBarAddPage) ? pixmapRect.height() : 1);
3529 groovePainter.fillRect(QRect(pixmapRect.topLeft(), QSize(1, pixmapRect.height())),
3530 QBrush(edgeColor, Qt::Dense4Pattern));
3531 groovePainter.fillRect(QRect(pixmapRect.topRight(), QSize(1, pixmapRect.height())),
3532 QBrush(edgeColor, Qt::Dense4Pattern));
3533 }
3534
3535 groovePainter.end();
3536 QPixmapCache::insert(groovePixmapName, cache);
3537 }
3538 painter->drawPixmap(option->rect.topLeft(), cache);
3539 }
3540 break;
3541 case CE_ScrollBarSubLine:
3542 if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
3543 QRect scrollBarSubLine = scrollBar->rect;
3544
3545 bool horizontal = scrollBar->orientation == Qt::Horizontal;
3546 bool isEnabled = scrollBar->state & State_Enabled;
3547 bool reverse = scrollBar->direction == Qt::RightToLeft;
3548 bool sunken = scrollBar->state & State_Sunken;
3549
3550 // The SubLine (up/left) buttons
3551 QRect button1;
3552 QRect button2;
3553 int scrollBarExtent = proxy()->pixelMetric(PM_ScrollBarExtent, option, widget);
3554 if (horizontal) {
3555 button1.setRect(scrollBarSubLine.left(), scrollBarSubLine.top(), scrollBarExtent, scrollBarSubLine.height());
3556 button2.setRect(scrollBarSubLine.right() - (scrollBarExtent - 1), scrollBarSubLine.top(), scrollBarExtent, scrollBarSubLine.height());
3557 } else {
3558 button1.setRect(scrollBarSubLine.left(), scrollBarSubLine.top(), scrollBarSubLine.width(), scrollBarExtent);
3559 button2.setRect(scrollBarSubLine.left(), scrollBarSubLine.bottom() - (scrollBarExtent - 1), scrollBarSubLine.width(), scrollBarExtent);
3560 }
3561
3562 QString subLinePixmapName = QStyleHelper::uniqueName(QLatin1String("scrollbar_subline"), option, button1.size());
3563 QPixmap cache;
3564 if (!QPixmapCache::find(subLinePixmapName, cache)) {
3565 cache = QPixmap(button1.size());
3566 cache.fill(Qt::white);
3567 QRect pixmapRect(0, 0, cache.width(), cache.height());
3568 QPainter subLinePainter(&cache);
3569 subLinePainter.fillRect(pixmapRect, option->palette.background());
3570
3571 if (isEnabled) {
3572 // Gradients
3573 if ((scrollBar->activeSubControls & SC_ScrollBarSubLine) && sunken) {
3574 qt_plastique_draw_gradient(&subLinePainter,
3575 QRect(pixmapRect.left() + 2, pixmapRect.top() + 2,
3576 pixmapRect.right() - 3, pixmapRect.bottom() - 3),
3577 gradientStopColor,
3578 gradientStopColor);
3579 } else {
3580 qt_plastique_draw_gradient(&subLinePainter,
3581 QRect(pixmapRect.left() + 2, pixmapRect.top() + 2,
3582 pixmapRect.right() - 3, pixmapRect.bottom() - 3),
3583 gradientStartColor.lighter(105),
3584 gradientStopColor);
3585 }
3586 }
3587
3588 // Details
3589 QImage subButton;
3590 if (horizontal) {
3591 subButton = QImage(reverse ? qt_scrollbar_button_right : qt_scrollbar_button_left);
3592 } else {
3593 subButton = QImage(qt_scrollbar_button_up);
3594 }
3595 subButton.setColor(1, alphaCornerColor.rgba());
3596 subButton.setColor(2, borderColor.rgba());
3597 if ((scrollBar->activeSubControls & SC_ScrollBarSubLine) && sunken) {
3598 subButton.setColor(3, gradientStopColor.rgba());
3599 subButton.setColor(4, gradientStopColor.rgba());
3600 } else {
3601 subButton.setColor(3, gradientStartColor.lighter(105).rgba());
3602 subButton.setColor(4, gradientStopColor.rgba());
3603 }
3604 subButton.setColor(5, scrollBar->palette.text().color().rgba());
3605 subLinePainter.drawImage(pixmapRect, subButton);
3606
3607 // Arrows
3608 if (horizontal) {
3609 QImage arrow(reverse ? qt_scrollbar_button_arrow_right : qt_scrollbar_button_arrow_left);
3610 arrow.setColor(1, scrollBar->palette.foreground().color().rgba());
3611
3612 if ((scrollBar->activeSubControls & SC_ScrollBarSubLine) && sunken)
3613 subLinePainter.translate(1, 1);
3614 subLinePainter.drawImage(QPoint(pixmapRect.center().x() - 2, pixmapRect.center().y() - 3), arrow);
3615 } else {
3616 QImage arrow(qt_scrollbar_button_arrow_up);
3617 arrow.setColor(1, scrollBar->palette.foreground().color().rgba());
3618
3619 if ((scrollBar->activeSubControls & SC_ScrollBarSubLine) && sunken)
3620 subLinePainter.translate(1, 1);
3621 subLinePainter.drawImage(QPoint(pixmapRect.center().x() - 3, pixmapRect.center().y() - 2), arrow);
3622 }
3623 subLinePainter.end();
3624 QPixmapCache::insert(subLinePixmapName, cache);
3625 }
3626 painter->drawPixmap(button1.topLeft(), cache);
3627 painter->drawPixmap(button2.topLeft(), cache);
3628 }
3629 break;
3630 case CE_ScrollBarSlider:
3631 if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
3632 bool horizontal = scrollBar->orientation == Qt::Horizontal;
3633 bool isEnabled = scrollBar->state & State_Enabled;
3634
3635 // The slider
3636 if (option->rect.isValid()) {
3637 QString sliderPixmapName = QStyleHelper::uniqueName(QLatin1String("scrollbar_slider"), option, option->rect.size());
3638 if (horizontal)
3639 sliderPixmapName += QLatin1String("-horizontal");
3640
3641 QPixmap cache;
3642 if (!QPixmapCache::find(sliderPixmapName, cache)) {
3643 cache = QPixmap(option->rect.size());
3644 cache.fill(Qt::white);
3645 QRect pixmapRect(0, 0, cache.width(), cache.height());
3646 QPainter sliderPainter(&cache);
3647 bool sunken = (scrollBar->state & State_Sunken);
3648
3649 if (isEnabled) {
3650 QLinearGradient gradient(pixmapRect.left(), pixmapRect.center().y(),
3651 pixmapRect.right(), pixmapRect.center().y());
3652 if (horizontal)
3653 gradient = QLinearGradient(pixmapRect.center().x(), pixmapRect.top(),
3654 pixmapRect.center().x(), pixmapRect.bottom());
3655
3656 if (sunken) {
3657 gradient.setColorAt(0, gradientStartColor.lighter(110));
3658 gradient.setColorAt(1, gradientStopColor.lighter(105));
3659 } else {
3660 gradient.setColorAt(0, gradientStartColor.lighter(105));
3661 gradient.setColorAt(1, gradientStopColor);
3662 }
3663 sliderPainter.fillRect(pixmapRect.adjusted(2, 2, -2, -2), gradient);
3664 } else {
3665 sliderPainter.fillRect(pixmapRect.adjusted(2, 2, -2, -2), option->palette.background());
3666 }
3667
3668 sliderPainter.setPen(borderColor);
3669 sliderPainter.drawRect(pixmapRect.adjusted(0, 0, -1, -1));
3670 sliderPainter.setPen(alphaCornerColor);
3671 QPoint points[4] = {
3672 QPoint(pixmapRect.left(), pixmapRect.top()),
3673 QPoint(pixmapRect.left(), pixmapRect.bottom()),
3674 QPoint(pixmapRect.right(), pixmapRect.top()),
3675 QPoint(pixmapRect.right(), pixmapRect.bottom()) };
3676 sliderPainter.drawPoints(points, 4);
3677
3678 QLine lines[2];
3679 sliderPainter.setPen(sunken ? gradientStartColor.lighter(110) : gradientStartColor.lighter(105));
3680 lines[0] = QLine(pixmapRect.left() + 1, pixmapRect.top() + 1,
3681 pixmapRect.right() - 1, pixmapRect.top() + 1);
3682 lines[1] = QLine(pixmapRect.left() + 1, pixmapRect.top() + 2,
3683 pixmapRect.left() + 1, pixmapRect.bottom() - 2);
3684 sliderPainter.drawLines(lines, 2);
3685
3686 sliderPainter.setPen(sunken ? gradientStopColor.lighter(105) : gradientStopColor);
3687 lines[0] = QLine(pixmapRect.left() + 1, pixmapRect.bottom() - 1,
3688 pixmapRect.right() - 1, pixmapRect.bottom() - 1);
3689 lines[1] = QLine(pixmapRect.right() - 1, pixmapRect.top() + 2,
3690 pixmapRect.right() - 1, pixmapRect.bottom() - 1);
3691 sliderPainter.drawLines(lines, 2);
3692
3693 int sliderMinLength = proxy()->pixelMetric(PM_ScrollBarSliderMin, scrollBar, widget);
3694 if ((horizontal && scrollBar->rect.width() > sliderMinLength)
3695 || (!horizontal && scrollBar->rect.height() > sliderMinLength)) {
3696 QImage pattern(horizontal ? qt_scrollbar_slider_pattern_horizontal
3697 : qt_scrollbar_slider_pattern_vertical);
3698 pattern.setColor(1, alphaCornerColor.rgba());
3699 pattern.setColor(2, (sunken ? gradientStartColor.lighter(110) : gradientStartColor.lighter(105)).rgba());
3700
3701 if (horizontal) {
3702 sliderPainter.drawImage(pixmapRect.center().x() - pattern.width() / 2 + 1,
3703 pixmapRect.center().y() - 4,
3704 pattern);
3705 } else {
3706 sliderPainter.drawImage(pixmapRect.center().x() - 4,
3707 pixmapRect.center().y() - pattern.height() / 2 + 1,
3708 pattern);
3709 }
3710 }
3711 sliderPainter.end();
3712 // insert the slider into the cache
3713 QPixmapCache::insert(sliderPixmapName, cache);
3714 }
3715 painter->drawPixmap(option->rect.topLeft(), cache);
3716 }
3717 }
3718 break;
3719 #endif
3720 #ifndef QT_NO_COMBOBOX
3721 case CE_ComboBoxLabel:
3722 if (const QStyleOptionComboBox *comboBox = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
3723 painter->save();
3724 if (!comboBox->editable) {
3725 // Plastique's non-editable combo box is drawn as a button, so
3726 // we need the label to be drawn using ButtonText where it
3727 // would usually use Text.
3728 painter->setPen(QPen(comboBox->palette.buttonText(), 0));
3729 QWindowsStyle::drawControl(element, option, painter, widget);
3730 } else if (!comboBox->currentIcon.isNull()) {
3731 {
3732 QRect editRect = proxy()->subControlRect(CC_ComboBox, comboBox, SC_ComboBoxEditField, widget);
3733 if (comboBox->direction == Qt::RightToLeft)
3734 editRect.adjust(0, 2, -2, -2);
3735 else
3736 editRect.adjust(2, 2, 0, -2);
3737 painter->save();
3738 painter->setClipRect(editRect);
3739 if (!comboBox->currentIcon.isNull()) {
3740 QIcon::Mode mode = comboBox->state & State_Enabled ? QIcon::Normal
3741 : QIcon::Disabled;
3742 QPixmap pixmap = comboBox->currentIcon.pixmap(comboBox->iconSize, mode);
3743 QRect iconRect(editRect);
3744 iconRect.setWidth(comboBox->iconSize.width() + 5);
3745 iconRect = alignedRect(comboBox->direction,
3746 Qt::AlignLeft | Qt::AlignVCenter,
3747 iconRect.size(), editRect);
3748 painter->fillRect(iconRect, option->palette.brush(QPalette::Base));
3749 proxy()->drawItemPixmap(painter, iconRect, Qt::AlignCenter, pixmap);
3750 }
3751 painter->restore();
3752 }
3753 } else {
3754 QWindowsStyle::drawControl(element, option, painter, widget);
3755 }
3756
3757 painter->restore();
3758 }
3759 break;
3760 #endif
3761 default:
3762 QWindowsStyle::drawControl(element, option, painter, widget);
3763 break;
3764 }
3765 }
3766
3767 /*!
3768 \reimp
3769 */
drawComplexControl(ComplexControl control,const QStyleOptionComplex * option,QPainter * painter,const QWidget * widget) const3770 void QPlastiqueStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
3771 QPainter *painter, const QWidget *widget) const
3772 {
3773 QColor borderColor = option->palette.background().color().darker(178);
3774 QColor alphaCornerColor;
3775 if (widget) {
3776 // ### backgroundrole/foregroundrole should be part of the style option
3777 alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), borderColor);
3778 } else {
3779 alphaCornerColor = mergedColors(option->palette.background().color(), borderColor);
3780 }
3781 QColor gradientStartColor = option->palette.button().color().lighter(104);
3782 QColor gradientStopColor = option->palette.button().color().darker(105);
3783
3784 switch (control) {
3785 #ifndef QT_NO_SLIDER
3786 case CC_Slider:
3787 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
3788 QRect grooveRegion = proxy()->subControlRect(CC_Slider, option, SC_SliderGroove, widget);
3789 QRect handle = proxy()->subControlRect(CC_Slider, option, SC_SliderHandle, widget);
3790 bool horizontal = slider->orientation == Qt::Horizontal;
3791 bool ticksAbove = slider->tickPosition & QSlider::TicksAbove;
3792 bool ticksBelow = slider->tickPosition & QSlider::TicksBelow;
3793
3794 QRect groove;
3795 //The clickable region is 5 px wider than the visible groove for improved usability
3796 if (grooveRegion.isValid())
3797 groove = horizontal ? grooveRegion.adjusted(0, 5, 0, -5) : grooveRegion.adjusted(5, 0, -5, 0);
3798
3799
3800 QPixmap cache;
3801
3802 if ((option->subControls & SC_SliderGroove) && groove.isValid()) {
3803 BEGIN_STYLE_PIXMAPCACHE(QString::fromLatin1("slider_groove-%0-%1").arg(ticksAbove).arg(ticksBelow))
3804 p->fillRect(groove, option->palette.background());
3805
3806 // draw groove
3807 if (horizontal) {
3808 p->setPen(borderColor);
3809 const QLine lines[4] = {
3810 QLine(groove.left() + 1, groove.top(),
3811 groove.right() - 1, groove.top()),
3812 QLine(groove.left() + 1, groove.bottom(),
3813 groove.right() - 1, groove.bottom()),
3814 QLine(groove.left(), groove.top() + 1,
3815 groove.left(), groove.bottom() - 1),
3816 QLine(groove.right(), groove.top() + 1,
3817 groove.right(), groove.bottom() - 1) };
3818 p->drawLines(lines, 4);
3819
3820 p->setPen(alphaCornerColor);
3821 const QPoint points[4] = {
3822 QPoint(groove.left(), groove.top()),
3823 QPoint(groove.left(), groove.bottom()),
3824 QPoint(groove.right(), groove.top()),
3825 QPoint(groove.right(), groove.bottom()) };
3826 p->drawPoints(points, 4);
3827 } else {
3828 p->setPen(borderColor);
3829 const QLine lines[4] = {
3830 QLine(groove.left() + 1, groove.top(),
3831 groove.right() - 1, groove.top()),
3832 QLine(groove.left() + 1, groove.bottom(),
3833 groove.right() - 1, groove.bottom()),
3834 QLine(groove.left(), groove.top() + 1,
3835 groove.left(), groove.bottom() - 1),
3836 QLine(groove.right(), groove.top() + 1,
3837 groove.right(), groove.bottom() - 1) };
3838 p->drawLines(lines, 4);
3839
3840 p->setPen(alphaCornerColor);
3841 const QPoint points[4] = {
3842 QPoint(groove.left(), groove.top()),
3843 QPoint(groove.right(), groove.top()),
3844 QPoint(groove.left(), groove.bottom()),
3845 QPoint(groove.right(), groove.bottom()) };
3846 p->drawPoints(points, 4);
3847 }
3848 END_STYLE_PIXMAPCACHE
3849 }
3850
3851 if ((option->subControls & SC_SliderHandle) && handle.isValid()) {
3852 QString handlePixmapName = QStyleHelper::uniqueName(QLatin1String("slider_handle"), option, handle.size());
3853 if (ticksAbove && !ticksBelow)
3854 handlePixmapName += QLatin1String("-flipped");
3855 if ((option->activeSubControls & SC_SliderHandle) && (option->state & State_Sunken))
3856 handlePixmapName += QLatin1String("-sunken");
3857
3858 if (!QPixmapCache::find(handlePixmapName, cache)) {
3859 cache = QPixmap(handle.size());
3860 cache.fill(Qt::white);
3861 QRect pixmapRect(0, 0, handle.width(), handle.height());
3862 QPainter handlePainter(&cache);
3863 handlePainter.fillRect(pixmapRect, option->palette.background());
3864
3865 // draw handle
3866 if (horizontal) {
3867 QPainterPath path;
3868 if (ticksAbove && !ticksBelow) {
3869 path.moveTo(QPoint(pixmapRect.right(), pixmapRect.bottom()));
3870 path.lineTo(QPoint(pixmapRect.right(), pixmapRect.bottom() - 10));
3871 path.lineTo(QPoint(pixmapRect.right() - 5, pixmapRect.bottom() - 14));
3872 path.lineTo(QPoint(pixmapRect.left() + 1, pixmapRect.bottom() - 10));
3873 path.lineTo(QPoint(pixmapRect.left() + 1, pixmapRect.bottom()));
3874 path.lineTo(QPoint(pixmapRect.right(), pixmapRect.bottom()));
3875 } else {
3876 path.moveTo(QPoint(pixmapRect.right(), pixmapRect.top() + 1));
3877 path.lineTo(QPoint(pixmapRect.right(), pixmapRect.top() + 10));
3878 path.lineTo(QPoint(pixmapRect.right() - 5, pixmapRect.top() + 14));
3879 path.lineTo(QPoint(pixmapRect.left() + 1, pixmapRect.top() + 10));
3880 path.lineTo(QPoint(pixmapRect.left() + 1, pixmapRect.top() + 1));
3881 path.lineTo(QPoint(pixmapRect.right(), pixmapRect.top() + 1));
3882 }
3883 if (slider->state & State_Enabled) {
3884 QLinearGradient gradient(pixmapRect.center().x(), pixmapRect.top(),
3885 pixmapRect.center().x(), pixmapRect.bottom());
3886 if ((option->activeSubControls & SC_SliderHandle) && (option->state & State_Sunken)) {
3887 gradient.setColorAt(0, gradientStartColor.lighter(110));
3888 gradient.setColorAt(1, gradientStopColor.lighter(110));
3889 } else {
3890 gradient.setColorAt(0, gradientStartColor);
3891 gradient.setColorAt(1, gradientStopColor);
3892 }
3893 handlePainter.fillPath(path, gradient);
3894 } else {
3895 handlePainter.fillPath(path, slider->palette.background());
3896 }
3897 } else {
3898 QPainterPath path;
3899 if (ticksAbove && !ticksBelow) {
3900 path.moveTo(QPoint(pixmapRect.right(), pixmapRect.top() + 1));
3901 path.lineTo(QPoint(pixmapRect.right() - 10, pixmapRect.top() + 1));
3902 path.lineTo(QPoint(pixmapRect.right() - 14, pixmapRect.top() + 5));
3903 path.lineTo(QPoint(pixmapRect.right() - 10, pixmapRect.bottom()));
3904 path.lineTo(QPoint(pixmapRect.right(), pixmapRect.bottom()));
3905 path.lineTo(QPoint(pixmapRect.right(), pixmapRect.top() + 1));
3906 } else {
3907 path.moveTo(QPoint(pixmapRect.left() + 1, pixmapRect.top() + 1));
3908 path.lineTo(QPoint(pixmapRect.left() + 10, pixmapRect.top() + 1));
3909 path.lineTo(QPoint(pixmapRect.left() + 14, pixmapRect.top() + 5));
3910 path.lineTo(QPoint(pixmapRect.left() + 10, pixmapRect.bottom()));
3911 path.lineTo(QPoint(pixmapRect.left() + 1, pixmapRect.bottom()));
3912 path.lineTo(QPoint(pixmapRect.left() + 1, pixmapRect.top() + 1));
3913 }
3914 if (slider->state & State_Enabled) {
3915 QLinearGradient gradient(pixmapRect.center().x(), pixmapRect.top(),
3916 pixmapRect.center().x(), pixmapRect.bottom());
3917 gradient.setColorAt(0, gradientStartColor);
3918 gradient.setColorAt(1, gradientStopColor);
3919 handlePainter.fillPath(path, gradient);
3920 } else {
3921 handlePainter.fillPath(path, slider->palette.background());
3922 }
3923 }
3924
3925 QImage image;
3926 if (horizontal) {
3927 image = QImage((ticksAbove && !ticksBelow) ? qt_plastique_slider_horizontalhandle_up : qt_plastique_slider_horizontalhandle);
3928 } else {
3929 image = QImage((ticksAbove && !ticksBelow) ? qt_plastique_slider_verticalhandle_left : qt_plastique_slider_verticalhandle);
3930 }
3931
3932 image.setColor(1, borderColor.rgba());
3933 image.setColor(2, gradientStartColor.rgba());
3934 image.setColor(3, alphaCornerColor.rgba());
3935 if (option->state & State_Enabled) {
3936 image.setColor(4, 0x80ffffff);
3937 image.setColor(5, 0x25000000);
3938 }
3939 handlePainter.drawImage(pixmapRect, image);
3940 handlePainter.end();
3941 QPixmapCache::insert(handlePixmapName, cache);
3942 }
3943
3944 painter->drawPixmap(handle.topLeft(), cache);
3945
3946 if (slider->state & State_HasFocus) {
3947 QStyleOptionFocusRect fropt;
3948 fropt.QStyleOption::operator=(*slider);
3949 fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
3950 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
3951 }
3952 }
3953
3954 if (option->subControls & SC_SliderTickmarks) {
3955 QPen oldPen = painter->pen();
3956 painter->setPen(borderColor);
3957 int tickSize = proxy()->pixelMetric(PM_SliderTickmarkOffset, option, widget);
3958 int available = proxy()->pixelMetric(PM_SliderSpaceAvailable, slider, widget);
3959 int interval = slider->tickInterval;
3960 if (interval <= 0) {
3961 interval = slider->singleStep;
3962 if (QStyle::sliderPositionFromValue(slider->minimum, slider->maximum, interval,
3963 available)
3964 - QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
3965 0, available) < 3)
3966 interval = slider->pageStep;
3967 }
3968 if (interval <= 0)
3969 interval = 1;
3970
3971 int v = slider->minimum;
3972 int len = proxy()->pixelMetric(PM_SliderLength, slider, widget);
3973 QVarLengthArray<QLine, 32> lines;
3974 while (v <= slider->maximum + 1) {
3975 if (v == slider->maximum + 1 && interval == 1)
3976 break;
3977 const int v_ = qMin(v, slider->maximum);
3978 int pos = sliderPositionFromValue(slider->minimum, slider->maximum,
3979 v_, (horizontal
3980 ? slider->rect.width()
3981 : slider->rect.height()) - len,
3982 slider->upsideDown) + len / 2;
3983
3984 int extra = 2 - ((v_ == slider->minimum || v_ == slider->maximum) ? 1 : 0);
3985
3986 if (horizontal) {
3987 if (ticksAbove) {
3988 lines.append(QLine(pos, slider->rect.top() + extra,
3989 pos, slider->rect.top() + tickSize));
3990 }
3991 if (ticksBelow) {
3992 lines.append(QLine(pos, slider->rect.bottom() - extra,
3993 pos, slider->rect.bottom() - tickSize));
3994 }
3995 } else {
3996 if (ticksAbove) {
3997 lines.append(QLine(slider->rect.left() + extra, pos,
3998 slider->rect.left() + tickSize, pos));
3999 }
4000 if (ticksBelow) {
4001 lines.append(QLine(slider->rect.right() - extra, pos,
4002 slider->rect.right() - tickSize, pos));
4003 }
4004 }
4005
4006 // in the case where maximum is max int
4007 int nextInterval = v + interval;
4008 if (nextInterval < v)
4009 break;
4010 v = nextInterval;
4011 }
4012 painter->drawLines(lines.constData(), lines.size());
4013 painter->setPen(oldPen);
4014 }
4015 }
4016 break;
4017 #endif // QT_NO_SLIDER
4018 #ifndef QT_NO_SPINBOX
4019 case CC_SpinBox:
4020 if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
4021 painter->save();
4022 bool upSunken = (spinBox->activeSubControls & SC_SpinBoxUp) && (spinBox->state & (State_Sunken | State_On));
4023 bool downSunken = (spinBox->activeSubControls & SC_SpinBoxDown) && (spinBox->state & (State_Sunken | State_On));
4024 bool reverse = (spinBox->direction == Qt::RightToLeft);
4025
4026 // Rects
4027 QRect upRect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxUp, widget);
4028 QRect downRect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxDown, widget);
4029 QRect buttonRect = upRect | downRect;
4030
4031 // Brushes
4032 QBrush corner = qMapBrushToRect(option->palette.shadow(), buttonRect);
4033 qBrushSetAlphaF(&corner, qreal(0.25));
4034 QBrush border = qMapBrushToRect(option->palette.shadow(), buttonRect);
4035 qBrushSetAlphaF(&border, qreal(0.4));
4036
4037 QVarLengthArray<QPoint, 4> points;
4038
4039 Q_D(const QPlastiqueStyle);
4040 if (spinBox->buttonSymbols == QAbstractSpinBox::NoButtons) {
4041 QRect filledRect = option->rect.adjusted(1, 1, -1, -1);
4042 QBrush baseBrush = qMapBrushToRect(option->palette.base(), filledRect);
4043 painter->setBrushOrigin(filledRect.topLeft());
4044 painter->fillRect(filledRect.adjusted(1, 1, -1, -1), baseBrush);
4045 qt_plastique_draw_frame(painter, option->rect, option, QFrame::Sunken);
4046 } else {
4047 d->drawPartialFrame(painter,
4048 option,
4049 proxy()->subControlRect(CC_SpinBox, spinBox, SC_SpinBoxEditField, widget),
4050 widget);
4051 }
4052 // Paint buttons
4053 if (spinBox->buttonSymbols == QAbstractSpinBox::NoButtons) {
4054 painter->restore();
4055 break;
4056 }
4057 // Button outlines
4058 painter->setPen(QPen(border, 0));
4059 if (!reverse)
4060 painter->drawLine(buttonRect.topLeft() + QPoint(0, 1), buttonRect.bottomLeft() + QPoint(0, -1));
4061 else
4062 painter->drawLine(buttonRect.topRight() + QPoint(0, -1), buttonRect.bottomRight() + QPoint(0, 1));
4063
4064 if (!reverse) {
4065 const QLine lines[4] = {
4066 QLine(upRect.left(), upRect.top(), upRect.right() - 2, upRect.top()),
4067 QLine(upRect.left() + 1, upRect.bottom(), upRect.right() - 1, upRect.bottom()),
4068 QLine(downRect.left(), downRect.bottom(), downRect.right() - 2, downRect.bottom()),
4069 QLine(buttonRect.right(), buttonRect.top() + 2, buttonRect.right(), buttonRect.bottom() - 2) };
4070 painter->drawLines(lines, 4);
4071
4072 points.append(QPoint(upRect.right() - 1, upRect.top() + 1));
4073 points.append(QPoint(downRect.right() - 1, downRect.bottom() - 1));
4074 painter->drawPoints(points.constData(), points.size());
4075 points.clear();
4076 painter->setPen(QPen(corner, 0));
4077 points.append(QPoint(upRect.right() - 1, upRect.top()));
4078 points.append(QPoint(upRect.right(), upRect.top() + 1));
4079 points.append(QPoint(upRect.right(), downRect.bottom() - 1));
4080 points.append(QPoint(upRect.right() - 1, downRect.bottom()));
4081 } else {
4082 const QLine lines[4] = {
4083 QLine(upRect.right(), upRect.top(), upRect.left() + 2, upRect.top()),
4084 QLine(upRect.right() - 1, upRect.bottom(), upRect.left() + 1, upRect.bottom()),
4085 QLine(downRect.right(), downRect.bottom(), downRect.left() + 2, downRect.bottom()),
4086 QLine(buttonRect.left(), buttonRect.top() + 2, buttonRect.left(), buttonRect.bottom() - 2) };
4087 painter->drawLines(lines, 4);
4088
4089 points.append(QPoint(upRect.left() + 1, upRect.top() + 1));
4090 points.append(QPoint(downRect.left() + 1, downRect.bottom() - 1));
4091 painter->drawPoints(points.constData(), points.size());
4092 points.clear();
4093 painter->setPen(QPen(corner, 0));
4094 points.append(QPoint(upRect.left() + 1, upRect.top()));
4095 points.append(QPoint(upRect.left(), upRect.top() + 1));
4096 points.append(QPoint(upRect.left(), downRect.bottom() - 1));
4097 points.append(QPoint(upRect.left() + 1, downRect.bottom()));
4098 }
4099 painter->drawPoints(points.constData(), points.size());
4100 points.clear();
4101
4102 // Button colors
4103 QBrush buttonGradientBrush;
4104 QBrush leftLineGradientBrush;
4105 QBrush rightLineGradientBrush;
4106 QBrush sunkenButtonGradientBrush;
4107 QBrush sunkenLeftLineGradientBrush;
4108 QBrush sunkenRightLineGradientBrush;
4109 QBrush buttonBrush = qMapBrushToRect(option->palette.button(), buttonRect);
4110 if (buttonBrush.gradient() || !buttonBrush.texture().isNull()) {
4111 buttonGradientBrush = buttonBrush;
4112 sunkenButtonGradientBrush = qBrushDark(buttonBrush, 108);
4113 leftLineGradientBrush = qBrushLight(buttonBrush, 105);
4114 rightLineGradientBrush = qBrushDark(buttonBrush, 105);
4115 sunkenLeftLineGradientBrush = qBrushDark(buttonBrush, 110);
4116 sunkenRightLineGradientBrush = qBrushDark(buttonBrush, 106);
4117 } else {
4118 // Generate gradients
4119 QLinearGradient buttonGradient(buttonRect.topLeft(), buttonRect.bottomLeft());
4120 buttonGradient.setColorAt(0.0, buttonBrush.color().lighter(104));
4121 buttonGradient.setColorAt(1.0, buttonBrush.color().darker(110));
4122 buttonGradientBrush = QBrush(buttonGradient);
4123
4124 QLinearGradient buttonGradient2(buttonRect.topLeft(), buttonRect.bottomLeft());
4125 buttonGradient2.setColorAt(0.0, buttonBrush.color().darker(113));
4126 buttonGradient2.setColorAt(1.0, buttonBrush.color().darker(103));
4127 sunkenButtonGradientBrush = QBrush(buttonGradient2);
4128
4129 QLinearGradient buttonGradient3(buttonRect.topLeft(), buttonRect.bottomLeft());
4130 buttonGradient3.setColorAt(0.0, buttonBrush.color().lighter(105));
4131 buttonGradient3.setColorAt(1.0, buttonBrush.color());
4132 leftLineGradientBrush = QBrush(buttonGradient3);
4133
4134 QLinearGradient buttonGradient4(buttonRect.topLeft(), buttonRect.bottomLeft());
4135 buttonGradient4.setColorAt(0.0, buttonBrush.color());
4136 buttonGradient4.setColorAt(1.0, buttonBrush.color().darker(110));
4137 rightLineGradientBrush = QBrush(buttonGradient4);
4138
4139 QLinearGradient buttonGradient5(buttonRect.topLeft(), buttonRect.bottomLeft());
4140 buttonGradient5.setColorAt(0.0, buttonBrush.color().darker(113));
4141 buttonGradient5.setColorAt(1.0, buttonBrush.color().darker(107));
4142 sunkenLeftLineGradientBrush = QBrush(buttonGradient5);
4143
4144 QLinearGradient buttonGradient6(buttonRect.topLeft(), buttonRect.bottomLeft());
4145 buttonGradient6.setColorAt(0.0, buttonBrush.color().darker(108));
4146 buttonGradient6.setColorAt(1.0, buttonBrush.color().darker(103));
4147 sunkenRightLineGradientBrush = QBrush(buttonGradient6);
4148 }
4149
4150 // Main fill
4151 painter->fillRect(upRect.adjusted(2, 2, -2, -2),
4152 qMapBrushToRect(upSunken ? sunkenButtonGradientBrush
4153 : buttonGradientBrush, upRect));
4154 painter->fillRect(downRect.adjusted(2, 2, -2, -2),
4155 qMapBrushToRect(downSunken ? sunkenButtonGradientBrush
4156 : buttonGradientBrush, downRect));
4157
4158 // Top line
4159 painter->setPen(QPen(qBrushLight(qMapBrushToRect(upSunken ? sunkenButtonGradientBrush
4160 : buttonGradientBrush, upRect), 105), 0));
4161 if (!reverse) {
4162 painter->drawLine(upRect.left() + 1, upRect.top() + 1,
4163 upRect.right() - 2, upRect.top() + 1);
4164 } else {
4165 painter->drawLine(upRect.right() - 1, upRect.top() + 1,
4166 upRect.left() + 2, upRect.top() + 1);
4167 }
4168 painter->setPen(QPen(qBrushLight(qMapBrushToRect(downSunken ? sunkenButtonGradientBrush
4169 : buttonGradientBrush, downRect), 105), 0));
4170 if (!reverse) {
4171 painter->drawLine(downRect.left() + 1, downRect.top() + 1,
4172 downRect.right() - 1, downRect.top() + 1);
4173 } else {
4174 painter->drawLine(downRect.right() - 1, downRect.top() + 1,
4175 downRect.left() + 1, downRect.top() + 1);
4176 }
4177
4178 // Left line
4179 painter->setPen(QPen(qMapBrushToRect(upSunken ? sunkenLeftLineGradientBrush
4180 : leftLineGradientBrush, upRect), 1));
4181 if (!reverse) {
4182 painter->drawLine(upRect.left() + 1, upRect.top() + 2,
4183 upRect.left() + 1, upRect.bottom() - 1);
4184 } else {
4185 painter->drawLine(upRect.left() + 1, upRect.top() + 2,
4186 upRect.left() + 1, upRect.bottom() - 1);
4187 }
4188 painter->setPen(QPen(qMapBrushToRect(downSunken ? sunkenLeftLineGradientBrush
4189 : leftLineGradientBrush, downRect), 1));
4190 if (!reverse) {
4191 painter->drawLine(downRect.left() + 1, downRect.top() + 2,
4192 downRect.left() + 1, downRect.bottom() - 1);
4193 } else {
4194 painter->drawLine(downRect.left() + 1, downRect.top() + 1,
4195 downRect.left() + 1, downRect.bottom() - 2);
4196 }
4197
4198 // Bottom line
4199 painter->setPen(QPen(qBrushDark(qMapBrushToRect(upSunken ? sunkenButtonGradientBrush
4200 : buttonGradientBrush, upRect), 105), 0));
4201 if (!reverse) {
4202 painter->drawLine(upRect.left() + 2, upRect.bottom() - 1,
4203 upRect.right() - 1, upRect.bottom() - 1);
4204 } else {
4205 painter->drawLine(upRect.right() - 2, upRect.bottom() - 1,
4206 upRect.left() + 1, upRect.bottom() - 1);
4207 }
4208 painter->setPen(QPen(qBrushDark(qMapBrushToRect(downSunken ? sunkenButtonGradientBrush
4209 : buttonGradientBrush, downRect), 105), 0));
4210 if (!reverse) {
4211 painter->drawLine(downRect.left() + 2, downRect.bottom() - 1,
4212 downRect.right() - 2, downRect.bottom() - 1);
4213 } else {
4214 painter->drawLine(downRect.right() - 2, downRect.bottom() - 1,
4215 downRect.left() + 2, downRect.bottom() - 1);
4216 }
4217
4218 // Right line
4219 painter->setPen(QPen(qMapBrushToRect(upSunken ? sunkenRightLineGradientBrush
4220 : rightLineGradientBrush, upRect), 1));
4221 if (!reverse) {
4222 painter->drawLine(upRect.right() - 1, upRect.top() + 2,
4223 upRect.right() - 1, upRect.bottom() - 1);
4224 } else {
4225 painter->drawLine(upRect.right() - 1, upRect.top() + 2,
4226 upRect.right() - 1, upRect.bottom() - 1);
4227 }
4228 painter->setPen(QPen(qMapBrushToRect(downSunken ? sunkenRightLineGradientBrush
4229 : rightLineGradientBrush, downRect), 1));
4230 if (!reverse) {
4231 painter->drawLine(downRect.right() - 1, downRect.top() + 1,
4232 downRect.right() - 1, downRect.bottom() - 2);
4233 } else {
4234 painter->drawLine(downRect.right() - 1, downRect.top() + 2,
4235 downRect.right() - 1, downRect.bottom() - 1);
4236 }
4237
4238 QBrush indicatorBrush = qMapBrushToRect(option->palette.buttonText(), buttonRect);
4239 painter->setPen(QPen(indicatorBrush, 0));
4240 if (spinBox->buttonSymbols == QAbstractSpinBox::PlusMinus) {
4241 QPoint center;
4242 if (spinBox->subControls & SC_SpinBoxUp) {
4243 // .......
4244 // ...X...
4245 // ...X...
4246 // .XXXXX.
4247 // ...X...
4248 // ...X...
4249 // .......
4250 center = upRect.center();
4251 if (upSunken) {
4252 ++center.rx();
4253 ++center.ry();
4254 }
4255 painter->drawLine(center.x(), center.y() - 2, center.x(), center.y() + 2);
4256 painter->drawLine(center.x() - 2, center.y(), center.x() + 2, center.y());
4257 }
4258 if (spinBox->subControls & SC_SpinBoxDown) {
4259 // .......
4260 // .......
4261 // .......
4262 // .XXXXX.
4263 // .......
4264 // .......
4265 // .......
4266 center = downRect.center();
4267 if (downSunken) {
4268 ++center.rx();
4269 ++center.ry();
4270 }
4271 painter->drawLine(center.x() - 2, center.y(), center.x() + 2, center.y());
4272 }
4273 } else {
4274 int offset;
4275 int centerX;
4276 if (spinBox->subControls & SC_SpinBoxUp) {
4277 // ...........
4278 // .....X.....
4279 // ....XXX....
4280 // ...XXXXX...
4281 // ..XXXXXXX..
4282 // ...........
4283 offset = upSunken ? 1 : 0;
4284 QRect upArrowRect(upRect.center().x() - 3 + offset, upRect.center().y() - 2 + offset, 7, 4);
4285 centerX = upArrowRect.center().x();
4286 painter->drawPoint(centerX, upArrowRect.top());
4287 const QLine lines[3] = {
4288 QLine(centerX - 1, upArrowRect.top() + 1, centerX + 1, upArrowRect.top() + 1),
4289 QLine(centerX - 2, upArrowRect.top() + 2, centerX + 2, upArrowRect.top() + 2),
4290 QLine(centerX - 3, upArrowRect.top() + 3, centerX + 3, upArrowRect.top() + 3) };
4291 painter->drawLines(lines, 3);
4292 }
4293 if (spinBox->subControls & SC_SpinBoxDown) {
4294 // ...........
4295 // ..XXXXXXX..
4296 // ...XXXXX...
4297 // ....XXX....
4298 // .....X.....
4299 // ...........
4300 offset = downSunken ? 1 : 0;
4301 QRect downArrowRect(downRect.center().x() - 3 + offset, downRect.center().y() - 2 + offset + 1, 7, 4);
4302 centerX = downArrowRect.center().x();
4303 const QLine lines[3] = {
4304 QLine(centerX - 3, downArrowRect.top(), centerX + 3, downArrowRect.top()),
4305 QLine(centerX - 2, downArrowRect.top() + 1, centerX + 2, downArrowRect.top() + 1),
4306 QLine(centerX - 1, downArrowRect.top() + 2, centerX + 1, downArrowRect.top() + 2) };
4307 painter->drawLines(lines, 3);
4308 painter->drawPoint(centerX, downArrowRect.top() + 3);
4309 }
4310 }
4311 painter->restore();
4312 }
4313 break;
4314 #endif // QT_NO_SPINBOX
4315 #ifndef QT_NO_COMBOBOX
4316 case CC_ComboBox:
4317 if (const QStyleOptionComboBox *comboBox = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
4318 bool sunken = comboBox->state & State_On; // play dead if combobox has no items
4319 bool reverse = comboBox->direction == Qt::RightToLeft;
4320 int menuButtonWidth = 16;
4321 int xoffset = sunken ? (reverse ? -1 : 1) : 0;
4322 int yoffset = sunken ? 1 : 0;
4323 QRect rect = comboBox->rect;
4324 QPen oldPen = painter->pen();
4325
4326 // Fill
4327 if (comboBox->editable) {
4328 // Button colors
4329 QBrush alphaCornerBrush = qBrushDark(option->palette.button(), 165);
4330 qBrushSetAlphaF(&alphaCornerBrush, 0.5);
4331 QBrush buttonGradientBrush;
4332 QBrush leftLineGradientBrush;
4333 QBrush rightLineGradientBrush;
4334 QBrush sunkenButtonGradientBrush;
4335 QBrush sunkenLeftLineGradientBrush;
4336 QBrush sunkenRightLineGradientBrush;
4337 QBrush button = option->palette.button();
4338 if (button.gradient() || !button.texture().isNull()) {
4339 buttonGradientBrush = button;
4340 sunkenButtonGradientBrush = qBrushDark(button, 108);
4341 leftLineGradientBrush = qBrushLight(button, 105);
4342 rightLineGradientBrush = qBrushDark(button, 105);
4343 sunkenLeftLineGradientBrush = qBrushDark(button, 110);
4344 sunkenRightLineGradientBrush = qBrushDark(button, 106);
4345 } else {
4346 // Generate gradients
4347 QLinearGradient buttonGradient(option->rect.topLeft(), option->rect.bottomLeft());
4348 buttonGradient.setColorAt(0.0, button.color().lighter(104));
4349 buttonGradient.setColorAt(1.0, button.color().darker(110));
4350 buttonGradientBrush = QBrush(buttonGradient);
4351
4352 QLinearGradient buttonGradient2(option->rect.topLeft(), option->rect.bottomLeft());
4353 buttonGradient2.setColorAt(0.0, button.color().darker(113));
4354 buttonGradient2.setColorAt(1.0, button.color().darker(103));
4355 sunkenButtonGradientBrush = QBrush(buttonGradient2);
4356
4357 QLinearGradient buttonGradient3(option->rect.topLeft(), option->rect.bottomLeft());
4358 buttonGradient3.setColorAt(0.0, button.color().lighter(105));
4359 buttonGradient3.setColorAt(1.0, button.color());
4360 leftLineGradientBrush = QBrush(buttonGradient3);
4361
4362 QLinearGradient buttonGradient4(option->rect.topLeft(), option->rect.bottomLeft());
4363 buttonGradient4.setColorAt(0.0, button.color());
4364 buttonGradient4.setColorAt(1.0, button.color().darker(110));
4365 rightLineGradientBrush = QBrush(buttonGradient4);
4366
4367 QLinearGradient buttonGradient5(option->rect.topLeft(), option->rect.bottomLeft());
4368 buttonGradient5.setColorAt(0.0, button.color().darker(113));
4369 buttonGradient5.setColorAt(1.0, button.color().darker(107));
4370 sunkenLeftLineGradientBrush = QBrush(buttonGradient5);
4371
4372 QLinearGradient buttonGradient6(option->rect.topLeft(), option->rect.bottomLeft());
4373 buttonGradient6.setColorAt(0.0, button.color().darker(108));
4374 buttonGradient6.setColorAt(1.0, button.color().darker(103));
4375 sunkenRightLineGradientBrush = QBrush(buttonGradient6);
4376 }
4377
4378 // ComboBox starts with a lineedit in place already.
4379 QRect buttonRect;
4380 if (!reverse) {
4381 buttonRect.setRect(rect.right() - menuButtonWidth, rect.top(), menuButtonWidth + 1, rect.height());
4382 } else {
4383 buttonRect.setRect(rect.left(), rect.top(), menuButtonWidth + 1, rect.height());
4384 }
4385
4386 Q_D(const QPlastiqueStyle);
4387 d->drawPartialFrame(painter,
4388 option,
4389 proxy()->subControlRect(CC_ComboBox, option, SC_ComboBoxEditField, widget),
4390 widget);
4391
4392 QBrush border = qMapBrushToRect(option->palette.shadow(), buttonRect);
4393 qBrushSetAlphaF(&border, qreal(0.4));
4394 painter->setPen(QPen(border, 0));
4395 if (!reverse)
4396 painter->drawLine(buttonRect.topLeft() + QPoint(0, 1), buttonRect.bottomLeft() + QPoint(0, -1));
4397 else
4398 painter->drawLine(buttonRect.topRight() + QPoint(0, -1), buttonRect.bottomRight() + QPoint(0, 1));
4399
4400 // Outline the button border
4401 if (!reverse) {
4402 const QLine lines[3] = {
4403 QLine(buttonRect.left(), buttonRect.top(),
4404 buttonRect.right() - 2, buttonRect.top()),
4405 QLine(buttonRect.right(), buttonRect.top() + 2,
4406 buttonRect.right(), buttonRect.bottom() - 2),
4407 QLine(buttonRect.left(), buttonRect.bottom(),
4408 buttonRect.right() - 2, buttonRect.bottom()) };
4409 painter->drawLines(lines, 3);
4410 {
4411 const QPoint points[2] = {
4412 QPoint(buttonRect.right() - 1, buttonRect.top() + 1),
4413 QPoint(buttonRect.right() - 1, buttonRect.bottom() - 1) };
4414 painter->drawPoints(points, 2);
4415 }
4416
4417 QBrush corner = qMapBrushToRect(option->palette.shadow(), buttonRect);
4418 qBrushSetAlphaF(&corner, qreal(0.16));
4419 painter->setPen(QPen(corner, 0));
4420 {
4421 const QPoint points[4] = {
4422 QPoint(buttonRect.right() - 1, buttonRect.top()),
4423 QPoint(buttonRect.right() - 1, buttonRect.bottom()),
4424 QPoint(buttonRect.right(), buttonRect.top() + 1),
4425 QPoint(buttonRect.right(), buttonRect.bottom() - 1) };
4426 painter->drawPoints(points, 4);
4427 }
4428 } else {
4429 const QLine lines[3] = {
4430 QLine(buttonRect.right(), buttonRect.top(),
4431 buttonRect.left() + 2, buttonRect.top()),
4432 QLine(buttonRect.left(), buttonRect.top() + 2,
4433 buttonRect.left(), buttonRect.bottom() - 2),
4434 QLine(buttonRect.right(), buttonRect.bottom(),
4435 buttonRect.left() + 2, buttonRect.bottom()) };
4436 painter->drawLines(lines, 3);
4437 {
4438 const QPoint points[2] = {
4439 QPoint(buttonRect.left() + 1, buttonRect.top() + 1),
4440 QPoint(buttonRect.left() + 1, buttonRect.bottom() - 1) };
4441 painter->drawPoints(points, 2);
4442 }
4443
4444 QBrush corner = qMapBrushToRect(option->palette.shadow(), buttonRect);
4445 qBrushSetAlphaF(&corner, qreal(0.16));
4446 painter->setPen(QPen(corner, 0));
4447 {
4448 const QPoint points[4] = {
4449 QPoint(buttonRect.left() + 1, buttonRect.top()),
4450 QPoint(buttonRect.left() + 1, buttonRect.bottom()),
4451 QPoint(buttonRect.left(), buttonRect.top() + 1),
4452 QPoint(buttonRect.left(), buttonRect.bottom() - 1) };
4453 painter->drawPoints(points, 4);
4454 }
4455 }
4456
4457 QRect fillRect = buttonRect.adjusted(2, 2, -2, -2);
4458 // Main fill
4459 painter->fillRect(fillRect,
4460 qMapBrushToRect(sunken ? sunkenButtonGradientBrush
4461 : buttonGradientBrush, option->rect));
4462
4463 // Top line
4464 painter->setPen(QPen(qBrushLight(qMapBrushToRect(sunken ? sunkenButtonGradientBrush
4465 : buttonGradientBrush, option->rect), 105), 0));
4466 if (!reverse) {
4467 painter->drawLine(QPointF(buttonRect.left() + 1, buttonRect.top() + 1),
4468 QPointF(buttonRect.right() - 2, buttonRect.top() + 1));
4469 } else {
4470 painter->drawLine(QPointF(buttonRect.right() - 1, buttonRect.top() + 1),
4471 QPointF(buttonRect.left() + 2, buttonRect.top() + 1));
4472 }
4473
4474 // Bottom line
4475 painter->setPen(QPen(qBrushDark(qMapBrushToRect(sunken ? sunkenButtonGradientBrush
4476 : buttonGradientBrush, option->rect), 105), 0));
4477 if (!reverse) {
4478 painter->drawLine(QPointF(buttonRect.left() + 1, buttonRect.bottom() - 1),
4479 QPointF(buttonRect.right() - 2, buttonRect.bottom() - 1));
4480 } else {
4481 painter->drawLine(QPointF(buttonRect.right() - 1, buttonRect.bottom() - 1),
4482 QPointF(buttonRect.left() + 2, buttonRect.bottom() - 1));
4483 }
4484
4485 // Left line
4486 painter->setPen(QPen(qMapBrushToRect(sunken ? sunkenLeftLineGradientBrush
4487 : leftLineGradientBrush, option->rect), 1));
4488 if (!reverse) {
4489 painter->drawLine(QPointF(buttonRect.left() + 1, buttonRect.top() + 2),
4490 QPointF(buttonRect.left() + 1, buttonRect.bottom() - 2));
4491 } else {
4492 painter->drawLine(QPointF(buttonRect.left() + 1, buttonRect.top() + 2),
4493 QPointF(buttonRect.left() + 1, buttonRect.bottom() - 2));
4494 }
4495
4496 // Right line
4497 painter->setPen(QPen(qMapBrushToRect(sunken ? sunkenRightLineGradientBrush
4498 : rightLineGradientBrush, option->rect), 1));
4499 if (!reverse) {
4500 painter->drawLine(QPointF(buttonRect.right() - 1, buttonRect.top() + 2),
4501 QPointF(buttonRect.right() - 1, buttonRect.bottom() - 2));
4502 } else {
4503 painter->drawLine(QPointF(buttonRect.right() - 1, buttonRect.top() + 2),
4504 QPointF(buttonRect.right() - 1, buttonRect.bottom() - 2));
4505 }
4506 } else {
4507 // Start with a standard panel button fill
4508 QStyleOptionButton buttonOption;
4509 buttonOption.QStyleOption::operator=(*comboBox);
4510 if (!sunken) {
4511 buttonOption.state &= ~State_Sunken;
4512 }
4513 proxy()->drawPrimitive(PE_PanelButtonCommand, &buttonOption, painter, widget);
4514
4515 // Draw the menu button separator line
4516 QBrush border = qMapBrushToRect(option->palette.shadow(), rect);
4517 qBrushSetAlphaF(&border, qreal(0.35));
4518 painter->setPen(QPen(border, 0));
4519 if (!reverse) {
4520 painter->drawLine(rect.right() - menuButtonWidth + xoffset, rect.top() + 1,
4521 rect.right() - menuButtonWidth + xoffset, rect.bottom() - 1);
4522 } else {
4523 painter->drawLine(rect.left() + menuButtonWidth + xoffset, rect.top() + 1,
4524 rect.left() + menuButtonWidth + xoffset, rect.bottom() - 1);
4525 }
4526 }
4527
4528 // Draw the little arrow
4529 if (comboBox->subControls & SC_ComboBoxArrow) {
4530 int left = !reverse ? rect.right() - menuButtonWidth : rect.left();
4531 int right = !reverse ? rect.right() : rect.left() + menuButtonWidth;
4532 QRect arrowRect((left + right) / 2 - 3 + xoffset,
4533 rect.center().y() - 1 + yoffset, 7, 4);
4534 painter->setPen(QPen(qMapBrushToRect(option->palette.buttonText(), rect), 0));
4535 const QLine lines[3] = {
4536 QLine(arrowRect.topLeft(), arrowRect.topRight()),
4537 QLine(arrowRect.left() + 1, arrowRect.top() + 1,
4538 arrowRect.right() - 1, arrowRect.top() + 1),
4539 QLine(arrowRect.left() + 2, arrowRect.top() + 2,
4540 arrowRect.right() - 2, arrowRect.top() + 2) };
4541 painter->drawLines(lines, 3);
4542 painter->drawPoint(arrowRect.center().x(), arrowRect.bottom());
4543 }
4544
4545 // Draw the focus rect
4546 if ((option->state & State_HasFocus) && !comboBox->editable
4547 && ((option->state & State_KeyboardFocusChange) || styleHint(SH_UnderlineShortcut, option, widget))) {
4548 QStyleOptionFocusRect focus;
4549 focus.rect = proxy()->subControlRect(CC_ComboBox, option, SC_ComboBoxEditField, widget)
4550 .adjusted(-2, 0, 2, 0);
4551 proxy()->drawPrimitive(PE_FrameFocusRect, &focus, painter, widget);
4552 }
4553
4554 painter->setPen(oldPen);
4555 }
4556 break;
4557 #endif // QT_NO_COMBOBOX
4558 case CC_TitleBar:
4559 if (const QStyleOptionTitleBar *titleBar = qstyleoption_cast<const QStyleOptionTitleBar *>(option)) {
4560 painter->save();
4561 bool active = (titleBar->titleBarState & State_Active);
4562 QRect fullRect = titleBar->rect;
4563
4564 // ### use palette colors instead
4565 QColor titleBarGradientStart(active ? 0x3b508a : 0x6e6e6e);
4566 QColor titleBarGradientStop(active ? 0x5d6e9e : 0x818181);
4567 QColor titleBarFrameBorder(0x393939);
4568 QColor titleBarAlphaCorner(active ? 0x4b5e7f : 0x6a6a6a);
4569 QColor titleBarInnerTopLine(active ? 0x8e98ba : 0xa4a4a4);
4570 QColor titleBarInnerInnerTopLine(active ? 0x57699b : 0x808080);
4571 QColor leftCorner(active ? 0x6f7ea8 : 0x8e8e8e);
4572 QColor rightCorner(active ? 0x44537d : 0x676767);
4573 QColor textColor(active ? 0x282e40 : 0x282e40);
4574 QColor textAlphaColor(active ? 0x3f4862 : 0x3f4862);
4575
4576 #ifdef QT3_SUPPORT
4577 if (widget && widget->inherits("Q3DockWindowTitleBar")) {
4578 QStyleOptionDockWidgetV2 dockwidget;
4579 dockwidget.QStyleOption::operator=(*option);
4580 dockwidget.title = titleBar->text;
4581 proxy()->drawControl(CE_DockWidgetTitle, &dockwidget, painter, widget);
4582 } else
4583 #endif // QT3_SUPPORT
4584
4585 {
4586 // Fill title bar gradient
4587 qt_plastique_draw_gradient(painter, option->rect.adjusted(1, 1, -1, 0),
4588 titleBarGradientStart,
4589 titleBarGradientStop);
4590
4591 // Frame and rounded corners
4592 painter->setPen(titleBarFrameBorder);
4593
4594 // top border line
4595 {
4596 const QLine lines[3] = {
4597 QLine(fullRect.left() + 2, fullRect.top(), fullRect.right() - 2, fullRect.top()),
4598 QLine(fullRect.left(), fullRect.top() + 2, fullRect.left(), fullRect.bottom()),
4599 QLine(fullRect.right(), fullRect.top() + 2, fullRect.right(), fullRect.bottom()) };
4600 painter->drawLines(lines, 3);
4601 const QPoint points[2] = {
4602 QPoint(fullRect.left() + 1, fullRect.top() + 1),
4603 QPoint(fullRect.right() - 1, fullRect.top() + 1) };
4604 painter->drawPoints(points, 2);
4605 }
4606
4607 // alpha corners
4608 painter->setPen(titleBarAlphaCorner);
4609 {
4610 const QPoint points[4] = {
4611 QPoint(fullRect.left() + 2, fullRect.top() + 1),
4612 QPoint(fullRect.left() + 1, fullRect.top() + 2),
4613 QPoint(fullRect.right() - 2, fullRect.top() + 1),
4614 QPoint(fullRect.right() - 1, fullRect.top() + 2) };
4615 painter->drawPoints(points, 4);
4616 }
4617
4618 // inner top line
4619 painter->setPen(titleBarInnerTopLine);
4620 painter->drawLine(fullRect.left() + 3, fullRect.top() + 1, fullRect.right() - 3, fullRect.top() + 1);
4621
4622 // inner inner top line
4623 painter->setPen(titleBarInnerInnerTopLine);
4624 painter->drawLine(fullRect.left() + 2, fullRect.top() + 2, fullRect.right() - 2, fullRect.top() + 2);
4625
4626 // left and right inner
4627 painter->setPen(leftCorner);
4628 painter->drawLine(fullRect.left() + 1, fullRect.top() + 3, fullRect.left() + 1, fullRect.bottom());
4629 painter->setPen(rightCorner);
4630 painter->drawLine(fullRect.right() - 1, fullRect.top() + 3, fullRect.right() - 1, fullRect.bottom());
4631
4632 if (titleBar->titleBarState & Qt::WindowMinimized) {
4633 painter->setPen(titleBarFrameBorder);
4634 painter->drawLine(fullRect.left() + 2, fullRect.bottom(), fullRect.right() - 2, fullRect.bottom());
4635 {
4636 const QPoint points[2] = {
4637 QPoint(fullRect.left() + 1, fullRect.bottom() - 1),
4638 QPoint(fullRect.right() - 1, fullRect.bottom() - 1) };
4639 painter->drawPoints(points, 2);
4640 }
4641 painter->setPen(rightCorner);
4642 painter->drawLine(fullRect.left() + 2, fullRect.bottom() - 1, fullRect.right() - 2, fullRect.bottom() - 1);
4643 painter->setPen(titleBarAlphaCorner);
4644 {
4645 const QPoint points[4] = {
4646 QPoint(fullRect.left() + 1, fullRect.bottom() - 2),
4647 QPoint(fullRect.left() + 2, fullRect.bottom() - 1),
4648 QPoint(fullRect.right() - 1, fullRect.bottom() - 2),
4649 QPoint(fullRect.right() - 2, fullRect.bottom() - 1) };
4650 painter->drawPoints(points, 4);
4651 }
4652 }
4653 // draw title
4654 QRect textRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarLabel, widget);
4655
4656 QFont font = painter->font();
4657 font.setBold(true);
4658 painter->setFont(font);
4659 painter->setPen(titleBar->palette.text().color());
4660
4661 // Attempt to align left if there is not enough room for the title
4662 // text. Otherwise, align center. QWorkspace does elliding for us,
4663 // and it doesn't know about the bold title, so we need to work
4664 // around some of the width mismatches.
4665 bool tooWide = (QFontMetrics(font).width(titleBar->text) > textRect.width());
4666 QTextOption option((tooWide ? Qt::AlignLeft : Qt::AlignHCenter) | Qt::AlignVCenter);
4667 option.setWrapMode(QTextOption::NoWrap);
4668
4669 painter->drawText(textRect.adjusted(1, 1, 1, 1), titleBar->text, option);
4670 painter->setPen(titleBar->palette.highlightedText().color());
4671 painter->drawText(textRect, titleBar->text, option);
4672 }
4673
4674 // min button
4675 if ((titleBar->subControls & SC_TitleBarMinButton)
4676 && (titleBar->titleBarFlags & Qt::WindowMinimizeButtonHint)
4677 && !(titleBar->titleBarState & Qt::WindowMinimized)) {
4678 bool hover = (titleBar->activeSubControls & SC_TitleBarMinButton) && (titleBar->state & State_MouseOver);
4679 bool sunken = (titleBar->activeSubControls & SC_TitleBarMinButton) && (titleBar->state & State_Sunken);
4680
4681 QRect minButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarMinButton, widget);
4682 qt_plastique_draw_mdibutton(painter, titleBar, minButtonRect, hover, sunken);
4683
4684 int xoffset = minButtonRect.width() / 3;
4685 int yoffset = minButtonRect.height() / 3;
4686
4687 QRect minButtonIconRect(minButtonRect.left() + xoffset, minButtonRect.top() + yoffset,
4688 minButtonRect.width() - xoffset * 2, minButtonRect.height() - yoffset * 2);
4689
4690 painter->setPen(textColor);
4691 {
4692 const QLine lines[2] = {
4693 QLine(minButtonIconRect.center().x() - 2,
4694 minButtonIconRect.center().y() + 3,
4695 minButtonIconRect.center().x() + 3,
4696 minButtonIconRect.center().y() + 3),
4697 QLine(minButtonIconRect.center().x() - 2,
4698 minButtonIconRect.center().y() + 4,
4699 minButtonIconRect.center().x() + 3,
4700 minButtonIconRect.center().y() + 4) };
4701 painter->drawLines(lines, 2);
4702 }
4703 painter->setPen(textAlphaColor);
4704 {
4705 const QLine lines[2] = {
4706 QLine(minButtonIconRect.center().x() - 3,
4707 minButtonIconRect.center().y() + 3,
4708 minButtonIconRect.center().x() - 3,
4709 minButtonIconRect.center().y() + 4),
4710 QLine(minButtonIconRect.center().x() + 4,
4711 minButtonIconRect.center().y() + 3,
4712 minButtonIconRect.center().x() + 4,
4713 minButtonIconRect.center().y() + 4) };
4714 painter->drawLines(lines, 2);
4715 }
4716 }
4717
4718 // max button
4719 if ((titleBar->subControls & SC_TitleBarMaxButton)
4720 && (titleBar->titleBarFlags & Qt::WindowMaximizeButtonHint)
4721 && !(titleBar->titleBarState & Qt::WindowMaximized)) {
4722 bool hover = (titleBar->activeSubControls & SC_TitleBarMaxButton) && (titleBar->state & State_MouseOver);
4723 bool sunken = (titleBar->activeSubControls & SC_TitleBarMaxButton) && (titleBar->state & State_Sunken);
4724
4725 QRect maxButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarMaxButton, widget);
4726 qt_plastique_draw_mdibutton(painter, titleBar, maxButtonRect, hover, sunken);
4727
4728 int xoffset = maxButtonRect.width() / 3;
4729 int yoffset = maxButtonRect.height() / 3;
4730
4731 QRect maxButtonIconRect(maxButtonRect.left() + xoffset, maxButtonRect.top() + yoffset,
4732 maxButtonRect.width() - xoffset * 2, maxButtonRect.height() - yoffset * 2);
4733
4734 painter->setPen(textColor);
4735 painter->drawRect(maxButtonIconRect.adjusted(0, 0, -1, -1));
4736 painter->drawLine(maxButtonIconRect.left() + 1, maxButtonIconRect.top() + 1,
4737 maxButtonIconRect.right() - 1, maxButtonIconRect.top() + 1);
4738 painter->setPen(textAlphaColor);
4739 const QPoint points[4] = {
4740 maxButtonIconRect.topLeft(), maxButtonIconRect.topRight(),
4741 maxButtonIconRect.bottomLeft(), maxButtonIconRect.bottomRight() };
4742 painter->drawPoints(points, 4);
4743 }
4744
4745 // close button
4746 if (titleBar->subControls & SC_TitleBarCloseButton && titleBar->titleBarFlags & Qt::WindowSystemMenuHint) {
4747 bool hover = (titleBar->activeSubControls & SC_TitleBarCloseButton) && (titleBar->state & State_MouseOver);
4748 bool sunken = (titleBar->activeSubControls & SC_TitleBarCloseButton) && (titleBar->state & State_Sunken);
4749
4750 QRect closeButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarCloseButton, widget);
4751 qt_plastique_draw_mdibutton(painter, titleBar, closeButtonRect, hover, sunken);
4752
4753 int xoffset = closeButtonRect.width() / 3;
4754 int yoffset = closeButtonRect.height() / 3;
4755
4756 QRect closeIconRect(closeButtonRect.left() + xoffset, closeButtonRect.top() + yoffset,
4757 closeButtonRect.width() - xoffset * 2, closeButtonRect.height() - yoffset * 2);
4758
4759 painter->setPen(textAlphaColor);
4760 {
4761 const QLine lines[4] = {
4762 QLine(closeIconRect.left() + 1, closeIconRect.top(),
4763 closeIconRect.right(), closeIconRect.bottom() - 1),
4764 QLine(closeIconRect.left(), closeIconRect.top() + 1,
4765 closeIconRect.right() - 1, closeIconRect.bottom()),
4766 QLine(closeIconRect.right() - 1, closeIconRect.top(),
4767 closeIconRect.left(), closeIconRect.bottom() - 1),
4768 QLine(closeIconRect.right(), closeIconRect.top() + 1,
4769 closeIconRect.left() + 1, closeIconRect.bottom()) };
4770 painter->drawLines(lines, 4);
4771 const QPoint points[4] = {
4772 closeIconRect.topLeft(), closeIconRect.topRight(),
4773 closeIconRect.bottomLeft(), closeIconRect.bottomRight() };
4774 painter->drawPoints(points, 4);
4775 }
4776 painter->setPen(textColor);
4777 {
4778 const QLine lines[2] = {
4779 QLine(closeIconRect.left() + 1, closeIconRect.top() + 1,
4780 closeIconRect.right() - 1, closeIconRect.bottom() - 1),
4781 QLine(closeIconRect.left() + 1, closeIconRect.bottom() - 1,
4782 closeIconRect.right() - 1, closeIconRect.top() + 1) };
4783 painter->drawLines(lines, 2);
4784 }
4785 }
4786
4787 // normalize button
4788 if ((titleBar->subControls & SC_TitleBarNormalButton) &&
4789 (((titleBar->titleBarFlags & Qt::WindowMinimizeButtonHint) &&
4790 (titleBar->titleBarState & Qt::WindowMinimized)) ||
4791 ((titleBar->titleBarFlags & Qt::WindowMaximizeButtonHint) &&
4792 (titleBar->titleBarState & Qt::WindowMaximized)))) {
4793 bool hover = (titleBar->activeSubControls & SC_TitleBarNormalButton) && (titleBar->state & State_MouseOver);
4794 bool sunken = (titleBar->activeSubControls & SC_TitleBarNormalButton) && (titleBar->state & State_Sunken);
4795
4796 QRect normalButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarNormalButton, widget);
4797 qt_plastique_draw_mdibutton(painter, titleBar, normalButtonRect, hover, sunken);
4798 int xoffset = int(normalButtonRect.width() / 3.5);
4799 int yoffset = int(normalButtonRect.height() / 3.5);
4800
4801 QRect normalButtonIconRect(normalButtonRect.left() + xoffset, normalButtonRect.top() + yoffset,
4802 normalButtonRect.width() - xoffset * 2, normalButtonRect.height() - yoffset * 2);
4803
4804 QRect frontWindowRect = normalButtonIconRect.adjusted(0, 3, -3, 0);
4805 painter->setPen(textColor);
4806 painter->drawRect(frontWindowRect.adjusted(0, 0, -1, -1));
4807 painter->drawLine(frontWindowRect.left() + 1, frontWindowRect.top() + 1,
4808 frontWindowRect.right() - 1, frontWindowRect.top() + 1);
4809 painter->setPen(textAlphaColor);
4810 {
4811 const QPoint points[4] = {
4812 frontWindowRect.topLeft(), frontWindowRect.topRight(),
4813 frontWindowRect.bottomLeft(), frontWindowRect.bottomRight() };
4814 painter->drawPoints(points, 4);
4815 }
4816
4817 QRect backWindowRect = normalButtonIconRect.adjusted(3, 0, 0, -3);
4818 QRegion clipRegion = backWindowRect;
4819 clipRegion -= frontWindowRect;
4820 painter->save();
4821 painter->setClipRegion(clipRegion);
4822 painter->setPen(textColor);
4823 painter->drawRect(backWindowRect.adjusted(0, 0, -1, -1));
4824 painter->drawLine(backWindowRect.left() + 1, backWindowRect.top() + 1,
4825 backWindowRect.right() - 1, backWindowRect.top() + 1);
4826 painter->setPen(textAlphaColor);
4827 {
4828 const QPoint points[4] = {
4829 backWindowRect.topLeft(), backWindowRect.topRight(),
4830 backWindowRect.bottomLeft(), backWindowRect.bottomRight() };
4831 painter->drawPoints(points, 4);
4832 }
4833 painter->restore();
4834 }
4835
4836 // context help button
4837 if (titleBar->subControls & SC_TitleBarContextHelpButton
4838 && (titleBar->titleBarFlags & Qt::WindowContextHelpButtonHint)) {
4839 bool hover = (titleBar->activeSubControls & SC_TitleBarContextHelpButton) && (titleBar->state & State_MouseOver);
4840 bool sunken = (titleBar->activeSubControls & SC_TitleBarContextHelpButton) && (titleBar->state & State_Sunken);
4841
4842 QRect contextHelpButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarContextHelpButton, widget);
4843
4844 qt_plastique_draw_mdibutton(painter, titleBar, contextHelpButtonRect, hover, sunken);
4845
4846 QColor blend;
4847 // ### Use palette colors
4848 if (active) {
4849 blend = mergedColors(QColor(hover ? 0x7d8bb1 : 0x55689a),
4850 QColor(hover ? 0x939ebe : 0x7381ab));
4851 } else {
4852 blend = mergedColors(QColor(hover ? 0x9e9e9e : 0x818181),
4853 QColor(hover ? 0xababab : 0x929292));
4854 }
4855 QImage image(qt_titlebar_context_help);
4856 image.setColor(4, textColor.rgba());
4857 image.setColor(3, mergedColors(blend, textColor, 30).rgba());
4858 image.setColor(2, mergedColors(blend, textColor, 70).rgba());
4859 image.setColor(1, mergedColors(blend, textColor, 90).rgba());
4860
4861 painter->drawImage(contextHelpButtonRect, image);
4862 }
4863
4864 // shade button
4865 if (titleBar->subControls & SC_TitleBarShadeButton) {
4866 bool hover = (titleBar->activeSubControls & SC_TitleBarShadeButton) && (titleBar->state & State_MouseOver);
4867 bool sunken = (titleBar->activeSubControls & SC_TitleBarShadeButton) && (titleBar->state & State_Sunken);
4868
4869 QRect shadeButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarShadeButton, widget);
4870 qt_plastique_draw_mdibutton(painter, titleBar, shadeButtonRect, hover, sunken);
4871
4872 int xoffset = shadeButtonRect.width() / 3;
4873 int yoffset = shadeButtonRect.height() / 3;
4874
4875 QRect shadeButtonIconRect(shadeButtonRect.left() + xoffset, shadeButtonRect.top() + yoffset,
4876 shadeButtonRect.width() - xoffset * 2, shadeButtonRect.height() - yoffset * 2);
4877
4878 QPainterPath path(shadeButtonIconRect.bottomLeft());
4879 path.lineTo(shadeButtonIconRect.center().x(), shadeButtonIconRect.bottom() - shadeButtonIconRect.height() / 2);
4880 path.lineTo(shadeButtonIconRect.bottomRight());
4881 path.lineTo(shadeButtonIconRect.bottomLeft());
4882
4883 painter->setPen(textAlphaColor);
4884 painter->setBrush(textColor);
4885 painter->drawPath(path);
4886 }
4887
4888 // unshade button
4889 if (titleBar->subControls & SC_TitleBarUnshadeButton) {
4890 bool hover = (titleBar->activeSubControls & SC_TitleBarUnshadeButton) && (titleBar->state & State_MouseOver);
4891 bool sunken = (titleBar->activeSubControls & SC_TitleBarUnshadeButton) && (titleBar->state & State_Sunken);
4892
4893 QRect unshadeButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarUnshadeButton, widget);
4894 qt_plastique_draw_mdibutton(painter, titleBar, unshadeButtonRect, hover, sunken);
4895
4896 int xoffset = unshadeButtonRect.width() / 3;
4897 int yoffset = unshadeButtonRect.height() / 3;
4898
4899 QRect unshadeButtonIconRect(unshadeButtonRect.left() + xoffset, unshadeButtonRect.top() + yoffset,
4900 unshadeButtonRect.width() - xoffset * 2, unshadeButtonRect.height() - yoffset * 2);
4901
4902 int midY = unshadeButtonIconRect.bottom() - unshadeButtonIconRect.height() / 2;
4903 QPainterPath path(QPoint(unshadeButtonIconRect.left(), midY));
4904 path.lineTo(unshadeButtonIconRect.right(), midY);
4905 path.lineTo(unshadeButtonIconRect.center().x(), unshadeButtonIconRect.bottom());
4906 path.lineTo(unshadeButtonIconRect.left(), midY);
4907
4908 painter->setPen(textAlphaColor);
4909 painter->setBrush(textColor);
4910 painter->drawPath(path);
4911 }
4912
4913 // from qwindowsstyle.cpp
4914 if ((titleBar->subControls & SC_TitleBarSysMenu) && (titleBar->titleBarFlags & Qt::WindowSystemMenuHint)) {
4915 bool hover = (titleBar->activeSubControls & SC_TitleBarSysMenu) && (titleBar->state & State_MouseOver);
4916 bool sunken = (titleBar->activeSubControls & SC_TitleBarSysMenu) && (titleBar->state & State_Sunken);
4917
4918 QRect iconRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarSysMenu, widget);
4919 if (hover)
4920 qt_plastique_draw_mdibutton(painter, titleBar, iconRect, hover, sunken);
4921
4922 if (!titleBar->icon.isNull()) {
4923 titleBar->icon.paint(painter, iconRect);
4924 } else {
4925 QStyleOption tool(0);
4926 tool.palette = titleBar->palette;
4927 QPixmap pm = standardPixmap(SP_TitleBarMenuButton, &tool, widget);
4928 tool.rect = iconRect;
4929 painter->save();
4930 proxy()->drawItemPixmap(painter, iconRect, Qt::AlignCenter, pm);
4931 painter->restore();
4932 }
4933 }
4934 painter->restore();
4935 }
4936 break;
4937 #ifndef QT_NO_DIAL
4938 case CC_Dial:
4939 if (const QStyleOptionSlider *dial = qstyleoption_cast<const QStyleOptionSlider *>(option))
4940 QStyleHelper::drawDial(dial, painter);
4941 break;
4942 #endif // QT_NO_DIAL
4943 default:
4944 QWindowsStyle::drawComplexControl(control, option, painter, widget);
4945 break;
4946 }
4947 }
4948
4949 /*!
4950 \reimp
4951 */
sizeFromContents(ContentsType type,const QStyleOption * option,const QSize & size,const QWidget * widget) const4952 QSize QPlastiqueStyle::sizeFromContents(ContentsType type, const QStyleOption *option,
4953 const QSize &size, const QWidget *widget) const
4954 {
4955 QSize newSize = QWindowsStyle::sizeFromContents(type, option, size, widget);
4956
4957 switch (type) {
4958 case CT_RadioButton:
4959 ++newSize.rheight();
4960 ++newSize.rwidth();
4961 break;
4962 #ifndef QT_NO_SLIDER
4963 case CT_Slider:
4964 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
4965 int tickSize = proxy()->pixelMetric(PM_SliderTickmarkOffset, option, widget);
4966 if (slider->tickPosition & QSlider::TicksBelow) {
4967 if (slider->orientation == Qt::Horizontal)
4968 newSize.rheight() += tickSize;
4969 else
4970 newSize.rwidth() += tickSize;
4971 }
4972 if (slider->tickPosition & QSlider::TicksAbove) {
4973 if (slider->orientation == Qt::Horizontal)
4974 newSize.rheight() += tickSize;
4975 else
4976 newSize.rwidth() += tickSize;
4977 }
4978 }
4979 break;
4980 #endif // QT_NO_SLIDER
4981 #ifndef QT_NO_SCROLLBAR
4982 case CT_ScrollBar:
4983 if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
4984 int scrollBarExtent = proxy()->pixelMetric(PM_ScrollBarExtent, option, widget);
4985 int scrollBarSliderMinimum = proxy()->pixelMetric(PM_ScrollBarSliderMin, option, widget);
4986 if (scrollBar->orientation == Qt::Horizontal) {
4987 newSize = QSize(scrollBarExtent * 3 + scrollBarSliderMinimum, scrollBarExtent);
4988 } else {
4989 newSize = QSize(scrollBarExtent, scrollBarExtent * 3 + scrollBarSliderMinimum);
4990 }
4991 }
4992 break;
4993 #endif // QT_NO_SCROLLBAR
4994 #ifndef QT_NO_SPINBOX
4995 case CT_SpinBox:
4996 // Make sure the size is odd
4997 newSize.setHeight(sizeFromContents(CT_LineEdit, option, size, widget).height());
4998 newSize.rheight() -= ((1 - newSize.rheight()) & 1);
4999 break;
5000 #endif
5001 #ifndef QT_NO_TOOLBUTTON
5002 case CT_ToolButton:
5003 newSize.rheight() += 3;
5004 newSize.rwidth() += 3;
5005 break;
5006 #endif
5007 #ifndef QT_NO_COMBOBOX
5008 case CT_ComboBox:
5009 newSize = sizeFromContents(CT_PushButton, option, size, widget);
5010 newSize.rwidth() += 30; // Make room for drop-down indicator
5011 newSize.rheight() += 4;
5012 break;
5013 #endif
5014 case CT_MenuItem:
5015 if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
5016 if (menuItem->menuItemType == QStyleOptionMenuItem::Separator)
5017 newSize.setHeight(menuItem->text.isEmpty() ? 2 : menuItem->fontMetrics.height());
5018 }
5019 break;
5020 case CT_MenuBarItem:
5021 newSize.setHeight(newSize.height());
5022 break;
5023 default:
5024 break;
5025 }
5026
5027 return newSize;
5028 }
5029
5030 /*!
5031 \reimp
5032 */
subElementRect(SubElement element,const QStyleOption * option,const QWidget * widget) const5033 QRect QPlastiqueStyle::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const
5034 {
5035 QRect rect;
5036 switch (element) {
5037 case SE_RadioButtonIndicator:
5038 rect = visualRect(option->direction, option->rect,
5039 QWindowsStyle::subElementRect(element, option, widget)).adjusted(0, 0, 1, 1);
5040 break;
5041 #ifndef QT_NO_PROGRESSBAR
5042 case SE_ProgressBarLabel:
5043 case SE_ProgressBarContents:
5044 case SE_ProgressBarGroove:
5045 return option->rect;
5046 #endif // QT_NO_PROGRESSBAR
5047 default:
5048 return QWindowsStyle::subElementRect(element, option, widget);
5049 }
5050
5051 return visualRect(option->direction, option->rect, rect);
5052 }
5053
5054 /*!
5055 \reimp
5056 */
subControlRect(ComplexControl control,const QStyleOptionComplex * option,SubControl subControl,const QWidget * widget) const5057 QRect QPlastiqueStyle::subControlRect(ComplexControl control, const QStyleOptionComplex *option,
5058 SubControl subControl, const QWidget *widget) const
5059 {
5060 QRect rect = QWindowsStyle::subControlRect(control, option, subControl, widget);
5061
5062 switch (control) {
5063 #ifndef QT_NO_SLIDER
5064 case CC_Slider:
5065 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
5066 int tickSize = proxy()->pixelMetric(PM_SliderTickmarkOffset, option, widget);
5067
5068 switch (subControl) {
5069 case SC_SliderHandle:
5070 if (slider->orientation == Qt::Horizontal) {
5071 rect.setWidth(11);
5072 rect.setHeight(15);
5073 int centerY = slider->rect.center().y() - rect.height() / 2;
5074 if (slider->tickPosition & QSlider::TicksAbove)
5075 centerY += tickSize;
5076 if (slider->tickPosition & QSlider::TicksBelow)
5077 centerY -= tickSize;
5078 rect.moveTop(centerY);
5079 } else {
5080 rect.setWidth(15);
5081 rect.setHeight(11);
5082 int centerX = slider->rect.center().x() - rect.width() / 2;
5083 if (slider->tickPosition & QSlider::TicksAbove)
5084 centerX += tickSize;
5085 if (slider->tickPosition & QSlider::TicksBelow)
5086 centerX -= tickSize;
5087 rect.moveLeft(centerX);
5088 }
5089 break;
5090 case SC_SliderGroove: {
5091 QPoint grooveCenter = slider->rect.center();
5092 if (slider->orientation == Qt::Horizontal) {
5093 rect.setHeight(14);
5094 --grooveCenter.ry();
5095 if (slider->tickPosition & QSlider::TicksAbove)
5096 grooveCenter.ry() += tickSize;
5097 if (slider->tickPosition & QSlider::TicksBelow)
5098 grooveCenter.ry() -= tickSize;
5099 } else {
5100 rect.setWidth(14);
5101 --grooveCenter.rx();
5102 if (slider->tickPosition & QSlider::TicksAbove)
5103 grooveCenter.rx() += tickSize;
5104 if (slider->tickPosition & QSlider::TicksBelow)
5105 grooveCenter.rx() -= tickSize;
5106 }
5107 rect.moveCenter(grooveCenter);
5108 break;
5109 }
5110 default:
5111 break;
5112 }
5113 }
5114 break;
5115 #endif // QT_NO_SLIDER
5116 #ifndef QT_NO_SCROLLBAR
5117 case CC_ScrollBar:
5118 if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
5119 int scrollBarExtent = proxy()->pixelMetric(PM_ScrollBarExtent, scrollBar, widget);
5120 int sliderMaxLength = ((scrollBar->orientation == Qt::Horizontal) ?
5121 scrollBar->rect.width() : scrollBar->rect.height()) - (scrollBarExtent * 3);
5122 int sliderMinLength = proxy()->pixelMetric(PM_ScrollBarSliderMin, scrollBar, widget);
5123 int sliderLength;
5124
5125 // calculate slider length
5126 if (scrollBar->maximum != scrollBar->minimum) {
5127 uint valueRange = scrollBar->maximum - scrollBar->minimum;
5128 sliderLength = (scrollBar->pageStep * sliderMaxLength) / (valueRange + scrollBar->pageStep);
5129
5130 if (sliderLength < sliderMinLength || valueRange > INT_MAX / 2)
5131 sliderLength = sliderMinLength;
5132 if (sliderLength > sliderMaxLength)
5133 sliderLength = sliderMaxLength;
5134 } else {
5135 sliderLength = sliderMaxLength;
5136 }
5137
5138 int sliderStart = scrollBarExtent + sliderPositionFromValue(scrollBar->minimum,
5139 scrollBar->maximum,
5140 scrollBar->sliderPosition,
5141 sliderMaxLength - sliderLength,
5142 scrollBar->upsideDown);
5143
5144 QRect scrollBarRect = scrollBar->rect;
5145
5146 switch (subControl) {
5147 case SC_ScrollBarSubLine: // top/left button
5148 if (scrollBar->orientation == Qt::Horizontal) {
5149 rect.setRect(scrollBarRect.left(), scrollBarRect.top(), scrollBarRect.width() - scrollBarExtent, scrollBarRect.height());
5150 } else {
5151 rect.setRect(scrollBarRect.left(), scrollBarRect.top(), scrollBarRect.width(), scrollBarRect.height() - scrollBarExtent);
5152 }
5153 break;
5154 case SC_ScrollBarAddLine: // bottom/right button
5155 if (scrollBar->orientation == Qt::Horizontal) {
5156 rect.setRect(scrollBarRect.right() - (scrollBarExtent - 1), scrollBarRect.top(), scrollBarExtent, scrollBarRect.height());
5157 } else {
5158 rect.setRect(scrollBarRect.left(), scrollBarRect.bottom() - (scrollBarExtent - 1), scrollBarRect.width(), scrollBarExtent);
5159 }
5160 break;
5161 case SC_ScrollBarSubPage:
5162 if (scrollBar->orientation == Qt::Horizontal) {
5163 rect.setRect(scrollBarRect.left() + scrollBarExtent, scrollBarRect.top(),
5164 sliderStart - (scrollBarRect.left() + scrollBarExtent), scrollBarRect.height());
5165 } else {
5166 rect.setRect(scrollBarRect.left(), scrollBarRect.top() + scrollBarExtent,
5167 scrollBarRect.width(), sliderStart - (scrollBarRect.left() + scrollBarExtent));
5168 }
5169 break;
5170 case SC_ScrollBarAddPage:
5171 if (scrollBar->orientation == Qt::Horizontal)
5172 rect.setRect(sliderStart + sliderLength, 0,
5173 sliderMaxLength - sliderStart - sliderLength + scrollBarExtent, scrollBarRect.height());
5174 else
5175 rect.setRect(0, sliderStart + sliderLength,
5176 scrollBarRect.width(), sliderMaxLength - sliderStart - sliderLength + scrollBarExtent);
5177 break;
5178 case SC_ScrollBarGroove:
5179 if (scrollBar->orientation == Qt::Horizontal) {
5180 rect = scrollBarRect.adjusted(scrollBarExtent, 0, -2 * scrollBarExtent, 0);
5181 } else {
5182 rect = scrollBarRect.adjusted(0, scrollBarExtent, 0, -2 * scrollBarExtent);
5183 }
5184 break;
5185 case SC_ScrollBarSlider:
5186 if (scrollBar->orientation == Qt::Horizontal) {
5187 rect.setRect(sliderStart, 0, sliderLength, scrollBarRect.height());
5188 } else {
5189 rect.setRect(0, sliderStart, scrollBarRect.width(), sliderLength);
5190 }
5191 break;
5192 default:
5193 break;
5194 }
5195 rect = visualRect(scrollBar->direction, scrollBarRect, rect);
5196 }
5197 break;
5198 #endif // QT_NO_SCROLLBAR
5199 #ifndef QT_NO_SPINBOX
5200 case CC_SpinBox:
5201 if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
5202 int center = spinBox->rect.height() / 2;
5203 switch (subControl) {
5204 case SC_SpinBoxUp:
5205 if (spinBox->buttonSymbols == QAbstractSpinBox::NoButtons)
5206 return QRect();
5207 rect = visualRect(spinBox->direction, spinBox->rect, rect);
5208 rect.setRect(spinBox->rect.right() - 16, spinBox->rect.top(), 17, center + 1);
5209 rect = visualRect(spinBox->direction, spinBox->rect, rect);
5210 break;
5211 case SC_SpinBoxDown:
5212 if (spinBox->buttonSymbols == QAbstractSpinBox::NoButtons)
5213 return QRect();
5214 rect = visualRect(spinBox->direction, spinBox->rect, rect);
5215 rect.setRect(spinBox->rect.right() - 16, spinBox->rect.top() + center, 17, spinBox->rect.height() - center);
5216 rect = visualRect(spinBox->direction, spinBox->rect, rect);
5217 break;
5218 case SC_SpinBoxEditField:
5219 if (spinBox->buttonSymbols != QAbstractSpinBox::NoButtons) {
5220 rect = spinBox->rect.adjusted(0, 0, -16, 0);
5221 } else {
5222 rect = spinBox->rect;
5223 }
5224 rect.adjust(blueFrameWidth, blueFrameWidth, -blueFrameWidth, -blueFrameWidth);
5225 rect = visualRect(spinBox->direction, spinBox->rect, rect);
5226 break;
5227 default:
5228 break;
5229 }
5230 }
5231 break;
5232 #endif // QT_NO_SPINBOX
5233 #ifndef QT_NO_COMBOBOX
5234 case CC_ComboBox:
5235 switch (subControl) {
5236 case SC_ComboBoxArrow:
5237 rect = visualRect(option->direction, option->rect, rect);
5238 rect.setRect(rect.right() - 17, rect.top() - 2,
5239 19, rect.height() + 4);
5240 rect = visualRect(option->direction, option->rect, rect);
5241 break;
5242 case SC_ComboBoxEditField: {
5243 if (const QStyleOptionComboBox *box = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
5244 int frameWidth = proxy()->pixelMetric(PM_DefaultFrameWidth);
5245 rect = visualRect(option->direction, option->rect, rect);
5246
5247 if (box->editable) {
5248 rect = box->rect.adjusted(blueFrameWidth, blueFrameWidth, -blueFrameWidth, -blueFrameWidth);
5249 rect.setRight(rect.right() - 16); // Overlaps the combobox button by 2 pixels
5250 } else {
5251 rect.setRect(option->rect.left() + frameWidth, option->rect.top() + frameWidth,
5252 option->rect.width() - 16 - 2 * frameWidth,
5253 option->rect.height() - 2 * frameWidth);
5254 rect.setLeft(rect.left() + 2);
5255 rect.setRight(rect.right() - 2);
5256 if (box->state & (State_Sunken | State_On))
5257 rect.translate(1, 1);
5258 }
5259 rect = visualRect(option->direction, option->rect, rect);
5260 }
5261 break;
5262 }
5263 default:
5264 break;
5265 }
5266 break;
5267 #endif // QT_NO_COMBOBOX
5268 case CC_TitleBar:
5269 if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(option)) {
5270 SubControl sc = subControl;
5271 QRect &ret = rect;
5272 const int indent = 3;
5273 const int controlTopMargin = 4;
5274 const int controlBottomMargin = 3;
5275 const int controlWidthMargin = 1;
5276 const int controlHeight = tb->rect.height() - controlTopMargin - controlBottomMargin;
5277 const int delta = controlHeight + controlWidthMargin;
5278 int offset = 0;
5279
5280 bool isMinimized = tb->titleBarState & Qt::WindowMinimized;
5281 bool isMaximized = tb->titleBarState & Qt::WindowMaximized;
5282
5283 switch (sc) {
5284 case SC_TitleBarLabel:
5285 if (tb->titleBarFlags & (Qt::WindowTitleHint | Qt::WindowSystemMenuHint)) {
5286 ret = tb->rect;
5287 if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
5288 ret.adjust(delta, 0, -delta, 0);
5289 if (tb->titleBarFlags & Qt::WindowMinimizeButtonHint)
5290 ret.adjust(0, 0, -delta, 0);
5291 if (tb->titleBarFlags & Qt::WindowMaximizeButtonHint)
5292 ret.adjust(0, 0, -delta, 0);
5293 if (tb->titleBarFlags & Qt::WindowShadeButtonHint)
5294 ret.adjust(0, 0, -delta, 0);
5295 if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
5296 ret.adjust(0, 0, -delta, 0);
5297 ret.adjusted(indent, 0, -indent, 0);
5298 }
5299 break;
5300 case SC_TitleBarContextHelpButton:
5301 if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
5302 offset += delta;
5303 case SC_TitleBarMinButton:
5304 if (!isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
5305 offset += delta;
5306 else if (sc == SC_TitleBarMinButton)
5307 break;
5308 case SC_TitleBarNormalButton:
5309 if (isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
5310 offset += delta;
5311 else if (isMaximized && (tb->titleBarFlags & Qt::WindowMaximizeButtonHint))
5312 offset += delta;
5313 else if (sc == SC_TitleBarNormalButton)
5314 break;
5315 case SC_TitleBarMaxButton:
5316 if (!isMaximized && (tb->titleBarFlags & Qt::WindowMaximizeButtonHint))
5317 offset += delta;
5318 else if (sc == SC_TitleBarMaxButton)
5319 break;
5320 case SC_TitleBarShadeButton:
5321 if (!isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
5322 offset += delta;
5323 else if (sc == SC_TitleBarShadeButton)
5324 break;
5325 case SC_TitleBarUnshadeButton:
5326 if (isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
5327 offset += delta;
5328 else if (sc == SC_TitleBarUnshadeButton)
5329 break;
5330 case SC_TitleBarCloseButton:
5331 if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
5332 offset += delta;
5333 else if (sc == SC_TitleBarCloseButton)
5334 break;
5335 ret.setRect(tb->rect.right() - indent - offset, tb->rect.top() + controlTopMargin,
5336 controlHeight, controlHeight);
5337 break;
5338 case SC_TitleBarSysMenu:
5339 if (tb->titleBarFlags & Qt::WindowSystemMenuHint) {
5340 ret.setRect(tb->rect.left() + controlWidthMargin + indent, tb->rect.top() + controlTopMargin,
5341 controlHeight, controlHeight);
5342 }
5343 break;
5344 default:
5345 break;
5346 }
5347 ret = visualRect(tb->direction, tb->rect, ret);
5348 }
5349 break;
5350 default:
5351 break;
5352 }
5353
5354 return rect;
5355 }
5356
5357 /*!
5358 \reimp
5359 */
styleHint(StyleHint hint,const QStyleOption * option,const QWidget * widget,QStyleHintReturn * returnData) const5360 int QPlastiqueStyle::styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget,
5361 QStyleHintReturn *returnData) const
5362 {
5363 int ret = 0;
5364 switch (hint) {
5365 case SH_WindowFrame_Mask:
5366 ret = 1;
5367 if (QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask *>(returnData)) {
5368 mask->region = option->rect;
5369 mask->region -= QRect(option->rect.left(), option->rect.top(), 2, 1);
5370 mask->region -= QRect(option->rect.right() - 1, option->rect.top(), 2, 1);
5371 mask->region -= QRect(option->rect.left(), option->rect.top() + 1, 1, 1);
5372 mask->region -= QRect(option->rect.right(), option->rect.top() + 1, 1, 1);
5373
5374 const QStyleOptionTitleBar *titleBar = qstyleoption_cast<const QStyleOptionTitleBar *>(option);
5375 if (titleBar && (titleBar->titleBarState & Qt::WindowMinimized)) {
5376 mask->region -= QRect(option->rect.left(), option->rect.bottom(), 2, 1);
5377 mask->region -= QRect(option->rect.right() - 1, option->rect.bottom(), 2, 1);
5378 mask->region -= QRect(option->rect.left(), option->rect.bottom() - 1, 1, 1);
5379 mask->region -= QRect(option->rect.right(), option->rect.bottom() - 1, 1, 1);
5380 } else {
5381 mask->region -= QRect(option->rect.bottomLeft(), QSize(1, 1));
5382 mask->region -= QRect(option->rect.bottomRight(), QSize(1, 1));
5383 }
5384 }
5385 break;
5386 case SH_TitleBar_NoBorder:
5387 ret = 1;
5388 break;
5389 case SH_TitleBar_AutoRaise:
5390 ret = 1;
5391 break;
5392 case SH_ItemView_ShowDecorationSelected:
5393 ret = true;
5394 break;
5395 case SH_ToolBox_SelectedPageTitleBold:
5396 case SH_ScrollBar_MiddleClickAbsolutePosition:
5397 ret = true;
5398 break;
5399 case SH_MainWindow_SpaceBelowMenuBar:
5400 ret = 0;
5401 break;
5402 case SH_FormLayoutWrapPolicy:
5403 ret = QFormLayout::DontWrapRows;
5404 break;
5405 case SH_FormLayoutFieldGrowthPolicy:
5406 ret = QFormLayout::ExpandingFieldsGrow;
5407 break;
5408 case SH_FormLayoutFormAlignment:
5409 ret = Qt::AlignLeft | Qt::AlignTop;
5410 break;
5411 case SH_FormLayoutLabelAlignment:
5412 ret = Qt::AlignRight;
5413 break;
5414 case SH_MessageBox_TextInteractionFlags:
5415 ret = Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse;
5416 break;
5417 case SH_LineEdit_PasswordCharacter:
5418 ret = QCommonStyle::styleHint(hint, option, widget, returnData);
5419 break;
5420 case SH_ItemView_ArrowKeysNavigateIntoChildren:
5421 ret = true;
5422 break;
5423 case SH_Menu_SubMenuPopupDelay:
5424 ret = 96; // from Plastik
5425 break;
5426 #ifdef Q_WS_X11
5427 case SH_DialogButtonBox_ButtonsHaveIcons:
5428 ret = true;
5429 break;
5430 #endif
5431 #ifndef Q_OS_WIN
5432 case SH_Menu_AllowActiveAndDisabled:
5433 ret = false;
5434 break;
5435 #endif
5436 default:
5437 ret = QWindowsStyle::styleHint(hint, option, widget, returnData);
5438 break;
5439 }
5440 return ret;
5441 }
5442
5443 /*!
5444 \reimp
5445 */
hitTestComplexControl(ComplexControl control,const QStyleOptionComplex * option,const QPoint & pos,const QWidget * widget) const5446 QStyle::SubControl QPlastiqueStyle::hitTestComplexControl(ComplexControl control, const QStyleOptionComplex *option,
5447 const QPoint &pos, const QWidget *widget) const
5448 {
5449 SubControl ret = SC_None;
5450 switch (control) {
5451 #ifndef QT_NO_SCROLLBAR
5452 case CC_ScrollBar:
5453 if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
5454 QRect slider = proxy()->subControlRect(control, scrollBar, SC_ScrollBarSlider, widget);
5455 if (slider.contains(pos)) {
5456 ret = SC_ScrollBarSlider;
5457 break;
5458 }
5459
5460 QRect scrollBarAddLine = proxy()->subControlRect(control, scrollBar, SC_ScrollBarAddLine, widget);
5461 if (scrollBarAddLine.contains(pos)) {
5462 ret = SC_ScrollBarAddLine;
5463 break;
5464 }
5465
5466 QRect scrollBarSubPage = proxy()->subControlRect(control, scrollBar, SC_ScrollBarSubPage, widget);
5467 if (scrollBarSubPage.contains(pos)) {
5468 ret = SC_ScrollBarSubPage;
5469 break;
5470 }
5471
5472 QRect scrollBarAddPage = proxy()->subControlRect(control, scrollBar, SC_ScrollBarAddPage, widget);
5473 if (scrollBarAddPage.contains(pos)) {
5474 ret = SC_ScrollBarAddPage;
5475 break;
5476 }
5477
5478 QRect scrollBarSubLine = proxy()->subControlRect(control, scrollBar, SC_ScrollBarSubLine, widget);
5479 if (scrollBarSubLine.contains(pos)) {
5480 ret = SC_ScrollBarSubLine;
5481 break;
5482 }
5483 }
5484 break;
5485 #endif // QT_NO_SCROLLBAR
5486 default:
5487 break;
5488 }
5489
5490 return ret != SC_None ? ret : QWindowsStyle::hitTestComplexControl(control, option, pos, widget);
5491 }
5492
5493 /*!
5494 \reimp
5495 */
pixelMetric(PixelMetric metric,const QStyleOption * option,const QWidget * widget) const5496 int QPlastiqueStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const
5497 {
5498 int ret = -1;
5499 switch (metric) {
5500 case PM_MenuVMargin:
5501 case PM_MenuHMargin:
5502 ret = 0;
5503 break;
5504 case PM_ButtonShiftHorizontal:
5505 case PM_ButtonShiftVertical:
5506 ret = 1;
5507 break;
5508 case PM_ButtonDefaultIndicator:
5509 ret = 0;
5510 break;
5511 #ifndef QT_NO_SLIDER
5512 case PM_SliderThickness:
5513 ret = 15;
5514 break;
5515 case PM_SliderLength:
5516 case PM_SliderControlThickness:
5517 ret = 11;
5518 break;
5519 case PM_SliderTickmarkOffset:
5520 ret = 5;
5521 break;
5522 case PM_SliderSpaceAvailable:
5523 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
5524 int size = 15;
5525 if (slider->tickPosition & QSlider::TicksBelow)
5526 ++size;
5527 if (slider->tickPosition & QSlider::TicksAbove)
5528 ++size;
5529 ret = size;
5530 break;
5531 }
5532 #endif // QT_NO_SLIDER
5533 case PM_ScrollBarExtent:
5534 ret = 16;
5535 break;
5536 case PM_ScrollBarSliderMin:
5537 ret = 26;
5538 break;
5539 case PM_ProgressBarChunkWidth:
5540 ret = 1;
5541 break;
5542 case PM_MenuBarItemSpacing:
5543 ret = 3;
5544 break;
5545 case PM_MenuBarVMargin:
5546 ret = 2;
5547 break;
5548 case PM_MenuBarHMargin:
5549 ret = 0;
5550 break;
5551 case PM_MenuBarPanelWidth:
5552 ret = 1;
5553 break;
5554 case PM_ToolBarHandleExtent:
5555 ret = 9;
5556 break;
5557 case PM_ToolBarSeparatorExtent:
5558 ret = 2;
5559 break;
5560 case PM_ToolBarItemSpacing:
5561 ret = 1;
5562 break;
5563 case PM_ToolBarItemMargin:
5564 ret = 1;
5565 break;
5566 case PM_ToolBarFrameWidth:
5567 ret = 2;
5568 break;
5569 case PM_SplitterWidth:
5570 ret = 6;
5571 break;
5572 case PM_DockWidgetSeparatorExtent:
5573 ret = 6;
5574 break;
5575 case PM_DockWidgetHandleExtent:
5576 ret = 20;
5577 break;
5578 case PM_DefaultFrameWidth:
5579 #ifndef QT_NO_MENU
5580 if (qobject_cast<const QMenu *>(widget)) {
5581 ret = 1;
5582 break;
5583 }
5584 #endif
5585 ret = 2;
5586 break;
5587 case PM_MdiSubWindowFrameWidth:
5588 ret = 4;
5589 break;
5590 case PM_TitleBarHeight:
5591 #ifdef QT3_SUPPORT
5592 if (widget && widget->inherits("Q3DockWindowTitleBar")) {
5593 // Q3DockWindow has smaller title bars than QDockWidget
5594 ret = qMax(widget->fontMetrics().height(), 20);
5595 } else
5596 #endif
5597 ret = qMax(widget ? widget->fontMetrics().height() :
5598 (option ? option->fontMetrics.height() : 0), 30);
5599 break;
5600 case PM_MaximumDragDistance:
5601 return -1;
5602 case PM_DockWidgetTitleMargin:
5603 return 2;
5604 case PM_LayoutHorizontalSpacing:
5605 case PM_LayoutVerticalSpacing:
5606 return -1; // rely on layoutHorizontalSpacing()
5607 case PM_LayoutLeftMargin:
5608 case PM_LayoutTopMargin:
5609 case PM_LayoutRightMargin:
5610 case PM_LayoutBottomMargin:
5611 {
5612 bool isWindow = false;
5613 if (option) {
5614 isWindow = (option->state & State_Window);
5615 } else if (widget) {
5616 isWindow = widget->isWindow();
5617 }
5618
5619 if (isWindow) {
5620 ret = 11;
5621 } else {
5622 ret = 9;
5623 }
5624 }
5625 default:
5626 break;
5627 }
5628
5629 return ret != -1 ? ret : QWindowsStyle::pixelMetric(metric, option, widget);
5630 }
5631
5632 /*!
5633 \reimp
5634 */
standardPalette() const5635 QPalette QPlastiqueStyle::standardPalette() const
5636 {
5637 QPalette palette;
5638
5639 palette.setBrush(QPalette::Disabled, QPalette::WindowText, QColor(QRgb(0xff808080)));
5640 palette.setBrush(QPalette::Disabled, QPalette::Button, QColor(QRgb(0xffdddfe4)));
5641 palette.setBrush(QPalette::Disabled, QPalette::Light, QColor(QRgb(0xffffffff)));
5642 palette.setBrush(QPalette::Disabled, QPalette::Midlight, QColor(QRgb(0xffffffff)));
5643 palette.setBrush(QPalette::Disabled, QPalette::Dark, QColor(QRgb(0xff555555)));
5644 palette.setBrush(QPalette::Disabled, QPalette::Mid, QColor(QRgb(0xffc7c7c7)));
5645 palette.setBrush(QPalette::Disabled, QPalette::Text, QColor(QRgb(0xffc7c7c7)));
5646 palette.setBrush(QPalette::Disabled, QPalette::BrightText, QColor(QRgb(0xffffffff)));
5647 palette.setBrush(QPalette::Disabled, QPalette::ButtonText, QColor(QRgb(0xff808080)));
5648 palette.setBrush(QPalette::Disabled, QPalette::Base, QColor(QRgb(0xffefefef)));
5649 palette.setBrush(QPalette::Disabled, QPalette::AlternateBase, palette.color(QPalette::Disabled, QPalette::Base).darker(110));
5650 palette.setBrush(QPalette::Disabled, QPalette::Window, QColor(QRgb(0xffefefef)));
5651 palette.setBrush(QPalette::Disabled, QPalette::Shadow, QColor(QRgb(0xff000000)));
5652 palette.setBrush(QPalette::Disabled, QPalette::Highlight, QColor(QRgb(0xff567594)));
5653 palette.setBrush(QPalette::Disabled, QPalette::HighlightedText, QColor(QRgb(0xffffffff)));
5654 palette.setBrush(QPalette::Disabled, QPalette::Link, QColor(QRgb(0xff0000ee)));
5655 palette.setBrush(QPalette::Disabled, QPalette::LinkVisited, QColor(QRgb(0xff52188b)));
5656 palette.setBrush(QPalette::Active, QPalette::WindowText, QColor(QRgb(0xff000000)));
5657 palette.setBrush(QPalette::Active, QPalette::Button, QColor(QRgb(0xffdddfe4)));
5658 palette.setBrush(QPalette::Active, QPalette::Light, QColor(QRgb(0xffffffff)));
5659 palette.setBrush(QPalette::Active, QPalette::Midlight, QColor(QRgb(0xffffffff)));
5660 palette.setBrush(QPalette::Active, QPalette::Dark, QColor(QRgb(0xff555555)));
5661 palette.setBrush(QPalette::Active, QPalette::Mid, QColor(QRgb(0xffc7c7c7)));
5662 palette.setBrush(QPalette::Active, QPalette::Text, QColor(QRgb(0xff000000)));
5663 palette.setBrush(QPalette::Active, QPalette::BrightText, QColor(QRgb(0xffffffff)));
5664 palette.setBrush(QPalette::Active, QPalette::ButtonText, QColor(QRgb(0xff000000)));
5665 palette.setBrush(QPalette::Active, QPalette::Base, QColor(QRgb(0xffffffff)));
5666 palette.setBrush(QPalette::Active, QPalette::AlternateBase, palette.color(QPalette::Active, QPalette::Base).darker(110));
5667 palette.setBrush(QPalette::Active, QPalette::Window, QColor(QRgb(0xffefefef)));
5668 palette.setBrush(QPalette::Active, QPalette::Shadow, QColor(QRgb(0xff000000)));
5669 palette.setBrush(QPalette::Active, QPalette::Highlight, QColor(QRgb(0xff678db2)));
5670 palette.setBrush(QPalette::Active, QPalette::HighlightedText, QColor(QRgb(0xffffffff)));
5671 palette.setBrush(QPalette::Active, QPalette::Link, QColor(QRgb(0xff0000ee)));
5672 palette.setBrush(QPalette::Active, QPalette::LinkVisited, QColor(QRgb(0xff52188b)));
5673 palette.setBrush(QPalette::Inactive, QPalette::WindowText, QColor(QRgb(0xff000000)));
5674 palette.setBrush(QPalette::Inactive, QPalette::Button, QColor(QRgb(0xffdddfe4)));
5675 palette.setBrush(QPalette::Inactive, QPalette::Light, QColor(QRgb(0xffffffff)));
5676 palette.setBrush(QPalette::Inactive, QPalette::Midlight, QColor(QRgb(0xffffffff)));
5677 palette.setBrush(QPalette::Inactive, QPalette::Dark, QColor(QRgb(0xff555555)));
5678 palette.setBrush(QPalette::Inactive, QPalette::Mid, QColor(QRgb(0xffc7c7c7)));
5679 palette.setBrush(QPalette::Inactive, QPalette::Text, QColor(QRgb(0xff000000)));
5680 palette.setBrush(QPalette::Inactive, QPalette::BrightText, QColor(QRgb(0xffffffff)));
5681 palette.setBrush(QPalette::Inactive, QPalette::ButtonText, QColor(QRgb(0xff000000)));
5682 palette.setBrush(QPalette::Inactive, QPalette::Base, QColor(QRgb(0xffffffff)));
5683 palette.setBrush(QPalette::Inactive, QPalette::AlternateBase, palette.color(QPalette::Inactive, QPalette::Base).darker(110));
5684 palette.setBrush(QPalette::Inactive, QPalette::Window, QColor(QRgb(0xffefefef)));
5685 palette.setBrush(QPalette::Inactive, QPalette::Shadow, QColor(QRgb(0xff000000)));
5686 palette.setBrush(QPalette::Inactive, QPalette::Highlight, QColor(QRgb(0xff678db2)));
5687 palette.setBrush(QPalette::Inactive, QPalette::HighlightedText, QColor(QRgb(0xffffffff)));
5688 palette.setBrush(QPalette::Inactive, QPalette::Link, QColor(QRgb(0xff0000ee)));
5689 palette.setBrush(QPalette::Inactive, QPalette::LinkVisited, QColor(QRgb(0xff52188b)));
5690 return palette;
5691 }
5692
5693 /*!
5694 \reimp
5695 */
polish(QWidget * widget)5696 void QPlastiqueStyle::polish(QWidget *widget)
5697 {
5698 if (qobject_cast<QPushButton *>(widget)
5699 #ifndef QT_NO_COMBOBOX
5700 || qobject_cast<QComboBox *>(widget)
5701 #endif
5702 #ifndef QT_NO_SPINBOX
5703 || qobject_cast<QAbstractSpinBox *>(widget)
5704 #endif
5705 || qobject_cast<QCheckBox *>(widget)
5706 #ifndef QT_NO_GROUPBOX
5707 || qobject_cast<QGroupBox *>(widget)
5708 #endif
5709 || qobject_cast<QRadioButton *>(widget)
5710 #ifndef QT_NO_SPLITTER
5711 || qobject_cast<QSplitterHandle *>(widget)
5712 #endif
5713 #ifndef QT_NO_TABBAR
5714 || qobject_cast<QTabBar *>(widget)
5715 #endif
5716 ) {
5717 widget->setAttribute(Qt::WA_Hover);
5718 }
5719
5720 if (widget->inherits("QWorkspaceTitleBar")
5721 || widget->inherits("QDockSeparator")
5722 || widget->inherits("QDockWidgetSeparator")
5723 || widget->inherits("Q3DockWindowResizeHandle")) {
5724 widget->setAttribute(Qt::WA_Hover);
5725 }
5726
5727 if (false // to simplify the #ifdefs
5728 #ifndef QT_NO_MENUBAR
5729 || qobject_cast<QMenuBar *>(widget)
5730 #endif
5731 #ifdef QT3_SUPPORT
5732 || widget->inherits("Q3ToolBar")
5733 #endif
5734 #ifndef QT_NO_TOOLBAR
5735 || qobject_cast<QToolBar *>(widget)
5736 || (widget && qobject_cast<QToolBar *>(widget->parent()))
5737 #endif
5738 ) {
5739 widget->setBackgroundRole(QPalette::Window);
5740 }
5741
5742 #ifndef QT_NO_PROGRESSBAR
5743 if (AnimateBusyProgressBar && qobject_cast<QProgressBar *>(widget))
5744 widget->installEventFilter(this);
5745 #endif
5746
5747 #if defined QPlastique_MaskButtons
5748 if (qobject_cast<QPushButton *>(widget) || qobject_cast<QToolButton *>(widget))
5749 widget->installEventFilter(this);
5750 #endif
5751 }
5752
5753 /*!
5754 \reimp
5755 */
unpolish(QWidget * widget)5756 void QPlastiqueStyle::unpolish(QWidget *widget)
5757 {
5758 if (qobject_cast<QPushButton *>(widget)
5759 #ifndef QT_NO_COMBOBOX
5760 || qobject_cast<QComboBox *>(widget)
5761 #endif
5762 #ifndef QT_NO_SPINBOX
5763 || qobject_cast<QAbstractSpinBox *>(widget)
5764 #endif
5765 || qobject_cast<QCheckBox *>(widget)
5766 #ifndef QT_NO_GROUPBOX
5767 || qobject_cast<QGroupBox *>(widget)
5768 #endif
5769 #ifndef QT_NO_SPLITTER
5770 || qobject_cast<QSplitterHandle *>(widget)
5771 #endif
5772 #ifndef QT_NO_TABBAR
5773 || qobject_cast<QTabBar *>(widget)
5774 #endif
5775 || qobject_cast<QRadioButton *>(widget)) {
5776 widget->setAttribute(Qt::WA_Hover, false);
5777 }
5778
5779 if (widget->inherits("QWorkspaceTitleBar")
5780 || widget->inherits("QDockSeparator")
5781 || widget->inherits("QDockWidgetSeparator")
5782 || widget->inherits("Q3DockWindowResizeHandle")) {
5783 widget->setAttribute(Qt::WA_Hover, false);
5784 }
5785
5786 if (false // to simplify the #ifdefs
5787 #ifndef QT_NO_MENUBAR
5788 || qobject_cast<QMenuBar *>(widget)
5789 #endif
5790 #ifndef QT_NO_TOOLBOX
5791 || qobject_cast<QToolBox *>(widget)
5792 #endif
5793 #ifdef QT3_SUPPORT
5794 || widget->inherits("Q3ToolBar")
5795 #endif
5796 #ifndef QT_NO_TOOLBAR
5797 || qobject_cast<QToolBar *>(widget)
5798 || (widget && qobject_cast<QToolBar *>(widget->parent()))
5799 #endif
5800 ) {
5801 widget->setBackgroundRole(QPalette::Button);
5802 }
5803
5804 #ifndef QT_NO_PROGRESSBAR
5805 if (AnimateBusyProgressBar && qobject_cast<QProgressBar *>(widget)) {
5806 Q_D(QPlastiqueStyle);
5807 widget->removeEventFilter(this);
5808 d->bars.removeAll(static_cast<QProgressBar*>(widget));
5809 }
5810 #endif
5811
5812 #if defined QPlastique_MaskButtons
5813 if (qobject_cast<QPushButton *>(widget) || qobject_cast<QToolButton *>(widget))
5814 widget->removeEventFilter(this);
5815 #endif
5816 }
5817
5818 /*!
5819 \reimp
5820 */
polish(QApplication * app)5821 void QPlastiqueStyle::polish(QApplication *app)
5822 {
5823 QWindowsStyle::polish(app);
5824 }
5825
5826 /*!
5827 \reimp
5828 */
polish(QPalette & pal)5829 void QPlastiqueStyle::polish(QPalette &pal)
5830 {
5831 QWindowsStyle::polish(pal);
5832 #ifdef Q_WS_MAC
5833 pal.setBrush(QPalette::Shadow, Qt::black);
5834 #endif
5835 }
5836
5837 /*!
5838 \reimp
5839 */
unpolish(QApplication * app)5840 void QPlastiqueStyle::unpolish(QApplication *app)
5841 {
5842 QWindowsStyle::unpolish(app);
5843 }
5844
5845 /*!
5846 \internal
5847 */
standardIconImplementation(StandardPixmap standardIcon,const QStyleOption * option,const QWidget * widget) const5848 QIcon QPlastiqueStyle::standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *option,
5849 const QWidget *widget) const
5850 {
5851 return QWindowsStyle::standardIconImplementation(standardIcon, option, widget);
5852 }
5853
5854 /*!
5855 \reimp
5856 */
standardPixmap(StandardPixmap standardPixmap,const QStyleOption * opt,const QWidget * widget) const5857 QPixmap QPlastiqueStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt,
5858 const QWidget *widget) const
5859 {
5860 return QWindowsStyle::standardPixmap(standardPixmap, opt, widget);
5861 }
5862
5863 // this works as long as we have at most 16 different control types
5864 #define CT1(c) CT2(c, c)
5865 #define CT2(c1, c2) (((uint)c1 << 16) | (uint)c2)
5866
5867 /*!
5868 \internal
5869 */
layoutSpacingImplementation(QSizePolicy::ControlType control1,QSizePolicy::ControlType control2,Qt::Orientation orientation,const QStyleOption *,const QWidget *) const5870 int QPlastiqueStyle::layoutSpacingImplementation(QSizePolicy::ControlType control1,
5871 QSizePolicy::ControlType control2,
5872 Qt::Orientation orientation,
5873 const QStyleOption * /* option */,
5874 const QWidget * /* widget */) const
5875 {
5876 const int ButtonMask = QSizePolicy::ButtonBox | QSizePolicy::PushButton;
5877
5878 if (control2 == QSizePolicy::ButtonBox)
5879 return 11;
5880
5881 if ((control1 | control2) & ButtonMask)
5882 return (orientation == Qt::Horizontal) ? 10 : 9;
5883
5884 switch (CT2(control1, control2)) {
5885 case CT1(QSizePolicy::Label):
5886 case CT2(QSizePolicy::Label, QSizePolicy::DefaultType):
5887 case CT2(QSizePolicy::Label, QSizePolicy::CheckBox):
5888 case CT2(QSizePolicy::Label, QSizePolicy::ComboBox):
5889 case CT2(QSizePolicy::Label, QSizePolicy::LineEdit):
5890 case CT2(QSizePolicy::Label, QSizePolicy::RadioButton):
5891 case CT2(QSizePolicy::Label, QSizePolicy::Slider):
5892 case CT2(QSizePolicy::Label, QSizePolicy::SpinBox):
5893 case CT2(QSizePolicy::Label, QSizePolicy::ToolButton):
5894 return 5;
5895 case CT2(QSizePolicy::CheckBox, QSizePolicy::RadioButton):
5896 case CT2(QSizePolicy::RadioButton, QSizePolicy::CheckBox):
5897 case CT1(QSizePolicy::CheckBox):
5898 if (orientation == Qt::Vertical)
5899 return 2;
5900 case CT1(QSizePolicy::RadioButton):
5901 if (orientation == Qt::Vertical)
5902 return 1;
5903 }
5904
5905 if (orientation == Qt::Horizontal
5906 && (control2 & (QSizePolicy::CheckBox | QSizePolicy::RadioButton)))
5907 return 8;
5908
5909 if ((control1 | control2) & (QSizePolicy::Frame
5910 | QSizePolicy::GroupBox
5911 | QSizePolicy::TabWidget)) {
5912 return 11;
5913 }
5914
5915 if ((control1 | control2) & (QSizePolicy::Line | QSizePolicy::Slider
5916 | QSizePolicy::LineEdit | QSizePolicy::ComboBox
5917 | QSizePolicy::SpinBox))
5918 return 7;
5919
5920 return 6;
5921 }
5922
5923 /*!
5924 \reimp
5925 */
eventFilter(QObject * watched,QEvent * event)5926 bool QPlastiqueStyle::eventFilter(QObject *watched, QEvent *event)
5927 {
5928 #ifndef QT_NO_PROGRESSBAR
5929 Q_D(QPlastiqueStyle);
5930
5931 switch (event->type()) {
5932 case QEvent::Show:
5933 if (QProgressBar *bar = qobject_cast<QProgressBar *>(watched)) {
5934 d->bars.append(bar);
5935 if (d->bars.size() == 1) {
5936 Q_ASSERT(ProgressBarFps > 0);
5937 d->timer.start();
5938 d->progressBarAnimateTimer = startTimer(1000 / ProgressBarFps);
5939 }
5940 }
5941 break;
5942 case QEvent::Destroy:
5943 case QEvent::Hide:
5944 if(!d->bars.isEmpty()) {
5945 d->bars.removeAll(reinterpret_cast<QProgressBar*>(watched));
5946 if (d->bars.isEmpty()) {
5947 killTimer(d->progressBarAnimateTimer);
5948 d->progressBarAnimateTimer = 0;
5949 }
5950 }
5951 break;
5952 #if defined QPlastique_MaskButtons
5953 case QEvent::Resize:
5954 if (qobject_cast<QPushButton *>(watched) || qobject_cast<QToolButton *>(watched)) {
5955 QWidget *widget = qobject_cast<QWidget *>(watched);
5956 QRect rect = widget->rect();
5957 QRegion region(rect);
5958 region -= QRect(rect.left(), rect.top(), 2, 1);
5959 region -= QRect(rect.left(), rect.top() + 1, 1, 1);
5960 region -= QRect(rect.left(), rect.bottom(), 2, 1);
5961 region -= QRect(rect.left(), rect.bottom() - 1, 1, 1);
5962 region -= QRect(rect.right() - 1, rect.top(), 2, 1);
5963 region -= QRect(rect.right(), rect.top() + 1, 1, 1);
5964 region -= QRect(rect.right() - 1, rect.bottom(), 2, 1);
5965 region -= QRect(rect.right(), rect.bottom() - 1, 1, 1);
5966 widget->setMask(region);
5967 }
5968 break;
5969 #endif
5970 default:
5971 break;
5972 }
5973 #endif // QT_NO_PROGRESSBAR
5974
5975 return QWindowsStyle::eventFilter(watched, event);
5976 }
5977
5978 /*!
5979 \reimp
5980 */
timerEvent(QTimerEvent * event)5981 void QPlastiqueStyle::timerEvent(QTimerEvent *event)
5982 {
5983 #ifndef QT_NO_PROGRESSBAR
5984 Q_D(QPlastiqueStyle);
5985
5986 if (event->timerId() == d->progressBarAnimateTimer) {
5987 Q_ASSERT(ProgressBarFps > 0);
5988 d->animateStep = d->timer.elapsed() / (1000 / ProgressBarFps);
5989 foreach (QProgressBar *bar, d->bars) {
5990 if (AnimateProgressBar || (bar->minimum() == 0 && bar->maximum() == 0))
5991 bar->update();
5992 }
5993 }
5994 #endif // QT_NO_PROGRESSBAR
5995 event->ignore();
5996 }
5997
5998 QT_END_NAMESPACE
5999
6000 #endif // !defined(QT_NO_STYLE_PLASTIQUE) || defined(QT_PLUGIN)
6001