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 "qcleanlooksstyle.h"
43 #include "qcleanlooksstyle_p.h"
44
45 #if !defined(QT_NO_STYLE_CLEANLOOKS) || defined(QT_PLUGIN)
46
47 #include "qwindowsstyle_p.h"
48 #include <qcombobox.h>
49 #include <qpushbutton.h>
50 #include <qpainter.h>
51 #include <qdir.h>
52 #include <qhash.h>
53 #include <qstyleoption.h>
54 #include <qapplication.h>
55 #include <qmainwindow.h>
56 #include <qfont.h>
57 #include <qgroupbox.h>
58 #include <qprocess.h>
59 #include <qpixmapcache.h>
60 #include <qdialogbuttonbox.h>
61 #include <qscrollbar.h>
62 #include <qspinbox.h>
63 #include <qslider.h>
64 #include <qsplitter.h>
65 #include <qprogressbar.h>
66 #include <qtoolbar.h>
67 #include <qwizard.h>
68 #include <qlibrary.h>
69 #include <private/qstylehelper_p.h>
70
71 QT_BEGIN_NAMESPACE
72
73 using namespace QStyleHelper;
74
75 enum Direction {
76 TopDown,
77 FromLeft,
78 BottomUp,
79 FromRight
80 };
81
82 // from windows style
83 static const int windowsItemFrame = 2; // menu item frame width
84 static const int windowsItemHMargin = 3; // menu item hor text margin
85 static const int windowsItemVMargin = 8; // menu item ver text margin
86 static const int windowsRightBorder = 15; // right border on windows
87
88 /* XPM */
89 static const char * const dock_widget_close_xpm[] = {
90 "11 13 7 1",
91 " c None",
92 ". c #D5CFCB",
93 "+ c #8F8B88",
94 "@ c #6C6A67",
95 "# c #ABA6A3",
96 "$ c #B5B0AC",
97 "% c #A4A09D",
98 " ",
99 " +@@@@@@@+ ",
100 "+# #+",
101 "@ $@ @$ @",
102 "@ @@@ @@@ @",
103 "@ @@@@@ @",
104 "@ @@@ @",
105 "@ @@@@@ @",
106 "@ @@@ @@@ @",
107 "@ $@ @$ @",
108 "+% #+",
109 " +@@@@@@@+ ",
110 " "};
111
112 static const char * const qt_cleanlooks_arrow_down_xpm[] = {
113 "11 7 2 1",
114 " c None",
115 "x c #000000",
116 " ",
117 " x x ",
118 " xxx xxx ",
119 " xxxxxxx ",
120 " xxxxx ",
121 " xxx ",
122 " x "};
123
124 static const char * const qt_cleanlooks_arrow_up_xpm[] = {
125 "11 7 2 1",
126 " c None",
127 "x c #000000",
128 " x ",
129 " xxx ",
130 " xxxxx ",
131 " xxxxxxx ",
132 " xxx xxx ",
133 " x x ",
134 " "};
135
136 static const char * const dock_widget_restore_xpm[] = {
137 "11 13 7 1",
138 " c None",
139 ". c #D5CFCB",
140 "+ c #8F8B88",
141 "@ c #6C6A67",
142 "# c #ABA6A3",
143 "$ c #B5B0AC",
144 "% c #A4A09D",
145 " ",
146 " +@@@@@@@+ ",
147 "+# #+",
148 "@ #@@@# @",
149 "@ @ @ @",
150 "@ #@@@# @ @",
151 "@ @ @ @ @",
152 "@ @ @@@ @",
153 "@ @ @ @",
154 "@ #@@@# @",
155 "+% #+",
156 " +@@@@@@@+ ",
157 " "};
158
159 static const char * const workspace_minimize[] = {
160 "11 13 7 1",
161 " c None",
162 ". c #D5CFCB",
163 "+ c #8F8B88",
164 "@ c #6C6A67",
165 "# c #ABA6A3",
166 "$ c #B5B0AC",
167 "% c #A4A09D",
168 " ",
169 " +@@@@@@@+ ",
170 "+# #+",
171 "@ @",
172 "@ @",
173 "@ @",
174 "@ @@@@@@@ @",
175 "@ @@@@@@@ @",
176 "@ @",
177 "@ @",
178 "+% #+",
179 " +@@@@@@@+ ",
180 " "};
181
182
183 static const char * const qt_titlebar_context_help[] = {
184 "10 10 3 1",
185 " c None",
186 "# c #000000",
187 "+ c #444444",
188 " +####+ ",
189 " ### ### ",
190 " ## ## ",
191 " +##+ ",
192 " +## ",
193 " ## ",
194 " ## ",
195 " ",
196 " ## ",
197 " ## "};
198
199 static const char * const qt_cleanlooks_radiobutton[] = {
200 "13 13 9 1",
201 " c None",
202 ". c #ABA094",
203 "+ c #B7ADA0",
204 "@ c #C4BBB2",
205 "# c #DDD4CD",
206 "$ c #E7E1E0",
207 "% c #F4EFED",
208 "& c #FFFAF9",
209 "* c #FCFEFB",
210 " #@...@# ",
211 " @+@#$$#+@ ",
212 " @+$%%***&@@ ",
213 "#+$%**&&**&+#",
214 "@@$&&******#@",
215 ".#**********.",
216 ".$&******&*&.",
217 ".$*&******&*.",
218 "+#********&#@",
219 "#+*********+#",
220 " @@*******@@ ",
221 " @+#%*%#+@ ",
222 " #@...+# "};
223
224 static const char * const qt_cleanlooks_radiobutton_checked[] = {
225 "13 13 20 1",
226 " c None",
227 ". c #A8ABAE",
228 "+ c #596066",
229 "@ c #283138",
230 "# c #A9ACAF",
231 "$ c #A6A9AB",
232 "% c #6B7378",
233 "& c #8C9296",
234 "* c #A2A6AA",
235 "= c #61696F",
236 "- c #596065",
237 "; c #93989C",
238 "> c #777E83",
239 ", c #60686E",
240 "' c #252D33",
241 ") c #535B62",
242 "! c #21292E",
243 "~ c #242B31",
244 "{ c #1F262B",
245 "] c #41484E",
246 " ",
247 " ",
248 " ",
249 " .+@+# ",
250 " $%&*&=# ",
251 " -&;>,'+ ",
252 " @*>,)!@ ",
253 " +&,)~{+ ",
254 " #='!{]# ",
255 " #+@+# ",
256 " ",
257 " ",
258 " "};
259
260
261 static const char * const qt_scrollbar_button_arrow_left[] = {
262 "4 7 2 1",
263 " c None",
264 "* c #BFBFBF",
265 " *",
266 " **",
267 " ***",
268 "****",
269 " ***",
270 " **",
271 " *"};
272
273 static const char * const qt_scrollbar_button_arrow_right[] = {
274 "4 7 2 1",
275 " c None",
276 "* c #BFBFBF",
277 "* ",
278 "** ",
279 "*** ",
280 "****",
281 "*** ",
282 "** ",
283 "* "};
284
285 static const char * const qt_scrollbar_button_arrow_up[] = {
286 "7 4 2 1",
287 " c None",
288 "* c #BFBFBF",
289 " * ",
290 " *** ",
291 " ***** ",
292 "*******"};
293
294 static const char * const qt_scrollbar_button_arrow_down[] = {
295 "7 4 2 1",
296 " c None",
297 "* c #BFBFBF",
298 "*******",
299 " ***** ",
300 " *** ",
301 " * "};
302
303 static const char * const qt_spinbox_button_arrow_down[] = {
304 "7 4 2 1",
305 " c None",
306 "* c #BFBFBF",
307 "*******",
308 " ***** ",
309 " *** ",
310 " * "};
311
312 static const char * const qt_spinbox_button_arrow_up[] = {
313 "7 4 2 1",
314 " c None",
315 "* c #BFBFBF",
316 " * ",
317 " *** ",
318 " ***** ",
319 "*******"};
320
321 static const char * const qt_scrollbar_button_left[] = {
322 "16 16 6 1",
323 " c None",
324 ". c #BFBFBF",
325 "+ c #979797",
326 "# c #FAFAFA",
327 "< c #FAFAFA",
328 "* c #FAFAFA",
329 " .++++++++++++++",
330 ".+#############+",
331 "+# <+",
332 "+# <+",
333 "+# <+",
334 "+# <+",
335 "+# <+",
336 "+# <+",
337 "+# <+",
338 "+# <+",
339 "+# <+",
340 "+# <+",
341 "+# <+",
342 "+# <+",
343 ".+<<<<<<<<<<<<<+",
344 " .++++++++++++++"};
345
346 static const char * const qt_scrollbar_button_right[] = {
347 "16 16 6 1",
348 " c None",
349 ". c #BFBFBF",
350 "+ c #979797",
351 "# c #FAFAFA",
352 "< c #FAFAFA",
353 "* c #FAFAFA",
354 "++++++++++++++. ",
355 "+#############+.",
356 "+# <+",
357 "+# <+",
358 "+# <+",
359 "+# <+",
360 "+# <+",
361 "+# <+",
362 "+# <+",
363 "+# <+",
364 "+# <+",
365 "+# <+",
366 "+# <+",
367 "+# <+",
368 "+<<<<<<<<<<<<<+.",
369 "++++++++++++++. "};
370
371 static const char * const qt_scrollbar_button_up[] = {
372 "16 16 6 1",
373 " c None",
374 ". c #BFBFBF",
375 "+ c #979797",
376 "# c #FAFAFA",
377 "< c #FAFAFA",
378 "* c #FAFAFA",
379 " .++++++++++++. ",
380 ".+############+.",
381 "+# <+",
382 "+# <+",
383 "+# <+",
384 "+# <+",
385 "+# <+",
386 "+# <+",
387 "+# <+",
388 "+# <+",
389 "+# <+",
390 "+# <+",
391 "+# <+",
392 "+# <+",
393 "+<<<<<<<<<<<<<<+",
394 "++++++++++++++++"};
395
396 static const char * const qt_scrollbar_button_down[] = {
397 "16 16 6 1",
398 " c None",
399 ". c #BFBFBF",
400 "+ c #979797",
401 "# c #FAFAFA",
402 "< c #FAFAFA",
403 "* c #FAFAFA",
404 "++++++++++++++++",
405 "+##############+",
406 "+# <+",
407 "+# <+",
408 "+# <+",
409 "+# <+",
410 "+# <+",
411 "+# <+",
412 "+# <+",
413 "+# <+",
414 "+# <+",
415 "+# <+",
416 "+# <+",
417 "+# <+",
418 ".+<<<<<<<<<<<<+.",
419 " .++++++++++++. "};
420
421 static const char * const qt_cleanlooks_menuitem_checkbox_checked[] = {
422 "8 7 6 1",
423 " g None",
424 ". g #959595",
425 "+ g #676767",
426 "@ g #454545",
427 "# g #1D1D1D",
428 "0 g #101010",
429 " ..",
430 " .+ ",
431 " .+ ",
432 "0 .@ ",
433 "@#++. ",
434 " @# ",
435 " . "};
436
437 static const char * const qt_cleanlooks_checkbox_checked[] = {
438 "13 13 3 1",
439 " c None",
440 ". c #272D33",
441 "% c #666666",
442
443 " ",
444 " % ",
445 " %. ",
446 " %.% ",
447 " %.. ",
448 " %.% %.. ",
449 " %..%..% ",
450 " %...% ",
451 " %..% ",
452 " %.% ",
453 " % ",
454 " ",
455 " "};
456
qt_cleanlooks_draw_gradient(QPainter * painter,const QRect & rect,const QColor & gradientStart,const QColor & gradientStop,Direction direction=TopDown,QBrush bgBrush=QBrush ())457 static void qt_cleanlooks_draw_gradient(QPainter *painter, const QRect &rect, const QColor &gradientStart,
458 const QColor &gradientStop, Direction direction = TopDown, QBrush bgBrush = QBrush())
459 {
460 int x = rect.center().x();
461 int y = rect.center().y();
462 QLinearGradient *gradient;
463 switch(direction) {
464 case FromLeft:
465 gradient = new QLinearGradient(rect.left(), y, rect.right(), y);
466 break;
467 case FromRight:
468 gradient = new QLinearGradient(rect.right(), y, rect.left(), y);
469 break;
470 case BottomUp:
471 gradient = new QLinearGradient(x, rect.bottom(), x, rect.top());
472 break;
473 case TopDown:
474 default:
475 gradient = new QLinearGradient(x, rect.top(), x, rect.bottom());
476 break;
477 }
478 if (bgBrush.gradient())
479 gradient->setStops(bgBrush.gradient()->stops());
480 else {
481 gradient->setColorAt(0, gradientStart);
482 gradient->setColorAt(1, gradientStop);
483 }
484 painter->fillRect(rect, *gradient);
485 delete gradient;
486 }
487
qt_cleanlooks_draw_buttongradient(QPainter * painter,const QRect & rect,const QColor & gradientStart,const QColor & gradientMid,const QColor & gradientStop,Direction direction=TopDown,QBrush bgBrush=QBrush ())488 static void qt_cleanlooks_draw_buttongradient(QPainter *painter, const QRect &rect, const QColor &gradientStart,
489 const QColor &gradientMid, const QColor &gradientStop, Direction direction = TopDown,
490 QBrush bgBrush = QBrush())
491 {
492 int x = rect.center().x();
493 int y = rect.center().y();
494 QLinearGradient *gradient;
495 bool horizontal = false;
496 switch(direction) {
497 case FromLeft:
498 horizontal = true;
499 gradient = new QLinearGradient(rect.left(), y, rect.right(), y);
500 break;
501 case FromRight:
502 horizontal = true;
503 gradient = new QLinearGradient(rect.right(), y, rect.left(), y);
504 break;
505 case BottomUp:
506 gradient = new QLinearGradient(x, rect.bottom(), x, rect.top());
507 break;
508 case TopDown:
509 default:
510 gradient = new QLinearGradient(x, rect.top(), x, rect.bottom());
511 break;
512 }
513 if (bgBrush.gradient())
514 gradient->setStops(bgBrush.gradient()->stops());
515 else {
516 int size = horizontal ? rect.width() : rect.height() ;
517 if (size > 4) {
518 float edge = 4.0/(float)size;
519 gradient->setColorAt(0, gradientStart);
520 gradient->setColorAt(edge, gradientMid.lighter(104));
521 gradient->setColorAt(1.0 - edge, gradientMid.darker(100));
522 gradient->setColorAt(1.0, gradientStop);
523 }
524 }
525 painter->fillRect(rect, *gradient);
526 delete gradient;
527 }
528
qt_cleanlooks_draw_mdibutton(QPainter * painter,const QStyleOptionTitleBar * option,const QRect & tmp,bool hover,bool sunken)529 static void qt_cleanlooks_draw_mdibutton(QPainter *painter, const QStyleOptionTitleBar *option, const QRect &tmp, bool hover, bool sunken)
530 {
531 QColor dark;
532 dark.setHsv(option->palette.button().color().hue(),
533 qMin(255, (int)(option->palette.button().color().saturation()*1.9)),
534 qMin(255, (int)(option->palette.button().color().value()*0.7)));
535
536 QColor highlight = option->palette.highlight().color();
537
538 bool active = (option->titleBarState & QStyle::State_Active);
539 QColor titleBarHighlight(255, 255, 255, 60);
540
541 if (sunken)
542 painter->fillRect(tmp.adjusted(1, 1, -1, -1), option->palette.highlight().color().darker(120));
543 else if (hover)
544 painter->fillRect(tmp.adjusted(1, 1, -1, -1), QColor(255, 255, 255, 20));
545
546 QColor mdiButtonGradientStartColor;
547 QColor mdiButtonGradientStopColor;
548
549 mdiButtonGradientStartColor = QColor(0, 0, 0, 40);
550 mdiButtonGradientStopColor = QColor(255, 255, 255, 60);
551
552 if (sunken)
553 titleBarHighlight = highlight.darker(130);
554
555 QLinearGradient gradient(tmp.center().x(), tmp.top(), tmp.center().x(), tmp.bottom());
556 gradient.setColorAt(0, mdiButtonGradientStartColor);
557 gradient.setColorAt(1, mdiButtonGradientStopColor);
558 QColor mdiButtonBorderColor(active ? option->palette.highlight().color().darker(180): dark.darker(110));
559
560 painter->setPen(QPen(mdiButtonBorderColor, 1));
561 const QLine lines[4] = {
562 QLine(tmp.left() + 2, tmp.top(), tmp.right() - 2, tmp.top()),
563 QLine(tmp.left() + 2, tmp.bottom(), tmp.right() - 2, tmp.bottom()),
564 QLine(tmp.left(), tmp.top() + 2, tmp.left(), tmp.bottom() - 2),
565 QLine(tmp.right(), tmp.top() + 2, tmp.right(), tmp.bottom() - 2)
566 };
567 painter->drawLines(lines, 4);
568 const QPoint points[4] = {
569 QPoint(tmp.left() + 1, tmp.top() + 1),
570 QPoint(tmp.right() - 1, tmp.top() + 1),
571 QPoint(tmp.left() + 1, tmp.bottom() - 1),
572 QPoint(tmp.right() - 1, tmp.bottom() - 1)
573 };
574 painter->drawPoints(points, 4);
575
576 painter->setPen(titleBarHighlight);
577 painter->drawLine(tmp.left() + 2, tmp.top() + 1, tmp.right() - 2, tmp.top() + 1);
578 painter->drawLine(tmp.left() + 1, tmp.top() + 2, tmp.left() + 1, tmp.bottom() - 2);
579
580 painter->setPen(QPen(gradient, 1));
581 painter->drawLine(tmp.right() + 1, tmp.top() + 2, tmp.right() + 1, tmp.bottom() - 2);
582 painter->drawPoint(tmp.right() , tmp.top() + 1);
583
584 painter->drawLine(tmp.left() + 2, tmp.bottom() + 1, tmp.right() - 2, tmp.bottom() + 1);
585 painter->drawPoint(tmp.left() + 1, tmp.bottom());
586 painter->drawPoint(tmp.right() - 1, tmp.bottom());
587 painter->drawPoint(tmp.right() , tmp.bottom() - 1);
588 }
589
590 /*!
591 \class QCleanlooksStyle
592 \brief The QCleanlooksStyle class provides a widget style similar to the
593 Clearlooks style available in GNOME.
594 \since 4.2
595
596 The Cleanlooks style provides a look and feel for widgets
597 that closely resembles the Clearlooks style, introduced by Richard
598 Stellingwerff and Daniel Borgmann.
599
600 \sa {Cleanlooks Style Widget Gallery}, QWindowsXPStyle, QMacStyle, QWindowsStyle,
601 QCDEStyle, QMotifStyle, QPlastiqueStyle
602 */
603
604 /*!
605 Constructs a QCleanlooksStyle object.
606 */
QCleanlooksStyle()607 QCleanlooksStyle::QCleanlooksStyle() : QWindowsStyle(*new QCleanlooksStylePrivate)
608 {
609 setObjectName(QLatin1String("CleanLooks"));
610 }
611
612 /*!
613 \internal
614
615 Constructs a QCleanlooksStyle object.
616 */
QCleanlooksStyle(QCleanlooksStylePrivate & dd)617 QCleanlooksStyle::QCleanlooksStyle(QCleanlooksStylePrivate &dd) : QWindowsStyle(dd)
618 {
619 }
620
621 /*!
622 Destroys the QCleanlooksStyle object.
623 */
~QCleanlooksStyle()624 QCleanlooksStyle::~QCleanlooksStyle()
625 {
626 }
627
628 /*!
629 \fn void QCleanlooksStyle::drawItemText(QPainter *painter, const QRect &rectangle, int alignment, const QPalette &palette,
630 bool enabled, const QString& text, QPalette::ColorRole textRole) const
631
632 Draws the given \a text in the specified \a rectangle using the
633 provided \a painter and \a palette.
634
635 Text is drawn using the painter's pen. If an explicit \a textRole
636 is specified, then the text is drawn using the \a palette's color
637 for the specified role. The \a enabled value indicates whether or
638 not the item is enabled; when reimplementing, this value should
639 influence how the item is drawn.
640
641 The text is aligned and wrapped according to the specified \a
642 alignment.
643
644 \sa Qt::Alignment
645 */
drawItemText(QPainter * painter,const QRect & rect,int alignment,const QPalette & pal,bool enabled,const QString & text,QPalette::ColorRole textRole) const646 void QCleanlooksStyle::drawItemText(QPainter *painter, const QRect &rect, int alignment, const QPalette &pal,
647 bool enabled, const QString& text, QPalette::ColorRole textRole) const
648 {
649 if (text.isEmpty())
650 return;
651
652 QPen savedPen = painter->pen();
653 if (textRole != QPalette::NoRole) {
654 painter->setPen(QPen(pal.brush(textRole), savedPen.widthF()));
655 }
656 if (!enabled) {
657 QPen pen = painter->pen();
658 painter->setPen(pen);
659 }
660 painter->drawText(rect, alignment, text);
661 painter->setPen(savedPen);
662 }
663
mergedColors(const QColor & colorA,const QColor & colorB,int factor=50)664 static QColor mergedColors(const QColor &colorA, const QColor &colorB, int factor = 50)
665 {
666 const int maxFactor = 100;
667 QColor tmp = colorA;
668 tmp.setRed((tmp.red() * factor) / maxFactor + (colorB.red() * (maxFactor - factor)) / maxFactor);
669 tmp.setGreen((tmp.green() * factor) / maxFactor + (colorB.green() * (maxFactor - factor)) / maxFactor);
670 tmp.setBlue((tmp.blue() * factor) / maxFactor + (colorB.blue() * (maxFactor - factor)) / maxFactor);
671 return tmp;
672 }
673
674 /*!
675 \reimp
676 */
drawPrimitive(PrimitiveElement elem,const QStyleOption * option,QPainter * painter,const QWidget * widget) const677 void QCleanlooksStyle::drawPrimitive(PrimitiveElement elem,
678 const QStyleOption *option,
679 QPainter *painter, const QWidget *widget) const
680 {
681 Q_ASSERT(option);
682 QRect rect = option->rect;
683 int state = option->state;
684 QColor button = option->palette.button().color();
685 QColor buttonShadow = option->palette.button().color().darker(110);
686 QColor buttonShadowAlpha = buttonShadow;
687 buttonShadowAlpha.setAlpha(128);
688 QColor darkOutline;
689 QColor dark;
690 darkOutline.setHsv(button.hue(),
691 qMin(255, (int)(button.saturation()*3.0)),
692 qMin(255, (int)(button.value()*0.6)));
693 dark.setHsv(button.hue(),
694 qMin(255, (int)(button.saturation()*1.9)),
695 qMin(255, (int)(button.value()*0.7)));
696 QColor tabFrameColor = mergedColors(option->palette.background().color(),
697 dark.lighter(135), 60);
698
699 switch(elem) {
700 #ifndef QT_NO_TABBAR
701 case PE_FrameTabBarBase:
702 if (const QStyleOptionTabBarBase *tbb
703 = qstyleoption_cast<const QStyleOptionTabBarBase *>(option)) {
704 painter->save();
705 painter->setPen(QPen(darkOutline.lighter(110), 0));
706 switch (tbb->shape) {
707 case QTabBar::RoundedNorth: {
708 QRegion region(tbb->rect);
709 region -= tbb->selectedTabRect;
710 painter->drawLine(tbb->rect.topLeft(), tbb->rect.topRight());
711 painter->setClipRegion(region);
712 painter->setPen(option->palette.light().color());
713 painter->drawLine(tbb->rect.topLeft() + QPoint(0, 1),
714 tbb->rect.topRight() + QPoint(0, 1));
715 }
716 break;
717 case QTabBar::RoundedWest:
718 painter->drawLine(tbb->rect.left(), tbb->rect.top(), tbb->rect.left(), tbb->rect.bottom());
719 break;
720 case QTabBar::RoundedSouth:
721 painter->drawLine(tbb->rect.left(), tbb->rect.bottom(),
722 tbb->rect.right(), tbb->rect.bottom());
723 break;
724 case QTabBar::RoundedEast:
725 painter->drawLine(tbb->rect.topRight(), tbb->rect.bottomRight());
726 break;
727 case QTabBar::TriangularNorth:
728 case QTabBar::TriangularEast:
729 case QTabBar::TriangularWest:
730 case QTabBar::TriangularSouth:
731 painter->restore();
732 QWindowsStyle::drawPrimitive(elem, option, painter, widget);
733 return;
734 }
735 painter->restore();
736 }
737 return;
738 #endif // QT_NO_TABBAR
739 case PE_IndicatorViewItemCheck:
740 {
741 QStyleOptionButton button;
742 button.QStyleOption::operator=(*option);
743 button.state &= ~State_MouseOver;
744 proxy()->drawPrimitive(PE_IndicatorCheckBox, &button, painter, widget);
745 }
746 return;
747 case PE_IndicatorHeaderArrow:
748 if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
749 QRect r = header->rect;
750 QImage arrow;
751 if (header->sortIndicator & QStyleOptionHeader::SortUp)
752 arrow = QImage(qt_cleanlooks_arrow_up_xpm);
753 else if (header->sortIndicator & QStyleOptionHeader::SortDown)
754 arrow = QImage(qt_cleanlooks_arrow_down_xpm);
755 if (!arrow.isNull()) {
756 r.setSize(arrow.size());
757 r.moveCenter(header->rect.center());
758 arrow.setColor(1, header->palette.foreground().color().rgba());
759 painter->drawImage(r, arrow);
760 }
761 }
762 break;
763 case PE_IndicatorButtonDropDown:
764 proxy()->drawPrimitive(PE_PanelButtonCommand, option, painter, widget);
765 break;
766 case PE_IndicatorToolBarSeparator:
767 {
768 QRect rect = option->rect;
769 const int margin = 6;
770 if (option->state & State_Horizontal) {
771 const int offset = rect.width()/2;
772 painter->setPen(QPen(option->palette.background().color().darker(110)));
773 painter->drawLine(rect.bottomLeft().x() + offset,
774 rect.bottomLeft().y() - margin,
775 rect.topLeft().x() + offset,
776 rect.topLeft().y() + margin);
777 painter->setPen(QPen(option->palette.background().color().lighter(110)));
778 painter->drawLine(rect.bottomLeft().x() + offset + 1,
779 rect.bottomLeft().y() - margin,
780 rect.topLeft().x() + offset + 1,
781 rect.topLeft().y() + margin);
782 } else { //Draw vertical separator
783 const int offset = rect.height()/2;
784 painter->setPen(QPen(option->palette.background().color().darker(110)));
785 painter->drawLine(rect.topLeft().x() + margin ,
786 rect.topLeft().y() + offset,
787 rect.topRight().x() - margin,
788 rect.topRight().y() + offset);
789 painter->setPen(QPen(option->palette.background().color().lighter(110)));
790 painter->drawLine(rect.topLeft().x() + margin ,
791 rect.topLeft().y() + offset + 1,
792 rect.topRight().x() - margin,
793 rect.topRight().y() + offset + 1);
794 }
795 }
796 break;
797 case PE_Frame:
798 painter->save();
799 painter->setPen(dark.lighter(108));
800 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
801 painter->restore();
802 break;
803 case PE_FrameMenu:
804 painter->save();
805 {
806 painter->setPen(QPen(darkOutline, 1));
807 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
808 QColor frameLight = option->palette.background().color().lighter(160);
809 QColor frameShadow = option->palette.background().color().darker(110);
810
811 //paint beveleffect
812 QRect frame = option->rect.adjusted(1, 1, -1, -1);
813 painter->setPen(frameLight);
814 painter->drawLine(frame.topLeft(), frame.bottomLeft());
815 painter->drawLine(frame.topLeft(), frame.topRight());
816
817 painter->setPen(frameShadow);
818 painter->drawLine(frame.topRight(), frame.bottomRight());
819 painter->drawLine(frame.bottomLeft(), frame.bottomRight());
820 }
821 painter->restore();
822 break;
823 case PE_FrameDockWidget:
824
825 painter->save();
826 {
827 QColor softshadow = option->palette.background().color().darker(120);
828
829 QRect rect= option->rect;
830 painter->setPen(softshadow);
831 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
832 painter->setPen(QPen(option->palette.light(), 0));
833 painter->drawLine(QPoint(rect.left() + 1, rect.top() + 1), QPoint(rect.left() + 1, rect.bottom() - 1));
834 painter->setPen(QPen(option->palette.background().color().darker(120), 0));
835 painter->drawLine(QPoint(rect.left() + 1, rect.bottom() - 1), QPoint(rect.right() - 2, rect.bottom() - 1));
836 painter->drawLine(QPoint(rect.right() - 1, rect.top() + 1), QPoint(rect.right() - 1, rect.bottom() - 1));
837
838 }
839 painter->restore();
840 break;
841 case PE_PanelButtonTool:
842 painter->save();
843 if ((option->state & State_Enabled || option->state & State_On) || !(option->state & State_AutoRaise)) {
844 QPen oldPen = painter->pen();
845
846 if (widget && widget->inherits("QDockWidgetTitleButton")) {
847 if (option->state & State_MouseOver)
848 proxy()->drawPrimitive(PE_PanelButtonCommand, option, painter, widget);
849 } else {
850 proxy()->drawPrimitive(PE_PanelButtonCommand, option, painter, widget);
851 }
852 }
853 painter->restore();
854 break;
855 case PE_IndicatorDockWidgetResizeHandle:
856 {
857 QStyleOption dockWidgetHandle = *option;
858 bool horizontal = option->state & State_Horizontal;
859 if (horizontal)
860 dockWidgetHandle.state &= ~State_Horizontal;
861 else
862 dockWidgetHandle.state |= State_Horizontal;
863 proxy()->drawControl(CE_Splitter, &dockWidgetHandle, painter, widget);
864 }
865 break;
866 case PE_FrameWindow:
867 painter->save();
868 {
869 QRect rect= option->rect;
870 painter->setPen(QPen(dark.darker(150), 0));
871 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
872 painter->setPen(QPen(option->palette.light(), 0));
873 painter->drawLine(QPoint(rect.left() + 1, rect.top() + 1),
874 QPoint(rect.left() + 1, rect.bottom() - 1));
875 painter->setPen(QPen(option->palette.background().color().darker(120), 0));
876 painter->drawLine(QPoint(rect.left() + 1, rect.bottom() - 1),
877 QPoint(rect.right() - 2, rect.bottom() - 1));
878 painter->drawLine(QPoint(rect.right() - 1, rect.top() + 1),
879 QPoint(rect.right() - 1, rect.bottom() - 1));
880 }
881 painter->restore();
882 break;
883 #ifndef QT_NO_LINEEDIT
884 case PE_FrameLineEdit:
885 // fall through
886 #endif // QT_NO_LINEEDIT
887 #ifdef QT3_SUPPORT
888 if (widget && widget->inherits("Q3ToolBar")) {
889 proxy()->drawPrimitive(PE_Q3Separator, option, painter, widget);
890 break;
891 }
892 #endif
893 {
894 QPen oldPen = painter->pen();
895 if (option->state & State_Enabled) {
896 painter->setPen(QPen(option->palette.background(), 0));
897 painter->drawRect(rect.adjusted(0, 0, 0, 0));
898 painter->drawRect(rect.adjusted(1, 1, -1, -1));
899 } else {
900 painter->fillRect(rect, option->palette.background());
901 }
902 QRect r = rect.adjusted(0, 1, 0, -1);
903 painter->setPen(buttonShadowAlpha);
904 painter->drawLine(QPoint(r.left() + 2, r.top() - 1), QPoint(r.right() - 2, r.top() - 1));
905 const QPoint points[8] = {
906 QPoint(r.right() - 1, r.top()),
907 QPoint(r.right(), r.top() + 1),
908 QPoint(r.right() - 1, r.bottom()),
909 QPoint(r.right(), r.bottom() - 1),
910 QPoint(r.left() + 1, r.top() ),
911 QPoint(r.left(), r.top() + 1),
912 QPoint(r.left() + 1, r.bottom() ),
913 QPoint(r.left(), r.bottom() - 1)
914 };
915 painter->drawPoints(points, 8);
916 painter->setPen(QPen(option->palette.background().color(), 1));
917 painter->drawLine(QPoint(r.left() + 2, r.top() + 1), QPoint(r.right() - 2, r.top() + 1));
918
919 if (option->state & State_HasFocus) {
920 QColor darkoutline = option->palette.highlight().color().darker(150);
921 QColor innerline = mergedColors(option->palette.highlight().color(), Qt::white);
922 painter->setPen(QPen(innerline, 0));
923 painter->drawRect(rect.adjusted(1, 2, -2, -3));
924 painter->setPen(QPen(darkoutline, 0));
925 }
926 else {
927 QColor highlight = Qt::white;
928 highlight.setAlpha(130);
929 painter->setPen(option->palette.base().color().darker(120));
930 painter->drawLine(QPoint(r.left() + 1, r.top() + 1),
931 QPoint(r.right() - 1, r.top() + 1));
932 painter->drawLine(QPoint(r.left() + 1, r.top() + 1),
933 QPoint(r.left() + 1, r.bottom() - 1));
934 painter->setPen(option->palette.base().color());
935 painter->drawLine(QPoint(r.right() - 1, r.top() + 1),
936 QPoint(r.right() - 1, r.bottom() - 1));
937 painter->setPen(highlight);
938 painter->drawLine(QPoint(r.left() + 1, r.bottom() + 1),
939 QPoint(r.right() - 1, r.bottom() + 1));
940 painter->drawPoint(QPoint(r.left(), r.bottom()));
941 painter->drawPoint(QPoint(r.right(), r.bottom() ));
942 painter->setPen(QPen(darkOutline.lighter(115), 1));
943 }
944 painter->drawLine(QPoint(r.left(), r.top() + 2), QPoint(r.left(), r.bottom() - 2));
945 painter->drawLine(QPoint(r.right(), r.top() + 2), QPoint(r.right(), r.bottom() - 2));
946 painter->drawLine(QPoint(r.left() + 2, r.bottom()), QPoint(r.right() - 2, r.bottom()));
947 const QPoint points2[4] = {
948 QPoint(r.right() - 1, r.bottom() - 1),
949 QPoint(r.right() - 1, r.top() + 1),
950 QPoint(r.left() + 1, r.bottom() - 1),
951 QPoint(r.left() + 1, r.top() + 1)
952 };
953 painter->drawPoints(points2, 4);
954 painter->drawLine(QPoint(r.left() + 2, r.top()), QPoint(r.right() - 2, r.top()));
955 painter->setPen(oldPen);
956 }
957 break;
958 case PE_IndicatorCheckBox:
959 painter->save();
960 if (const QStyleOptionButton *checkbox = qstyleoption_cast<const QStyleOptionButton*>(option)) {
961 QRect checkRect;
962 checkRect.setX(rect.left() );
963 checkRect.setY(rect.top() );
964 checkRect.setWidth(rect.width() - 1);
965 checkRect.setHeight(rect.height() - 1);
966 if (state & State_Sunken)
967 painter->setBrush(dark.lighter(130));
968 else
969 painter->setBrush(option->palette.base());
970 painter->setPen(QPen(dark.lighter(110), 0));
971 painter->drawRect(checkRect);
972 if (checkbox->state & (State_On | State_Sunken | State_NoChange)) {
973 QImage image(qt_cleanlooks_checkbox_checked);
974 QColor fillColor = option->palette.text().color();
975 image.setColor(1, fillColor.rgba());
976 fillColor.setAlpha(100);
977 image.setColor(2, fillColor.rgba());
978 painter->drawImage(rect, image);
979 if (checkbox->state & State_NoChange) {
980 QColor bgc = option->palette.background().color();
981 bgc.setAlpha(127);
982 painter->fillRect(checkRect.adjusted(1, 1, -1, -1), bgc);
983 }
984 }
985 }
986 painter->restore();
987 break;
988 case PE_IndicatorRadioButton:
989 painter->save();
990 {
991 painter->setRenderHint(QPainter::SmoothPixmapTransform);
992 QRect checkRect = rect.adjusted(0, 0, 0, 0);
993 if (state & (State_On )) {
994 painter->drawImage(rect, QImage(qt_cleanlooks_radiobutton));
995 painter->drawImage(checkRect, QImage(qt_cleanlooks_radiobutton_checked));
996 }
997 else if (state & State_Sunken) {
998 painter->drawImage(rect, QImage(qt_cleanlooks_radiobutton));
999 QColor bgc = buttonShadow;
1000 painter->setRenderHint(QPainter::Antialiasing);
1001 painter->setBrush(bgc);
1002 painter->setPen(Qt::NoPen);
1003 painter->drawEllipse(rect.adjusted(1, 1, -1, -1)); }
1004 else {
1005 painter->drawImage(rect, QImage(qt_cleanlooks_radiobutton));
1006 }
1007 }
1008 painter->restore();
1009 break;
1010 case PE_IndicatorToolBarHandle:
1011 painter->save();
1012 if (option->state & State_Horizontal) {
1013 for (int i = rect.height()/5; i <= 4*(rect.height()/5) ; ++i) {
1014 int y = rect.topLeft().y() + i + 1;
1015 int x1 = rect.topLeft().x() + 3;
1016 int x2 = rect.topRight().x() - 2;
1017
1018 if (i % 2 == 0)
1019 painter->setPen(QPen(option->palette.light(), 0));
1020 else
1021 painter->setPen(QPen(dark.lighter(110), 0));
1022 painter->drawLine(x1, y, x2, y);
1023 }
1024 }
1025 else { //vertical toolbar
1026 for (int i = rect.width()/5; i <= 4*(rect.width()/5) ; ++i) {
1027 int x = rect.topLeft().x() + i + 1;
1028 int y1 = rect.topLeft().y() + 3;
1029 int y2 = rect.topLeft().y() + 5;
1030
1031 if (i % 2 == 0)
1032 painter->setPen(QPen(option->palette.light(), 0));
1033 else
1034 painter->setPen(QPen(dark.lighter(110), 0));
1035 painter->drawLine(x, y1, x, y2);
1036 }
1037 }
1038 painter->restore();
1039 break;
1040 case PE_FrameDefaultButton:
1041 case PE_FrameFocusRect:
1042 if (const QStyleOptionFocusRect *focusFrame = qstyleoption_cast<const QStyleOptionFocusRect *>(option)) {
1043 if (!(focusFrame->state & State_KeyboardFocusChange))
1044 return;
1045 QRect rect = focusFrame->rect;
1046 painter->save();
1047 painter->setBackgroundMode(Qt::TransparentMode);
1048 painter->setBrush(QBrush(dark.darker(120), Qt::Dense4Pattern));
1049 painter->setBrushOrigin(rect.topLeft());
1050 painter->setPen(Qt::NoPen);
1051 const QRect rects[4] = {
1052 QRect(rect.left(), rect.top(), rect.width(), 1), // Top
1053 QRect(rect.left(), rect.bottom(), rect.width(), 1), // Bottom
1054 QRect(rect.left(), rect.top(), 1, rect.height()), // Left
1055 QRect(rect.right(), rect.top(), 1, rect.height()) // Right
1056 };
1057 painter->drawRects(rects, 4);
1058 painter->restore();
1059 }
1060 break;
1061 case PE_PanelButtonCommand:
1062 {
1063 bool isDefault = false;
1064 bool isFlat = false;
1065 bool isDown = (option->state & State_Sunken) || (option->state & State_On);
1066 QPen oldPen = painter->pen();
1067 QBrush oldBrush = painter->brush();
1068 QRect r;
1069
1070 if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton*>(option)) {
1071 isDefault = (button->features & QStyleOptionButton::DefaultButton) && (button->state & State_Enabled);
1072 isFlat = (button->features & QStyleOptionButton::Flat);
1073 }
1074
1075 if (isFlat && !isDown) {
1076 if (isDefault) {
1077 r = option->rect.adjusted(0, 1, 0, -1);
1078 painter->setPen(QPen(Qt::black, 0));
1079 const QLine lines[4] = {
1080 QLine(QPoint(r.left() + 2, r.top()),
1081 QPoint(r.right() - 2, r.top())),
1082 QLine(QPoint(r.left(), r.top() + 2),
1083 QPoint(r.left(), r.bottom() - 2)),
1084 QLine(QPoint(r.right(), r.top() + 2),
1085 QPoint(r.right(), r.bottom() - 2)),
1086 QLine(QPoint(r.left() + 2, r.bottom()),
1087 QPoint(r.right() - 2, r.bottom()))
1088 };
1089 painter->drawLines(lines, 4);
1090 const QPoint points[4] = {
1091 QPoint(r.right() - 1, r.bottom() - 1),
1092 QPoint(r.right() - 1, r.top() + 1),
1093 QPoint(r.left() + 1, r.bottom() - 1),
1094 QPoint(r.left() + 1, r.top() + 1)
1095 };
1096 painter->drawPoints(points, 4);
1097 painter->setPen(oldPen);
1098 }
1099 return;
1100 }
1101
1102 BEGIN_STYLE_PIXMAPCACHE(QString::fromLatin1("pushbutton-%1").arg(isDefault))
1103 r = rect.adjusted(0, 1, 0, -1);
1104
1105 bool isEnabled = (option->state & State_Enabled);
1106
1107 QColor highlightedGradientStartColor = option->palette.button().color().lighter(107);
1108 QColor highlightedGradientMidColor = option->palette.button().color().lighter(105);
1109 QColor highlightedGradientStopColor = buttonShadow.lighter(107);
1110 QColor gradientStartColor = option->palette.button().color().lighter(108);
1111
1112 QColor buttonColor = option->palette.button().color();
1113 QColor gradientMidColor = option->palette.button().color();
1114 QColor gradientStopColor;
1115 gradientStopColor.setHsv(buttonColor.hue(),
1116 qMin(255, (int)(buttonColor.saturation()*1.9)),
1117 qMin(255, (int)(buttonColor.value()*0.96)));
1118
1119 QRect gradRect = rect.adjusted(1, 2, -1, -2);
1120 // gradient fill
1121 QRect innerBorder = r.adjusted(1, 1, -1, 0);
1122
1123 if (isDown) {
1124 QBrush fillColor = gradientStopColor.darker(110);
1125 if (option->palette.button().gradient())
1126 fillColor = option->palette.button();
1127 p->fillRect(gradRect, fillColor);
1128 p->setPen(gradientStopColor.darker(125));
1129 p->drawLine(innerBorder.topLeft(), innerBorder.topRight());
1130 p->drawLine(innerBorder.topLeft(), innerBorder.bottomLeft());
1131 } else {
1132 if (isEnabled && option->state & State_MouseOver ) {
1133 qt_cleanlooks_draw_buttongradient(p, gradRect,
1134 highlightedGradientStartColor,
1135 highlightedGradientMidColor,
1136 highlightedGradientStopColor, TopDown, option->palette.button());
1137 } else {
1138 qt_cleanlooks_draw_buttongradient(p, gradRect,
1139 gradientStartColor,
1140 gradientMidColor,
1141 gradientStopColor, TopDown, option->palette.button());
1142 }
1143 }
1144
1145 bool hasFocus = option->state & State_HasFocus;
1146
1147 if (!isEnabled)
1148 p->setPen(QPen(dark.lighter(115)));
1149 else if (isDefault)
1150 p->setPen(QPen(Qt::black, 1));
1151 else
1152 p->setPen(QPen(darkOutline, 1));
1153
1154 p->drawLine(QPoint(r.left(), r.top() + 2),
1155 QPoint(r.left(), r.bottom() - 2));
1156 p->drawLine(QPoint(r.right(), r.top() + 2),
1157 QPoint(r.right(), r.bottom() - 2));
1158 p->drawLine(QPoint(r.left() + 2, r.bottom()),
1159 QPoint(r.right() - 2, r.bottom()));
1160 const QPoint points[4] = {
1161 QPoint(r.right() - 1, r.bottom() - 1),
1162 QPoint(r.right() - 1, r.top() + 1),
1163 QPoint(r.left() + 1, r.bottom() - 1),
1164 QPoint(r.left() + 1, r.top() + 1)
1165 };
1166 p->drawPoints(points, 4);
1167
1168 if (!isDefault && !hasFocus && isEnabled)
1169 p->setPen(QPen(darkOutline.darker(110), 0));
1170
1171 p->drawLine(QPoint(r.left() + 2, r.top()),
1172 QPoint(r.right() - 2, r.top()));
1173
1174 QColor highlight = Qt::white;
1175 highlight.setAlpha(110);
1176 p->setPen(highlight);
1177 p->drawLine(QPoint(r.left() + 1, r.top() + 2),
1178 QPoint(r.left() + 1, r.bottom() - 2));
1179 p->drawLine(QPoint(r.left() + 3, r.bottom() + 1),
1180 QPoint(r.right() - 3, r.bottom() + 1));
1181
1182 QColor topShadow = darkOutline;
1183 topShadow.setAlpha(60);
1184
1185 p->setPen(topShadow);
1186 const QPoint points2[8] = {
1187 QPoint(r.right(), r.top() + 1),
1188 QPoint(r.right() - 1, r.top() ),
1189 QPoint(r.right(), r.bottom() - 1),
1190 QPoint(r.right() - 1, r.bottom() ),
1191 QPoint(r.left() + 1, r.bottom()),
1192 QPoint(r.left(), r.bottom() - 1),
1193 QPoint(r.left() + 1, r.top()),
1194 QPoint(r.left(), r.top() + 1)
1195 };
1196 p->drawPoints(points2, 8);
1197
1198 topShadow.setAlpha(30);
1199 p->setPen(topShadow);
1200
1201 p->drawLine(QPoint(r.right() - 1, r.top() + 2),
1202 QPoint(r.right() - 1, r.bottom() - 2));
1203 p->drawLine(QPoint(r.left() + 2, r.top() - 1),
1204 QPoint(r.right() - 2, r.top() - 1));
1205
1206 if (isDefault) {
1207 r.adjust(-1, -1, 1, 1);
1208 p->setPen(buttonShadowAlpha.darker(120));
1209 const QLine lines[4] = {
1210 QLine(r.topLeft() + QPoint(3, 0), r.topRight() - QPoint(3, 0)),
1211 QLine(r.bottomLeft() + QPoint(3, 0), r.bottomRight() - QPoint(3, 0)),
1212 QLine(r.topLeft() + QPoint(0, 3), r.bottomLeft() - QPoint(0, 3)),
1213 QLine(r.topRight() + QPoint(0, 3), r.bottomRight() - QPoint(0, 3))
1214 };
1215 p->drawLines(lines, 4);
1216 const QPoint points3[8] = {
1217 r.topRight() + QPoint(-2, 1),
1218 r.topRight() + QPoint(-1, 2),
1219 r.bottomRight() + QPoint(-1, -2),
1220 r.bottomRight() + QPoint(-2, -1),
1221 r.topLeft() + QPoint(1, 2),
1222 r.topLeft() + QPoint(2, 1),
1223 r.bottomLeft() + QPoint(1, -2),
1224 r.bottomLeft() + QPoint(2, -1)
1225 };
1226 p->drawPoints(points3, 8);
1227 }
1228 painter->setPen(oldPen);
1229 painter->setBrush(oldBrush);
1230 END_STYLE_PIXMAPCACHE
1231 }
1232 break;
1233 #ifndef QT_NO_TABBAR
1234 case PE_FrameTabWidget:
1235 painter->save();
1236 {
1237 painter->fillRect(option->rect, tabFrameColor);
1238 }
1239 #ifndef QT_NO_TABWIDGET
1240 if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(option)) {
1241 QColor borderColor = darkOutline.lighter(110);
1242 QColor alphaCornerColor = mergedColors(borderColor, option->palette.background().color());
1243
1244 int borderThickness = proxy()->pixelMetric(PM_TabBarBaseOverlap, twf, widget);
1245 bool reverse = (twf->direction == Qt::RightToLeft);
1246 QRect tabBarRect;
1247
1248 switch (twf->shape) {
1249 case QTabBar::RoundedNorth:
1250 if (reverse) {
1251 tabBarRect = QRect(twf->rect.right() - twf->leftCornerWidgetSize.width()
1252 - twf->tabBarSize.width() + 1,
1253 twf->rect.top(),
1254 twf->tabBarSize.width(), borderThickness);
1255 } else {
1256 tabBarRect = QRect(twf->rect.left() + twf->leftCornerWidgetSize.width(),
1257 twf->rect.top(),
1258 twf->tabBarSize.width(), borderThickness);
1259 }
1260 break ;
1261 case QTabBar::RoundedWest:
1262 tabBarRect = QRect(twf->rect.left(),
1263 twf->rect.top() + twf->leftCornerWidgetSize.height(),
1264 borderThickness,
1265 twf->tabBarSize.height());
1266 tabBarRect = tabBarRect; //adjust
1267 break ;
1268 case QTabBar::RoundedEast:
1269 tabBarRect = QRect(twf->rect.right() - borderThickness + 1,
1270 twf->rect.top() + twf->leftCornerWidgetSize.height(),
1271 0,
1272 twf->tabBarSize.height());
1273 break ;
1274 case QTabBar::RoundedSouth:
1275 if (reverse) {
1276 tabBarRect = QRect(twf->rect.right() - twf->leftCornerWidgetSize.width() - twf->tabBarSize.width() + 1,
1277 twf->rect.bottom() + 1,
1278 twf->tabBarSize.width(),
1279 borderThickness);
1280 } else {
1281 tabBarRect = QRect(twf->rect.left() + twf->leftCornerWidgetSize.width(),
1282 twf->rect.bottom() + 1,
1283 twf->tabBarSize.width(),
1284 borderThickness);
1285 }
1286 break;
1287 default:
1288 break;
1289 }
1290
1291 QRegion region(twf->rect);
1292 region -= tabBarRect;
1293 painter->setClipRegion(region);
1294
1295 // Outer border
1296 QLine leftLine = QLine(twf->rect.topLeft() + QPoint(0, 2), twf->rect.bottomLeft() - QPoint(0, 2));
1297 QLine rightLine = QLine(twf->rect.topRight(), twf->rect.bottomRight() - QPoint(0, 2));
1298 QLine bottomLine = QLine(twf->rect.bottomLeft() + QPoint(2, 0), twf->rect.bottomRight() - QPoint(2, 0));
1299 QLine topLine = QLine(twf->rect.topLeft(), twf->rect.topRight());
1300
1301 painter->setPen(borderColor);
1302 painter->drawLine(topLine);
1303
1304 // Inner border
1305 QLine innerLeftLine = QLine(leftLine.p1() + QPoint(1, 0), leftLine.p2() + QPoint(1, 0));
1306 QLine innerRightLine = QLine(rightLine.p1() - QPoint(1, -1), rightLine.p2() - QPoint(1, 0));
1307 QLine innerBottomLine = QLine(bottomLine.p1() - QPoint(0, 1), bottomLine.p2() - QPoint(0, 1));
1308 QLine innerTopLine = QLine(topLine.p1() + QPoint(0, 1), topLine.p2() + QPoint(-1, 1));
1309
1310 // Rounded Corner
1311 QPoint leftBottomOuterCorner = QPoint(innerLeftLine.p2() + QPoint(0, 1));
1312 QPoint leftBottomInnerCorner1 = QPoint(leftLine.p2() + QPoint(0, 1));
1313 QPoint leftBottomInnerCorner2 = QPoint(bottomLine.p1() - QPoint(1, 0));
1314 QPoint rightBottomOuterCorner = QPoint(innerRightLine.p2() + QPoint(0, 1));
1315 QPoint rightBottomInnerCorner1 = QPoint(rightLine.p2() + QPoint(0, 1));
1316 QPoint rightBottomInnerCorner2 = QPoint(bottomLine.p2() + QPoint(1, 0));
1317 QPoint leftTopOuterCorner = QPoint(innerLeftLine.p1() - QPoint(0, 1));
1318 QPoint leftTopInnerCorner1 = QPoint(leftLine.p1() - QPoint(0, 1));
1319 QPoint leftTopInnerCorner2 = QPoint(topLine.p1() - QPoint(1, 0));
1320
1321 painter->setPen(borderColor);
1322 painter->drawLine(leftLine);
1323 painter->drawLine(rightLine);
1324 painter->drawLine(bottomLine);
1325 painter->drawPoint(leftBottomOuterCorner);
1326 painter->drawPoint(rightBottomOuterCorner);
1327 painter->drawPoint(leftTopOuterCorner);
1328
1329 painter->setPen(option->palette.light().color());
1330 painter->drawLine(innerLeftLine);
1331 painter->drawLine(innerTopLine);
1332
1333 painter->setPen(buttonShadowAlpha);
1334 painter->drawLine(innerRightLine);
1335 painter->drawLine(innerBottomLine);
1336
1337 painter->setPen(alphaCornerColor);
1338 const QPoint points[6] = {
1339 leftBottomInnerCorner1,
1340 leftBottomInnerCorner2,
1341 rightBottomInnerCorner1,
1342 rightBottomInnerCorner2,
1343 leftTopInnerCorner1,
1344 leftTopInnerCorner2
1345 };
1346 painter->drawPoints(points, 6);
1347 }
1348 #endif // QT_NO_TABWIDGET
1349 painter->restore();
1350 break ;
1351
1352 case PE_FrameStatusBarItem:
1353 break;
1354 case PE_IndicatorTabClose:
1355 {
1356 Q_D(const QCleanlooksStyle);
1357 if (d->tabBarcloseButtonIcon.isNull())
1358 d->tabBarcloseButtonIcon = standardIcon(SP_DialogCloseButton, option, widget);
1359 if ((option->state & State_Enabled) && (option->state & State_MouseOver))
1360 proxy()->drawPrimitive(PE_PanelButtonCommand, option, painter, widget);
1361 QPixmap pixmap = d->tabBarcloseButtonIcon.pixmap(QSize(16, 16), QIcon::Normal, QIcon::On);
1362 proxy()->drawItemPixmap(painter, option->rect, Qt::AlignCenter, pixmap);
1363 }
1364 break;
1365
1366 #endif // QT_NO_TABBAR
1367 default:
1368 QWindowsStyle::drawPrimitive(elem, option, painter, widget);
1369 break;
1370 }
1371 }
1372
1373 /*!
1374 \reimp
1375 */
drawControl(ControlElement element,const QStyleOption * option,QPainter * painter,const QWidget * widget) const1376 void QCleanlooksStyle::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter,
1377 const QWidget *widget) const
1378 {
1379 QColor button = option->palette.button().color();
1380 QColor dark;
1381 dark.setHsv(button.hue(),
1382 qMin(255, (int)(button.saturation()*1.9)),
1383 qMin(255, (int)(button.value()*0.7)));
1384 QColor darkOutline;
1385 darkOutline.setHsv(button.hue(),
1386 qMin(255, (int)(button.saturation()*2.0)),
1387 qMin(255, (int)(button.value()*0.6)));
1388 QRect rect = option->rect;
1389 QColor shadow = mergedColors(option->palette.background().color().darker(120),
1390 dark.lighter(130), 60);
1391 QColor tabFrameColor = mergedColors(option->palette.background().color(),
1392 dark.lighter(135), 60);
1393
1394 QColor highlight = option->palette.highlight().color();
1395
1396 switch(element) {
1397 case CE_RadioButton: //fall through
1398 case CE_CheckBox:
1399 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
1400 bool hover = (btn->state & State_MouseOver && btn->state & State_Enabled);
1401 if (hover)
1402 painter->fillRect(rect, btn->palette.background().color().lighter(104));
1403 QStyleOptionButton copy = *btn;
1404 copy.rect.adjust(2, 0, -2, 0);
1405 QWindowsStyle::drawControl(element, ©, painter, widget);
1406 }
1407 break;
1408 case CE_Splitter:
1409 painter->save();
1410 {
1411 // hover appearance
1412 QBrush fillColor = option->palette.background().color();
1413 if (option->state & State_MouseOver && option->state & State_Enabled)
1414 fillColor = fillColor.color().lighter(106);
1415
1416 painter->fillRect(option->rect, fillColor);
1417
1418 QColor grooveColor = mergedColors(dark.lighter(110), option->palette.button().color(),40);
1419 QColor gripShadow = grooveColor.darker(110);
1420 QPalette palette = option->palette;
1421 bool vertical = !(option->state & State_Horizontal);
1422 QRect scrollBarSlider = option->rect;
1423 int gripMargin = 4;
1424 //draw grips
1425 if (vertical) {
1426 for( int i = -20; i< 20 ; i += 2) {
1427 painter->setPen(QPen(gripShadow, 1));
1428 painter->drawLine(
1429 QPoint(scrollBarSlider.center().x() + i ,
1430 scrollBarSlider.top() + gripMargin),
1431 QPoint(scrollBarSlider.center().x() + i,
1432 scrollBarSlider.bottom() - gripMargin));
1433 painter->setPen(QPen(palette.light(), 1));
1434 painter->drawLine(
1435 QPoint(scrollBarSlider.center().x() + i + 1,
1436 scrollBarSlider.top() + gripMargin ),
1437 QPoint(scrollBarSlider.center().x() + i + 1,
1438 scrollBarSlider.bottom() - gripMargin));
1439 }
1440 } else {
1441 for (int i = -20; i < 20 ; i += 2) {
1442 painter->setPen(QPen(gripShadow, 1));
1443 painter->drawLine(
1444 QPoint(scrollBarSlider.left() + gripMargin ,
1445 scrollBarSlider.center().y()+ i),
1446 QPoint(scrollBarSlider.right() - gripMargin,
1447 scrollBarSlider.center().y()+ i));
1448 painter->setPen(QPen(palette.light(), 1));
1449 painter->drawLine(
1450 QPoint(scrollBarSlider.left() + gripMargin,
1451 scrollBarSlider.center().y() + 1 + i),
1452 QPoint(scrollBarSlider.right() - gripMargin,
1453 scrollBarSlider.center().y() + 1 + i));
1454
1455 }
1456 }
1457 }
1458 painter->restore();
1459 break;
1460 #ifndef QT_NO_SIZEGRIP
1461 case CE_SizeGrip:
1462 painter->save();
1463 {
1464 int x, y, w, h;
1465 option->rect.getRect(&x, &y, &w, &h);
1466 int sw = qMin(h, w);
1467 if (h > w)
1468 painter->translate(0, h - w);
1469 else
1470 painter->translate(w - h, 0);
1471
1472 int sx = x;
1473 int sy = y;
1474 int s = 4;
1475 if (option->direction == Qt::RightToLeft) {
1476 sx = x + sw;
1477 for (int i = 0; i < 4; ++i) {
1478 painter->setPen(QPen(option->palette.light().color(), 1));
1479 painter->drawLine(x, sy - 1 , sx + 1, sw);
1480 painter->setPen(QPen(dark.lighter(120), 1));
1481 painter->drawLine(x, sy, sx, sw);
1482 sx -= s;
1483 sy += s;
1484 }
1485 } else {
1486 for (int i = 0; i < 4; ++i) {
1487 painter->setPen(QPen(option->palette.light().color(), 1));
1488 painter->drawLine(sx - 1, sw, sw, sy - 1);
1489 painter->setPen(QPen(dark.lighter(120), 1));
1490 painter->drawLine(sx, sw, sw, sy);
1491 sx += s;
1492 sy += s;
1493 }
1494 }
1495 }
1496 painter->restore();
1497 break;
1498 #endif // QT_NO_SIZEGRIP
1499 #ifndef QT_NO_TOOLBAR
1500 case CE_ToolBar:
1501 painter->save();
1502 if (const QStyleOptionToolBar *toolbar = qstyleoption_cast<const QStyleOptionToolBar *>(option)) {
1503 QRect rect = option->rect;
1504
1505 bool paintLeftBorder = true;
1506 bool paintRightBorder = true;
1507 bool paintBottomBorder = true;
1508
1509 switch (toolbar->toolBarArea) {
1510 case Qt::BottomToolBarArea:
1511 switch(toolbar->positionOfLine) {
1512 case QStyleOptionToolBar::Beginning:
1513 case QStyleOptionToolBar::OnlyOne:
1514 paintBottomBorder = false;
1515 default:
1516 break;
1517 }
1518 case Qt::TopToolBarArea:
1519 switch (toolbar->positionWithinLine) {
1520 case QStyleOptionToolBar::Beginning:
1521 paintLeftBorder = false;
1522 break;
1523 case QStyleOptionToolBar::End:
1524 paintRightBorder = false;
1525 break;
1526 case QStyleOptionToolBar::OnlyOne:
1527 paintRightBorder = false;
1528 paintLeftBorder = false;
1529 default:
1530 break;
1531 }
1532 if (toolbar->direction == Qt::RightToLeft) { //reverse layout changes the order of Beginning/end
1533 bool tmp = paintLeftBorder;
1534 paintRightBorder=paintLeftBorder;
1535 paintLeftBorder=tmp;
1536 }
1537 break;
1538 case Qt::RightToolBarArea:
1539 switch (toolbar->positionOfLine) {
1540 case QStyleOptionToolBar::Beginning:
1541 case QStyleOptionToolBar::OnlyOne:
1542 paintRightBorder = false;
1543 break;
1544 default:
1545 break;
1546 }
1547 break;
1548 case Qt::LeftToolBarArea:
1549 switch (toolbar->positionOfLine) {
1550 case QStyleOptionToolBar::Beginning:
1551 case QStyleOptionToolBar::OnlyOne:
1552 paintLeftBorder = false;
1553 break;
1554 default:
1555 break;
1556 }
1557 break;
1558 default:
1559 break;
1560 }
1561
1562 QColor light = option->palette.background().color().lighter(110);
1563
1564 //draw top border
1565 painter->setPen(QPen(light));
1566 painter->drawLine(rect.topLeft().x(),
1567 rect.topLeft().y(),
1568 rect.topRight().x(),
1569 rect.topRight().y());
1570
1571 if (paintLeftBorder) {
1572 painter->setPen(QPen(light));
1573 painter->drawLine(rect.topLeft().x(),
1574 rect.topLeft().y(),
1575 rect.bottomLeft().x(),
1576 rect.bottomLeft().y());
1577 }
1578
1579 if (paintRightBorder) {
1580 painter->setPen(QPen(shadow));
1581 painter->drawLine(rect.topRight().x(),
1582 rect.topRight().y(),
1583 rect.bottomRight().x(),
1584 rect.bottomRight().y());
1585 }
1586
1587 if (paintBottomBorder) {
1588 painter->setPen(QPen(shadow));
1589 painter->drawLine(rect.bottomLeft().x(),
1590 rect.bottomLeft().y(),
1591 rect.bottomRight().x(),
1592 rect.bottomRight().y());
1593 }
1594 }
1595 painter->restore();
1596 break;
1597 #endif // QT_NO_TOOLBAR
1598 #ifndef QT_NO_DOCKWIDGET
1599 case CE_DockWidgetTitle:
1600 painter->save();
1601 if (const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<const QStyleOptionDockWidget *>(option)) {
1602 const QStyleOptionDockWidgetV2 *v2
1603 = qstyleoption_cast<const QStyleOptionDockWidgetV2*>(dwOpt);
1604 bool verticalTitleBar = v2 == 0 ? false : v2->verticalTitleBar;
1605
1606 QRect rect = dwOpt->rect;
1607 QRect titleRect = subElementRect(SE_DockWidgetTitleBarText, option, widget);
1608 QRect r = rect.adjusted(0, 0, -1, 0);
1609 if (verticalTitleBar)
1610 r.adjust(0, 0, 0, -1);
1611 painter->setPen(option->palette.light().color());
1612 painter->drawRect(r.adjusted(1, 1, 1, 1));
1613 painter->setPen(shadow);
1614 painter->drawRect(r);
1615
1616 if (verticalTitleBar) {
1617 QRect r = rect;
1618 QSize s = r.size();
1619 s.transpose();
1620 r.setSize(s);
1621
1622 titleRect = QRect(r.left() + rect.bottom()
1623 - titleRect.bottom(),
1624 r.top() + titleRect.left() - rect.left(),
1625 titleRect.height(), titleRect.width());
1626
1627 painter->translate(r.left(), r.top() + r.width());
1628 painter->rotate(-90);
1629 painter->translate(-r.left(), -r.top());
1630
1631 rect = r;
1632 }
1633
1634 if (!dwOpt->title.isEmpty()) {
1635 QString titleText
1636 = painter->fontMetrics().elidedText(dwOpt->title,
1637 Qt::ElideRight, titleRect.width());
1638 proxy()->drawItemText(painter,
1639 titleRect,
1640 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, dwOpt->palette,
1641 dwOpt->state & State_Enabled, titleText,
1642 QPalette::WindowText);
1643 }
1644 }
1645 painter->restore();
1646 break;
1647 #endif // QT_NO_DOCKWIDGET
1648 case CE_HeaderSection:
1649 painter->save();
1650 // Draws the header in tables.
1651 if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
1652 QPixmap cache;
1653 QString pixmapName = QStyleHelper::uniqueName(QLatin1String("headersection"), option, option->rect.size());
1654 pixmapName += QString::number(- int(header->position));
1655 pixmapName += QString::number(- int(header->orientation));
1656 QRect r = option->rect;
1657 QColor gradientStopColor;
1658 QColor gradientStartColor = option->palette.button().color();
1659 gradientStopColor.setHsv(gradientStartColor.hue(),
1660 qMin(255, (int)(gradientStartColor.saturation()*2)),
1661 qMin(255, (int)(gradientStartColor.value()*0.96)));
1662 QLinearGradient gradient(rect.topLeft(), rect.bottomLeft());
1663 if (option->palette.background().gradient()) {
1664 gradient.setStops(option->palette.background().gradient()->stops());
1665 } else {
1666 gradient.setColorAt(0, gradientStartColor);
1667 gradient.setColorAt(0.8, gradientStartColor);
1668 gradient.setColorAt(1, gradientStopColor);
1669 }
1670 painter->fillRect(r, gradient);
1671
1672 if (!QPixmapCache::find(pixmapName, cache)) {
1673 cache = QPixmap(r.size());
1674 cache.fill(Qt::transparent);
1675 QRect pixmapRect(0, 0, r.width(), r.height());
1676 QPainter cachePainter(&cache);
1677 if (header->orientation == Qt::Vertical) {
1678 cachePainter.setPen(QPen(dark));
1679 cachePainter.drawLine(pixmapRect.topRight(), pixmapRect.bottomRight());
1680 if (header->position != QStyleOptionHeader::End) {
1681 cachePainter.setPen(QPen(shadow));
1682 cachePainter.drawLine(pixmapRect.bottomLeft() + QPoint(3, -1), pixmapRect.bottomRight() + QPoint(-3, -1)); cachePainter.setPen(QPen(option->palette.light().color()));
1683 cachePainter.drawLine(pixmapRect.bottomLeft() + QPoint(3, 0), pixmapRect.bottomRight() + QPoint(-3, 0)); }
1684 } else {
1685 cachePainter.setPen(QPen(dark));
1686 cachePainter.drawLine(pixmapRect.bottomLeft(), pixmapRect.bottomRight());
1687 cachePainter.setPen(QPen(shadow));
1688 cachePainter.drawLine(pixmapRect.topRight() + QPoint(-1, 3), pixmapRect.bottomRight() + QPoint(-1, -3)); cachePainter.setPen(QPen(option->palette.light().color()));
1689 cachePainter.drawLine(pixmapRect.topRight() + QPoint(0, 3), pixmapRect.bottomRight() + QPoint(0, -3)); }
1690 cachePainter.end();
1691 QPixmapCache::insert(pixmapName, cache);
1692 }
1693 painter->drawPixmap(r.topLeft(), cache);
1694 }
1695 painter->restore();
1696 break;
1697 case CE_ProgressBarGroove:
1698 painter->save();
1699 {
1700 painter->fillRect(rect, option->palette.base());
1701 QColor borderColor = dark.lighter(110);
1702 painter->setPen(QPen(borderColor, 0));
1703 const QLine lines[4] = {
1704 QLine(QPoint(rect.left() + 1, rect.top()), QPoint(rect.right() - 1, rect.top())),
1705 QLine(QPoint(rect.left() + 1, rect.bottom()), QPoint(rect.right() - 1, rect.bottom())),
1706 QLine(QPoint(rect.left(), rect.top() + 1), QPoint(rect.left(), rect.bottom() - 1)),
1707 QLine(QPoint(rect.right(), rect.top() + 1), QPoint(rect.right(), rect.bottom() - 1))
1708 };
1709 painter->drawLines(lines, 4);
1710 QColor alphaCorner = mergedColors(borderColor, option->palette.background().color());
1711 QColor innerShadow = mergedColors(borderColor, option->palette.base().color());
1712
1713 //corner smoothing
1714 painter->setPen(alphaCorner);
1715 const QPoint points[4] = {
1716 rect.topRight(),
1717 rect.topLeft(),
1718 rect.bottomRight(),
1719 rect.bottomLeft()
1720 };
1721 painter->drawPoints(points, 4);
1722
1723 //inner shadow
1724 painter->setPen(innerShadow);
1725 painter->drawLine(QPoint(rect.left() + 1, rect.top() + 1),
1726 QPoint(rect.right() - 1, rect.top() + 1));
1727 painter->drawLine(QPoint(rect.left() + 1, rect.top() + 1),
1728 QPoint(rect.left() + 1, rect.bottom() + 1));
1729
1730 }
1731 painter->restore();
1732 break;
1733 case CE_ProgressBarContents:
1734 painter->save();
1735 if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
1736 QRect rect = bar->rect;
1737 bool vertical = false;
1738 bool inverted = false;
1739 bool indeterminate = (bar->minimum == 0 && bar->maximum == 0);
1740
1741 // Get extra style options if version 2
1742 if (const QStyleOptionProgressBarV2 *bar2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(option)) {
1743 vertical = (bar2->orientation == Qt::Vertical);
1744 inverted = bar2->invertedAppearance;
1745 }
1746
1747 // If the orientation is vertical, we use a transform to rotate
1748 // the progress bar 90 degrees clockwise. This way we can use the
1749 // same rendering code for both orientations.
1750 if (vertical) {
1751 rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height
1752 QTransform m = QTransform::fromTranslate(rect.height()-1, -1.0);
1753 m.rotate(90.0);
1754 painter->setTransform(m, true);
1755 }
1756
1757 int maxWidth = rect.width() - 4;
1758 int minWidth = 4;
1759 qreal progress = qMax(bar->progress, bar->minimum); // workaround for bug in QProgressBar
1760 int progressBarWidth = (progress - bar->minimum) * qreal(maxWidth) / qMax(qreal(1.0), qreal(bar->maximum) - bar->minimum);
1761 int width = indeterminate ? maxWidth : qMax(minWidth, progressBarWidth);
1762
1763 bool reverse = (!vertical && (bar->direction == Qt::RightToLeft)) || vertical;
1764 if (inverted)
1765 reverse = !reverse;
1766
1767 QRect progressBar;
1768 if (!indeterminate) {
1769 if (!reverse) {
1770 progressBar.setRect(rect.left() + 1, rect.top() + 1, width + 1, rect.height() - 3);
1771 } else {
1772 progressBar.setRect(rect.right() - 1 - width, rect.top() + 1, width + 1, rect.height() - 3);
1773 }
1774 } else {
1775 Q_D(const QCleanlooksStyle);
1776 int slideWidth = (qMax(rect.width() - 4, minWidth) * 2) / 3;
1777 int step = ((d->animateStep * slideWidth) / d->animationFps) % slideWidth;
1778 if ((((d->animateStep * slideWidth) / d->animationFps) % (2 * slideWidth)) >= slideWidth)
1779 step = slideWidth - step;
1780 progressBar.setRect(rect.left() + 1 + step, rect.top() + 1,
1781 slideWidth / 2, rect.height() - 3);
1782 }
1783 QColor highlight = option->palette.color(QPalette::Normal, QPalette::Highlight);
1784 painter->setPen(QPen(highlight.darker(140), 0));
1785
1786 QColor highlightedGradientStartColor = highlight.lighter(100);
1787 QColor highlightedGradientStopColor = highlight.lighter(130);
1788
1789 QLinearGradient gradient(rect.topLeft(), QPoint(rect.bottomLeft().x(),
1790 rect.bottomLeft().y()*2));
1791
1792 gradient.setColorAt(0, highlightedGradientStartColor);
1793 gradient.setColorAt(1, highlightedGradientStopColor);
1794
1795 painter->setBrush(gradient);
1796 painter->drawRect(progressBar);
1797
1798 painter->setPen(QPen(highlight.lighter(120), 0));
1799 painter->drawLine(QPoint(progressBar.left() + 1, progressBar.top() + 1),
1800 QPoint(progressBar.right(), progressBar.top() + 1));
1801 painter->drawLine(QPoint(progressBar.left() + 1, progressBar.top() + 1),
1802 QPoint(progressBar.left() + 1, progressBar.bottom() - 1));
1803
1804 painter->setPen(QPen(highlightedGradientStartColor, 7.0));//QPen(option->palette.highlight(), 3));
1805
1806 painter->save();
1807 painter->setClipRect(progressBar.adjusted(2, 2, -1, -1));
1808 for (int x = progressBar.left() - 32; x < rect.right() ; x+=18) {
1809 painter->drawLine(x, progressBar.bottom() + 1, x + 23, progressBar.top() - 2);
1810 }
1811 painter->restore();
1812
1813 }
1814 painter->restore();
1815 break;
1816 case CE_MenuBarItem:
1817 painter->save();
1818 if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option))
1819 {
1820 QStyleOptionMenuItem item = *mbi;
1821 item.rect = mbi->rect.adjusted(0, 3, 0, -1);
1822 QColor highlightOutline = highlight.darker(125);
1823 QLinearGradient gradient(rect.topLeft(), QPoint(rect.bottomLeft().x(), rect.bottomLeft().y()*2));
1824
1825 if (option->palette.button().gradient()) {
1826 gradient.setStops(option->palette.button().gradient()->stops());
1827 } else {
1828 gradient.setColorAt(0, option->palette.button().color());
1829 gradient.setColorAt(1, option->palette.button().color().darker(110));
1830 }
1831 painter->fillRect(rect, gradient);
1832
1833 QCommonStyle::drawControl(element, &item, painter, widget);
1834
1835 bool act = mbi->state & State_Selected && mbi->state & State_Sunken;
1836 bool dis = !(mbi->state & State_Enabled);
1837
1838 QRect r = option->rect;
1839 if (act) {
1840 qt_cleanlooks_draw_gradient(painter, r.adjusted(1, 1, -1, -1),
1841 highlight,
1842 highlightOutline, TopDown,
1843 option->palette.highlight());
1844
1845 painter->setPen(QPen(highlightOutline, 0));
1846 const QLine lines[4] = {
1847 QLine(QPoint(r.left(), r.top() + 1), QPoint(r.left(), r.bottom())),
1848 QLine(QPoint(r.right(), r.top() + 1), QPoint(r.right(), r.bottom())),
1849 QLine(QPoint(r.left() + 1, r.bottom()), QPoint(r.right() - 1, r.bottom())),
1850 QLine(QPoint(r.left() + 1, r.top()), QPoint(r.right() - 1, r.top()))
1851 };
1852 painter->drawLines(lines, 4);
1853
1854 //draw text
1855 QPalette::ColorRole textRole = dis ? QPalette::Text : QPalette::HighlightedText;
1856 uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
1857 if (!styleHint(SH_UnderlineShortcut, mbi, widget))
1858 alignment |= Qt::TextHideMnemonic;
1859 proxy()->drawItemText(painter, item.rect, alignment, mbi->palette, mbi->state & State_Enabled, mbi->text, textRole);
1860 }
1861
1862 }
1863 painter->restore();
1864 break;
1865 case CE_MenuItem:
1866 painter->save();
1867 // Draws one item in a popup menu.
1868 if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
1869 QColor highlightOutline = highlight.darker(125);
1870 QColor menuBackground = option->palette.background().color().lighter(104);
1871 QColor borderColor = option->palette.background().color().darker(160);
1872 QColor alphaCornerColor;
1873
1874 if (widget) {
1875 // ### backgroundrole/foregroundrole should be part of the style option
1876 alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), borderColor);
1877 } else {
1878 alphaCornerColor = mergedColors(option->palette.background().color(), borderColor);
1879 }
1880 if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
1881 painter->fillRect(menuItem->rect, menuBackground);
1882 int w = 0;
1883 if (!menuItem->text.isEmpty()) {
1884 painter->setFont(menuItem->font);
1885 proxy()->drawItemText(painter, menuItem->rect.adjusted(5, 0, -5, 0), Qt::AlignLeft | Qt::AlignVCenter,
1886 menuItem->palette, menuItem->state & State_Enabled, menuItem->text,
1887 QPalette::Text);
1888 w = menuItem->fontMetrics.width(menuItem->text) + 5;
1889 }
1890 painter->setPen(shadow.lighter(106));
1891 bool reverse = menuItem->direction == Qt::RightToLeft;
1892 painter->drawLine(menuItem->rect.left() + 5 + (reverse ? 0 : w), menuItem->rect.center().y(),
1893 menuItem->rect.right() - 5 - (reverse ? w : 0), menuItem->rect.center().y());
1894 painter->restore();
1895 break;
1896 }
1897 bool selected = menuItem->state & State_Selected && menuItem->state & State_Enabled;
1898 if (selected) {
1899 QRect r = option->rect.adjusted(1, 0, -2, -1);
1900 qt_cleanlooks_draw_gradient(painter, r, highlight,
1901 highlightOutline, TopDown,
1902 highlight);
1903 r = r.adjusted(-1, 0, 1, 0);
1904 painter->setPen(QPen(highlightOutline, 0));
1905 const QLine lines[4] = {
1906 QLine(QPoint(r.left(), r.top() + 1), QPoint(r.left(), r.bottom() - 1)),
1907 QLine(QPoint(r.right(), r.top() + 1), QPoint(r.right(), r.bottom() - 1)),
1908 QLine(QPoint(r.left() + 1, r.bottom()), QPoint(r.right() - 1, r.bottom())),
1909 QLine(QPoint(r.left() + 1, r.top()), QPoint(r.right() - 1, r.top()))
1910 };
1911 painter->drawLines(lines, 4);
1912 } else {
1913 painter->fillRect(option->rect, menuBackground);
1914 }
1915
1916 bool checkable = menuItem->checkType != QStyleOptionMenuItem::NotCheckable;
1917 bool checked = menuItem->checked;
1918 bool sunken = menuItem->state & State_Sunken;
1919 bool enabled = menuItem->state & State_Enabled;
1920
1921 bool ignoreCheckMark = false;
1922 int checkcol = qMax(menuItem->maxIconWidth, 20);
1923
1924 #ifndef QT_NO_COMBOBOX
1925 if (qobject_cast<const QComboBox*>(widget))
1926 ignoreCheckMark = true; //ignore the checkmarks provided by the QComboMenuDelegate
1927 #endif
1928
1929 if (!ignoreCheckMark) {
1930 // Check
1931 QRect checkRect(option->rect.left() + 7, option->rect.center().y() - 6, 13, 13);
1932 checkRect = visualRect(menuItem->direction, menuItem->rect, checkRect);
1933 if (checkable) {
1934 if (menuItem->checkType & QStyleOptionMenuItem::Exclusive) {
1935 // Radio button
1936 if (checked || sunken) {
1937 painter->setRenderHint(QPainter::Antialiasing);
1938 painter->setPen(Qt::NoPen);
1939
1940 QPalette::ColorRole textRole = !enabled ? QPalette::Text:
1941 selected ? QPalette::HighlightedText : QPalette::ButtonText;
1942 painter->setBrush(option->palette.brush( option->palette.currentColorGroup(), textRole));
1943 painter->drawEllipse(checkRect.adjusted(4, 4, -4, -4));
1944 }
1945 } else {
1946 // Check box
1947 if (menuItem->icon.isNull()) {
1948 if (checked || sunken) {
1949 QImage image(qt_cleanlooks_menuitem_checkbox_checked);
1950 if (enabled && (menuItem->state & State_Selected)) {
1951 image.setColor(1, 0x55ffffff);
1952 image.setColor(2, 0xAAffffff);
1953 image.setColor(3, 0xBBffffff);
1954 image.setColor(4, 0xFFffffff);
1955 image.setColor(5, 0x33ffffff);
1956 } else {
1957 image.setColor(1, 0x55000000);
1958 image.setColor(2, 0xAA000000);
1959 image.setColor(3, 0xBB000000);
1960 image.setColor(4, 0xFF000000);
1961 image.setColor(5, 0x33000000);
1962 }
1963 painter->drawImage(QPoint(checkRect.center().x() - image.width() / 2,
1964 checkRect.center().y() - image.height() / 2), image);
1965 }
1966 }
1967 }
1968 }
1969 } else { //ignore checkmark
1970 if (menuItem->icon.isNull())
1971 checkcol = 0;
1972 else
1973 checkcol = menuItem->maxIconWidth;
1974 }
1975
1976 // Text and icon, ripped from windows style
1977 bool dis = !(menuItem->state & State_Enabled);
1978 bool act = menuItem->state & State_Selected;
1979 const QStyleOption *opt = option;
1980 const QStyleOptionMenuItem *menuitem = menuItem;
1981
1982 QPainter *p = painter;
1983 QRect vCheckRect = visualRect(opt->direction, menuitem->rect,
1984 QRect(menuitem->rect.x(), menuitem->rect.y(),
1985 checkcol, menuitem->rect.height()));
1986 if (!menuItem->icon.isNull()) {
1987 QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
1988 if (act && !dis)
1989 mode = QIcon::Active;
1990 QPixmap pixmap;
1991
1992 int smallIconSize = proxy()->pixelMetric(PM_SmallIconSize, option, widget);
1993 QSize iconSize(smallIconSize, smallIconSize);
1994 #ifndef QT_NO_COMBOBOX
1995 if (const QComboBox *combo = qobject_cast<const QComboBox*>(widget))
1996 iconSize = combo->iconSize();
1997 #endif // QT_NO_COMBOBOX
1998 if (checked)
1999 pixmap = menuItem->icon.pixmap(iconSize, mode, QIcon::On);
2000 else
2001 pixmap = menuItem->icon.pixmap(iconSize, mode);
2002
2003 int pixw = pixmap.width();
2004 int pixh = pixmap.height();
2005
2006 QRect pmr(0, 0, pixw, pixh);
2007 pmr.moveCenter(vCheckRect.center());
2008 painter->setPen(menuItem->palette.text().color());
2009 if (checkable && checked) {
2010 QStyleOption opt = *option;
2011 if (act) {
2012 QColor activeColor = mergedColors(option->palette.background().color(),
2013 option->palette.highlight().color());
2014 opt.palette.setBrush(QPalette::Button, activeColor);
2015 }
2016 opt.state |= State_Sunken;
2017 opt.rect = vCheckRect;
2018 proxy()->drawPrimitive(PE_PanelButtonCommand, &opt, painter, widget);
2019 }
2020 painter->drawPixmap(pmr.topLeft(), pixmap);
2021 }
2022 if (selected) {
2023 painter->setPen(menuItem->palette.highlightedText().color());
2024 } else {
2025 painter->setPen(menuItem->palette.text().color());
2026 }
2027 int x, y, w, h;
2028 menuitem->rect.getRect(&x, &y, &w, &h);
2029 int tab = menuitem->tabWidth;
2030 QColor discol;
2031 if (dis) {
2032 discol = menuitem->palette.text().color();
2033 p->setPen(discol);
2034 }
2035 int xm = windowsItemFrame + checkcol + windowsItemHMargin;
2036 int xpos = menuitem->rect.x() + xm;
2037
2038 QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
2039 QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
2040 QString s = menuitem->text;
2041 if (!s.isEmpty()) { // draw text
2042 p->save();
2043 int t = s.indexOf(QLatin1Char('\t'));
2044 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
2045 if (!styleHint(SH_UnderlineShortcut, menuitem, widget))
2046 text_flags |= Qt::TextHideMnemonic;
2047 text_flags |= Qt::AlignLeft;
2048 if (t >= 0) {
2049 QRect vShortcutRect = visualRect(opt->direction, menuitem->rect,
2050 QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
2051 if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, option, widget)) {
2052 p->setPen(menuitem->palette.light().color());
2053 p->drawText(vShortcutRect.adjusted(1, 1, 1, 1), text_flags, s.mid(t + 1));
2054 p->setPen(discol);
2055 }
2056 p->drawText(vShortcutRect, text_flags, s.mid(t + 1));
2057 s = s.left(t);
2058 }
2059 QFont font = menuitem->font;
2060 // font may not have any "hard" flags set. We override
2061 // the point size so that when it is resolved against the device, this font will win.
2062 // This is mainly to handle cases where someone sets the font on the window
2063 // and then the combo inherits it and passes it onward. At that point the resolve mask
2064 // is very, very weak. This makes it stonger.
2065 font.setPointSizeF(QFontInfo(menuItem->font).pointSizeF());
2066
2067 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
2068 font.setBold(true);
2069
2070 p->setFont(font);
2071 if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, option, widget)) {
2072 p->setPen(menuitem->palette.light().color());
2073 p->drawText(vTextRect.adjusted(1, 1, 1, 1), text_flags, s.left(t));
2074 p->setPen(discol);
2075 }
2076 p->drawText(vTextRect, text_flags, s.left(t));
2077 p->restore();
2078 }
2079
2080 // Arrow
2081 if (menuItem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow
2082 int dim = (menuItem->rect.height() - 4) / 2;
2083 PrimitiveElement arrow;
2084 arrow = QApplication::isRightToLeft() ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
2085 int xpos = menuItem->rect.left() + menuItem->rect.width() - 3 - dim;
2086 QRect vSubMenuRect = visualRect(option->direction, menuItem->rect,
2087 QRect(xpos, menuItem->rect.top() + menuItem->rect.height() / 2 - dim / 2, dim, dim));
2088 QStyleOptionMenuItem newMI = *menuItem;
2089 newMI.rect = vSubMenuRect;
2090 newMI.state = !enabled ? State_None : State_Enabled;
2091 if (selected)
2092 newMI.palette.setColor(QPalette::ButtonText,
2093 newMI.palette.highlightedText().color());
2094 proxy()->drawPrimitive(arrow, &newMI, painter, widget);
2095 }
2096 }
2097 painter->restore();
2098 break;
2099 case CE_MenuHMargin:
2100 case CE_MenuVMargin:
2101 break;
2102 case CE_MenuEmptyArea:
2103 break;
2104 case CE_PushButtonLabel:
2105 if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
2106 QRect ir = button->rect;
2107 uint tf = Qt::AlignVCenter;
2108 if (styleHint(SH_UnderlineShortcut, button, widget))
2109 tf |= Qt::TextShowMnemonic;
2110 else
2111 tf |= Qt::TextHideMnemonic;
2112
2113 if (!button->icon.isNull()) {
2114 //Center both icon and text
2115 QPoint point;
2116
2117 QIcon::Mode mode = button->state & State_Enabled ? QIcon::Normal
2118 : QIcon::Disabled;
2119 if (mode == QIcon::Normal && button->state & State_HasFocus)
2120 mode = QIcon::Active;
2121 QIcon::State state = QIcon::Off;
2122 if (button->state & State_On)
2123 state = QIcon::On;
2124
2125 QPixmap pixmap = button->icon.pixmap(button->iconSize, mode, state);
2126 int w = pixmap.width();
2127 int h = pixmap.height();
2128
2129 if (!button->text.isEmpty())
2130 w += button->fontMetrics.boundingRect(option->rect, tf, button->text).width() + 2;
2131
2132 point = QPoint(ir.x() + ir.width() / 2 - w / 2,
2133 ir.y() + ir.height() / 2 - h / 2);
2134
2135 if (button->direction == Qt::RightToLeft)
2136 point.rx() += pixmap.width();
2137
2138 painter->drawPixmap(visualPos(button->direction, button->rect, point), pixmap);
2139
2140 if (button->direction == Qt::RightToLeft)
2141 ir.translate(-point.x() - 2, 0);
2142 else
2143 ir.translate(point.x() + pixmap.width(), 0);
2144
2145 // left-align text if there is
2146 if (!button->text.isEmpty())
2147 tf |= Qt::AlignLeft;
2148
2149 } else {
2150 tf |= Qt::AlignHCenter;
2151 }
2152
2153 if (button->features & QStyleOptionButton::HasMenu)
2154 ir = ir.adjusted(0, 0, -proxy()->pixelMetric(PM_MenuButtonIndicator, button, widget), 0);
2155 proxy()->drawItemText(painter, ir, tf, button->palette, (button->state & State_Enabled),
2156 button->text, QPalette::ButtonText);
2157 }
2158 break;
2159 case CE_MenuBarEmptyArea:
2160 painter->save();
2161 {
2162 QColor shadow = mergedColors(option->palette.background().color().darker(120),
2163 dark.lighter(140), 60);
2164
2165 QLinearGradient gradient(rect.topLeft(), QPoint(rect.bottomLeft().x(), rect.bottomLeft().y()*2));
2166 gradient.setColorAt(0, option->palette.button().color());
2167 gradient.setColorAt(1, option->palette.button().color().darker(110));
2168 painter->fillRect(rect, gradient);
2169
2170 #ifndef QT_NO_MAINWINDOW
2171 if (widget && qobject_cast<const QMainWindow *>(widget->parentWidget())) {
2172 QPen oldPen = painter->pen();
2173 painter->setPen(QPen(shadow));
2174 painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
2175 }
2176 #endif // QT_NO_MAINWINDOW
2177 }
2178 painter->restore();
2179 break;
2180 #ifndef QT_NO_TABBAR
2181 case CE_TabBarTabShape:
2182 painter->save();
2183 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
2184
2185 bool rtlHorTabs = (tab->direction == Qt::RightToLeft
2186 && (tab->shape == QTabBar::RoundedNorth
2187 || tab->shape == QTabBar::RoundedSouth));
2188 bool selected = tab->state & State_Selected;
2189 bool lastTab = ((!rtlHorTabs && tab->position == QStyleOptionTab::End)
2190 || (rtlHorTabs
2191 && tab->position == QStyleOptionTab::Beginning));
2192 bool onlyTab = tab->position == QStyleOptionTab::OnlyOneTab;
2193 bool leftCornerWidget = (tab->cornerWidgets & QStyleOptionTab::LeftCornerWidget);
2194
2195 bool atBeginning = ((tab->position == (tab->direction == Qt::LeftToRight ?
2196 QStyleOptionTab::Beginning : QStyleOptionTab::End)) || onlyTab);
2197
2198 bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab;
2199 bool previousSelected =
2200 ((!rtlHorTabs
2201 && tab->selectedPosition == QStyleOptionTab::PreviousIsSelected)
2202 || (rtlHorTabs
2203 && tab->selectedPosition == QStyleOptionTab::NextIsSelected));
2204 bool nextSelected =
2205 ((!rtlHorTabs
2206 && tab->selectedPosition == QStyleOptionTab::NextIsSelected)
2207 || (rtlHorTabs
2208 && tab->selectedPosition
2209 == QStyleOptionTab::PreviousIsSelected));
2210 int tabBarAlignment = proxy()->styleHint(SH_TabBar_Alignment, tab, widget);
2211 bool leftAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignLeft)
2212 || (rtlHorTabs
2213 && tabBarAlignment == Qt::AlignRight);
2214
2215 bool rightAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignRight)
2216 || (rtlHorTabs
2217 && tabBarAlignment == Qt::AlignLeft);
2218
2219 QColor light = tab->palette.light().color();
2220
2221 QColor background = tab->palette.background().color();
2222 int borderThinkness = proxy()->pixelMetric(PM_TabBarBaseOverlap, tab, widget);
2223 if (selected)
2224 borderThinkness /= 2;
2225 QRect r2(option->rect);
2226 int x1 = r2.left();
2227 int x2 = r2.right();
2228 int y1 = r2.top();
2229 int y2 = r2.bottom();
2230
2231 QTransform rotMatrix;
2232 bool flip = false;
2233 painter->setPen(shadow);
2234 QColor activeHighlight = option->palette.color(QPalette::Normal, QPalette::Highlight);
2235 switch (tab->shape) {
2236 case QTabBar::RoundedNorth:
2237 break;
2238 case QTabBar::RoundedSouth:
2239 rotMatrix.rotate(180);
2240 rotMatrix.translate(0, -rect.height() + 1);
2241 rotMatrix.scale(-1, 1);
2242 painter->setTransform(rotMatrix, true);
2243 break;
2244 case QTabBar::RoundedWest:
2245 rotMatrix.rotate(180 + 90);
2246 rotMatrix.scale(-1, 1);
2247 flip = true;
2248 painter->setTransform(rotMatrix, true);
2249 break;
2250 case QTabBar::RoundedEast:
2251 rotMatrix.rotate(90);
2252 rotMatrix.translate(0, - rect.width() + 1);
2253 flip = true;
2254 painter->setTransform(rotMatrix, true);
2255 break;
2256 default:
2257 painter->restore();
2258 QWindowsStyle::drawControl(element, tab, painter, widget);
2259 return;
2260 }
2261
2262 if (flip) {
2263 QRect tmp = rect;
2264 rect = QRect(tmp.y(), tmp.x(), tmp.height(), tmp.width());
2265 int temp = x1;
2266 x1 = y1;
2267 y1 = temp;
2268 temp = x2;
2269 x2 = y2;
2270 y2 = temp;
2271 }
2272
2273 QLinearGradient gradient(rect.topLeft(), rect.bottomLeft());
2274 if (option->palette.button().gradient()) {
2275 if (selected)
2276 gradient.setStops(option->palette.background().gradient()->stops());
2277 else
2278 gradient.setStops(option->palette.background().gradient()->stops());
2279 }
2280 else if (selected) {
2281 gradient.setColorAt(0, option->palette.background().color().lighter(104));
2282 gradient.setColorAt(1, tabFrameColor);
2283 painter->fillRect(rect.adjusted(0, 2, 0, -1), gradient);
2284 } else {
2285 y1 += 2;
2286 gradient.setColorAt(0, option->palette.background().color());
2287 gradient.setColorAt(1, dark.lighter(120));
2288 painter->fillRect(rect.adjusted(0, 2, 0, -2), gradient);
2289 }
2290
2291 // Delete border
2292 if (selected) {
2293 painter->setPen(QPen(activeHighlight, 0));
2294 painter->drawLine(x1 + 1, y1 + 1, x2 - 1, y1 + 1);
2295 painter->drawLine(x1 , y1 + 2, x2 , y1 + 2);
2296 } else {
2297 painter->setPen(dark);
2298 painter->drawLine(x1, y2 - 1, x2 + 2, y2 - 1 );
2299 if (tab->shape == QTabBar::RoundedNorth || tab->shape == QTabBar::RoundedWest) {
2300 painter->setPen(light);
2301 painter->drawLine(x1, y2 , x2, y2 );
2302 }
2303 }
2304 // Left
2305 if (atBeginning || selected ) {
2306 painter->setPen(light);
2307 painter->drawLine(x1 + 1, y1 + 2 + 1, x1 + 1, y2 - ((onlyOne || atBeginning) && selected && leftAligned ? 0 : borderThinkness) - (atBeginning && leftCornerWidget ? 1 : 0));
2308 painter->drawPoint(x1 + 1, y1 + 1);
2309 painter->setPen(dark);
2310 painter->drawLine(x1, y1 + 2, x1, y2 - ((onlyOne || atBeginning) && leftAligned ? 0 : borderThinkness) - (atBeginning && leftCornerWidget ? 1 : 0));
2311 }
2312 // Top
2313 {
2314 int beg = x1 + (previousSelected ? 0 : 2);
2315 int end = x2 - (nextSelected ? 0 : 2);
2316 painter->setPen(light);
2317
2318 if (!selected)painter->drawLine(beg - 2, y1 + 1, end, y1 + 1);
2319
2320 if (selected)
2321 painter->setPen(QPen(activeHighlight.darker(150), 0));
2322 else
2323 painter->setPen(darkOutline);
2324 painter->drawLine(beg, y1 , end, y1);
2325
2326 if (atBeginning|| selected) {
2327 painter->drawPoint(beg - 1, y1 + 1);
2328 } else if (!atBeginning) {
2329 painter->drawPoint(beg - 1, y1);
2330 painter->drawPoint(beg - 2, y1);
2331 if (!lastTab) {
2332 painter->setPen(dark.lighter(130));
2333 painter->drawPoint(end + 1, y1);
2334 painter->drawPoint(end + 2 , y1);
2335 painter->drawPoint(end + 2, y1 + 1);
2336 }
2337 }
2338 }
2339 // Right
2340 if (lastTab || selected || onlyOne || !nextSelected) {
2341 painter->setPen(darkOutline);
2342 painter->drawLine(x2, y1 + 2, x2, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
2343 if (selected)
2344 painter->setPen(QPen(activeHighlight.darker(150), 0));
2345 else
2346 painter->setPen(darkOutline);
2347 painter->drawPoint(x2 - 1, y1 + 1);
2348
2349 if (selected) {
2350 painter->setPen(background.darker(110));
2351 painter->drawLine(x2 - 1, y1 + 3, x2 - 1, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
2352 }
2353 }
2354 }
2355 painter->restore();
2356 break;
2357
2358 #endif // QT_NO_TABBAR
2359 default:
2360 QWindowsStyle::drawControl(element,option,painter,widget);
2361 break;
2362 }
2363 }
2364
2365 /*!
2366 \reimp
2367 */
standardPalette() const2368 QPalette QCleanlooksStyle::standardPalette () const
2369 {
2370 QPalette palette = QWindowsStyle::standardPalette();
2371 palette.setBrush(QPalette::Active, QPalette::Highlight, QColor(98, 140, 178));
2372 palette.setBrush(QPalette::Inactive, QPalette::Highlight, QColor(145, 141, 126));
2373 palette.setBrush(QPalette::Disabled, QPalette::Highlight, QColor(145, 141, 126));
2374
2375 QColor backGround(239, 235, 231);
2376
2377 QColor light = backGround.lighter(150);
2378 QColor base = Qt::white;
2379 QColor dark = QColor(170, 156, 143).darker(110);
2380 dark = backGround.darker(150);
2381 QColor darkDisabled = QColor(209, 200, 191).darker(110);
2382
2383 //### Find the correct disabled text color
2384 palette.setBrush(QPalette::Disabled, QPalette::Text, QColor(190, 190, 190));
2385
2386 palette.setBrush(QPalette::Window, backGround);
2387 palette.setBrush(QPalette::Mid, backGround.darker(130));
2388 palette.setBrush(QPalette::Light, light);
2389
2390 palette.setBrush(QPalette::Active, QPalette::Base, base);
2391 palette.setBrush(QPalette::Inactive, QPalette::Base, base);
2392 palette.setBrush(QPalette::Disabled, QPalette::Base, backGround);
2393
2394 palette.setBrush(QPalette::Midlight, palette.mid().color().lighter(110));
2395
2396 palette.setBrush(QPalette::All, QPalette::Dark, dark);
2397 palette.setBrush(QPalette::Disabled, QPalette::Dark, darkDisabled);
2398
2399 QColor button = backGround;
2400
2401 palette.setBrush(QPalette::Button, button);
2402
2403 QColor shadow = dark.darker(135);
2404 palette.setBrush(QPalette::Shadow, shadow);
2405 palette.setBrush(QPalette::Disabled, QPalette::Shadow, shadow.lighter(150));
2406 palette.setBrush(QPalette::HighlightedText, QColor(QRgb(0xffffffff)));
2407 return palette;
2408 }
2409
2410 /*!
2411 \reimp
2412 */
drawComplexControl(ComplexControl control,const QStyleOptionComplex * option,QPainter * painter,const QWidget * widget) const2413 void QCleanlooksStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
2414 QPainter *painter, const QWidget *widget) const
2415 {
2416 QColor button = option->palette.button().color();
2417 QColor dark;
2418 QColor grooveColor;
2419 QColor darkOutline;
2420 dark.setHsv(button.hue(),
2421 qMin(255, (int)(button.saturation()*1.9)),
2422 qMin(255, (int)(button.value()*0.7)));
2423 grooveColor.setHsv(button.hue(),
2424 qMin(255, (int)(button.saturation()*2.6)),
2425 qMin(255, (int)(button.value()*0.9)));
2426 darkOutline.setHsv(button.hue(),
2427 qMin(255, (int)(button.saturation()*3.0)),
2428 qMin(255, (int)(button.value()*0.6)));
2429
2430 QColor alphaCornerColor;
2431 if (widget) {
2432 // ### backgroundrole/foregroundrole should be part of the style option
2433 alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), darkOutline);
2434 } else {
2435 alphaCornerColor = mergedColors(option->palette.background().color(), darkOutline);
2436 }
2437 QColor gripShadow = grooveColor.darker(110);
2438 QColor buttonShadow = option->palette.button().color().darker(110);
2439
2440 QColor gradientStartColor = option->palette.button().color().lighter(108);
2441 QColor gradientStopColor = mergedColors(option->palette.button().color().darker(108), dark.lighter(150), 70);
2442
2443 QPalette palette = option->palette;
2444
2445 switch (control) {
2446 #ifndef QT_NO_SPINBOX
2447 case CC_SpinBox:
2448 if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
2449 QPixmap cache;
2450 QString pixmapName = QStyleHelper::uniqueName(QLatin1String("spinbox"), spinBox, spinBox->rect.size());
2451 if (!QPixmapCache::find(pixmapName, cache)) {
2452 cache = QPixmap(spinBox->rect.size());
2453 cache.fill(Qt::transparent);
2454 QRect pixmapRect(0, 0, spinBox->rect.width(), spinBox->rect.height());
2455 QPainter cachePainter(&cache);
2456
2457 bool isEnabled = (spinBox->state & State_Enabled);
2458 //bool focus = isEnabled && (spinBox->state & State_HasFocus);
2459 bool hover = isEnabled && (spinBox->state & State_MouseOver);
2460 bool sunken = (spinBox->state & State_Sunken);
2461 bool upIsActive = (spinBox->activeSubControls == SC_SpinBoxUp);
2462 bool downIsActive = (spinBox->activeSubControls == SC_SpinBoxDown);
2463
2464 QRect rect = pixmapRect;
2465 QStyleOptionSpinBox spinBoxCopy = *spinBox;
2466 spinBoxCopy.rect = pixmapRect;
2467 QRect upRect = proxy()->subControlRect(CC_SpinBox, &spinBoxCopy, SC_SpinBoxUp, widget);
2468 QRect downRect = proxy()->subControlRect(CC_SpinBox, &spinBoxCopy, SC_SpinBoxDown, widget);
2469
2470 int fw = spinBoxCopy.frame ? proxy()->pixelMetric(PM_SpinBoxFrameWidth, &spinBoxCopy, widget) : 0;
2471 cachePainter.fillRect(rect.adjusted(1, qMax(fw - 1, 0), -1, -fw),
2472 option->palette.base());
2473
2474 QRect r = rect.adjusted(0, 1, 0, -1);
2475 if (spinBox->frame) {
2476
2477 QColor topShadow = darkOutline;
2478 topShadow.setAlpha(60);
2479 cachePainter.setPen(topShadow);
2480
2481 // antialias corners
2482 const QPoint points[8] = {
2483 QPoint(r.right(), r.top() + 1),
2484 QPoint(r.right() - 1, r.top() ),
2485 QPoint(r.right(), r.bottom() - 1),
2486 QPoint(r.right() - 1, r.bottom() ),
2487 QPoint(r.left() + 1, r.bottom()),
2488 QPoint(r.left(), r.bottom() - 1),
2489 QPoint(r.left() + 1, r.top()),
2490 QPoint(r.left(), r.top() + 1)
2491 };
2492 cachePainter.drawPoints(points, 8);
2493
2494 // draw frame
2495 topShadow.setAlpha(30);
2496 cachePainter.setPen(topShadow);
2497 cachePainter.drawLine(QPoint(r.left() + 2, r.top() - 1), QPoint(r.right() - 2, r.top() - 1));
2498
2499 cachePainter.setPen(QPen(option->palette.background().color(), 1));
2500 cachePainter.drawLine(QPoint(r.left() + 2, r.top() + 1), QPoint(r.right() - 2, r.top() + 1));
2501 QColor highlight = Qt::white;
2502 highlight.setAlpha(130);
2503 cachePainter.setPen(option->palette.base().color().darker(120));
2504 cachePainter.drawLine(QPoint(r.left() + 1, r.top() + 1),
2505 QPoint(r.right() - 1, r.top() + 1));
2506 cachePainter.drawLine(QPoint(r.left() + 1, r.top() + 1),
2507 QPoint(r.left() + 1, r.bottom() - 1));
2508 cachePainter.setPen(option->palette.base().color());
2509 cachePainter.drawLine(QPoint(r.right() - 1, r.top() + 1),
2510 QPoint(r.right() - 1, r.bottom() - 1));
2511 cachePainter.drawLine(QPoint(r.left() + 1, r.bottom() - 1),
2512 QPoint(r.right() - 1, r.bottom() - 1));
2513 cachePainter.setPen(highlight);
2514 cachePainter.drawLine(QPoint(r.left() + 3, r.bottom() + 1),
2515 QPoint(r.right() - 3, r.bottom() + 1));
2516
2517 cachePainter.setPen(QPen(darkOutline, 1));
2518
2519 // top and bottom lines
2520 const QLine lines[4] = {
2521 QLine(QPoint(r.left() + 2, r.bottom()), QPoint(r.right()- 2, r.bottom())),
2522 QLine(QPoint(r.left() + 2, r.top()), QPoint(r.right() - 2, r.top())),
2523 QLine(QPoint(r.right(), r.top() + 2), QPoint(r.right(), r.bottom() - 2)),
2524 QLine(QPoint(r.left(), r.top() + 2), QPoint(r.left(), r.bottom() - 2))
2525 };
2526 cachePainter.drawLines(lines, 4);
2527 }
2528
2529 // gradients
2530 qt_cleanlooks_draw_gradient(&cachePainter, upRect,
2531 gradientStartColor.darker(106),
2532 gradientStopColor, TopDown, option->palette.button());
2533 qt_cleanlooks_draw_gradient(&cachePainter, downRect.adjusted(0, 0, 0, 1),
2534 gradientStartColor.darker(106),
2535 gradientStopColor, TopDown, option->palette.button());
2536 if (isEnabled) {
2537 if(upIsActive) {
2538 if (sunken) {
2539 cachePainter.fillRect(upRect.adjusted(1, 0, 0, 0), gradientStopColor.darker(110));
2540 } else if (hover) {
2541 qt_cleanlooks_draw_gradient(&cachePainter, upRect.adjusted(1, 0, 0, 0),
2542 gradientStartColor.lighter(110),
2543 gradientStopColor.lighter(110), TopDown, option->palette.button());
2544 }
2545 }
2546 if(downIsActive) {
2547 if (sunken) {
2548 cachePainter.fillRect(downRect.adjusted(1, 0, 0, 1), gradientStopColor.darker(110));
2549
2550 } else if (hover) {
2551 qt_cleanlooks_draw_gradient(&cachePainter, downRect.adjusted(1, 0, 0, 1),
2552 gradientStartColor.lighter(110),
2553 gradientStopColor.lighter(110), TopDown, option->palette.button());
2554 }
2555 }
2556 }
2557
2558 if (spinBox->frame) {
2559 // rounded corners
2560 const QPoint points[4] = {
2561 QPoint(r.left() + 1, r.bottom() - 1),
2562 QPoint(r.left() + 1, r.top() + 1),
2563 QPoint(r.right() - 1, r.bottom() - 1),
2564 QPoint(r.right() - 1, r.top() + 1)
2565 };
2566 cachePainter.drawPoints(points, 4);
2567
2568 if (option->state & State_HasFocus) {
2569 QColor darkoutline = option->palette.highlight().color().darker(150);
2570 QColor innerline = mergedColors(option->palette.highlight().color(), Qt::white);
2571 cachePainter.setPen(QPen(innerline, 0));
2572 if (spinBox->direction == Qt::LeftToRight) {
2573 cachePainter.drawRect(rect.adjusted(1, 2, -3 -downRect.width(), -3));
2574 cachePainter.setPen(QPen(darkoutline, 0));
2575 const QLine lines[4] = {
2576 QLine(QPoint(r.left() + 2, r.bottom()), QPoint(r.right()- downRect.width() - 1, r.bottom())),
2577 QLine(QPoint(r.left() + 2, r.top()), QPoint(r.right() - downRect.width() - 1, r.top())),
2578 QLine(QPoint(r.right() - downRect.width() - 1, r.top() + 1), QPoint(r.right()- downRect.width() - 1, r.bottom() - 1)),
2579 QLine(QPoint(r.left(), r.top() + 2), QPoint(r.left(), r.bottom() - 2))
2580 };
2581 cachePainter.drawLines(lines, 4);
2582 cachePainter.drawPoint(QPoint(r.left() + 1, r.bottom() - 1));
2583 cachePainter.drawPoint(QPoint(r.left() + 1, r.top() + 1));
2584 cachePainter.drawLine(QPoint(r.left(), r.top() + 2), QPoint(r.left(), r.bottom() - 2));
2585 } else {
2586 cachePainter.drawRect(rect.adjusted(downRect.width() + 2, 2, -2, -3));
2587 cachePainter.setPen(QPen(darkoutline, 0));
2588 cachePainter.drawLine(QPoint(r.left() + downRect.width(), r.bottom()), QPoint(r.right()- 2 - 1, r.bottom()));
2589 cachePainter.drawLine(QPoint(r.left() + downRect.width(), r.top()), QPoint(r.right() - 2 - 1, r.top()));
2590
2591 cachePainter.drawLine(QPoint(r.right(), r.top() + 2), QPoint(r.right(), r.bottom() - 2));
2592 cachePainter.drawPoint(QPoint(r.right() - 1, r.bottom() - 1));
2593 cachePainter.drawPoint(QPoint(r.right() - 1, r.top() + 1));
2594 cachePainter.drawLine(QPoint(r.left() + downRect.width() + 1, r.top()),
2595 QPoint(r.left() + downRect.width() + 1, r.bottom()));
2596 }
2597 }
2598 }
2599
2600 // outline the up/down buttons
2601 cachePainter.setPen(darkOutline);
2602 QColor light = option->palette.light().color().lighter();
2603
2604 if (spinBox->direction == Qt::RightToLeft) {
2605 cachePainter.drawLine(upRect.right(), upRect.top() - 1, upRect.right(), downRect.bottom() + 1);
2606 cachePainter.setPen(light);
2607 cachePainter.drawLine(upRect.right() - 1, upRect.top() + 3, upRect.right() - 1, downRect.bottom() );
2608 } else {
2609 cachePainter.drawLine(upRect.left(), upRect.top() - 1, upRect.left(), downRect.bottom() + 1);
2610 cachePainter.setPen(light);
2611 cachePainter.drawLine(upRect.left() + 1, upRect.top() , upRect.left() + 1, downRect.bottom() );
2612 }
2613 if (upIsActive && sunken) {
2614 cachePainter.setPen(gradientStopColor.darker(130));
2615 cachePainter.drawLine(upRect.left() + 1, upRect.top(), upRect.left() + 1, upRect.bottom());
2616 cachePainter.drawLine(upRect.left(), upRect.top() - 1, upRect.right(), upRect.top() - 1);
2617 } else {
2618 cachePainter.setPen(light);
2619 cachePainter.drawLine(upRect.topLeft() + QPoint(1, -1), upRect.topRight() + QPoint(-1, -1));
2620 cachePainter.setPen(darkOutline);
2621 cachePainter.drawLine(upRect.bottomLeft(), upRect.bottomRight());
2622 }
2623 if (downIsActive && sunken) {
2624 cachePainter.setPen(gradientStopColor.darker(130));
2625 cachePainter.drawLine(downRect.left() + 1, downRect.top(), downRect.left() + 1, downRect.bottom() + 1);
2626 cachePainter.drawLine(downRect.left(), downRect.top(), downRect.right(), downRect.top());
2627 cachePainter.setPen(gradientStopColor.darker(110));
2628 cachePainter.drawLine(downRect.left(), downRect.bottom() + 1, downRect.right(), downRect.bottom() + 1);
2629 } else {
2630 cachePainter.setPen(light);
2631 cachePainter.drawLine(downRect.topLeft() + QPoint(2,0), downRect.topRight());
2632 }
2633
2634 if (spinBox->buttonSymbols == QAbstractSpinBox::PlusMinus) {
2635 int centerX = upRect.center().x();
2636 int centerY = upRect.center().y();
2637 cachePainter.setPen(spinBox->palette.foreground().color());
2638
2639 // plus/minus
2640 if (spinBox->activeSubControls == SC_SpinBoxUp && sunken) {
2641 cachePainter.drawLine(1 + centerX - 2, 1 + centerY, 1 + centerX + 2, 1 + centerY);
2642 cachePainter.drawLine(1 + centerX, 1 + centerY - 2, 1 + centerX, 1 + centerY + 2);
2643 } else {
2644 cachePainter.drawLine(centerX - 2, centerY, centerX + 2, centerY);
2645 cachePainter.drawLine(centerX, centerY - 2, centerX, centerY + 2);
2646 }
2647
2648 centerX = downRect.center().x();
2649 centerY = downRect.center().y();
2650 if (spinBox->activeSubControls == SC_SpinBoxDown && sunken) {
2651 cachePainter.drawLine(1 + centerX - 2, 1 + centerY, 1 + centerX + 2, 1 + centerY);
2652 } else {
2653 cachePainter.drawLine(centerX - 2, centerY, centerX + 2, centerY);
2654 }
2655 } else if (spinBox->buttonSymbols == QAbstractSpinBox::UpDownArrows){
2656 // arrows
2657 QImage upArrow(qt_spinbox_button_arrow_up);
2658 upArrow.setColor(1, spinBox->palette.foreground().color().rgba());
2659
2660 cachePainter.drawImage(upRect.center().x() - upArrow.width() / 2,
2661 upRect.center().y() - upArrow.height() / 2,
2662 upArrow);
2663
2664 QImage downArrow(qt_spinbox_button_arrow_down);
2665 downArrow.setColor(1, spinBox->palette.foreground().color().rgba());
2666
2667 cachePainter.drawImage(downRect.center().x() - downArrow.width() / 2,
2668 downRect.center().y() - downArrow.height() / 2 + 1,
2669 downArrow);
2670 }
2671
2672 QColor disabledColor = option->palette.background().color();
2673 disabledColor.setAlpha(150);
2674 if (!(spinBox->stepEnabled & QAbstractSpinBox::StepUpEnabled))
2675 cachePainter.fillRect(upRect.adjusted(1, 0, 0, 0), disabledColor);
2676 if (!(spinBox->stepEnabled & QAbstractSpinBox::StepDownEnabled)) {
2677 cachePainter.fillRect(downRect.adjusted(1, 0, 0, 0), disabledColor);
2678 }
2679 cachePainter.end();
2680 QPixmapCache::insert(pixmapName, cache);
2681 }
2682 painter->drawPixmap(spinBox->rect.topLeft(), cache);
2683 }
2684 break;
2685 #endif // QT_NO_SPINBOX
2686 case CC_TitleBar:
2687 painter->save();
2688 if (const QStyleOptionTitleBar *titleBar = qstyleoption_cast<const QStyleOptionTitleBar *>(option)) {
2689 const int buttonMargin = 5;
2690 bool active = (titleBar->titleBarState & State_Active);
2691 QRect fullRect = titleBar->rect;
2692 QPalette palette = option->palette;
2693 QColor highlight = option->palette.highlight().color();
2694
2695 QColor titleBarFrameBorder(active ? highlight.darker(180): dark.darker(110));
2696 QColor titleBarHighlight(active ? highlight.lighter(120): palette.background().color().lighter(120));
2697 QColor textColor(active ? 0xffffff : 0xff000000);
2698 QColor textAlphaColor(active ? 0xffffff : 0xff000000 );
2699
2700 #ifdef QT3_SUPPORT
2701 if (widget && widget->inherits("Q3DockWindowTitleBar")) {
2702 QStyleOptionDockWidgetV2 dockwidget;
2703 dockwidget.QStyleOption::operator=(*option);
2704 proxy()->drawControl(CE_DockWidgetTitle, &dockwidget, painter, widget);
2705 } else
2706 #endif // QT3_SUPPORT
2707 {
2708 // Fill title bar gradient
2709 QColor titlebarColor = QColor(active ? highlight: palette.background().color());
2710 QLinearGradient gradient(option->rect.center().x(), option->rect.top(),
2711 option->rect.center().x(), option->rect.bottom());
2712
2713 gradient.setColorAt(0, titlebarColor.lighter(114));
2714 gradient.setColorAt(0.5, titlebarColor.lighter(102));
2715 gradient.setColorAt(0.51, titlebarColor.darker(104));
2716 gradient.setColorAt(1, titlebarColor);
2717 painter->fillRect(option->rect.adjusted(1, 1, -1, 0), gradient);
2718
2719 // Frame and rounded corners
2720 painter->setPen(titleBarFrameBorder);
2721
2722 // top outline
2723 painter->drawLine(fullRect.left() + 5, fullRect.top(), fullRect.right() - 5, fullRect.top());
2724 painter->drawLine(fullRect.left(), fullRect.top() + 4, fullRect.left(), fullRect.bottom());
2725 const QPoint points[5] = {
2726 QPoint(fullRect.left() + 4, fullRect.top() + 1),
2727 QPoint(fullRect.left() + 3, fullRect.top() + 1),
2728 QPoint(fullRect.left() + 2, fullRect.top() + 2),
2729 QPoint(fullRect.left() + 1, fullRect.top() + 3),
2730 QPoint(fullRect.left() + 1, fullRect.top() + 4)
2731 };
2732 painter->drawPoints(points, 5);
2733
2734 painter->drawLine(fullRect.right(), fullRect.top() + 4, fullRect.right(), fullRect.bottom());
2735 const QPoint points2[5] = {
2736 QPoint(fullRect.right() - 3, fullRect.top() + 1),
2737 QPoint(fullRect.right() - 4, fullRect.top() + 1),
2738 QPoint(fullRect.right() - 2, fullRect.top() + 2),
2739 QPoint(fullRect.right() - 1, fullRect.top() + 3),
2740 QPoint(fullRect.right() - 1, fullRect.top() + 4)
2741 };
2742 painter->drawPoints(points2, 5);
2743
2744 // draw bottomline
2745 painter->drawLine(fullRect.right(), fullRect.bottom(), fullRect.left(), fullRect.bottom());
2746
2747 // top highlight
2748 painter->setPen(titleBarHighlight);
2749 painter->drawLine(fullRect.left() + 6, fullRect.top() + 1, fullRect.right() - 6, fullRect.top() + 1);
2750 }
2751 // draw title
2752 QRect textRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarLabel, widget);
2753 QFont font = painter->font();
2754 font.setBold(true);
2755 painter->setFont(font);
2756 painter->setPen(active? (titleBar->palette.text().color().lighter(120)) :
2757 titleBar->palette.text().color() );
2758 // Note workspace also does elliding but it does not use the correct font
2759 QString title = QFontMetrics(font).elidedText(titleBar->text, Qt::ElideRight, textRect.width() - 14);
2760 painter->drawText(textRect.adjusted(1, 1, 1, 1), title, QTextOption(Qt::AlignHCenter | Qt::AlignVCenter));
2761 painter->setPen(Qt::white);
2762 if (active)
2763 painter->drawText(textRect, title, QTextOption(Qt::AlignHCenter | Qt::AlignVCenter));
2764 // min button
2765 if ((titleBar->subControls & SC_TitleBarMinButton) && (titleBar->titleBarFlags & Qt::WindowMinimizeButtonHint) &&
2766 !(titleBar->titleBarState& Qt::WindowMinimized)) {
2767 QRect minButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarMinButton, widget);
2768 if (minButtonRect.isValid()) {
2769 bool hover = (titleBar->activeSubControls & SC_TitleBarMinButton) && (titleBar->state & State_MouseOver);
2770 bool sunken = (titleBar->activeSubControls & SC_TitleBarMinButton) && (titleBar->state & State_Sunken);
2771 qt_cleanlooks_draw_mdibutton(painter, titleBar, minButtonRect, hover, sunken);
2772 QRect minButtonIconRect = minButtonRect.adjusted(buttonMargin ,buttonMargin , -buttonMargin, -buttonMargin);
2773 painter->setPen(textColor);
2774 painter->drawLine(minButtonIconRect.center().x() - 2, minButtonIconRect.center().y() + 3,
2775 minButtonIconRect.center().x() + 3, minButtonIconRect.center().y() + 3);
2776 painter->drawLine(minButtonIconRect.center().x() - 2, minButtonIconRect.center().y() + 4,
2777 minButtonIconRect.center().x() + 3, minButtonIconRect.center().y() + 4);
2778 painter->setPen(textAlphaColor);
2779 painter->drawLine(minButtonIconRect.center().x() - 3, minButtonIconRect.center().y() + 3,
2780 minButtonIconRect.center().x() - 3, minButtonIconRect.center().y() + 4);
2781 painter->drawLine(minButtonIconRect.center().x() + 4, minButtonIconRect.center().y() + 3,
2782 minButtonIconRect.center().x() + 4, minButtonIconRect.center().y() + 4);
2783 }
2784 }
2785 // max button
2786 if ((titleBar->subControls & SC_TitleBarMaxButton) && (titleBar->titleBarFlags & Qt::WindowMaximizeButtonHint) &&
2787 !(titleBar->titleBarState & Qt::WindowMaximized)) {
2788 QRect maxButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarMaxButton, widget);
2789 if (maxButtonRect.isValid()) {
2790 bool hover = (titleBar->activeSubControls & SC_TitleBarMaxButton) && (titleBar->state & State_MouseOver);
2791 bool sunken = (titleBar->activeSubControls & SC_TitleBarMaxButton) && (titleBar->state & State_Sunken);
2792 qt_cleanlooks_draw_mdibutton(painter, titleBar, maxButtonRect, hover, sunken);
2793
2794 QRect maxButtonIconRect = maxButtonRect.adjusted(buttonMargin, buttonMargin, -buttonMargin, -buttonMargin);
2795
2796 painter->setPen(textColor);
2797 painter->drawRect(maxButtonIconRect.adjusted(0, 0, -1, -1));
2798 painter->drawLine(maxButtonIconRect.left() + 1, maxButtonIconRect.top() + 1,
2799 maxButtonIconRect.right() - 1, maxButtonIconRect.top() + 1);
2800 painter->setPen(textAlphaColor);
2801 const QPoint points[4] = {
2802 maxButtonIconRect.topLeft(),
2803 maxButtonIconRect.topRight(),
2804 maxButtonIconRect.bottomLeft(),
2805 maxButtonIconRect.bottomRight()
2806 };
2807 painter->drawPoints(points, 4);
2808 }
2809 }
2810
2811 // close button
2812 if ((titleBar->subControls & SC_TitleBarCloseButton) && (titleBar->titleBarFlags & Qt::WindowSystemMenuHint)) {
2813 QRect closeButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarCloseButton, widget);
2814 if (closeButtonRect.isValid()) {
2815 bool hover = (titleBar->activeSubControls & SC_TitleBarCloseButton) && (titleBar->state & State_MouseOver);
2816 bool sunken = (titleBar->activeSubControls & SC_TitleBarCloseButton) && (titleBar->state & State_Sunken);
2817 qt_cleanlooks_draw_mdibutton(painter, titleBar, closeButtonRect, hover, sunken);
2818 QRect closeIconRect = closeButtonRect.adjusted(buttonMargin, buttonMargin, -buttonMargin, -buttonMargin);
2819 painter->setPen(textAlphaColor);
2820 const QLine lines[4] = {
2821 QLine(closeIconRect.left() + 1, closeIconRect.top(),
2822 closeIconRect.right(), closeIconRect.bottom() - 1),
2823 QLine(closeIconRect.left(), closeIconRect.top() + 1,
2824 closeIconRect.right() - 1, closeIconRect.bottom()),
2825 QLine(closeIconRect.right() - 1, closeIconRect.top(),
2826 closeIconRect.left(), closeIconRect.bottom() - 1),
2827 QLine(closeIconRect.right(), closeIconRect.top() + 1,
2828 closeIconRect.left() + 1, closeIconRect.bottom())
2829 };
2830 painter->drawLines(lines, 4);
2831 const QPoint points[4] = {
2832 closeIconRect.topLeft(),
2833 closeIconRect.topRight(),
2834 closeIconRect.bottomLeft(),
2835 closeIconRect.bottomRight()
2836 };
2837 painter->drawPoints(points, 4);
2838
2839 painter->setPen(textColor);
2840 painter->drawLine(closeIconRect.left() + 1, closeIconRect.top() + 1,
2841 closeIconRect.right() - 1, closeIconRect.bottom() - 1);
2842 painter->drawLine(closeIconRect.left() + 1, closeIconRect.bottom() - 1,
2843 closeIconRect.right() - 1, closeIconRect.top() + 1);
2844 }
2845 }
2846
2847 // normalize button
2848 if ((titleBar->subControls & SC_TitleBarNormalButton) &&
2849 (((titleBar->titleBarFlags & Qt::WindowMinimizeButtonHint) &&
2850 (titleBar->titleBarState & Qt::WindowMinimized)) ||
2851 ((titleBar->titleBarFlags & Qt::WindowMaximizeButtonHint) &&
2852 (titleBar->titleBarState & Qt::WindowMaximized)))) {
2853 QRect normalButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarNormalButton, widget);
2854 if (normalButtonRect.isValid()) {
2855
2856 bool hover = (titleBar->activeSubControls & SC_TitleBarNormalButton) && (titleBar->state & State_MouseOver);
2857 bool sunken = (titleBar->activeSubControls & SC_TitleBarNormalButton) && (titleBar->state & State_Sunken);
2858 QRect normalButtonIconRect = normalButtonRect.adjusted(buttonMargin, buttonMargin, -buttonMargin, -buttonMargin);
2859 qt_cleanlooks_draw_mdibutton(painter, titleBar, normalButtonRect, hover, sunken);
2860
2861 QRect frontWindowRect = normalButtonIconRect.adjusted(0, 3, -3, 0);
2862 painter->setPen(textColor);
2863 painter->drawRect(frontWindowRect.adjusted(0, 0, -1, -1));
2864 painter->drawLine(frontWindowRect.left() + 1, frontWindowRect.top() + 1,
2865 frontWindowRect.right() - 1, frontWindowRect.top() + 1);
2866 painter->setPen(textAlphaColor);
2867 const QPoint points[4] = {
2868 frontWindowRect.topLeft(),
2869 frontWindowRect.topRight(),
2870 frontWindowRect.bottomLeft(),
2871 frontWindowRect.bottomRight()
2872 };
2873 painter->drawPoints(points, 4);
2874
2875 QRect backWindowRect = normalButtonIconRect.adjusted(3, 0, 0, -3);
2876 QRegion clipRegion = backWindowRect;
2877 clipRegion -= frontWindowRect;
2878 painter->save();
2879 painter->setClipRegion(clipRegion);
2880 painter->setPen(textColor);
2881 painter->drawRect(backWindowRect.adjusted(0, 0, -1, -1));
2882 painter->drawLine(backWindowRect.left() + 1, backWindowRect.top() + 1,
2883 backWindowRect.right() - 1, backWindowRect.top() + 1);
2884 painter->setPen(textAlphaColor);
2885 const QPoint points2[4] = {
2886 backWindowRect.topLeft(),
2887 backWindowRect.topRight(),
2888 backWindowRect.bottomLeft(),
2889 backWindowRect.bottomRight()
2890 };
2891 painter->drawPoints(points2, 4);
2892 painter->restore();
2893 }
2894 }
2895
2896 // context help button
2897 if (titleBar->subControls & SC_TitleBarContextHelpButton
2898 && (titleBar->titleBarFlags & Qt::WindowContextHelpButtonHint)) {
2899 QRect contextHelpButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarContextHelpButton, widget);
2900 if (contextHelpButtonRect.isValid()) {
2901 bool hover = (titleBar->activeSubControls & SC_TitleBarContextHelpButton) && (titleBar->state & State_MouseOver);
2902 bool sunken = (titleBar->activeSubControls & SC_TitleBarContextHelpButton) && (titleBar->state & State_Sunken);
2903 qt_cleanlooks_draw_mdibutton(painter, titleBar, contextHelpButtonRect, hover, sunken);
2904
2905 QColor blend;
2906 QImage image(qt_titlebar_context_help);
2907 QColor alpha = textColor;
2908 alpha.setAlpha(128);
2909 image.setColor(1, textColor.rgba());
2910 image.setColor(2, alpha.rgba());
2911 painter->setRenderHint(QPainter::SmoothPixmapTransform);
2912 painter->drawImage(contextHelpButtonRect.adjusted(4, 4, -4, -4), image);
2913 }
2914 }
2915
2916 // shade button
2917 if (titleBar->subControls & SC_TitleBarShadeButton && (titleBar->titleBarFlags & Qt::WindowShadeButtonHint)) {
2918 QRect shadeButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarShadeButton, widget);
2919 if (shadeButtonRect.isValid()) {
2920 bool hover = (titleBar->activeSubControls & SC_TitleBarShadeButton) && (titleBar->state & State_MouseOver);
2921 bool sunken = (titleBar->activeSubControls & SC_TitleBarShadeButton) && (titleBar->state & State_Sunken);
2922 qt_cleanlooks_draw_mdibutton(painter, titleBar, shadeButtonRect, hover, sunken);
2923 QImage image(qt_scrollbar_button_arrow_up);
2924 image.setColor(1, textColor.rgba());
2925 painter->drawImage(shadeButtonRect.adjusted(5, 7, -5, -7), image);
2926 }
2927 }
2928
2929 // unshade button
2930 if (titleBar->subControls & SC_TitleBarUnshadeButton && (titleBar->titleBarFlags & Qt::WindowShadeButtonHint)) {
2931 QRect unshadeButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarUnshadeButton, widget);
2932 if (unshadeButtonRect.isValid()) {
2933 bool hover = (titleBar->activeSubControls & SC_TitleBarUnshadeButton) && (titleBar->state & State_MouseOver);
2934 bool sunken = (titleBar->activeSubControls & SC_TitleBarUnshadeButton) && (titleBar->state & State_Sunken);
2935 qt_cleanlooks_draw_mdibutton(painter, titleBar, unshadeButtonRect, hover, sunken);
2936 QImage image(qt_scrollbar_button_arrow_down);
2937 image.setColor(1, textColor.rgba());
2938 painter->drawImage(unshadeButtonRect.adjusted(5, 7, -5, -7), image);
2939 }
2940 }
2941
2942 if ((titleBar->subControls & SC_TitleBarSysMenu) && (titleBar->titleBarFlags & Qt::WindowSystemMenuHint)) {
2943 QRect iconRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarSysMenu, widget);
2944 if (iconRect.isValid()) {
2945 if (!titleBar->icon.isNull()) {
2946 titleBar->icon.paint(painter, iconRect);
2947 } else {
2948 QStyleOption tool(0);
2949 tool.palette = titleBar->palette;
2950 QPixmap pm = standardIcon(SP_TitleBarMenuButton, &tool, widget).pixmap(16, 16);
2951 tool.rect = iconRect;
2952 painter->save();
2953 proxy()->drawItemPixmap(painter, iconRect, Qt::AlignCenter, pm);
2954 painter->restore();
2955 }
2956 }
2957 }
2958 }
2959 painter->restore();
2960 break;
2961 #ifndef QT_NO_SCROLLBAR
2962 case CC_ScrollBar:
2963 painter->save();
2964 if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
2965 bool isEnabled = scrollBar->state & State_Enabled;
2966 bool reverse = scrollBar->direction == Qt::RightToLeft;
2967 bool horizontal = scrollBar->orientation == Qt::Horizontal;
2968 bool sunken = scrollBar->state & State_Sunken;
2969
2970 painter->fillRect(option->rect, option->palette.background());
2971
2972 QRect scrollBarSubLine = proxy()->subControlRect(control, scrollBar, SC_ScrollBarSubLine, widget);
2973 QRect scrollBarAddLine = proxy()->subControlRect(control, scrollBar, SC_ScrollBarAddLine, widget);
2974 QRect scrollBarSlider = proxy()->subControlRect(control, scrollBar, SC_ScrollBarSlider, widget);
2975 QRect grooveRect = proxy()->subControlRect(control, scrollBar, SC_ScrollBarGroove, widget);
2976
2977 // paint groove
2978 if (scrollBar->subControls & SC_ScrollBarGroove) {
2979 painter->setBrush(grooveColor);
2980 painter->setPen(Qt::NoPen);
2981 if (horizontal) {
2982 painter->drawRect(grooveRect);
2983 painter->setPen(darkOutline);
2984 painter->drawLine(grooveRect.topLeft(), grooveRect.topRight());
2985 painter->drawLine(grooveRect.bottomLeft(), grooveRect.bottomRight());
2986 } else {
2987 painter->drawRect(grooveRect);
2988 painter->setPen(darkOutline);
2989 painter->drawLine(grooveRect.topLeft(), grooveRect.bottomLeft());
2990 painter->drawLine(grooveRect.topRight(), grooveRect.bottomRight());
2991 }
2992 }
2993 //paint slider
2994 if (scrollBar->subControls & SC_ScrollBarSlider) {
2995 QRect pixmapRect = scrollBarSlider;
2996 if (horizontal)
2997 pixmapRect.adjust(-1, 0, 0, -1);
2998 else
2999 pixmapRect.adjust(0, -1, -1, 0);
3000
3001 if (isEnabled) {
3002 QLinearGradient gradient(pixmapRect.center().x(), pixmapRect.top(),
3003 pixmapRect.center().x(), pixmapRect.bottom());
3004 if (!horizontal)
3005 gradient = QLinearGradient(pixmapRect.left(), pixmapRect.center().y(),
3006 pixmapRect.right(), pixmapRect.center().y());
3007
3008 if (option->palette.button().gradient()) {
3009 gradient.setStops(option->palette.button().gradient()->stops());
3010 } else {
3011 if (sunken || (option->state & State_MouseOver &&
3012 (scrollBar->activeSubControls & SC_ScrollBarSlider))) {
3013 gradient.setColorAt(0, gradientStartColor.lighter(110));
3014 gradient.setColorAt(1, gradientStopColor.lighter(110));
3015 } else {
3016 gradient.setColorAt(0, gradientStartColor);
3017 gradient.setColorAt(1, gradientStopColor);
3018 }
3019 }
3020 painter->setPen(QPen(darkOutline, 0));
3021 painter->setBrush(gradient);
3022 painter->drawRect(pixmapRect);
3023
3024
3025 //calculate offsets used by highlight and shadow
3026 int yoffset, xoffset;
3027 if (option->state & State_Horizontal) {
3028 xoffset = 0;
3029 yoffset = 1;
3030 } else {
3031 xoffset = 1;
3032 yoffset = 0;
3033 }
3034 //draw slider highlights
3035 painter->setPen(QPen(gradientStopColor, 0));
3036 painter->drawLine(scrollBarSlider.left() + xoffset,
3037 scrollBarSlider.bottom() - yoffset,
3038 scrollBarSlider.right() - xoffset,
3039 scrollBarSlider.bottom() - yoffset);
3040 painter->drawLine(scrollBarSlider.right() - xoffset,
3041 scrollBarSlider.top() + yoffset,
3042 scrollBarSlider.right() - xoffset,
3043 scrollBarSlider.bottom() - yoffset);
3044
3045 //draw slider shadow
3046 painter->setPen(QPen(gradientStartColor, 0));
3047 painter->drawLine(scrollBarSlider.left() + xoffset,
3048 scrollBarSlider.top() + yoffset,
3049 scrollBarSlider.right() - xoffset,
3050 scrollBarSlider.top() + yoffset);
3051 painter->drawLine(scrollBarSlider.left() + xoffset,
3052 scrollBarSlider.top() + yoffset,
3053 scrollBarSlider.left() + xoffset,
3054 scrollBarSlider.bottom() - yoffset);
3055 } else {
3056 QLinearGradient gradient(pixmapRect.center().x(), pixmapRect.top(),
3057 pixmapRect.center().x(), pixmapRect.bottom());
3058 if (!horizontal) {
3059 gradient = QLinearGradient(pixmapRect.left(), pixmapRect.center().y(),
3060 pixmapRect.right(), pixmapRect.center().y());
3061 }
3062 if (sunken) {
3063 gradient.setColorAt(0, gradientStartColor.lighter(110));
3064 gradient.setColorAt(1, gradientStopColor.lighter(110));
3065 } else {
3066 gradient.setColorAt(0, gradientStartColor);
3067 gradient.setColorAt(1, gradientStopColor);
3068 }
3069 painter->setPen(darkOutline);
3070 painter->setBrush(gradient);
3071 painter->drawRect(pixmapRect);
3072 }
3073 int gripMargin = 4;
3074 //draw grips
3075 if (horizontal) {
3076 for (int i = -3; i< 6 ; i += 3) {
3077 painter->setPen(QPen(gripShadow, 1));
3078 painter->drawLine(
3079 QPoint(scrollBarSlider.center().x() + i ,
3080 scrollBarSlider.top() + gripMargin),
3081 QPoint(scrollBarSlider.center().x() + i,
3082 scrollBarSlider.bottom() - gripMargin));
3083 painter->setPen(QPen(palette.light(), 1));
3084 painter->drawLine(
3085 QPoint(scrollBarSlider.center().x() + i + 1,
3086 scrollBarSlider.top() + gripMargin ),
3087 QPoint(scrollBarSlider.center().x() + i + 1,
3088 scrollBarSlider.bottom() - gripMargin));
3089 }
3090 } else {
3091 for (int i = -3; i < 6 ; i += 3) {
3092 painter->setPen(QPen(gripShadow, 1));
3093 painter->drawLine(
3094 QPoint(scrollBarSlider.left() + gripMargin ,
3095 scrollBarSlider.center().y()+ i),
3096 QPoint(scrollBarSlider.right() - gripMargin,
3097 scrollBarSlider.center().y()+ i));
3098 painter->setPen(QPen(palette.light(), 1));
3099 painter->drawLine(
3100 QPoint(scrollBarSlider.left() + gripMargin,
3101 scrollBarSlider.center().y() + 1 + i),
3102 QPoint(scrollBarSlider.right() - gripMargin,
3103 scrollBarSlider.center().y() + 1 + i));
3104 }
3105 }
3106 }
3107
3108 // The SubLine (up/left) buttons
3109 if (scrollBar->subControls & SC_ScrollBarSubLine) {
3110 //int scrollBarExtent = proxy()->pixelMetric(PM_ScrollBarExtent, option, widget);
3111 QRect pixmapRect = scrollBarSubLine;
3112 if (isEnabled ) {
3113 QRect fillRect = pixmapRect.adjusted(1, 1, -1, -1);
3114 // Gradients
3115 if ((scrollBar->activeSubControls & SC_ScrollBarSubLine) && sunken) {
3116 qt_cleanlooks_draw_gradient(painter,
3117 QRect(fillRect),
3118 gradientStopColor.darker(120),
3119 gradientStopColor.darker(120),
3120 horizontal ? TopDown : FromLeft, option->palette.button());
3121 } else {
3122 qt_cleanlooks_draw_gradient(painter,
3123 QRect(fillRect),
3124 gradientStartColor.lighter(105),
3125 gradientStopColor,
3126 horizontal ? TopDown : FromLeft, option->palette.button());
3127 }
3128 }
3129 // Details
3130 QImage subButton;
3131 if (horizontal) {
3132 subButton = QImage(reverse ? qt_scrollbar_button_right : qt_scrollbar_button_left);
3133 } else {
3134 subButton = QImage(qt_scrollbar_button_up);
3135 }
3136 subButton.setColor(1, alphaCornerColor.rgba());
3137 subButton.setColor(2, darkOutline.rgba());
3138 if ((scrollBar->activeSubControls & SC_ScrollBarSubLine) && sunken) {
3139 subButton.setColor(3, gradientStopColor.darker(140).rgba());
3140 subButton.setColor(4, gradientStopColor.darker(120).rgba());
3141 } else {
3142 subButton.setColor(3, gradientStartColor.lighter(105).rgba());
3143 subButton.setColor(4, gradientStopColor.rgba());
3144 }
3145 subButton.setColor(5, scrollBar->palette.text().color().rgba());
3146 painter->drawImage(pixmapRect, subButton);
3147
3148 // Arrows
3149 PrimitiveElement arrow;
3150 if (option->state & State_Horizontal)
3151 arrow = option->direction == Qt::LeftToRight ? PE_IndicatorArrowLeft: PE_IndicatorArrowRight;
3152 else
3153 arrow = PE_IndicatorArrowUp;
3154 QStyleOption arrowOpt = *option;
3155 arrowOpt.rect = scrollBarSubLine.adjusted(3, 3, -2, -2);
3156 proxy()->drawPrimitive(arrow, &arrowOpt, painter, widget);
3157
3158
3159 // The AddLine (down/right) button
3160 if (scrollBar->subControls & SC_ScrollBarAddLine) {
3161 QString addLinePixmapName = QStyleHelper::uniqueName(QLatin1String("scrollbar_addline"), option, QSize(16, 16));
3162 QRect pixmapRect = scrollBarAddLine;
3163 if (isEnabled) {
3164 QRect fillRect = pixmapRect.adjusted(1, 1, -1, -1);
3165 // Gradients
3166 if ((scrollBar->activeSubControls & SC_ScrollBarAddLine) && sunken) {
3167 qt_cleanlooks_draw_gradient(painter,
3168 fillRect,
3169 gradientStopColor.darker(120),
3170 gradientStopColor.darker(120),
3171 horizontal ? TopDown: FromLeft, option->palette.button());
3172 } else {
3173 qt_cleanlooks_draw_gradient(painter,
3174 fillRect,
3175 gradientStartColor.lighter(105),
3176 gradientStopColor,
3177 horizontal ? TopDown : FromLeft, option->palette.button());
3178 }
3179 }
3180 // Details
3181 QImage addButton;
3182 if (horizontal) {
3183 addButton = QImage(reverse ? qt_scrollbar_button_left : qt_scrollbar_button_right);
3184 } else {
3185 addButton = QImage(qt_scrollbar_button_down);
3186 }
3187 addButton.setColor(1, alphaCornerColor.rgba());
3188 addButton.setColor(2, darkOutline.rgba());
3189 if ((scrollBar->activeSubControls & SC_ScrollBarAddLine) && sunken) {
3190 addButton.setColor(3, gradientStopColor.darker(140).rgba());
3191 addButton.setColor(4, gradientStopColor.darker(120).rgba());
3192 } else {
3193 addButton.setColor(3, gradientStartColor.lighter(105).rgba());
3194 addButton.setColor(4, gradientStopColor.rgba());
3195 }
3196 addButton.setColor(5, scrollBar->palette.text().color().rgba());
3197 painter->drawImage(pixmapRect, addButton);
3198
3199 PrimitiveElement arrow;
3200 if (option->state & State_Horizontal)
3201 arrow = option->direction == Qt::LeftToRight ? PE_IndicatorArrowRight : PE_IndicatorArrowLeft;
3202 else
3203 arrow = PE_IndicatorArrowDown;
3204
3205 QStyleOption arrowOpt = *option;
3206 arrowOpt.rect = scrollBarAddLine.adjusted(3, 3, -2, -2);
3207 proxy()->drawPrimitive(arrow, &arrowOpt, painter, widget);
3208 }
3209 }
3210 }
3211 painter->restore();
3212 break;;
3213 #endif // QT_NO_SCROLLBAR
3214 #ifndef QT_NO_COMBOBOX
3215 case CC_ComboBox:
3216 painter->save();
3217 if (const QStyleOptionComboBox *comboBox = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
3218 bool sunken = comboBox->state & State_On; // play dead, if combobox has no items
3219 bool isEnabled = (comboBox->state & State_Enabled);
3220 bool focus = isEnabled && (comboBox->state & State_HasFocus);
3221 QPixmap cache;
3222 QString pixmapName = QStyleHelper::uniqueName(QLatin1String("combobox"), option, comboBox->rect.size());
3223 if (sunken)
3224 pixmapName += QLatin1String("-sunken");
3225 if (comboBox->editable)
3226 pixmapName += QLatin1String("-editable");
3227 if (isEnabled)
3228 pixmapName += QLatin1String("-enabled");
3229
3230 if (!QPixmapCache::find(pixmapName, cache)) {
3231 cache = QPixmap(comboBox->rect.size());
3232 cache.fill(Qt::transparent);
3233 QPainter cachePainter(&cache);
3234 QRect pixmapRect(0, 0, comboBox->rect.width(), comboBox->rect.height());
3235 QStyleOptionComboBox comboBoxCopy = *comboBox;
3236 comboBoxCopy.rect = pixmapRect;
3237
3238 QRect rect = pixmapRect;
3239 QRect downArrowRect = proxy()->subControlRect(CC_ComboBox, &comboBoxCopy,
3240 SC_ComboBoxArrow, widget);
3241 QRect editRect = proxy()->subControlRect(CC_ComboBox, &comboBoxCopy,
3242 SC_ComboBoxEditField, widget);
3243 // Draw a push button
3244 if (comboBox->editable) {
3245 QStyleOptionFrame buttonOption;
3246 buttonOption.QStyleOption::operator=(*comboBox);
3247 buttonOption.rect = rect;
3248 buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver);
3249
3250 if (sunken) {
3251 buttonOption.state |= State_Sunken;
3252 buttonOption.state &= ~State_MouseOver;
3253 }
3254
3255 proxy()->drawPrimitive(PE_PanelButtonCommand, &buttonOption, &cachePainter, widget);
3256
3257 //remove shadow from left side of edit field when pressed:
3258 if (comboBox->direction != Qt::RightToLeft)
3259 cachePainter.fillRect(editRect.left() - 1, editRect.top() + 1, editRect.left(),
3260 editRect.bottom() - 3, option->palette.base());
3261
3262 cachePainter.setPen(dark.lighter(110));
3263 if (!sunken) {
3264 int borderSize = 2;
3265 if (comboBox->direction == Qt::RightToLeft) {
3266 cachePainter.drawLine(QPoint(downArrowRect.right() - 1, downArrowRect.top() + borderSize ),
3267 QPoint(downArrowRect.right() - 1, downArrowRect.bottom() - borderSize));
3268 cachePainter.setPen(option->palette.light().color());
3269 cachePainter.drawLine(QPoint(downArrowRect.right(), downArrowRect.top() + borderSize),
3270 QPoint(downArrowRect.right(), downArrowRect.bottom() - borderSize));
3271 } else {
3272 cachePainter.drawLine(QPoint(downArrowRect.left() , downArrowRect.top() + borderSize),
3273 QPoint(downArrowRect.left() , downArrowRect.bottom() - borderSize));
3274 cachePainter.setPen(option->palette.light().color());
3275 cachePainter.drawLine(QPoint(downArrowRect.left() + 1, downArrowRect.top() + borderSize),
3276 QPoint(downArrowRect.left() + 1, downArrowRect.bottom() - borderSize));
3277 }
3278 } else {
3279 if (comboBox->direction == Qt::RightToLeft) {
3280 cachePainter.drawLine(QPoint(downArrowRect.right(), downArrowRect.top() + 2),
3281 QPoint(downArrowRect.right(), downArrowRect.bottom() - 2));
3282
3283 } else {
3284 cachePainter.drawLine(QPoint(downArrowRect.left(), downArrowRect.top() + 2),
3285 QPoint(downArrowRect.left(), downArrowRect.bottom() - 2));
3286 }
3287 }
3288 } else {
3289 QStyleOptionButton buttonOption;
3290 buttonOption.QStyleOption::operator=(*comboBox);
3291 buttonOption.rect = rect;
3292 buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver);
3293 if (sunken) {
3294 buttonOption.state |= State_Sunken;
3295 buttonOption.state &= ~State_MouseOver;
3296 }
3297 proxy()->drawPrimitive(PE_PanelButtonCommand, &buttonOption, &cachePainter, widget);
3298
3299 cachePainter.setPen(buttonShadow.darker(102));
3300 int borderSize = 4;
3301
3302 if (!sunken) {
3303 if (comboBox->direction == Qt::RightToLeft) {
3304 cachePainter.drawLine(QPoint(downArrowRect.right() + 1, downArrowRect.top() + borderSize),
3305 QPoint(downArrowRect.right() + 1, downArrowRect.bottom() - borderSize));
3306 cachePainter.setPen(option->palette.light().color());
3307 cachePainter.drawLine(QPoint(downArrowRect.right(), downArrowRect.top() + borderSize),
3308 QPoint(downArrowRect.right(), downArrowRect.bottom() - borderSize));
3309 } else {
3310 cachePainter.drawLine(QPoint(downArrowRect.left() - 1, downArrowRect.top() + borderSize),
3311 QPoint(downArrowRect.left() - 1, downArrowRect.bottom() - borderSize));
3312 cachePainter.setPen(option->palette.light().color());
3313 cachePainter.drawLine(QPoint(downArrowRect.left() , downArrowRect.top() + borderSize),
3314 QPoint(downArrowRect.left() , downArrowRect.bottom() - borderSize));
3315 }
3316 } else {
3317 cachePainter.setPen(dark.lighter(110));
3318 if (comboBox->direction == Qt::RightToLeft) {
3319 cachePainter.drawLine(QPoint(downArrowRect.right() + 1, downArrowRect.top() + borderSize),
3320 QPoint(downArrowRect.right() + 1, downArrowRect.bottom() - borderSize));
3321
3322 } else {
3323 cachePainter.drawLine(QPoint(downArrowRect.left() - 1, downArrowRect.top() + borderSize),
3324 QPoint(downArrowRect.left() - 1, downArrowRect.bottom() - borderSize));
3325 }
3326 }
3327 }
3328
3329
3330 if (comboBox->subControls & SC_ComboBoxArrow) {
3331 if (comboBox->editable) {
3332 // Draw the down arrow
3333 QImage downArrow(qt_cleanlooks_arrow_down_xpm);
3334 downArrow.setColor(1, comboBox->palette.foreground().color().rgba());
3335 cachePainter.drawImage(downArrowRect.center().x() - downArrow.width() / 2,
3336 downArrowRect.center().y() - downArrow.height() / 2 + 1, downArrow);
3337 } else {
3338 // Draw the up/down arrow
3339 QImage upArrow(qt_scrollbar_button_arrow_up);
3340 upArrow.setColor(1, comboBox->palette.foreground().color().rgba());
3341 QImage downArrow(qt_scrollbar_button_arrow_down);
3342 downArrow.setColor(1, comboBox->palette.foreground().color().rgba());
3343 cachePainter.drawImage(downArrowRect.center().x() - downArrow.width() / 2,
3344 downArrowRect.center().y() - upArrow.height() - 1 , upArrow);
3345 cachePainter.drawImage(downArrowRect.center().x() - downArrow.width() / 2,
3346 downArrowRect.center().y() + 2, downArrow);
3347 }
3348 }
3349 // Draw the focus rect
3350 if (focus && !comboBox->editable
3351 && ((option->state & State_KeyboardFocusChange) || styleHint(SH_UnderlineShortcut, option, widget))) {
3352 QStyleOptionFocusRect focus;
3353 focus.rect = proxy()->subControlRect(CC_ComboBox, &comboBoxCopy, SC_ComboBoxEditField, widget)
3354 .adjusted(0, 2, option->direction == Qt::RightToLeft ? 1 : -1, -2);
3355 proxy()->drawPrimitive(PE_FrameFocusRect, &focus, &cachePainter, widget);
3356 }
3357 cachePainter.end();
3358 QPixmapCache::insert(pixmapName, cache);
3359 }
3360 painter->drawPixmap(comboBox->rect.topLeft(), cache);
3361 }
3362 painter->restore();
3363 break;
3364 #endif // QT_NO_COMBOBOX
3365 #ifndef QT_NO_GROUPBOX
3366 case CC_GroupBox:
3367 painter->save();
3368 if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
3369 QRect textRect = proxy()->subControlRect(CC_GroupBox, groupBox, SC_GroupBoxLabel, widget);
3370 QRect checkBoxRect = proxy()->subControlRect(CC_GroupBox, groupBox, SC_GroupBoxCheckBox, widget);
3371 bool flat = groupBox->features & QStyleOptionFrameV2::Flat;
3372
3373 if(!flat) {
3374 if (groupBox->subControls & QStyle::SC_GroupBoxFrame) {
3375 QStyleOptionFrameV2 frame;
3376 frame.QStyleOption::operator=(*groupBox);
3377 frame.features = groupBox->features;
3378 frame.lineWidth = groupBox->lineWidth;
3379 frame.midLineWidth = groupBox->midLineWidth;
3380 frame.rect = proxy()->subControlRect(CC_GroupBox, option, SC_GroupBoxFrame, widget);
3381
3382 painter->save();
3383 QRegion region(groupBox->rect);
3384 bool ltr = groupBox->direction == Qt::LeftToRight;
3385 region -= checkBoxRect.united(textRect).adjusted(ltr ? -4 : 0, 0, ltr ? 0 : 4, 0);
3386 if (!groupBox->text.isEmpty() || groupBox->subControls & SC_GroupBoxCheckBox)
3387 painter->setClipRegion(region);
3388 frame.palette.setBrush(QPalette::Dark, option->palette.mid().color().lighter(110));
3389 proxy()->drawPrimitive(PE_FrameGroupBox, &frame, painter);
3390 painter->restore();
3391 }
3392 }
3393 // Draw title
3394 if ((groupBox->subControls & QStyle::SC_GroupBoxLabel) && !groupBox->text.isEmpty()) {
3395 if (!groupBox->text.isEmpty()) {
3396 QColor textColor = groupBox->textColor;
3397 if (textColor.isValid())
3398 painter->setPen(textColor);
3399 int alignment = int(groupBox->textAlignment);
3400 if (!styleHint(QStyle::SH_UnderlineShortcut, option, widget))
3401 alignment |= Qt::TextHideMnemonic;
3402 if (flat) {
3403 QFont font = painter->font();
3404 font.setBold(true);
3405 painter->setFont(font);
3406 if (groupBox->subControls & SC_GroupBoxCheckBox) {
3407 textRect.adjust(checkBoxRect.right() + 4, 0, checkBoxRect.right() + 4, 0);
3408 }
3409 }
3410 painter->drawText(textRect, Qt::TextShowMnemonic | Qt::AlignLeft| alignment, groupBox->text);
3411 }
3412 }
3413 if (groupBox->subControls & SC_GroupBoxCheckBox) {
3414 QStyleOptionButton box;
3415 box.QStyleOption::operator=(*groupBox);
3416 box.rect = checkBoxRect;
3417 proxy()->drawPrimitive(PE_IndicatorCheckBox, &box, painter, widget);
3418 }
3419 }
3420 painter->restore();
3421 break;
3422 #endif // QT_NO_GROUPBOX
3423 #ifndef QT_NO_SLIDER
3424 case CC_Slider:
3425 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
3426 QRect groove = proxy()->subControlRect(CC_Slider, option, SC_SliderGroove, widget);
3427 QRect handle = proxy()->subControlRect(CC_Slider, option, SC_SliderHandle, widget);
3428
3429 bool horizontal = slider->orientation == Qt::Horizontal;
3430 bool ticksAbove = slider->tickPosition & QSlider::TicksAbove;
3431 bool ticksBelow = slider->tickPosition & QSlider::TicksBelow;
3432 QColor activeHighlight = option->palette.color(QPalette::Normal, QPalette::Highlight);
3433 QPixmap cache;
3434
3435 QBrush oldBrush = painter->brush();
3436 QPen oldPen = painter->pen();
3437
3438 QColor shadowAlpha(Qt::black);
3439 shadowAlpha.setAlpha(10);
3440 QColor highlightAlpha(Qt::white);
3441 highlightAlpha.setAlpha(80);
3442
3443 if ((option->subControls & SC_SliderGroove) && groove.isValid()) {
3444 QString groovePixmapName = QStyleHelper::uniqueName(QLatin1String("slider_groove"), option, groove.size());
3445 QRect pixmapRect(0, 0, groove.width(), groove.height());
3446
3447 // draw background groove
3448 if (!QPixmapCache::find(groovePixmapName, cache)) {
3449 cache = QPixmap(pixmapRect.size());
3450 cache.fill(Qt::transparent);
3451 QPainter groovePainter(&cache);
3452
3453 groovePainter.setPen(shadowAlpha);
3454 groovePainter.drawLine(1, 0, groove.width(), 0);
3455 groovePainter.drawLine(0, 0, 0, groove.height() - 1);
3456
3457 groovePainter.setPen(highlightAlpha);
3458 groovePainter.drawLine(1, groove.height() - 1, groove.width() - 1, groove.height() - 1);
3459 groovePainter.drawLine(groove.width() - 1, 1, groove.width() - 1, groove.height() - 1);
3460 QLinearGradient gradient;
3461 if (horizontal) {
3462 gradient.setStart(pixmapRect.center().x(), pixmapRect.top());
3463 gradient.setFinalStop(pixmapRect.center().x(), pixmapRect.bottom());
3464 }
3465 else {
3466 gradient.setStart(pixmapRect.left(), pixmapRect.center().y());
3467 gradient.setFinalStop(pixmapRect.right(), pixmapRect.center().y());
3468 }
3469 groovePainter.setPen(QPen(darkOutline.darker(110), 0));
3470 gradient.setColorAt(0, grooveColor.darker(110));//dark.lighter(120));
3471 gradient.setColorAt(1, grooveColor.lighter(110));//palette.button().color().darker(115));
3472 groovePainter.setBrush(gradient);
3473 groovePainter.drawRect(pixmapRect.adjusted(1, 1, -2, -2));
3474 groovePainter.end();
3475 QPixmapCache::insert(groovePixmapName, cache);
3476 }
3477 painter->drawPixmap(groove.topLeft(), cache);
3478
3479 // draw blue groove highlight
3480 QRect clipRect;
3481 groovePixmapName += QLatin1String("_blue");
3482 if (!QPixmapCache::find(groovePixmapName, cache)) {
3483 cache = QPixmap(pixmapRect.size());
3484 cache.fill(Qt::transparent);
3485 QPainter groovePainter(&cache);
3486 QLinearGradient gradient;
3487 if (horizontal) {
3488 gradient.setStart(pixmapRect.center().x(), pixmapRect.top());
3489 gradient.setFinalStop(pixmapRect.center().x(), pixmapRect.bottom());
3490 }
3491 else {
3492 gradient.setStart(pixmapRect.left(), pixmapRect.center().y());
3493 gradient.setFinalStop(pixmapRect.right(), pixmapRect.center().y());
3494 }
3495 groovePainter.setPen(QPen(activeHighlight.darker(150), 0));
3496 gradient.setColorAt(0, activeHighlight.darker(120));
3497 gradient.setColorAt(1, activeHighlight.lighter(160));
3498 groovePainter.setBrush(gradient);
3499 groovePainter.drawRect(pixmapRect.adjusted(1, 1, -2, -2));
3500 groovePainter.end();
3501 QPixmapCache::insert(groovePixmapName, cache);
3502 }
3503 if (horizontal) {
3504 if (slider->upsideDown)
3505 clipRect = QRect(handle.right(), groove.top(), groove.right() - handle.right(), groove.height());
3506 else
3507 clipRect = QRect(groove.left(), groove.top(), handle.left(), groove.height());
3508 } else {
3509 if (slider->upsideDown)
3510 clipRect = QRect(groove.left(), handle.bottom(), groove.width(), groove.height() - handle.bottom());
3511 else
3512 clipRect = QRect(groove.left(), groove.top(), groove.width(), handle.top() - groove.top());
3513 }
3514 painter->save();
3515 painter->setClipRect(clipRect.adjusted(0, 0, 1, 1));
3516 painter->drawPixmap(groove.topLeft(), cache);
3517 painter->restore();
3518 }
3519
3520 // draw handle
3521 if ((option->subControls & SC_SliderHandle) ) {
3522 QString handlePixmapName = QStyleHelper::uniqueName(QLatin1String("slider_handle"), option, handle.size());
3523 if (!QPixmapCache::find(handlePixmapName, cache)) {
3524 cache = QPixmap(handle.size());
3525 cache.fill(Qt::transparent);
3526 QRect pixmapRect(0, 0, handle.width(), handle.height());
3527 QPainter handlePainter(&cache);
3528
3529 QColor gradientStartColor = mergedColors(option->palette.button().color().lighter(155),
3530 dark.lighter(155), 50);
3531 QColor gradientStopColor = gradientStartColor.darker(108);
3532 QRect gradRect = pixmapRect.adjusted(2, 2, -2, -2);
3533
3534 QColor gradientBgStartColor = gradientStartColor;
3535 QColor gradientBgStopColor = gradientStopColor;
3536
3537 QColor outline = option->state & State_Enabled ? dark : dark.lighter(130);
3538 if (option->state & State_Enabled && option->activeSubControls & SC_SliderHandle) {
3539 gradientBgStartColor = option->palette.highlight().color().lighter(180);
3540 gradientBgStopColor = option->palette.highlight().color().lighter(110);
3541 outline = option->palette.highlight().color().darker(130);
3542 }
3543
3544 // gradient fill
3545 QRect r = pixmapRect.adjusted(1, 1, -1, -1);
3546
3547 qt_cleanlooks_draw_gradient(&handlePainter, gradRect,
3548 gradientBgStartColor,
3549 gradientBgStopColor,
3550 horizontal ? TopDown : FromLeft, option->palette.button());
3551
3552 handlePainter.setPen(QPen(outline.darker(110), 1));
3553 handlePainter.drawLine(QPoint(r.left(), r.top() + 3), QPoint(r.left(), r.bottom() - 3));
3554 handlePainter.drawLine(QPoint(r.right(), r.top() + 3), QPoint(r.right(), r.bottom() - 3));
3555 handlePainter.drawLine(QPoint(r.left() + 3, r.bottom()), QPoint(r.right() - 3, r.bottom()));
3556
3557 handlePainter.save();
3558 handlePainter.setRenderHint(QPainter::Antialiasing);
3559 handlePainter.translate(0.5, 0.5);
3560 const QLine lines[4] = {
3561 QLine(QPoint(r.left(), r.bottom() - 2), QPoint(r.left() + 2, r.bottom())),
3562 QLine(QPoint(r.left(), r.top() + 2), QPoint(r.left() + 2, r.top())),
3563 QLine(QPoint(r.right(), r.bottom() - 2), QPoint(r.right() - 2, r.bottom())),
3564 QLine(QPoint(r.right(), r.top() + 2), QPoint(r.right() - 2, r.top()))
3565 };
3566 handlePainter.drawLines(lines, 4);
3567 handlePainter.restore();;
3568 handlePainter.setPen(QPen(outline.darker(130), 1));
3569 handlePainter.drawLine(QPoint(r.left() + 3, r.top()), QPoint(r.right() - 3, r.top()));
3570 QColor cornerAlpha = outline.darker(120);
3571 cornerAlpha.setAlpha(80);
3572
3573 handlePainter.setPen(cornerAlpha);
3574 if (horizontal) {
3575 handlePainter.drawLine(QPoint(r.left() + 6, r.top()), QPoint(r.left() + 6, r.bottom()));
3576 handlePainter.drawLine(QPoint(r.right() - 6, r.top()), QPoint(r.right() - 6, r.bottom()));
3577 } else {
3578 handlePainter.drawLine(QPoint(r.left(), r.top() + 6), QPoint(r.right(), r.top() + 6));
3579 handlePainter.drawLine(QPoint(r.left(), r.bottom() - 6), QPoint(r.right(), r.bottom() - 6));
3580 }
3581
3582 //handle shadow
3583 handlePainter.setPen(shadowAlpha);
3584 handlePainter.drawLine(QPoint(r.left() + 2, r.bottom() + 1), QPoint(r.right() - 2, r.bottom() + 1));
3585 handlePainter.drawLine(QPoint(r.right() + 1, r.bottom() - 3), QPoint(r.right() + 1, r.top() + 4));
3586 handlePainter.drawLine(QPoint(r.right() - 1, r.bottom()), QPoint(r.right() + 1, r.bottom() - 2));
3587
3588 qt_cleanlooks_draw_gradient(&handlePainter, horizontal ?
3589 gradRect.adjusted(6, 0, -6, 0) : gradRect.adjusted(0, 6, 0, -6),
3590 gradientStartColor,
3591 gradientStopColor.darker(106),
3592 horizontal ? TopDown : FromLeft,
3593 option->palette.button());
3594
3595 //draw grips
3596 for (int i = -3; i< 6 ; i += 3) {
3597 for (int j = -3; j< 6 ; j += 3) {
3598 handlePainter.fillRect(r.center().x() + i, r.center().y() + j, 2, 2, highlightAlpha);
3599 handlePainter.setPen(gripShadow);
3600 handlePainter.drawPoint(r.center().x() + i, r.center().y() + j );
3601 }
3602 }
3603 handlePainter.end();
3604 QPixmapCache::insert(handlePixmapName, cache);
3605 }
3606
3607 painter->drawPixmap(handle.topLeft(), cache);
3608
3609 if (slider->state & State_HasFocus) {
3610 QStyleOptionFocusRect fropt;
3611 fropt.QStyleOption::operator=(*slider);
3612 fropt.rect = slider->rect;
3613 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
3614 }
3615 }
3616 if (option->subControls & SC_SliderTickmarks) {
3617 painter->setPen(darkOutline);
3618 int tickSize = proxy()->pixelMetric(PM_SliderTickmarkOffset, option, widget);
3619 int available = proxy()->pixelMetric(PM_SliderSpaceAvailable, slider, widget);
3620 int interval = slider->tickInterval;
3621 if (interval <= 0) {
3622 interval = slider->singleStep;
3623 if (QStyle::sliderPositionFromValue(slider->minimum, slider->maximum, interval,
3624 available)
3625 - QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
3626 0, available) < 3)
3627 interval = slider->pageStep;
3628 }
3629 if (interval <= 0)
3630 interval = 1;
3631
3632 int v = slider->minimum;
3633 int len = proxy()->pixelMetric(PM_SliderLength, slider, widget);
3634 while (v <= slider->maximum + 1) {
3635 if (v == slider->maximum + 1 && interval == 1)
3636 break;
3637 const int v_ = qMin(v, slider->maximum);
3638 int pos = sliderPositionFromValue(slider->minimum, slider->maximum,
3639 v_, (horizontal
3640 ? slider->rect.width()
3641 : slider->rect.height()) - len,
3642 slider->upsideDown) + len / 2;
3643 int extra = 2 - ((v_ == slider->minimum || v_ == slider->maximum) ? 1 : 0);
3644
3645 if (horizontal) {
3646 if (ticksAbove) {
3647 painter->drawLine(pos, slider->rect.top() + extra,
3648 pos, slider->rect.top() + tickSize);
3649 }
3650 if (ticksBelow) {
3651 painter->drawLine(pos, slider->rect.bottom() - extra,
3652 pos, slider->rect.bottom() - tickSize);
3653 }
3654 } else {
3655 if (ticksAbove) {
3656 painter->drawLine(slider->rect.left() + extra, pos,
3657 slider->rect.left() + tickSize, pos);
3658 }
3659 if (ticksBelow) {
3660 painter->drawLine(slider->rect.right() - extra, pos,
3661 slider->rect.right() - tickSize, pos);
3662 }
3663 }
3664 // in the case where maximum is max int
3665 int nextInterval = v + interval;
3666 if (nextInterval < v)
3667 break;
3668 v = nextInterval;
3669 }
3670 }
3671 painter->setBrush(oldBrush);
3672 painter->setPen(oldPen);
3673 }
3674 break;
3675 #endif // QT_NO_SLIDER
3676 #ifndef QT_NO_DIAL
3677 case CC_Dial:
3678 if (const QStyleOptionSlider *dial = qstyleoption_cast<const QStyleOptionSlider *>(option))
3679 QStyleHelper::drawDial(dial, painter);
3680 break;
3681 #endif // QT_NO_DIAL
3682 default:
3683 QWindowsStyle::drawComplexControl(control, option, painter, widget);
3684 break;
3685 }
3686 }
3687
3688 /*!
3689 \reimp
3690 */
pixelMetric(PixelMetric metric,const QStyleOption * option,const QWidget * widget) const3691 int QCleanlooksStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const
3692 {
3693 int ret = -1;
3694 switch (metric) {
3695 case PM_ToolTipLabelFrameWidth:
3696 ret = 2;
3697 break;
3698 case PM_ButtonDefaultIndicator:
3699 ret = 0;
3700 break;
3701 case PM_ButtonShiftHorizontal:
3702 case PM_ButtonShiftVertical:
3703 ret = 0;
3704 break;
3705 case PM_MessageBoxIconSize:
3706 ret = 48;
3707 break;
3708 case PM_ListViewIconSize:
3709 ret = 24;
3710 break;
3711 case PM_DialogButtonsSeparator:
3712 case PM_SplitterWidth:
3713 ret = 6;
3714 break;
3715 case PM_ScrollBarSliderMin:
3716 ret = 26;
3717 break;
3718 case PM_MenuPanelWidth: //menu framewidth
3719 ret = 2;
3720 break;
3721 case PM_TitleBarHeight:
3722 ret = 24;
3723 break;
3724 case PM_ScrollBarExtent:
3725 ret = 15;
3726 break;
3727 case PM_SliderThickness:
3728 ret = 15;
3729 break;
3730 case PM_SliderLength:
3731 ret = 27;
3732 break;
3733 case PM_DockWidgetTitleMargin:
3734 ret = 1;
3735 break;
3736 case PM_MenuBarVMargin:
3737 ret = 1;
3738 break;
3739 case PM_DefaultFrameWidth:
3740 ret = 2;
3741 break;
3742 case PM_SpinBoxFrameWidth:
3743 ret = 3;
3744 break;
3745 case PM_MenuBarItemSpacing:
3746 ret = 6;
3747 break;
3748 case PM_MenuBarHMargin:
3749 ret = 0;
3750 break;
3751 case PM_ToolBarHandleExtent:
3752 ret = 9;
3753 break;
3754 case PM_ToolBarItemSpacing:
3755 ret = 2;
3756 break;
3757 case PM_ToolBarFrameWidth:
3758 ret = 0;
3759 break;
3760 case PM_ToolBarItemMargin:
3761 ret = 1;
3762 break;
3763 case PM_SmallIconSize:
3764 ret = 16;
3765 break;
3766 case PM_ButtonIconSize:
3767 ret = 24;
3768 break;
3769 case PM_MenuVMargin:
3770 case PM_MenuHMargin:
3771 ret = 0;
3772 break;
3773 case PM_DockWidgetTitleBarButtonMargin:
3774 ret = 4;
3775 break;
3776 case PM_MaximumDragDistance:
3777 return -1;
3778 case PM_TabCloseIndicatorWidth:
3779 case PM_TabCloseIndicatorHeight:
3780 return 20;
3781 default:
3782 break;
3783 }
3784
3785 return ret != -1 ? ret : QWindowsStyle::pixelMetric(metric, option, widget);
3786 }
3787
3788 /*!
3789 \reimp
3790 */
sizeFromContents(ContentsType type,const QStyleOption * option,const QSize & size,const QWidget * widget) const3791 QSize QCleanlooksStyle::sizeFromContents(ContentsType type, const QStyleOption *option,
3792 const QSize &size, const QWidget *widget) const
3793 {
3794 QSize newSize = QWindowsStyle::sizeFromContents(type, option, size, widget);
3795 switch (type) {
3796 case CT_PushButton:
3797 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
3798 if (!btn->text.isEmpty() && newSize.width() < 80)
3799 newSize.setWidth(80);
3800 if (!btn->icon.isNull() && btn->iconSize.height() > 16)
3801 newSize -= QSize(0, 2);
3802 newSize += QSize(0, 1);
3803 }
3804 if (const QPushButton *button = qobject_cast<const QPushButton *>(widget)) {
3805 if (qobject_cast<const QDialogButtonBox *>(button->parentWidget())) {
3806 if (newSize.height() < 32)
3807 newSize.setHeight(32);
3808 }
3809 }
3810 break;
3811 #ifndef QT_NO_GROUPBOX
3812 case CT_GroupBox:
3813 // Since we use a bold font we have to recalculate base width
3814 if (const QGroupBox *gb = qobject_cast<const QGroupBox*>(widget)) {
3815 QFont font = gb->font();
3816 font.setBold(true);
3817 QFontMetrics metrics(font);
3818 int baseWidth = metrics.width(gb->title()) + metrics.width(QLatin1Char(' '));
3819 if (gb->isCheckable()) {
3820 baseWidth += proxy()->pixelMetric(QStyle::PM_IndicatorWidth, option, widget);
3821 baseWidth += proxy()->pixelMetric(QStyle::PM_CheckBoxLabelSpacing, option, widget);
3822 }
3823 newSize.setWidth(qMax(baseWidth, newSize.width()));
3824 }
3825 newSize += QSize(0, 1);
3826 break;
3827 #endif //QT_NO_GROUPBOX
3828 case CT_RadioButton:
3829 case CT_CheckBox:
3830 newSize += QSize(0, 1);
3831 break;
3832 case CT_ToolButton:
3833 #ifndef QT_NO_TOOLBAR
3834 if (widget && qobject_cast<QToolBar *>(widget->parentWidget()))
3835 newSize += QSize(4, 6);
3836 #endif // QT_NO_TOOLBAR
3837 break;
3838 case CT_SpinBox:
3839 newSize += QSize(0, -2);
3840 break;
3841 case CT_ComboBox:
3842 newSize += QSize(2, 4);
3843 break;
3844 case CT_LineEdit:
3845 newSize += QSize(0, 4);
3846 break;
3847 case CT_MenuBarItem:
3848 newSize += QSize(0, 2);
3849 break;
3850 case CT_MenuItem:
3851 if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
3852 if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
3853 if (!menuItem->text.isEmpty()) {
3854 newSize.setHeight(menuItem->fontMetrics.height());
3855 }
3856 }
3857 #ifndef QT_NO_COMBOBOX
3858 else if (!menuItem->icon.isNull()) {
3859 if (const QComboBox *combo = qobject_cast<const QComboBox*>(widget)) {
3860 newSize.setHeight(qMax(combo->iconSize().height() + 2, newSize.height()));
3861 }
3862 }
3863 #endif // QT_NO_COMBOBOX
3864 }
3865 break;
3866 case CT_SizeGrip:
3867 newSize += QSize(4, 4);
3868 break;
3869 case CT_MdiControls:
3870 if (const QStyleOptionComplex *styleOpt = qstyleoption_cast<const QStyleOptionComplex *>(option)) {
3871 int width = 0;
3872 if (styleOpt->subControls & SC_MdiMinButton)
3873 width += 19 + 1;
3874 if (styleOpt->subControls & SC_MdiNormalButton)
3875 width += 19 + 1;
3876 if (styleOpt->subControls & SC_MdiCloseButton)
3877 width += 19 + 1;
3878 newSize = QSize(width, 19);
3879 } else {
3880 newSize = QSize(60, 19);
3881 }
3882 break;
3883 default:
3884 break;
3885 }
3886 return newSize;
3887 }
3888
3889 /*!
3890 \reimp
3891 */
polish(QApplication * app)3892 void QCleanlooksStyle::polish(QApplication *app)
3893 {
3894 QWindowsStyle::polish(app);
3895 }
3896
3897 /*!
3898 \reimp
3899 */
polish(QWidget * widget)3900 void QCleanlooksStyle::polish(QWidget *widget)
3901 {
3902 QWindowsStyle::polish(widget);
3903 if (qobject_cast<QAbstractButton*>(widget)
3904 #ifndef QT_NO_COMBOBOX
3905 || qobject_cast<QComboBox *>(widget)
3906 #endif
3907 #ifndef QT_NO_PROGRESSBAR
3908 || qobject_cast<QProgressBar *>(widget)
3909 #endif
3910 #ifndef QT_NO_SCROLLBAR
3911 || qobject_cast<QScrollBar *>(widget)
3912 #endif
3913 #ifndef QT_NO_SPLITTER
3914 || qobject_cast<QSplitterHandle *>(widget)
3915 #endif
3916 || qobject_cast<QAbstractSlider *>(widget)
3917 #ifndef QT_NO_SPINBOX
3918 || qobject_cast<QAbstractSpinBox *>(widget)
3919 #endif
3920 || (widget->inherits("QWorkspaceChild"))
3921 || (widget->inherits("QDockSeparator"))
3922 || (widget->inherits("QDockWidgetSeparator"))
3923 ) {
3924 widget->setAttribute(Qt::WA_Hover, true);
3925 }
3926 }
3927
3928 /*!
3929 \reimp
3930 */
polish(QPalette & pal)3931 void QCleanlooksStyle::polish(QPalette &pal)
3932 {
3933 QWindowsStyle::polish(pal);
3934 //this is a workaround for some themes such as Human, where the contrast
3935 //between text and background is too low.
3936 QColor highlight = pal.highlight().color();
3937 QColor highlightText = pal.highlightedText().color();
3938 if (qAbs(qGray(highlight.rgb()) - qGray(highlightText.rgb())) < 150) {
3939 if (qGray(highlightText.rgb()) < 128)
3940 pal.setBrush(QPalette::Highlight, highlight.lighter(145));
3941 }
3942 }
3943
3944 /*!
3945 \reimp
3946 */
unpolish(QWidget * widget)3947 void QCleanlooksStyle::unpolish(QWidget *widget)
3948 {
3949 QWindowsStyle::unpolish(widget);
3950 if (qobject_cast<QAbstractButton*>(widget)
3951 #ifndef QT_NO_COMBOBOX
3952 || qobject_cast<QComboBox *>(widget)
3953 #endif
3954 #ifndef QT_NO_PROGRESSBAR
3955 || qobject_cast<QProgressBar *>(widget)
3956 #endif
3957 #ifndef QT_NO_SCROLLBAR
3958 || qobject_cast<QScrollBar *>(widget)
3959 #endif
3960 #ifndef QT_NO_SPLITTER
3961 || qobject_cast<QSplitterHandle *>(widget)
3962 #endif
3963 || qobject_cast<QAbstractSlider *>(widget)
3964 #ifndef QT_NO_SPINBOX
3965 || qobject_cast<QAbstractSpinBox *>(widget)
3966 #endif
3967 || (widget->inherits("QWorkspaceChild"))
3968 || (widget->inherits("QDockSeparator"))
3969 || (widget->inherits("QDockWidgetSeparator"))
3970 ) {
3971 widget->setAttribute(Qt::WA_Hover, false);
3972 }
3973 }
3974
3975 /*!
3976 \reimp
3977 */
unpolish(QApplication * app)3978 void QCleanlooksStyle::unpolish(QApplication *app)
3979 {
3980 QWindowsStyle::unpolish(app);
3981 }
3982
3983 /*!
3984 \reimp
3985 */
subControlRect(ComplexControl control,const QStyleOptionComplex * option,SubControl subControl,const QWidget * widget) const3986 QRect QCleanlooksStyle::subControlRect(ComplexControl control, const QStyleOptionComplex *option,
3987 SubControl subControl, const QWidget *widget) const
3988 {
3989 QRect rect = QWindowsStyle::subControlRect(control, option, subControl, widget);
3990
3991 switch (control) {
3992 #ifndef QT_NO_SLIDER
3993 case CC_Slider:
3994 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
3995 int tickSize = proxy()->pixelMetric(PM_SliderTickmarkOffset, option, widget);
3996 switch (subControl) {
3997 case SC_SliderHandle: {
3998 if (slider->orientation == Qt::Horizontal) {
3999 rect.setHeight(proxy()->pixelMetric(PM_SliderThickness));
4000 rect.setWidth(proxy()->pixelMetric(PM_SliderLength));
4001 int centerY = slider->rect.center().y() - rect.height() / 2;
4002 if (slider->tickPosition & QSlider::TicksAbove)
4003 centerY += tickSize;
4004 if (slider->tickPosition & QSlider::TicksBelow)
4005 centerY -= tickSize;
4006 rect.moveTop(centerY);
4007 } else {
4008 rect.setWidth(proxy()->pixelMetric(PM_SliderThickness));
4009 rect.setHeight(proxy()->pixelMetric(PM_SliderLength));
4010 int centerX = slider->rect.center().x() - rect.width() / 2;
4011 if (slider->tickPosition & QSlider::TicksAbove)
4012 centerX += tickSize;
4013 if (slider->tickPosition & QSlider::TicksBelow)
4014 centerX -= tickSize;
4015 rect.moveLeft(centerX);
4016 }
4017 }
4018 break;
4019 case SC_SliderGroove: {
4020 QPoint grooveCenter = slider->rect.center();
4021 if (slider->orientation == Qt::Horizontal) {
4022 rect.setHeight(7);
4023 if (slider->tickPosition & QSlider::TicksAbove)
4024 grooveCenter.ry() += tickSize;
4025 if (slider->tickPosition & QSlider::TicksBelow)
4026 grooveCenter.ry() -= tickSize;
4027 } else {
4028 rect.setWidth(7);
4029 if (slider->tickPosition & QSlider::TicksAbove)
4030 grooveCenter.rx() += tickSize;
4031 if (slider->tickPosition & QSlider::TicksBelow)
4032 grooveCenter.rx() -= tickSize;
4033 }
4034 rect.moveCenter(grooveCenter);
4035 break;
4036 }
4037 default:
4038 break;
4039 }
4040 }
4041 break;
4042 #endif // QT_NO_SLIDER
4043 case CC_ScrollBar:
4044 break;
4045 #ifndef QT_NO_SPINBOX
4046 case CC_SpinBox:
4047 if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
4048 QSize bs;
4049 int center = spinbox->rect.height() / 2;
4050 int fw = spinbox->frame ? proxy()->pixelMetric(PM_SpinBoxFrameWidth, spinbox, widget) : 0;
4051 int y = fw;
4052 bs.setHeight(qMax(8, spinbox->rect.height()/2 - y));
4053 bs.setWidth(15);
4054 int x, lx, rx;
4055 x = spinbox->rect.width() - y - bs.width() + 2;
4056 lx = fw;
4057 rx = x - fw;
4058 switch (subControl) {
4059 case SC_SpinBoxUp:
4060 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
4061 return QRect();
4062 rect = QRect(x, fw, bs.width(), center - fw);
4063 break;
4064 case SC_SpinBoxDown:
4065 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
4066 return QRect();
4067
4068 rect = QRect(x, center, bs.width(), spinbox->rect.bottom() - center - fw + 1);
4069 break;
4070 case SC_SpinBoxEditField:
4071 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons) {
4072 rect = QRect(lx, fw, spinbox->rect.width() - 2*fw, spinbox->rect.height() - 2*fw);
4073 } else {
4074 rect = QRect(lx, fw, rx - qMax(fw - 1, 0), spinbox->rect.height() - 2*fw);
4075 }
4076 break;
4077 case SC_SpinBoxFrame:
4078 rect = spinbox->rect;
4079 default:
4080 break;
4081 }
4082 rect = visualRect(spinbox->direction, spinbox->rect, rect);
4083 }
4084 break;
4085 #endif // Qt_NO_SPINBOX
4086 #ifndef QT_NO_GROUPBOX
4087 case CC_GroupBox:
4088 if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
4089 int topMargin = 0;
4090 int topHeight = 0;
4091 int verticalAlignment = proxy()->styleHint(SH_GroupBox_TextLabelVerticalAlignment, groupBox, widget);
4092 bool flat = groupBox->features & QStyleOptionFrameV2::Flat;
4093 if (!groupBox->text.isEmpty()) {
4094 topHeight = groupBox->fontMetrics.height();
4095 if (verticalAlignment & Qt::AlignVCenter)
4096 topMargin = topHeight / 2;
4097 else if (verticalAlignment & Qt::AlignTop)
4098 topMargin = topHeight;
4099 }
4100 QRect frameRect = groupBox->rect;
4101 frameRect.setTop(topMargin);
4102 if (subControl == SC_GroupBoxFrame) {
4103 return rect;
4104 }
4105 else if (subControl == SC_GroupBoxContents) {
4106 if( flat ) {
4107 int margin = 0;
4108 int leftMarginExtension = 16;
4109 rect = frameRect.adjusted(leftMarginExtension + margin, margin + topHeight, -margin, -margin);
4110 }
4111 break;
4112 }
4113 if(flat) {
4114 if (const QGroupBox *groupBoxWidget = qobject_cast<const QGroupBox *>(widget)) {
4115 //Prepare metrics for a bold font
4116 QFont font = widget->font();
4117 font.setBold(true);
4118 QFontMetrics fontMetrics(font);
4119
4120 QSize textRect = fontMetrics.boundingRect(groupBoxWidget->title()).size() + QSize(2, 2);
4121 if (subControl == SC_GroupBoxCheckBox) {
4122 int indicatorWidth = proxy()->pixelMetric(PM_IndicatorWidth, option, widget);
4123 int indicatorHeight = proxy()->pixelMetric(PM_IndicatorHeight, option, widget);
4124 rect.setWidth(indicatorWidth);
4125 rect.setHeight(indicatorHeight);
4126 rect.moveTop((fontMetrics.height() - indicatorHeight) / 2 + 2);
4127 } else if (subControl == SC_GroupBoxLabel) {
4128 rect.setSize(textRect);
4129 }
4130 }
4131 }
4132 }
4133 return rect;
4134 #ifndef QT_NO_COMBOBOX
4135 case CC_ComboBox:
4136 switch (subControl) {
4137 case SC_ComboBoxArrow:
4138 rect = visualRect(option->direction, option->rect, rect);
4139 rect.setRect(rect.right() - 18, rect.top() - 2,
4140 19, rect.height() + 4);
4141 rect = visualRect(option->direction, option->rect, rect);
4142 break;
4143 case SC_ComboBoxEditField: {
4144 int frameWidth = proxy()->pixelMetric(PM_DefaultFrameWidth);
4145 rect = visualRect(option->direction, option->rect, rect);
4146 rect.setRect(option->rect.left() + frameWidth, option->rect.top() + frameWidth,
4147 option->rect.width() - 19 - 2 * frameWidth,
4148 option->rect.height() - 2 * frameWidth);
4149 if (const QStyleOptionComboBox *box = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
4150 if (!box->editable) {
4151 rect.adjust(2, 0, 0, 0);
4152 if (box->state & (State_Sunken | State_On))
4153 rect.translate(1, 1);
4154 }
4155 }
4156 rect = visualRect(option->direction, option->rect, rect);
4157 break;
4158 }
4159 default:
4160 break;
4161 }
4162 break;
4163 #endif // QT_NO_COMBOBOX
4164 #endif //QT_NO_GROUPBOX
4165 case CC_TitleBar:
4166 if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(option)) {
4167 SubControl sc = subControl;
4168 QRect &ret = rect;
4169 const int indent = 3;
4170 const int controlTopMargin = 3;
4171 const int controlBottomMargin = 3;
4172 const int controlWidthMargin = 2;
4173 const int controlHeight = tb->rect.height() - controlTopMargin - controlBottomMargin ;
4174 const int delta = controlHeight + controlWidthMargin;
4175 int offset = 0;
4176
4177 bool isMinimized = tb->titleBarState & Qt::WindowMinimized;
4178 bool isMaximized = tb->titleBarState & Qt::WindowMaximized;
4179
4180 switch (sc) {
4181 case SC_TitleBarLabel:
4182 if (tb->titleBarFlags & (Qt::WindowTitleHint | Qt::WindowSystemMenuHint)) {
4183 ret = tb->rect;
4184 if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
4185 ret.adjust(delta, 0, -delta, 0);
4186 if (tb->titleBarFlags & Qt::WindowMinimizeButtonHint)
4187 ret.adjust(0, 0, -delta, 0);
4188 if (tb->titleBarFlags & Qt::WindowMaximizeButtonHint)
4189 ret.adjust(0, 0, -delta, 0);
4190 if (tb->titleBarFlags & Qt::WindowShadeButtonHint)
4191 ret.adjust(0, 0, -delta, 0);
4192 if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
4193 ret.adjust(0, 0, -delta, 0);
4194 }
4195 break;
4196 case SC_TitleBarContextHelpButton:
4197 if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
4198 offset += delta;
4199 case SC_TitleBarMinButton:
4200 if (!isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
4201 offset += delta;
4202 else if (sc == SC_TitleBarMinButton)
4203 break;
4204 case SC_TitleBarNormalButton:
4205 if (isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
4206 offset += delta;
4207 else if (isMaximized && (tb->titleBarFlags & Qt::WindowMaximizeButtonHint))
4208 offset += delta;
4209 else if (sc == SC_TitleBarNormalButton)
4210 break;
4211 case SC_TitleBarMaxButton:
4212 if (!isMaximized && (tb->titleBarFlags & Qt::WindowMaximizeButtonHint))
4213 offset += delta;
4214 else if (sc == SC_TitleBarMaxButton)
4215 break;
4216 case SC_TitleBarShadeButton:
4217 if (!isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
4218 offset += delta;
4219 else if (sc == SC_TitleBarShadeButton)
4220 break;
4221 case SC_TitleBarUnshadeButton:
4222 if (isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
4223 offset += delta;
4224 else if (sc == SC_TitleBarUnshadeButton)
4225 break;
4226 case SC_TitleBarCloseButton:
4227 if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
4228 offset += delta;
4229 else if (sc == SC_TitleBarCloseButton)
4230 break;
4231 ret.setRect(tb->rect.right() - indent - offset, tb->rect.top() + controlTopMargin,
4232 controlHeight, controlHeight);
4233 break;
4234 case SC_TitleBarSysMenu:
4235 if (tb->titleBarFlags & Qt::WindowSystemMenuHint) {
4236 ret.setRect(tb->rect.left() + controlWidthMargin + indent, tb->rect.top() + controlTopMargin,
4237 controlHeight, controlHeight);
4238 }
4239 break;
4240 default:
4241 break;
4242 }
4243 ret = visualRect(tb->direction, tb->rect, ret);
4244 }
4245 break;
4246 default:
4247 break;
4248 }
4249
4250 return rect;
4251 }
4252
4253
4254 /*!
4255 \reimp
4256 */
itemPixmapRect(const QRect & r,int flags,const QPixmap & pixmap) const4257 QRect QCleanlooksStyle::itemPixmapRect(const QRect &r, int flags, const QPixmap &pixmap) const
4258 {
4259 return QWindowsStyle::itemPixmapRect(r, flags, pixmap);
4260 }
4261
4262 /*!
4263 \reimp
4264 */
drawItemPixmap(QPainter * painter,const QRect & rect,int alignment,const QPixmap & pixmap) const4265 void QCleanlooksStyle::drawItemPixmap(QPainter *painter, const QRect &rect,
4266 int alignment, const QPixmap &pixmap) const
4267 {
4268 QWindowsStyle::drawItemPixmap(painter, rect, alignment, pixmap);
4269 }
4270
4271 /*!
4272 \reimp
4273 */
hitTestComplexControl(ComplexControl cc,const QStyleOptionComplex * opt,const QPoint & pt,const QWidget * w) const4274 QStyle::SubControl QCleanlooksStyle::hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt,
4275 const QPoint &pt, const QWidget *w) const
4276 {
4277 return QWindowsStyle::hitTestComplexControl(cc, opt, pt, w);
4278 }
4279
4280 /*!
4281 \reimp
4282 */
generatedIconPixmap(QIcon::Mode iconMode,const QPixmap & pixmap,const QStyleOption * opt) const4283 QPixmap QCleanlooksStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap,
4284 const QStyleOption *opt) const
4285 {
4286 return QWindowsStyle::generatedIconPixmap(iconMode, pixmap, opt);
4287 }
4288
4289 /*!
4290 \reimp
4291 */
styleHint(StyleHint hint,const QStyleOption * option,const QWidget * widget,QStyleHintReturn * returnData) const4292 int QCleanlooksStyle::styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget,
4293 QStyleHintReturn *returnData) const
4294 {
4295 int ret = 0;
4296 switch (hint) {
4297 case SH_ScrollBar_MiddleClickAbsolutePosition:
4298 ret = true;
4299 break;
4300 case SH_EtchDisabledText:
4301 ret = 1;
4302 break;
4303 case SH_Menu_AllowActiveAndDisabled:
4304 ret = false;
4305 break;
4306 case SH_MainWindow_SpaceBelowMenuBar:
4307 ret = 0;
4308 break;
4309 case SH_MenuBar_MouseTracking:
4310 ret = 1;
4311 break;
4312 case SH_TitleBar_AutoRaise:
4313 ret = 1;
4314 break;
4315 case SH_TitleBar_NoBorder:
4316 ret = 1;
4317 break;
4318 case SH_ItemView_ShowDecorationSelected:
4319 ret = true;
4320 break;
4321 case SH_Table_GridLineColor:
4322 if (option) {
4323 ret = option->palette.background().color().darker(120).rgb();
4324 break;
4325 }
4326 case SH_ComboBox_Popup:
4327 #ifdef QT3_SUPPORT
4328 if (widget && widget->inherits("Q3ComboBox"))
4329 return 0;
4330 #endif
4331 if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(option))
4332 ret = !cmb->editable;
4333 else
4334 ret = 0;
4335 break;
4336 case SH_WindowFrame_Mask:
4337 ret = 1;
4338 if (QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask *>(returnData)) {
4339 //left rounded corner
4340 mask->region = option->rect;
4341 mask->region -= QRect(option->rect.left(), option->rect.top(), 5, 1);
4342 mask->region -= QRect(option->rect.left(), option->rect.top() + 1, 3, 1);
4343 mask->region -= QRect(option->rect.left(), option->rect.top() + 2, 2, 1);
4344 mask->region -= QRect(option->rect.left(), option->rect.top() + 3, 1, 2);
4345
4346 //right rounded corner
4347 mask->region -= QRect(option->rect.right() - 4, option->rect.top(), 5, 1);
4348 mask->region -= QRect(option->rect.right() - 2, option->rect.top() + 1, 3, 1);
4349 mask->region -= QRect(option->rect.right() - 1, option->rect.top() + 2, 2, 1);
4350 mask->region -= QRect(option->rect.right() , option->rect.top() + 3, 1, 2);
4351 }
4352 break;
4353 case SH_MessageBox_TextInteractionFlags:
4354 ret = Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse;
4355 break;
4356 case SH_DialogButtonBox_ButtonsHaveIcons:
4357 ret = true;
4358 break;
4359 case SH_MessageBox_CenterButtons:
4360 ret = false;
4361 break;
4362 #ifndef QT_NO_WIZARD
4363 case SH_WizardStyle:
4364 ret = QWizard::ClassicStyle;
4365 break;
4366 #endif
4367 case SH_ItemView_ArrowKeysNavigateIntoChildren:
4368 ret = false;
4369 break;
4370 case SH_Menu_SubMenuPopupDelay:
4371 ret = 225; // default from GtkMenu
4372 break;
4373 default:
4374 ret = QWindowsStyle::styleHint(hint, option, widget, returnData);
4375 break;
4376 }
4377 return ret;
4378 }
4379
4380 /*! \reimp */
subElementRect(SubElement sr,const QStyleOption * opt,const QWidget * w) const4381 QRect QCleanlooksStyle::subElementRect(SubElement sr, const QStyleOption *opt, const QWidget *w) const
4382 {
4383 QRect r = QWindowsStyle::subElementRect(sr, opt, w);
4384 switch (sr) {
4385 case SE_PushButtonFocusRect:
4386 r.adjust(0, 1, 0, -1);
4387 break;
4388 case SE_DockWidgetTitleBarText: {
4389 const QStyleOptionDockWidgetV2 *v2
4390 = qstyleoption_cast<const QStyleOptionDockWidgetV2*>(opt);
4391 bool verticalTitleBar = v2 == 0 ? false : v2->verticalTitleBar;
4392 if (verticalTitleBar) {
4393 r.adjust(0, 0, 0, -4);
4394 } else {
4395 if (opt->direction == Qt::LeftToRight)
4396 r.adjust(4, 0, 0, 0);
4397 else
4398 r.adjust(0, 0, -4, 0);
4399 }
4400
4401 break;
4402 }
4403 case SE_ProgressBarContents:
4404 r = subElementRect(SE_ProgressBarGroove, opt, w);
4405 break;
4406 default:
4407 break;
4408 }
4409 return r;
4410 }
4411
4412 /*!
4413 \internal
4414 */
standardIconImplementation(StandardPixmap standardIcon,const QStyleOption * option,const QWidget * widget) const4415 QIcon QCleanlooksStyle::standardIconImplementation(StandardPixmap standardIcon,
4416 const QStyleOption *option,
4417 const QWidget *widget) const
4418 {
4419 return QWindowsStyle::standardIconImplementation(standardIcon, option, widget);
4420 }
4421
4422 /*!
4423 \reimp
4424 */
standardPixmap(StandardPixmap standardPixmap,const QStyleOption * opt,const QWidget * widget) const4425 QPixmap QCleanlooksStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt,
4426 const QWidget *widget) const
4427 {
4428 QPixmap pixmap;
4429
4430 #ifndef QT_NO_IMAGEFORMAT_XPM
4431 switch (standardPixmap) {
4432 case SP_TitleBarNormalButton:
4433 return QPixmap((const char **)dock_widget_restore_xpm);
4434 case SP_TitleBarMinButton:
4435 return QPixmap((const char **)workspace_minimize);
4436 case SP_TitleBarCloseButton:
4437 case SP_DockWidgetCloseButton:
4438 return QPixmap((const char **)dock_widget_close_xpm);
4439
4440 default:
4441 break;
4442 }
4443 #endif //QT_NO_IMAGEFORMAT_XPM
4444
4445 return QWindowsStyle::standardPixmap(standardPixmap, opt, widget);
4446 }
4447
4448 QT_END_NAMESPACE
4449
4450 #endif // QT_NO_STYLE_CLEANLOOKS || QT_PLUGIN
4451