Remove QWorkspace.
[qt:rb-qtbase.git] / src / widgets / styles / qcleanlooksstyle.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
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
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
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
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     \inmodule QtWidgets
597  
598     The Cleanlooks style provides a look and feel for widgets
599     that closely resembles the Clearlooks style, introduced by Richard
600     Stellingwerff and Daniel Borgmann.
601
602     \sa {Cleanlooks Style Widget Gallery}, QWindowsXPStyle, QMacStyle, QWindowsStyle,
603         QCDEStyle, QMotifStyle, QPlastiqueStyle
604 */
605
606 /*!
607     Constructs a QCleanlooksStyle object.
608 */
609 QCleanlooksStyle::QCleanlooksStyle() : QWindowsStyle(*new QCleanlooksStylePrivate)
610 {
611     setObjectName(QLatin1String("CleanLooks"));
612 }
613
614 /*!
615     \internal
616
617     Constructs a QCleanlooksStyle object.
618 */
619 QCleanlooksStyle::QCleanlooksStyle(QCleanlooksStylePrivate &dd) : QWindowsStyle(dd)
620 {
621 }
622
623 /*!
624     Destroys the QCleanlooksStyle object.
625 */
626 QCleanlooksStyle::~QCleanlooksStyle()
627 {
628 }
629
630 /*!
631     \fn void QCleanlooksStyle::drawItemText(QPainter *painter, const QRect &rectangle, int alignment, const QPalette &palette,
632                                     bool enabled, const QString& text, QPalette::ColorRole textRole) const
633
634     Draws the given \a text in the specified \a rectangle using the
635     provided \a painter and \a palette.
636
637     Text is drawn using the painter's pen. If an explicit \a textRole
638     is specified, then the text is drawn using the \a palette's color
639     for the specified role.  The \a enabled value indicates whether or
640     not the item is enabled; when reimplementing, this value should
641     influence how the item is drawn.
642
643     The text is aligned and wrapped according to the specified \a
644     alignment.
645
646     \sa Qt::Alignment
647 */
648 void QCleanlooksStyle::drawItemText(QPainter *painter, const QRect &rect, int alignment, const QPalette &pal,
649                                     bool enabled, const QString& text, QPalette::ColorRole textRole) const
650 {
651     if (text.isEmpty())
652         return;
653
654     QPen savedPen = painter->pen();
655     if (textRole != QPalette::NoRole) {
656         painter->setPen(QPen(pal.brush(textRole), savedPen.widthF()));
657     }
658     if (!enabled) {
659         QPen pen = painter->pen();
660         painter->setPen(pen);
661     }
662     painter->drawText(rect, alignment, text);
663     painter->setPen(savedPen);
664 }
665
666 static QColor mergedColors(const QColor &colorA, const QColor &colorB, int factor = 50)
667 {
668     const int maxFactor = 100;
669     QColor tmp = colorA;
670     tmp.setRed((tmp.red() * factor) / maxFactor + (colorB.red() * (maxFactor - factor)) / maxFactor);
671     tmp.setGreen((tmp.green() * factor) / maxFactor + (colorB.green() * (maxFactor - factor)) / maxFactor);
672     tmp.setBlue((tmp.blue() * factor) / maxFactor + (colorB.blue() * (maxFactor - factor)) / maxFactor);
673     return tmp;
674 }
675
676 /*!
677     \reimp
678 */
679 void QCleanlooksStyle::drawPrimitive(PrimitiveElement elem,
680                         const QStyleOption *option,
681                         QPainter *painter, const QWidget *widget) const
682 {
683     Q_ASSERT(option);
684     QRect rect = option->rect;
685     int state = option->state;
686     QColor button = option->palette.button().color();
687     QColor buttonShadow = option->palette.button().color().darker(110);
688     QColor buttonShadowAlpha = buttonShadow;
689     buttonShadowAlpha.setAlpha(128);
690     QColor darkOutline;
691     QColor dark;
692     darkOutline.setHsv(button.hue(),
693                 qMin(255, (int)(button.saturation()*3.0)),
694                 qMin(255, (int)(button.value()*0.6)));
695     dark.setHsv(button.hue(),
696                 qMin(255, (int)(button.saturation()*1.9)),
697                 qMin(255, (int)(button.value()*0.7)));
698     QColor tabFrameColor = mergedColors(option->palette.background().color(),
699                                                 dark.lighter(135), 60);
700
701     switch(elem) {
702 #ifndef QT_NO_TABBAR
703     case PE_FrameTabBarBase:
704         if (const QStyleOptionTabBarBase *tbb
705                 = qstyleoption_cast<const QStyleOptionTabBarBase *>(option)) {
706             painter->save();
707             painter->setPen(QPen(darkOutline.lighter(110), 0));
708             switch (tbb->shape) {
709             case QTabBar::RoundedNorth: {
710                 QRegion region(tbb->rect);
711                 region -= tbb->selectedTabRect;
712                 painter->drawLine(tbb->rect.topLeft(), tbb->rect.topRight());
713                 painter->setClipRegion(region);
714                 painter->setPen(option->palette.light().color());
715                 painter->drawLine(tbb->rect.topLeft() + QPoint(0, 1),
716                                   tbb->rect.topRight()  + QPoint(0, 1));
717             }
718                 break;
719             case QTabBar::RoundedWest:
720                 painter->drawLine(tbb->rect.left(), tbb->rect.top(), tbb->rect.left(), tbb->rect.bottom());
721                 break;
722             case QTabBar::RoundedSouth:
723                 painter->drawLine(tbb->rect.left(), tbb->rect.bottom(),
724                             tbb->rect.right(), tbb->rect.bottom());
725                 break;
726             case QTabBar::RoundedEast:
727                 painter->drawLine(tbb->rect.topRight(), tbb->rect.bottomRight());
728                 break;
729             case QTabBar::TriangularNorth:
730             case QTabBar::TriangularEast:
731             case QTabBar::TriangularWest:
732             case QTabBar::TriangularSouth:
733                 painter->restore();
734                 QWindowsStyle::drawPrimitive(elem, option, painter, widget);
735                 return;
736             }
737             painter->restore();
738         }
739         return;
740 #endif // QT_NO_TABBAR
741     case PE_IndicatorViewItemCheck:
742         {
743             QStyleOptionButton button;
744             button.QStyleOption::operator=(*option);
745             button.state &= ~State_MouseOver;
746             proxy()->drawPrimitive(PE_IndicatorCheckBox, &button, painter, widget);
747         }
748         return;
749     case PE_IndicatorHeaderArrow:
750         if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
751             QRect r = header->rect;
752             QImage arrow;
753             if (header->sortIndicator & QStyleOptionHeader::SortUp)
754                 arrow = QImage(qt_cleanlooks_arrow_up_xpm);
755             else if (header->sortIndicator & QStyleOptionHeader::SortDown)
756                 arrow = QImage(qt_cleanlooks_arrow_down_xpm);
757             if (!arrow.isNull()) {
758                 r.setSize(arrow.size());
759                 r.moveCenter(header->rect.center());
760                 arrow.setColor(1, header->palette.foreground().color().rgba());
761                 painter->drawImage(r, arrow);
762             }
763         }
764         break;
765     case PE_IndicatorButtonDropDown:
766         proxy()->drawPrimitive(PE_PanelButtonCommand, option, painter, widget);
767         break;
768     case PE_IndicatorToolBarSeparator:
769         {
770             QRect rect = option->rect;
771             const int margin = 6;
772             if (option->state & State_Horizontal) {
773                 const int offset = rect.width()/2;
774                 painter->setPen(QPen(option->palette.background().color().darker(110)));
775                 painter->drawLine(rect.bottomLeft().x() + offset,
776                             rect.bottomLeft().y() - margin,
777                             rect.topLeft().x() + offset,
778                             rect.topLeft().y() + margin);
779                 painter->setPen(QPen(option->palette.background().color().lighter(110)));
780                 painter->drawLine(rect.bottomLeft().x() + offset + 1,
781                             rect.bottomLeft().y() - margin,
782                             rect.topLeft().x() + offset + 1,
783                             rect.topLeft().y() + margin);
784             } else { //Draw vertical separator
785                 const int offset = rect.height()/2;
786                 painter->setPen(QPen(option->palette.background().color().darker(110)));
787                 painter->drawLine(rect.topLeft().x() + margin ,
788                             rect.topLeft().y() + offset,
789                             rect.topRight().x() - margin,
790                             rect.topRight().y() + offset);
791                 painter->setPen(QPen(option->palette.background().color().lighter(110)));
792                 painter->drawLine(rect.topLeft().x() + margin ,
793                             rect.topLeft().y() + offset + 1,
794                             rect.topRight().x() - margin,
795                             rect.topRight().y() + offset + 1);
796             }
797         }
798         break;
799     case PE_Frame:
800         painter->save();
801         painter->setPen(dark.lighter(108));
802         painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
803         painter->restore();
804         break;
805     case PE_FrameMenu:
806         painter->save();
807         {
808             painter->setPen(QPen(darkOutline, 1));
809             painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
810             QColor frameLight = option->palette.background().color().lighter(160);
811             QColor frameShadow = option->palette.background().color().darker(110);
812
813             //paint beveleffect
814             QRect frame = option->rect.adjusted(1, 1, -1, -1);
815             painter->setPen(frameLight);
816             painter->drawLine(frame.topLeft(), frame.bottomLeft());
817             painter->drawLine(frame.topLeft(), frame.topRight());
818
819             painter->setPen(frameShadow);
820             painter->drawLine(frame.topRight(), frame.bottomRight());
821             painter->drawLine(frame.bottomLeft(), frame.bottomRight());
822         }
823         painter->restore();
824         break;
825     case PE_FrameDockWidget:
826
827         painter->save();
828         {
829             QColor softshadow = option->palette.background().color().darker(120);
830
831             QRect rect= option->rect;
832             painter->setPen(softshadow);
833             painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
834             painter->setPen(QPen(option->palette.light(), 0));
835             painter->drawLine(QPoint(rect.left() + 1, rect.top() + 1), QPoint(rect.left() + 1, rect.bottom() - 1));
836             painter->setPen(QPen(option->palette.background().color().darker(120), 0));
837             painter->drawLine(QPoint(rect.left() + 1, rect.bottom() - 1), QPoint(rect.right() - 2, rect.bottom() - 1));
838             painter->drawLine(QPoint(rect.right() - 1, rect.top() + 1), QPoint(rect.right() - 1, rect.bottom() - 1));
839
840         }
841         painter->restore();
842         break;
843     case PE_PanelButtonTool:
844         painter->save();
845         if ((option->state & State_Enabled || option->state & State_On) || !(option->state & State_AutoRaise)) {
846             QPen oldPen = painter->pen();
847
848             if (widget && widget->inherits("QDockWidgetTitleButton")) {
849                    if (option->state & State_MouseOver)
850                        proxy()->drawPrimitive(PE_PanelButtonCommand, option, painter, widget);
851             } else {
852                 proxy()->drawPrimitive(PE_PanelButtonCommand, option, painter, widget);
853             }
854         }
855         painter->restore();
856         break;
857     case PE_IndicatorDockWidgetResizeHandle:
858         {
859             QStyleOption dockWidgetHandle = *option;
860             bool horizontal = option->state & State_Horizontal;
861             if (horizontal)
862                 dockWidgetHandle.state &= ~State_Horizontal;
863             else
864                 dockWidgetHandle.state |= State_Horizontal;
865             proxy()->drawControl(CE_Splitter, &dockWidgetHandle, painter, widget);
866         }
867         break;
868     case PE_FrameWindow:
869         painter->save();
870         {
871             QRect rect= option->rect;
872             painter->setPen(QPen(dark.darker(150), 0));
873             painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
874             painter->setPen(QPen(option->palette.light(), 0));
875             painter->drawLine(QPoint(rect.left() + 1, rect.top() + 1),
876                               QPoint(rect.left() + 1, rect.bottom() - 1));
877             painter->setPen(QPen(option->palette.background().color().darker(120), 0));
878             painter->drawLine(QPoint(rect.left() + 1, rect.bottom() - 1),
879                               QPoint(rect.right() - 2, rect.bottom() - 1));
880             painter->drawLine(QPoint(rect.right() - 1, rect.top() + 1),
881                               QPoint(rect.right() - 1, rect.bottom() - 1));
882         }
883         painter->restore();
884         break;
885 #ifndef QT_NO_LINEEDIT
886     case PE_FrameLineEdit:
887         // fall through
888 #endif // QT_NO_LINEEDIT
889         {
890             QPen oldPen = painter->pen();
891             if (option->state & State_Enabled) {
892                 painter->setPen(QPen(option->palette.background(), 0));
893                 painter->drawRect(rect.adjusted(0, 0, 0, 0));
894                 painter->drawRect(rect.adjusted(1, 1, -1, -1));
895             } else {
896                 painter->fillRect(rect, option->palette.background());
897             }
898             QRect r = rect.adjusted(0, 1, 0, -1);
899             painter->setPen(buttonShadowAlpha);
900             painter->drawLine(QPoint(r.left() + 2, r.top() - 1), QPoint(r.right() - 2, r.top() - 1));
901             const QPoint points[8] = {
902                 QPoint(r.right() - 1, r.top()),
903                 QPoint(r.right(), r.top() + 1),
904                 QPoint(r.right() - 1, r.bottom()),
905                 QPoint(r.right(), r.bottom() - 1),
906                 QPoint(r.left() + 1, r.top() ),
907                 QPoint(r.left(), r.top() + 1),
908                 QPoint(r.left() + 1, r.bottom() ),
909                 QPoint(r.left(), r.bottom() - 1)
910             };
911             painter->drawPoints(points, 8);
912             painter->setPen(QPen(option->palette.background().color(), 1));
913             painter->drawLine(QPoint(r.left() + 2, r.top() + 1), QPoint(r.right() - 2, r.top() + 1));
914
915             if (option->state & State_HasFocus) {
916                 QColor darkoutline = option->palette.highlight().color().darker(150);
917                 QColor innerline = mergedColors(option->palette.highlight().color(), Qt::white);
918                 painter->setPen(QPen(innerline, 0));
919                 painter->drawRect(rect.adjusted(1, 2, -2, -3));
920                 painter->setPen(QPen(darkoutline, 0));
921             }
922             else {
923                 QColor highlight = Qt::white;
924                 highlight.setAlpha(130);
925                 painter->setPen(option->palette.base().color().darker(120));
926                 painter->drawLine(QPoint(r.left() + 1, r.top() + 1),
927                                   QPoint(r.right() - 1, r.top() + 1));
928                 painter->drawLine(QPoint(r.left() + 1, r.top() + 1),
929                                   QPoint(r.left() + 1, r.bottom() - 1));
930                 painter->setPen(option->palette.base().color());
931                 painter->drawLine(QPoint(r.right() - 1, r.top() + 1),
932                                   QPoint(r.right() - 1, r.bottom() - 1));
933                 painter->setPen(highlight);
934                 painter->drawLine(QPoint(r.left() + 1, r.bottom() + 1),
935                                   QPoint(r.right() - 1, r.bottom() + 1));
936                 painter->drawPoint(QPoint(r.left(), r.bottom()));
937                 painter->drawPoint(QPoint(r.right(), r.bottom() ));
938                 painter->setPen(QPen(darkOutline.lighter(115), 1));
939             }
940             painter->drawLine(QPoint(r.left(), r.top() + 2), QPoint(r.left(), r.bottom() - 2));
941             painter->drawLine(QPoint(r.right(), r.top() + 2), QPoint(r.right(), r.bottom() - 2));
942             painter->drawLine(QPoint(r.left() + 2, r.bottom()), QPoint(r.right() - 2, r.bottom()));
943             const QPoint points2[4] = {
944                 QPoint(r.right() - 1, r.bottom() - 1),
945                 QPoint(r.right() - 1, r.top() + 1),
946                 QPoint(r.left() + 1, r.bottom() - 1),
947                 QPoint(r.left() + 1, r.top() + 1)
948             };
949             painter->drawPoints(points2, 4);
950             painter->drawLine(QPoint(r.left() + 2, r.top()), QPoint(r.right() - 2, r.top()));
951             painter->setPen(oldPen);
952         }
953         break;
954     case PE_IndicatorCheckBox:
955         painter->save();
956         if (const QStyleOptionButton *checkbox = qstyleoption_cast<const QStyleOptionButton*>(option)) {
957             QRect checkRect;
958             checkRect.setX(rect.left() );
959             checkRect.setY(rect.top() );
960             checkRect.setWidth(rect.width() - 1);
961             checkRect.setHeight(rect.height() - 1);
962             if (state & State_Sunken)
963                 painter->setBrush(dark.lighter(130));
964             else
965                 painter->setBrush(option->palette.base());
966             painter->setPen(QPen(dark.lighter(110), 0));
967             painter->drawRect(checkRect);
968             if (checkbox->state & (State_On | State_Sunken  | State_NoChange)) {
969                 QImage image(qt_cleanlooks_checkbox_checked);
970                 QColor fillColor = option->palette.text().color();
971                 image.setColor(1, fillColor.rgba()); 
972                 fillColor.setAlpha(100);
973                 image.setColor(2, fillColor.rgba()); 
974                 painter->drawImage(rect, image);
975                 if (checkbox->state & State_NoChange) {
976                     QColor bgc = option->palette.background().color();
977                     bgc.setAlpha(127);
978                     painter->fillRect(checkRect.adjusted(1, 1, -1, -1), bgc);
979                 }
980             }
981         }
982         painter->restore();
983         break;
984     case PE_IndicatorRadioButton:
985         painter->save();
986         {
987             painter->setRenderHint(QPainter::SmoothPixmapTransform);
988             QRect checkRect = rect.adjusted(0, 0, 0, 0);
989             if (state & (State_On )) {
990                 painter->drawImage(rect, QImage(qt_cleanlooks_radiobutton));
991                 painter->drawImage(checkRect, QImage(qt_cleanlooks_radiobutton_checked));
992             }
993             else if (state & State_Sunken) {
994                 painter->drawImage(rect, QImage(qt_cleanlooks_radiobutton));
995                 QColor bgc = buttonShadow;
996                 painter->setRenderHint(QPainter::Antialiasing);
997                 painter->setBrush(bgc);
998                 painter->setPen(Qt::NoPen);
999                 painter->drawEllipse(rect.adjusted(1, 1, -1, -1));                }
1000             else {
1001                 painter->drawImage(rect, QImage(qt_cleanlooks_radiobutton));
1002             }
1003         }
1004         painter->restore();
1005     break;
1006     case PE_IndicatorToolBarHandle:
1007         painter->save();
1008         if (option->state & State_Horizontal) {
1009             for (int i = rect.height()/5; i <= 4*(rect.height()/5) ; ++i) {
1010                 int y = rect.topLeft().y() + i + 1;
1011                 int x1 = rect.topLeft().x() + 3;
1012                 int x2 = rect.topRight().x() - 2;
1013
1014                 if (i % 2 == 0)
1015                     painter->setPen(QPen(option->palette.light(), 0));
1016                 else
1017                     painter->setPen(QPen(dark.lighter(110), 0));
1018                 painter->drawLine(x1, y, x2, y);
1019             }
1020         }
1021         else { //vertical toolbar
1022             for (int i = rect.width()/5; i <= 4*(rect.width()/5) ; ++i) {
1023                 int x = rect.topLeft().x() + i + 1;
1024                 int y1 = rect.topLeft().y() + 3;
1025                 int y2 = rect.topLeft().y() + 5;
1026
1027                 if (i % 2 == 0)
1028                     painter->setPen(QPen(option->palette.light(), 0));
1029                 else
1030                     painter->setPen(QPen(dark.lighter(110), 0));
1031                 painter->drawLine(x, y1, x, y2);
1032             }
1033         }
1034         painter->restore();
1035         break;
1036     case PE_FrameDefaultButton:
1037         case PE_FrameFocusRect:
1038         if (const QStyleOptionFocusRect *focusFrame = qstyleoption_cast<const QStyleOptionFocusRect *>(option)) {
1039             if (!(focusFrame->state & State_KeyboardFocusChange))
1040                 return;
1041             QRect rect = focusFrame->rect;
1042             painter->save();
1043             painter->setBackgroundMode(Qt::TransparentMode);
1044             painter->setBrush(QBrush(dark.darker(120), Qt::Dense4Pattern));
1045             painter->setBrushOrigin(rect.topLeft());
1046             painter->setPen(Qt::NoPen);
1047             const QRect rects[4] = {
1048                 QRect(rect.left(), rect.top(), rect.width(), 1),    // Top
1049                 QRect(rect.left(), rect.bottom(), rect.width(), 1), // Bottom
1050                 QRect(rect.left(), rect.top(), 1, rect.height()),   // Left
1051                 QRect(rect.right(), rect.top(), 1, rect.height())   // Right
1052             };
1053             painter->drawRects(rects, 4);
1054             painter->restore();
1055         }
1056         break;
1057     case PE_PanelButtonCommand:
1058         {
1059             bool isDefault = false;
1060             bool isFlat = false;
1061             bool isDown = (option->state & State_Sunken) || (option->state & State_On);
1062             QPen oldPen = painter->pen();
1063             QBrush oldBrush = painter->brush();
1064             QRect r;
1065
1066             if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton*>(option)) {
1067                 isDefault = (button->features & QStyleOptionButton::DefaultButton) && (button->state & State_Enabled);
1068                 isFlat = (button->features & QStyleOptionButton::Flat);
1069             }
1070
1071             if (isFlat && !isDown) {
1072                 if (isDefault) {
1073                     r = option->rect.adjusted(0, 1, 0, -1);
1074                     painter->setPen(QPen(Qt::black, 0));
1075                     const QLine lines[4] = {
1076                         QLine(QPoint(r.left() + 2, r.top()),
1077                               QPoint(r.right() - 2, r.top())),
1078                         QLine(QPoint(r.left(), r.top() + 2),
1079                               QPoint(r.left(), r.bottom() - 2)),
1080                         QLine(QPoint(r.right(), r.top() + 2),
1081                               QPoint(r.right(), r.bottom() - 2)),
1082                         QLine(QPoint(r.left() + 2, r.bottom()),
1083                               QPoint(r.right() - 2, r.bottom()))
1084                     };
1085                     painter->drawLines(lines, 4);
1086                     const QPoint points[4] = {
1087                         QPoint(r.right() - 1, r.bottom() - 1),
1088                         QPoint(r.right() - 1, r.top() + 1),
1089                         QPoint(r.left() + 1, r.bottom() - 1),
1090                         QPoint(r.left() + 1, r.top() + 1)
1091                     };
1092                     painter->drawPoints(points, 4);
1093                     painter->setPen(oldPen);
1094                 }
1095                 return;
1096             }
1097
1098             BEGIN_STYLE_PIXMAPCACHE(QString::fromLatin1("pushbutton-%1").arg(isDefault))
1099             r = rect.adjusted(0, 1, 0, -1);
1100
1101             bool isEnabled = (option->state & State_Enabled);
1102
1103             QColor highlightedGradientStartColor = option->palette.button().color().lighter(107);
1104             QColor highlightedGradientMidColor = option->palette.button().color().lighter(105);
1105             QColor highlightedGradientStopColor = buttonShadow.lighter(107);
1106             QColor gradientStartColor = option->palette.button().color().lighter(108);
1107
1108             QColor buttonColor = option->palette.button().color();
1109             QColor gradientMidColor = option->palette.button().color();
1110             QColor gradientStopColor;
1111             gradientStopColor.setHsv(buttonColor.hue(),
1112                                      qMin(255, (int)(buttonColor.saturation()*1.9)),
1113                                      qMin(255, (int)(buttonColor.value()*0.96)));
1114
1115             QRect gradRect = rect.adjusted(1, 2, -1, -2);
1116             // gradient fill
1117             QRect innerBorder = r.adjusted(1, 1, -1, 0);
1118
1119             if (isDown) {
1120                 QBrush fillColor = gradientStopColor.darker(110);
1121                 if (option->palette.button().gradient())
1122                     fillColor = option->palette.button();
1123                 p->fillRect(gradRect, fillColor);
1124                 p->setPen(gradientStopColor.darker(125));
1125                 p->drawLine(innerBorder.topLeft(), innerBorder.topRight());
1126                 p->drawLine(innerBorder.topLeft(), innerBorder.bottomLeft());
1127             } else {
1128                 if (isEnabled && option->state & State_MouseOver ) {
1129                     qt_cleanlooks_draw_buttongradient(p, gradRect,
1130                                                 highlightedGradientStartColor,
1131                                                 highlightedGradientMidColor,
1132                                                 highlightedGradientStopColor, TopDown, option->palette.button());
1133                 } else {
1134                     qt_cleanlooks_draw_buttongradient(p, gradRect,
1135                                                 gradientStartColor,
1136                                                 gradientMidColor,
1137                                                 gradientStopColor, TopDown, option->palette.button());
1138                 }
1139             }
1140
1141             bool hasFocus = option->state & State_HasFocus;
1142
1143             if (!isEnabled)
1144                 p->setPen(QPen(dark.lighter(115)));
1145             else if (isDefault)
1146                 p->setPen(QPen(Qt::black, 1));
1147             else
1148                 p->setPen(QPen(darkOutline, 1));
1149
1150             p->drawLine(QPoint(r.left(), r.top() + 2),
1151                               QPoint(r.left(), r.bottom() - 2));
1152             p->drawLine(QPoint(r.right(), r.top() + 2),
1153                               QPoint(r.right(), r.bottom() - 2));
1154             p->drawLine(QPoint(r.left() + 2, r.bottom()),
1155                               QPoint(r.right() - 2, r.bottom()));
1156             const QPoint points[4] = {
1157                 QPoint(r.right() - 1, r.bottom() - 1),
1158                 QPoint(r.right() - 1, r.top() + 1),
1159                 QPoint(r.left() + 1, r.bottom() - 1),
1160                 QPoint(r.left() + 1, r.top() + 1)
1161             };
1162             p->drawPoints(points, 4);
1163
1164             if (!isDefault && !hasFocus && isEnabled)
1165                 p->setPen(QPen(darkOutline.darker(110), 0));
1166
1167             p->drawLine(QPoint(r.left() + 2, r.top()),
1168                               QPoint(r.right() - 2, r.top()));
1169
1170             QColor highlight = Qt::white;
1171             highlight.setAlpha(110);
1172             p->setPen(highlight);
1173             p->drawLine(QPoint(r.left() + 1, r.top() + 2),
1174                               QPoint(r.left() + 1, r.bottom() - 2));
1175             p->drawLine(QPoint(r.left() + 3, r.bottom() + 1),
1176                               QPoint(r.right() - 3, r.bottom() + 1));
1177
1178             QColor topShadow = darkOutline;
1179             topShadow.setAlpha(60);
1180
1181             p->setPen(topShadow);
1182             const QPoint points2[8] = {
1183                 QPoint(r.right(), r.top() + 1),
1184                 QPoint(r.right() - 1, r.top() ),
1185                 QPoint(r.right(), r.bottom() - 1),
1186                 QPoint(r.right() - 1, r.bottom() ),
1187                 QPoint(r.left() + 1, r.bottom()),
1188                 QPoint(r.left(), r.bottom() - 1),
1189                 QPoint(r.left() + 1, r.top()),
1190                 QPoint(r.left(), r.top() + 1)
1191             };
1192             p->drawPoints(points2, 8);
1193
1194             topShadow.setAlpha(30);
1195             p->setPen(topShadow);
1196
1197             p->drawLine(QPoint(r.right() - 1, r.top() + 2),
1198                               QPoint(r.right() - 1, r.bottom() - 2));
1199             p->drawLine(QPoint(r.left() + 2, r.top() - 1),
1200                               QPoint(r.right() - 2, r.top() - 1));
1201
1202             if (isDefault) {
1203                 r.adjust(-1, -1, 1, 1);
1204                 p->setPen(buttonShadowAlpha.darker(120));
1205                 const QLine lines[4] = {
1206                     QLine(r.topLeft() + QPoint(3, 0), r.topRight() - QPoint(3, 0)),
1207                     QLine(r.bottomLeft() + QPoint(3, 0), r.bottomRight() - QPoint(3, 0)),
1208                     QLine(r.topLeft() + QPoint(0, 3), r.bottomLeft() - QPoint(0, 3)),
1209                     QLine(r.topRight() + QPoint(0, 3), r.bottomRight() - QPoint(0, 3))
1210                 };
1211                 p->drawLines(lines, 4);
1212                 const QPoint points3[8] = {
1213                     r.topRight() + QPoint(-2, 1),
1214                     r.topRight() + QPoint(-1, 2),
1215                     r.bottomRight() + QPoint(-1, -2),
1216                     r.bottomRight() + QPoint(-2, -1),
1217                     r.topLeft() + QPoint(1, 2),
1218                     r.topLeft() + QPoint(2, 1),
1219                     r.bottomLeft() + QPoint(1, -2),
1220                     r.bottomLeft() + QPoint(2, -1)
1221                 };
1222                 p->drawPoints(points3, 8);
1223             }
1224             painter->setPen(oldPen);
1225             painter->setBrush(oldBrush);
1226             END_STYLE_PIXMAPCACHE
1227         }
1228         break;
1229 #ifndef QT_NO_TABBAR
1230         case PE_FrameTabWidget:
1231             painter->save();
1232         {
1233             painter->fillRect(option->rect, tabFrameColor);
1234         }
1235 #ifndef QT_NO_TABWIDGET
1236         if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(option)) {
1237             QColor borderColor = darkOutline.lighter(110);
1238             QColor alphaCornerColor = mergedColors(borderColor, option->palette.background().color());
1239
1240             int borderThickness = proxy()->pixelMetric(PM_TabBarBaseOverlap, twf, widget);
1241             bool reverse = (twf->direction == Qt::RightToLeft);
1242             QRect tabBarRect;
1243
1244             switch (twf->shape) {
1245             case QTabBar::RoundedNorth:
1246                 if (reverse) {
1247                     tabBarRect = QRect(twf->rect.right() - twf->leftCornerWidgetSize.width()
1248                                        - twf->tabBarSize.width() + 1,
1249                                        twf->rect.top(),
1250                                        twf->tabBarSize.width(), borderThickness);
1251                 } else {
1252                     tabBarRect = QRect(twf->rect.left() + twf->leftCornerWidgetSize.width(),
1253                                        twf->rect.top(),
1254                                        twf->tabBarSize.width(), borderThickness);
1255                 }
1256                 break ;
1257             case QTabBar::RoundedWest:
1258                 tabBarRect = QRect(twf->rect.left(),
1259                                    twf->rect.top() + twf->leftCornerWidgetSize.height(),
1260                                    borderThickness,
1261                                    twf->tabBarSize.height());
1262                 tabBarRect = tabBarRect; //adjust
1263                 break ;
1264             case QTabBar::RoundedEast:
1265                 tabBarRect = QRect(twf->rect.right() - borderThickness + 1,
1266                                    twf->rect.top()  + twf->leftCornerWidgetSize.height(),
1267                                    0,
1268                                    twf->tabBarSize.height());
1269                 break ;
1270             case QTabBar::RoundedSouth:
1271                 if (reverse) {
1272                     tabBarRect = QRect(twf->rect.right() - twf->leftCornerWidgetSize.width() - twf->tabBarSize.width() + 1,
1273                                        twf->rect.bottom() + 1,
1274                                        twf->tabBarSize.width(),
1275                                        borderThickness);
1276                 } else {
1277                     tabBarRect = QRect(twf->rect.left() + twf->leftCornerWidgetSize.width(),
1278                                        twf->rect.bottom() + 1,
1279                                        twf->tabBarSize.width(),
1280                                        borderThickness);
1281                 }
1282                 break;
1283             default:
1284                 break;
1285             }
1286
1287             QRegion region(twf->rect);
1288             region -= tabBarRect;
1289             painter->setClipRegion(region);
1290
1291             // Outer border
1292             QLine leftLine = QLine(twf->rect.topLeft() + QPoint(0, 2), twf->rect.bottomLeft() - QPoint(0, 2));
1293             QLine rightLine = QLine(twf->rect.topRight(), twf->rect.bottomRight() - QPoint(0, 2));
1294             QLine bottomLine = QLine(twf->rect.bottomLeft() + QPoint(2, 0), twf->rect.bottomRight() - QPoint(2, 0));
1295             QLine topLine = QLine(twf->rect.topLeft(), twf->rect.topRight());
1296
1297             painter->setPen(borderColor);
1298             painter->drawLine(topLine);
1299
1300             // Inner border
1301             QLine innerLeftLine = QLine(leftLine.p1() + QPoint(1, 0), leftLine.p2() + QPoint(1, 0));
1302             QLine innerRightLine = QLine(rightLine.p1() - QPoint(1, -1), rightLine.p2() - QPoint(1, 0));
1303             QLine innerBottomLine = QLine(bottomLine.p1() - QPoint(0, 1), bottomLine.p2() - QPoint(0, 1));
1304             QLine innerTopLine = QLine(topLine.p1() + QPoint(0, 1), topLine.p2() + QPoint(-1, 1));
1305
1306             // Rounded Corner
1307             QPoint leftBottomOuterCorner = QPoint(innerLeftLine.p2() + QPoint(0, 1));
1308             QPoint leftBottomInnerCorner1 = QPoint(leftLine.p2() + QPoint(0, 1));
1309             QPoint leftBottomInnerCorner2 = QPoint(bottomLine.p1() - QPoint(1, 0));
1310             QPoint rightBottomOuterCorner = QPoint(innerRightLine.p2() + QPoint(0, 1));
1311             QPoint rightBottomInnerCorner1 = QPoint(rightLine.p2() + QPoint(0, 1));
1312             QPoint rightBottomInnerCorner2 = QPoint(bottomLine.p2() + QPoint(1, 0));
1313             QPoint leftTopOuterCorner = QPoint(innerLeftLine.p1() - QPoint(0, 1));
1314             QPoint leftTopInnerCorner1 = QPoint(leftLine.p1() - QPoint(0, 1));
1315             QPoint leftTopInnerCorner2 = QPoint(topLine.p1() - QPoint(1, 0));
1316
1317             painter->setPen(borderColor);
1318             painter->drawLine(leftLine);
1319             painter->drawLine(rightLine);
1320             painter->drawLine(bottomLine);
1321             painter->drawPoint(leftBottomOuterCorner);
1322             painter->drawPoint(rightBottomOuterCorner);
1323             painter->drawPoint(leftTopOuterCorner);
1324
1325             painter->setPen(option->palette.light().color());
1326             painter->drawLine(innerLeftLine);
1327             painter->drawLine(innerTopLine);
1328
1329             painter->setPen(buttonShadowAlpha);
1330             painter->drawLine(innerRightLine);
1331             painter->drawLine(innerBottomLine);
1332
1333             painter->setPen(alphaCornerColor);
1334             const QPoint points[6] = {
1335                 leftBottomInnerCorner1,
1336                 leftBottomInnerCorner2,
1337                 rightBottomInnerCorner1,
1338                 rightBottomInnerCorner2,
1339                 leftTopInnerCorner1,
1340                 leftTopInnerCorner2
1341             };
1342             painter->drawPoints(points, 6);
1343         }
1344 #endif // QT_NO_TABWIDGET
1345     painter->restore();
1346     break ;
1347
1348     case PE_FrameStatusBarItem:
1349         break;
1350     case PE_IndicatorTabClose:
1351         {
1352             Q_D(const QCleanlooksStyle);
1353             if (d->tabBarcloseButtonIcon.isNull())
1354                 d->tabBarcloseButtonIcon = standardIcon(SP_DialogCloseButton, option, widget);
1355             if ((option->state & State_Enabled) && (option->state & State_MouseOver))
1356                 proxy()->drawPrimitive(PE_PanelButtonCommand, option, painter, widget);
1357             QPixmap pixmap = d->tabBarcloseButtonIcon.pixmap(QSize(16, 16), QIcon::Normal, QIcon::On);
1358             proxy()->drawItemPixmap(painter, option->rect, Qt::AlignCenter, pixmap);
1359         }
1360         break;
1361
1362 #endif // QT_NO_TABBAR
1363     default:
1364         QWindowsStyle::drawPrimitive(elem, option, painter, widget);
1365         break;
1366     }
1367 }
1368
1369 /*!
1370   \reimp
1371 */
1372 void QCleanlooksStyle::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter,
1373                                    const QWidget *widget) const
1374 {
1375     QColor button = option->palette.button().color();
1376     QColor dark;
1377     dark.setHsv(button.hue(),
1378                 qMin(255, (int)(button.saturation()*1.9)),
1379                 qMin(255, (int)(button.value()*0.7)));
1380     QColor darkOutline;
1381     darkOutline.setHsv(button.hue(),
1382                 qMin(255, (int)(button.saturation()*2.0)),
1383                 qMin(255, (int)(button.value()*0.6)));
1384     QRect rect = option->rect;
1385     QColor shadow = mergedColors(option->palette.background().color().darker(120),
1386                                  dark.lighter(130), 60);
1387     QColor tabFrameColor = mergedColors(option->palette.background().color(),
1388                                                 dark.lighter(135), 60);
1389
1390     QColor highlight = option->palette.highlight().color();
1391
1392     switch(element) {
1393      case CE_RadioButton: //fall through
1394      case CE_CheckBox:
1395         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
1396             bool hover = (btn->state & State_MouseOver && btn->state & State_Enabled);
1397             if (hover)
1398                 painter->fillRect(rect, btn->palette.background().color().lighter(104));
1399             QStyleOptionButton copy = *btn;
1400             copy.rect.adjust(2, 0, -2, 0);
1401             QWindowsStyle::drawControl(element, &copy, painter, widget);
1402         }
1403         break;
1404     case CE_Splitter:
1405         painter->save();
1406         {
1407             // hover appearance
1408             QBrush fillColor = option->palette.background().color();
1409             if (option->state & State_MouseOver && option->state & State_Enabled)
1410                 fillColor = fillColor.color().lighter(106);
1411
1412             painter->fillRect(option->rect, fillColor);
1413
1414             QColor grooveColor = mergedColors(dark.lighter(110), option->palette.button().color(),40);
1415             QColor gripShadow = grooveColor.darker(110);
1416             QPalette palette = option->palette;
1417             bool vertical = !(option->state & State_Horizontal);
1418             QRect scrollBarSlider = option->rect;
1419             int gripMargin = 4;
1420             //draw grips
1421             if (vertical) {
1422                 for( int i = -20; i< 20 ; i += 2) {
1423                     painter->setPen(QPen(gripShadow, 1));
1424                     painter->drawLine(
1425                         QPoint(scrollBarSlider.center().x() + i ,
1426                                scrollBarSlider.top() + gripMargin),
1427                         QPoint(scrollBarSlider.center().x() + i,
1428                                scrollBarSlider.bottom() - gripMargin));
1429                     painter->setPen(QPen(palette.light(), 1));
1430                     painter->drawLine(
1431                         QPoint(scrollBarSlider.center().x() + i + 1,
1432                                scrollBarSlider.top() + gripMargin  ),
1433                         QPoint(scrollBarSlider.center().x() + i + 1,
1434                                scrollBarSlider.bottom() - gripMargin));
1435                 }
1436             } else {
1437                 for (int i = -20; i < 20 ; i += 2) {
1438                     painter->setPen(QPen(gripShadow, 1));
1439                     painter->drawLine(
1440                         QPoint(scrollBarSlider.left() + gripMargin ,
1441                                scrollBarSlider.center().y()+ i),
1442                         QPoint(scrollBarSlider.right() - gripMargin,
1443                                scrollBarSlider.center().y()+ i));
1444                     painter->setPen(QPen(palette.light(), 1));
1445                     painter->drawLine(
1446                         QPoint(scrollBarSlider.left() + gripMargin,
1447                                scrollBarSlider.center().y() + 1 + i),
1448                         QPoint(scrollBarSlider.right() - gripMargin,
1449                                scrollBarSlider.center().y() + 1 + i));
1450
1451                 }
1452             }
1453         }
1454         painter->restore();
1455         break;
1456 #ifndef QT_NO_SIZEGRIP
1457     case CE_SizeGrip:
1458         painter->save();
1459         {
1460             int x, y, w, h;
1461             option->rect.getRect(&x, &y, &w, &h);
1462             int sw = qMin(h, w);
1463             if (h > w)
1464                 painter->translate(0, h - w);
1465             else
1466                 painter->translate(w - h, 0);
1467
1468             int sx = x;
1469             int sy = y;
1470             int s = 4;
1471             if (option->direction == Qt::RightToLeft) {
1472                 sx = x + sw;
1473                 for (int i = 0; i < 4; ++i) {
1474                     painter->setPen(QPen(option->palette.light().color(), 1));
1475                     painter->drawLine(x, sy - 1 , sx + 1, sw);
1476                     painter->setPen(QPen(dark.lighter(120), 1));
1477                     painter->drawLine(x, sy, sx, sw);
1478                     sx -= s;
1479                     sy += s;
1480                 }
1481             } else {
1482                 for (int i = 0; i < 4; ++i) {
1483                     painter->setPen(QPen(option->palette.light().color(), 1));
1484                     painter->drawLine(sx - 1, sw, sw, sy - 1);
1485                     painter->setPen(QPen(dark.lighter(120), 1));
1486                     painter->drawLine(sx, sw, sw, sy);
1487                     sx += s;
1488                     sy += s;
1489                 }
1490             }
1491         }
1492         painter->restore();
1493         break;
1494 #endif // QT_NO_SIZEGRIP
1495 #ifndef QT_NO_TOOLBAR
1496     case CE_ToolBar:
1497         painter->save();
1498         if (const QStyleOptionToolBar *toolbar = qstyleoption_cast<const QStyleOptionToolBar *>(option)) {
1499             QRect rect = option->rect;
1500
1501             bool paintLeftBorder = true;
1502             bool paintRightBorder = true;
1503             bool paintBottomBorder = true;
1504
1505             switch (toolbar->toolBarArea) {
1506             case Qt::BottomToolBarArea:
1507                 switch(toolbar->positionOfLine) {
1508                 case QStyleOptionToolBar::Beginning:
1509                 case QStyleOptionToolBar::OnlyOne:
1510                     paintBottomBorder = false;
1511                 default:
1512                     break;
1513                 }
1514             case Qt::TopToolBarArea:
1515                 switch (toolbar->positionWithinLine) {
1516                 case QStyleOptionToolBar::Beginning:
1517                     paintLeftBorder = false;
1518                     break;
1519                 case QStyleOptionToolBar::End:
1520                     paintRightBorder = false;
1521                     break;
1522                 case QStyleOptionToolBar::OnlyOne:
1523                     paintRightBorder = false;
1524                     paintLeftBorder = false;
1525                 default:
1526                     break;
1527                 }
1528                 if (toolbar->direction == Qt::RightToLeft) { //reverse layout changes the order of Beginning/end
1529                     bool tmp = paintLeftBorder;
1530                     paintRightBorder=paintLeftBorder;
1531                     paintLeftBorder=tmp;
1532                 }
1533                 break;
1534             case Qt::RightToolBarArea:
1535                 switch (toolbar->positionOfLine) {
1536                 case QStyleOptionToolBar::Beginning:
1537                 case QStyleOptionToolBar::OnlyOne:
1538                     paintRightBorder = false;
1539                     break;
1540                 default:
1541                     break;
1542                 }
1543                 break;
1544             case Qt::LeftToolBarArea:
1545                 switch (toolbar->positionOfLine) {
1546                 case QStyleOptionToolBar::Beginning:
1547                 case QStyleOptionToolBar::OnlyOne:
1548                     paintLeftBorder = false;
1549                     break;
1550                 default:
1551                     break;
1552                 }
1553                 break;
1554             default:
1555                 break;
1556             }
1557
1558             QColor light = option->palette.background().color().lighter(110);
1559
1560             //draw top border
1561             painter->setPen(QPen(light));
1562             painter->drawLine(rect.topLeft().x(),
1563                         rect.topLeft().y(),
1564                         rect.topRight().x(),
1565                         rect.topRight().y());
1566
1567             if (paintLeftBorder) {
1568                 painter->setPen(QPen(light));
1569                 painter->drawLine(rect.topLeft().x(),
1570                             rect.topLeft().y(),
1571                             rect.bottomLeft().x(),
1572                             rect.bottomLeft().y());
1573             }
1574
1575             if (paintRightBorder) {
1576                 painter->setPen(QPen(shadow));
1577                 painter->drawLine(rect.topRight().x(),
1578                             rect.topRight().y(),
1579                             rect.bottomRight().x(),
1580                             rect.bottomRight().y());
1581             }
1582
1583             if (paintBottomBorder) {
1584                 painter->setPen(QPen(shadow));
1585                 painter->drawLine(rect.bottomLeft().x(),
1586                             rect.bottomLeft().y(),
1587                             rect.bottomRight().x(),
1588                             rect.bottomRight().y());
1589             }
1590         }
1591         painter->restore();
1592         break;
1593 #endif // QT_NO_TOOLBAR
1594 #ifndef QT_NO_DOCKWIDGET
1595     case CE_DockWidgetTitle:
1596         painter->save();
1597         if (const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<const QStyleOptionDockWidget *>(option)) {
1598             const QStyleOptionDockWidgetV2 *v2
1599                 = qstyleoption_cast<const QStyleOptionDockWidgetV2*>(dwOpt);
1600             bool verticalTitleBar = v2 == 0 ? false : v2->verticalTitleBar;
1601
1602             QRect rect = dwOpt->rect;
1603             QRect titleRect = subElementRect(SE_DockWidgetTitleBarText, option, widget);
1604             QRect r = rect.adjusted(0, 0, -1, 0);
1605             if (verticalTitleBar)
1606                 r.adjust(0, 0, 0, -1);
1607             painter->setPen(option->palette.light().color());
1608             painter->drawRect(r.adjusted(1, 1, 1, 1));
1609             painter->setPen(shadow);
1610             painter->drawRect(r);
1611
1612             if (verticalTitleBar) {
1613                 QRect r = rect;
1614                 QSize s = r.size();
1615                 s.transpose();
1616                 r.setSize(s);
1617
1618                 titleRect = QRect(r.left() + rect.bottom()
1619                                     - titleRect.bottom(),
1620                                 r.top() + titleRect.left() - rect.left(),
1621                                 titleRect.height(), titleRect.width());
1622
1623                 painter->translate(r.left(), r.top() + r.width());
1624                 painter->rotate(-90);
1625                 painter->translate(-r.left(), -r.top());
1626
1627                 rect = r;
1628             }
1629
1630             if (!dwOpt->title.isEmpty()) {
1631                 QString titleText
1632                     = painter->fontMetrics().elidedText(dwOpt->title,
1633                                             Qt::ElideRight, titleRect.width());
1634                 proxy()->drawItemText(painter,
1635                              titleRect,
1636                              Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, dwOpt->palette,
1637                              dwOpt->state & State_Enabled, titleText,
1638                              QPalette::WindowText);
1639                 }
1640         }
1641         painter->restore();
1642         break;
1643 #endif // QT_NO_DOCKWIDGET
1644     case CE_HeaderSection:
1645         painter->save();
1646         // Draws the header in tables.
1647         if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
1648             QPixmap cache;
1649             QString pixmapName = QStyleHelper::uniqueName(QLatin1String("headersection"), option, option->rect.size());
1650             pixmapName += QString::number(- int(header->position));
1651             pixmapName += QString::number(- int(header->orientation));
1652             QRect r = option->rect;
1653             QColor gradientStopColor;
1654             QColor gradientStartColor = option->palette.button().color();
1655             gradientStopColor.setHsv(gradientStartColor.hue(),
1656                                      qMin(255, (int)(gradientStartColor.saturation()*2)),
1657                                      qMin(255, (int)(gradientStartColor.value()*0.96)));
1658             QLinearGradient gradient(rect.topLeft(), rect.bottomLeft());
1659             if (option->palette.background().gradient()) {
1660                 gradient.setStops(option->palette.background().gradient()->stops());
1661             } else {
1662                 gradient.setColorAt(0, gradientStartColor);
1663                 gradient.setColorAt(0.8, gradientStartColor);
1664                 gradient.setColorAt(1, gradientStopColor);
1665             }
1666             painter->fillRect(r, gradient);
1667
1668             if (!QPixmapCache::find(pixmapName, cache)) {
1669                 cache = QPixmap(r.size());
1670                 cache.fill(Qt::transparent);
1671                 QRect pixmapRect(0, 0, r.width(), r.height());
1672                 QPainter cachePainter(&cache);
1673                 if (header->orientation == Qt::Vertical) {
1674                     cachePainter.setPen(QPen(dark));
1675                     cachePainter.drawLine(pixmapRect.topRight(), pixmapRect.bottomRight());
1676                     if (header->position != QStyleOptionHeader::End) {
1677                         cachePainter.setPen(QPen(shadow));
1678                         cachePainter.drawLine(pixmapRect.bottomLeft() + QPoint(3, -1), pixmapRect.bottomRight() + QPoint(-3, -1));                                cachePainter.setPen(QPen(option->palette.light().color()));
1679                         cachePainter.drawLine(pixmapRect.bottomLeft() + QPoint(3, 0), pixmapRect.bottomRight() + QPoint(-3, 0));                              }
1680                 } else {
1681                     cachePainter.setPen(QPen(dark));
1682                     cachePainter.drawLine(pixmapRect.bottomLeft(), pixmapRect.bottomRight());
1683                     cachePainter.setPen(QPen(shadow));
1684                     cachePainter.drawLine(pixmapRect.topRight() + QPoint(-1, 3), pixmapRect.bottomRight() + QPoint(-1, -3));                                  cachePainter.setPen(QPen(option->palette.light().color()));
1685                     cachePainter.drawLine(pixmapRect.topRight() + QPoint(0, 3), pixmapRect.bottomRight() + QPoint(0, -3));                                }
1686                 cachePainter.end();
1687                 QPixmapCache::insert(pixmapName, cache);
1688             }
1689             painter->drawPixmap(r.topLeft(), cache);
1690         }
1691         painter->restore();
1692         break;
1693     case CE_ProgressBarGroove:
1694         painter->save();
1695         {
1696             painter->fillRect(rect, option->palette.base());
1697             QColor borderColor = dark.lighter(110);
1698             painter->setPen(QPen(borderColor, 0));
1699             const QLine lines[4] = {
1700                 QLine(QPoint(rect.left() + 1, rect.top()), QPoint(rect.right() - 1, rect.top())),
1701                 QLine(QPoint(rect.left() + 1, rect.bottom()), QPoint(rect.right() - 1, rect.bottom())),
1702                 QLine(QPoint(rect.left(), rect.top() + 1), QPoint(rect.left(), rect.bottom() - 1)),
1703                 QLine(QPoint(rect.right(), rect.top() + 1), QPoint(rect.right(), rect.bottom() - 1))
1704             };
1705             painter->drawLines(lines, 4);
1706             QColor alphaCorner = mergedColors(borderColor, option->palette.background().color());
1707             QColor innerShadow = mergedColors(borderColor, option->palette.base().color());
1708
1709             //corner smoothing
1710             painter->setPen(alphaCorner);
1711             const QPoint points[4] = {
1712                 rect.topRight(),
1713                 rect.topLeft(),
1714                 rect.bottomRight(),
1715                 rect.bottomLeft()
1716             };
1717             painter->drawPoints(points, 4);
1718
1719             //inner shadow
1720             painter->setPen(innerShadow);
1721             painter->drawLine(QPoint(rect.left() + 1, rect.top() + 1),
1722                               QPoint(rect.right() - 1, rect.top() + 1));
1723             painter->drawLine(QPoint(rect.left() + 1, rect.top() + 1),
1724                               QPoint(rect.left() + 1, rect.bottom() + 1));
1725
1726         }
1727         painter->restore();
1728         break;
1729     case CE_ProgressBarContents:
1730         painter->save();
1731         if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
1732             QRect rect = bar->rect;
1733             bool vertical = false;
1734             bool inverted = false;
1735             bool indeterminate = (bar->minimum == 0 && bar->maximum == 0);
1736
1737             // Get extra style options if version 2
1738             if (const QStyleOptionProgressBarV2 *bar2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(option)) {
1739                 vertical = (bar2->orientation == Qt::Vertical);
1740                 inverted = bar2->invertedAppearance;
1741             }
1742
1743             // If the orientation is vertical, we use a transform to rotate
1744             // the progress bar 90 degrees clockwise.  This way we can use the
1745             // same rendering code for both orientations.
1746             if (vertical) {
1747                 rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height
1748                 QTransform m = QTransform::fromTranslate(rect.height()-1, -1.0);
1749                 m.rotate(90.0);
1750                 painter->setTransform(m, true);
1751             }
1752
1753             int maxWidth = rect.width() - 4;
1754             int minWidth = 4;
1755             qreal progress = qMax(bar->progress, bar->minimum); // workaround for bug in QProgressBar
1756             int progressBarWidth = (progress - bar->minimum) * qreal(maxWidth) / qMax(qreal(1.0), qreal(bar->maximum) - bar->minimum);
1757             int width = indeterminate ? maxWidth : qMax(minWidth, progressBarWidth);
1758
1759             bool reverse = (!vertical && (bar->direction == Qt::RightToLeft)) || vertical;
1760             if (inverted)
1761                 reverse = !reverse;
1762
1763             QRect progressBar;
1764             if (!indeterminate) {
1765                 if (!reverse) {
1766                     progressBar.setRect(rect.left() + 1, rect.top() + 1, width + 1, rect.height() - 3);
1767                 } else {
1768                     progressBar.setRect(rect.right() - 1 - width, rect.top() + 1, width + 1, rect.height() - 3);
1769                 }
1770             } else {
1771                 Q_D(const QCleanlooksStyle);
1772                 int slideWidth = ((rect.width() - 4) * 2) / 3;
1773                 int step = ((d->animateStep * slideWidth) / d->animationFps) % slideWidth;
1774                 if ((((d->animateStep * slideWidth) / d->animationFps) % (2 * slideWidth)) >= slideWidth)
1775                     step = slideWidth - step;
1776                 progressBar.setRect(rect.left() + 1 + step, rect.top() + 1,
1777                                     slideWidth / 2, rect.height() - 3);
1778             }
1779             QColor highlight = option->palette.color(QPalette::Normal, QPalette::Highlight);
1780             painter->setPen(QPen(highlight.darker(140), 0));
1781
1782             QColor highlightedGradientStartColor = highlight.lighter(100);
1783             QColor highlightedGradientStopColor  = highlight.lighter(130);
1784
1785             QLinearGradient gradient(rect.topLeft(), QPoint(rect.bottomLeft().x(),
1786                                                             rect.bottomLeft().y()*2));
1787
1788             gradient.setColorAt(0, highlightedGradientStartColor);
1789             gradient.setColorAt(1, highlightedGradientStopColor);
1790
1791             painter->setBrush(gradient);
1792             painter->drawRect(progressBar);
1793
1794             painter->setPen(QPen(highlight.lighter(120), 0));
1795             painter->drawLine(QPoint(progressBar.left() + 1, progressBar.top() + 1),
1796                               QPoint(progressBar.right(), progressBar.top() + 1));
1797             painter->drawLine(QPoint(progressBar.left() + 1, progressBar.top() + 1),
1798                               QPoint(progressBar.left() + 1, progressBar.bottom() - 1));
1799
1800             painter->setPen(QPen(highlightedGradientStartColor, 7.0));//QPen(option->palette.highlight(), 3));
1801
1802             painter->save();
1803             painter->setClipRect(progressBar.adjusted(2, 2, -1, -1));
1804             for (int x = progressBar.left() - 32; x < rect.right() ; x+=18) {
1805                 painter->drawLine(x, progressBar.bottom() + 1, x + 23, progressBar.top() - 2);
1806             }
1807             painter->restore();
1808
1809         }
1810         painter->restore();
1811         break;
1812     case CE_MenuBarItem:
1813         painter->save();
1814         if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option))
1815         {
1816             QStyleOptionMenuItem item = *mbi;
1817             item.rect = mbi->rect.adjusted(0, 3, 0, -1);
1818             QColor highlightOutline = highlight.darker(125);
1819             QLinearGradient gradient(rect.topLeft(), QPoint(rect.bottomLeft().x(), rect.bottomLeft().y()*2));
1820
1821             if (option->palette.button().gradient()) {
1822                 gradient.setStops(option->palette.button().gradient()->stops());
1823             } else {
1824                 gradient.setColorAt(0, option->palette.button().color());
1825                 gradient.setColorAt(1, option->palette.button().color().darker(110));
1826             }
1827             painter->fillRect(rect, gradient);
1828
1829             QCommonStyle::drawControl(element, &item, painter, widget);
1830
1831             bool act = mbi->state & State_Selected && mbi->state & State_Sunken;
1832             bool dis = !(mbi->state & State_Enabled);
1833
1834             QRect r = option->rect;
1835             if (act) {
1836                 qt_cleanlooks_draw_gradient(painter, r.adjusted(1, 1, -1, -1),
1837                                             highlight,
1838                                             highlightOutline, TopDown,
1839                                             option->palette.highlight());
1840
1841                 painter->setPen(QPen(highlightOutline, 0));
1842                 const QLine lines[4] = {
1843                     QLine(QPoint(r.left(), r.top() + 1), QPoint(r.left(), r.bottom())),
1844                     QLine(QPoint(r.right(), r.top() + 1), QPoint(r.right(), r.bottom())),
1845                     QLine(QPoint(r.left() + 1, r.bottom()), QPoint(r.right() - 1, r.bottom())),
1846                     QLine(QPoint(r.left() + 1, r.top()), QPoint(r.right() - 1, r.top()))
1847                 };
1848                 painter->drawLines(lines, 4);
1849
1850                 //draw text
1851                 QPalette::ColorRole textRole = dis ? QPalette::Text : QPalette::HighlightedText;
1852                 uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
1853                 if (!styleHint(SH_UnderlineShortcut, mbi, widget))
1854                     alignment |= Qt::TextHideMnemonic;
1855                 proxy()->drawItemText(painter, item.rect, alignment, mbi->palette, mbi->state & State_Enabled, mbi->text, textRole);
1856             }
1857
1858         }
1859         painter->restore();
1860         break;
1861     case CE_MenuItem:
1862         painter->save();
1863         // Draws one item in a popup menu.
1864         if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
1865             QColor highlightOutline = highlight.darker(125);
1866             QColor menuBackground = option->palette.background().color().lighter(104);
1867             QColor borderColor = option->palette.background().color().darker(160);
1868             QColor alphaCornerColor;
1869
1870             if (widget) {
1871                 // ### backgroundrole/foregroundrole should be part of the style option
1872                 alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), borderColor);
1873             } else {
1874                 alphaCornerColor = mergedColors(option->palette.background().color(), borderColor);
1875             }
1876             if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
1877                 painter->fillRect(menuItem->rect, menuBackground);
1878                 int w = 0;
1879                 if (!menuItem->text.isEmpty()) {
1880                     painter->setFont(menuItem->font);
1881                     proxy()->drawItemText(painter, menuItem->rect.adjusted(5, 0, -5, 0), Qt::AlignLeft | Qt::AlignVCenter,
1882                                  menuItem->palette, menuItem->state & State_Enabled, menuItem->text,
1883                                  QPalette::Text);
1884                     w = menuItem->fontMetrics.width(menuItem->text) + 5;
1885                 }
1886                 painter->setPen(shadow.lighter(106));
1887                 bool reverse = menuItem->direction == Qt::RightToLeft;
1888                 painter->drawLine(menuItem->rect.left() + 5 + (reverse ? 0 : w), menuItem->rect.center().y(),
1889                                   menuItem->rect.right() - 5 - (reverse ? w : 0), menuItem->rect.center().y());
1890                 painter->restore();
1891                 break;
1892             }
1893             bool selected = menuItem->state & State_Selected && menuItem->state & State_Enabled;
1894             if (selected) {
1895                 QRect r = option->rect.adjusted(1, 0, -2, -1);
1896                 qt_cleanlooks_draw_gradient(painter, r, highlight,
1897                                             highlightOutline, TopDown,
1898                                             highlight);
1899                 r = r.adjusted(-1, 0, 1, 0);
1900                 painter->setPen(QPen(highlightOutline, 0));
1901                 const QLine lines[4] = {
1902                     QLine(QPoint(r.left(), r.top() + 1), QPoint(r.left(), r.bottom() - 1)),
1903                     QLine(QPoint(r.right(), r.top() + 1), QPoint(r.right(), r.bottom() - 1)),
1904                     QLine(QPoint(r.left() + 1, r.bottom()), QPoint(r.right() - 1, r.bottom())),
1905                     QLine(QPoint(r.left() + 1, r.top()), QPoint(r.right() - 1, r.top()))
1906                 };
1907                 painter->drawLines(lines, 4);
1908             } else {
1909                 painter->fillRect(option->rect, menuBackground);
1910             }
1911
1912             bool checkable = menuItem->checkType != QStyleOptionMenuItem::NotCheckable;
1913             bool checked = menuItem->checked;
1914             bool sunken = menuItem->state & State_Sunken;
1915             bool enabled = menuItem->state & State_Enabled;
1916
1917             bool ignoreCheckMark = false;
1918             int checkcol = qMax(menuItem->maxIconWidth, 20);
1919
1920 #ifndef QT_NO_COMBOBOX
1921             if (qobject_cast<const QComboBox*>(widget))
1922                 ignoreCheckMark = true; //ignore the checkmarks provided by the QComboMenuDelegate
1923 #endif
1924
1925             if (!ignoreCheckMark) {
1926                 // Check
1927                 QRect checkRect(option->rect.left() + 7, option->rect.center().y() - 6, 13, 13);
1928                 checkRect = visualRect(menuItem->direction, menuItem->rect, checkRect);
1929                 if (checkable) {
1930                     if (menuItem->checkType & QStyleOptionMenuItem::Exclusive) {
1931                         // Radio button
1932                         if (checked || sunken) {
1933                             painter->setRenderHint(QPainter::Antialiasing);
1934                             painter->setPen(Qt::NoPen);
1935
1936                             QPalette::ColorRole textRole = !enabled ? QPalette::Text:
1937                                                         selected ? QPalette::HighlightedText : QPalette::ButtonText;
1938                             painter->setBrush(option->palette.brush( option->palette.currentColorGroup(), textRole));
1939                             painter->drawEllipse(checkRect.adjusted(4, 4, -4, -4));
1940                         }
1941                     } else {
1942                         // Check box
1943                         if (menuItem->icon.isNull()) {
1944                             if (checked || sunken) {
1945                                 QImage image(qt_cleanlooks_menuitem_checkbox_checked);
1946                                 if (enabled && (menuItem->state & State_Selected)) {
1947                                     image.setColor(1, 0x55ffffff);
1948                                     image.setColor(2, 0xAAffffff);
1949                                     image.setColor(3, 0xBBffffff);
1950                                     image.setColor(4, 0xFFffffff);
1951                                     image.setColor(5, 0x33ffffff);
1952                                 } else {
1953                                     image.setColor(1, 0x55000000);
1954                                     image.setColor(2, 0xAA000000);
1955                                     image.setColor(3, 0xBB000000);
1956                                     image.setColor(4, 0xFF000000);
1957                                     image.setColor(5, 0x33000000);
1958                                 }
1959                                 painter->drawImage(QPoint(checkRect.center().x() - image.width() / 2,
1960                                                         checkRect.center().y() - image.height() / 2), image);
1961                             }
1962                         }
1963                     }
1964                 }
1965             } else { //ignore checkmark
1966                 if (menuItem->icon.isNull())
1967                     checkcol = 0;
1968                 else
1969                     checkcol = menuItem->maxIconWidth;
1970             }
1971
1972             // Text and icon, ripped from windows style
1973             bool dis = !(menuItem->state & State_Enabled);
1974             bool act = menuItem->state & State_Selected;
1975             const QStyleOption *opt = option;
1976             const QStyleOptionMenuItem *menuitem = menuItem;
1977
1978             QPainter *p = painter;
1979             QRect vCheckRect = visualRect(opt->direction, menuitem->rect,
1980                                           QRect(menuitem->rect.x(), menuitem->rect.y(),
1981                                                 checkcol, menuitem->rect.height()));
1982             if (!menuItem->icon.isNull()) {
1983                 QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
1984                 if (act && !dis)
1985                     mode = QIcon::Active;
1986                 QPixmap pixmap;
1987
1988                 int smallIconSize = proxy()->pixelMetric(PM_SmallIconSize, option, widget);
1989                 QSize iconSize(smallIconSize, smallIconSize);
1990 #ifndef QT_NO_COMBOBOX
1991                 if (const QComboBox *combo = qobject_cast<const QComboBox*>(widget))
1992                     iconSize = combo->iconSize();
1993 #endif // QT_NO_COMBOBOX
1994                 if (checked)
1995                     pixmap = menuItem->icon.pixmap(iconSize, mode, QIcon::On);
1996                 else
1997                     pixmap = menuItem->icon.pixmap(iconSize, mode);
1998
1999                 int pixw = pixmap.width();
2000                 int pixh = pixmap.height();
2001
2002                 QRect pmr(0, 0, pixw, pixh);
2003                 pmr.moveCenter(vCheckRect.center());
2004                 painter->setPen(menuItem->palette.text().color());
2005                 if (checkable && checked) {
2006                     QStyleOption opt = *option;
2007                     if (act) {
2008                         QColor activeColor = mergedColors(option->palette.background().color(),
2009                                                         option->palette.highlight().color());
2010                         opt.palette.setBrush(QPalette::Button, activeColor);
2011                     }
2012                     opt.state |= State_Sunken;
2013                     opt.rect = vCheckRect;
2014                     proxy()->drawPrimitive(PE_PanelButtonCommand, &opt, painter, widget);
2015                 }
2016                 painter->drawPixmap(pmr.topLeft(), pixmap);
2017             }
2018             if (selected) {
2019                 painter->setPen(menuItem->palette.highlightedText().color());
2020             } else {
2021                 painter->setPen(menuItem->palette.text().color());
2022             }
2023             int x, y, w, h;
2024             menuitem->rect.getRect(&x, &y, &w, &h);
2025             int tab = menuitem->tabWidth;
2026             QColor discol;
2027             if (dis) {
2028                 discol = menuitem->palette.text().color();
2029                 p->setPen(discol);
2030             }
2031             int xm = windowsItemFrame + checkcol + windowsItemHMargin;
2032             int xpos = menuitem->rect.x() + xm;
2033
2034             QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
2035             QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
2036             QString s = menuitem->text;
2037             if (!s.isEmpty()) {                     // draw text
2038                 p->save();
2039                 int t = s.indexOf(QLatin1Char('\t'));
2040                 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
2041                 if (!styleHint(SH_UnderlineShortcut, menuitem, widget))
2042                     text_flags |= Qt::TextHideMnemonic;
2043                 text_flags |= Qt::AlignLeft;
2044                 if (t >= 0) {
2045                     QRect vShortcutRect = visualRect(opt->direction, menuitem->rect,
2046                                                      QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
2047                     if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, option, widget)) {
2048                         p->setPen(menuitem->palette.light().color());
2049                         p->drawText(vShortcutRect.adjusted(1, 1, 1, 1), text_flags, s.mid(t + 1));
2050                         p->setPen(discol);
2051                     }
2052                     p->drawText(vShortcutRect, text_flags, s.mid(t + 1));
2053                     s = s.left(t);
2054                 }
2055                 QFont font = menuitem->font;
2056                 // font may not have any "hard" flags set. We override
2057                 // the point size so that when it is resolved against the device, this font will win.
2058                 // This is mainly to handle cases where someone sets the font on the window
2059                 // and then the combo inherits it and passes it onward. At that point the resolve mask
2060                 // is very, very weak. This makes it stonger.
2061                 font.setPointSizeF(QFontInfo(menuItem->font).pointSizeF());
2062
2063                 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
2064                     font.setBold(true);
2065
2066                 p->setFont(font);
2067                 if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, option, widget)) {
2068                     p->setPen(menuitem->palette.light().color());
2069                     p->drawText(vTextRect.adjusted(1, 1, 1, 1), text_flags, s.left(t));
2070                     p->setPen(discol);
2071                 }
2072                 p->drawText(vTextRect, text_flags, s.left(t));
2073                 p->restore();
2074             }
2075
2076             // Arrow
2077             if (menuItem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow
2078                 int dim = (menuItem->rect.height() - 4) / 2;
2079                 PrimitiveElement arrow;
2080                 arrow = QApplication::isRightToLeft() ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
2081                 int xpos = menuItem->rect.left() + menuItem->rect.width() - 3 - dim;
2082                 QRect  vSubMenuRect = visualRect(option->direction, menuItem->rect,
2083                                                  QRect(xpos, menuItem->rect.top() + menuItem->rect.height() / 2 - dim / 2, dim, dim));
2084                 QStyleOptionMenuItem newMI = *menuItem;
2085                 newMI.rect = vSubMenuRect;
2086                 newMI.state = !enabled ? State_None : State_Enabled;
2087                 if (selected)
2088                     newMI.palette.setColor(QPalette::ButtonText,
2089                                            newMI.palette.highlightedText().color());
2090                 proxy()->drawPrimitive(arrow, &newMI, painter, widget);
2091             }
2092         }
2093         painter->restore();
2094         break;
2095     case CE_MenuHMargin:
2096     case CE_MenuVMargin:
2097         break;
2098     case CE_MenuEmptyArea:
2099         break;
2100     case CE_PushButtonLabel:
2101         if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
2102             QRect ir = button->rect;
2103             uint tf = Qt::AlignVCenter;
2104             if (styleHint(SH_UnderlineShortcut, button, widget))
2105                 tf |= Qt::TextShowMnemonic;
2106             else
2107                tf |= Qt::TextHideMnemonic;
2108
2109             if (!button->icon.isNull()) {
2110                 //Center both icon and text
2111                 QPoint point;
2112
2113                 QIcon::Mode mode = button->state & State_Enabled ? QIcon::Normal
2114                                                               : QIcon::Disabled;
2115                 if (mode == QIcon::Normal && button->state & State_HasFocus)
2116                     mode = QIcon::Active;
2117                 QIcon::State state = QIcon::Off;
2118                 if (button->state & State_On)
2119                     state = QIcon::On;
2120
2121                 QPixmap pixmap = button->icon.pixmap(button->iconSize, mode, state);
2122                 int w = pixmap.width();
2123                 int h = pixmap.height();
2124
2125                 if (!button->text.isEmpty())
2126                     w += button->fontMetrics.boundingRect(option->rect, tf, button->text).width() + 2;
2127
2128                 point = QPoint(ir.x() + ir.width() / 2 - w / 2,
2129                                ir.y() + ir.height() / 2 - h / 2);
2130
2131                 if (button->direction == Qt::RightToLeft)
2132                     point.rx() += pixmap.width();
2133
2134                 painter->drawPixmap(visualPos(button->direction, button->rect, point), pixmap);
2135
2136                 if (button->direction == Qt::RightToLeft)
2137                     ir.translate(-point.x() - 2, 0);
2138                 else
2139                     ir.translate(point.x() + pixmap.width(), 0);
2140
2141                 // left-align text if there is
2142                 if (!button->text.isEmpty())
2143                     tf |= Qt::AlignLeft;
2144
2145             } else {
2146                 tf |= Qt::AlignHCenter;
2147             }
2148
2149             if (button->features & QStyleOptionButton::HasMenu)
2150                 ir = ir.adjusted(0, 0, -proxy()->pixelMetric(PM_MenuButtonIndicator, button, widget), 0);
2151             proxy()->drawItemText(painter, ir, tf, button->palette, (button->state & State_Enabled),
2152                          button->text, QPalette::ButtonText);
2153         }
2154         break;
2155     case CE_MenuBarEmptyArea:
2156         painter->save();
2157         {
2158             QColor shadow = mergedColors(option->palette.background().color().darker(120),
2159                                  dark.lighter(140), 60);
2160
2161             QLinearGradient gradient(rect.topLeft(), QPoint(rect.bottomLeft().x(), rect.bottomLeft().y()*2));
2162             gradient.setColorAt(0, option->palette.button().color());
2163             gradient.setColorAt(1, option->palette.button().color().darker(110));
2164             painter->fillRect(rect, gradient);
2165
2166 #ifndef QT_NO_MAINWINDOW
2167             if (widget && qobject_cast<const QMainWindow *>(widget->parentWidget())) {
2168                 QPen oldPen = painter->pen();
2169                 painter->setPen(QPen(shadow));
2170                 painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
2171             }
2172 #endif // QT_NO_MAINWINDOW
2173         }
2174         painter->restore();
2175         break;
2176 #ifndef QT_NO_TABBAR
2177         case CE_TabBarTabShape:
2178         painter->save();
2179         if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
2180
2181             bool rtlHorTabs = (tab->direction == Qt::RightToLeft
2182                                && (tab->shape == QTabBar::RoundedNorth
2183                                    || tab->shape == QTabBar::RoundedSouth));
2184             bool selected = tab->state & State_Selected;
2185             bool lastTab = ((!rtlHorTabs && tab->position == QStyleOptionTab::End)
2186                             || (rtlHorTabs
2187                                 && tab->position == QStyleOptionTab::Beginning));
2188             bool onlyTab = tab->position == QStyleOptionTab::OnlyOneTab;
2189             bool leftCornerWidget = (tab->cornerWidgets & QStyleOptionTab::LeftCornerWidget);
2190
2191             bool atBeginning = ((tab->position == (tab->direction == Qt::LeftToRight ?
2192                                 QStyleOptionTab::Beginning : QStyleOptionTab::End)) || onlyTab);
2193
2194             bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab;
2195             bool previousSelected =
2196                 ((!rtlHorTabs
2197                   && tab->selectedPosition == QStyleOptionTab::PreviousIsSelected)
2198                  || (rtlHorTabs
2199                      && tab->selectedPosition == QStyleOptionTab::NextIsSelected));
2200             bool nextSelected =
2201                 ((!rtlHorTabs
2202                   && tab->selectedPosition == QStyleOptionTab::NextIsSelected)
2203                  || (rtlHorTabs
2204                      && tab->selectedPosition
2205                      == QStyleOptionTab::PreviousIsSelected));
2206             int tabBarAlignment = proxy()->styleHint(SH_TabBar_Alignment, tab, widget);
2207             bool leftAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignLeft)
2208                                || (rtlHorTabs
2209                                    && tabBarAlignment == Qt::AlignRight);
2210
2211             bool rightAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignRight)
2212                                 || (rtlHorTabs
2213                                     && tabBarAlignment == Qt::AlignLeft);
2214
2215             QColor light = tab->palette.light().color();
2216
2217             QColor background = tab->palette.background().color();
2218             int borderThinkness = proxy()->pixelMetric(PM_TabBarBaseOverlap, tab, widget);
2219             if (selected)
2220                 borderThinkness /= 2;
2221             QRect r2(option->rect);
2222             int x1 = r2.left();
2223             int x2 = r2.right();
2224             int y1 = r2.top();
2225             int y2 = r2.bottom();
2226
2227             QTransform rotMatrix;
2228             bool flip = false;
2229             painter->setPen(shadow);
2230             QColor activeHighlight = option->palette.color(QPalette::Normal, QPalette::Highlight);
2231             switch (tab->shape) {
2232             case QTabBar::RoundedNorth:
2233                 break;
2234             case QTabBar::RoundedSouth:
2235                 rotMatrix.rotate(180);
2236                 rotMatrix.translate(0, -rect.height() + 1);
2237                 rotMatrix.scale(-1, 1);
2238                 painter->setTransform(rotMatrix, true);
2239                 break;
2240             case QTabBar::RoundedWest:
2241                 rotMatrix.rotate(180 + 90);
2242                 rotMatrix.scale(-1, 1);
2243                 flip = true;
2244                 painter->setTransform(rotMatrix, true);
2245                 break;
2246             case QTabBar::RoundedEast:
2247                 rotMatrix.rotate(90);
2248                 rotMatrix.translate(0, - rect.width() + 1);
2249                 flip = true;
2250                 painter->setTransform(rotMatrix, true);
2251                 break;
2252             default:
2253                 painter->restore();
2254                 QWindowsStyle::drawControl(element, tab, painter, widget);
2255                 return;
2256             }
2257
2258             if (flip) {
2259                 QRect tmp = rect;
2260                 rect = QRect(tmp.y(), tmp.x(), tmp.height(), tmp.width());
2261                 int temp = x1;
2262                 x1 = y1;
2263                 y1 = temp;
2264                 temp = x2;
2265                 x2 = y2;
2266                 y2 = temp;
2267             }
2268
2269             QLinearGradient gradient(rect.topLeft(), rect.bottomLeft());
2270             if (option->palette.button().gradient()) {
2271                 if (selected)
2272                     gradient.setStops(option->palette.background().gradient()->stops());
2273                 else
2274                     gradient.setStops(option->palette.background().gradient()->stops());
2275             }
2276             else if (selected) {
2277                 gradient.setColorAt(0, option->palette.background().color().lighter(104));
2278                 gradient.setColorAt(1, tabFrameColor);
2279                 painter->fillRect(rect.adjusted(0, 2, 0, -1), gradient);
2280             } else {
2281                 y1 += 2;
2282                 gradient.setColorAt(0, option->palette.background().color());
2283                 gradient.setColorAt(1, dark.lighter(120));
2284                 painter->fillRect(rect.adjusted(0, 2, 0, -2), gradient);
2285             }
2286
2287             // Delete border
2288             if (selected) {
2289                 painter->setPen(QPen(activeHighlight, 0));
2290                 painter->drawLine(x1 + 1, y1 + 1, x2 - 1, y1 + 1);
2291                 painter->drawLine(x1 , y1 + 2, x2 , y1 + 2);
2292             } else {
2293                 painter->setPen(dark);
2294                 painter->drawLine(x1, y2 - 1, x2 + 2, y2 - 1 );
2295                 if (tab->shape == QTabBar::RoundedNorth || tab->shape == QTabBar::RoundedWest) {
2296                     painter->setPen(light);
2297                     painter->drawLine(x1, y2 , x2, y2 );
2298                 }
2299             }
2300             // Left
2301             if (atBeginning || selected ) {
2302                 painter->setPen(light);
2303                 painter->drawLine(x1 + 1, y1 + 2 + 1, x1 + 1, y2 - ((onlyOne || atBeginning) && selected && leftAligned ? 0 : borderThinkness) - (atBeginning && leftCornerWidget ? 1 : 0));
2304                 painter->drawPoint(x1 + 1, y1 + 1);
2305                 painter->setPen(dark);
2306                 painter->drawLine(x1, y1 + 2, x1, y2 - ((onlyOne || atBeginning)  && leftAligned ? 0 : borderThinkness) - (atBeginning && leftCornerWidget ? 1 : 0));
2307             }
2308             // Top
2309             {
2310                 int beg = x1 + (previousSelected ? 0 : 2);
2311                 int end = x2 - (nextSelected ? 0 : 2);
2312                 painter->setPen(light);
2313
2314                 if (!selected)painter->drawLine(beg - 2, y1 + 1, end, y1 + 1);
2315
2316                 if (selected)
2317                     painter->setPen(QPen(activeHighlight.darker(150), 0));
2318                 else
2319                     painter->setPen(darkOutline);
2320                 painter->drawLine(beg, y1 , end, y1);
2321
2322                 if (atBeginning|| selected) {
2323                     painter->drawPoint(beg - 1, y1 + 1);
2324                 } else if (!atBeginning) {
2325                     painter->drawPoint(beg - 1, y1);
2326                     painter->drawPoint(beg - 2, y1);
2327                     if (!lastTab) {
2328                         painter->setPen(dark.lighter(130));
2329                         painter->drawPoint(end + 1, y1);
2330                         painter->drawPoint(end + 2 , y1);
2331                         painter->drawPoint(end + 2, y1 + 1);
2332                     }
2333                 }
2334             }
2335             // Right
2336             if (lastTab || selected || onlyOne || !nextSelected) {
2337                 painter->setPen(darkOutline);
2338                 painter->drawLine(x2, y1 + 2, x2, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
2339                 if (selected)
2340                     painter->setPen(QPen(activeHighlight.darker(150), 0));
2341                 else
2342                     painter->setPen(darkOutline);
2343                 painter->drawPoint(x2 - 1, y1 + 1);
2344
2345                 if (selected) {
2346                     painter->setPen(background.darker(110));
2347                     painter->drawLine(x2 - 1, y1 + 3, x2 - 1, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
2348                 }
2349             }
2350         }
2351         painter->restore();
2352         break;
2353
2354 #endif // QT_NO_TABBAR
2355     default:
2356         QWindowsStyle::drawControl(element,option,painter,widget);
2357         break;
2358     }
2359 }
2360
2361 /*!
2362   \reimp
2363 */
2364 QPalette QCleanlooksStyle::standardPalette () const
2365 {
2366     QPalette palette = QWindowsStyle::standardPalette();
2367     palette.setBrush(QPalette::Active, QPalette::Highlight, QColor(98, 140, 178));
2368     palette.setBrush(QPalette::Inactive, QPalette::Highlight, QColor(145, 141, 126));
2369     palette.setBrush(QPalette::Disabled, QPalette::Highlight, QColor(145, 141, 126));
2370
2371     QColor backGround(239, 235, 231);
2372
2373     QColor light = backGround.lighter(150);
2374     QColor base = Qt::white;
2375     QColor dark = QColor(170, 156, 143).darker(110);
2376     dark = backGround.darker(150);
2377     QColor darkDisabled = QColor(209, 200, 191).darker(110);
2378
2379     //### Find the correct disabled text color
2380     palette.setBrush(QPalette::Disabled, QPalette::Text, QColor(190, 190, 190));
2381
2382     palette.setBrush(QPalette::Window, backGround);
2383     palette.setBrush(QPalette::Mid, backGround.darker(130));
2384     palette.setBrush(QPalette::Light, light);
2385
2386     palette.setBrush(QPalette::Active, QPalette::Base, base);
2387     palette.setBrush(QPalette::Inactive, QPalette::Base, base);
2388     palette.setBrush(QPalette::Disabled, QPalette::Base, backGround);
2389
2390     palette.setBrush(QPalette::Midlight, palette.mid().color().lighter(110));
2391
2392     palette.setBrush(QPalette::All, QPalette::Dark, dark);
2393     palette.setBrush(QPalette::Disabled, QPalette::Dark, darkDisabled);
2394
2395     QColor button = backGround;
2396
2397     palette.setBrush(QPalette::Button, button);
2398
2399     QColor shadow = dark.darker(135);
2400     palette.setBrush(QPalette::Shadow, shadow);
2401     palette.setBrush(QPalette::Disabled, QPalette::Shadow, shadow.lighter(150));
2402     palette.setBrush(QPalette::HighlightedText, QColor(QRgb(0xffffffff)));
2403     return palette;
2404 }
2405
2406 /*!
2407   \reimp
2408 */
2409 void QCleanlooksStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
2410                                          QPainter *painter, const QWidget *widget) const
2411 {
2412     QColor button = option->palette.button().color();
2413     QColor dark;
2414     QColor grooveColor;
2415     QColor darkOutline;
2416     dark.setHsv(button.hue(),
2417                 qMin(255, (int)(button.saturation()*1.9)),
2418                 qMin(255, (int)(button.value()*0.7)));
2419     grooveColor.setHsv(button.hue(),
2420                 qMin(255, (int)(button.saturation()*2.6)),
2421                 qMin(255, (int)(button.value()*0.9)));
2422     darkOutline.setHsv(button.hue(),
2423                 qMin(255, (int)(button.saturation()*3.0)),
2424                 qMin(255, (int)(button.value()*0.6)));
2425
2426     QColor alphaCornerColor;
2427     if (widget) {
2428         // ### backgroundrole/foregroundrole should be part of the style option
2429         alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), darkOutline);
2430     } else {
2431         alphaCornerColor = mergedColors(option->palette.background().color(), darkOutline);
2432     }
2433     QColor gripShadow = grooveColor.darker(110);
2434     QColor buttonShadow = option->palette.button().color().darker(110);
2435
2436     QColor gradientStartColor = option->palette.button().color().lighter(108);
2437     QColor gradientStopColor = mergedColors(option->palette.button().color().darker(108), dark.lighter(150), 70);
2438
2439     QPalette palette = option->palette;
2440
2441     switch (control) {
2442 #ifndef QT_NO_SPINBOX
2443     case CC_SpinBox:
2444         if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
2445             QPixmap cache;
2446             QString pixmapName = QStyleHelper::uniqueName(QLatin1String("spinbox"), spinBox, spinBox->rect.size());
2447             if (!QPixmapCache::find(pixmapName, cache)) {
2448                 cache = QPixmap(spinBox->rect.size());
2449                 cache.fill(Qt::transparent);
2450                 QRect pixmapRect(0, 0, spinBox->rect.width(), spinBox->rect.height());
2451                 QPainter cachePainter(&cache);
2452
2453                 bool isEnabled = (spinBox->state & State_Enabled);
2454                 //bool focus = isEnabled && (spinBox->state & State_HasFocus);
2455                 bool hover = isEnabled && (spinBox->state & State_MouseOver);
2456                 bool sunken = (spinBox->state & State_Sunken);
2457                 bool upIsActive = (spinBox->activeSubControls == SC_SpinBoxUp);
2458                 bool downIsActive = (spinBox->activeSubControls == SC_SpinBoxDown);
2459
2460                 QRect rect = pixmapRect;
2461                 QStyleOptionSpinBox spinBoxCopy = *spinBox;
2462                 spinBoxCopy.rect = pixmapRect;
2463                 QRect upRect = proxy()->subControlRect(CC_SpinBox, &spinBoxCopy, SC_SpinBoxUp, widget);
2464                 QRect downRect = proxy()->subControlRect(CC_SpinBox, &spinBoxCopy, SC_SpinBoxDown, widget);
2465
2466                 int fw = spinBoxCopy.frame ? proxy()->pixelMetric(PM_SpinBoxFrameWidth, &spinBoxCopy, widget) : 0;
2467                 cachePainter.fillRect(rect.adjusted(1, qMax(fw - 1, 0), -1, -fw),
2468                                       option->palette.base());
2469
2470                 QRect r = rect.adjusted(0, 1, 0, -1);
2471                 if (spinBox->frame) {
2472
2473                     QColor topShadow = darkOutline;
2474                     topShadow.setAlpha(60);
2475                     cachePainter.setPen(topShadow);
2476
2477                     // antialias corners
2478                     const QPoint points[8] = {
2479                         QPoint(r.right(), r.top() + 1),
2480                         QPoint(r.right() - 1, r.top() ),
2481                         QPoint(r.right(), r.bottom() - 1),
2482                         QPoint(r.right() - 1, r.bottom() ),
2483                         QPoint(r.left() + 1, r.bottom()),
2484                         QPoint(r.left(), r.bottom() - 1),
2485                         QPoint(r.left() + 1, r.top()),
2486                         QPoint(r.left(), r.top() + 1)
2487                     };
2488                     cachePainter.drawPoints(points, 8);
2489
2490                     // draw frame
2491                     topShadow.setAlpha(30);
2492                     cachePainter.setPen(topShadow);
2493                     cachePainter.drawLine(QPoint(r.left() + 2, r.top() - 1), QPoint(r.right() - 2, r.top() - 1));
2494
2495                     cachePainter.setPen(QPen(option->palette.background().color(), 1));
2496                     cachePainter.drawLine(QPoint(r.left() + 2, r.top() + 1), QPoint(r.right() - 2, r.top() + 1));
2497                     QColor highlight = Qt::white;
2498                     highlight.setAlpha(130);
2499                     cachePainter.setPen(option->palette.base().color().darker(120));
2500                     cachePainter.drawLine(QPoint(r.left() + 1, r.top() + 1),
2501                                   QPoint(r.right() - 1, r.top() + 1));
2502                     cachePainter.drawLine(QPoint(r.left() + 1, r.top() + 1),
2503                                   QPoint(r.left() + 1, r.bottom() - 1));
2504                     cachePainter.setPen(option->palette.base().color());
2505                     cachePainter.drawLine(QPoint(r.right() - 1, r.top() + 1),
2506                                   QPoint(r.right() - 1, r.bottom() - 1));
2507                     cachePainter.drawLine(QPoint(r.left() + 1, r.bottom() - 1),
2508                                   QPoint(r.right() - 1, r.bottom() - 1));
2509                     cachePainter.setPen(highlight);
2510                     cachePainter.drawLine(QPoint(r.left() + 3, r.bottom() + 1),
2511                                   QPoint(r.right() - 3, r.bottom() + 1));
2512
2513                     cachePainter.setPen(QPen(darkOutline, 1));
2514
2515                     // top and bottom lines
2516                     const QLine lines[4] = {
2517                         QLine(QPoint(r.left() + 2, r.bottom()), QPoint(r.right()- 2, r.bottom())),
2518                         QLine(QPoint(r.left() + 2, r.top()), QPoint(r.right() - 2, r.top())),
2519                         QLine(QPoint(r.right(), r.top() + 2), QPoint(r.right(), r.bottom() - 2)),
2520                         QLine(QPoint(r.left(), r.top() + 2), QPoint(r.left(), r.bottom() - 2))
2521                     };
2522                     cachePainter.drawLines(lines, 4);
2523                 }
2524
2525                     // gradients
2526                     qt_cleanlooks_draw_gradient(&cachePainter, upRect,
2527                                             gradientStartColor.darker(106),
2528                                             gradientStopColor, TopDown, option->palette.button());
2529                     qt_cleanlooks_draw_gradient(&cachePainter, downRect.adjusted(0, 0, 0, 1),
2530                                             gradientStartColor.darker(106),
2531                                             gradientStopColor, TopDown, option->palette.button());
2532                 if (isEnabled) {
2533                     if(upIsActive) {
2534                         if (sunken) {
2535                             cachePainter.fillRect(upRect.adjusted(1, 0, 0, 0), gradientStopColor.darker(110));
2536                         } else if (hover) {
2537                             qt_cleanlooks_draw_gradient(&cachePainter, upRect.adjusted(1, 0, 0, 0),
2538                                                     gradientStartColor.lighter(110),
2539                                                     gradientStopColor.lighter(110), TopDown, option->palette.button());
2540                         }
2541                     }
2542                     if(downIsActive) {
2543                         if (sunken) {
2544                             cachePainter.fillRect(downRect.adjusted(1, 0, 0, 1), gradientStopColor.darker(110));
2545
2546                         } else if (hover) {
2547                                 qt_cleanlooks_draw_gradient(&cachePainter, downRect.adjusted(1, 0, 0, 1),
2548                                                         gradientStartColor.lighter(110),
2549                                                         gradientStopColor.lighter(110), TopDown, option->palette.button());
2550                         }
2551                     }
2552                 }
2553
2554                 if (spinBox->frame) {
2555                     // rounded corners
2556                     const QPoint points[4] = {
2557                         QPoint(r.left() + 1, r.bottom() - 1),
2558                         QPoint(r.left() + 1, r.top() + 1),
2559                         QPoint(r.right() - 1, r.bottom() - 1),
2560                         QPoint(r.right() - 1, r.top() + 1)
2561                     };
2562                     cachePainter.drawPoints(points, 4);
2563
2564                     if (option->state & State_HasFocus) {
2565                         QColor darkoutline = option->palette.highlight().color().darker(150);