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