src/gui/styles/qwindowsstyle.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the QtGui module of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://www.trolltech.com/products/qt/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00017 ** sales department at sales@trolltech.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ****************************************************************************/
00023 
00024 #include "qwindowsstyle.h"
00025 #include "qwindowsstyle_p.h"
00026 
00027 #if !defined(QT_NO_STYLE_WINDOWS) || defined(QT_PLUGIN)
00028 
00029 #include "qapplication.h"
00030 #include "qbitmap.h"
00031 #include "qdockwidget.h"
00032 #include "qdrawutil.h" // for now
00033 #include "qevent.h"
00034 #include "qmenu.h"
00035 #include "qmenubar.h"
00036 #include "qpaintengine.h"
00037 #include "qpainter.h"
00038 #include "qprogressbar.h"
00039 #include "qrubberband.h"
00040 #include "qstyleoption.h"
00041 #include "qtabbar.h"
00042 #include "qwidget.h"
00043 #include "qdebug.h"
00044 #include "qmainwindow.h"
00045 #include "qfile.h"
00046 #include "qtextstream.h"
00047 #include "qpixmapcache.h"
00048 
00049 #ifdef Q_WS_X11
00050 #include "qfileinfo.h"
00051 #include "qdir.h"
00052 #include <private/qt_x11_p.h>
00053 #endif
00054 
00055 #if defined(Q_WS_WIN)
00056 #include "qt_windows.h"
00057 #  ifndef COLOR_GRADIENTACTIVECAPTION
00058 #    define COLOR_GRADIENTACTIVECAPTION     27
00059 #  endif
00060 #  ifndef COLOR_GRADIENTINACTIVECAPTION
00061 #    define COLOR_GRADIENTINACTIVECAPTION   28
00062 #  endif
00063 #endif
00064 
00065 #include <limits.h>
00066 
00067 static const int windowsItemFrame        =  2; // menu item frame width
00068 static const int windowsSepHeight        =  9; // separator item height
00069 static const int windowsItemHMargin      =  3; // menu item hor text margin
00070 static const int windowsItemVMargin      =  2; // menu item ver text margin
00071 static const int windowsArrowHMargin   =  6; // arrow horizontal margin
00072 static const int windowsTabSpacing   = 12; // space between text and tab
00073 static const int windowsCheckMarkHMargin =  2; // horiz. margins of check mark
00074 static const int windowsRightBorder      = 15; // right border on windows
00075 static const int windowsCheckMarkWidth   = 12; // checkmarks width on windows
00076 
00077 static bool use2000style = true;
00078 
00079 enum QSliderDirection { SlUp, SlDown, SlLeft, SlRight };
00080 
00081 /*
00082     \internal
00083 */
00084 QWindowsStylePrivate::QWindowsStylePrivate()
00085     : alt_down(false), menuBarTimer(0), animationFps(10), animateTimer(0), animateStep(0)
00086 {
00087 }
00088 
00089 // Returns true if the toplevel parent of \a widget has seen the Alt-key
00090 bool QWindowsStylePrivate::hasSeenAlt(const QWidget *widget) const
00091 {
00092     widget = widget->window();
00093     return seenAlt.contains(widget);
00094 }
00095 
00099 void QWindowsStyle::timerEvent(QTimerEvent *event)
00100 {
00101 #ifndef QT_NO_PROGRESSBAR
00102     Q_D(QWindowsStyle);
00103     if (event->timerId() == d->animateTimer) {
00104         Q_ASSERT(d->animationFps> 0);
00105         d->animateStep = d->startTime.elapsed() / (1000 / d->animationFps);
00106         foreach (QProgressBar *bar, d->bars) {
00107             if ((bar->minimum() == 0 && bar->maximum() == 0))
00108                 bar->update();
00109         }
00110     }
00111 #endif // QT_NO_PROGRESSBAR
00112     event->ignore();
00113 }
00114 
00118 bool QWindowsStyle::eventFilter(QObject *o, QEvent *e)
00119 {
00120     // Records Alt- and Focus events
00121     if (!o->isWidgetType())
00122         return QObject::eventFilter(o, e);
00123 
00124     QWidget *widget = ::qobject_cast<QWidget*>(o);
00125     Q_D(QWindowsStyle);
00126     switch(e->type()) {
00127     case QEvent::KeyPress:
00128         if (static_cast<QKeyEvent *>(e)->key() == Qt::Key_Alt) {
00129             widget = widget->window();
00130 
00131             // Alt has been pressed - find all widgets that care
00132             QList<QWidget *> l = qFindChildren<QWidget *>(widget);
00133             for (int pos=0 ; pos < l.size() ; ++pos) {
00134                 QWidget *w = l.at(pos);
00135                 if (w->isWindow() || !w->isVisible() ||
00136                     w->style()->styleHint(SH_UnderlineShortcut, 0, w))
00137                     l.removeAt(pos);
00138             }
00139             // Update states before repainting
00140             d->seenAlt.append(widget);
00141             d->alt_down = true;
00142 
00143             // Repaint all relevant widgets
00144             for (int pos = 0; pos < l.size(); ++pos)
00145                 l.at(pos)->update();
00146         }
00147         break;
00148     case QEvent::KeyRelease:
00149   if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_Alt) {
00150       widget = widget->window();
00151 
00152       // Update state and repaint the menubars.
00153       d->alt_down = false;
00154 #ifndef QT_NO_MENUBAR
00155             QList<QMenuBar *> l = qFindChildren<QMenuBar *>(widget);
00156             for (int i = 0; i < l.size(); ++i)
00157                 l.at(i)->update();
00158 #endif
00159   }
00160   break;
00161     case QEvent::Close:
00162         // Reset widget when closing
00163         d->seenAlt.removeAll(widget);
00164         d->seenAlt.removeAll(widget->window());
00165         break;
00166 #ifndef QT_NO_PROGRESSBAR
00167     case QEvent::StyleChange:
00168     case QEvent::Show:
00169         if (QProgressBar *bar = qobject_cast<QProgressBar *>(o)) {
00170             d->bars << bar;
00171             if (d->bars.size() == 1) {
00172                 Q_ASSERT(d->animationFps> 0);
00173                 d->animateTimer = startTimer(1000 / d->animationFps);
00174             }
00175         }
00176         break;
00177     case QEvent::Destroy:
00178     case QEvent::Hide:
00179         // reinterpret_cast because there is no type info when getting
00180         // the destroy event. We know that it is a QProgressBar.
00181         if (QProgressBar *bar = reinterpret_cast<QProgressBar *>(o)) {
00182             d->bars.removeAll(bar);
00183             if (d->bars.isEmpty() && d->animateTimer) {
00184                 killTimer(d->animateTimer);
00185                 d->animateTimer = 0;
00186             }
00187         }
00188         break;
00189 #endif // QT_NO_PROGRESSBAR
00190     default:
00191         break;
00192     }
00193     return QCommonStyle::eventFilter(o, e);
00194 }
00195 
00211 QWindowsStyle::QWindowsStyle() : QCommonStyle(*new QWindowsStylePrivate)
00212 {
00213 #if defined(Q_OS_WIN32)
00214     use2000style = QSysInfo::WindowsVersion != QSysInfo::WV_NT && QSysInfo::WindowsVersion != QSysInfo::WV_95;
00215 #endif
00216 }
00217 
00223 QWindowsStyle::QWindowsStyle(QWindowsStylePrivate &dd) : QCommonStyle(dd)
00224 {
00225 #if defined(Q_OS_WIN32)
00226     use2000style = QSysInfo::WindowsVersion != QSysInfo::WV_NT && QSysInfo::WindowsVersion != QSysInfo::WV_95;
00227 #endif
00228 }
00229 
00230 
00232 QWindowsStyle::~QWindowsStyle()
00233 {
00234 }
00235 
00236 #ifdef Q_WS_WIN
00237 static inline QRgb colorref2qrgb(COLORREF col)
00238 {
00239     return qRgb(GetRValue(col), GetGValue(col), GetBValue(col));
00240 }
00241 #endif
00242 
00244 void QWindowsStyle::polish(QApplication *app)
00245 {
00246     QWindowsStylePrivate *d = const_cast<QWindowsStylePrivate*>(d_func());
00247     // We only need the overhead when shortcuts are sometimes hidden
00248     if (!styleHint(SH_UnderlineShortcut, 0) && app)
00249         app->installEventFilter(this);
00250 
00251     d->activeCaptionColor = app->palette().highlight().color();
00252     d->activeGradientCaptionColor = app->palette().highlight() .color();
00253     d->inactiveCaptionColor = app->palette().dark().color();
00254     d->inactiveGradientCaptionColor = app->palette().dark().color();
00255     d->inactiveCaptionText = app->palette().background().color();
00256 
00257 #if defined(Q_WS_WIN) //fetch native titlebar colors
00258     if(app->desktopSettingsAware()){
00259         DWORD activeCaption = GetSysColor(COLOR_ACTIVECAPTION);
00260         DWORD gradientActiveCaption = GetSysColor(COLOR_GRADIENTACTIVECAPTION);
00261         DWORD inactiveCaption = GetSysColor(COLOR_INACTIVECAPTION);
00262         DWORD gradientInactiveCaption = GetSysColor(COLOR_GRADIENTINACTIVECAPTION);
00263         DWORD inactiveCaptionText = GetSysColor(COLOR_INACTIVECAPTIONTEXT);
00264         d->activeCaptionColor = colorref2qrgb(activeCaption);
00265         d->activeGradientCaptionColor = colorref2qrgb(gradientActiveCaption);
00266         d->inactiveCaptionColor = colorref2qrgb(inactiveCaption);
00267         d->inactiveGradientCaptionColor = colorref2qrgb(gradientInactiveCaption);
00268         d->inactiveCaptionText = colorref2qrgb(inactiveCaptionText);
00269     }
00270 #endif
00271 }
00272 
00274 void QWindowsStyle::unpolish(QApplication *app)
00275 {
00276     app->removeEventFilter(this);
00277 }
00278 
00280 void QWindowsStyle::polish(QWidget *widget)
00281 {
00282     QCommonStyle::polish(widget);
00283 #ifndef QT_NO_PROGRESSBAR
00284     if (qobject_cast<QProgressBar *>(widget))
00285         widget->installEventFilter(this);
00286 #endif
00287 }
00288 
00290 void QWindowsStyle::unpolish(QWidget *widget)
00291 {
00292     QCommonStyle::unpolish(widget);
00293 #ifndef QT_NO_PROGRESSBAR
00294     if (qobject_cast<QProgressBar *>(widget))
00295         widget->removeEventFilter(this);
00296 #endif
00297 }
00298 
00300 void QWindowsStyle::polish(QPalette &pal)
00301 {
00302     QCommonStyle::polish(pal);
00303 }
00304 
00308 int QWindowsStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt, const QWidget *widget) const
00309 {
00310     int ret;
00311 
00312     switch (pm) {
00313     case PM_ButtonDefaultIndicator:
00314     case PM_ButtonShiftHorizontal:
00315     case PM_ButtonShiftVertical:
00316         ret = 1;
00317         break;
00318 #ifndef QT_NO_TABBAR
00319     case PM_TabBarTabShiftHorizontal:
00320         ret = 0;
00321         break;
00322     case PM_TabBarTabShiftVertical:
00323         ret = 2;
00324         break;
00325 #endif
00326     case PM_MaximumDragDistance:
00327         ret = 60;
00328         break;
00329 
00330 #ifndef QT_NO_SLIDER
00331     case PM_SliderLength:
00332         ret = 11;
00333         break;
00334 
00335         // Returns the number of pixels to use for the business part of the
00336         // slider (i.e., the non-tickmark portion). The remaining space is shared
00337         // equally between the tickmark regions.
00338     case PM_SliderControlThickness:
00339         if (const QStyleOptionSlider *sl = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
00340             int space = (sl->orientation == Qt::Horizontal) ? sl->rect.height() : sl->rect.width();
00341             int ticks = sl->tickPosition;
00342             int n = 0;
00343             if (ticks & QSlider::TicksAbove)
00344                 ++n;
00345             if (ticks & QSlider::TicksBelow)
00346                 ++n;
00347             if (!n) {
00348                 ret = space;
00349                 break;
00350             }
00351 
00352             int thick = 6;        // Magic constant to get 5 + 16 + 5
00353             if (ticks != QSlider::TicksBothSides && ticks != QSlider::NoTicks)
00354                 thick += pixelMetric(PM_SliderLength, sl, widget) / 4;
00355 
00356             space -= thick;
00357             if (space > 0)
00358                 thick += (space * 2) / (n + 2);
00359             ret = thick;
00360         } else {
00361             ret = 0;
00362         }
00363         break;
00364 #endif // QT_NO_SLIDER
00365 
00366 #ifndef QT_NO_MENU
00367     case PM_MenuBarHMargin:
00368         ret = 0;
00369         break;
00370 
00371     case PM_MenuBarVMargin:
00372         ret = 0;
00373         break;
00374 
00375     case PM_MenuBarPanelWidth:
00376         ret = 0;
00377         break;
00378 
00379     case PM_SmallIconSize:
00380         ret = 16;
00381         break;
00382 
00383     case PM_LargeIconSize:
00384         ret = 32;
00385         break;
00386 
00387     case PM_IconViewIconSize:
00388         ret = pixelMetric(PM_LargeIconSize, opt, widget);
00389         break;
00390 
00391     case PM_ToolBarIconSize:
00392         ret = 24;
00393         break;
00394     case PM_DockWidgetTitleMargin:
00395         ret = 3;
00396         break;
00397 #if defined(Q_WS_WIN)
00398     case PM_DockWidgetFrameWidth:
00399         ret = GetSystemMetrics(SM_CXFRAME);
00400         break;
00401 #else
00402     case PM_DockWidgetFrameWidth:
00403         ret = 4;
00404         break;
00405 #endif // Q_WS_WIN
00406     break;
00407 
00408 #endif // QT_NO_MENU
00409 
00410 
00411 #if defined(Q_WS_WIN)
00412     case PM_TitleBarHeight:
00413         if (widget && (widget->windowType() == Qt::Tool)) {
00414             // MS always use one less than they say
00415 #if defined(Q_OS_TEMP)
00416             ret = GetSystemMetrics(SM_CYCAPTION) - 1;
00417 #else
00418             ret = GetSystemMetrics(SM_CYSMCAPTION) - 1;
00419 #endif
00420         } else {
00421             ret = GetSystemMetrics(SM_CYCAPTION) - 1;
00422         }
00423 
00424         break;
00425 
00426     case PM_ScrollBarExtent:
00427         {
00428 #ifndef Q_OS_TEMP
00429             NONCLIENTMETRICS ncm;
00430             ncm.cbSize = sizeof(NONCLIENTMETRICS);
00431             if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0))
00432                 ret = qMax(ncm.iScrollHeight, ncm.iScrollWidth);
00433             else
00434 #endif
00435                 ret = QCommonStyle::pixelMetric(pm, opt, widget);
00436         }
00437         break;
00438 #endif // Q_WS_WIN
00439 
00440     case PM_SplitterWidth:
00441         ret = qMax(4, QApplication::globalStrut().width());
00442         break;
00443 
00444 #if defined(Q_WS_WIN)
00445     case PM_MDIFrameWidth:
00446         ret = GetSystemMetrics(SM_CYFRAME);
00447         break;
00448 #endif
00449     case PM_ToolBarItemMargin:
00450         ret = 1;
00451         break;
00452     case PM_ToolBarItemSpacing:
00453         ret = 0;
00454         break;
00455     case PM_ToolBarHandleExtent:
00456         ret = 10;
00457         break;
00458     default:
00459         ret = QCommonStyle::pixelMetric(pm, opt, widget);
00460         break;
00461     }
00462 
00463     return ret;
00464 }
00465 
00466 #ifndef QT_NO_IMAGEFORMAT_XPM
00467 
00468 static const char * const qt_menu_xpm[] = {
00469 "16 16 11 1",
00470 "  c #000000",
00471 ", c #336600",
00472 ". c #99CC00",
00473 "X c #666600",
00474 "o c #999933",
00475 "+ c #333300",
00476 "@ c #669900",
00477 "# c #999900",
00478 "$ c #336633",
00479 "% c #666633",
00480 "& c #99CC33",
00481 "................",
00482 "................",
00483 ".....#,++X#.....",
00484 "....X      X....",
00485 "...X  Xo#%  X&..",
00486 "..#  o..&@o  o..",
00487 ".., X..#+ @X X..",
00488 "..+ o.o+ +o# +..",
00489 "..+ #o+  +## +..",
00490 ".., %@ ++ +, X..",
00491 "..#  o@oo+   #..",
00492 "...X  X##$   o..",
00493 "....X        X..",
00494 "....&oX++X#oX...",
00495 "................",
00496 "................"};
00497 
00498 static const char * const qt_close_xpm[] = {
00499 "10 10 2 1",
00500 "# c #000000",
00501 ". c None",
00502 "..........",
00503 ".##....##.",
00504 "..##..##..",
00505 "...####...",
00506 "....##....",
00507 "...####...",
00508 "..##..##..",
00509 ".##....##.",
00510 "..........",
00511 ".........."};
00512 
00513 static const char * const qt_maximize_xpm[]={
00514 "10 10 2 1",
00515 "# c #000000",
00516 ". c None",
00517 "#########.",
00518 "#########.",
00519 "#.......#.",
00520 "#.......#.",
00521 "#.......#.",
00522 "#.......#.",
00523 "#.......#.",
00524 "#.......#.",
00525 "#########.",
00526 ".........."};
00527 
00528 static const char * const qt_minimize_xpm[] = {
00529 "10 10 2 1",
00530 "# c #000000",
00531 ". c None",
00532 "..........",
00533 "..........",
00534 "..........",
00535 "..........",
00536 "..........",
00537 "..........",
00538 "..........",
00539 ".#######..",
00540 ".#######..",
00541 ".........."};
00542 
00543 static const char * const qt_normalizeup_xpm[] = {
00544 "10 10 2 1",
00545 "# c #000000",
00546 ". c None",
00547 "...######.",
00548 "...######.",
00549 "...#....#.",
00550 ".######.#.",
00551 ".######.#.",
00552 ".#....###.",
00553 ".#....#...",
00554 ".#....#...",
00555 ".######...",
00556 ".........."};
00557 
00558 static const char * const qt_help_xpm[] = {
00559 "10 10 2 1",
00560 ". c None",
00561 "# c #000000",
00562 "..........",
00563 "..######..",
00564 ".##....##.",
00565 "......##..",
00566 ".....##...",
00567 "....##....",
00568 "....##....",
00569 "..........",
00570 "....##....",
00571 ".........."};
00572 
00573 static const char * const qt_shade_xpm[] = {
00574 "10 10 2 1",
00575 "# c #000000",
00576 ". c None",
00577 "..........",
00578 "..........",
00579 "..........",
00580 "..........",
00581 "....#.....",
00582 "...###....",
00583 "..#####...",
00584 ".#######..",
00585 "..........",
00586 ".........."};
00587 
00588 static const char * const qt_unshade_xpm[] = {
00589 "10 10 2 1",
00590 "# c #000000",
00591 ". c None",
00592 "..........",
00593 "..........",
00594 "..........",
00595 ".#######..",
00596 "..#####...",
00597 "...###....",
00598 "....#.....",
00599 "..........",
00600 "..........",
00601 ".........."};
00602 
00603 static const char * dock_widget_close_xpm[] = {
00604 "8 8 2 1",
00605 "# c #000000",
00606 ". c None",
00607 "........",
00608 ".##..##.",
00609 "..####..",
00610 "...##...",
00611 "..####..",
00612 ".##..##.",
00613 "........",
00614 "........"};
00615 
00616 /* XPM */
00617 static const char * const information_xpm[]={
00618 "32 32 5 1",
00619 ". c None",
00620 "c c #000000",
00621 "* c #999999",
00622 "a c #ffffff",
00623 "b c #0000ff",
00624 "...........********.............",
00625 "........***aaaaaaaa***..........",
00626 "......**aaaaaaaaaaaaaa**........",
00627 ".....*aaaaaaaaaaaaaaaaaa*.......",
00628 "....*aaaaaaaabbbbaaaaaaaac......",
00629 "...*aaaaaaaabbbbbbaaaaaaaac.....",
00630 "..*aaaaaaaaabbbbbbaaaaaaaaac....",
00631 ".*aaaaaaaaaaabbbbaaaaaaaaaaac...",
00632 ".*aaaaaaaaaaaaaaaaaaaaaaaaaac*..",
00633 "*aaaaaaaaaaaaaaaaaaaaaaaaaaaac*.",
00634 "*aaaaaaaaaabbbbbbbaaaaaaaaaaac*.",
00635 "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
00636 "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
00637 "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
00638 "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
00639 "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
00640 ".*aaaaaaaaaaabbbbbaaaaaaaaaac***",
00641 ".*aaaaaaaaaaabbbbbaaaaaaaaaac***",
00642 "..*aaaaaaaaaabbbbbaaaaaaaaac***.",
00643 "...caaaaaaabbbbbbbbbaaaaaac****.",
00644 "....caaaaaaaaaaaaaaaaaaaac****..",
00645 ".....caaaaaaaaaaaaaaaaaac****...",
00646 "......ccaaaaaaaaaaaaaacc****....",
00647 ".......*cccaaaaaaaaccc*****.....",
00648 "........***cccaaaac*******......",
00649 "..........****caaac*****........",
00650 ".............*caaac**...........",
00651 "...............caac**...........",
00652 "................cac**...........",
00653 ".................cc**...........",
00654 "..................***...........",
00655 "...................**..........."};
00656 /* XPM */
00657 static const char* const warning_xpm[]={
00658 "32 32 4 1",
00659 ". c None",
00660 "a c #ffff00",
00661 "* c #000000",
00662 "b c #999999",
00663 ".............***................",
00664 "............*aaa*...............",
00665 "...........*aaaaa*b.............",
00666 "...........*aaaaa*bb............",
00667 "..........*aaaaaaa*bb...........",
00668 "..........*aaaaaaa*bb...........",
00669 ".........*aaaaaaaaa*bb..........",
00670 ".........*aaaaaaaaa*bb..........",
00671 "........*aaaaaaaaaaa*bb.........",
00672 "........*aaaa***aaaa*bb.........",
00673 ".......*aaaa*****aaaa*bb........",
00674 ".......*aaaa*****aaaa*bb........",
00675 "......*aaaaa*****aaaaa*bb.......",
00676 "......*aaaaa*****aaaaa*bb.......",
00677 ".....*aaaaaa*****aaaaaa*bb......",
00678 ".....*aaaaaa*****aaaaaa*bb......",
00679 "....*aaaaaaaa***aaaaaaaa*bb.....",
00680 "....*aaaaaaaa***aaaaaaaa*bb.....",
00681 "...*aaaaaaaaa***aaaaaaaaa*bb....",
00682 "...*aaaaaaaaaa*aaaaaaaaaa*bb....",
00683 "..*aaaaaaaaaaa*aaaaaaaaaaa*bb...",
00684 "..*aaaaaaaaaaaaaaaaaaaaaaa*bb...",
00685 ".*aaaaaaaaaaaa**aaaaaaaaaaa*bb..",
00686 ".*aaaaaaaaaaa****aaaaaaaaaa*bb..",
00687 "*aaaaaaaaaaaa****aaaaaaaaaaa*bb.",
00688 "*aaaaaaaaaaaaa**aaaaaaaaaaaa*bb.",
00689 "*aaaaaaaaaaaaaaaaaaaaaaaaaaa*bbb",
00690 "*aaaaaaaaaaaaaaaaaaaaaaaaaaa*bbb",
00691 ".*aaaaaaaaaaaaaaaaaaaaaaaaa*bbbb",
00692 "..*************************bbbbb",
00693 "....bbbbbbbbbbbbbbbbbbbbbbbbbbb.",
00694 ".....bbbbbbbbbbbbbbbbbbbbbbbbb.."};
00695 /* XPM */
00696 static const char* const critical_xpm[]={
00697 "32 32 4 1",
00698 ". c None",
00699 "a c #999999",
00700 "* c #ff0000",
00701 "b c #ffffff",
00702 "...........********.............",
00703 ".........************...........",
00704 ".......****************.........",
00705 "......******************........",
00706 ".....********************a......",
00707 "....**********************a.....",
00708 "...************************a....",
00709 "..*******b**********b*******a...",
00710 "..******bbb********bbb******a...",
00711 ".******bbbbb******bbbbb******a..",
00712 ".*******bbbbb****bbbbb*******a..",
00713 "*********bbbbb**bbbbb*********a.",
00714 "**********bbbbbbbbbb**********a.",
00715 "***********bbbbbbbb***********aa",
00716 "************bbbbbb************aa",
00717 "************bbbbbb************aa",
00718 "***********bbbbbbbb***********aa",
00719 "**********bbbbbbbbbb**********aa",
00720 "*********bbbbb**bbbbb*********aa",
00721 ".*******bbbbb****bbbbb*******aa.",
00722 ".******bbbbb******bbbbb******aa.",
00723 "..******bbb********bbb******aaa.",
00724 "..*******b**********b*******aa..",
00725 "...************************aaa..",
00726 "....**********************aaa...",
00727 "....a********************aaa....",
00728 ".....a******************aaa.....",
00729 "......a****************aaa......",
00730 ".......aa************aaaa.......",
00731 ".........aa********aaaaa........",
00732 "...........aaaaaaaaaaa..........",
00733 ".............aaaaaaa............"};
00734 /* XPM */
00735 static const char *const question_xpm[] = {
00736 "32 32 5 1",
00737 ". c None",
00738 "c c #000000",
00739 "* c #999999",
00740 "a c #ffffff",
00741 "b c #0000ff",
00742 "...........********.............",
00743 "........***aaaaaaaa***..........",
00744 "......**aaaaaaaaaaaaaa**........",
00745 ".....*aaaaaaaaaaaaaaaaaa*.......",
00746 "....*aaaaaaaaaaaaaaaaaaaac......",
00747 "...*aaaaaaaabbbbbbaaaaaaaac.....",
00748 "..*aaaaaaaabaaabbbbaaaaaaaac....",
00749 ".*aaaaaaaabbaaaabbbbaaaaaaaac...",
00750 ".*aaaaaaaabbbbaabbbbaaaaaaaac*..",
00751 "*aaaaaaaaabbbbaabbbbaaaaaaaaac*.",
00752 "*aaaaaaaaaabbaabbbbaaaaaaaaaac*.",
00753 "*aaaaaaaaaaaaabbbbaaaaaaaaaaac**",
00754 "*aaaaaaaaaaaaabbbaaaaaaaaaaaac**",
00755 "*aaaaaaaaaaaaabbaaaaaaaaaaaaac**",
00756 "*aaaaaaaaaaaaabbaaaaaaaaaaaaac**",
00757 "*aaaaaaaaaaaaaaaaaaaaaaaaaaaac**",
00758 ".*aaaaaaaaaaaabbaaaaaaaaaaaac***",
00759 ".*aaaaaaaaaaabbbbaaaaaaaaaaac***",
00760 "..*aaaaaaaaaabbbbaaaaaaaaaac***.",
00761 "...caaaaaaaaaabbaaaaaaaaaac****.",
00762 "....caaaaaaaaaaaaaaaaaaaac****..",
00763 ".....caaaaaaaaaaaaaaaaaac****...",
00764 "......ccaaaaaaaaaaaaaacc****....",
00765 ".......*cccaaaaaaaaccc*****.....",
00766 "........***cccaaaac*******......",
00767 "..........****caaac*****........",
00768 ".............*caaac**...........",
00769 "...............caac**...........",
00770 "................cac**...........",
00771 ".................cc**...........",
00772 "..................***...........",
00773 "...................**..........."};
00774 
00775 #endif //QT_NO_IMAGEFORMAT_XPM
00776 
00777 #ifdef Q_WS_WIN
00778 QPixmap convertHIconToPixmap( const HICON icon)
00779 {
00780     bool foundAlpha = false;
00781     HDC screenDevice = qt_win_display_dc();
00782     HDC hdc = CreateCompatibleDC(screenDevice);
00783 
00784     ICONINFO iconinfo;
00785     GetIconInfo(icon, &iconinfo); //x and y Hotspot describes the icon center
00786     
00787     BITMAPINFOHEADER bitmapInfo;
00788     bitmapInfo.biSize        = sizeof(BITMAPINFOHEADER);
00789     bitmapInfo.biWidth       = iconinfo.xHotspot * 2;
00790     bitmapInfo.biHeight      = iconinfo.yHotspot * 2;
00791     bitmapInfo.biPlanes      = 1;
00792     bitmapInfo.biBitCount    = 32;
00793     bitmapInfo.biCompression = BI_RGB;
00794     bitmapInfo.biSizeImage   = 0;
00795     bitmapInfo.biXPelsPerMeter = 0;
00796     bitmapInfo.biYPelsPerMeter = 0;
00797     bitmapInfo.biClrUsed       = 0;
00798     bitmapInfo.biClrImportant  = 0;
00799     DWORD* bits;
00800 
00801     HBITMAP winBitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bitmapInfo, DIB_RGB_COLORS, (VOID**)&bits, NULL, 0);
00802     HGDIOBJ oldhdc = (HBITMAP)SelectObject(hdc, winBitmap);
00803     DrawIconEx( hdc, 0, 0, icon, iconinfo.xHotspot * 2, iconinfo.yHotspot * 2, 0, 0, DI_NORMAL);
00804     
00805     QPixmap::HBitmapFormat alphaType = QPixmap::PremultipliedAlpha;
00806     QPixmap iconpixmap = QPixmap::fromWinHBITMAP(winBitmap, alphaType);
00807     QImage img = iconpixmap.toImage();
00808 
00809     for (int y = 0 ; y < iconpixmap.height() && !foundAlpha ; y++) {
00810         QRgb *scanLine= reinterpret_cast<QRgb *>(img.scanLine(y));
00811         for (int x = 0; x < img.width() ; x++) {
00812             if (qAlpha(scanLine[x]) != 0) {
00813                 foundAlpha = true;
00814                 break;
00815             }
00816         }
00817     }
00818 
00819     if (!foundAlpha) {
00820         //If no alpha was found, we use the mask to set alpha values
00821         DrawIconEx( hdc, 0, 0, icon, iconinfo.xHotspot * 2, iconinfo.yHotspot * 2, 0, 0, DI_MASK);
00822         QPixmap maskPixmap = QPixmap::fromWinHBITMAP(winBitmap, alphaType);
00823         QImage mask = maskPixmap.toImage();
00824 
00825         for (int y = 0 ; y< iconpixmap.height() ; y++){
00826             QRgb *scanlineImage = reinterpret_cast<QRgb *>(img.scanLine(y));
00827             QRgb *scanlineMask = reinterpret_cast<QRgb *>(mask.scanLine(y));
00828             for (int x = 0; x < img.width() ; x++){
00829                 if (qRed(scanlineMask[x]) != 0)
00830                     scanlineImage[x] = 0; //mask out this pixel
00831                 else
00832                     scanlineImage[x] |= 0xff000000; // set the alpha channel to 255
00833             }
00834         }
00835     }
00836 
00837     //dispose resources created by iconinfo call
00838     DeleteObject(iconinfo.hbmMask);
00839     DeleteObject(iconinfo.hbmColor);
00840 
00841     SelectObject(hdc, oldhdc); //restore state
00842     DeleteObject(winBitmap);
00843     DeleteDC(hdc);
00844     return QPixmap::fromImage(img);
00845 }
00846 
00847 QPixmap loadIconFromShell32( int resourceId, int size )
00848 {
00849     HMODULE hmod = LoadLibraryA("shell32.dll");
00850     if( hmod ) {
00851         HICON iconHandle = (HICON)LoadImage(hmod, MAKEINTRESOURCE(resourceId), IMAGE_ICON, size, size, 0);
00852         if( iconHandle ) {
00853             QPixmap iconpixmap = convertHIconToPixmap( iconHandle );
00854             DestroyIcon(iconHandle);
00855             return iconpixmap;
00856         }
00857     }
00858     return QPixmap();
00859 }
00860 #endif
00861 
00865 QPixmap QWindowsStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt,
00866                                       const QWidget *widget) const
00867 {
00868 #ifdef Q_WS_WIN
00869     QPixmap desktopIcon;
00870     switch(standardPixmap) {
00871     case SP_DriveCDIcon:
00872     case SP_DriveDVDIcon:
00873         {
00874             desktopIcon = loadIconFromShell32(12, 16);
00875             break;
00876         }
00877     case SP_DriveNetIcon:
00878         {
00879             desktopIcon = loadIconFromShell32(10, 16);
00880             break;
00881         }
00882     case SP_DriveHDIcon:
00883         {
00884             desktopIcon = loadIconFromShell32(9, 16);
00885             break;
00886         }
00887     case SP_DriveFDIcon:
00888         {
00889             desktopIcon = loadIconFromShell32(7, 16);
00890             break;
00891         }
00892     case SP_FileIcon:
00893         {
00894             desktopIcon = loadIconFromShell32(1, 16);
00895             break;
00896         }
00897     case SP_FileLinkIcon:
00898         {
00899             desktopIcon = loadIconFromShell32(1, 16);
00900             QPainter painter(&desktopIcon);
00901             QPixmap link = loadIconFromShell32(30, 16);
00902             painter.drawPixmap(0, 0, 16, 16, link);
00903             break;
00904         }
00905     case SP_DirLinkIcon:
00906         {
00907             desktopIcon = loadIconFromShell32(4, 16);
00908             QPainter painter(&desktopIcon);
00909             QPixmap link = loadIconFromShell32(30, 16);
00910             painter.drawPixmap(0, 0, 16, 16, link);
00911             break;
00912         }
00913     case SP_DirClosedIcon:
00914         {
00915             desktopIcon = loadIconFromShell32(4, 16);
00916             break;
00917         }
00918     case SP_DesktopIcon:
00919         {
00920             desktopIcon = loadIconFromShell32(35, 16);
00921             break;
00922         }
00923     case SP_ComputerIcon:
00924         {
00925             desktopIcon = loadIconFromShell32(16, 16);
00926             break;
00927         }
00928     case SP_DirOpenIcon:
00929         {
00930             desktopIcon = loadIconFromShell32(5, 16);
00931             break;
00932         }
00933     case SP_FileDialogNewFolder:
00934         {
00935             desktopIcon = loadIconFromShell32(319, 16);
00936             break;
00937         }
00938     case SP_TrashIcon:
00939         {
00940             desktopIcon = loadIconFromShell32(191, 16);
00941             break;
00942         }
00943     case SP_MessageBoxInformation:
00944         {
00945             HICON iconHandle = LoadIcon(NULL, IDI_INFORMATION);
00946             desktopIcon = convertHIconToPixmap( iconHandle );
00947             DestroyIcon(iconHandle);
00948             break;
00949         }
00950     case SP_MessageBoxWarning:
00951         {
00952             HICON iconHandle = LoadIcon(NULL, IDI_WARNING);
00953             desktopIcon = convertHIconToPixmap( iconHandle );
00954             DestroyIcon(iconHandle);
00955             break;
00956         }
00957     case SP_MessageBoxCritical:
00958         {
00959             HICON iconHandle = LoadIcon(NULL, IDI_ERROR);
00960             desktopIcon = convertHIconToPixmap( iconHandle );
00961             DestroyIcon(iconHandle);
00962             break;
00963         }
00964     case SP_MessageBoxQuestion:
00965         {
00966             HICON iconHandle = LoadIcon(NULL, IDI_QUESTION);
00967             desktopIcon = convertHIconToPixmap( iconHandle );
00968             DestroyIcon(iconHandle);
00969             break;
00970         }
00971     }
00972     if (!desktopIcon.isNull()) {
00973         return desktopIcon;
00974     }
00975 #endif
00976 #ifndef QT_NO_IMAGEFORMAT_XPM
00977     switch (standardPixmap) {
00978     case SP_TitleBarMenuButton:
00979         return QPixmap(qt_menu_xpm);
00980     case SP_TitleBarShadeButton:
00981         return QPixmap(qt_shade_xpm);
00982     case SP_TitleBarUnshadeButton:
00983         return QPixmap(qt_unshade_xpm);
00984     case SP_TitleBarNormalButton:
00985         return QPixmap(qt_normalizeup_xpm);
00986     case SP_TitleBarMinButton:
00987         return QPixmap(qt_minimize_xpm);
00988     case SP_TitleBarMaxButton:
00989         return QPixmap(qt_maximize_xpm);
00990     case SP_TitleBarCloseButton:
00991         return QPixmap(qt_close_xpm);
00992     case SP_TitleBarContextHelpButton:
00993         return QPixmap(qt_help_xpm);
00994     case SP_DockWidgetCloseButton:
00995         return QPixmap(dock_widget_close_xpm);
00996     case SP_MessageBoxInformation:
00997         return QPixmap(information_xpm);
00998     case SP_MessageBoxWarning:
00999         return QPixmap(warning_xpm);
01000     case SP_MessageBoxCritical:
01001         return QPixmap(critical_xpm);
01002     case SP_MessageBoxQuestion:
01003         return QPixmap(question_xpm);
01004     default:
01005         break;
01006     }
01007 #endif //QT_NO_IMAGEFORMAT_XPM
01008     return QCommonStyle::standardPixmap(standardPixmap, opt, widget);
01009 }
01010 
01012 int QWindowsStyle::styleHint(StyleHint hint, const QStyleOption *opt, const QWidget *widget,
01013                              QStyleHintReturn *returnData) const
01014 {
01015     int ret = 0;
01016 
01017     switch (hint) {
01018     case SH_EtchDisabledText:
01019     case SH_Slider_SnapToValue:
01020     case SH_PrintDialog_RightAlignButtons:
01021     case SH_FontDialog_SelectAssociatedText:
01022     case SH_Menu_AllowActiveAndDisabled:
01023     case SH_MenuBar_AltKeyNavigation:
01024     case SH_MenuBar_MouseTracking:
01025     case SH_Menu_MouseTracking:
01026     case SH_ComboBox_ListMouseTracking:
01027     case SH_ScrollBar_StopMouseOverSlider:
01028     case SH_MainWindow_SpaceBelowMenuBar:
01029         ret = 1;
01030 
01031         break;
01032     case SH_ItemView_ChangeHighlightOnFocus:
01033 #if defined(Q_WS_WIN)
01034         if (QSysInfo::WindowsVersion != QSysInfo::WV_95 && QSysInfo::WindowsVersion != QSysInfo::WV_NT)
01035             ret = 1;
01036         else
01037 #endif
01038             ret = 0;
01039         break;
01040     case SH_ToolBox_SelectedPageTitleBold:
01041         ret = 0;
01042         break;
01043 
01044 #if defined(Q_WS_WIN)
01045     case SH_UnderlineShortcut:
01046         ret = 1;
01047         if (QSysInfo::WindowsVersion != QSysInfo::WV_95
01048             && QSysInfo::WindowsVersion != QSysInfo::WV_98
01049             && QSysInfo::WindowsVersion != QSysInfo::WV_NT) {
01050             BOOL cues;
01051             SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &cues, 0);
01052             ret = int(cues);
01053             // Do nothing if we always paint underlines
01054             Q_D(const QWindowsStyle);
01055             if (!ret && widget && d) {
01056 #ifndef QT_NO_MENUBAR
01057                 const QMenuBar *menuBar = ::qobject_cast<const QMenuBar*>(widget);
01058                 if (!menuBar && ::qobject_cast<const QMenu *>(widget)) {
01059                     QWidget *w = QApplication::activeWindow();
01060                     if (w && w != widget)
01061                         menuBar = qFindChild<QMenuBar *>(w);
01062                 }
01063                 // If we paint a menubar draw underlines if it has focus, or if alt is down,
01064                 // or if a popup menu belonging to the menubar is active and paints underlines
01065                 if (menuBar) {
01066                     if (menuBar->hasFocus() || d->altDown())
01067                         ret = 1;
01068                     // Otherwise draw underlines if the toplevel widget has seen an alt-press
01069                 } else
01070 #endif // QT_NO_MENUBAR
01071                 if (d->hasSeenAlt(widget)) {
01072                     ret = 1;
01073                 }
01074             }
01075         }
01076         break;
01077 #endif
01078 #ifndef QT_NO_RUBBERBAND
01079     case SH_RubberBand_Mask:
01080         if (const QStyleOptionRubberBand *rbOpt = qstyleoption_cast<const QStyleOptionRubberBand *>(opt)) {
01081             ret = 0;
01082             if (rbOpt->shape == QRubberBand::Rectangle) {
01083                 ret = true;
01084                 if(QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask*>(returnData)) {
01085                     mask->region = opt->rect;
01086                     int size = 1;
01087                     if (widget && widget->isWindow())
01088                         size = 4;
01089                     mask->region -= opt->rect.adjusted(size, size, -size, -size);
01090                 }
01091             }
01092         }
01093         break;
01094 #endif // QT_NO_RUBBERBAND
01095     default:
01096         ret = QCommonStyle::styleHint(hint, opt, widget, returnData);
01097         break;
01098     }
01099     return ret;
01100 }
01101 
01103 void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p,
01104                                   const QWidget *w) const
01105 {
01106     // Used to restore across fallthrough cases. Currently only used in PE_IndicatorCheckBox
01107     bool doRestore = false;
01108 
01109     switch (pe) {
01110 #ifndef QT_NO_TOOLBAR
01111   case PE_IndicatorToolBarSeparator:
01112         {
01113             QRect rect = opt->rect;
01114             const int margin = 2;
01115             if(opt->state & State_Horizontal){
01116                 const int offset = rect.width()/2;
01117                 p->setPen(QPen(opt->palette.dark().color()));
01118                 p->drawLine(rect.bottomLeft().x() + offset,
01119                             rect.bottomLeft().y() - margin,
01120                             rect.topLeft().x() + offset,
01121                             rect.topLeft().y() + margin);
01122                 p->setPen(QPen(opt->palette.light().color()));
01123                 p->drawLine(rect.bottomLeft().x() + offset + 1,
01124                             rect.bottomLeft().y() - margin,
01125                             rect.topLeft().x() + offset + 1,
01126                             rect.topLeft().y() + margin);
01127             }
01128             else{ //Draw vertical separator
01129                 const int offset = rect.height()/2;
01130                 p->setPen(QPen(opt->palette.dark().color()));
01131                 p->drawLine(rect.topLeft().x() + margin ,
01132                             rect.topLeft().y() + offset,
01133                             rect.topRight().x() - margin,
01134                             rect.topRight().y() + offset);
01135                 p->setPen(QPen(opt->palette.light().color()));
01136                 p->drawLine(rect.topLeft().x() + margin ,
01137                             rect.topLeft().y() + offset + 1,
01138                             rect.topRight().x() - margin,
01139                             rect.topRight().y() + offset + 1);
01140             }
01141         }
01142         break;
01143     case PE_IndicatorToolBarHandle:
01144         p->save();
01145         p->translate(opt->rect.x(), opt->rect.y());
01146         if (opt->state & State_Horizontal) {
01147             int x = opt->rect.width() / 2 - 4;
01148             if (QApplication::layoutDirection() == Qt::RightToLeft)
01149                 x -= 2;
01150             if (opt->rect.height() > 4) {
01151                 qDrawShadePanel(p, x, 2, 3, opt->rect.height() - 4,
01152                                 opt->palette, false, 1, 0);
01153                 qDrawShadePanel(p, x + 3, 2, 3, opt->rect.height() - 4,
01154                                 opt->palette, false, 1, 0);
01155             }
01156         } else {
01157             if (opt->rect.width() > 4) {
01158                 int y = opt->rect.height() / 2 - 4;
01159                 qDrawShadePanel(p, 2, y, opt->rect.width() - 4, 3,
01160                                 opt->palette, false, 1, 0);
01161                 qDrawShadePanel(p, 2, y + 3, opt->rect.width() - 4, 3,
01162                                 opt->palette, false, 1, 0);
01163             }
01164         }
01165         p->restore();
01166         break;
01167 
01168 #endif // QT_NO_TOOLBAR
01169     case PE_FrameButtonTool:
01170     case PE_PanelButtonTool: {
01171 #ifndef QT_NO_DOCKWIDGET
01172         if (w && w->inherits("QDockWidgetTitleButton")) {
01173            if (const QDockWidget *dw = qobject_cast<const QDockWidget *>(w->parent()))
01174                 if (dw->isFloating()){
01175                     qDrawWinButton(p, opt->rect.adjusted(1, 1, 0, 0), opt->palette, opt->state & (State_Sunken | State_On),
01176                            &opt->palette.button());
01177 
01178                     return;
01179                 }
01180         }
01181 #endif // QT_NO_DOCKWIDGET
01182         QBrush fill;
01183         bool stippled;
01184         bool panel = (pe == PE_PanelButtonTool);
01185         if ((!(opt->state & State_Sunken ))
01186             && (!(opt->state & State_Enabled)
01187                 || ((opt->state & State_Enabled ) && !(opt->state & State_MouseOver)))
01188             && (opt->state & State_On) && use2000style) {
01189             fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
01190             stippled = true;
01191         } else {
01192             fill = opt->palette.brush(QPalette::Button);
01193             stippled = false;
01194         }
01195 
01196         if (opt->state & (State_Raised | State_Sunken | State_On)) {
01197             if (opt->state & State_AutoRaise) {
01198                 if(opt->state & (State_Enabled | State_Sunken | State_On)){
01199                     if (panel)
01200                         qDrawShadePanel(p, opt->rect, opt->palette,
01201                                         opt->state & (State_Sunken | State_On), 1, &fill);
01202                     else
01203                         qDrawShadeRect(p, opt->rect, opt->palette,
01204                                        opt->state & (State_Sunken | State_On), 1);
01205                 }
01206                 if (stippled) {
01207                     p->setPen(opt->palette.button().color());
01208                     p->drawRect(opt->rect.adjusted(1,1,-2,-2));
01209                 }
01210             } else {
01211                 qDrawWinButton(p, opt->rect, opt->palette,
01212                                opt->state & (State_Sunken | State_On), panel ? &fill : 0);
01213             }
01214         } else {
01215             p->fillRect(opt->rect, fill);
01216         }
01217         break; }
01218     case PE_PanelButtonCommand:
01219         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
01220             QBrush fill;
01221             State flags = opt->state;
01222             QPalette pal = opt->palette;
01223             QRect r = opt->rect;
01224             if (! (flags & State_Sunken) && (flags & State_On))
01225                 fill = QBrush(pal.light().color(), Qt::Dense4Pattern);
01226             else
01227                 fill = pal.brush(QPalette::Button);
01228 
01229             if (btn->features & QStyleOptionButton::DefaultButton && flags & State_Sunken) {
01230                 p->setPen(pal.dark().color());
01231                 p->setBrush(fill);
01232                 p->drawRect(r.adjusted(0, 0, -1, -1));
01233             } else if (flags & (State_Raised | State_Sunken | State_On | State_Sunken)) {
01234                 qDrawWinButton(p, r, pal, flags & (State_Sunken | State_On),
01235                                &fill);
01236             } else {
01237                 p->fillRect(r, fill);
01238             }
01239         }
01240         break;
01241     case PE_FrameDefaultButton: {
01242         p->setPen(opt->palette.shadow().color());
01243         QRect rect = opt->rect;
01244         rect.adjust(0, 0, -1, -1);
01245         p->drawRect(rect);
01246         break;
01247     }
01248     case PE_IndicatorArrowUp:
01249     case PE_IndicatorArrowDown:
01250     case PE_IndicatorArrowRight:
01251     case PE_IndicatorArrowLeft: {
01252         QPoint points[7];
01253         switch (pe) {
01254             case PE_IndicatorArrowUp:
01255                 points[0] = QPoint(-4, 1);
01256                 points[1] = QPoint(2, 1);
01257                 points[2] = QPoint(-3, 0);
01258                 points[3] = QPoint(1, 0);
01259                 points[4] = QPoint(-2, -1);
01260                 points[5] = QPoint(0, -1);
01261                 points[6] = QPoint(-1, -2);
01262                 break;
01263             case PE_IndicatorArrowDown:
01264                 points[0] = QPoint(-4, -2);
01265                 points[1] = QPoint(2, -2);
01266                 points[2] = QPoint(-3, -1);
01267                 points[3] = QPoint(1, -1);
01268                 points[4] = QPoint(-2, 0);
01269                 points[5] = QPoint(0, 0);
01270                 points[6] = QPoint(-1, 1);
01271                 break;
01272             case PE_IndicatorArrowRight:
01273                 points[0] = QPoint(-2, -3);
01274                 points[1] = QPoint(-2, 3);
01275                 points[2] = QPoint(-1, -2);
01276                 points[3] = QPoint(-1, 2);
01277                 points[4] = QPoint(0, -1);
01278                 points[5] = QPoint(0, 1);
01279                 points[6] = QPoint(1, 0);
01280                 break;
01281             case PE_IndicatorArrowLeft:
01282                 points[0] = QPoint(0, -3);
01283                 points[1] = QPoint(0, 3);
01284                 points[2] = QPoint(-1, -2);
01285                 points[3] = QPoint(-1, 2);
01286                 points[4] = QPoint(-2, -1);
01287                 points[5] = QPoint(-2, 1);
01288                 points[6] = QPoint(-3, 0);
01289                 break;
01290             default:
01291                 break;
01292         }
01293         p->save();
01294         if (opt->state & State_Sunken)
01295             p->translate(pixelMetric(PM_ButtonShiftHorizontal),
01296                          pixelMetric(PM_ButtonShiftVertical));
01297         if (opt->state & State_Enabled) {
01298             p->translate(opt->rect.x() + opt->rect.width() / 2,
01299                          opt->rect.y() + opt->rect.height() / 2);
01300             p->setPen(opt->palette.buttonText().color());
01301             p->drawLine(points[0], points[1]);
01302             p->drawLine(points[2], points[3]);
01303             p->drawLine(points[4], points[5]);
01304             p->drawPoint(points[6]);
01305         } else {
01306             p->translate(opt->rect.x() + opt->rect.width() / 2 + 1,
01307                          opt->rect.y() + opt->rect.height() / 2 + 1);
01308             p->setPen(opt->palette.light().color());
01309             p->drawLine(points[0], points[1]);
01310             p->drawLine(points[2], points[3]);
01311             p->drawLine(points[4], points[5]);
01312             p->drawPoint(points[6]);
01313             p->translate(-1, -1);
01314             p->setPen(opt->palette.mid().color());
01315             p->drawLine(points[0], points[1]);
01316             p->drawLine(points[2], points[3]);
01317             p->drawLine(points[4], points[5]);
01318             p->drawPoint(points[6]);
01319         }
01320         p->restore();
01321         break; }
01322     case PE_IndicatorCheckBox: {
01323         QBrush fill;
01324         if (opt->state & State_NoChange)
01325             fill = QBrush(opt->palette.base().color(), Qt::Dense4Pattern);
01326         else if (opt->state & State_Sunken)
01327             fill = opt->palette.button();
01328         else if (opt->state & State_Enabled)
01329             fill = opt->palette.base();
01330         else
01331             fill = opt->palette.background();
01332         p->save();
01333         doRestore = true;
01334         qDrawWinPanel(p, opt->rect, opt->palette, true, &fill);
01335         if (opt->state & State_NoChange)
01336             p->setPen(opt->palette.dark().color());
01337         else
01338             p->setPen(opt->palette.text().color());
01339         } // Fall through!
01340     case PE_IndicatorViewItemCheck:
01341     case PE_Q3CheckListIndicator:
01342         if (!doRestore) {
01343             p->save();
01344             doRestore = true;
01345         }
01346         if (pe == PE_Q3CheckListIndicator || pe == PE_IndicatorViewItemCheck) {
01347             const QStyleOptionViewItem *itemViewOpt = qstyleoption_cast<const QStyleOptionViewItem *>(opt);
01348             p->setPen(itemViewOpt
01349                       && itemViewOpt->showDecorationSelected
01350                       && opt->state & State_Selected
01351                         ? opt->palette.highlightedText().color()
01352                         : opt->palette.text().color());
01353             if (opt->state & State_NoChange)
01354                 p->setBrush(opt->palette.brush(QPalette::Button));
01355             p->drawRect(opt->rect.x() + 1, opt->rect.y() + 1, 11, 11);
01356         }
01357         if (!(opt->state & State_Off)) {
01358             QLineF lines[7];
01359             int i, xx, yy;
01360             xx = opt->rect.x() + 3;
01361             yy = opt->rect.y() + 5;
01362             for (i = 0; i < 3; ++i) {
01363                 lines[i] = QLineF(xx, yy, xx, yy + 2);
01364                 ++xx;
01365                 ++yy;
01366             }
01367             yy -= 2;
01368             for (i = 3; i < 7; ++i) {
01369                 lines[i] = QLineF(xx, yy, xx, yy + 2);
01370                 ++xx;
01371                 --yy;
01372             }
01373             p->drawLines(lines, 7);
01374         }
01375         if (doRestore)
01376             p->restore();
01377         break;
01378     case PE_FrameFocusRect:
01379         if (const QStyleOptionFocusRect *fropt = qstyleoption_cast<const QStyleOptionFocusRect *>(opt)) {
01380             //### check for d->alt_down
01381             if (!(fropt->state & State_KeyboardFocusChange) && !styleHint(SH_UnderlineShortcut, opt))
01382                 return;
01383             QRect r = opt->rect;
01384             p->save();
01385             p->setBackgroundMode(Qt::TransparentMode);
01386             QColor bg_col = fropt->backgroundColor;
01387             if (!bg_col.isValid())
01388                 bg_col = p->background().color();
01389             // Create an "XOR" color.
01390             QColor patternCol((bg_col.red() ^ 0xff) & 0xff,
01391                               (bg_col.green() ^ 0xff) & 0xff,
01392                               (bg_col.blue() ^ 0xff) & 0xff);
01393             p->setBrush(QBrush(patternCol, Qt::Dense4Pattern));
01394             p->setBrushOrigin(r.topLeft());
01395             p->setPen(Qt::NoPen);
01396             p->drawRect(r.left(), r.top(), r.width(), 1);    // Top
01397             p->drawRect(r.left(), r.bottom(), r.width(), 1); // Bottom
01398             p->drawRect(r.left(), r.top(), 1, r.height());   // Left
01399             p->drawRect(r.right(), r.top(), 1, r.height());  // Right
01400             p->restore();
01401         }
01402         break;
01403     case PE_IndicatorRadioButton:
01404         {
01405 #define PTSARRLEN(x) sizeof(x)/(sizeof(QPoint))
01406             static const QPoint pts1[] = {              // dark lines
01407                 QPoint(1, 9), QPoint(1, 8), QPoint(0, 7), QPoint(0, 4), QPoint(1, 3), QPoint(1, 2),
01408                 QPoint(2, 1), QPoint(3, 1), QPoint(4, 0), QPoint(7, 0), QPoint(8, 1), QPoint(9, 1)
01409             };
01410             static const QPoint pts2[] = {              // black lines
01411                 QPoint(2, 8), QPoint(1, 7), QPoint(1, 4), QPoint(2, 3), QPoint(2, 2), QPoint(3, 2),
01412                 QPoint(4, 1), QPoint(7, 1), QPoint(8, 2), QPoint(9, 2)
01413             };
01414             static const QPoint pts3[] = {              // background lines
01415                 QPoint(2, 9), QPoint(3, 9), QPoint(4, 10), QPoint(7, 10), QPoint(8, 9), QPoint(9, 9),
01416                 QPoint(9, 8), QPoint(10, 7), QPoint(10, 4), QPoint(9, 3)
01417             };
01418             static const QPoint pts4[] = {              // white lines
01419                 QPoint(2, 10), QPoint(3, 10), QPoint(4, 11), QPoint(7, 11), QPoint(8, 10),
01420                 QPoint(9, 10), QPoint(10, 9), QPoint(10, 8), QPoint(11, 7), QPoint(11, 4),
01421                 QPoint(10, 3), QPoint(10, 2)
01422             };
01423             static const QPoint pts5[] = {              // inner fill
01424                 QPoint(4, 2), QPoint(7, 2), QPoint(9, 4), QPoint(9, 7), QPoint(7, 9), QPoint(4, 9),
01425                 QPoint(2, 7), QPoint(2, 4)
01426             };
01427 
01428             // make sure the indicator is square
01429             QRect ir = opt->rect;
01430 
01431             if (opt->rect.width() < opt->rect.height()) {
01432                 ir.setTop(opt->rect.top() + (opt->rect.height() - opt->rect.width()) / 2);
01433                 ir.setHeight(opt->rect.width());
01434             } else if (opt->rect.height() < opt->rect.width()) {
01435                 ir.setLeft(opt->rect.left() + (opt->rect.width() - opt->rect.height()) / 2);
01436                 ir.setWidth(opt->rect.height());
01437             }
01438 
01439             p->save();
01440             bool down = opt->state & State_Sunken;
01441             bool enabled = opt->state & State_Enabled;
01442             bool on = opt->state & State_On;
01443             QPolygon a;
01444             p->translate(ir.x(), ir.y());
01445 
01446             p->setPen(opt->palette.dark().color());
01447             p->drawPolyline(pts1, PTSARRLEN(pts1));
01448 
01449             p->setPen(opt->palette.shadow().color());
01450             p->drawPolyline(pts2, PTSARRLEN(pts2));
01451 
01452             p->setPen(opt->palette.midlight().color());
01453             p->drawPolyline(pts3, PTSARRLEN(pts3));
01454 
01455             p->setPen(opt->palette.light().color());
01456             p->drawPolyline(pts4, PTSARRLEN(pts4));
01457 
01458             QColor fillColor = (down || !enabled)
01459                                ? opt->palette.button().color()
01460                                : opt->palette.base().color();
01461             p->setPen(fillColor);
01462             p->setBrush(fillColor) ;
01463             p->drawPolygon(pts5, PTSARRLEN(pts5));
01464 
01465             p->translate(-ir.x(), -ir.y()); // restore translate
01466 
01467             if (on) {
01468                 p->setPen(Qt::NoPen);
01469                 p->setBrush(opt->palette.text());
01470                 p->drawRect(ir.x() + 5, ir.y() + 4, 2, 4);
01471                 p->drawRect(ir.x() + 4, ir.y() + 5, 4, 2);
01472             }
01473             p->restore();
01474             break;
01475         }
01476 #ifndef QT_NO_FRAME
01477     case PE_Frame:
01478     case PE_FrameMenu:
01479         if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
01480             if (frame->lineWidth == 2 || pe == PE_Frame) {
01481                 QPalette popupPal = frame->palette;
01482                 if (pe == PE_FrameMenu) {
01483                     popupPal.setColor(QPalette::Light, frame->palette.background().color());
01484                     popupPal.setColor(QPalette::Midlight, frame->palette.light().color());
01485                 }
01486                 if (use2000style && pe == PE_Frame && (frame->state & State_Raised))
01487                     qDrawWinButton(p, frame->rect, popupPal, frame->state & State_Sunken);
01488                 else
01489                     qDrawWinPanel(p, frame->rect, popupPal, frame->state & State_Sunken);
01490             } else {
01491                 QCommonStyle::drawPrimitive(pe, opt, p, w);
01492             }
01493         }
01494         break;
01495 #endif // QT_NO_FRAME
01496     case PE_IndicatorBranch: {
01497         // This is _way_ too similar to the common style.
01498         static const int decoration_size = 9;
01499         int mid_h = opt->rect.x() + opt->rect.width() / 2;
01500         int mid_v = opt->rect.y() + opt->rect.height() / 2;
01501         int bef_h = mid_h;
01502         int bef_v = mid_v;
01503         int aft_h = mid_h;
01504         int aft_v = mid_v;
01505         if (opt->state & State_Children) {
01506             int delta = decoration_size / 2;
01507             bef_h -= delta;
01508             bef_v -= delta;
01509             aft_h += delta;
01510             aft_v += delta;
01511             p->drawLine(bef_h + 2, bef_v + 4, bef_h + 6, bef_v + 4);
01512             if (!(opt->state & State_Open))
01513                 p->drawLine(bef_h + 4, bef_v + 2, bef_h + 4, bef_v + 6);
01514             QPen oldPen = p->pen();
01515             p->setPen(opt->palette.dark().color());
01516             p->drawRect(bef_h, bef_v, decoration_size - 1, decoration_size - 1);
01517             p->setPen(oldPen);
01518         }
01519         QBrush brush(opt->palette.dark().color(), Qt::Dense4Pattern);
01520         if (opt->state & State_Item) {
01521             if (opt->direction == Qt::RightToLeft)
01522                 p->fillRect(opt->rect.left(), mid_v, bef_h - opt->rect.left(), 1, brush);
01523             else
01524                 p->fillRect(aft_h, mid_v, opt->rect.right() - aft_h + 1, 1, brush);
01525         }
01526         if (opt->state & State_Sibling)
01527             p->fillRect(mid_h, aft_v, 1, opt->rect.bottom() - aft_v + 1, brush);
01528         if (opt->state & (State_Open | State_Children | State_Item | State_Sibling))
01529             p->fillRect(mid_h, opt->rect.y(), 1, bef_v - opt->rect.y(), brush);
01530         break; }
01531     case PE_FrameButtonBevel:
01532     case PE_PanelButtonBevel: {
01533         QBrush fill;
01534         bool panel = pe != PE_FrameButtonBevel;
01535         p->setBrushOrigin(opt->rect.topLeft());
01536         if (!(opt->state & State_Sunken) && (opt->state & State_On))
01537             fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
01538         else
01539             fill = opt->palette.brush(QPalette::Button);
01540 
01541         if (opt->state & (State_Raised | State_On | State_Sunken)) {
01542             qDrawWinButton(p, opt->rect, opt->palette, opt->state & (State_Sunken | State_On),
01543                            panel ? &fill : 0);
01544         } else {
01545             if (panel)
01546                 p->fillRect(opt->rect, fill);
01547             else
01548                 p->drawRect(opt->rect);
01549         }
01550         break; }
01551     case PE_FrameWindow: {
01552          QPalette popupPal = opt->palette;
01553          popupPal.setColor(QPalette::Light, opt->palette.background().color());
01554          popupPal.setColor(QPalette::Midlight, opt->palette.light().color());
01555          qDrawWinPanel(p, opt->rect, popupPal, opt->state & State_Sunken);
01556         break; }
01557 #ifndef QT_NO_DOCKWIDGET
01558     case PE_IndicatorDockWidgetResizeHandle: {
01559         QPen oldPen = p->pen();
01560         p->setPen(opt->palette.light().color());
01561         if (opt->state & State_Horizontal) {
01562             p->drawLine(opt->rect.left(),          opt->rect.top(),
01563                         opt->rect.right(), opt->rect.top());
01564             p->setPen(opt->palette.dark().color());
01565             p->drawLine(opt->rect.left(),          opt->rect.bottom() - 1,
01566                         opt->rect.right(), opt->rect.bottom() - 1);
01567             p->setPen(opt->palette.shadow().color());
01568             p->drawLine(opt->rect.left(),          opt->rect.bottom(),
01569                         opt->rect.right(), opt->rect.bottom());
01570         } else {
01571             p->drawLine(opt->rect.left(), opt->rect.top(),
01572                         opt->rect.left(), opt->rect.bottom());
01573             p->setPen(opt->palette.dark().color());
01574             p->drawLine(opt->rect.right() - 1, opt->rect.top(),
01575                         opt->rect.right() - 1, opt->rect.bottom());
01576             p->setPen(opt->palette.shadow().color());
01577             p->drawLine(opt->rect.right(), opt->rect.top(),
01578                         opt->rect.right(), opt->rect.bottom());
01579         }
01580         p->setPen(oldPen);
01581         break; }
01582 case PE_FrameDockWidget:
01583         if (qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
01584             drawPrimitive(QStyle::PE_FrameWindow, opt, p, w);
01585         }
01586     break;
01587 #endif // QT_NO_DOCKWIDGET
01588 
01589     case PE_FrameTabWidget:
01590         if (use2000style) {
01591             QRect rect = opt->rect;
01592             QPalette pal = opt->palette;
01593             qDrawWinButton(p, opt->rect, opt->palette, false, 0);
01594             break;
01595        }
01596     default:
01597         QCommonStyle::drawPrimitive(pe, opt, p, w);
01598     }
01599 }
01600 
01602 void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter *p,
01603                                 const QWidget *widget) const
01604 {
01605     switch (ce) {
01606 #ifndef QT_NO_RUBBERBAND
01607     case CE_RubberBand:
01608         if (qstyleoption_cast<const QStyleOptionRubberBand *>(opt)) {
01609             // ### workaround for slow general painter path
01610             QPixmap tiledPixmap(16, 16);
01611             QPainter pixmapPainter(&tiledPixmap);
01612             pixmapPainter.setPen(Qt::NoPen);
01613             pixmapPainter.setBrush(Qt::Dense4Pattern);
01614             pixmapPainter.setBackground(Qt::white);
01615             pixmapPainter.setBackgroundMode(Qt::OpaqueMode);
01616             pixmapPainter.drawRect(0, 0, tiledPixmap.width(), tiledPixmap.height());
01617             pixmapPainter.end();
01618             tiledPixmap = QPixmap::fromImage(tiledPixmap.toImage());
01619             p->save();
01620             QRect r = opt->rect;
01621             QStyleHintReturnMask mask;
01622             if (styleHint(QStyle::SH_RubberBand_Mask, opt, widget, &mask))
01623                 p->setClipRegion(mask.region);
01624             p->drawTiledPixmap(r.x(), r.y(), r.width(), r.height(), tiledPixmap);
01625             p->restore();
01626             return;
01627         }
01628         break;
01629 #endif // QT_NO_RUBBERBAND
01630 
01631 #if !defined(QT_NO_MENU) && !defined(QT_NO_MAINWINDOW)
01632     case CE_MenuBarEmptyArea:
01633         if (widget && qobject_cast<const QMainWindow *>(widget->parentWidget())) {
01634             QPen oldPen = p->pen();
01635             p->setPen(QPen(opt->palette.dark().color()));
01636             p->drawLine(opt->rect.bottomLeft(), opt->rect.bottomRight());
01637         }
01638         break;
01639 #endif
01640 #ifndef QT_NO_MENU
01641     case CE_MenuItem:
01642         if (const QStyleOptionMenuItem *menuitem = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
01643             int x, y, w, h;
01644             menuitem->rect.getRect(&x, &y, &w, &h);
01645             int tab = menuitem->tabWidth;
01646             bool dis = !(menuitem->state & State_Enabled);
01647             bool checked = menuitem->checkType != QStyleOptionMenuItem::NotCheckable
01648                             ? menuitem->checked : false;
01649             bool act = menuitem->state & State_Selected;
01650 
01651             // windows always has a check column, regardless whether we have an icon or not
01652             int checkcol = qMax(menuitem->maxIconWidth, use2000style ? 20 : windowsCheckMarkWidth);
01653 
01654 
01655             QBrush fill = menuitem->palette.brush(act ? QPalette::Highlight : QPalette::Button);
01656             p->fillRect(menuitem->rect, fill);
01657 
01658             if (menuitem->menuItemType == QStyleOptionMenuItem::Separator){
01659                 int yoff = y-1 + h / 2;
01660                 p->setPen(menuitem->palette.dark().color());
01661                 p->drawLine(x + 2, yoff, x + w - 4, yoff);
01662                 p->setPen(menuitem->palette.light().color());
01663                 p->drawLine(x + 2, yoff + 1, x + w - 4, yoff + 1);
01664                 return;
01665             }
01666 
01667             QRect vCheckRect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x(), menuitem->rect.y(), checkcol, menuitem->rect.height()));
01668             if (checked) {
01669                 if (act && !dis) {
01670                     qDrawShadePanel(p, vCheckRect,
01671                                     menuitem->palette, true, 1,
01672                                     &menuitem->palette.brush(QPalette::Button));
01673                 } else {
01674                     QBrush fill(menuitem->palette.light().color(), Qt::Dense4Pattern);
01675                     qDrawShadePanel(p, vCheckRect, menuitem->palette, true, 1, &fill);
01676                 }
01677             } else if (!act) {
01678                 p->fillRect(vCheckRect, menuitem->palette.brush(QPalette::Button));
01679             }
01680 
01681             // On Windows Style, if we have a checkable item and an icon we
01682             // draw the icon recessed to indicate an item is checked. If we
01683             // have no icon, we draw a checkmark instead.
01684             if (!menuitem->icon.isNull()) {
01685                 QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
01686                 if (act && !dis)
01687                     mode = QIcon::Active;
01688                 QPixmap pixmap;
01689                 if (checked)
01690                     pixmap = menuitem->icon.pixmap(pixelMetric(PM_SmallIconSize), mode, QIcon::On);
01691                 else
01692                     pixmap = menuitem->icon.pixmap(pixelMetric(PM_SmallIconSize), mode);
01693                 int pixw = pixmap.width();
01694                 int pixh = pixmap.height();
01695                 if (act && !dis && !checked)
01696                     qDrawShadePanel(p, vCheckRect,  menuitem->palette, false, 1,
01697                                     &menuitem->palette.brush(QPalette::Button));
01698                 QRect pmr(0, 0, pixw, pixh);
01699                 pmr.moveCenter(vCheckRect.center());
01700                 p->setPen(menuitem->palette.text().color());
01701                 p->drawPixmap(pmr.topLeft(), pixmap);
01702             } else if (checked) {
01703                 QStyleOptionMenuItem newMi = *menuitem;
01704                 newMi.state = State_None;
01705                 if (!dis)
01706                     newMi.state |= State_Enabled;
01707                 if (act)
01708                     newMi.state |= State_On;
01709                 newMi.rect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x() + windowsItemFrame, menuitem->rect.y() + windowsItemFrame,
01710                                                                               checkcol - 2 * windowsItemFrame, menuitem->rect.height() - 2*windowsItemFrame));
01711                 drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, widget);
01712             }
01713             p->setPen(act ? menuitem->palette.highlightedText().color() : menuitem->palette.buttonText().color());
01714 
01715             QColor discol;
01716             if (dis) {
01717                 discol = menuitem->palette.text().color();
01718                 p->setPen(discol);
01719             }
01720 
01721             int xm = windowsItemFrame + checkcol + windowsItemHMargin;
01722             int xpos = menuitem->rect.x() + xm;
01723             QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
01724             QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
01725             QString s = menuitem->text;
01726             if (!s.isEmpty()) {                     // draw text
01727                 p->save();
01728                 int t = s.indexOf(QLatin1Char('\t'));
01729                 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
01730                 if (!styleHint(SH_UnderlineShortcut, menuitem, widget))
01731                     text_flags |= Qt::TextHideMnemonic;
01732                 text_flags |= Qt::AlignLeft;
01733                 if (t >= 0) {
01734                     QRect vShortcutRect = visualRect(opt->direction, menuitem->rect, 
01735                         QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
01736                     if (dis && !act) {
01737                         p->setPen(menuitem->palette.light().color());
01738                         p->drawText(vShortcutRect.adjusted(1,1,1,1), text_flags, s.mid(t + 1));
01739                         p->setPen(discol);
01740                     }
01741                     p->drawText(vShortcutRect, text_flags, s.mid(t + 1));
01742                     s = s.left(t);
01743                 }
01744                 QFont font = menuitem->font;
01745                 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
01746                     font.setBold(true);
01747                 p->setFont(font);
01748                 if (dis && !act) {
01749                     p->setPen(menuitem->palette.light().color());
01750                     p->drawText(vTextRect.adjusted(1,1,1,1), text_flags, s.left(t));
01751                     p->setPen(discol);
01752                 }
01753                 p->drawText(vTextRect, text_flags, s.left(t));
01754                 p->restore();
01755             }
01756             if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow
01757                 int dim = (h - 2 * windowsItemFrame) / 2;
01758                 PrimitiveElement arrow;
01759                 arrow = (opt->direction == Qt::RightToLeft) ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
01760                 xpos = x + w - windowsArrowHMargin - windowsItemFrame - dim;
01761                 QRect  vSubMenuRect = visualRect(opt->direction, menuitem->rect, QRect(xpos, y + h / 2 - dim / 2, dim, dim));
01762                 QStyleOptionMenuItem newMI = *menuitem;
01763                 newMI.rect = vSubMenuRect;
01764                 newMI.state = dis ? State_None : State_Enabled;
01765                 if (act)
01766                     newMI.palette.setColor(QPalette::ButtonText,
01767                                            newMI.palette.highlightedText().color());
01768                 drawPrimitive(arrow, &newMI, p, widget);
01769             }
01770 
01771         }
01772         break;
01773 #endif // QT_NO_MENU
01774 #ifndef QT_NO_MENUBAR
01775     case CE_MenuBarItem:
01776         if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
01777             bool active = mbi->state & State_Selected;
01778             bool hasFocus = mbi->state & State_HasFocus;
01779             bool down = mbi->state & State_Sunken;
01780             QStyleOptionMenuItem newMbi = *mbi;
01781             p->fillRect(mbi->rect, mbi->palette.brush(QPalette::Button));
01782             if (active || hasFocus) {
01783                 QBrush b = mbi->palette.brush(QPalette::Button);
01784                 if (active && down)
01785                     p->setBrushOrigin(p->brushOrigin() + QPoint(1, 1));
01786                 if (active && hasFocus)
01787                     qDrawShadeRect(p, mbi->rect.x(), mbi->rect.y(), mbi->rect.width(),
01788                                    mbi->rect.height(), mbi->palette, active && down, 1, 0, &b);
01789                 if (active && down) {
01790                     newMbi.rect.translate(pixelMetric(PM_ButtonShiftHorizontal, mbi, widget),
01791                                        pixelMetric(PM_ButtonShiftVertical, mbi, widget));
01792                     p->setBrushOrigin(p->brushOrigin() - QPoint(1, 1));
01793                 }
01794             }
01795             QCommonStyle::drawControl(ce, &newMbi, p, widget);
01796         }
01797         break;
01798 #endif // QT_NO_MENUBAR
01799 #ifndef QT_NO_TABBAR
01800     case CE_TabBarTabShape:
01801         if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
01802             bool rtlHorTabs = (tab->direction == Qt::RightToLeft
01803                                && (tab->shape == QTabBar::RoundedNorth
01804                                    || tab->shape == QTabBar::RoundedSouth));
01805             bool selected = tab->state & State_Selected;
01806             bool lastTab = ((!rtlHorTabs && tab->position == QStyleOptionTab::End)
01807                             || (rtlHorTabs
01808                                 && tab->position == QStyleOptionTab::Beginning));
01809             bool firstTab = ((!rtlHorTabs
01810                                && tab->position == QStyleOptionTab::Beginning)
01811                              || (rtlHorTabs
01812                                  && tab->position == QStyleOptionTab::End));
01813             bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab;
01814             bool previousSelected =
01815                 ((!rtlHorTabs
01816                   && tab->selectedPosition == QStyleOptionTab::PreviousIsSelected)
01817                 || (rtlHorTabs
01818                     && tab->selectedPosition == QStyleOptionTab::NextIsSelected));
01819             bool nextSelected =
01820                 ((!rtlHorTabs
01821                   && tab->selectedPosition == QStyleOptionTab::NextIsSelected)
01822                  || (rtlHorTabs
01823                      && tab->selectedPosition
01824                             == QStyleOptionTab::PreviousIsSelected));
01825             int tabBarAlignment = styleHint(SH_TabBar_Alignment, tab, widget);
01826             bool leftAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignLeft)
01827                                 || (rtlHorTabs
01828                                     && tabBarAlignment == Qt::AlignRight);
01829 
01830             bool rightAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignRight)
01831                                  || (rtlHorTabs
01832                                          && tabBarAlignment == Qt::AlignLeft);
01833 
01834             QColor light = tab->palette.light().color();
01835             QColor midlight = tab->palette.midlight().color();
01836             QColor dark = tab->palette.dark().color();
01837             QColor shadow = tab->palette.shadow().color();
01838             QColor background = tab->palette.background().color();
01839             int borderThinkness = pixelMetric(PM_TabBarBaseOverlap, tab, widget);
01840             if (selected)
01841                 borderThinkness /= 2;
01842             QRect r2(opt->rect);
01843             int x1 = r2.left();
01844             int x2 = r2.right();
01845             int y1 = r2.top();
01846             int y2 = r2.bottom();
01847             switch (tab->shape) {
01848             default:
01849                 QCommonStyle::drawControl(ce, tab, p, widget);
01850                 break;
01851             case QTabBar::RoundedNorth: {
01852                 if (!selected) {
01853                     y1 += 2;
01854                     x1 += firstTab ? borderThinkness : 0;
01855                     x2 -= lastTab ? borderThinkness : 0;
01856                 }
01857 
01858                 p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 2), tab->palette.background());
01859 
01860                 // Delete border
01861                 if (selected) {
01862                     p->setPen(background);
01863                     p->drawLine(x1, y2 - 1, x2, y2 - 1);
01864                     p->drawLine(x1, y2, x2, y2);
01865                 }
01866                 // Left
01867                 if (firstTab || selected || onlyOne || !previousSelected) {
01868                     p->setPen(light);
01869                     p->drawLine(x1, y1 + 2, x1, y2 - ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness));
01870                     p->drawPoint(x1 + 1, y1 + 1);
01871                     if (!use2000style) {
01872                         p->setPen(midlight);
01873                         p->drawLine(x1 + 1, y1 + 2, x1 + 1, y2 - ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness));
01874                     }
01875                 }
01876                 // Top
01877                 {
01878                     int beg = x1 + (previousSelected ? 0 : 2);
01879                     int end = x2 - (nextSelected ? 0 : 2);
01880                     p->setPen(light);
01881                     p->drawLine(beg, y1, end, y1);
01882                     if (!use2000style) {
01883                         p->setPen(midlight);
01884                         p->drawLine(beg, y1 + 1, end, y1 + 1);
01885                     }
01886                 }
01887                 // Right
01888                 if (lastTab || selected || onlyOne || !nextSelected) {
01889                     p->setPen(shadow);
01890                     p->drawLine(x2, y1 + 2, x2, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
01891                     p->drawPoint(x2 - 1, y1 + 1);
01892                     p->setPen(dark);
01893                     p->drawLine(x2 - 1, y1 + 2, x2 - 1, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
01894                 }
01895                 break; }
01896             case QTabBar::RoundedSouth: {
01897                 if (!selected) {
01898                     y2 -= 2;
01899                     x1 += firstTab ? borderThinkness : 0;
01900                     x2 -= lastTab ? borderThinkness : 0;
01901                 }
01902 
01903                 p->fillRect(QRect(x1 + 1, y1 + 2, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.background());
01904 
01905                 // Delete border
01906                 if (selected) {
01907                     p->setPen(background);
01908                     p->drawLine(x1, y1 + 1, x2 - 1, y1 + 1);
01909                     p->drawLine(x1, y1, x2 - 1, y1);
01910                 }
01911                 // Left
01912                 if (firstTab || selected || onlyOne || !previousSelected) {
01913                     p->setPen(light);
01914                     p->drawLine(x1, y2 - 2, x1, y1 + ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness));
01915                     p->drawPoint(x1 + 1, y2 - 1);
01916                     if (!use2000style) {
01917                         p->setPen(midlight);
01918                         p->drawLine(x1 + 1, y2 - 2, x1 + 1, y1 + ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness));
01919                     }
01920                 }
01921                 // Bottom
01922                 {
01923                     int beg = x1 + (previousSelected ? 0 : 2);
01924                     int end = x2 - (nextSelected ? 0 : 2);
01925                     p->setPen(shadow);
01926                     p->drawLine(beg, y2, end, y2);
01927                     p->setPen(dark);
01928                     p->drawLine(beg, y2 - 1, end, y2 - 1);
01929                 }
01930                 // Right
01931                 if (lastTab || selected || onlyOne || !nextSelected) {
01932                     p->setPen(shadow);
01933                     p->drawLine(x2, y2 - 2, x2, y1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
01934                     p->drawPoint(x2 - 1, y2 - 1);
01935                     p->setPen(dark);
01936                     p->drawLine(x2 - 1, y2 - 2, x2 - 1, y1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
01937                 }
01938                 break; }
01939             case QTabBar::RoundedWest: {
01940                 if (!selected) {
01941                     x1 += 2;
01942                     y1 += firstTab ? borderThinkness : 0;
01943                     y2 -= lastTab ? borderThinkness : 0;
01944                 }
01945 
01946                 p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 2, (y2 - y1) - 1), tab->palette.background());
01947 
01948                 // Delete border
01949                 if (selected) {
01950                     p->setPen(background);
01951                     p->drawLine(x2 - 1, y1, x2 - 1, y2);
01952                     p->drawLine(x2, y1, x2, y2);
01953                 }
01954                 // Top
01955                 if (firstTab || selected || onlyOne || !previousSelected) {
01956                     p->setPen(light);
01957                     p->drawLine(x1 + 2, y1, x2 - ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness), y1);
01958                     p->drawPoint(x1 + 1, y1 + 1);
01959                     if (!use2000style) {
01960                         p->setPen(midlight);
01961                         p->drawLine(x1 + 2, y1 + 1, x2 - ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness), y1 + 1);
01962                     }
01963                 }
01964                 // Left
01965                 {
01966                     int beg = y1 + (previousSelected ? 0 : 2);
01967                     int end = y2 - (nextSelected ? 0 : 2);
01968                     p->setPen(light);
01969                     p->drawLine(x1, beg, x1, end);
01970                     if (!use2000style) {
01971                         p->setPen(midlight);
01972                         p->drawLine(x1 + 1, beg, x1 + 1, end);
01973                     }
01974                 }
01975                 // Bottom
01976                 if (lastTab || selected || onlyOne || !nextSelected) {
01977                     p->setPen(shadow);
01978                     p->drawLine(x1 + 3, y2, x2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2);
01979                     p->drawPoint(x1 + 2, y2 - 1);
01980                     p->setPen(dark);
01981                     p->drawLine(x1 + 3, y2 - 1, x2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2 - 1);
01982                     p->drawPoint(x1 + 1, y2 - 1);
01983                     p->drawPoint(x1 + 2, y2);
01984                 }
01985                 break; }
01986             case QTabBar::RoundedEast: {
01987                 if (!selected) {
01988                     x2 -= 2;
01989                     y1 += firstTab ? borderThinkness : 0;
01990                     y2 -= lastTab ? borderThinkness : 0;
01991                 }
01992 
01993                 p->fillRect(QRect(x1 + 2, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.background());
01994 
01995                 // Delete border
01996                 if (selected) {
01997                     p->setPen(background);
01998                     p->drawLine(x1 + 1, y1, x1 + 1, y2 - 1);
01999                     p->drawLine(x1, y1, x1, y2 - 1);
02000                 }
02001                 // Top
02002                 if (firstTab || selected || onlyOne || !previousSelected) {
02003                     p->setPen(light);
02004                     p->drawLine(x2 - 2, y1, x1 + ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness), y1);
02005                     p->drawPoint(x2 - 1, y1 + 1);
02006                     if (!use2000style) {
02007                         p->setPen(midlight);
02008                         p->drawLine(x2 - 3, y1 + 1, x1 + ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness), y1 + 1);
02009                         p->drawPoint(x2 - 1, y1);
02010                     }
02011                 }
02012                 // Right
02013                 {
02014                     int beg = y1 + (previousSelected ? 0 : 2);
02015                     int end = y2 - (nextSelected ? 0 : 2);
02016                     p->setPen(shadow);
02017                     p->drawLine(x2, beg, x2, end);
02018                     p->setPen(dark);
02019                     p->drawLine(x2 - 1, beg, x2 - 1, end);
02020                 }
02021                 // Bottom
02022                 if (lastTab || selected || onlyOne || !nextSelected) {
02023                     p->setPen(shadow);
02024                     p->drawLine(x2 - 2, y2, x1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2);
02025                     p->drawPoint(x2 - 1, y2 - 1);
02026                     p->setPen(dark);
02027                     p->drawLine(x2 - 2, y2 - 1, x1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2 - 1);
02028                 }
02029                 break; }
02030             }
02031         }
02032         break;
02033 #endif // QT_NO_TABBAR
02034     case CE_ToolBoxTab:
02035         qDrawShadePanel(p, opt->rect, opt->palette,
02036                         opt->state & (State_Sunken | State_On), 1,
02037                         &opt->palette.brush(QPalette::Button));
02038         break;
02039 #ifndef QT_NO_SPLITTER
02040     case CE_Splitter:
02041         p->eraseRect(opt->rect);
02042         break;
02043 #endif // QT_NO_SPLITTER
02044 #ifndef QT_NO_SCROLLBAR
02045     case CE_ScrollBarSubLine:
02046     case CE_ScrollBarAddLine: {
02047         if (use2000style && (opt->state & State_Sunken)) {
02048             p->setPen(opt->palette.dark().color());
02049             p->setBrush(opt->palette.brush(QPalette::Button));
02050             p->drawRect(opt->rect.adjusted(0, 0, -1, -1));
02051         } else {
02052             QStyleOption buttonOpt = *opt;
02053             if (!(buttonOpt.state & State_Sunken))
02054                 buttonOpt.state |= State_Raised;
02055             drawPrimitive(PE_PanelButtonBevel, &buttonOpt, p, widget);
02056         }
02057         PrimitiveElement arrow;
02058         if (opt->state & State_Horizontal) {
02059             if (ce == CE_ScrollBarAddLine)
02060                 arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowRight : PE_IndicatorArrowLeft;
02061             else
02062                 arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
02063         } else {
02064             if (ce == CE_ScrollBarAddLine)
02065                 arrow = PE_IndicatorArrowDown;
02066             else
02067                 arrow = PE_IndicatorArrowUp;
02068         }
02069         drawPrimitive(arrow, opt, p, widget);
02070         break; }
02071     case CE_ScrollBarAddPage:
02072     case CE_ScrollBarSubPage: {
02073             QBrush br;
02074             QBrush bg = p->background();
02075             Qt::BGMode bg_mode = p->backgroundMode();
02076             p->setPen(Qt::NoPen);
02077             p->setBackgroundMode(Qt::OpaqueMode);
02078 
02079             if (opt->state & State_Sunken) {
02080                 br = QBrush(opt->palette.shadow().color(), Qt::Dense4Pattern);
02081                 p->setBackground(opt->palette.dark().color());
02082                 p->setBrush(br);
02083             } else {
02084                 QPixmap pm = opt->palette.brush(QPalette::Light).texture();
02085                 br = !pm.isNull() ? QBrush(pm) : QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
02086                 p->setBackground(opt->palette.background().color());
02087                 p->setBrush(br);
02088             }
02089             p->drawRect(opt->rect);
02090             p->setBackground(bg);
02091             p->setBackgroundMode(bg_mode);
02092             break; }
02093     case CE_ScrollBarSlider:
02094         if (!(opt->state & State_Enabled)) {
02095             QPixmap pm = opt->palette.brush(QPalette::Light).texture();
02096             QBrush br = !pm.isNull() ? QBrush(pm) : QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
02097             p->setPen(Qt::NoPen);
02098             p->setBrush(br);
02099             p->setBackgroundMode(Qt::OpaqueMode);
02100             p->drawRect(opt->rect);
02101         } else {
02102             QStyleOptionButton buttonOpt;
02103             buttonOpt.QStyleOption::operator=(*opt);
02104             buttonOpt.state = State_Enabled | State_Raised;
02105             drawPrimitive(PE_PanelButtonBevel, &buttonOpt, p, widget);
02106         }
02107         break;
02108 #endif // QT_NO_SCROLLBAR
02109     case CE_HeaderSection: {
02110         QBrush fill;
02111         if (opt->state & State_On)
02112             fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
02113         else
02114             fill = opt->palette.brush(QPalette::Button);
02115 
02116         if (opt->state & (State_Raised | State_Sunken)) {
02117             qDrawWinButton(p, opt->rect, opt->palette, opt->state & State_Sunken, &fill);
02118         } else {
02119             p->fillRect(opt->rect, fill);
02120         }
02121         break; }
02122 #ifndef QT_NO_TOOLBAR
02123     case CE_ToolBar:
02124         if (const QStyleOptionToolBar *toolbar = qstyleoption_cast<const QStyleOptionToolBar *>(opt)) {
02125             QRect rect = opt->rect;
02126 
02127             bool paintLeftBorder = true;
02128             bool paintRightBorder = true;
02129             bool paintBottomBorder = true;
02130 
02131             switch (toolbar->toolBarArea){
02132             case Qt::BottomToolBarArea :
02133                 switch(toolbar->positionOfLine){
02134                 case QStyleOptionToolBar::Beginning:
02135                 case QStyleOptionToolBar::OnlyOne:
02136                     paintBottomBorder = false;
02137                 default:
02138                     break;
02139                 }
02140             case Qt::TopToolBarArea :
02141                 switch(toolbar->positionWithinLine){
02142                 case QStyleOptionToolBar::Beginning:
02143                     paintLeftBorder = false;
02144                     break;
02145                 case QStyleOptionToolBar::End:
02146                     paintRightBorder = false;
02147                     break;
02148                 case QStyleOptionToolBar::OnlyOne:
02149                     paintRightBorder = false;
02150                     paintLeftBorder = false;
02151                 default:
02152                     break;
02153                 }
02154                 if(QApplication::layoutDirection() == Qt::RightToLeft){ //reverse layout changes the order of Beginning/end
02155                     bool tmp = paintLeftBorder;
02156                     paintRightBorder=paintLeftBorder;
02157                     paintLeftBorder=tmp;
02158                 }
02159                 break;
02160             case Qt::RightToolBarArea :
02161                 switch (toolbar->positionOfLine){
02162                 case QStyleOptionToolBar::Beginning:
02163                 case QStyleOptionToolBar::OnlyOne:
02164                     paintRightBorder = false;
02165                     break;
02166                 default:
02167                     break;
02168                 }
02169                 break;
02170             case Qt::LeftToolBarArea :
02171                 switch (toolbar->positionOfLine){
02172                 case QStyleOptionToolBar::Beginning:
02173                 case QStyleOptionToolBar::OnlyOne:
02174                     paintLeftBorder = false;
02175                     break;
02176                 default:
02177                     break;
02178                 }
02179                 break;
02180             default:
02181                 break;
02182             }
02183 
02184 
02185             //draw top border
02186             p->setPen(QPen(opt->palette.light().color()));
02187             p->drawLine(rect.topLeft().x(),
02188                         rect.topLeft().y(),
02189                         rect.topRight().x(),
02190                         rect.topRight().y());
02191 
02192             if (paintLeftBorder){
02193                 p->setPen(QPen(opt->palette.light().color()));
02194                 p->drawLine(rect.topLeft().x(),
02195                             rect.topLeft().y(),
02196                             rect.bottomLeft().x(),
02197                             rect.bottomLeft().y());
02198             }
02199 
02200             if (paintRightBorder){
02201                 p->setPen(QPen(opt->palette.dark().color()));
02202                 p->drawLine(rect.topRight().x(),
02203                             rect.topRight().y(),
02204                             rect.bottomRight().x(),
02205                             rect.bottomRight().y());
02206             }
02207 
02208             if (paintBottomBorder){
02209                 p->setPen(QPen(opt->palette.dark().color()));
02210                 p->drawLine(rect.bottomLeft().x(),
02211                             rect.bottomLeft().y(),
02212                             rect.bottomRight().x(),
02213                             rect.bottomRight().y());
02214             }
02215         }
02216         break;
02217 
02218 
02219 #endif // QT_NO_TOOLBAR
02220 #ifndef QT_NO_PROGRESSBAR
02221     case CE_ProgressBarContents:
02222         if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
02223 
02224             QRect rect = pb->rect;
02225             bool vertical = false;
02226             bool inverted = false;
02227 
02228             // Get extra style options if version 2
02229             const QStyleOptionProgressBarV2 *pb2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt);
02230             if (pb2) {
02231                 vertical = (pb2->orientation == Qt::Vertical);
02232                 inverted = pb2->invertedAppearance;
02233             }
02234             QMatrix m;
02235             if (vertical) {
02236                 rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height
02237                 m.translate(rect.height(), 0.0);
02238                 m.rotate(90);
02239             }
02240             QPalette pal2 = pb->palette;
02241             // Correct the highlight color if it is the same as the background
02242             if (pal2.highlight() == pal2.background())
02243                 pal2.setColor(QPalette::Highlight, pb->palette.color(QPalette::Active,
02244                                                                      QPalette::Highlight));
02245             bool reverse = ((!vertical && (pb->direction == Qt::RightToLeft)) || vertical);
02246             if (inverted)
02247                 reverse = !reverse;
02248             int fw = 2;
02249             int w = rect.width() - 2 * fw;
02250             if (pb->minimum == 0 && pb->maximum == 0) {
02251                 Q_D(const QWindowsStyle);
02252                 const int unit_width = pixelMetric(PM_ProgressBarChunkWidth, pb, widget);
02253                 QStyleOptionProgressBarV2 pbBits = *pb;
02254                 Q_ASSERT(unit_width >0);
02255 
02256                 pbBits.rect = rect;
02257                 pbBits.palette = pal2;
02258 
02259                 int chunkCount = w / unit_width + 1;
02260                 int step = d->animateStep%chunkCount;
02261                 int margin = 3;
02262                 int chunksInRow = 5;
02263                 int myY = pbBits.rect.y();
02264                 int myHeight = pbBits.rect.height();
02265                 int chunksToDraw = chunksInRow;
02266 
02267                 if(step > chunkCount - 5)chunksToDraw = (chunkCount - step);
02268                 QRegion prevClip = p->clipRegion(); //save state
02269                 QRect clip = rect;
02270                 clip.setLeft(clip.left() + margin);
02271                 clip.setRight(clip.right() - margin);
02272                 QRegion intersection = prevClip.intersected(clip);
02273 
02274                 int x0 = reverse ? rect.right() - unit_width*(step) - unit_width  : margin + unit_width * step;
02275                 int x = 0;
02276 
02277                 //Make sure the cliprect is also rotated if vertical
02278                 if(vertical)clip = m.mapRect(clip);
02279 
02280                 if(!prevClip.isEmpty())p->setClipRegion(intersection);
02281                 else p->setClipRect(clip);
02282 
02283                 for (int i = 0; i < chunksToDraw ; ++i) {
02284                     pbBits.rect.setRect(x0 + x, myY, unit_width, myHeight);
02285                     pbBits.rect = m.mapRect(pbBits.rect);
02286                     drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget);
02287                     x += reverse ? -unit_width : unit_width;
02288                 }
02289                 //Draw wrap-around chunks
02290                 if( step > chunkCount-5){
02291                     x0 = reverse ? rect.right() - unit_width : margin ;
02292                     x = 0;
02293                     int chunksToDraw = step - (chunkCount - chunksInRow);
02294                     for (int i = 0; i < chunksToDraw ; ++i) {
02295                         pbBits.rect.setRect(x0 + x, myY, unit_width, myHeight);
02296                         pbBits.rect = m.mapRect(pbBits.rect);
02297                         drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget);
02298                         x += reverse ? -unit_width : unit_width;
02299                     }
02300                 }
02301                 p->setClipRegion(prevClip); //restore state
02302             }
02303             else {
02304                 QCommonStyle::drawControl(ce, opt, p, widget);
02305             }
02306         }
02307         break;
02308 #endif // QT_NO_PROGRESSBAR
02309 
02310 #ifndef QT_NO_DOCKWIDGET
02311     case CE_DockWidgetTitle:
02312 
02313         if (const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<const QStyleOptionDockWidget *>(opt)) {
02314             Q_D(const QWindowsStyle);
02315             QRect r = dwOpt->rect;
02316             bool floating = false;
02317             int menuOffset = 0; //used to center text when floated
02318             QColor inactiveCaptionTextColor = d->inactiveCaptionText;
02319             if (dwOpt->movable) {
02320                 const QDockWidget *dockWidget = qobject_cast<const QDockWidget *>(widget);
02321                 QColor left, right;
02322 
02323                 //Titlebar gradient
02324                 if (dockWidget && dockWidget->isFloating()) {
02325                     floating = true;
02326                     if (widget && widget->isActiveWindow()) {
02327                         left = d->activeCaptionColor;
02328                         right = d->activeGradientCaptionColor;
02329                     } else {
02330                         left = d->inactiveCaptionColor;
02331                         right = d->inactiveGradientCaptionColor;
02332                     }
02333                     menuOffset = 2;
02334                     QBrush fillBrush(left);
02335                     if (left != right) {
02336                         QPoint p1(dwOpt->rect.x(), dwOpt->rect.top() + dwOpt->rect.height()/2);
02337                         QPoint p2(dwOpt->rect.right(), dwOpt->rect.top() + dwOpt->rect.height()/2);
02338                         QLinearGradient lg(p1, p2);
02339                         lg.setColorAt(0, left);
02340                         lg.setColorAt(1, right);
02341                         fillBrush = lg;
02342                     }
02343                     p->fillRect(opt->rect.adjusted(0, 0, 0, -3), fillBrush);
02344                 }
02345                 p->setPen(dwOpt->palette.color(QPalette::Light));
02346                 if (!dockWidget || !dockWidget->isFloating()) {
02347                     p->drawLine(r.topLeft(), r.topRight());
02348                     p->setPen(dwOpt->palette.color(QPalette::Dark));
02349                     p->drawLine(r.bottomLeft(), r.bottomRight());            }
02350             }
02351             if (!dwOpt->title.isEmpty()) {
02352                 QFont oldFont = p->font();
02353                 if (floating) {
02354                     QFont font = oldFont;
02355                     font.setBold(true);
02356                     p->setFont(font);
02357                 }
02358                 QPalette palette = dwOpt->palette;
02359                 palette.setColor(QPalette::Window, inactiveCaptionTextColor);
02360                 bool active = dwOpt->state & State_Active;
02361                 const int indent = p->fontMetrics().descent();
02362                 drawItemText(p, r.adjusted(indent + 1, - menuOffset, -indent - 1, -1),
02363                             Qt::AlignLeft | Qt::AlignVCenter, palette,
02364                             dwOpt->state & State_Enabled, dwOpt->title,
02365                             floating ? (active ? QPalette::BrightText : QPalette::Window) : QPalette::WindowText);
02366                 p->setFont(oldFont);
02367             }
02368         }
02369         return;
02370 #endif // QT_NO_DOCKWIDGET
02371     default:
02372         QCommonStyle::drawControl(ce, opt, p, widget);
02373     }
02374 }
02375 
02377 QRect QWindowsStyle::subElementRect(SubElement sr, const QStyleOption *opt, const QWidget *w) const
02378 {
02379     QRect r;
02380     switch (sr) {
02381     case SE_SliderFocusRect:
02382     case SE_ToolBoxTabContents:
02383         r = visualRect(opt->direction, opt->rect, opt->rect);
02384         break;
02385     default:
02386         r = QCommonStyle::subElementRect(sr, opt, w);
02387     }
02388     return r;
02389 }
02390 
02391 #ifdef QT3_SUPPORT
02392 Q_GLOBAL_STATIC_WITH_ARGS(QBitmap, globalVerticalLine, (1, 129))
02393 Q_GLOBAL_STATIC_WITH_ARGS(QBitmap, globalHorizontalLine, (128, 1))
02394 #endif
02395 
02397 void QWindowsStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt,
02398                                        QPainter *p, const QWidget *widget) const
02399 {
02400     switch (cc) {
02401 #ifndef QT_NO_SLIDER
02402     case CC_Slider:
02403         if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
02404             int thickness  = pixelMetric(PM_SliderControlThickness, slider, widget);
02405             int len        = pixelMetric(PM_SliderLength, slider, widget);
02406             int ticks = slider->tickPosition;
02407             QRect groove = subControlRect(CC_Slider, slider, SC_SliderGroove, widget);
02408             QRect handle = subControlRect(CC_Slider, slider, SC_SliderHandle, widget);
02409 
02410             if ((slider->subControls & SC_SliderGroove) && groove.isValid()) {
02411                 int mid = thickness / 2;
02412 
02413                 if (ticks & QSlider::TicksAbove)
02414                     mid += len / 8;
02415                 if (ticks & QSlider::TicksBelow)
02416                     mid -= len / 8;
02417 
02418                 p->setPen(slider->palette.shadow().color());
02419                 if (slider->orientation == Qt::Horizontal) {
02420                     qDrawWinPanel(p, groove.x(), groove.y() + mid - 2,
02421                                    groove.width(), 4, slider->palette, true);
02422                     p->drawLine(groove.x() + 1, groove.y() + mid - 1,
02423                                 groove.x() + groove.width() - 3, groove.y() + mid - 1);
02424                 } else {
02425                     qDrawWinPanel(p, groove.x() + mid - 2, groove.y(),
02426                                   4, groove.height(), slider->palette, true);
02427                     p->drawLine(groove.x() + mid - 1, groove.y() + 1,
02428                                 groove.x() + mid - 1, groove.y() + groove.height() - 3);
02429                 }
02430             }
02431 
02432             if (slider->subControls & SC_SliderTickmarks) {
02433                 QStyleOptionSlider tmpSlider = *slider;
02434                 tmpSlider.subControls = SC_SliderTickmarks;
02435                 QCommonStyle::drawComplexControl(cc, &tmpSlider, p, widget);
02436             }
02437 
02438             if (slider->subControls & SC_SliderHandle) {
02439                 // 4444440
02440                 // 4333310
02441                 // 4322210
02442                 // 4322210
02443                 // 4322210
02444                 // 4322210
02445                 // *43210*
02446                 // **410**
02447                 // ***0***
02448                 const QColor c0 = slider->palette.shadow().color();
02449                 const QColor c1 = slider->palette.dark().color();
02450                 // const QColor c2 = g.button();
02451                 const QColor c3 = slider->palette.midlight().color();
02452                 const QColor c4 = slider->palette.light().color();
02453                 QBrush handleBrush;
02454 
02455                 if (slider->state & State_Enabled) {
02456                     handleBrush = slider->palette.color(QPalette::Button);
02457                 } else {
02458                     handleBrush = QBrush(slider->palette.color(QPalette::Button),
02459                                          Qt::Dense4Pattern);
02460                 }
02461 
02462 
02463                 int x = handle.x(), y = handle.y(),
02464                    wi = handle.width(), he = handle.height();
02465 
02466                 int x1 = x;
02467                 int x2 = x+wi-1;
02468                 int y1 = y;
02469                 int y2 = y+he-1;
02470 
02471                 Qt::Orientation orient = slider->orientation;
02472                 bool tickAbove = slider->tickPosition == QSlider::TicksAbove;
02473                 bool tickBelow = slider->tickPosition == QSlider::TicksBelow;
02474 
02475                 if (slider->state & State_HasFocus) {
02476                     QStyleOptionFocusRect fropt;
02477                     fropt.QStyleOption::operator=(*slider);
02478                     fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
02479                     drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
02480                 }
02481 
02482                 if ((tickAbove && tickBelow) || (!tickAbove && !tickBelow)) {
02483                     Qt::BGMode oldMode = p->backgroundMode();
02484                     p->setBackgroundMode(Qt::OpaqueMode);
02485                     qDrawWinButton(p, QRect(x, y, wi, he), slider->palette, false,
02486                                    &handleBrush);
02487                     p->setBackgroundMode(oldMode);
02488                     return;
02489                 }
02490 
02491                 QSliderDirection dir;
02492 
02493                 if (orient == Qt::Horizontal)
02494                     if (tickAbove)
02495                         dir = SlUp;
02496                     else
02497                         dir = SlDown;
02498                 else
02499                     if (tickAbove)
02500                         dir = SlLeft;
02501                     else
02502                         dir = SlRight;
02503 
02504                 QPolygon a;
02505 
02506                 int d = 0;
02507                 switch (dir) {
02508                 case SlUp:
02509                     y1 = y1 + wi/2;
02510                     d =  (wi + 1) / 2 - 1;
02511                     a.setPoints(5, x1,y1, x1,y2, x2,y2, x2,y1, x1+d,y1-d);
02512                     break;
02513                 case SlDown:
02514                     y2 = y2 - wi/2;
02515                     d =  (wi + 1) / 2 - 1;
02516                     a.setPoints(5, x1,y1, x1,y2, x1+d,y2+d, x2,y2, x2,y1);
02517                     break;
02518                 case SlLeft:
02519                     d =  (he + 1) / 2 - 1;
02520                     x1 = x1 + he/2;
02521                     a.setPoints(5, x1,y1, x1-d,y1+d, x1,y2, x2,y2, x2,y1);
02522                     break;
02523                 case SlRight:
02524                     d =  (he + 1) / 2 - 1;
02525                     x2 = x2 - he/2;
02526                     a.setPoints(5, x1,y1, x1,y2, x2,y2, x2+d,y1+d, x2,y1);
02527                     break;
02528                 }
02529 
02530                 QBrush oldBrush = p->brush();
02531                 p->setPen(Qt::NoPen);
02532                 p->setBrush(handleBrush);
02533                 Qt::BGMode oldMode = p->backgroundMode();
02534                 p->setBackgroundMode(Qt::OpaqueMode);
02535                 p->drawRect(x1, y1, x2-x1+1, y2-y1+1);
02536                 p->drawPolygon(a);
02537                 p->setBrush(oldBrush);
02538                 p->setBackgroundMode(oldMode);
02539 
02540                 if (dir != SlUp) {
02541                     p->setPen(c4);
02542                     p->drawLine(x1, y1, x2, y1);
02543                     p->setPen(c3);
02544                     p->drawLine(x1, y1+1, x2, y1+1);
02545                 }
02546                 if (dir != SlLeft) {
02547                     p->setPen(c3);
02548                     p->drawLine(x1+1, y1+1, x1+1, y2);
02549                     p->setPen(c4);
02550                     p->drawLine(x1, y1, x1, y2);
02551                 }
02552                 if (dir != SlRight) {
02553                     p->setPen(c0);
02554                     p->drawLine(x2, y1, x2, y2);
02555                     p->setPen(c1);
02556                     p->drawLine(x2-1, y1+1, x2-1, y2-1);
02557                 }
02558                 if (dir != SlDown) {
02559                     p->setPen(c0);
02560                     p->drawLine(x1, y2, x2, y2);
02561                     p->setPen(c1);
02562                     p->drawLine(x1+1, y2-1, x2-1, y2-1);
02563                 }
02564 
02565                 switch (dir) {
02566                 case SlUp:
02567                     p->setPen(c4);
02568                     p->drawLine(x1, y1, x1+d, y1-d);
02569                     p->setPen(c0);
02570                     d = wi - d - 1;
02571                     p->drawLine(x2, y1, x2-d, y1-d);
02572                     d--;
02573                     p->setPen(c3);
02574                     p->drawLine(x1+1, y1, x1+1+d, y1-d);
02575                     p->setPen(c1);
02576                     p->drawLine(x2-1, y1, x2-1-d, y1-d);
02577                     break;
02578                 case SlDown:
02579                     p->setPen(c4);
02580                     p->drawLine(x1, y2, x1+d, y2+d);
02581                     p->setPen(c0);
02582                     d = wi - d - 1;
02583                     p->drawLine(x2, y2, x2-d, y2+d);
02584                     d--;
02585                     p->setPen(c3);
02586                     p->drawLine(x1+1, y2, x1+1+d, y2+d);
02587                     p->setPen(c1);
02588                     p->drawLine(x2-1, y2, x2-1-d, y2+d);
02589                     break;
02590                 case SlLeft:
02591                     p->setPen(c4);
02592                     p->drawLine(x1, y1, x1-d, y1+d);
02593                     p->setPen(c0);
02594                     d = he - d - 1;
02595                     p->drawLine(x1, y2, x1-d, y2-d);
02596                     d--;
02597                     p->setPen(c3);
02598                     p->drawLine(x1, y1+1, x1-d, y1+1+d);
02599                     p->setPen(c1);
02600                     p->drawLine(x1, y2-1, x1-d, y2-1-d);
02601                     break;
02602                 case SlRight:
02603                     p->setPen(c4);
02604                     p->drawLine(x2, y1, x2+d, y1+d);
02605                     p->setPen(c0);
02606                     d = he - d - 1;
02607                     p->drawLine(x2, y2, x2+d, y2-d);
02608                     d--;
02609                     p->setPen(c3);
02610                     p->drawLine(x2, y1+1, x2+d, y1+1+d);
02611                     p->setPen(c1);
02612                     p->drawLine(x2, y2-1, x2+d, y2-1-d);
02613                     break;
02614                 }
02615             }
02616         }
02617         break;
02618 #endif // QT_NO_SLIDER
02619 #ifdef QT3_SUPPORT
02620     case CC_Q3ListView:
02621         if (const QStyleOptionQ3ListView *lv = qstyleoption_cast<const QStyleOptionQ3ListView *>(opt)) {
02622             int i;
02623             if (lv->subControls & SC_Q3ListView)
02624                 QCommonStyle::drawComplexControl(cc, lv, p, widget);
02625             if (lv->subControls & (SC_Q3ListViewBranch | SC_Q3ListViewExpand)) {
02626                 if (lv->items.isEmpty())
02627                     break;
02628                 QStyleOptionQ3ListViewItem item = lv->items.at(0);
02629                 int y = lv->rect.y();
02630                 int c;
02631                 int dotoffset = 0;
02632                 QPolygon dotlines;
02633                 if ((lv->activeSubControls & SC_All) && (lv->subControls & SC_Q3ListViewExpand)) {
02634                     c = 2;
02635                     dotlines.resize(2);
02636                     dotlines[0] = QPoint(lv->rect.right(), lv->rect.top());
02637                     dotlines[1] = QPoint(lv->rect.right(), lv->rect.bottom());
02638                 } else {
02639                     int linetop = 0, linebot = 0;
02640                     // each branch needs at most two lines, ie. four end points
02641                     dotoffset = (item.itemY + item.height - y) % 2;
02642                     dotlines.resize(item.childCount * 4);
02643                     c = 0;
02644 
02645                     // skip the stuff above the exposed rectangle
02646                     for (i = 1; i < lv->items.size(); ++i) {
02647                         QStyleOptionQ3ListViewItem child = lv->items.at(i);
02648                         if (child.height + y > 0)
02649                             break;
02650                         y += child.totalHeight;
02651                     }
02652                     int bx = lv->rect.width() / 2;
02653 
02654                     // paint stuff in the magical area
02655                     while (i < lv->items.size() && y < lv->rect.height()) {
02656                         QStyleOptionQ3ListViewItem child = lv->items.at(i);
02657                         if (child.features & QStyleOptionQ3ListViewItem::Visible) {
02658                             int lh;
02659                             if (!(item.features & QStyleOptionQ3ListViewItem::MultiLine))
02660                                 lh = child.height;
02661                             else
02662                                 lh = p->fontMetrics().height() + 2 * lv->itemMargin;
02663                             lh = qMax(lh, QApplication::globalStrut().height());
02664                             if (lh % 2 > 0)
02665                                 ++lh;
02666                             linebot = y + lh / 2;
02667                             if (child.features & QStyleOptionQ3ListViewItem::Expandable
02668                                 || child.childCount > 0 && child.height > 0) {
02669                                 // needs a box
02670                                 p->setPen(lv->palette.mid().color());
02671                                 p->drawRect(bx - 4, linebot - 4, 8, 8);
02672                                 // plus or minus
02673                                 p->setPen(lv->palette.text().color());
02674                                 p->drawLine(bx - 2, linebot, bx + 2, linebot);
02675                                 if (!(child.state & State_Open))
02676                                     p->drawLine(bx, linebot - 2, bx, linebot + 2);
02677                                 // dotlinery
02678                                 p->setPen(lv->palette.mid().color());
02679                                 dotlines[c++] = QPoint(bx, linetop);
02680                                 dotlines[c++] = QPoint(bx, linebot - 4);
02681                                 dotlines[c++] = QPoint(bx + 5, linebot);
02682                                 dotlines[c++] = QPoint(lv->rect.width(), linebot);
02683                                 linetop = linebot + 5;
02684                             } else {
02685                                 // just dotlinery
02686                                 dotlines[c++] = QPoint(bx+1, linebot -1);
02687                                 dotlines[c++] = QPoint(lv->rect.width(), linebot -1);
02688                             }
02689                             y += child.totalHeight;
02690                         }
02691                         ++i;
02692                     }
02693 
02694                     // Expand line height to edge of rectangle if there's any
02695                     // visible child below
02696                     while (i < lv->items.size() && lv->items.at(i).height <= 0)
02697                         ++i;
02698                     if (i < lv->items.size())
02699                         linebot = lv->rect.height();
02700 
02701                     if (linetop < linebot) {
02702                         dotlines[c++] = QPoint(bx, linetop);
02703                         dotlines[c++] = QPoint(bx, linebot);
02704                     }
02705                 }
02706                 p->setPen(lv->palette.text().color());
02707                 QBitmap *verticalLine = globalVerticalLine();
02708                 QBitmap *horizontalLine = globalHorizontalLine();
02709                 static bool isInit = false;
02710                 if (!isInit) {
02711                     isInit = true;
02712                     // make 128*1 and 1*128 bitmaps that can be used for
02713                     // drawing the right sort of lines.
02714                     verticalLine->clear();
02715                     horizontalLine->clear();
02716                     QPolygon a(64);
02717                     QPainter p;
02718                     p.begin(verticalLine);
02719                     for(i = 0; i < 64; ++i)
02720                         a.setPoint(i, 0, i * 2 + 1);
02721                     p.setPen(Qt::color1);
02722                     p.drawPoints(a);
02723                     p.end();
02724                     QApplication::flush();
02725                     verticalLine->setMask(*verticalLine);
02726                     p.begin(horizontalLine);
02727                     for(i = 0; i < 64; ++i)
02728                         a.setPoint(i, i * 2 + 1, 0);
02729                     p.setPen(Qt::color1);
02730                     p.drawPoints(a);
02731                     p.end();
02732                     QApplication::flush();
02733                     horizontalLine->setMask(*horizontalLine);
02734                 }
02735 
02736                 int line; // index into dotlines
02737                 if (lv->subControls & SC_Q3ListViewBranch) for(line = 0; line < c; line += 2) {
02738                     // assumptions here: lines are horizontal or vertical.
02739                     // lines always start with the numerically lowest
02740                     // coordinate.
02741 
02742                     // point ... relevant coordinate of current point
02743                     // end ..... same coordinate of the end of the current line
02744                     // other ... the other coordinate of the current point/line
02745                     if (dotlines[line].y() == dotlines[line+1].y()) {
02746                         int end = dotlines[line + 1].x();
02747                         int point = dotlines[line].x();
02748                         int other = dotlines[line].y();
02749                         while (point < end) {
02750                             int i = 128;
02751                             if (i + point > end)
02752                                 i = end-point;
02753                             p->drawPixmap(point, other, *horizontalLine, 0, 0, i, 1);
02754                             point += i;
02755                         }
02756                     } else {
02757                         int end = dotlines[line + 1].y();
02758                         int point = dotlines[line].y();
02759                         int other = dotlines[line].x();
02760                         int pixmapoffset = ((point & 1) != dotoffset) ? 1 : 0;
02761                         while(point < end) {
02762                             int i = 128;
02763                             if (i + point > end)
02764                                 i = end-point;
02765                             p->drawPixmap(other, point, *verticalLine, 0, pixmapoffset, 1, i);
02766                             point += i;
02767                         }
02768                     }
02769                 }
02770             }
02771         }
02772         break;
02773 #endif // QT3_SUPPORT
02774 #ifndef QT_NO_COMBOBOX
02775     case CC_ComboBox:
02776         if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
02777             QBrush editBrush = cmb->palette.brush(QPalette::Base);
02778             if ((cmb->subControls & SC_ComboBoxFrame) && cmb->frame)
02779                 qDrawWinPanel(p, opt->rect, opt->palette, true, &editBrush);
02780             else
02781                 p->fillRect(opt->rect, editBrush);
02782 
02783             if (cmb->subControls & SC_ComboBoxArrow) {
02784                 State flags = State_None;
02785 
02786                 QRect ar = subControlRect(CC_ComboBox, cmb, SC_ComboBoxArrow, widget);
02787                 if (cmb->activeSubControls == SC_ComboBoxArrow) {
02788                     p->setPen(cmb->palette.dark().color());
02789                     p->setBrush(cmb->palette.brush(QPalette::Button));
02790                     p->drawRect(ar.adjusted(0,0,-1,-1));
02791                 } else {
02792                     // Make qDrawWinButton use the right colors for drawing the shade of the button
02793                     QPalette pal(cmb->palette);
02794                     pal.setColor(QPalette::Button, cmb->palette.light().color());
02795                     pal.setColor(QPalette::Light, cmb->palette.button().color());
02796                     qDrawWinButton(p, ar, pal, false,
02797                                    &cmb->palette.brush(QPalette::Button));
02798                 }
02799 
02800                 ar.adjust(2, 2, -2, -2);
02801                 if (opt->state & State_Enabled)
02802                     flags |= State_Enabled;
02803 
02804                 if (cmb->activeSubControls == SC_ComboBoxArrow)
02805                     flags |= State_Sunken;
02806                 QStyleOption arrowOpt(0);
02807                 arrowOpt.rect = ar;
02808                 arrowOpt.palette = cmb->palette;
02809                 arrowOpt.state = flags;
02810                 drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, widget);
02811             }
02812 
02813             if (cmb->subControls & SC_ComboBoxEditField) {
02814                 QRect re = subControlRect(CC_ComboBox, cmb, SC_ComboBoxEditField, widget);
02815                 if (cmb->state & State_HasFocus && !cmb->editable)
02816                     p->fillRect(re.x(), re.y(), re.width(), re.height(),
02817                                 cmb->palette.brush(QPalette::Highlight));
02818 
02819                 if (cmb->state & State_HasFocus) {
02820                     p->setPen(cmb->palette.highlightedText().color());
02821                     p->setBackground(cmb->palette.highlight());
02822 
02823                 } else {
02824                     p->setPen(cmb->palette.text().color());
02825                     p->setBackground(cmb->palette.background());
02826                 }
02827 
02828                 if (cmb->state & State_HasFocus && !cmb->editable) {
02829                     QStyleOptionFocusRect focus;
02830                     focus.QStyleOption::operator=(*cmb);
02831                     focus.rect = subElementRect(SE_ComboBoxFocusRect, cmb, widget);
02832                     focus.state |= State_FocusAtBorder;
02833                     focus.backgroundColor = cmb->palette.highlight().color();
02834                     drawPrimitive(PE_FrameFocusRect, &focus, p, widget);
02835                 }
02836             }
02837         }
02838         break;
02839 #endif // QT_NO_COMBOBOX
02840     default:
02841         QCommonStyle::drawComplexControl(cc, opt, p, widget);
02842     }
02843 }
02844 
02846 QSize QWindowsStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
02847                                       const QSize &csz, const QWidget *widget) const
02848 {
02849     QSize sz(csz);
02850     switch (ct) {
02851     case CT_PushButton:
02852         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
02853             sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
02854             int w = sz.width(),
02855                 h = sz.height();
02856             int defwidth = 0;
02857             if (btn->features & QStyleOptionButton::AutoDefaultButton)
02858                 defwidth = 2 * pixelMetric(PM_ButtonDefaultIndicator, btn, widget);
02859             if (w < 75 + defwidth && btn->icon.isNull())
02860                 w = 75 + defwidth;
02861             if (h < 23 + defwidth)
02862                 h = 23 + defwidth;
02863             sz = QSize(w, h);
02864         }
02865         break;
02866 #ifndef QT_NO_MENU
02867     case CT_MenuItem:
02868         if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
02869             int w = sz.width();
02870             sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
02871 
02872             if (mi->menuItemType == QStyleOptionMenuItem::Separator) {
02873                 sz = QSize(10, windowsSepHeight);
02874             }
02875             else if (mi->icon.isNull()) {
02876                 sz.setHeight(sz.height() - 2);
02877                 w -= 6;
02878             }
02879 
02880             if (mi->menuItemType != QStyleOptionMenuItem::Separator && !mi->icon.isNull())
02881                  sz.setHeight(qMax(sz.height(),
02882                               mi->icon.pixmap(pixelMetric(PM_SmallIconSize), QIcon::Normal).height()
02883                               + 2 * windowsItemFrame));
02884             int maxpmw = mi->maxIconWidth;
02885             int tabSpacing = use2000style ? 20 :windowsTabSpacing;
02886             if (mi->text.contains(QLatin1Char('\t')))
02887                 w += tabSpacing;
02888             else if (mi->menuItemType == QStyleOptionMenuItem::SubMenu)
02889                 w += 2 * windowsArrowHMargin;
02890             else if (mi->menuItemType == QStyleOptionMenuItem::DefaultItem) {
02891                 // adjust the font and add the difference in size.
02892                 // it would be better if the font could be adjusted in the getStyleOptions qmenu func!!
02893                 QFontMetrics fm(mi->font);
02894                 QFont fontBold = mi->font;
02895                 fontBold.setBold(true);
02896                 QFontMetrics fmBold(fontBold);
02897                 w += fmBold.width(mi->text) - fm.width(mi->text);
02898             }
02899 
02900             int checkcol = qMax(maxpmw, use2000style ? 20 : windowsCheckMarkWidth); // Windows always shows a check column
02901             w += checkcol;
02902             w += windowsRightBorder + 10;
02903             sz.setWidth(w);
02904         }
02905         break;
02906 #endif // QT_NO_MENU
02907 #ifndef QT_NO_MENUBAR
02908     case CT_MenuBarItem:
02909         if (!sz.isEmpty())
02910             sz += QSize(windowsItemHMargin * 4, windowsItemVMargin * 2);
02911         break;
02912 #endif
02913                 // Otherwise, fall through
02914     case CT_ToolButton:
02915         if (qstyleoption_cast<const QStyleOptionToolButton *>(opt))
02916             return sz += QSize(7, 6);
02917         // Otherwise, fall through
02918 
02919     default:
02920         sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
02921     }
02922     return sz;
02923 }
02924 
02928 QIcon QWindowsStyle::standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *option,
02929                                                 const QWidget *widget) const
02930 {
02931     QIcon icon;
02932     QPixmap pixmap;
02933 #ifdef Q_OS_WIN
02934     switch (standardIcon) {
02935     case SP_DirIcon:
02936         for (int size = 16 ; size <= 32 ; size += 16) {
02937             pixmap = loadIconFromShell32(4, size);
02938             icon.addPixmap(pixmap, QIcon::Normal, QIcon::Off);
02939             pixmap = loadIconFromShell32(5, size);
02940             icon.addPixmap(pixmap, QIcon::Normal, QIcon::On);
02941         }
02942         break;
02943     case SP_DirLinkIcon:
02944         for (int size = 16 ; size <= 32 ; size += 16) {
02945             QPixmap link = loadIconFromShell32(30, size);
02946             pixmap = loadIconFromShell32(4, size);
02947             if (!pixmap.isNull() && !link.isNull()) {
02948                 QPainter painter(&pixmap);
02949                 painter.drawPixmap(0, 0, size, size, link);
02950                 icon.addPixmap(pixmap, QIcon::Normal, QIcon::Off);
02951             }
02952             link = loadIconFromShell32(30, size);
02953             pixmap = loadIconFromShell32(5, size);
02954             if (!pixmap.isNull() && !link.isNull()) {
02955                 QPainter painter(&pixmap);
02956                 painter.drawPixmap(0, 0, size, size, link);
02957                 icon.addPixmap(pixmap, QIcon::Normal, QIcon::On);
02958             }
02959         }
02960         break;
02961     case SP_FileIcon:
02962         for (int size = 16 ; size <= 32 ; size += 16) {
02963             pixmap = loadIconFromShell32(1, size);
02964             icon.addPixmap(pixmap, QIcon::Normal);
02965         }
02966         break;
02967     case SP_ComputerIcon:
02968         for (int size = 16 ; size <= 32 ; size += 16) {
02969             pixmap = loadIconFromShell32(16, size);
02970             icon.addPixmap(pixmap, QIcon::Normal);
02971         }
02972         break;
02973 
02974     case SP_DesktopIcon:
02975         for (int size = 16 ; size <= 32 ; size += 16) {
02976             pixmap = loadIconFromShell32(35, size);
02977             icon.addPixmap(pixmap, QIcon::Normal);
02978         }
02979         break;
02980     case SP_DriveCDIcon:
02981     case SP_DriveDVDIcon:
02982         for (int size = 16 ; size <= 32 ; size += 16) {
02983             pixmap = loadIconFromShell32(12, size);
02984             icon.addPixmap(pixmap, QIcon::Normal);
02985         }
02986         break;
02987     case SP_DriveNetIcon:
02988         for (int size = 16 ; size <= 32 ; size += 16) {
02989             pixmap = loadIconFromShell32(10, size);
02990             icon.addPixmap(pixmap, QIcon::Normal);
02991         }
02992         break;
02993     case SP_DriveHDIcon:
02994         for (int size = 16 ; size <= 32 ; size += 16) {
02995             pixmap = loadIconFromShell32(9, size);
02996             icon.addPixmap(pixmap, QIcon::Normal);
02997         }
02998         break;
02999     case SP_DriveFDIcon:
03000         for (int size = 16 ; size <= 32 ; size += 16) {
03001             pixmap = loadIconFromShell32(7, size);
03002             icon.addPixmap(pixmap, QIcon::Normal);
03003         }
03004         break;
03005     case SP_FileLinkIcon:
03006         for (int size = 16 ; size <= 32 ; size += 16) {
03007             QPixmap link;
03008             link = loadIconFromShell32(30, size);
03009             pixmap = loadIconFromShell32(1, size);
03010             if (!pixmap.isNull() && !link.isNull()) {
03011                 QPainter painter(&pixmap);
03012                 painter.drawPixmap(0, 0, size, size, link);
03013                 icon.addPixmap(pixmap, QIcon::Normal);
03014             }
03015         }
03016         break;
03017     default:
03018         break;
03019     }
03020 #endif
03021 
03022     if (icon.isNull())
03023         icon = QCommonStyle::standardIconImplementation(standardIcon, option, widget);
03024     return icon;
03025 }
03026 
03027 
03028 #ifdef Q_WS_X11
03029 IconTheme QWindowsStylePrivate::parseIndexFile(const QString &themeName) const
03030 {
03031     Q_Q(const QWindowsStyle);
03032     IconTheme theme;
03033     QFile themeIndex;
03034     QStringList parents;
03035     QHash <int, QString> dirList;
03036 
03037     for ( int i = 0 ; i < iconDirs.size() && !themeIndex.exists() ; ++i) {
03038           themeIndex.setFileName(iconDirs[i] + "/icons/" +
03039                                  themeName + QLatin1String("/index.theme"));
03040     }
03041 
03042     if (themeIndex.open(QIODevice::ReadOnly | QIODevice::Text)) {
03043 
03044         QTextStream in(&themeIndex);
03045 
03046         while (!in.atEnd()) {
03047 
03048             QString line = in.readLine();
03049 
03050             if (line.startsWith(QLatin1String("Inherits="))) {
03051                 line = line.right(line.length() - 9);
03052                 parents = line.split(QLatin1Char(','));
03053             }
03054 
03055             if (line.startsWith(QLatin1String("["))) {
03056                 line = line.trimmed();
03057                 line.chop(1);
03058                 QString dirName = line.right(line.length() - 1);
03059                 if (!in.atEnd()) {
03060                     line = in.readLine();
03061                     int size;
03062                     if (line.startsWith("Size=")) {
03063                         size = line.right(line.length() - 5).toInt();
03064                         if (size)
03065                             dirList.insertMulti(size, dirName);
03066                     }
03067                 }
03068             }
03069         }
03070     } 
03071 
03072     if (q->inherits("QPlastiqueStyle")) {
03073         QFileInfo fileInfo("/usr/share/icons/default.kde");
03074         QDir dir(fileInfo.canonicalFilePath());
03075         QString defaultKDETheme = dir.exists() ? dir.dirName() : "crystalsvg";
03076         if (!parents.contains(defaultKDETheme) && themeName != defaultKDETheme)
03077             parents.append(defaultKDETheme);        
03078     } else if (parents.isEmpty() && themeName != "hicolor") {
03079         parents.append("hicolor");
03080     }
03081     theme = IconTheme(dirList, parents);
03082     return theme;
03083 }
03084 
03085 QPixmap QWindowsStylePrivate::findIconHelper(int size,
03086                                                    const QString &themeName,
03087                                                    const QString &iconName,
03088                                                    QStringList &visited) const
03089 {
03090     QPixmap pixmap;
03091 
03092     if (!themeName.isEmpty()) {
03093 
03094         visited << themeName;
03095         IconTheme theme = themeList.value(themeName);
03096 
03097         if (!theme.isValid()) {
03098             theme = parseIndexFile(themeName);
03099             themeList.insert(themeName, theme);
03100         }
03101 
03102         if (!theme.isValid())
03103             return QPixmap();
03104 
03105         QList <QString> subDirs = theme.dirList().values(size);
03106 
03107         for ( int i = 0 ; i < iconDirs.size() ; ++i) {
03108             for ( int j = 0 ; j < subDirs.size() ; ++j) {
03109                 QString fileName = iconDirs[i] + "/icons/" + themeName + "/" + subDirs[j] + QLatin1Char('/') + iconName;
03110                 pixmap.load(fileName);
03111                 if (!pixmap.isNull())
03112                     break;
03113             }
03114         }
03115 
03116         if (pixmap.isNull()) {
03117             QStringList parents = theme.parents();
03118             //search recursively through inherited themes
03119             for (int i = 0 ; pixmap.isNull() && i < parents.size() ; ++i) {
03120                QString parentTheme = parents[i].trimmed();
03121                if (!visited.contains(parentTheme)) //guard against endless recursion
03122                   pixmap = findIconHelper(size, parentTheme, iconName, visited);
03123             }
03124         }
03125     }
03126     return pixmap;
03127 }
03128 #endif
03129 
03130 QPixmap QWindowsStylePrivate::findIcon(int size, const QString &name) const
03131 {
03132 #ifdef Q_WS_X11
03133     QPixmap pixmap;
03134     QString pixmapName = QLatin1String("$qt") + name + QString::number(size);
03135 
03136     if (QPixmapCache::find(pixmapName, pixmap))
03137         return pixmap;
03138 
03139     if (!themeName.isEmpty()) {
03140         QStringList visited;
03141         pixmap = findIconHelper(size, themeName, name, visited);
03142     }
03143     QPixmapCache::insert(pixmapName, pixmap);
03144 
03145     return pixmap;
03146 #else
03147     Q_UNUSED(size);
03148     Q_UNUSED(name);
03149     return QPixmap();
03150 #endif
03151 }
03152 
03153 #endif // QT_NO_STYLE_WINDOWS

Generated on Thu Mar 15 11:55:46 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1