src/gui/styles/qs60style.cpp
changeset 7 f7bc934e204c
parent 3 41300fa6a67c
equal deleted inserted replaced
3:41300fa6a67c 7:f7bc934e204c
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     8 **
     8 **
    48 #include "qpixmapcache.h"
    48 #include "qpixmapcache.h"
    49 
    49 
    50 #include "qcalendarwidget.h"
    50 #include "qcalendarwidget.h"
    51 #include "qdial.h"
    51 #include "qdial.h"
    52 #include "qdialog.h"
    52 #include "qdialog.h"
       
    53 #include "qmessagebox.h"
    53 #include "qgroupbox.h"
    54 #include "qgroupbox.h"
    54 #include "qheaderview.h"
    55 #include "qheaderview.h"
    55 #include "qlist.h"
    56 #include "qlist.h"
    56 #include "qlistwidget.h"
    57 #include "qlistwidget.h"
    57 #include "qlistview.h"
    58 #include "qlistview.h"
    59 #include "qmenubar.h"
    60 #include "qmenubar.h"
    60 #include "qpushbutton.h"
    61 #include "qpushbutton.h"
    61 #include "qscrollarea.h"
    62 #include "qscrollarea.h"
    62 #include "qscrollbar.h"
    63 #include "qscrollbar.h"
    63 #include "qtabbar.h"
    64 #include "qtabbar.h"
    64 #include "qtablewidget.h"
       
    65 #include "qtableview.h"
    65 #include "qtableview.h"
    66 #include "qtextedit.h"
    66 #include "qtextedit.h"
    67 #include "qtoolbar.h"
    67 #include "qtoolbar.h"
    68 #include "qtoolbutton.h"
    68 #include "qtoolbutton.h"
    69 #include "qfocusframe.h"
    69 #include "qfocusframe.h"
    70 #include "qformlayout.h"
    70 #include "qformlayout.h"
       
    71 #include "qradiobutton.h"
       
    72 #include "qcheckbox.h"
       
    73 #include "qdesktopwidget.h"
       
    74 #include "qprogressbar.h"
    71 
    75 
    72 #include "private/qtoolbarextension_p.h"
    76 #include "private/qtoolbarextension_p.h"
    73 #include "private/qcombobox_p.h"
    77 #include "private/qcombobox_p.h"
    74 #include "private/qwidget_p.h"
    78 #include "private/qwidget_p.h"
    75 #include "private/qapplication_p.h"
    79 #include "private/qapplication_p.h"
    86 
    90 
    87 static const qreal goldenRatio = 1.618;
    91 static const qreal goldenRatio = 1.618;
    88 
    92 
    89 const layoutHeader QS60StylePrivate::m_layoutHeaders[] = {
    93 const layoutHeader QS60StylePrivate::m_layoutHeaders[] = {
    90 // *** generated layout data ***
    94 // *** generated layout data ***
    91 {240,320,1,15,"QVGA Landscape"},
    95 {240,320,1,17,"QVGA Landscape"},
    92 {320,240,1,15,"QVGA Portrait"},
    96 {320,240,1,17,"QVGA Portrait"},
    93 {360,640,1,15,"NHD Landscape"},
    97 {360,640,1,17,"NHD Landscape"},
    94 {640,360,1,15,"NHD Portrait"},
    98 {640,360,1,17,"NHD Portrait"},
    95 {352,800,1,12,"E90 Landscape"}
    99 {352,800,1,12,"E90 Landscape"}
    96 // *** End of generated data ***
   100 // *** End of generated data ***
    97 };
   101 };
    98 const int QS60StylePrivate::m_numberOfLayouts =
   102 const int QS60StylePrivate::m_numberOfLayouts =
    99     (int)sizeof(QS60StylePrivate::m_layoutHeaders)/sizeof(QS60StylePrivate::m_layoutHeaders[0]);
   103     (int)sizeof(QS60StylePrivate::m_layoutHeaders)/sizeof(QS60StylePrivate::m_layoutHeaders[0]);
   100 
   104 
   101 const short QS60StylePrivate::data[][MAX_PIXELMETRICS] = {
   105 const short QS60StylePrivate::data[][MAX_PIXELMETRICS] = {
   102 // *** generated pixel metrics ***
   106 // *** generated pixel metrics ***
   103 {5,0,-909,0,0,2,0,0,-1,7,12,19,13,13,6,200,-909,-909,-909,20,13,2,0,0,21,7,18,-909,3,3,1,-909,-909,0,1,0,0,12,20,15,15,18,18,1,115,18,0,-909,-909,-909,-909,0,0,16,2,-909,0,0,-909,16,-909,-909,-909,-909,32,18,55,24,55,3,3,4,9,13,-909,5,51,11,5,0,3,3,6,8,3,3,-909,2,-909,-909,-909,-909,5,5,3,1},
   107 {5,0,-909,0,0,2,0,0,-1,7,12,19,13,13,6,200,-909,-909,-909,20,13,2,0,0,21,7,18,0,3,3,1,-909,-909,0,1,0,0,12,20,15,15,18,18,1,115,18,0,-909,-909,-909,-909,0,0,16,2,-909,0,0,-909,16,-909,-909,-909,-909,32,18,55,24,55,4,4,4,9,13,-909,5,51,11,5,0,3,3,6,8,3,3,-909,2,-909,-909,-909,-909,5,5,3,1, 106},
   104 {5,0,-909,0,0,1,0,0,-1,8,14,22,15,15,7,164,-909,-909,-909,19,15,2,0,0,21,8,27,-909,4,4,1,-909,-909,0,7,6,0,13,23,17,17,21,21,7,115,21,0,-909,-909,-909,-909,0,0,15,1,-909,0,0,-909,15,-909,-909,-909,-909,32,21,65,27,65,4,4,5,10,15,-909,5,58,13,5,0,4,4,7,9,4,4,-909,2,-909,-909,-909,-909,6,6,3,1},
   108 {5,0,-909,0,0,1,0,0,-1,8,14,22,15,15,7,164,-909,-909,-909,19,15,2,0,0,21,8,27,0,4,4,1,-909,-909,0,7,6,0,13,23,17,17,21,21,7,115,21,0,-909,-909,-909,-909,0,0,15,1,-909,0,0,-909,15,-909,-909,-909,-909,32,21,65,27,65,3,3,5,10,15,-909,5,58,13,5,0,4,4,7,9,4,4,-909,2,-909,-909,-909,-909,6,6,3,1, 106},
   105 {7,0,-909,0,0,2,0,0,-1,25,69,28,19,19,9,258,-909,-909,-909,23,19,26,0,0,32,25,72,-909,5,5,2,-909,-909,0,7,21,0,17,29,22,22,27,27,7,173,29,0,-909,-909,-909,-909,0,0,25,2,-909,0,0,-909,25,-909,-909,-909,-909,87,27,77,35,77,5,5,6,8,19,-909,7,74,19,7,0,5,5,8,12,5,5,-909,3,-909,-909,-909,-909,7,7,3,1},
   109 {7,0,-909,0,0,2,0,0,-1,25,69,28,19,19,9,258,-909,-909,-909,23,19,26,0,0,32,25,72,0,5,5,2,-909,-909,0,7,21,0,17,29,22,22,27,27,7,173,29,0,-909,-909,-909,-909,0,0,25,2,-909,0,0,-909,25,-909,-909,-909,-909,87,27,77,35,77,13,13,6,8,19,-909,7,74,19,7,0,5,5,8,12,5,5,-909,3,-909,-909,-909,-909,7,7,3,1, 135},
   106 {7,0,-909,0,0,2,0,0,-1,25,68,28,19,19,9,258,-909,-909,-909,31,19,6,0,0,32,25,60,-909,5,5,2,-909,-909,0,7,32,0,17,29,22,22,27,27,7,173,29,0,-909,-909,-909,-909,0,0,26,2,-909,0,0,-909,26,-909,-909,-909,-909,87,27,96,35,96,5,5,6,8,19,-909,7,74,22,7,0,5,5,8,12,5,5,-909,3,-909,-909,-909,-909,7,7,3,1},
   110 {7,0,-909,0,0,2,0,0,-1,25,68,28,19,19,9,258,-909,-909,-909,31,19,6,0,0,32,25,60,0,5,5,2,-909,-909,0,7,32,0,17,29,22,22,27,27,7,173,29,0,-909,-909,-909,-909,0,0,26,2,-909,0,0,-909,26,-909,-909,-909,-909,87,27,96,35,96,12,12,6,8,19,-909,7,74,22,7,0,5,5,8,12,5,5,-909,3,-909,-909,-909,-909,7,7,3,1, 135},
   107 {7,0,-909,0,0,2,0,0,-1,10,20,27,18,18,9,301,-909,-909,-909,29,18,5,0,0,35,7,32,-909,5,5,2,-909,-909,0,2,8,0,16,28,21,21,26,26,2,170,26,0,-909,-909,-909,-909,0,0,21,6,-909,0,0,-909,-909,-909,-909,-909,-909,54,26,265,34,265,5,5,6,3,18,-909,7,72,19,7,0,5,6,8,11,6,5,-909,2,-909,-909,-909,-909,5,5,3,1}
   111 {7,0,-909,0,0,2,0,0,-1,10,20,27,18,18,9,301,-909,-909,-909,29,18,5,0,0,35,7,32,0,5,5,2,-909,-909,0,2,8,0,16,28,21,21,26,26,2,170,26,0,-909,-909,-909,-909,0,0,21,6,-909,0,0,-909,-909,-909,-909,-909,-909,54,26,265,34,265,5,5,6,3,18,-909,7,72,19,7,0,5,6,8,11,6,5,-909,2,-909,-909,-909,-909,5,5,3,1, 106}
   108 // *** End of generated data ***
   112 // *** End of generated data ***
   109 };
   113 };
   110 
   114 
   111 const short *QS60StylePrivate::m_pmPointer = QS60StylePrivate::data[0];
   115 const short *QS60StylePrivate::m_pmPointer = QS60StylePrivate::data[0];
   112 
   116 
   113 // theme background texture
   117 // theme background texture
   114 QPixmap *QS60StylePrivate::m_background = 0;
   118 QPixmap *QS60StylePrivate::m_background = 0;
   115 
   119 
   116 // theme palette
   120 // theme palette
   117 QPalette *QS60StylePrivate::m_themePalette = 0;
   121 QPalette *QS60StylePrivate::m_themePalette = 0;
       
   122 
       
   123 qint64 QS60StylePrivate::m_webPaletteKey = 0;
   118 
   124 
   119 const struct QS60StylePrivate::frameElementCenter QS60StylePrivate::m_frameElementsData[] = {
   125 const struct QS60StylePrivate::frameElementCenter QS60StylePrivate::m_frameElementsData[] = {
   120     {SE_ButtonNormal,           QS60StyleEnums::SP_QsnFrButtonTbCenter},
   126     {SE_ButtonNormal,           QS60StyleEnums::SP_QsnFrButtonTbCenter},
   121     {SE_ButtonPressed,          QS60StyleEnums::SP_QsnFrButtonTbCenterPressed},
   127     {SE_ButtonPressed,          QS60StyleEnums::SP_QsnFrButtonTbCenterPressed},
   122     {SE_FrameLineEdit,          QS60StyleEnums::SP_QsnFrInputCenter},
   128     {SE_FrameLineEdit,          QS60StyleEnums::SP_QsnFrInputCenter},
   123     {SE_ListHighlight,          QS60StyleEnums::SP_QsnFrListCenter},
   129     {SE_ListHighlight,          QS60StyleEnums::SP_QsnFrListCenter},
   124     {SE_OptionsMenu,            QS60StyleEnums::SP_QsnFrPopupCenter},
   130     {SE_PopupBackground,        QS60StyleEnums::SP_QsnFrPopupCenter},
   125     {SE_SettingsList,           QS60StyleEnums::SP_QsnFrSetOptCenter},
   131     {SE_SettingsList,           QS60StyleEnums::SP_QsnFrSetOptCenter},
   126     {SE_TableItem,              QS60StyleEnums::SP_QsnFrCaleCenter},
   132     {SE_TableItem,              QS60StyleEnums::SP_QsnFrCaleCenter},
   127     {SE_TableHeaderItem,        QS60StyleEnums::SP_QsnFrCaleHeadingCenter},
   133     {SE_TableHeaderItem,        QS60StyleEnums::SP_QsnFrCaleHeadingCenter},
   128     {SE_ToolTip,                QS60StyleEnums::SP_QsnFrPopupPreviewCenter},
   134     {SE_ToolTip,                QS60StyleEnums::SP_QsnFrPopupPreviewCenter},
   129     {SE_ToolBar,                QS60StyleEnums::SP_QsnFrPopupSubCenter},
   135     {SE_ToolBar,                QS60StyleEnums::SP_QsnFrPopupSubCenter},
   242             QS60StyleEnums::SP_QgnGrafTabPassiveL, Qt::Vertical, painter, rect, flags | SF_PointWest);
   248             QS60StyleEnums::SP_QgnGrafTabPassiveL, Qt::Vertical, painter, rect, flags | SF_PointWest);
   243         break;
   249         break;
   244     case SE_ListHighlight:
   250     case SE_ListHighlight:
   245         drawFrame(SF_ListHighlight, painter, rect, flags | SF_PointNorth);
   251         drawFrame(SF_ListHighlight, painter, rect, flags | SF_PointNorth);
   246         break;
   252         break;
   247     case SE_OptionsMenu:
   253     case SE_PopupBackground:
   248         drawFrame(SF_OptionsMenu, painter, rect, flags | SF_PointNorth);
   254         drawFrame(SF_PopupBackground, painter, rect, flags | SF_PointNorth);
   249         break;
   255         break;
   250     case SE_SettingsList:
   256     case SE_SettingsList:
   251         drawFrame(SF_SettingsList, painter, rect, flags | SF_PointNorth);
   257         drawFrame(SF_SettingsList, painter, rect, flags | SF_PointNorth);
   252         break;
   258         break;
   253     case SE_TableItem:
   259     case SE_TableItem:
   283         drawFrame(SF_ButtonInactive, painter, rect, flags | SF_PointNorth);
   289         drawFrame(SF_ButtonInactive, painter, rect, flags | SF_PointNorth);
   284         break;
   290         break;
   285     case SE_Editor:
   291     case SE_Editor:
   286         drawFrame(SF_FrameLineEdit, painter, rect, flags | SF_PointNorth);
   292         drawFrame(SF_FrameLineEdit, painter, rect, flags | SF_PointNorth);
   287         break;
   293         break;
       
   294     case SE_DropArea:
       
   295         drawPart(QS60StyleEnums::SP_QgnGrafOrgBgGrid, painter, rect, flags | SF_PointNorth);
       
   296         break;
   288     default:
   297     default:
   289         break;
   298         break;
   290     }
   299     }
   291 }
   300 }
   292 
   301 
   296     drawPart(part, painter, rect, flags);
   305     drawPart(part, painter, rect, flags);
   297 }
   306 }
   298 
   307 
   299 short QS60StylePrivate::pixelMetric(int metric)
   308 short QS60StylePrivate::pixelMetric(int metric)
   300 {
   309 {
       
   310     //If it is a custom value, need to strip away the base to map to internal
       
   311     //pixel metric value table
       
   312     if (metric & QStyle::PM_CustomBase) {
       
   313         metric -= QStyle::PM_CustomBase;
       
   314         metric += MAX_NON_CUSTOM_PIXELMETRICS - 1;
       
   315     }
       
   316 
   301     Q_ASSERT(metric < MAX_PIXELMETRICS);
   317     Q_ASSERT(metric < MAX_PIXELMETRICS);
   302     const short returnValue = m_pmPointer[metric];
   318     const short returnValue = m_pmPointer[metric];
   303     return returnValue;
   319     return returnValue;
   304 }
   320 }
   305 
   321 
   308     QColor retColor (color);
   324     QColor retColor (color);
   309     if (option && !(option->state & QStyle::State_Enabled)) {
   325     if (option && !(option->state & QStyle::State_Enabled)) {
   310         QColor hsvColor = retColor.toHsv();
   326         QColor hsvColor = retColor.toHsv();
   311         int colorSat = hsvColor.saturation();
   327         int colorSat = hsvColor.saturation();
   312         int colorVal = hsvColor.value();
   328         int colorVal = hsvColor.value();
   313         colorSat = (colorSat!=0) ? (colorSat>>1) : 128;
   329         colorSat = (colorSat != 0) ? (colorSat >> 1) : 128;
   314         colorVal = (colorVal!=0) ? (colorVal>>1) : 128;
   330         colorVal = (colorVal != 0) ? (colorVal >> 1) : 128;
   315         hsvColor.setHsv(hsvColor.hue(), colorSat, colorVal);
   331         hsvColor.setHsv(hsvColor.hue(), colorSat, colorVal);
   316         retColor = hsvColor.toRgb();
   332         retColor = hsvColor.toRgb();
   317     }
   333     }
   318     return retColor;
   334     return retColor;
   319 }
   335 }
   337     return result;
   353     return result;
   338 }
   354 }
   339 
   355 
   340 bool QS60StylePrivate::drawsOwnThemeBackground(const QWidget *widget)
   356 bool QS60StylePrivate::drawsOwnThemeBackground(const QWidget *widget)
   341 {
   357 {
   342     return qobject_cast<const QDialog *> (widget);
   358     return (widget ? (widget->windowType() == Qt::Dialog) : false);
   343 }
   359 }
   344 
   360 
   345 QFont QS60StylePrivate::s60Font(
   361 QFont QS60StylePrivate::s60Font(
   346     QS60StyleEnums::FontCategories fontCategory, int pointSize) const
   362     QS60StyleEnums::FontCategories fontCategory,
       
   363     int pointSize, bool resolveFontSize) const
   347 {
   364 {
   348     QFont result;
   365     QFont result;
   349     int actualPointSize = pointSize;
   366     int actualPointSize = pointSize;
   350     if (actualPointSize <= 0) {
   367     if (actualPointSize <= 0) {
   351         const QFont appFont = QApplication::font();
   368         const QFont appFont = QApplication::font();
   354             actualPointSize = appFont.pixelSize() * 72 / qt_defaultDpiY();
   371             actualPointSize = appFont.pixelSize() * 72 / qt_defaultDpiY();
   355     }
   372     }
   356     Q_ASSERT(actualPointSize > 0);
   373     Q_ASSERT(actualPointSize > 0);
   357     const QPair<QS60StyleEnums::FontCategories, int> key(fontCategory, actualPointSize);
   374     const QPair<QS60StyleEnums::FontCategories, int> key(fontCategory, actualPointSize);
   358     if (!m_mappedFontsCache.contains(key)) {
   375     if (!m_mappedFontsCache.contains(key)) {
   359         result = s60Font_specific(fontCategory, actualPointSize);
   376         result = s60Font_specific(fontCategory, actualPointSize, resolveFontSize);
   360         m_mappedFontsCache.insert(key, result);
   377         m_mappedFontsCache.insert(key, result);
   361     } else {
   378     } else {
   362         result = m_mappedFontsCache.value(key);
   379         result = m_mappedFontsCache.value(key);
   363         if (result.pointSize() != actualPointSize)
   380         if (result.pointSize() != actualPointSize)
   364             result.setPointSize(actualPointSize);
   381             result.setPointSize(actualPointSize);
   370 {
   387 {
   371     switch(reason){
   388     switch(reason){
   372     case CC_LayoutChange:
   389     case CC_LayoutChange:
   373         // when layout changes, the colors remain in cache, but graphics and fonts can change
   390         // when layout changes, the colors remain in cache, but graphics and fonts can change
   374         m_mappedFontsCache.clear();
   391         m_mappedFontsCache.clear();
   375         deleteBackground();
       
   376         QPixmapCache::clear();
   392         QPixmapCache::clear();
   377         break;
   393         break;
   378     case CC_ThemeChange:
   394     case CC_ThemeChange:
   379         m_colorCache.clear();
   395         m_colorCache.clear();
   380         QPixmapCache::clear();
   396         QPixmapCache::clear();
   396 // Returns Qt::black if there is an issue with the graphics (image is NULL, or no bits() found).
   412 // Returns Qt::black if there is an issue with the graphics (image is NULL, or no bits() found).
   397 QColor QS60StylePrivate::colorFromFrameGraphics(SkinFrameElements frame) const
   413 QColor QS60StylePrivate::colorFromFrameGraphics(SkinFrameElements frame) const
   398 {
   414 {
   399     const bool cachedColorExists = m_colorCache.contains(frame);
   415     const bool cachedColorExists = m_colorCache.contains(frame);
   400     if (!cachedColorExists) {
   416     if (!cachedColorExists) {
   401         const int frameCornerWidth = pixelMetric(PM_Custom_FrameCornerWidth);
   417         const int frameCornerWidth = pixelMetric(PM_FrameCornerWidth);
   402         const int frameCornerHeight = pixelMetric(PM_Custom_FrameCornerHeight);
   418         const int frameCornerHeight = pixelMetric(PM_FrameCornerHeight);
   403         Q_ASSERT(2*frameCornerWidth<32);
   419         Q_ASSERT(2 * frameCornerWidth < 32);
   404         Q_ASSERT(2*frameCornerHeight<32);
   420         Q_ASSERT(2 * frameCornerHeight < 32);
   405 
   421 
   406         const QImage frameImage = QS60StylePrivate::frame(frame, QSize(32,32)).toImage();
   422         const QImage frameImage = QS60StylePrivate::frame(frame, QSize(32, 32)).toImage();
   407         Q_ASSERT(frameImage.bytesPerLine() > 0);
   423         Q_ASSERT(frameImage.bytesPerLine() > 0);
   408         if (frameImage.isNull())
   424         if (frameImage.isNull())
   409             return Qt::black;
   425             return Qt::black;
   410 
   426 
   411         const QRgb *pixelRgb = (const QRgb*)frameImage.bits();
   427         const QRgb *pixelRgb = (const QRgb*)frameImage.bits();
   416         int estimatedBlue = 0;
   432         int estimatedBlue = 0;
   417 
   433 
   418         int skips = 0;
   434         int skips = 0;
   419         int estimations = 0;
   435         int estimations = 0;
   420 
   436 
   421         const int topBorderLastPixel = frameCornerHeight*frameImage.width()-1;
   437         const int topBorderLastPixel = frameCornerHeight*frameImage.width() - 1;
   422         const int bottomBorderFirstPixel = frameImage.width()*frameImage.height()-frameCornerHeight*frameImage.width()-1;
   438         const int bottomBorderFirstPixel = frameImage.width() * frameImage.height() - frameCornerHeight*frameImage.width() - 1;
   423         const int rightBorderFirstPixel = frameImage.width()-frameCornerWidth;
   439         const int rightBorderFirstPixel = frameImage.width() - frameCornerWidth;
   424         const int leftBorderLastPixel = frameCornerWidth;
   440         const int leftBorderLastPixel = frameCornerWidth;
   425 
   441 
   426         while ((skips + estimations) < pixels) {
   442         while ((skips + estimations) < pixels) {
   427             if ((skips+estimations) > topBorderLastPixel &&
   443             if ((skips + estimations) > topBorderLastPixel &&
   428                 (skips+estimations) < bottomBorderFirstPixel) {
   444                 (skips + estimations) < bottomBorderFirstPixel) {
   429                 for (int rowIndex = 0; rowIndex < frameImage.width(); rowIndex++) {
   445                 for (int rowIndex = 0; rowIndex < frameImage.width(); rowIndex++) {
   430                     if (rowIndex > leftBorderLastPixel &&
   446                     if (rowIndex > leftBorderLastPixel &&
   431                         rowIndex < rightBorderFirstPixel) {
   447                         rowIndex < rightBorderFirstPixel) {
   432                         estimatedRed += qRed(*pixelRgb);
   448                         estimatedRed += qRed(*pixelRgb);
   433                         estimatedGreen += qGreen(*pixelRgb);
   449                         estimatedGreen += qGreen(*pixelRgb);
   528     if (orientation == Qt::Horizontal) {
   544     if (orientation == Qt::Horizontal) {
   529         startRect.setWidth(qMin((rect.width() >> 1) - 1, startRect.width()));
   545         startRect.setWidth(qMin((rect.width() >> 1) - 1, startRect.width()));
   530         endRect = startRect.translated(rect.width() - startRect.width(), 0);
   546         endRect = startRect.translated(rect.width() - startRect.width(), 0);
   531         middleRect.adjust(startRect.width(), 0, -startRect.width(), 0);
   547         middleRect.adjust(startRect.width(), 0, -startRect.width(), 0);
   532         if (startRect.bottomRight().x() > endRect.topLeft().x()) {
   548         if (startRect.bottomRight().x() > endRect.topLeft().x()) {
   533             const int overlap = (startRect.bottomRight().x() -  endRect.topLeft().x())>>1;
   549             const int overlap = (startRect.bottomRight().x() -  endRect.topLeft().x()) >> 1;
   534             startRect.setWidth(startRect.width()-overlap);
   550             startRect.setWidth(startRect.width() - overlap);
   535             endRect.adjust(overlap,0,0,0);
   551             endRect.adjust(overlap, 0, 0, 0);
   536         }
   552         }
   537     } else {
   553     } else {
   538         startRect.setHeight(qMin((rect.height() >> 1) - 1, startRect.height()));
   554         startRect.setHeight(qMin((rect.height() >> 1) - 1, startRect.height()));
   539         endRect = startRect.translated(0, rect.height() - startRect.height());
   555         endRect = startRect.translated(0, rect.height() - startRect.height());
   540         middleRect.adjust(0, startRect.height(), 0, -startRect.height());
   556         middleRect.adjust(0, startRect.height(), 0, -startRect.height());
   541         if (startRect.topRight().y() > endRect.bottomLeft().y()) {
   557         if (startRect.topRight().y() > endRect.bottomLeft().y()) {
   542             const int overlap = (startRect.topRight().y() - endRect.bottomLeft().y())>>1;
   558             const int overlap = (startRect.topRight().y() - endRect.bottomLeft().y()) >> 1;
   543             startRect.setHeight(startRect.height()-overlap);
   559             startRect.setHeight(startRect.height() - overlap);
   544             endRect.adjust(0,overlap,0,0);
   560             endRect.adjust(0, overlap, 0, 0);
   545         }
   561         }
   546     }
   562     }
   547 
   563 
   548 #if 0
   564 #if 0
   549     painter->save();
   565     painter->save();
   562 
   578 
   563 QPixmap QS60StylePrivate::cachedPart(QS60StyleEnums::SkinParts part,
   579 QPixmap QS60StylePrivate::cachedPart(QS60StyleEnums::SkinParts part,
   564     const QSize &size, QPainter *painter, SkinElementFlags flags)
   580     const QSize &size, QPainter *painter, SkinElementFlags flags)
   565 {
   581 {
   566     QPixmap result;
   582     QPixmap result;
       
   583     const int animationFrame = (flags & SF_Animation) ? currentAnimationFrame(part) : 0;
       
   584 
   567     const QString cacheKey =
   585     const QString cacheKey =
   568         QString::fromLatin1("S60Style: SkinParts=%1 QSize=%2|%3 SkinPartFlags=%4")
   586         QString::fromLatin1("S60Style: SkinParts=%1 QSize=%2|%3 SkinPartFlags=%4 AnimationFrame=%5")
   569             .arg((int)part).arg(size.width()).arg(size.height()).arg((int)flags);
   587             .arg((int)part).arg(size.width()).arg(size.height()).arg((int)flags).arg(animationFrame);
   570     if (!QPixmapCache::find(cacheKey, result)) {
   588     if (!QPixmapCache::find(cacheKey, result)) {
   571         result = QS60StylePrivate::part(part, size, painter, flags);
   589         result = QS60StylePrivate::part(part, size, painter, flags);
   572         QPixmapCache::insert(cacheKey, result);
   590         QPixmapCache::insert(cacheKey, result);
   573     }
   591     }
   574     return result;
   592     return result;
   617         fontCategory = QS60StyleEnums::FC_Primary;
   635         fontCategory = QS60StyleEnums::FC_Primary;
   618     } else if (qobject_cast<QHeaderView *>(widget)){
   636     } else if (qobject_cast<QHeaderView *>(widget)){
   619         fontCategory = QS60StyleEnums::FC_Secondary;
   637         fontCategory = QS60StyleEnums::FC_Secondary;
   620     } else if (qobject_cast<QGroupBox *>(widget)){
   638     } else if (qobject_cast<QGroupBox *>(widget)){
   621         fontCategory = QS60StyleEnums::FC_Title;
   639         fontCategory = QS60StyleEnums::FC_Title;
       
   640     } else if (qobject_cast<QMessageBox *>(widget)){
       
   641         fontCategory = QS60StyleEnums::FC_Primary;
   622     }
   642     }
   623     if (fontCategory != QS60StyleEnums::FC_Undefined) {
   643     if (fontCategory != QS60StyleEnums::FC_Undefined) {
       
   644         const bool resolveFontSize = widget->testAttribute(Qt::WA_SetFont)
       
   645             && (widget->font().resolve() & QFont::SizeResolved);
   624         const QFont suggestedFont =
   646         const QFont suggestedFont =
   625             s60Font(fontCategory, widget->font().pointSizeF());
   647             s60Font(fontCategory, widget->font().pointSizeF(), resolveFontSize);
   626         widget->setFont(suggestedFont);
   648         widget->setFont(suggestedFont);
   627     }
   649     }
   628 }
   650 }
   629 
   651 
   630 void QS60StylePrivate::setThemePalette(QWidget *widget) const
   652 void QS60StylePrivate::setThemePalette(QWidget *widget) const
   668     palette->setColor(QPalette::LinkVisited, palette->color(QPalette::Link).darker());
   690     palette->setColor(QPalette::LinkVisited, palette->color(QPalette::Link).darker());
   669     palette->setColor(QPalette::Highlight,
   691     palette->setColor(QPalette::Highlight,
   670         s60Color(QS60StyleEnums::CL_QsnHighlightColors, 2, 0));
   692         s60Color(QS60StyleEnums::CL_QsnHighlightColors, 2, 0));
   671     // set background image as a texture brush
   693     // set background image as a texture brush
   672     palette->setBrush(QPalette::Window, backgroundTexture());
   694     palette->setBrush(QPalette::Window, backgroundTexture());
   673     // set these as transparent so that styled full screen theme background is visible
   695     // set as transparent so that styled full screen theme background is visible
   674     palette->setColor(QPalette::AlternateBase, Qt::transparent);
       
   675     palette->setBrush(QPalette::Base, Qt::transparent);
   696     palette->setBrush(QPalette::Base, Qt::transparent);
   676     // set button and tooltipbase based on pixel colors
   697     // set button and tooltipbase based on pixel colors
   677     const QColor buttonColor = colorFromFrameGraphics(SF_ButtonNormal);
   698     const QColor buttonColor = colorFromFrameGraphics(SF_ButtonNormal);
   678     palette->setColor(QPalette::Button, buttonColor);
   699     palette->setColor(QPalette::Button, buttonColor);
   679     const QColor toolTipColor = colorFromFrameGraphics(SF_ToolTip);
   700     const QColor toolTipColor = colorFromFrameGraphics(SF_ToolTip);
   681     palette->setColor(QPalette::Light, palette->color(QPalette::Button).lighter());
   702     palette->setColor(QPalette::Light, palette->color(QPalette::Button).lighter());
   682     palette->setColor(QPalette::Dark, palette->color(QPalette::Button).darker());
   703     palette->setColor(QPalette::Dark, palette->color(QPalette::Button).darker());
   683     palette->setColor(QPalette::Midlight, palette->color(QPalette::Button).lighter(125));
   704     palette->setColor(QPalette::Midlight, palette->color(QPalette::Button).lighter(125));
   684     palette->setColor(QPalette::Mid, palette->color(QPalette::Button).darker(150));
   705     palette->setColor(QPalette::Mid, palette->color(QPalette::Button).darker(150));
   685     palette->setColor(QPalette::Shadow, Qt::black);
   706     palette->setColor(QPalette::Shadow, Qt::black);
       
   707     QColor alternateBase = palette->light().color();
       
   708     alternateBase.setAlphaF(0.8);
       
   709     palette->setColor(QPalette::AlternateBase, alternateBase);
   686 
   710 
   687     QApplication::setPalette(*palette); //calling QApplication::setPalette clears palette hash
   711     QApplication::setPalette(*palette); //calling QApplication::setPalette clears palette hash
   688     setThemePaletteHash(palette);
   712     setThemePaletteHash(palette);
   689     storeThemePalette(palette);
   713     storeThemePalette(palette);
   690 }
   714 }
   742     widgetPalette.setColor(QPalette::ButtonText,
   766     widgetPalette.setColor(QPalette::ButtonText,
   743         s60Color(QS60StyleEnums::CL_QsnTextColors, 8, 0));
   767         s60Color(QS60StyleEnums::CL_QsnTextColors, 8, 0));
   744     QApplication::setPalette(widgetPalette, "QMenuBar");
   768     QApplication::setPalette(widgetPalette, "QMenuBar");
   745     widgetPalette = *palette;
   769     widgetPalette = *palette;
   746 
   770 
       
   771     widgetPalette.setColor(QPalette::Text,
       
   772         s60Color(QS60StyleEnums::CL_QsnTextColors, 22, 0));
       
   773     widgetPalette.setColor(QPalette::HighlightedText,
       
   774         s60Color(QS60StyleEnums::CL_QsnTextColors, 11, 0));
       
   775     QApplication::setPalette(widgetPalette, "QMenu");
       
   776     widgetPalette = *palette;
       
   777 
   747     widgetPalette.setColor(QPalette::WindowText,
   778     widgetPalette.setColor(QPalette::WindowText,
   748         s60Color(QS60StyleEnums::CL_QsnTextColors, 4, 0));
   779         s60Color(QS60StyleEnums::CL_QsnTextColors, 4, 0));
       
   780     widgetPalette.setColor(QPalette::HighlightedText,
       
   781         s60Color(QS60StyleEnums::CL_QsnTextColors, 3, 0));
   749     QApplication::setPalette(widgetPalette, "QTabBar");
   782     QApplication::setPalette(widgetPalette, "QTabBar");
   750     widgetPalette = *palette;
   783     widgetPalette = *palette;
   751 
   784 
       
   785     widgetPalette.setColor(QPalette::HighlightedText,
       
   786         s60Color(QS60StyleEnums::CL_QsnTextColors, 10, 0));
       
   787     QApplication::setPalette(widgetPalette, "QListView");
       
   788     widgetPalette = *palette;
       
   789 
   752     widgetPalette.setColor(QPalette::Text,
   790     widgetPalette.setColor(QPalette::Text,
   753         s60Color(QS60StyleEnums::CL_QsnTextColors, 22, 0));
   791         s60Color(QS60StyleEnums::CL_QsnTextColors, 22, 0));
       
   792     widgetPalette.setColor(QPalette::HighlightedText,
       
   793         s60Color(QS60StyleEnums::CL_QsnTextColors, 11, 0));
   754     QApplication::setPalette(widgetPalette, "QTableView");
   794     QApplication::setPalette(widgetPalette, "QTableView");
   755     widgetPalette = *palette;
   795     widgetPalette = *palette;
   756 
   796 
   757     widgetPalette.setColor(QPalette::Text,
   797     widgetPalette.setColor(QPalette::Text,
   758         s60Color(QS60StyleEnums::CL_QsnTextColors, 27, 0));
   798         s60Color(QS60StyleEnums::CL_QsnTextColors, 27, 0));
   771     widgetPalette.setColor(QPalette::HighlightedText,
   811     widgetPalette.setColor(QPalette::HighlightedText,
   772         s60Color(QS60StyleEnums::CL_QsnTextColors, 24, 0));
   812         s60Color(QS60StyleEnums::CL_QsnTextColors, 24, 0));
   773     QApplication::setPalette(widgetPalette, "QComboBox");
   813     QApplication::setPalette(widgetPalette, "QComboBox");
   774     widgetPalette = *palette;
   814     widgetPalette = *palette;
   775 
   815 
       
   816     widgetPalette.setColor(QPalette::WindowText, s60Color(QS60StyleEnums::CL_QsnTextColors, 7, 0));
       
   817     widgetPalette.setColor(QPalette::HighlightedText,
       
   818         s60Color(QS60StyleEnums::CL_QsnTextColors, 11, 0));
       
   819     QApplication::setPalette(widgetPalette, "QRadioButton");
       
   820     QApplication::setPalette(widgetPalette, "QCheckBox");
       
   821     widgetPalette = *palette;
       
   822 
   776     widgetPalette.setColor(QPalette::WindowText, mainAreaTextColor);
   823     widgetPalette.setColor(QPalette::WindowText, mainAreaTextColor);
   777     widgetPalette.setColor(QPalette::Button, QApplication::palette().color(QPalette::Button));
   824     widgetPalette.setColor(QPalette::Button, QApplication::palette().color(QPalette::Button));
   778     widgetPalette.setColor(QPalette::Dark, mainAreaTextColor.darker());
   825     widgetPalette.setColor(QPalette::Dark, mainAreaTextColor.darker());
   779     widgetPalette.setColor(QPalette::Light, mainAreaTextColor.lighter());
   826     widgetPalette.setColor(QPalette::Light, mainAreaTextColor.lighter());
   780     QApplication::setPalette(widgetPalette, "QDial");
   827     QApplication::setPalette(widgetPalette, "QDial");
   787     //Webpages should not use S60 theme colors as they are designed to work
   834     //Webpages should not use S60 theme colors as they are designed to work
   788     //with themeBackground and do not generally mesh well with web page backgrounds.
   835     //with themeBackground and do not generally mesh well with web page backgrounds.
   789     QPalette webPalette = *palette;
   836     QPalette webPalette = *palette;
   790     webPalette.setColor(QPalette::WindowText, Qt::black);
   837     webPalette.setColor(QPalette::WindowText, Qt::black);
   791     webPalette.setColor(QPalette::Text, Qt::black);
   838     webPalette.setColor(QPalette::Text, Qt::black);
       
   839     webPalette.setBrush(QPalette::Base, Qt::white);
       
   840 
   792     QApplication::setPalette(webPalette, "QWebView");
   841     QApplication::setPalette(webPalette, "QWebView");
   793     QApplication::setPalette(webPalette, "QGraphicsWebView");
   842     QApplication::setPalette(webPalette, "QGraphicsWebView");
       
   843 
       
   844     m_webPaletteKey = webPalette.cacheKey();
   794 }
   845 }
   795 
   846 
   796 QSize QS60StylePrivate::partSize(QS60StyleEnums::SkinParts part, SkinElementFlags flags)
   847 QSize QS60StylePrivate::partSize(QS60StyleEnums::SkinParts part, SkinElementFlags flags)
   797 {
   848 {
   798     QSize result(20, 20);
   849     QSize result(20, 20);
   807         case QS60StyleEnums::SP_QgnGrafTabPassiveR:
   858         case QS60StyleEnums::SP_QgnGrafTabPassiveR:
   808         case QS60StyleEnums::SP_QgnGrafTabPassiveL:
   859         case QS60StyleEnums::SP_QgnGrafTabPassiveL:
   809         case QS60StyleEnums::SP_QgnGrafTabActiveL:
   860         case QS60StyleEnums::SP_QgnGrafTabActiveL:
   810             //Returned QSize for tabs must not be square, but narrow rectangle with width:height
   861             //Returned QSize for tabs must not be square, but narrow rectangle with width:height
   811             //ratio of 1:2 for horizontal tab bars (and 2:1 for vertical ones).
   862             //ratio of 1:2 for horizontal tab bars (and 2:1 for vertical ones).
   812             result.setWidth(result.height()>>1);
   863             result.setWidth(result.height() >> 1);
   813             break;
   864             break;
   814             
   865 
   815         case QS60StyleEnums::SP_QgnGrafNsliderEndLeft:
   866         case QS60StyleEnums::SP_QgnGrafNsliderEndLeft:
   816         case QS60StyleEnums::SP_QgnGrafNsliderEndRight:
   867         case QS60StyleEnums::SP_QgnGrafNsliderEndRight:
   817         case QS60StyleEnums::SP_QgnGrafNsliderMiddle:
   868         case QS60StyleEnums::SP_QgnGrafNsliderMiddle:
   818             result.setWidth(result.height()>>1);
   869             result.setWidth(result.height() >> 1);
   819             break;
   870             break;
   820             
   871 
   821         case QS60StyleEnums::SP_QgnGrafNsliderMarker:
   872         case QS60StyleEnums::SP_QgnGrafNsliderMarker:
   822         case QS60StyleEnums::SP_QgnGrafNsliderMarkerSelected:
   873         case QS60StyleEnums::SP_QgnGrafNsliderMarkerSelected:
   823             result.scale(pixelMetric(QStyle::PM_SliderLength),
   874             result.scale(pixelMetric(QStyle::PM_SliderLength),
   824                 pixelMetric(QStyle::PM_SliderControlThickness), Qt::IgnoreAspectRatio);
   875                 pixelMetric(QStyle::PM_SliderControlThickness), Qt::IgnoreAspectRatio);
   825             break;
   876             break;
   826 
   877 
   827         case QS60StyleEnums::SP_QgnGrafBarFrameSideL:
   878         case QS60StyleEnums::SP_QgnGrafBarFrameSideL:
   828         case QS60StyleEnums::SP_QgnGrafBarFrameSideR:
   879         case QS60StyleEnums::SP_QgnGrafBarFrameSideR:
   829             result.setWidth(pixelMetric(PM_Custom_FrameCornerWidth));
   880             result.setWidth(pixelMetric(PM_FrameCornerWidth));
   830             break;
   881             break;
   831 
   882 
   832         case QS60StyleEnums::SP_QsnCpScrollHandleBottomPressed:
       
   833         case QS60StyleEnums::SP_QsnCpScrollHandleTopPressed:
   883         case QS60StyleEnums::SP_QsnCpScrollHandleTopPressed:
   834         case QS60StyleEnums::SP_QsnCpScrollHandleMiddlePressed:
       
   835         case QS60StyleEnums::SP_QsnCpScrollBgBottom:
   884         case QS60StyleEnums::SP_QsnCpScrollBgBottom:
   836         case QS60StyleEnums::SP_QsnCpScrollBgMiddle:
       
   837         case QS60StyleEnums::SP_QsnCpScrollBgTop:
   885         case QS60StyleEnums::SP_QsnCpScrollBgTop:
   838         case QS60StyleEnums::SP_QsnCpScrollHandleBottom:
   886         case QS60StyleEnums::SP_QsnCpScrollHandleBottom:
       
   887         case QS60StyleEnums::SP_QsnCpScrollHandleTop:
       
   888         case QS60StyleEnums::SP_QsnCpScrollHandleBottomPressed:
       
   889             result.setHeight(pixelMetric(QStyle::PM_ScrollBarExtent));
       
   890             result.setWidth(pixelMetric(QStyle::PM_ScrollBarExtent));
       
   891             break;
       
   892         case QS60StyleEnums::SP_QsnCpScrollHandleMiddlePressed:
       
   893         case QS60StyleEnums::SP_QsnCpScrollBgMiddle:
   839         case QS60StyleEnums::SP_QsnCpScrollHandleMiddle:
   894         case QS60StyleEnums::SP_QsnCpScrollHandleMiddle:
   840         case QS60StyleEnums::SP_QsnCpScrollHandleTop:
       
   841             result.setHeight(pixelMetric(QStyle::PM_ScrollBarExtent));
   895             result.setHeight(pixelMetric(QStyle::PM_ScrollBarExtent));
   842             result.setWidth(pixelMetric(QStyle::PM_ScrollBarSliderMin));
   896             result.setWidth(pixelMetric(QStyle::PM_ScrollBarSliderMin));
   843             break;
   897             break;
   844         default:
   898         default:
   845             // Generic frame part size gathering.
   899             // Generic frame part size gathering.
   848                 switch (m_frameElementsData[i].center - part) {
   902                 switch (m_frameElementsData[i].center - part) {
   849                     case 8: /* CornerTl */
   903                     case 8: /* CornerTl */
   850                     case 7: /* CornerTr */
   904                     case 7: /* CornerTr */
   851                     case 6: /* CornerBl */
   905                     case 6: /* CornerBl */
   852                     case 5: /* CornerBr */
   906                     case 5: /* CornerBr */
   853                         result.setWidth(pixelMetric(PM_Custom_FrameCornerWidth));
   907                         result.setWidth(pixelMetric(PM_FrameCornerWidth));
   854                         // Falltrough intended...
   908                         // Falltrough intended...
   855                     case 4: /* SideT */
   909                     case 4: /* SideT */
   856                     case 3: /* SideB */
   910                     case 3: /* SideB */
   857                         result.setHeight(pixelMetric(PM_Custom_FrameCornerHeight));
   911                         result.setHeight(pixelMetric(PM_FrameCornerHeight));
   858                         break;
   912                         break;
   859                     case 2: /* SideL */
   913                     case 2: /* SideL */
   860                     case 1: /* SideR */
   914                     case 1: /* SideR */
   861                         result.setWidth(pixelMetric(PM_Custom_FrameCornerWidth));
   915                         result.setWidth(pixelMetric(PM_FrameCornerWidth));
   862                         break;
   916                         break;
   863                     case 0: /* center */
   917                     case 0: /* center */
   864                     default:
   918                     default:
   865                         break;
   919                         break;
   866                 }
   920                 }
   873         result.setHeight(temp);
   927         result.setHeight(temp);
   874     }
   928     }
   875     return result;
   929     return result;
   876 }
   930 }
   877 
   931 
   878 bool QS60StylePrivate::canDrawThemeBackground(const QBrush &backgroundBrush)
   932 bool QS60StylePrivate::canDrawThemeBackground(const QBrush &backgroundBrush, const QWidget *widget)
   879 {
   933 {
       
   934     // Always return true for web pages.
       
   935     if (widget && m_webPaletteKey == QApplication::palette(widget).cacheKey())
       
   936         return true;
   880     //If brush is not changed from style's default values, draw theme graphics.
   937     //If brush is not changed from style's default values, draw theme graphics.
   881     return (backgroundBrush.color() == Qt::transparent ||
   938     return (backgroundBrush.color() == Qt::transparent ||
   882             backgroundBrush.style() == Qt::NoBrush) ? true : false;
   939             backgroundBrush.style() == Qt::NoBrush) ? true : false;
   883 }
   940 }
   884 
   941 
   918 
   975 
   919             const QS60StylePrivate::SkinElements grooveElement =
   976             const QS60StylePrivate::SkinElements grooveElement =
   920                 horizontal ? QS60StylePrivate::SE_ScrollBarGrooveHorizontal : QS60StylePrivate::SE_ScrollBarGrooveVertical;
   977                 horizontal ? QS60StylePrivate::SE_ScrollBarGrooveHorizontal : QS60StylePrivate::SE_ScrollBarGrooveVertical;
   921             QS60StylePrivate::drawSkinElement(grooveElement, painter, grooveRect, flags);
   978             QS60StylePrivate::drawSkinElement(grooveElement, painter, grooveRect, flags);
   922 
   979 
   923             const QStyle::SubControls subControls = optionSlider->subControls;
   980             const SubControls subControls = optionSlider->subControls;
   924 
   981 
   925             // select correct slider (horizontal/vertical/pressed)
   982             // select correct slider (horizontal/vertical/pressed)
   926             const bool sliderPressed = ((optionSlider->state & QStyle::State_Sunken) && (subControls & SC_ScrollBarSlider));
   983             const bool sliderPressed = ((optionSlider->state & State_Sunken) && (subControls & SC_ScrollBarSlider));
   927             const QS60StylePrivate::SkinElements handleElement =
   984             const QS60StylePrivate::SkinElements handleElement =
   928                 horizontal ?
   985                 horizontal ?
   929                     ( sliderPressed ?
   986                     ( sliderPressed ?
   930                         QS60StylePrivate::SE_ScrollBarHandlePressedHorizontal :
   987                         QS60StylePrivate::SE_ScrollBarHandlePressedHorizontal :
   931                         QS60StylePrivate::SE_ScrollBarHandleHorizontal ) :
   988                         QS60StylePrivate::SE_ScrollBarHandleHorizontal ) :
   942 
   999 
   943             const QRect sliderGroove = subControlRect(control, optionSlider, SC_SliderGroove, widget);
  1000             const QRect sliderGroove = subControlRect(control, optionSlider, SC_SliderGroove, widget);
   944             const bool horizontal = optionSlider->orientation == Qt::Horizontal;
  1001             const bool horizontal = optionSlider->orientation == Qt::Horizontal;
   945 
  1002 
   946             //Highlight
  1003             //Highlight
   947 /*            if (optionSlider->state & QStyle::State_HasFocus)
  1004 /*            if (optionSlider->state & State_HasFocus)
   948                 drawPrimitive(PE_FrameFocusRect, optionSlider, painter, widget);*/
  1005                 drawPrimitive(PE_FrameFocusRect, optionSlider, painter, widget);*/
   949             
  1006 
   950             //Groove graphics
  1007             //Groove graphics
   951             if (QS60StylePrivate::hasSliderGrooveGraphic()) {
  1008             if (QS60StylePrivate::hasSliderGrooveGraphic()) {
   952                 const QS60StylePrivate::SkinElements grooveElement = horizontal ? 
  1009                 const QS60StylePrivate::SkinElements grooveElement = horizontal ?
   953                     QS60StylePrivate::SE_SliderGrooveHorizontal : 
  1010                     QS60StylePrivate::SE_SliderGrooveHorizontal :
   954                     QS60StylePrivate::SE_SliderGrooveVertical;
  1011                     QS60StylePrivate::SE_SliderGrooveVertical;
   955                 QS60StylePrivate::drawSkinElement(grooveElement, painter, sliderGroove, flags);
  1012                 QS60StylePrivate::drawSkinElement(grooveElement, painter, sliderGroove, flags);
   956             } else {
  1013             } else {
   957                 const QRect sliderGroove = subControlRect(control, optionSlider, SC_SliderGroove, widget);
       
   958                 const QPoint sliderGrooveCenter = sliderGroove.center();
  1014                 const QPoint sliderGrooveCenter = sliderGroove.center();
   959                 const bool horizontal = optionSlider->orientation == Qt::Horizontal;
  1015                 const bool horizontal = optionSlider->orientation == Qt::Horizontal;
   960                 painter->save();
  1016                 painter->save();
   961                 if (widget)
  1017                 if (widget)
   962                     painter->setPen(widget->palette().windowText().color());
  1018                     painter->setPen(widget->palette().windowText().color());
   968             }
  1024             }
   969 
  1025 
   970             //Handle graphics
  1026             //Handle graphics
   971             const QRect sliderHandle = subControlRect(control, optionSlider, SC_SliderHandle, widget);
  1027             const QRect sliderHandle = subControlRect(control, optionSlider, SC_SliderHandle, widget);
   972             QS60StylePrivate::SkinElements handleElement;
  1028             QS60StylePrivate::SkinElements handleElement;
   973             if (optionSlider->state & QStyle::State_Sunken)
  1029             if (optionSlider->state & State_Sunken)
   974                 handleElement =
  1030                 handleElement =
   975                         horizontal ? QS60StylePrivate::SE_SliderHandleSelectedHorizontal : QS60StylePrivate::SE_SliderHandleSelectedVertical;
  1031                         horizontal ? QS60StylePrivate::SE_SliderHandleSelectedHorizontal : QS60StylePrivate::SE_SliderHandleSelectedVertical;
   976             else    
  1032             else
   977                 handleElement =
  1033                 handleElement =
   978                     horizontal ? QS60StylePrivate::SE_SliderHandleHorizontal : QS60StylePrivate::SE_SliderHandleVertical;
  1034                     horizontal ? QS60StylePrivate::SE_SliderHandleHorizontal : QS60StylePrivate::SE_SliderHandleVertical;
   979             QS60StylePrivate::drawSkinElement(handleElement, painter, sliderHandle, flags);
  1035             QS60StylePrivate::drawSkinElement(handleElement, painter, sliderHandle, flags);
   980         }
  1036         }
   981         break;
  1037         break;
   990             // Button frame
  1046             // Button frame
   991             QStyleOptionFrame  buttonOption;
  1047             QStyleOptionFrame  buttonOption;
   992             buttonOption.QStyleOption::operator=(*cmb);
  1048             buttonOption.QStyleOption::operator=(*cmb);
   993             const int maxHeight = cmbxFrame.height();
  1049             const int maxHeight = cmbxFrame.height();
   994             const int maxWidth = cmbxFrame.width() - cmbxEditField.width();
  1050             const int maxWidth = cmbxFrame.width() - cmbxEditField.width();
   995             const int topLeftPoint = direction ? cmbxEditField.right()+1 : cmbxEditField.left()+1-maxWidth;
  1051             const int topLeftPoint = direction ?
       
  1052                 (cmbxEditField.right() + 1) : (cmbxEditField.left() + 1 - maxWidth);
   996             const QRect buttonRect(topLeftPoint, cmbxEditField.top(), maxWidth, maxHeight);
  1053             const QRect buttonRect(topLeftPoint, cmbxEditField.top(), maxWidth, maxHeight);
   997             buttonOption.rect = buttonRect;
  1054             buttonOption.rect = buttonRect;
   998             buttonOption.state = cmb->state & (State_Enabled | State_MouseOver);
  1055             buttonOption.state = cmb->state;
   999             drawPrimitive(PE_PanelButtonCommand, &buttonOption, painter, widget);
  1056             drawPrimitive(PE_PanelButtonCommand, &buttonOption, painter, widget);
  1000 
  1057 
  1001             // draw label background - label itself is drawn separately
  1058             // draw label background - label itself is drawn separately
  1002             const QS60StylePrivate::SkinElements skinElement = QS60StylePrivate::SE_FrameLineEdit;
  1059             const QS60StylePrivate::SkinElements skinElement = QS60StylePrivate::SE_FrameLineEdit;
  1003             QS60StylePrivate::drawSkinElement(skinElement, painter, cmbxEditField, flags);
  1060             QS60StylePrivate::drawSkinElement(skinElement, painter, cmbxEditField, flags);
  1015         break;
  1072         break;
  1016 #endif // QT_NO_COMBOBOX
  1073 #endif // QT_NO_COMBOBOX
  1017 #ifndef QT_NO_TOOLBUTTON
  1074 #ifndef QT_NO_TOOLBUTTON
  1018     case CC_ToolButton:
  1075     case CC_ToolButton:
  1019         if (const QStyleOptionToolButton *toolBtn = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
  1076         if (const QStyleOptionToolButton *toolBtn = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
  1020             const State bflags = toolBtn->state;
  1077             State bflags = toolBtn->state & ~State_Sunken;
       
  1078 
       
  1079             if (bflags & State_AutoRaise) {
       
  1080                 if (!(bflags & State_MouseOver) || !(bflags & State_Enabled)) {
       
  1081                     bflags &= ~State_Raised;
       
  1082                 }
       
  1083             }
       
  1084             State mflags = bflags;
       
  1085             if (toolBtn->state & State_Sunken) {
       
  1086                 if (toolBtn->activeSubControls & SC_ToolButton)
       
  1087                     bflags |= State_Sunken;
       
  1088                 mflags |= State_Sunken;
       
  1089             }
       
  1090 
  1021             const QRect button(subControlRect(control, toolBtn, SC_ToolButton, widget));
  1091             const QRect button(subControlRect(control, toolBtn, SC_ToolButton, widget));
  1022             QRect menuRect = QRect();
  1092             QRect menuRect = QRect();
  1023             if (toolBtn->subControls & SC_ToolButtonMenu)
  1093             if (toolBtn->subControls & SC_ToolButtonMenu)
  1024                 menuRect = subControlRect(control, toolBtn, SC_ToolButtonMenu, widget);
  1094                 menuRect = subControlRect(control, toolBtn, SC_ToolButtonMenu, widget);
  1025 
  1095 
  1026             QStyleOptionToolButton toolButton = *toolBtn;
  1096             if (toolBtn->subControls & SC_ToolButton) {
  1027 
       
  1028             if (sub&SC_ToolButton) {
       
  1029                 QStyleOption tool(0);
  1097                 QStyleOption tool(0);
  1030                 tool.palette = toolBtn->palette;
  1098                 tool.palette = toolBtn->palette;
  1031 
  1099 
  1032                 // Check if toolbutton is in toolbar.
  1100                 if (bflags & (State_Sunken | State_On | State_Raised | State_Enabled)) {
  1033                 QToolBar *toolBar = 0;
       
  1034                 if (widget)
       
  1035                     toolBar = qobject_cast<QToolBar *>(widget->parentWidget());
       
  1036 
       
  1037                 if (bflags & (State_Sunken | State_On | State_Raised)) {
       
  1038                     tool.rect = button.unite(menuRect);
  1101                     tool.rect = button.unite(menuRect);
  1039                     tool.state = bflags;
  1102                     tool.state = bflags;
  1040 
  1103                     const QToolButton *toolButtonWidget = qobject_cast<const QToolButton *>(widget);
  1041                     // todo: I'd like to move extension button next to where last button is
  1104                     QS60StylePrivate::SkinElements element;
  1042                     // however, the painter seems to want to clip the button rect even if I turn of the clipping.
  1105                     if (toolButtonWidget)
  1043                     if (toolBar && (qobject_cast<const QToolBarExtension *>(widget))){
  1106                         element = (toolButtonWidget->isDown()) ? QS60StylePrivate::SE_ToolBarButtonPressed : QS60StylePrivate::SE_ToolBarButton;
  1044                         /*QList<QAction *> actionList = toolBar->actions();
  1107                     else
  1045                         const int actionCount = actionList.count();
  1108                         element = (option->state & State_Sunken) ? QS60StylePrivate::SE_ToolBarButtonPressed : QS60StylePrivate::SE_ToolBarButton;
  1046                         const int toolbarWidth = toolBar->width();
  1109                     QS60StylePrivate::drawSkinElement(element, painter, tool.rect, flags);
  1047                         const int extButtonWidth = pixelMetric(PM_ToolBarExtensionExtent, option, widget);
  1110                     drawPrimitive(PE_PanelButtonTool, &tool, painter, widget);
  1048                         const int toolBarButtonWidth = pixelMetric(PM_ToolBarIconSize, option, widget);
       
  1049                         const int frame = pixelMetric(PM_ToolBarFrameWidth, option, widget);
       
  1050                         const int margin = pixelMetric(PM_ToolBarItemMargin, option, widget);
       
  1051                         const int border = frame + margin;
       
  1052                         const int spacing = pixelMetric(PM_ToolBarItemSpacing, option, widget);
       
  1053                         const int toolBarButtonArea = toolbarWidth - extButtonWidth - spacing - 2*border;
       
  1054                         const int numberOfVisibleButtons = toolBarButtonArea / toolBarButtonWidth;
       
  1055                         // new extension button place is after border and all the other visible buttons (with spacings)
       
  1056                         const int newXForExtensionButton = numberOfVisibleButtons * toolBarButtonWidth + (numberOfVisibleButtons-1)*spacing + border;
       
  1057                         painter->save();
       
  1058                         painter->setClipping(false);
       
  1059                         tool.rect.translate(-newXForExtensionButton,0);
       
  1060                         painter->restore();*/
       
  1061                     }
       
  1062 
       
  1063                     if (toolBar){
       
  1064                         /*if (toolBar->orientation() == Qt::Vertical){
       
  1065                             // todo: I'd like to make all vertical buttons the same size, but again the painter
       
  1066                             // prefers to use clipping for button rects, even though clipping has been set off.
       
  1067                             painter->save();
       
  1068                             painter->setClipping(false);
       
  1069 
       
  1070                             const int origWidth = tool.rect.width();
       
  1071                             const int newWidth = toolBar->width()-2*pixelMetric(PM_ToolBarFrameWidth, option, widget);
       
  1072                             painter->translate(origWidth-newWidth,0);
       
  1073                             tool.rect.translate(origWidth-tool.rect.width(),0);
       
  1074                             tool.rect.setWidth(newWidth);
       
  1075 
       
  1076                             if (option->state & QStyle::State_Sunken)
       
  1077                                 QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ToolBarButtonPressed, painter, tool.rect, flags);
       
  1078                             else
       
  1079                                 QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ToolBarButton, painter, tool.rect, flags);
       
  1080 
       
  1081                         }*/
       
  1082                         if (option->state & QStyle::State_Sunken)
       
  1083                             QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ToolBarButtonPressed, painter, tool.rect, flags);
       
  1084                         else
       
  1085                             QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ToolBarButton, painter, tool.rect, flags);
       
  1086                         /*
       
  1087                         if (toolBar->orientation() == Qt::Vertical)
       
  1088                             painter->restore();
       
  1089                             */
       
  1090                     } else {
       
  1091                         drawPrimitive(PE_PanelButtonTool, &tool, painter, widget);
       
  1092                     }
       
  1093 
       
  1094                     if (toolButton.subControls & SC_ToolButtonMenu) {
       
  1095                         tool.rect = menuRect;
       
  1096                         tool.state = bflags;
       
  1097                         drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget);
       
  1098                     }
       
  1099                 }
  1111                 }
  1100             }
  1112                 if (toolBtn->subControls & SC_ToolButtonMenu) {
  1101 
  1113                     tool.rect = menuRect;
       
  1114                     tool.state = mflags;
       
  1115                     drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget);
       
  1116                 }
       
  1117             }
       
  1118             QStyleOptionToolButton toolButton = *toolBtn;
  1102             if (toolBtn->features & QStyleOptionToolButton::Arrow) {
  1119             if (toolBtn->features & QStyleOptionToolButton::Arrow) {
  1103                 QStyle::PrimitiveElement pe;
  1120                 PrimitiveElement pe;
  1104                 switch (toolBtn->arrowType) {
  1121                 switch (toolBtn->arrowType) {
  1105                     case Qt::LeftArrow:
  1122                     case Qt::LeftArrow:
  1106                         pe = QStyle::PE_IndicatorArrowLeft;
  1123                         pe = PE_IndicatorArrowLeft;
  1107                         break;
  1124                         break;
  1108                     case Qt::RightArrow:
  1125                     case Qt::RightArrow:
  1109                         pe = QStyle::PE_IndicatorArrowRight;
  1126                         pe = PE_IndicatorArrowRight;
  1110                         break;
  1127                         break;
  1111                     case Qt::UpArrow:
  1128                     case Qt::UpArrow:
  1112                         pe = QStyle::PE_IndicatorArrowUp;
  1129                         pe = PE_IndicatorArrowUp;
  1113                         break;
  1130                         break;
  1114                     case Qt::DownArrow:
  1131                     case Qt::DownArrow:
  1115                         pe = QStyle::PE_IndicatorArrowDown;
  1132                         pe = PE_IndicatorArrowDown;
  1116                         break;
  1133                         break;
  1117                     default:
  1134                     default:
  1118                         break; }
  1135                         break; }
  1119                 toolButton.rect = button;
  1136                 toolButton.rect = button;
  1120                 drawPrimitive(pe, &toolButton, painter, widget);
  1137                 drawPrimitive(pe, &toolButton, painter, widget);
  1121             }
  1138             }
  1122 
  1139 
  1123             if (toolBtn->text.length()>0 ||
  1140             if (toolBtn->text.length() > 0 ||
  1124                 !toolBtn->icon.isNull()) {
  1141                 !toolBtn->icon.isNull()) {
  1125                 const int frameWidth = pixelMetric(PM_DefaultFrameWidth, option, widget);
  1142                 const int frameWidth = pixelMetric(PM_DefaultFrameWidth, option, widget);
  1126                 toolButton.rect = button.adjusted(frameWidth, frameWidth, -frameWidth, -frameWidth);
  1143                 toolButton.rect = button.adjusted(frameWidth, frameWidth, -frameWidth, -frameWidth);
  1127                 drawControl(CE_ToolButtonLabel, &toolButton, painter, widget);
  1144                 drawControl(CE_ToolButtonLabel, &toolButton, painter, widget);
  1128                 }
  1145                 }
  1194     case CC_GroupBox:
  1211     case CC_GroupBox:
  1195         if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
  1212         if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
  1196             // Draw frame
  1213             // Draw frame
  1197             const QRect textRect = subControlRect(CC_GroupBox, option, SC_GroupBoxLabel, widget);
  1214             const QRect textRect = subControlRect(CC_GroupBox, option, SC_GroupBoxLabel, widget);
  1198             const QRect checkBoxRect = subControlRect(CC_GroupBox, option, SC_GroupBoxCheckBox, widget);
  1215             const QRect checkBoxRect = subControlRect(CC_GroupBox, option, SC_GroupBoxCheckBox, widget);
  1199             if (groupBox->subControls & QStyle::SC_GroupBoxFrame) {
  1216             if (groupBox->subControls & SC_GroupBoxFrame) {
  1200                 QStyleOptionFrameV2 frame;
  1217                 QStyleOptionFrameV2 frame;
  1201                 frame.QStyleOption::operator=(*groupBox);
  1218                 frame.QStyleOption::operator=(*groupBox);
  1202                 frame.features = groupBox->features;
  1219                 frame.features = groupBox->features;
  1203                 frame.lineWidth = groupBox->lineWidth;
  1220                 frame.lineWidth = groupBox->lineWidth;
  1204                 frame.midLineWidth = groupBox->midLineWidth;
  1221                 frame.midLineWidth = groupBox->midLineWidth;
  1205                 frame.rect = subControlRect(CC_GroupBox, option, SC_GroupBoxFrame, widget);
  1222                 frame.rect = subControlRect(CC_GroupBox, option, SC_GroupBoxFrame, widget);
  1206                 drawPrimitive(PE_FrameGroupBox, &frame, painter, widget);
  1223                 drawPrimitive(PE_FrameGroupBox, &frame, painter, widget);
  1207             }
  1224             }
  1208 
  1225 
  1209             // Draw title
  1226             // Draw title
  1210             if ((groupBox->subControls & QStyle::SC_GroupBoxLabel) && !groupBox->text.isEmpty()) {
  1227             if ((groupBox->subControls & SC_GroupBoxLabel) && !groupBox->text.isEmpty()) {
  1211                 const QColor textColor = groupBox->textColor;
  1228                 const QColor textColor = groupBox->textColor;
  1212                 painter->save();
  1229                 painter->save();
  1213 
  1230 
  1214                 if (textColor.isValid())
  1231                 if (textColor.isValid())
  1215                     painter->setPen(textColor);
  1232                     painter->setPen(textColor);
  1216                 int alignment = int(groupBox->textAlignment);
  1233                 int alignment = int(groupBox->textAlignment);
  1217                 if (!styleHint(QStyle::SH_UnderlineShortcut, option, widget))
  1234                 if (!styleHint(SH_UnderlineShortcut, option, widget))
  1218                     alignment |= Qt::TextHideMnemonic;
  1235                     alignment |= Qt::TextHideMnemonic;
  1219 
  1236 
  1220                 drawItemText(painter, textRect,  Qt::TextShowMnemonic | Qt::AlignHCenter | Qt::AlignVCenter | alignment,
  1237                 drawItemText(painter, textRect,  Qt::TextShowMnemonic | Qt::AlignHCenter | Qt::AlignVCenter | alignment,
  1221                              groupBox->palette, groupBox->state & State_Enabled, groupBox->text,
  1238                              groupBox->palette, groupBox->state & State_Enabled, groupBox->text,
  1222                              textColor.isValid() ? QPalette::NoRole : QPalette::WindowText);
  1239                              textColor.isValid() ? QPalette::NoRole : QPalette::WindowText);
  1244 void QS60Style::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
  1261 void QS60Style::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
  1245 {
  1262 {
  1246     Q_D(const QS60Style);
  1263     Q_D(const QS60Style);
  1247     const QS60StylePrivate::SkinElementFlags flags = (option->state & State_Enabled) ?  QS60StylePrivate::SF_StateEnabled : QS60StylePrivate::SF_StateDisabled;
  1264     const QS60StylePrivate::SkinElementFlags flags = (option->state & State_Enabled) ?  QS60StylePrivate::SF_StateEnabled : QS60StylePrivate::SF_StateDisabled;
  1248     switch (element) {
  1265     switch (element) {
       
  1266         case CE_CheckBox:
       
  1267         case CE_RadioButton:
       
  1268             if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
       
  1269                 bool isRadio = (element == CE_RadioButton);
       
  1270                 QStyleOptionButton subopt = *btn;
       
  1271 
       
  1272                 // Highlight needs to be drawn first, as it goes "underneath" the text and indicator.
       
  1273                 if (btn->state & State_HasFocus) {
       
  1274                     QStyleOptionFocusRect fropt;
       
  1275                     fropt.QStyleOption::operator=(*btn);
       
  1276                     fropt.rect = subElementRect(isRadio ? SE_RadioButtonFocusRect
       
  1277                                                         : SE_CheckBoxFocusRect, btn, widget);
       
  1278                     drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
       
  1279 
       
  1280                     subopt.palette.setColor(QPalette::Active, QPalette::WindowText,
       
  1281                         subopt.palette.highlightedText().color());
       
  1282                 }
       
  1283 
       
  1284                 subopt.rect = subElementRect(isRadio ? SE_RadioButtonIndicator
       
  1285                                                      : SE_CheckBoxIndicator, btn, widget);
       
  1286                 drawPrimitive(isRadio ? PE_IndicatorRadioButton : PE_IndicatorCheckBox,
       
  1287                               &subopt, painter, widget);
       
  1288                 subopt.rect = subElementRect(isRadio ? SE_RadioButtonContents
       
  1289                                                      : SE_CheckBoxContents, btn, widget);
       
  1290 
       
  1291                 drawControl(isRadio ? CE_RadioButtonLabel : CE_CheckBoxLabel, &subopt, painter, widget);
       
  1292             }
       
  1293             break;
       
  1294 
  1249     case CE_PushButton:
  1295     case CE_PushButton:
  1250         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
  1296         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
  1251 
  1297 
  1252             drawControl(CE_PushButtonBevel, btn, painter, widget);
  1298             drawControl(CE_PushButtonBevel, btn, painter, widget);
  1253             QStyleOptionButton subopt = *btn;
  1299             QStyleOptionButton subopt = *btn;
  1256             drawControl(CE_PushButtonLabel, &subopt, painter, widget);
  1302             drawControl(CE_PushButtonLabel, &subopt, painter, widget);
  1257         }
  1303         }
  1258         break;
  1304         break;
  1259     case CE_PushButtonBevel:
  1305     case CE_PushButtonBevel:
  1260         if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
  1306         if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
  1261             const bool isDisabled = !(option->state & QStyle::State_Enabled);
  1307             const bool isDisabled = !(option->state & State_Enabled);
  1262             const bool isFlat = button->features & QStyleOptionButton::Flat;
  1308             const bool isFlat = button->features & QStyleOptionButton::Flat;
  1263             QS60StyleEnums::SkinParts skinPart;
  1309             QS60StyleEnums::SkinParts skinPart;
  1264             QS60StylePrivate::SkinElements skinElement;
  1310             QS60StylePrivate::SkinElements skinElement;
  1265             if (!isDisabled) {
  1311             if (!isDisabled) {
  1266                 const bool isPressed = (option->state & QStyle::State_Sunken) ||
  1312                 const bool isPressed = (option->state & State_Sunken) ||
  1267                                        (option->state & QStyle::State_On);
  1313                                        (option->state & State_On);
  1268                 if (isFlat) {
  1314                 if (isFlat) {
  1269                     skinPart =
  1315                     skinPart =
  1270                         isPressed ? QS60StyleEnums::SP_QsnFrButtonTbCenterPressed : QS60StyleEnums::SP_QsnFrButtonTbCenter;
  1316                         isPressed ? QS60StyleEnums::SP_QsnFrButtonTbCenterPressed : QS60StyleEnums::SP_QsnFrButtonTbCenter;
  1271                 } else {
  1317                 } else {
  1272                     skinElement =
  1318                     skinElement =
  1287 #ifndef QT_NO_TOOLBUTTON
  1333 #ifndef QT_NO_TOOLBUTTON
  1288     case CE_ToolButtonLabel:
  1334     case CE_ToolButtonLabel:
  1289         if (const QStyleOptionToolButton *toolBtn = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
  1335         if (const QStyleOptionToolButton *toolBtn = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
  1290             QStyleOptionToolButton optionToolButton = *toolBtn;
  1336             QStyleOptionToolButton optionToolButton = *toolBtn;
  1291 
  1337 
  1292             if (!optionToolButton.icon.isNull() && (optionToolButton.state & QStyle::State_Sunken)
  1338             if (!optionToolButton.icon.isNull() && (optionToolButton.state & State_Sunken)
  1293                     && (optionToolButton.state & State_Enabled)) {
  1339                     && (optionToolButton.state & State_Enabled)) {
  1294 
  1340 
  1295                     const QIcon::State state = optionToolButton.state & State_On ? QIcon::On : QIcon::Off;
  1341                     const QIcon::State state = optionToolButton.state & State_On ? QIcon::On : QIcon::Off;
  1296                     const QPixmap pm(optionToolButton.icon.pixmap(optionToolButton.rect.size().boundedTo(optionToolButton.iconSize),
  1342                     const QPixmap pm(optionToolButton.icon.pixmap(optionToolButton.rect.size().boundedTo(optionToolButton.iconSize),
  1297                             QIcon::Normal, state));
  1343                             QIcon::Normal, state));
  1331                 else
  1377                 else
  1332                     editRect.translate(comboBox->iconSize.width() + 4, 0);
  1378                     editRect.translate(comboBox->iconSize.width() + 4, 0);
  1333             }
  1379             }
  1334             if (!comboBox->currentText.isEmpty() && !comboBox->editable) {
  1380             if (!comboBox->currentText.isEmpty() && !comboBox->editable) {
  1335                 QCommonStyle::drawItemText(painter,
  1381                 QCommonStyle::drawItemText(painter,
  1336                             editRect.adjusted(QS60StylePrivate::pixelMetric(PM_Custom_FrameCornerWidth), 0, -1, 0),
  1382                             editRect.adjusted(QS60StylePrivate::pixelMetric(PM_FrameCornerWidth), 0, -1, 0),
  1337                             visualAlignment(comboBox->direction, Qt::AlignLeft | Qt::AlignVCenter),
  1383                             visualAlignment(comboBox->direction, Qt::AlignLeft | Qt::AlignVCenter),
  1338                             comboBox->palette, comboBox->state & State_Enabled, comboBox->currentText);
  1384                             comboBox->palette, comboBox->state & State_Enabled, comboBox->currentText);
  1339             }
  1385             }
  1340             painter->restore();
  1386             painter->restore();
  1341         }
  1387         }
  1346         if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(option)) {
  1392         if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(option)) {
  1347             QStyleOptionViewItemV4 voptAdj = *vopt;
  1393             QStyleOptionViewItemV4 voptAdj = *vopt;
  1348             painter->save();
  1394             painter->save();
  1349 
  1395 
  1350             painter->setClipRect(voptAdj.rect);
  1396             painter->setClipRect(voptAdj.rect);
  1351             const bool isSelected = (vopt->state & QStyle::State_Selected);
  1397             const bool isSelected = (vopt->state & State_Selected);
  1352             const bool hasFocus = (vopt->state & QStyle::State_HasFocus);
  1398             const bool hasFocus = (vopt->state & State_HasFocus);
  1353 
  1399 
  1354             bool isScrollBarVisible = false;
  1400             bool isScrollBarVisible = false;
  1355             int scrollBarWidth = 0;
  1401             int scrollBarWidth = 0;
  1356             QList<QScrollBar *> scrollBars = qFindChildren<QScrollBar *>(widget);
  1402             QList<QScrollBar *> scrollBars = qFindChildren<QScrollBar *>(widget);
  1357             for (int i = 0; i < scrollBars.size(); ++i) {
  1403             for (int i = 0; i < scrollBars.size(); ++i) {
  1361                     scrollBarWidth = scrollBar->size().width();
  1407                     scrollBarWidth = scrollBar->size().width();
  1362                     break;
  1408                     break;
  1363                 }
  1409                 }
  1364             }
  1410             }
  1365 
  1411 
  1366             int rightValue = widget ? widget->contentsRect().right() : 0;
  1412             int rightValue = widget ? widget->contentsRect().right() : voptAdj.rect.right();
  1367 
  1413 
  1368             if (isScrollBarVisible)
  1414             if (isScrollBarVisible)
  1369                 rightValue -= scrollBarWidth;
  1415                 rightValue -= scrollBarWidth;
  1370 
  1416 
  1371             if (voptAdj.rect.right() > rightValue)
  1417             if (voptAdj.rect.right() > rightValue)
  1379             if (vopt->backgroundBrush == Qt::NoBrush) {
  1425             if (vopt->backgroundBrush == Qt::NoBrush) {
  1380                 if (itemView) {
  1426                 if (itemView) {
  1381                     const QModelIndex index = vopt->index;
  1427                     const QModelIndex index = vopt->index;
  1382                     //todo: Draw cell background only once - for the first cell.
  1428                     //todo: Draw cell background only once - for the first cell.
  1383                     QStyleOptionViewItemV4 voptAdj2 = voptAdj;
  1429                     QStyleOptionViewItemV4 voptAdj2 = voptAdj;
  1384                     const QModelIndex indexFirst = itemView->model()->index(0,0);
  1430                     const QModelIndex indexFirst = itemView->model()->index(0, 0);
  1385                     const QModelIndex indexLast = itemView->model()->index(
  1431                     const QModelIndex indexLast = itemView->model()->index(
  1386                             itemView->model()->rowCount()-1,itemView->model()->columnCount()-1);
  1432                             itemView->model()->rowCount() - 1, itemView->model()->columnCount() -1);
  1387                     if (itemView->viewport())
  1433                     if (itemView->viewport())
  1388                         voptAdj2.rect = QRect( itemView->visualRect(indexFirst).topLeft(),
  1434                         voptAdj2.rect = QRect( itemView->visualRect(indexFirst).topLeft(),
  1389                                 itemView->visualRect(indexLast).bottomRight()).intersect(itemView->viewport()->rect());
  1435                                 itemView->visualRect(indexLast).bottomRight()).intersect(itemView->viewport()->rect());
  1390                     drawPrimitive(PE_PanelItemViewItem, &voptAdj, painter, widget);
  1436                     drawPrimitive(PE_PanelItemViewItem, &voptAdj, painter, widget);
  1391                 }
  1437                 }
  1392             } else { QCommonStyle::drawPrimitive(PE_PanelItemViewItem, &voptAdj, painter, widget);}
  1438             } else { QCommonStyle::drawPrimitive(PE_PanelItemViewItem, &voptAdj, painter, widget);}
  1393 
  1439 
  1394             // draw the focus rect
  1440             // draw the focus rect
  1395             if (isSelected | hasFocus) {
  1441             if (isSelected || hasFocus ) {
  1396                 QRect highlightRect = option->rect.adjusted(1,1,-1,-1);
  1442                 QRect highlightRect = option->rect.adjusted(1,1,-1,-1);
  1397                 QAbstractItemView::SelectionBehavior selectionBehavior =
  1443                 QAbstractItemView::SelectionBehavior selectionBehavior =
  1398                     itemView ? itemView->selectionBehavior() : QAbstractItemView::SelectItems;
  1444                     itemView ? itemView->selectionBehavior() : QAbstractItemView::SelectItems;
  1399                 if (selectionBehavior != QAbstractItemView::SelectItems) {
  1445                 if (selectionBehavior != QAbstractItemView::SelectItems) {
  1400                     // set highlight rect so that it is continuous from cell to cell, yet sligthly
  1446                     // set highlight rect so that it is continuous from cell to cell, yet sligthly
  1421                 else
  1467                 else
  1422                     painter->fillRect(highlightRect, vopt->palette.highlight());
  1468                     painter->fillRect(highlightRect, vopt->palette.highlight());
  1423             }
  1469             }
  1424 
  1470 
  1425              // draw the icon
  1471              // draw the icon
  1426              const QIcon::Mode mode = (voptAdj.state & QStyle::State_Enabled) ? QIcon::Normal : QIcon::Disabled;
  1472              const QIcon::Mode mode = (voptAdj.state & State_Enabled) ? QIcon::Normal : QIcon::Disabled;
  1427              const QIcon::State state = voptAdj.state & QStyle::State_Open ? QIcon::On : QIcon::Off;
  1473              const QIcon::State state = voptAdj.state & State_Open ? QIcon::On : QIcon::Off;
  1428              voptAdj.icon.paint(painter, iconRect, voptAdj.decorationAlignment, mode, state);
  1474              voptAdj.icon.paint(painter, iconRect, voptAdj.decorationAlignment, mode, state);
  1429 
  1475 
  1430              // Draw selection check mark. Show check mark only in multi selection modes.
  1476              // Draw selection check mark. Show check mark only in multi selection modes.
  1431              if (itemView) {
  1477              if (itemView) {
  1432                  const bool singleSelection =
  1478                  const bool singleSelection =
  1434                       itemView->selectionMode() == QAbstractItemView::NoSelection);
  1480                       itemView->selectionMode() == QAbstractItemView::NoSelection);
  1435                  const QRect selectionRect = subElementRect(SE_ItemViewItemCheckIndicator, &voptAdj, widget);
  1481                  const QRect selectionRect = subElementRect(SE_ItemViewItemCheckIndicator, &voptAdj, widget);
  1436 
  1482 
  1437                  QStyleOptionViewItemV4 checkMarkOption(voptAdj);
  1483                  QStyleOptionViewItemV4 checkMarkOption(voptAdj);
  1438                  // Draw selection mark.
  1484                  // Draw selection mark.
  1439                  if (voptAdj.state & QStyle::State_Selected && !singleSelection) {
  1485                  if (voptAdj.state & State_Selected && !singleSelection) {
  1440                      checkMarkOption.rect = selectionRect;
  1486                      checkMarkOption.rect = selectionRect;
  1441                      drawPrimitive(QStyle::PE_IndicatorViewItemCheck, &checkMarkOption, painter, widget);
  1487                      drawPrimitive(PE_IndicatorViewItemCheck, &checkMarkOption, painter, widget);
  1442                      if ( textRect.right() > selectionRect.left() )
  1488                      if ( textRect.right() > selectionRect.left() )
  1443                          textRect.setRight(selectionRect.left());
  1489                          textRect.setRight(selectionRect.left());
  1444                  } else if (singleSelection &&
  1490                  } else if (singleSelection &&
  1445                      voptAdj.features & QStyleOptionViewItemV2::HasCheckIndicator &&
  1491                      voptAdj.features & QStyleOptionViewItemV2::HasCheckIndicator &&
  1446                      selectionRect.isValid()) {
  1492                      selectionRect.isValid()) {
  1447                      checkMarkOption.rect = selectionRect;
  1493                      checkMarkOption.rect = selectionRect;
  1448                      checkMarkOption.state = checkMarkOption.state & ~QStyle::State_HasFocus;
  1494                      checkMarkOption.state = checkMarkOption.state & ~State_HasFocus;
  1449 
  1495 
  1450                      switch (vopt->checkState) {
  1496                      switch (vopt->checkState) {
  1451                      case Qt::Unchecked:
  1497                      case Qt::Unchecked:
  1452                          checkMarkOption.state |= QStyle::State_Off;
  1498                          checkMarkOption.state |= State_Off;
  1453                          break;
  1499                          break;
  1454                      case Qt::PartiallyChecked:
  1500                      case Qt::PartiallyChecked:
  1455                          checkMarkOption.state |= QStyle::State_NoChange;
  1501                          checkMarkOption.state |= State_NoChange;
  1456                          break;
  1502                          break;
  1457                      case Qt::Checked:
  1503                      case Qt::Checked:
  1458                          checkMarkOption.state |= QStyle::State_On;
  1504                          checkMarkOption.state |= State_On;
  1459                          break;
  1505                          break;
  1460                      }
  1506                      }
  1461                      drawPrimitive(QStyle::PE_IndicatorViewItemCheck, &checkMarkOption, painter, widget);
  1507                      drawPrimitive(PE_IndicatorViewItemCheck, &checkMarkOption, painter, widget);
  1462                  }
  1508                  }
  1463              }
  1509              }
  1464 
  1510 
  1465              // draw the text
  1511              // draw the text
  1466             if (!voptAdj.text.isEmpty()) {
  1512             if (!voptAdj.text.isEmpty()) {
  1467                 if (isSelected) {
  1513                 if (isSelected || hasFocus )
  1468                     if (qobject_cast<const QTableView *>(widget))
  1514                     painter->setPen(voptAdj.palette.highlightedText().color());
  1469                         voptAdj.palette.setColor(
  1515                 else
  1470                             QPalette::Text, QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnTextColors, 11, 0));
  1516                     painter->setPen(voptAdj.palette.text().color());
  1471                     else
       
  1472                         voptAdj.palette.setColor(
       
  1473                             QPalette::Text, QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnTextColors, 10, 0));
       
  1474                 }
       
  1475                 painter->setPen(voptAdj.palette.text().color());
       
  1476                 d->viewItemDrawText(painter, &voptAdj, textRect);
  1517                 d->viewItemDrawText(painter, &voptAdj, textRect);
  1477             }
  1518             }
  1478             painter->restore();
  1519             painter->restore();
  1479         }
  1520         }
  1480         break;
  1521         break;
  1481 #endif // QT_NO_ITEMVIEWS
  1522 #endif // QT_NO_ITEMVIEWS
  1482 #ifndef QT_NO_TABBAR
  1523 #ifndef QT_NO_TABBAR
  1483     case CE_TabBarTabShape:
  1524     case CE_TabBarTabShape:
  1484         if (const QStyleOptionTabV3 *optionTab = qstyleoption_cast<const QStyleOptionTabV3 *>(option)) {
  1525         if (const QStyleOptionTabV3 *optionTab = qstyleoption_cast<const QStyleOptionTabV3 *>(option)) {
  1485             QStyleOptionTabV3 optionTabAdj = *optionTab;
  1526             QStyleOptionTabV3 optionTabAdj = *optionTab;
  1486             const bool isSelected = optionTab->state & QStyle::State_Selected;
  1527             const bool isSelected = optionTab->state & State_Selected;
  1487             const bool directionMirrored = (optionTab->direction == Qt::RightToLeft);
  1528             const bool directionMirrored = (optionTab->direction == Qt::RightToLeft);
  1488             QS60StylePrivate::SkinElements skinElement;
  1529             QS60StylePrivate::SkinElements skinElement;
  1489             switch (optionTab->shape) {
  1530             switch (optionTab->shape) {
  1490                 case QTabBar::TriangularEast:
  1531                 case QTabBar::TriangularEast:
  1491                 case QTabBar::RoundedEast:
  1532                 case QTabBar::RoundedEast:
  1516                     skinElement==QS60StylePrivate::SE_TabBarTabEastActive||
  1557                     skinElement==QS60StylePrivate::SE_TabBarTabEastActive||
  1517                     skinElement==QS60StylePrivate::SE_TabBarTabNorthActive||
  1558                     skinElement==QS60StylePrivate::SE_TabBarTabNorthActive||
  1518                     skinElement==QS60StylePrivate::SE_TabBarTabSouthActive||
  1559                     skinElement==QS60StylePrivate::SE_TabBarTabSouthActive||
  1519                     skinElement==QS60StylePrivate::SE_TabBarTabWestActive) {
  1560                     skinElement==QS60StylePrivate::SE_TabBarTabWestActive) {
  1520                 const int borderThickness =
  1561                 const int borderThickness =
  1521                     QS60StylePrivate::pixelMetric(QStyle::PM_DefaultFrameWidth);
  1562                     QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth);
  1522                 const int tabOverlap =
  1563                 const int tabOverlap =
  1523                     QS60StylePrivate::pixelMetric(QStyle::PM_TabBarTabOverlap) - borderThickness;
  1564                     QS60StylePrivate::pixelMetric(PM_TabBarTabOverlap) - borderThickness;
  1524                 //todo: draw navi wipe behind tabbar - must be drawn with first draw
  1565                 //todo: draw navi wipe behind tabbar - must be drawn with first draw
  1525 
  1566 
  1526                 if (skinElement==QS60StylePrivate::SE_TabBarTabEastInactive||
  1567                 if (skinElement==QS60StylePrivate::SE_TabBarTabEastInactive||
  1527                         skinElement==QS60StylePrivate::SE_TabBarTabEastActive||
  1568                         skinElement==QS60StylePrivate::SE_TabBarTabEastActive||
  1528                         skinElement==QS60StylePrivate::SE_TabBarTabWestInactive||
  1569                         skinElement==QS60StylePrivate::SE_TabBarTabWestInactive||
  1541     case CE_TabBarTabLabel:
  1582     case CE_TabBarTabLabel:
  1542         if (const QStyleOptionTabV3 *tab = qstyleoption_cast<const QStyleOptionTabV3 *>(option)) {
  1583         if (const QStyleOptionTabV3 *tab = qstyleoption_cast<const QStyleOptionTabV3 *>(option)) {
  1543             QStyleOptionTabV3 optionTab = *tab;
  1584             QStyleOptionTabV3 optionTab = *tab;
  1544             QRect tr = optionTab.rect;
  1585             QRect tr = optionTab.rect;
  1545             const bool directionMirrored = (optionTab.direction == Qt::RightToLeft);
  1586             const bool directionMirrored = (optionTab.direction == Qt::RightToLeft);
  1546             const int borderThickness = QS60StylePrivate::pixelMetric(QStyle::PM_DefaultFrameWidth);
  1587             const int borderThickness = QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth);
  1547             const int tabOverlap =
  1588             const int tabOverlap =
  1548                 QS60StylePrivate::pixelMetric(QStyle::PM_TabBarTabOverlap) - borderThickness;
  1589                 QS60StylePrivate::pixelMetric(PM_TabBarTabOverlap) - borderThickness;
  1549             const QRect windowRect = painter->window();
  1590             const QRect windowRect = painter->window();
  1550 
  1591 
  1551             switch (tab->shape) {
  1592             switch (tab->shape) {
  1552                 case QTabBar::TriangularWest:
  1593                 case QTabBar::TriangularWest:
  1553                 case QTabBar::RoundedWest:
  1594                 case QTabBar::RoundedWest:
  1569             painter->save();
  1610             painter->save();
  1570             QFont f = painter->font();
  1611             QFont f = painter->font();
  1571             f.setPointSizeF(f.pointSizeF() * KTabFontMul);
  1612             f.setPointSizeF(f.pointSizeF() * KTabFontMul);
  1572             painter->setFont(f);
  1613             painter->setFont(f);
  1573 
  1614 
  1574             if (option->state & QStyle::State_Selected){
  1615             const bool selected = optionTab.state & State_Selected;
       
  1616             if (selected)
  1575                 optionTab.palette.setColor(QPalette::Active, QPalette::WindowText,
  1617                 optionTab.palette.setColor(QPalette::Active, QPalette::WindowText,
  1576                     QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnTextColors, 3, option));
  1618                     optionTab.palette.highlightedText().color());
  1577             }
       
  1578 
  1619 
  1579             const bool verticalTabs = optionTab.shape == QTabBar::RoundedEast
  1620             const bool verticalTabs = optionTab.shape == QTabBar::RoundedEast
  1580                                 || optionTab.shape == QTabBar::RoundedWest
  1621                                 || optionTab.shape == QTabBar::RoundedWest
  1581                                 || optionTab.shape == QTabBar::TriangularEast
  1622                                 || optionTab.shape == QTabBar::TriangularEast
  1582                                 || optionTab.shape == QTabBar::TriangularWest;
  1623                                 || optionTab.shape == QTabBar::TriangularWest;
  1583             const bool selected = optionTab.state & State_Selected;
  1624 
  1584             if (verticalTabs) {
  1625             if (verticalTabs) {
  1585                 painter->save();
  1626                 painter->save();
  1586                 int newX, newY, newRotation;
  1627                 int newX, newY, newRotation;
  1587                 if (optionTab.shape == QTabBar::RoundedEast || optionTab.shape == QTabBar::TriangularEast) {
  1628                 if (optionTab.shape == QTabBar::RoundedEast || optionTab.shape == QTabBar::TriangularEast) {
  1588                     newX = tr.width();
  1629                     newX = tr.width();
  1597                 QTransform m;
  1638                 QTransform m;
  1598                 m.translate(newX, newY);
  1639                 m.translate(newX, newY);
  1599                 m.rotate(newRotation);
  1640                 m.rotate(newRotation);
  1600                 painter->setTransform(m, true);
  1641                 painter->setTransform(m, true);
  1601             }
  1642             }
  1602             tr.adjust(0, 0, pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, tab, widget),
  1643             tr.adjust(0, 0, pixelMetric(PM_TabBarTabShiftHorizontal, tab, widget),
  1603                             pixelMetric(QStyle::PM_TabBarTabShiftVertical, tab, widget));
  1644                             pixelMetric(PM_TabBarTabShiftVertical, tab, widget));
  1604 
  1645 
  1605             if (selected) {
  1646             if (selected) {
  1606                 tr.setBottom(tr.bottom() - pixelMetric(QStyle::PM_TabBarTabShiftVertical, tab, widget));
  1647                 tr.setBottom(tr.bottom() - pixelMetric(PM_TabBarTabShiftVertical, tab, widget));
  1607                 tr.setRight(tr.right() - pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, tab, widget));
  1648                 tr.setRight(tr.right() - pixelMetric(PM_TabBarTabShiftHorizontal, tab, widget));
  1608             }
  1649             }
  1609 
  1650 
  1610             int alignment = Qt::AlignCenter | Qt::TextShowMnemonic;
  1651             int alignment = Qt::AlignCenter | Qt::TextShowMnemonic;
  1611             if (!styleHint(SH_UnderlineShortcut, &optionTab, widget))
  1652             if (!styleHint(SH_UnderlineShortcut, &optionTab, widget))
  1612                 alignment |= Qt::TextHideMnemonic;
  1653                 alignment |= Qt::TextHideMnemonic;
  1616                 if (iconSize.height() > iconExtent || iconSize.width() > iconExtent)
  1657                 if (iconSize.height() > iconExtent || iconSize.width() > iconExtent)
  1617                     iconSize = QSize(iconExtent, iconExtent);
  1658                     iconSize = QSize(iconExtent, iconExtent);
  1618                 QPixmap tabIcon = optionTab.icon.pixmap(iconSize,
  1659                 QPixmap tabIcon = optionTab.icon.pixmap(iconSize,
  1619                     (optionTab.state & State_Enabled) ? QIcon::Normal : QIcon::Disabled);
  1660                     (optionTab.state & State_Enabled) ? QIcon::Normal : QIcon::Disabled);
  1620                 if (tab->text.isEmpty())
  1661                 if (tab->text.isEmpty())
  1621                     painter->drawPixmap(tr.center().x() - (tabIcon.height() >>1),
  1662                     painter->drawPixmap(tr.center().x() - (tabIcon.height() >> 1),
  1622                                         tr.center().y() - (tabIcon.height() >>1),
  1663                                         tr.center().y() - (tabIcon.height() >> 1),
  1623                                         tabIcon);
  1664                                         tabIcon);
  1624                 else
  1665                 else
  1625                     painter->drawPixmap(tr.left() + tabOverlap,
  1666                     painter->drawPixmap(tr.left() + tabOverlap,
  1626                                         tr.center().y() - (tabIcon.height() >>1),
  1667                                         tr.center().y() - (tabIcon.height() >> 1),
  1627                                         tabIcon);
  1668                                         tabIcon);
  1628                 tr.setLeft(tr.left() + iconSize.width() + 4);
  1669                 tr.setLeft(tr.left() + iconSize.width() + 4);
  1629             }
  1670             }
  1630 
  1671 
  1631             QCommonStyle::drawItemText(painter, tr, alignment, optionTab.palette, tab->state & State_Enabled, tab->text, QPalette::WindowText);
  1672             QCommonStyle::drawItemText(painter, tr, alignment, optionTab.palette, tab->state & State_Enabled, tab->text, QPalette::WindowText);
  1643 
  1684 
  1644             if (optionProgressBar->minimum == optionProgressBar->maximum && optionProgressBar->minimum == 0) {
  1685             if (optionProgressBar->minimum == optionProgressBar->maximum && optionProgressBar->minimum == 0) {
  1645                 // busy indicator
  1686                 // busy indicator
  1646                 const QS60StylePrivate::SkinElementFlag orientationFlag = optionProgressBar->orientation == Qt::Horizontal ?
  1687                 const QS60StylePrivate::SkinElementFlag orientationFlag = optionProgressBar->orientation == Qt::Horizontal ?
  1647                     QS60StylePrivate::SF_PointNorth : QS60StylePrivate::SF_PointWest;
  1688                     QS60StylePrivate::SF_PointNorth : QS60StylePrivate::SF_PointWest;
  1648                 QS60StylePrivate::drawSkinPart(QS60StyleEnums::SP_QgnGrafBarWait, painter, progressRect, flags | orientationFlag);
  1689 
       
  1690                 QS60StylePrivate::drawSkinPart(QS60StyleEnums::SP_QgnGrafBarWaitAnim,
       
  1691                         painter, progressRect, flags | orientationFlag | QS60StylePrivate::SF_Animation );
  1649             } else {
  1692             } else {
  1650                 const qreal progressFactor = (optionProgressBar->minimum == optionProgressBar->maximum) ? 1.0
  1693                 const qreal progressFactor = (optionProgressBar->minimum == optionProgressBar->maximum) ? 1.0
  1651                     : (qreal)optionProgressBar->progress / optionProgressBar->maximum;
  1694                     : (qreal)optionProgressBar->progress / optionProgressBar->maximum;
       
  1695                 const int frameWidth = pixelMetric(PM_DefaultFrameWidth, option, widget);
  1652                 if (optionProgressBar->orientation == Qt::Horizontal) {
  1696                 if (optionProgressBar->orientation == Qt::Horizontal) {
  1653                     progressRect.setWidth(int(progressRect.width() * progressFactor));
  1697                     progressRect.setWidth(int(progressRect.width() * progressFactor));
  1654                     if(optionProgressBar->direction == Qt::RightToLeft)
  1698                     if(optionProgressBar->direction == Qt::RightToLeft)
  1655                         progressRect.translate(optionProgressBar->rect.width()-progressRect.width(),0);
  1699                         progressRect.translate(optionProgressBar->rect.width() - progressRect.width(), 0);
  1656                     progressRect.adjust(1, 0, -1, 0);
  1700                     progressRect.adjust(frameWidth, 0, -frameWidth, 0);
  1657                 } else {
  1701                 } else {
  1658                     progressRect.adjust(0, 1, 0, -1);
  1702                     progressRect.adjust(0, frameWidth, 0, -frameWidth);
  1659                     progressRect.setTop(progressRect.bottom() - int(progressRect.height() * progressFactor));
  1703                     progressRect.setTop(progressRect.bottom() - int(progressRect.height() * progressFactor));
  1660                 }
  1704                 }
  1661 
  1705 
  1662                 const QS60StylePrivate::SkinElements skinElement = optionProgressBar->orientation == Qt::Horizontal ?
  1706                 const QS60StylePrivate::SkinElements skinElement = optionProgressBar->orientation == Qt::Horizontal ?
  1663                     QS60StylePrivate::SE_ProgressBarIndicatorHorizontal : QS60StylePrivate::SE_ProgressBarIndicatorVertical;
  1707                     QS60StylePrivate::SE_ProgressBarIndicatorHorizontal : QS60StylePrivate::SE_ProgressBarIndicatorVertical;
  1702             uint text_flags = Qt::AlignLeading | Qt::TextShowMnemonic | Qt::TextDontClip
  1746             uint text_flags = Qt::AlignLeading | Qt::TextShowMnemonic | Qt::TextDontClip
  1703                             | Qt::TextSingleLine | Qt::AlignVCenter;
  1747                             | Qt::TextSingleLine | Qt::AlignVCenter;
  1704             if (!styleHint(SH_UnderlineShortcut, menuItem, widget))
  1748             if (!styleHint(SH_UnderlineShortcut, menuItem, widget))
  1705                 text_flags |= Qt::TextHideMnemonic;
  1749                 text_flags |= Qt::TextHideMnemonic;
  1706 
  1750 
  1707             if ((option->state & State_Selected) && (option->state & State_Enabled))
  1751             const bool selected = (option->state & State_Selected) && (option->state & State_Enabled);
       
  1752             if (selected)
  1708                 QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ListHighlight, painter, option->rect, flags);
  1753                 QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ListHighlight, painter, option->rect, flags);
  1709 
  1754 
  1710             QRect iconRect = subElementRect(SE_ItemViewItemDecoration, &optionMenuItem, widget);
  1755             QRect iconRect = subElementRect(SE_ItemViewItemDecoration, &optionMenuItem, widget);
  1711             QRect textRect = subElementRect(SE_ItemViewItemText, &optionMenuItem, widget);
  1756             QRect textRect = subElementRect(SE_ItemViewItemText, &optionMenuItem, widget);
  1712 
  1757 
  1713             //todo: move the vertical spacing stuff into subElementRect
  1758             //todo: move the vertical spacing stuff into subElementRect
  1714             const int vSpacing = QS60StylePrivate::pixelMetric(QStyle::PM_LayoutVerticalSpacing);
  1759             const int vSpacing = QS60StylePrivate::pixelMetric(PM_LayoutVerticalSpacing);
  1715             if (checkable){
  1760             if (checkable){
  1716                 const int hSpacing = QS60StylePrivate::pixelMetric(QStyle::PM_LayoutHorizontalSpacing);
  1761                 const int hSpacing = QS60StylePrivate::pixelMetric(PM_LayoutHorizontalSpacing);
  1717                 QStyleOptionMenuItem optionCheckBox;
  1762                 QStyleOptionMenuItem optionCheckBox;
  1718                 optionCheckBox.QStyleOptionMenuItem::operator=(*menuItem);
  1763                 optionCheckBox.QStyleOptionMenuItem::operator=(*menuItem);
  1719                 optionCheckBox.rect.setWidth(pixelMetric(PM_IndicatorWidth));
  1764                 optionCheckBox.rect.setWidth(pixelMetric(PM_IndicatorWidth));
  1720                 optionCheckBox.rect.setHeight(pixelMetric(PM_IndicatorHeight));
  1765                 optionCheckBox.rect.setHeight(pixelMetric(PM_IndicatorHeight));
  1721                 const int moveByX = optionCheckBox.rect.width()+vSpacing;
  1766                 const int moveByX = optionCheckBox.rect.width() + vSpacing;
  1722                 if (optionMenuItem.direction == Qt::LeftToRight) {
  1767                 if (optionMenuItem.direction == Qt::LeftToRight) {
  1723                     textRect.translate(moveByX,0);
  1768                     textRect.translate(moveByX, 0);
  1724                     iconRect.translate(moveByX, 0);
  1769                     iconRect.translate(moveByX, 0);
  1725                     iconRect.setWidth(iconRect.width()+vSpacing);
  1770                     iconRect.setWidth(iconRect.width() + vSpacing);
  1726                     textRect.setWidth(textRect.width()-moveByX-vSpacing);
  1771                     textRect.setWidth(textRect.width() - moveByX - vSpacing);
  1727                     optionCheckBox.rect.translate(vSpacing/2, hSpacing/2);
  1772                     optionCheckBox.rect.translate(vSpacing >> 1, hSpacing >> 1);
  1728                 } else {
  1773                 } else {
  1729                     textRect.setWidth(textRect.width()-moveByX);
  1774                     textRect.setWidth(textRect.width() - moveByX);
  1730                     iconRect.setWidth(iconRect.width()+vSpacing);
  1775                     iconRect.setWidth(iconRect.width() + vSpacing);
  1731                     iconRect.translate(-optionCheckBox.rect.width()-vSpacing, 0);
  1776                     iconRect.translate(-optionCheckBox.rect.width() - vSpacing, 0);
  1732                     optionCheckBox.rect.translate(textRect.width()+iconRect.width(),0);
  1777                     optionCheckBox.rect.translate(textRect.width() + iconRect.width(), 0);
  1733                 }
  1778                 }
  1734                 drawPrimitive(PE_IndicatorMenuCheckMark, &optionCheckBox, painter, widget);
  1779                 drawPrimitive(PE_IndicatorMenuCheckMark, &optionCheckBox, painter, widget);
  1735             }
  1780             }
  1736             //draw icon and/or checkState
  1781             //draw icon and/or checkState
  1737             QPixmap pix = menuItem->icon.pixmap(pixelMetric(PM_SmallIconSize),
  1782             QPixmap pix = menuItem->icon.pixmap(pixelMetric(PM_SmallIconSize),
  1738                 enabled ? QIcon::Normal : QIcon::Disabled);
  1783                 enabled ? QIcon::Normal : QIcon::Disabled);
  1739             const bool itemWithIcon = !pix.isNull();
  1784             const bool itemWithIcon = !pix.isNull();
  1740             if (itemWithIcon) {
  1785             if (itemWithIcon) {
  1741                 drawItemPixmap(painter, iconRect, text_flags, pix);
  1786                 drawItemPixmap(painter, iconRect, text_flags, pix);
  1742                 if (optionMenuItem.direction == Qt::LeftToRight)
  1787                 if (optionMenuItem.direction == Qt::LeftToRight)
  1743                     textRect.translate(vSpacing,0);
  1788                     textRect.translate(vSpacing, 0);
  1744                 else
  1789                 else
  1745                     textRect.translate(-vSpacing,0);
  1790                     textRect.translate(-vSpacing, 0);
  1746                 textRect.setWidth(textRect.width()-vSpacing);
  1791                 textRect.setWidth(textRect.width()-vSpacing);
  1747             }
  1792             }
  1748 
  1793 
  1749             //draw indicators
  1794             //draw indicators
  1750             if (drawSubMenuIndicator) {
  1795             if (drawSubMenuIndicator) {
  1751                 QStyleOptionMenuItem arrowOptions;
  1796                 QStyleOptionMenuItem arrowOptions;
  1752                 arrowOptions.QStyleOption::operator=(*menuItem);
  1797                 arrowOptions.QStyleOption::operator=(*menuItem);
  1753                 const int indicatorWidth = (pixelMetric(PM_ListViewIconSize, option, widget)>>1) +
  1798                 const int indicatorWidth = (pixelMetric(PM_ListViewIconSize, option, widget) >> 1) +
  1754                     pixelMetric(QStyle::PM_LayoutVerticalSpacing, option, widget);
  1799                     pixelMetric(PM_LayoutVerticalSpacing, option, widget);
  1755                 if (optionMenuItem.direction == Qt::LeftToRight)
  1800                 if (optionMenuItem.direction == Qt::LeftToRight)
  1756                     arrowOptions.rect.setLeft(textRect.right());
  1801                     arrowOptions.rect.setLeft(textRect.right());
  1757                 arrowOptions.rect.setWidth(indicatorWidth);
  1802                 arrowOptions.rect.setWidth(indicatorWidth);
  1758                 //by default sub menu indicator in S60 points to east,so here icon
  1803                 //by default sub menu indicator in S60 points to east,so here icon
  1759                 // direction is set to north (and south when in RightToLeft)
  1804                 // direction is set to north (and south when in RightToLeft)
  1772                 optionMenuItem.palette.setColor(QPalette::Disabled, QPalette::Text, QS60StylePrivate::lighterColor(
  1817                 optionMenuItem.palette.setColor(QPalette::Disabled, QPalette::Text, QS60StylePrivate::lighterColor(
  1773                         optionMenuItem.palette.color(QPalette::Disabled, QPalette::Text)));
  1818                         optionMenuItem.palette.color(QPalette::Disabled, QPalette::Text)));
  1774                 painter->save();
  1819                 painter->save();
  1775                 painter->setOpacity(0.5);
  1820                 painter->setOpacity(0.5);
  1776             }
  1821             }
       
  1822             if (selected)
       
  1823                 optionMenuItem.palette.setColor(
       
  1824                     QPalette::Active, QPalette::Text, optionMenuItem.palette.highlightedText().color());
       
  1825 
  1777             QCommonStyle::drawItemText(painter, textRect, text_flags,
  1826             QCommonStyle::drawItemText(painter, textRect, text_flags,
  1778                     optionMenuItem.palette, enabled,
  1827                     optionMenuItem.palette, enabled,
  1779                     optionMenuItem.text, QPalette::Text);
  1828                     optionMenuItem.text, QPalette::Text);
  1780             if (!enabled)
  1829             if (!enabled)
  1781                 painter->restore();
  1830                 painter->restore();
  1793     case CE_HeaderSection:
  1842     case CE_HeaderSection:
  1794         if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
  1843         if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
  1795             painter->save();
  1844             painter->save();
  1796             QPen linePen = QPen(QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnLineColors, 1, header));
  1845             QPen linePen = QPen(QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnLineColors, 1, header));
  1797             const int penWidth = (header->orientation == Qt::Horizontal) ?
  1846             const int penWidth = (header->orientation == Qt::Horizontal) ?
  1798                 linePen.width()+QS60StylePrivate::pixelMetric(PM_Custom_BoldLineWidth)
  1847                 linePen.width() + QS60StylePrivate::pixelMetric(PM_BoldLineWidth)
  1799                 : linePen.width()+QS60StylePrivate::pixelMetric(PM_Custom_ThinLineWidth);
  1848                 : linePen.width() + QS60StylePrivate::pixelMetric(PM_ThinLineWidth);
  1800             linePen.setWidth(penWidth);
  1849             linePen.setWidth(penWidth);
  1801             painter->setPen(linePen);
  1850             painter->setPen(linePen);
  1802             if (header->orientation == Qt::Horizontal){
  1851             if (header->orientation == Qt::Horizontal){
  1803                 painter->drawLine(header->rect.bottomLeft(), header->rect.bottomRight());
  1852                 painter->drawLine(header->rect.bottomLeft(), header->rect.bottomRight());
  1804             } else {
  1853             } else {
  1813             //Draw corner button as normal pushButton.
  1862             //Draw corner button as normal pushButton.
  1814             if (qobject_cast<const QAbstractButton *>(widget)) {
  1863             if (qobject_cast<const QAbstractButton *>(widget)) {
  1815                 //Make cornerButton slightly smaller so that it is not on top of table border graphic.
  1864                 //Make cornerButton slightly smaller so that it is not on top of table border graphic.
  1816                 QStyleOptionHeader subopt = *header;
  1865                 QStyleOptionHeader subopt = *header;
  1817                 const int borderTweak =
  1866                 const int borderTweak =
  1818                     QS60StylePrivate::pixelMetric(PM_Custom_FrameCornerWidth)>>1;
  1867                     QS60StylePrivate::pixelMetric(PM_FrameCornerWidth) >> 1;
  1819                 if (subopt.direction == Qt::LeftToRight)
  1868                 if (subopt.direction == Qt::LeftToRight)
  1820                     subopt.rect.adjust(borderTweak, borderTweak, 0, -borderTweak);
  1869                     subopt.rect.adjust(borderTweak, borderTweak, 0, -borderTweak);
  1821                 else
  1870                 else
  1822                     subopt.rect.adjust(0, borderTweak, -borderTweak, -borderTweak);
  1871                     subopt.rect.adjust(0, borderTweak, -borderTweak, -borderTweak);
  1823                 drawPrimitive(PE_PanelButtonBevel, &subopt, painter, widget);
  1872                 drawPrimitive(PE_PanelButtonBevel, &subopt, painter, widget);
  1889         break;
  1938         break;
  1890 #endif //QT_NO_TOOLBAR
  1939 #endif //QT_NO_TOOLBAR
  1891     case CE_ShapedFrame:
  1940     case CE_ShapedFrame:
  1892         if (const QTextEdit *textEdit = qobject_cast<const QTextEdit *>(widget)) {
  1941         if (const QTextEdit *textEdit = qobject_cast<const QTextEdit *>(widget)) {
  1893             const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(option);
  1942             const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(option);
  1894             if (QS60StylePrivate::canDrawThemeBackground(frame->palette.base()))
  1943             if (QS60StylePrivate::canDrawThemeBackground(frame->palette.base(), widget))
  1895                 QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_Editor, painter, option->rect, flags);
  1944                 QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_Editor, painter, option->rect, flags);
  1896             else
  1945             else
  1897                 QCommonStyle::drawControl(element, option, painter, widget);
  1946                 QCommonStyle::drawControl(element, option, painter, widget);
  1898         } else if (qobject_cast<const QTableView *>(widget)) {
  1947         } else if (qobject_cast<const QTableView *>(widget)) {
  1899             QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_TableItem, painter, option->rect, flags);
  1948             QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_TableItem, painter, option->rect, flags);
  1906                 //todo: update to horizontal table graphic
  1955                 //todo: update to horizontal table graphic
  1907                 adjustableFlags = (adjustableFlags | QS60StylePrivate::SF_PointWest);
  1956                 adjustableFlags = (adjustableFlags | QS60StylePrivate::SF_PointWest);
  1908             } else {
  1957             } else {
  1909                 const int frameWidth = QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth);
  1958                 const int frameWidth = QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth);
  1910                 if (option->direction == Qt::LeftToRight)
  1959                 if (option->direction == Qt::LeftToRight)
  1911                     headerRect.adjust(-2*frameWidth, 0, 0, 0);
  1960                     headerRect.adjust(-2 * frameWidth, 0, 0, 0);
  1912                 else
  1961                 else
  1913                     headerRect.adjust(0, 0, 2*frameWidth, 0);
  1962                     headerRect.adjust(0, 0, 2 * frameWidth, 0);
  1914             }
  1963             }
  1915             if (option->palette.brush(QPalette::Button).color() == Qt::transparent)
  1964             if (option->palette.brush(QPalette::Button).color() == Qt::transparent)
  1916                 QS60StylePrivate::drawSkinElement(
  1965                 QS60StylePrivate::drawSkinElement(
  1917                         QS60StylePrivate::SE_TableHeaderItem, painter, headerRect, adjustableFlags);
  1966                         QS60StylePrivate::SE_TableHeaderItem, painter, headerRect, adjustableFlags);
  1918 
  1967 
  1920             QCommonStyle::drawControl(element, option, painter, widget);
  1969             QCommonStyle::drawControl(element, option, painter, widget);
  1921         }
  1970         }
  1922         break;
  1971         break;
  1923     case CE_MenuScroller:
  1972     case CE_MenuScroller:
  1924         break;
  1973         break;
  1925     case CE_FocusFrame:
  1974     case CE_FocusFrame: {
  1926         {
       
  1927             // The pen width should nearly fill the layoutspacings around the widget
       
  1928             const int penWidth =
       
  1929                 qMin(pixelMetric(QS60Style::PM_LayoutVerticalSpacing), pixelMetric(QS60Style::PM_LayoutHorizontalSpacing))
       
  1930                 - 2; // But keep 1 pixel distance to the focus widget and 1 pixel to the adjacent widgets
       
  1931 
       
  1932 #ifdef QT_KEYPAD_NAVIGATION
  1975 #ifdef QT_KEYPAD_NAVIGATION
  1933             bool editFocus = false;
  1976             bool editFocus = false;
  1934             if (const QFocusFrame *focusFrame = qobject_cast<const QFocusFrame*>(widget)) {
  1977             if (const QFocusFrame *focusFrame = qobject_cast<const QFocusFrame*>(widget)) {
  1935                 if (focusFrame->widget() && focusFrame->widget()->hasEditFocus())
  1978                 if (focusFrame->widget() && focusFrame->widget()->hasEditFocus())
  1936                     editFocus = true;
  1979                     editFocus = true;
  1937             }
  1980             }
  1938             const qreal opacity = editFocus ? 0.65 : 0.45; // Trial and error factors. Feel free to improve.
  1981             const qreal opacity = editFocus ? 1 : 0.75; // Trial and error factors. Feel free to improve.
  1939 #else
  1982 #else
  1940             const qreal opacity = 0.5;
  1983             const qreal opacity = 0.85;
  1941 #endif
  1984 #endif
  1942             // Because of Qts coordinate system, we need to tweak the rect by .5 pixels, otherwise it gets blurred.
  1985             // We need to reduce the focus frame size if LayoutSpacing is smaller than FocusFrameMargin
  1943             const qreal rectAdjustment = (penWidth % 2) ? -.5 : 0;
  1986             // Otherwise, we would overlay adjacent widgets.
  1944 
  1987             const int frameHeightReduction =
  1945             // Make sure that the pen stroke is inside the rect
  1988                     qMin(0, pixelMetric(QStyle::PM_LayoutVerticalSpacing)
  1946             const QRectF adjustedRect =
  1989                             - pixelMetric(QStyle::PM_FocusFrameVMargin));
  1947                 QRectF(option->rect).adjusted(
  1990             const int frameWidthReduction =
  1948                     rectAdjustment + penWidth,
  1991                     qMin(0, pixelMetric(QStyle::PM_LayoutHorizontalSpacing)
  1949                     rectAdjustment + penWidth,
  1992                             - pixelMetric(QStyle::PM_FocusFrameHMargin));
  1950                     -rectAdjustment - penWidth,
  1993             const int rounding =
  1951                     -rectAdjustment - penWidth
  1994                     qMin(pixelMetric(QStyle::PM_FocusFrameVMargin),
  1952                 );
  1995                             pixelMetric(QStyle::PM_LayoutVerticalSpacing));
  1953 
  1996             const QRect frameRect =
  1954             const qreal roundRectRadius = penWidth * goldenRatio;
  1997                     option->rect.adjusted(-frameWidthReduction, -frameHeightReduction,
       
  1998                             frameWidthReduction, frameHeightReduction);
       
  1999             QPainterPath framePath;
       
  2000             framePath.addRoundedRect(frameRect, rounding, rounding);
  1955 
  2001 
  1956             painter->save();
  2002             painter->save();
  1957             painter->setRenderHint(QPainter::Antialiasing);
  2003             painter->setRenderHint(QPainter::Antialiasing);
  1958             painter->setOpacity(opacity);
  2004             painter->setOpacity(opacity);
  1959             painter->setPen(QPen(option->palette.color(QPalette::Text), penWidth));
  2005             painter->fillPath(framePath, option->palette.color(QPalette::Text));
  1960             painter->drawRoundedRect(adjustedRect, roundRectRadius, roundRectRadius);
       
  1961             painter->restore();
  2006             painter->restore();
  1962         }
  2007         }
  1963         break;
  2008         break;
  1964     case CE_Splitter:
  2009     case CE_Splitter:
  1965         if (option->state & State_Sunken && option->state & State_Enabled) {
  2010         if (option->state & State_Sunken && option->state & State_Enabled) {
  1980 /*!
  2025 /*!
  1981   \reimp
  2026   \reimp
  1982 */
  2027 */
  1983 void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
  2028 void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
  1984 {
  2029 {
  1985     Q_D(const QS60Style);
       
  1986     const QS60StylePrivate::SkinElementFlags flags = (option->state & State_Enabled) ?  QS60StylePrivate::SF_StateEnabled : QS60StylePrivate::SF_StateDisabled;
  2030     const QS60StylePrivate::SkinElementFlags flags = (option->state & State_Enabled) ?  QS60StylePrivate::SF_StateEnabled : QS60StylePrivate::SF_StateDisabled;
  1987     bool commonStyleDraws = false;
  2031     bool commonStyleDraws = false;
  1988 
  2032 
  1989     switch (element) {
  2033     switch (element) {
       
  2034         case PE_FrameFocusRect: {
       
  2035             //Draw themed highlight to radiobuttons and checkboxes.
       
  2036             //For other widgets skip, unless palette has been modified. In that case, draw with commonstyle.
       
  2037             if (option->palette.highlight().color() == QS60StylePrivate::themePalette()->highlight().color())
       
  2038                 if ((qstyleoption_cast<const QStyleOptionFocusRect *>(option) &&
       
  2039                     (qobject_cast<const QRadioButton *>(widget) || qobject_cast<const QCheckBox *>(widget))))
       
  2040                         QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ListHighlight, painter, option->rect, flags);
       
  2041             else
       
  2042                 commonStyleDraws = true;
       
  2043             }
       
  2044         break;
  1990 #ifndef QT_NO_LINEEDIT
  2045 #ifndef QT_NO_LINEEDIT
  1991     case PE_PanelLineEdit:
  2046     case PE_PanelLineEdit:
  1992         if (const QStyleOptionFrame *lineEdit = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
  2047         if (const QStyleOptionFrame *lineEdit = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
  1993 #ifndef QT_NO_COMBOBOX
  2048 #ifndef QT_NO_COMBOBOX
  1994             if (widget && qobject_cast<const QComboBox *>(widget->parentWidget()))
  2049             if (widget && qobject_cast<const QComboBox *>(widget->parentWidget()))
  1995                 break;
  2050                 break;
  1996 #endif
  2051 #endif
  1997             if (QS60StylePrivate::canDrawThemeBackground(option->palette.base()))
  2052             if (QS60StylePrivate::canDrawThemeBackground(option->palette.base(), widget))
  1998                 QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_FrameLineEdit, painter, option->rect, flags);
  2053                 QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_FrameLineEdit, painter, option->rect, flags);
  1999             else
  2054             else
  2000                 commonStyleDraws = true;
  2055                 commonStyleDraws = true;
  2001         }
  2056         }
  2002     break;
  2057     break;
  2003 #endif // QT_NO_LINEEDIT
  2058 #endif // QT_NO_LINEEDIT
  2004     case PE_IndicatorCheckBox:
  2059     case PE_IndicatorCheckBox: {
  2005         {
       
  2006             // Draw checkbox indicator as color skinned graphics.
  2060             // Draw checkbox indicator as color skinned graphics.
  2007             const QS60StyleEnums::SkinParts skinPart = (option->state & QStyle::State_On) ?
  2061             const QS60StyleEnums::SkinParts skinPart = (option->state & State_On) ?
  2008                 QS60StyleEnums::SP_QgnIndiCheckboxOn : QS60StyleEnums::SP_QgnIndiCheckboxOff;
  2062                 QS60StyleEnums::SP_QgnIndiCheckboxOn : QS60StyleEnums::SP_QgnIndiCheckboxOff;
  2009             painter->save();
  2063             painter->save();
  2010 
  2064 
  2011             QColor themeColor = QS60StylePrivate::themePalette()->windowText().color();
  2065             const QColor themeColor = QS60StylePrivate::themePalette()->windowText().color();
  2012             QColor windowTextColor = option->palette.windowText().color();
  2066             const QColor windowTextColor = option->palette.windowText().color();
  2013 
  2067 
  2014             if (themeColor != windowTextColor)
  2068             if (themeColor != windowTextColor)
  2015                 painter->setPen(windowTextColor);
  2069                 painter->setPen(windowTextColor);
  2016 
  2070 
  2017             QS60StylePrivate::drawSkinPart(skinPart, painter, option->rect, flags | QS60StylePrivate::SF_ColorSkinned );
  2071             QS60StylePrivate::drawSkinPart(skinPart, painter, option->rect, flags | QS60StylePrivate::SF_ColorSkinned );
  2018             painter->restore();
  2072             painter->restore();
  2019         }
  2073         }
  2020         break;
  2074         break;
  2021     case PE_IndicatorViewItemCheck:
  2075     case PE_IndicatorViewItemCheck:
  2022 #ifndef QT_NO_ITEMVIEWS
  2076 #ifndef QT_NO_ITEMVIEWS
  2023         if (const QListView *listItem = (qobject_cast<const QListView *>(widget))) {
  2077         if (const QAbstractItemView *itemView = (qobject_cast<const QAbstractItemView *>(widget))) {
  2024             if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(option)) {
  2078             if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(option)) {
  2025                 const bool checkBoxVisible = vopt->features & QStyleOptionViewItemV2::HasCheckIndicator;
  2079                 const bool checkBoxVisible = vopt->features & QStyleOptionViewItemV2::HasCheckIndicator;
  2026                 const bool singleSelection = listItem->selectionMode() ==
  2080                 const bool singleSelection = itemView->selectionMode() ==
  2027                     QAbstractItemView::SingleSelection || listItem->selectionMode() == QAbstractItemView::NoSelection;
  2081                     QAbstractItemView::SingleSelection || itemView->selectionMode() == QAbstractItemView::NoSelection;
  2028                 // draw either checkbox at the beginning
  2082                 // draw either checkbox at the beginning
  2029                 if (checkBoxVisible && singleSelection) {
  2083                 if (checkBoxVisible && singleSelection) {
  2030                     drawPrimitive(PE_IndicatorCheckBox, option, painter, widget);
  2084                     drawPrimitive(PE_IndicatorCheckBox, option, painter, widget);
  2031                 // ... or normal "tick" selection at the end.
  2085                 // ... or normal "tick" selection at the end.
  2032                 } else if (option->state & QStyle::State_Selected) {
  2086                 } else if (option->state & State_Selected) {
  2033                     QRect tickRect = option->rect;
  2087                     QRect tickRect = option->rect;
  2034                     const int frameBorderWidth = QS60StylePrivate::pixelMetric(PM_Custom_FrameCornerWidth);
  2088                     const int frameBorderWidth = QS60StylePrivate::pixelMetric(PM_FrameCornerWidth);
  2035                     // adjust tickmark rect to exclude frame border
  2089                     // adjust tickmark rect to exclude frame border
  2036                     tickRect.adjust(0,-frameBorderWidth,0,-frameBorderWidth);
  2090                     tickRect.adjust(0, -frameBorderWidth, 0, -frameBorderWidth);
  2037                     QS60StyleEnums::SkinParts skinPart = QS60StyleEnums::SP_QgnIndiMarkedAdd;
  2091                     QS60StyleEnums::SkinParts skinPart = QS60StyleEnums::SP_QgnIndiMarkedAdd;
  2038                     QS60StylePrivate::drawSkinPart(skinPart, painter, tickRect,
  2092                     QS60StylePrivate::drawSkinPart(skinPart, painter, tickRect,
  2039                         (flags | QS60StylePrivate::SF_ColorSkinned));
  2093                         (flags | QS60StylePrivate::SF_ColorSkinned));
  2040                 }
  2094                 }
  2041             }
  2095             }
  2043 #endif //QT_NO_ITEMVIEWS
  2097 #endif //QT_NO_ITEMVIEWS
  2044         break;
  2098         break;
  2045     case PE_IndicatorRadioButton: {
  2099     case PE_IndicatorRadioButton: {
  2046             QRect buttonRect = option->rect;
  2100             QRect buttonRect = option->rect;
  2047             //there is empty (a. 33%) space in svg graphics for radiobutton
  2101             //there is empty (a. 33%) space in svg graphics for radiobutton
  2048             const qreal reduceWidth = (qreal)buttonRect.width()/3.0;
  2102             const qreal reduceWidth = (qreal)buttonRect.width() / 3.0;
  2049             const qreal rectWidth = (qreal)option->rect.width() != 0 ? option->rect.width() : 1.0;
  2103             const qreal rectWidth = (qreal)option->rect.width() != 0 ? option->rect.width() : 1.0;
  2050             // Try to occupy the full area
  2104             // Try to occupy the full area
  2051             const qreal scaler = 1 + (reduceWidth/rectWidth);
  2105             const qreal scaler = 1 + (reduceWidth/rectWidth);
  2052             buttonRect.setWidth((int)((buttonRect.width()-reduceWidth) * scaler));
  2106             buttonRect.setWidth((int)((buttonRect.width()-reduceWidth) * scaler));
  2053             buttonRect.setHeight((int)(buttonRect.height() * scaler));
  2107             buttonRect.setHeight((int)(buttonRect.height() * scaler));
  2054             // move the rect up for half of the new height-gain
  2108             // move the rect up for half of the new height-gain
  2055             const int newY = (buttonRect.bottomRight().y() - option->rect.bottomRight().y()) >> 1 ;
  2109             const int newY = (buttonRect.bottomRight().y() - option->rect.bottomRight().y()) >> 1 ;
  2056             buttonRect.adjust(0, -newY, -1, -newY);
  2110             buttonRect.adjust(0, -newY, -1, -newY);
  2057 
  2111 
  2058             painter->save();
  2112             painter->save();
  2059             QColor themeColor = d->s60Color(QS60StyleEnums::CL_QsnTextColors, 6, option);
  2113             const QColor themeColor = QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnTextColors, 6, option);
  2060             QColor buttonTextColor = option->palette.buttonText().color();
  2114             const QColor buttonTextColor = option->palette.buttonText().color();
  2061             if (themeColor != buttonTextColor)
  2115             if (themeColor != buttonTextColor)
  2062                 painter->setPen(buttonTextColor);
  2116                 painter->setPen(buttonTextColor);
  2063             else
  2117             else
  2064                 painter->setPen(themeColor);
  2118                 painter->setPen(themeColor);
  2065 
  2119 
  2066             // Draw radiobutton indicator as color skinned graphics.
  2120             // Draw radiobutton indicator as color skinned graphics.
  2067             QS60StyleEnums::SkinParts skinPart = (option->state & QStyle::State_On) ?
  2121             QS60StyleEnums::SkinParts skinPart = (option->state & State_On) ?
  2068                 QS60StyleEnums::SP_QgnIndiRadiobuttOn : QS60StyleEnums::SP_QgnIndiRadiobuttOff;
  2122                 QS60StyleEnums::SP_QgnIndiRadiobuttOn : QS60StyleEnums::SP_QgnIndiRadiobuttOff;
  2069             QS60StylePrivate::drawSkinPart(skinPart, painter, buttonRect,
  2123             QS60StylePrivate::drawSkinPart(skinPart, painter, buttonRect,
  2070                 (flags | QS60StylePrivate::SF_ColorSkinned));
  2124                 (flags | QS60StylePrivate::SF_ColorSkinned));
  2071             painter->restore();
  2125             painter->restore();
  2072         }
  2126         }
  2073         break;
  2127         break;
  2074     case PE_PanelButtonCommand:
  2128     case PE_PanelButtonCommand:
  2075     case PE_PanelButtonTool:
  2129     case PE_PanelButtonTool:
  2076     case PE_PanelButtonBevel:
  2130     case PE_PanelButtonBevel:
  2077     case PE_FrameButtonBevel: {
  2131     case PE_FrameButtonBevel:
  2078         if (QS60StylePrivate::canDrawThemeBackground(option->palette.base())) {
  2132         if (QS60StylePrivate::canDrawThemeBackground(option->palette.base(), widget)) {
  2079             const bool isPressed = option->state & QStyle::State_Sunken;
  2133             const bool isPressed = option->state & State_Sunken;
  2080             const QS60StylePrivate::SkinElements skinElement =
  2134             const QS60StylePrivate::SkinElements skinElement =
  2081                 isPressed ? QS60StylePrivate::SE_ButtonPressed : QS60StylePrivate::SE_ButtonNormal;
  2135                 isPressed ? QS60StylePrivate::SE_ButtonPressed : QS60StylePrivate::SE_ButtonNormal;
  2082             QS60StylePrivate::drawSkinElement(skinElement, painter, option->rect, flags);
  2136             QS60StylePrivate::drawSkinElement(skinElement, painter, option->rect, flags);
  2083         } else {
  2137         } else {
  2084             commonStyleDraws = true;
  2138             commonStyleDraws = true;
  2085             }
       
  2086         }
  2139         }
  2087         break;
  2140         break;
  2088 #ifndef QT_NO_TOOLBUTTON
  2141 #ifndef QT_NO_TOOLBUTTON
  2089     case PE_IndicatorArrowDown:
  2142     case PE_IndicatorArrowDown:
  2090     case PE_IndicatorArrowLeft:
  2143     case PE_IndicatorArrowLeft:
  2106 #endif //QT_NO_TOOLBUTTON
  2159 #endif //QT_NO_TOOLBUTTON
  2107 #ifndef QT_NO_SPINBOX
  2160 #ifndef QT_NO_SPINBOX
  2108     case PE_IndicatorSpinDown:
  2161     case PE_IndicatorSpinDown:
  2109     case PE_IndicatorSpinUp:
  2162     case PE_IndicatorSpinUp:
  2110         if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
  2163         if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
  2111             QStyleOptionSpinBox optionSpinBox = *spinBox;
  2164             if (QS60StylePrivate::canDrawThemeBackground(spinBox->palette.base(), widget)) {
  2112             if (QS60StylePrivate::canDrawThemeBackground(optionSpinBox.palette.base())) {
  2165                 QStyleOptionSpinBox optionSpinBox = *spinBox;
  2113                 const QS60StyleEnums::SkinParts part = (element == PE_IndicatorSpinUp) ?
  2166                 const QS60StyleEnums::SkinParts part = (element == PE_IndicatorSpinUp) ?
  2114                     QS60StyleEnums::SP_QgnGrafScrollArrowUp :
  2167                     QS60StyleEnums::SP_QgnGrafScrollArrowUp :
  2115                     QS60StyleEnums::SP_QgnGrafScrollArrowDown;
  2168                     QS60StyleEnums::SP_QgnGrafScrollArrowDown;
  2116                 const int adjustment = qMin(optionSpinBox.rect.width(), optionSpinBox.rect.height())/6;
  2169                 const int iconMargin = QS60StylePrivate::pixelMetric(PM_FrameCornerWidth) >> 1;
  2117                 optionSpinBox.rect.translate(0, (element == PE_IndicatorSpinDown) ? adjustment : -adjustment );
  2170                 optionSpinBox.rect.translate(0, (element == PE_IndicatorSpinDown) ? iconMargin : -iconMargin );
  2118                 QS60StylePrivate::drawSkinPart(part, painter, optionSpinBox.rect,flags);
  2171                 QS60StylePrivate::drawSkinPart(part, painter, optionSpinBox.rect, flags);
  2119             } else {
  2172             } else {
  2120                 commonStyleDraws = true;
  2173                 commonStyleDraws = true;
  2121             }
  2174             }
  2122         }
  2175         }
       
  2176 #endif //QT_NO_SPINBOX
  2123 #ifndef QT_NO_COMBOBOX
  2177 #ifndef QT_NO_COMBOBOX
  2124         else if (const QStyleOptionFrame *cmb = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
  2178         if (const QStyleOptionFrame *cmb = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
  2125             if (QS60StylePrivate::canDrawThemeBackground( option->palette.base())) {
  2179             if (QS60StylePrivate::canDrawThemeBackground( option->palette.base(), widget)) {
  2126                 // We want to draw down arrow here for comboboxes as well.
  2180                 // We want to draw down arrow here for comboboxes as well.
       
  2181                 QStyleOptionFrame optionsComboBox = *cmb;
  2127                 const QS60StyleEnums::SkinParts part = QS60StyleEnums::SP_QgnGrafScrollArrowDown;
  2182                 const QS60StyleEnums::SkinParts part = QS60StyleEnums::SP_QgnGrafScrollArrowDown;
  2128                 QStyleOptionFrame comboBox = *cmb;
  2183                 const int iconMargin = QS60StylePrivate::pixelMetric(PM_FrameCornerWidth) >> 1;
  2129                 const int adjustment = qMin(comboBox.rect.width(), comboBox.rect.height())/6;
  2184                 optionsComboBox.rect.translate(0, (element == PE_IndicatorSpinDown) ? iconMargin : -iconMargin );
  2130                 comboBox.rect.translate(0, (element == PE_IndicatorSpinDown) ? adjustment : -adjustment );
  2185                 QS60StylePrivate::drawSkinPart(part, painter, optionsComboBox.rect, flags);
  2131                 QS60StylePrivate::drawSkinPart(part, painter, comboBox.rect,flags);
       
  2132             } else {
  2186             } else {
  2133                 commonStyleDraws = true;
  2187                 commonStyleDraws = true;
  2134             }
  2188             }
  2135         }
  2189         }
  2136 #endif //QT_NO_COMBOBOX
  2190 #endif //QT_NO_COMBOBOX
  2144 #ifndef QT_NO_COMBOBOX
  2198 #ifndef QT_NO_COMBOBOX
  2145         else if (const QStyleOptionFrame *cmb = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
  2199         else if (const QStyleOptionFrame *cmb = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
  2146             // We want to draw down arrow here for comboboxes as well.
  2200             // We want to draw down arrow here for comboboxes as well.
  2147             QStyleOptionFrame comboBox = *cmb;
  2201             QStyleOptionFrame comboBox = *cmb;
  2148             const int frameWidth = QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth);
  2202             const int frameWidth = QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth);
  2149             comboBox.rect.adjust(0,frameWidth,0,-frameWidth);
  2203             comboBox.rect.adjust(0, frameWidth, 0, -frameWidth);
  2150             QCommonStyle::drawPrimitive(element, &comboBox, painter, widget);
  2204             QCommonStyle::drawPrimitive(element, &comboBox, painter, widget);
  2151         }
  2205         }
  2152 #endif //QT_NO_COMBOBOX
  2206 #endif //QT_NO_COMBOBOX
  2153         break;
  2207         break;
  2154 #endif //QT_NO_SPINBOX
       
  2155     case PE_Widget:
  2208     case PE_Widget:
  2156         if (QS60StylePrivate::drawsOwnThemeBackground(widget)
  2209         if (QS60StylePrivate::drawsOwnThemeBackground(widget)
  2157 #ifndef QT_NO_COMBOBOX
  2210 #ifndef QT_NO_COMBOBOX
  2158             || qobject_cast<const QComboBoxListView *>(widget)
  2211             || qobject_cast<const QComboBoxListView *>(widget)
  2159 #endif //QT_NO_COMBOBOX
  2212 #endif //QT_NO_COMBOBOX
  2160 #ifndef QT_NO_MENU
  2213 #ifndef QT_NO_MENU
  2161             || qobject_cast<const QMenu *> (widget)
  2214             || qobject_cast<const QMenu *> (widget)
  2162 #endif //QT_NO_MENU
  2215 #endif //QT_NO_MENU
  2163             ) {
  2216             ) {
  2164             if (QS60StylePrivate::canDrawThemeBackground(option->palette.base()))
  2217             //Need extra check since dialogs have their own theme background
  2165                 QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_OptionsMenu, painter, option->rect, flags);
  2218             if (QS60StylePrivate::canDrawThemeBackground(option->palette.base(), widget) &&
       
  2219                 option->palette.window().texture().cacheKey() ==
       
  2220                     QS60StylePrivate::m_themePalette->window().texture().cacheKey())
       
  2221                 QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_PopupBackground, painter, option->rect, flags);
  2166             else
  2222             else
  2167                 commonStyleDraws = true;
  2223                 commonStyleDraws = true;
  2168         }
  2224         }
  2169         break;
  2225         break;
  2170     case PE_FrameWindow:
  2226     case PE_FrameWindow:
  2199         break;
  2255         break;
  2200     case PE_Frame:
  2256     case PE_Frame:
  2201         break;
  2257         break;
  2202 #ifndef QT_NO_ITEMVIEWS
  2258 #ifndef QT_NO_ITEMVIEWS
  2203     case PE_PanelItemViewItem:
  2259     case PE_PanelItemViewItem:
  2204     case PE_PanelItemViewRow: // ### Qt 5: remove
       
  2205         break;
  2260         break;
  2206 #endif //QT_NO_ITEMVIEWS
  2261 #endif //QT_NO_ITEMVIEWS
  2207 
  2262 
  2208     case PE_IndicatorMenuCheckMark:
  2263     case PE_IndicatorMenuCheckMark:
  2209         if (const QStyleOptionMenuItem *checkBox = qstyleoption_cast<const QStyleOptionMenuItem *>(option)){
  2264         if (const QStyleOptionMenuItem *checkBox = qstyleoption_cast<const QStyleOptionMenuItem *>(option)){
  2256 
  2311 
  2257             if (option->state & State_Children) {
  2312             if (option->state & State_Children) {
  2258                 QS60StyleEnums::SkinParts skinPart =
  2313                 QS60StyleEnums::SkinParts skinPart =
  2259                         (option->state & State_Open) ? QS60StyleEnums::SP_QgnIndiHlColSuper : QS60StyleEnums::SP_QgnIndiHlExpSuper;
  2314                         (option->state & State_Open) ? QS60StyleEnums::SP_QgnIndiHlColSuper : QS60StyleEnums::SP_QgnIndiHlExpSuper;
  2260                 int minDimension = qMin(option->rect.width(), option->rect.height());
  2315                 int minDimension = qMin(option->rect.width(), option->rect.height());
  2261                 const int resizeValue = minDimension >> 1;
       
  2262                 minDimension += resizeValue; // Adjust the icon bigger because of empty space in svg icon.
       
  2263                 QRect iconRect(option->rect.topLeft(), QSize(minDimension, minDimension));
  2316                 QRect iconRect(option->rect.topLeft(), QSize(minDimension, minDimension));
  2264                 int verticalMagic(0);
  2317                 const int magicTweak = 3;
  2265                 // magic values for positioning svg icon.
  2318                 int resizeValue = minDimension >> 1;
  2266                 if (option->rect.width() <= option->rect.height())
  2319                 if (!QS60StylePrivate::isTouchSupported()) {
  2267                     verticalMagic = 3;
  2320                     minDimension += resizeValue; // Adjust the icon bigger because of empty space in svg icon.
  2268                 iconRect.translate(3, verticalMagic - resizeValue);
  2321                     iconRect.setSize(QSize(minDimension, minDimension));
       
  2322                     const int verticalMagic = (option->rect.width() <= option->rect.height()) ? magicTweak : 0;
       
  2323                     resizeValue = verticalMagic - resizeValue;
       
  2324                 }
       
  2325                 iconRect.translate(magicTweak, resizeValue);
  2269                 QS60StylePrivate::drawSkinPart(skinPart, painter, iconRect, flags);
  2326                 QS60StylePrivate::drawSkinPart(skinPart, painter, iconRect, flags);
  2270             }
  2327             }
  2271         }
  2328         }
  2272         break;
  2329         break;
  2273 
  2330     case PE_PanelItemViewRow: // ### Qt 5: remove
       
  2331 #ifndef QT_NO_ITEMVIEWS
       
  2332         if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(option)) {
       
  2333             if (vopt->palette.base().texture().cacheKey() != QS60StylePrivate::m_themePalette->base().texture().cacheKey()) {
       
  2334                 //QPalette::Base has been changed, let commonstyle draw the item
       
  2335                 commonStyleDraws = true;
       
  2336             } else {
       
  2337                 QPalette::ColorGroup cg = vopt->state & State_Enabled ? QPalette::Normal : QPalette::Disabled;
       
  2338                 if (cg == QPalette::Normal && !(vopt->state & State_Active))
       
  2339                     cg = QPalette::Inactive;
       
  2340                 if (vopt->features & QStyleOptionViewItemV2::Alternate)
       
  2341                     painter->fillRect(vopt->rect, vopt->palette.brush(cg, QPalette::AlternateBase));
       
  2342                 //apart from alternate base, no background for list item is drawn for S60Style
       
  2343             }
       
  2344         }
       
  2345 #endif
       
  2346         break;
  2274     case PE_PanelScrollAreaCorner:
  2347     case PE_PanelScrollAreaCorner:
  2275         break;
  2348         break;
  2276 
  2349     case PE_IndicatorItemViewItemDrop:
       
  2350         if (QS60StylePrivate::isTouchSupported())
       
  2351             QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_DropArea, painter, option->rect, flags);
       
  2352         else
       
  2353             commonStyleDraws = true;
       
  2354         break;
  2277         // todo: items are below with #ifdefs "just in case". in final version, remove all non-required cases
  2355         // todo: items are below with #ifdefs "just in case". in final version, remove all non-required cases
  2278     case PE_FrameLineEdit:
  2356     case PE_FrameLineEdit:
  2279     case PE_IndicatorDockWidgetResizeHandle:
  2357     case PE_IndicatorDockWidgetResizeHandle:
  2280     case PE_PanelTipLabel:
  2358     case PE_PanelTipLabel:
  2281 
  2359 
  2292 #ifndef QT_NO_TOOLBAR
  2370 #ifndef QT_NO_TOOLBAR
  2293     case PE_PanelToolBar:
  2371     case PE_PanelToolBar:
  2294 #endif //QT_NO_TOOLBAR
  2372 #endif //QT_NO_TOOLBAR
  2295 #ifndef QT_NO_COLUMNVIEW
  2373 #ifndef QT_NO_COLUMNVIEW
  2296     case PE_IndicatorColumnViewArrow:
  2374     case PE_IndicatorColumnViewArrow:
  2297     case PE_IndicatorItemViewItemDrop:
       
  2298 #endif //QT_NO_COLUMNVIEW
  2375 #endif //QT_NO_COLUMNVIEW
  2299     case PE_FrameTabBarBase: // since tabs are in S60 always in navipane, let's use common style for tab base in Qt.
  2376     case PE_FrameTabBarBase: // since tabs are in S60 always in navipane, let's use common style for tab base in Qt.
  2300     default:
  2377     default:
  2301         commonStyleDraws = true;
  2378         commonStyleDraws = true;
  2302     }
  2379     }
  2310 {
  2387 {
  2311     int metricValue = QS60StylePrivate::pixelMetric(metric);
  2388     int metricValue = QS60StylePrivate::pixelMetric(metric);
  2312     if (metricValue == KNotFound)
  2389     if (metricValue == KNotFound)
  2313         metricValue = QCommonStyle::pixelMetric(metric, option, widget);
  2390         metricValue = QCommonStyle::pixelMetric(metric, option, widget);
  2314 
  2391 
  2315     if (metric == PM_SubMenuOverlap && widget) {
       
  2316         const QMenu *menu = qobject_cast<const QMenu *>(widget);
       
  2317         if (menu && menu->activeAction() && menu->activeAction()->menu()) {
       
  2318             const int menuWidth = menu->activeAction()->menu()->sizeHint().width();
       
  2319             metricValue = -menuWidth;
       
  2320         }
       
  2321     }
       
  2322     //if layout direction is mirrored, switch left and right border margins
  2392     //if layout direction is mirrored, switch left and right border margins
  2323     if (option && option->direction == Qt::RightToLeft) {
  2393     if (option && option->direction == Qt::RightToLeft) {
  2324         if (metric == PM_LayoutLeftMargin)
  2394         if (metric == PM_LayoutLeftMargin)
  2325             metricValue = QS60StylePrivate::pixelMetric(PM_LayoutRightMargin);
  2395             metricValue = QS60StylePrivate::pixelMetric(PM_LayoutRightMargin);
  2326         else if (metric == PM_LayoutRightMargin)
  2396         else if (metric == PM_LayoutRightMargin)
  2327             metricValue = QS60StylePrivate::pixelMetric(PM_LayoutLeftMargin);
  2397             metricValue = QS60StylePrivate::pixelMetric(PM_LayoutLeftMargin);
  2328     }
  2398     }
       
  2399 
       
  2400     if (widget && (metric == PM_LayoutTopMargin))
       
  2401         if (widget->windowType() == Qt::Dialog)
       
  2402             //double the top layout margin for dialogs, it is very close to real value
       
  2403             //without having to define custom pixel metric
       
  2404             metricValue *= 2;
  2329     return metricValue;
  2405     return metricValue;
  2330 }
  2406 }
  2331 
  2407 
  2332 /*! \reimp */
  2408 /*! \reimp */
  2333 QSize QS60Style::sizeFromContents(ContentsType ct, const QStyleOption *opt,
  2409 QSize QS60Style::sizeFromContents(ContentsType ct, const QStyleOption *opt,
  2336     QSize sz(csz);
  2412     QSize sz(csz);
  2337     switch (ct) {
  2413     switch (ct) {
  2338         case CT_ToolButton:
  2414         case CT_ToolButton:
  2339             sz = QCommonStyle::sizeFromContents( ct, opt, csz, widget);
  2415             sz = QCommonStyle::sizeFromContents( ct, opt, csz, widget);
  2340             //FIXME properly - style should calculate the location of border frame-part
  2416             //FIXME properly - style should calculate the location of border frame-part
  2341             sz += QSize(2*pixelMetric(PM_ButtonMargin), 2*pixelMetric(PM_ButtonMargin));
  2417             sz += QSize(2 * pixelMetric(PM_ButtonMargin), 2 * pixelMetric(PM_ButtonMargin));
  2342             if (const QStyleOptionToolButton *toolBtn = qstyleoption_cast<const QStyleOptionToolButton *>(opt))
  2418             if (const QStyleOptionToolButton *toolBtn = qstyleoption_cast<const QStyleOptionToolButton *>(opt))
  2343                 if (toolBtn->subControls & SC_ToolButtonMenu)
  2419                 if (toolBtn->subControls & SC_ToolButtonMenu)
  2344                     sz += QSize(pixelMetric(PM_MenuButtonIndicator),0);
  2420                     sz += QSize(pixelMetric(PM_MenuButtonIndicator), 0);
  2345             break;
  2421             break;
  2346         case CT_PushButton:
  2422         case CT_PushButton:
  2347             sz = QCommonStyle::sizeFromContents( ct, opt, csz, widget);
  2423             sz = QCommonStyle::sizeFromContents( ct, opt, csz, widget);
  2348             //FIXME properly - style should calculate the location of border frame-part
  2424             //FIXME properly - style should calculate the location of border frame-part
  2349             sz += QSize(2*pixelMetric(PM_ButtonMargin), 2*pixelMetric(PM_ButtonMargin));
  2425             if (const QAbstractButton *buttonWidget = (qobject_cast<const QAbstractButton *>(widget)))  {
  2350             if (const QAbstractButton *buttonWidget = (qobject_cast<const QAbstractButton *>(widget)))
       
  2351                 if (buttonWidget->isCheckable())
  2426                 if (buttonWidget->isCheckable())
  2352                     sz += QSize(pixelMetric(PM_IndicatorWidth) + pixelMetric(PM_CheckBoxLabelSpacing), 0);
  2427                     sz += QSize(pixelMetric(PM_IndicatorWidth) + pixelMetric(PM_CheckBoxLabelSpacing), 0);
       
  2428                 const int iconHeight = (!buttonWidget->icon().isNull()) ? buttonWidget->iconSize().height() : 0;
       
  2429                 const int textHeight = (buttonWidget->text().length() > 0) ?
       
  2430                     buttonWidget->fontMetrics().size(Qt::TextSingleLine, buttonWidget->text()).height() : 0;
       
  2431                 const int decoratorHeight = (buttonWidget->isCheckable()) ? pixelMetric(PM_IndicatorHeight) : 0;
       
  2432 
       
  2433                 const int contentHeight =
       
  2434                         qMax(qMax(iconHeight, decoratorHeight) + pixelMetric(PM_ButtonMargin),
       
  2435                              textHeight + 2*pixelMetric(PM_ButtonMargin));
       
  2436                 sz.setHeight(contentHeight);
       
  2437                 sz += QSize(2 * pixelMetric(PM_ButtonMargin), 0);
       
  2438             }
  2353             break;
  2439             break;
  2354         case CT_LineEdit:
  2440         case CT_LineEdit:
  2355             if (const QStyleOptionFrame *f = qstyleoption_cast<const QStyleOptionFrame *>(opt))
  2441             if (const QStyleOptionFrame *f = qstyleoption_cast<const QStyleOptionFrame *>(opt))
  2356                 sz += QSize(2*f->lineWidth, 4*f->lineWidth);
  2442                 sz += QSize(2 * f->lineWidth, 4 * f->lineWidth);
  2357             break;
  2443             break;
  2358         case CT_TabBarTab:
  2444         case CT_TabBarTab: {
  2359             {
       
  2360                 const QSize naviPaneSize = QS60StylePrivate::naviPaneSize();
  2445                 const QSize naviPaneSize = QS60StylePrivate::naviPaneSize();
  2361                 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
  2446                 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
  2362                 if (naviPaneSize.height() > sz.height())
  2447                 if (naviPaneSize.height() > sz.height())
  2363                     sz.setHeight(naviPaneSize.height());
  2448                     sz.setHeight(naviPaneSize.height());
  2364             }
  2449             }
  2366         case CT_ItemViewItem:
  2451         case CT_ItemViewItem:
  2367             sz = QCommonStyle::sizeFromContents( ct, opt, csz, widget);
  2452             sz = QCommonStyle::sizeFromContents( ct, opt, csz, widget);
  2368             if (QS60StylePrivate::isTouchSupported())
  2453             if (QS60StylePrivate::isTouchSupported())
  2369                 //Make itemview easier to use in touch devices
  2454                 //Make itemview easier to use in touch devices
  2370                 //QCommonStyle does not adjust height with horizontal margin, it only adjusts width
  2455                 //QCommonStyle does not adjust height with horizontal margin, it only adjusts width
  2371                 sz.setHeight(sz.height() + 2*pixelMetric(QStyle::PM_FocusFrameVMargin));
  2456                 sz.setHeight(sz.height() + 2 * pixelMetric(PM_FocusFrameVMargin));
  2372             break;
  2457             break;
       
  2458 #ifndef QT_NO_COMBOBOX
       
  2459         case CT_ComboBox: {
       
  2460                 // Fixing Ui design issues with too wide QComboBoxes and greedy SizeHints
       
  2461                 // Make sure, that the combobox stays within the screen.
       
  2462                 const QSize desktopContentSize = QApplication::desktop()->availableGeometry().size()
       
  2463                         - QSize(pixelMetric(PM_LayoutLeftMargin) + pixelMetric(PM_LayoutRightMargin), 0);
       
  2464                 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget).
       
  2465                         boundedTo(desktopContentSize);
       
  2466             }
       
  2467             break;
       
  2468 #endif
  2373         default:
  2469         default:
  2374             sz = QCommonStyle::sizeFromContents( ct, opt, csz, widget);
  2470             sz = QCommonStyle::sizeFromContents( ct, opt, csz, widget);
  2375             break;
  2471             break;
  2376     }
  2472     }
  2377     return sz;
  2473     return sz;
  2381 int QS60Style::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *widget,
  2477 int QS60Style::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *widget,
  2382                             QStyleHintReturn *hret) const
  2478                             QStyleHintReturn *hret) const
  2383 {
  2479 {
  2384     int retValue = -1;
  2480     int retValue = -1;
  2385     switch (sh) {
  2481     switch (sh) {
       
  2482         case SH_RequestSoftwareInputPanel:
       
  2483             if (QS60StylePrivate::isSingleClickUi())
       
  2484                 retValue = RSIP_OnMouseClick;
       
  2485             else
       
  2486                 retValue = RSIP_OnMouseClickAndAlreadyFocused;
       
  2487             break;
       
  2488         case SH_ComboBox_Popup:
       
  2489             retValue = true;
       
  2490             break;
  2386         case SH_Table_GridLineColor:
  2491         case SH_Table_GridLineColor:
  2387             retValue = int(QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnLineColors,2,0).rgba());
  2492             retValue = int(QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnLineColors, 2, 0).rgba());
  2388             break;
  2493             break;
  2389         case SH_GroupBox_TextLabelColor:
  2494         case SH_GroupBox_TextLabelColor:
  2390             retValue = int(QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnTextColors,6,0).rgba());
  2495             retValue = int(QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnTextColors, 6, 0).rgba());
  2391             break;
  2496             break;
  2392         case SH_ScrollBar_ScrollWhenPointerLeavesControl:
  2497         case SH_ScrollBar_ScrollWhenPointerLeavesControl:
  2393             retValue = true;
  2498             retValue = true;
  2394             break;
  2499             break;
  2395         case SH_Slider_SnapToValue:
  2500         case SH_Slider_SnapToValue:
  2406             break;
  2511             break;
  2407         case SH_Dial_BackgroundRole:
  2512         case SH_Dial_BackgroundRole:
  2408             retValue = QPalette::Base;
  2513             retValue = QPalette::Base;
  2409             break;
  2514             break;
  2410         case SH_ItemView_ActivateItemOnSingleClick:
  2515         case SH_ItemView_ActivateItemOnSingleClick:
  2411             retValue = true;
  2516             retValue = QS60StylePrivate::isSingleClickUi();
  2412             break;
  2517             break;
  2413         case SH_ProgressDialog_TextLabelAlignment:
  2518         case SH_ProgressDialog_TextLabelAlignment:
  2414             retValue = (QApplication::layoutDirection() == Qt::LeftToRight) ?
  2519             retValue = (QApplication::layoutDirection() == Qt::LeftToRight) ?
  2415                 Qt::AlignLeft :
  2520                 Qt::AlignLeft :
  2416                 Qt::AlignRight;
  2521                 Qt::AlignRight;
  2434             retValue = true;
  2539             retValue = true;
  2435             break;
  2540             break;
  2436         case SH_UnderlineShortcut:
  2541         case SH_UnderlineShortcut:
  2437             retValue = 0;
  2542             retValue = 0;
  2438             break;
  2543             break;
  2439         case SH_RequestSoftwareInputPanel:
       
  2440             retValue = RSIP_OnMouseClickAndAlreadyFocused;
       
  2441             break;
       
  2442         case SH_FormLayoutWrapPolicy:
  2544         case SH_FormLayoutWrapPolicy:
  2443             retValue = QFormLayout::WrapLongRows;
  2545             retValue = QFormLayout::WrapLongRows;
       
  2546             break;
       
  2547         case SH_ScrollBar_ContextMenu:
       
  2548             retValue = false;
  2444             break;
  2549             break;
  2445         default:
  2550         default:
  2446             retValue = QCommonStyle::styleHint(sh, opt, widget, hret);
  2551             retValue = QCommonStyle::styleHint(sh, opt, widget, hret);
  2447             break;
  2552             break;
  2448     }
  2553     }
  2467             if (scrollbarOption->maximum != scrollbarOption->minimum) {
  2572             if (scrollbarOption->maximum != scrollbarOption->minimum) {
  2468                 const uint range = scrollbarOption->maximum - scrollbarOption->minimum;
  2573                 const uint range = scrollbarOption->maximum - scrollbarOption->minimum;
  2469                 sliderlen = (qint64(scrollbarOption->pageStep) * maxlen) / (range + scrollbarOption->pageStep);
  2574                 sliderlen = (qint64(scrollbarOption->pageStep) * maxlen) / (range + scrollbarOption->pageStep);
  2470 
  2575 
  2471                 const int slidermin = pixelMetric(PM_ScrollBarSliderMin, scrollbarOption, widget);
  2576                 const int slidermin = pixelMetric(PM_ScrollBarSliderMin, scrollbarOption, widget);
  2472                 if (sliderlen < slidermin || range > (INT_MAX>>1))
  2577                 if (sliderlen < slidermin || range > (INT_MAX >> 1))
  2473                     sliderlen = slidermin;
  2578                     sliderlen = slidermin;
  2474                 if (sliderlen > maxlen)
  2579                 if (sliderlen > maxlen)
  2475                     sliderlen = maxlen;
  2580                     sliderlen = maxlen;
  2476             } else {
  2581             } else {
  2477                 sliderlen = maxlen;
  2582                 sliderlen = maxlen;
  2518 #endif // QT_NO_SCROLLBAR
  2623 #endif // QT_NO_SCROLLBAR
  2519     case CC_SpinBox:
  2624     case CC_SpinBox:
  2520         if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
  2625         if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
  2521             const int frameThickness = spinbox->frame ? pixelMetric(PM_SpinBoxFrameWidth, spinbox, widget) : 0;
  2626             const int frameThickness = spinbox->frame ? pixelMetric(PM_SpinBoxFrameWidth, spinbox, widget) : 0;
  2522             const int buttonMargin = spinbox->frame ? 2 : 0;
  2627             const int buttonMargin = spinbox->frame ? 2 : 0;
  2523             const int buttonWidth = QS60StylePrivate::pixelMetric(QStyle::PM_ButtonIconSize) + 2*buttonMargin;
  2628             const int buttonContentWidth = QS60StylePrivate::pixelMetric(PM_ButtonIconSize) + 2 * buttonMargin;
       
  2629             // Spinbox buttons should be no larger than one fourth of total width.
       
  2630             // Thus, side-by-side buttons would take half of the total width.
       
  2631             const int maxSize = qMax(spinbox->rect.width() / 4, buttonContentWidth);
  2524             QSize buttonSize;
  2632             QSize buttonSize;
  2525             buttonSize.setHeight(qMax(8, spinbox->rect.height() - frameThickness));
  2633             buttonSize.setHeight(qMin(maxSize, qMax(8, spinbox->rect.height() - frameThickness)));
  2526             buttonSize.setWidth(buttonWidth);
  2634             //width should at least be equal to height
       
  2635             buttonSize.setWidth(qMax(buttonSize.height(), buttonContentWidth));
  2527             buttonSize = buttonSize.expandedTo(QApplication::globalStrut());
  2636             buttonSize = buttonSize.expandedTo(QApplication::globalStrut());
  2528 
  2637 
  2529             const int y = frameThickness + spinbox->rect.y();
  2638             // Normally spinbuttons should be side-by-side, but if spinbox grows very big
  2530             const int x = spinbox->rect.x() + spinbox->rect.width() - frameThickness - 2*buttonSize.width();
  2639             // and spinbuttons reach their maximum size, they can be deployed one top of the other.
       
  2640             const bool sideBySide = (buttonSize.height() * 2 < spinbox->rect.height()) ? false : true;
       
  2641             const int y = frameThickness + spinbox->rect.y() +  
       
  2642                           (spinbox->rect.height() - (sideBySide ? 1 : 2) * buttonSize.height()) / 2;
       
  2643             const int x = spinbox->rect.x() + 
       
  2644                           spinbox->rect.width() - frameThickness - (sideBySide ? 2 : 1) * buttonSize.width();
  2531 
  2645 
  2532             switch (scontrol) {
  2646             switch (scontrol) {
  2533                 case SC_SpinBoxUp:
  2647                 case SC_SpinBoxUp:
  2534                     if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
  2648                     if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
  2535                         return QRect();
  2649                         return QRect();
  2536                     ret = QRect(x, y, buttonWidth, buttonSize.height());
  2650                     ret = QRect(x, y, buttonSize.width(), buttonSize.height());
  2537                     break;
  2651                     break;
  2538                 case SC_SpinBoxDown:
  2652                 case SC_SpinBoxDown:
  2539                     if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
  2653                     if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
  2540                         return QRect();
  2654                         return QRect();
  2541                     ret = QRect(x+buttonSize.width(), y, buttonWidth, buttonSize.height());
  2655                     ret = QRect(x + (sideBySide ? buttonSize.width() : 0), 
       
  2656                                 y + (sideBySide ? 0 : buttonSize.height()), 
       
  2657                                 buttonSize.width(), buttonSize.height());
  2542                     break;
  2658                     break;
  2543                 case SC_SpinBoxEditField:
  2659                 case SC_SpinBoxEditField:
  2544                     if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
  2660                     if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
  2545                         ret = QRect(
  2661                         ret = QRect(
  2546                                 frameThickness,
  2662                                 frameThickness,
  2547                                 frameThickness,
  2663                                 frameThickness,
  2548                                 spinbox->rect.width() - 2*frameThickness,
  2664                                 spinbox->rect.width() - 2 * frameThickness,
  2549                                 spinbox->rect.height() - 2*frameThickness);
  2665                                 spinbox->rect.height() - 2 * frameThickness);
  2550                     else
  2666                     else
  2551                         ret = QRect(
  2667                         ret = QRect(
  2552                                 frameThickness,
  2668                                 frameThickness,
  2553                                 frameThickness,
  2669                                 frameThickness,
  2554                                 x - frameThickness,
  2670                                 x - frameThickness,
  2555                                 spinbox->rect.height() - 2*frameThickness);
  2671                                 spinbox->rect.height() - 2 * frameThickness);
  2556                     break;
  2672                     break;
  2557                 case SC_SpinBoxFrame:
  2673                 case SC_SpinBoxFrame:
  2558                     ret = spinbox->rect;
  2674                     ret = spinbox->rect;
  2559                     break;
  2675                     break;
  2560                 default:
  2676                 default:
  2566     case CC_ComboBox:
  2682     case CC_ComboBox:
  2567         if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
  2683         if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
  2568             ret = cmb->rect;
  2684             ret = cmb->rect;
  2569             const int width = cmb->rect.width();
  2685             const int width = cmb->rect.width();
  2570             const int height = cmb->rect.height();
  2686             const int height = cmb->rect.height();
       
  2687             const int buttonIconSize = QS60StylePrivate::pixelMetric(PM_ButtonIconSize);
  2571             const int buttonMargin = cmb->frame ? 2 : 0;
  2688             const int buttonMargin = cmb->frame ? 2 : 0;
  2572             // lets use spinbox frame here as well, as no combobox specific value available.
  2689             // lets use spinbox frame here as well, as no combobox specific value available.
  2573             const int frameThickness = cmb->frame ? pixelMetric(PM_SpinBoxFrameWidth, cmb, widget) : 0;
  2690             const int frameThickness = cmb->frame ? pixelMetric(PM_SpinBoxFrameWidth, cmb, widget) : 0;
  2574             const int buttonWidth = QS60StylePrivate::pixelMetric(QStyle::PM_ButtonIconSize);
  2691             const int buttonWidth = qMax(cmb->rect.height(), buttonIconSize);
  2575 
  2692 
  2576             QSize buttonSize;
  2693             QSize buttonSize;
  2577             buttonSize.setHeight(qMax(8, (cmb->rect.height()>>1) - frameThickness)); //minimum of 8 pixels
  2694             buttonSize.setWidth(buttonWidth + 2 * buttonMargin);
  2578             buttonSize.setWidth(buttonWidth+2*buttonMargin);
  2695             buttonSize.setHeight(qMax(8, (cmb->rect.height() >> 1) - frameThickness)); //buttons should be squares
  2579             buttonSize = buttonSize.expandedTo(QApplication::globalStrut());
  2696             buttonSize = buttonSize.expandedTo(QApplication::globalStrut());
  2580             switch (scontrol) {
  2697             switch (scontrol) {
  2581                 case SC_ComboBoxArrow:
  2698                 case SC_ComboBoxArrow: {
  2582                     ret.setRect(
  2699                     const int xposMod = cmb->rect.x() + width - buttonMargin - buttonWidth;
  2583                         ret.x() + ret.width() - buttonMargin - buttonWidth,
  2700                     const int ypos = cmb->rect.y();
  2584                         ret.y() + buttonMargin,
  2701                     ret.setRect(xposMod, ypos + buttonMargin, buttonWidth, height - 2 * buttonMargin);
  2585                         buttonWidth,
  2702                     }
  2586                         height - 2*buttonMargin);
       
  2587                     break;
  2703                     break;
  2588                 case SC_ComboBoxEditField: {
  2704                 case SC_ComboBoxEditField: {
  2589                     ret.setRect(
  2705                     const int withFrameX = cmb->rect.x() + width - frameThickness - buttonSize.width();
  2590                         ret.x() + frameThickness,
  2706                     ret = QRect(
  2591                         ret.y() + frameThickness,
  2707                         frameThickness,
  2592                         ret.width() - 2*frameThickness - buttonSize.width(),
  2708                         frameThickness,
  2593                         ret.height() - 2*frameThickness);
  2709                         withFrameX - frameThickness,
       
  2710                         height - 2 * frameThickness);
       
  2711                     }
       
  2712                 break;
       
  2713                 case SC_ComboBoxListBoxPopup: {
       
  2714                     const QRect desktopContent = QApplication::desktop()->availableGeometry();
       
  2715 
       
  2716                     // take the size of this and position bottom above available area
       
  2717                     QRect popupRect;
       
  2718                     const int width = desktopContent.width() - pixelMetric(PM_LayoutRightMargin) - pixelMetric(PM_LayoutLeftMargin);
       
  2719                     popupRect.setWidth(width);
       
  2720                     popupRect.setHeight(desktopContent.height()); //combobox resets height anyway based on content
       
  2721                     popupRect.setBottom(desktopContent.bottom());
       
  2722                     popupRect.translate(pixelMetric(PM_LayoutLeftMargin), 0);
       
  2723                     ret = popupRect;
  2594                     }
  2724                     }
  2595                 break;
  2725                 break;
  2596             default:
  2726             default:
  2597                 break;
  2727                 break;
  2598             }
  2728             }
       
  2729             ret = visualRect(cmb->direction, cmb->rect, ret);
  2599         }
  2730         }
  2600         break;
  2731         break;
  2601     case CC_GroupBox:
  2732     case CC_GroupBox:
  2602         if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
  2733         if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
  2603             ret = QCommonStyle::subControlRect(control, option, scontrol, widget);
  2734             ret = QCommonStyle::subControlRect(control, option, scontrol, widget);
  2604             switch (scontrol) {
  2735             switch (scontrol) {
  2605                 case SC_GroupBoxCheckBox: //fallthrough
  2736                 case SC_GroupBoxCheckBox: //fallthrough
  2606                 case SC_GroupBoxLabel: {
  2737                 case SC_GroupBoxLabel: {
  2607                     //slightly indent text and boxes, so that dialog border does not mess with them.
  2738                     //slightly indent text and boxes, so that dialog border does not mess with them.
  2608                     const int horizontalSpacing =
  2739                     const int horizontalSpacing =
  2609                         QS60StylePrivate::pixelMetric(QStyle::PM_LayoutHorizontalSpacing);
  2740                         QS60StylePrivate::pixelMetric(PM_LayoutHorizontalSpacing);
  2610                     ret.adjust(2,horizontalSpacing-3,0,0);
  2741                     ret.adjust(2, horizontalSpacing - 3, 0, 0);
  2611                     }
  2742                     }
  2612                     break;
  2743                     break;
  2613                 case SC_GroupBoxFrame: {
  2744                 case SC_GroupBoxFrame: {
  2614                     const QRect textBox = subControlRect(control, option, SC_GroupBoxLabel, widget);
  2745                     const QRect textBox = subControlRect(control, option, SC_GroupBoxLabel, widget);
  2615                     const int tbHeight = textBox.height();
  2746                     const int tbHeight = textBox.height();
  2616                     ret.translate(0, -ret.y());
  2747                     ret.translate(0, -ret.y());
  2617                     // include title to within the groupBox frame
  2748                     // include title to within the groupBox frame
  2618                     ret.setHeight(ret.height()+tbHeight);
  2749                     ret.setHeight(ret.height() + tbHeight);
  2619                     if (widget && ret.bottom() > widget->rect().bottom())
  2750                     if (widget && ret.bottom() > widget->rect().bottom())
  2620                         ret.setBottom(widget->rect().bottom());
  2751                         ret.setBottom(widget->rect().bottom());
  2621                     }
  2752                     }
  2622                     break;
  2753                     break;
  2623                 default:
  2754                 default:
  2625             }
  2756             }
  2626         }
  2757         }
  2627         break;
  2758         break;
  2628     case CC_ToolButton:
  2759     case CC_ToolButton:
  2629         if (const QStyleOptionToolButton *toolButton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
  2760         if (const QStyleOptionToolButton *toolButton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
  2630             const int indicatorRect = pixelMetric(PM_MenuButtonIndicator) + 2*pixelMetric(PM_ButtonMargin);
  2761             const int indicatorRect = pixelMetric(PM_MenuButtonIndicator) + 2 * pixelMetric(PM_ButtonMargin);
  2631             const int border = pixelMetric(PM_ButtonMargin) + pixelMetric(PM_DefaultFrameWidth);
  2762             const int border = pixelMetric(PM_ButtonMargin) + pixelMetric(PM_DefaultFrameWidth);
  2632             ret = toolButton->rect;
  2763             ret = toolButton->rect;
  2633             const bool popup = (toolButton->features &
  2764             const bool popup = (toolButton->features &
  2634                     (QStyleOptionToolButton::MenuButtonPopup | QStyleOptionToolButton::PopupDelay))
  2765                     (QStyleOptionToolButton::MenuButtonPopup | QStyleOptionToolButton::PopupDelay))
  2635                     == QStyleOptionToolButton::MenuButtonPopup;
  2766                     == QStyleOptionToolButton::MenuButtonPopup;
  2659 */
  2790 */
  2660 QRect QS60Style::subElementRect(SubElement element, const QStyleOption *opt, const QWidget *widget) const
  2791 QRect QS60Style::subElementRect(SubElement element, const QStyleOption *opt, const QWidget *widget) const
  2661 {
  2792 {
  2662     QRect ret;
  2793     QRect ret;
  2663     switch (element) {
  2794     switch (element) {
       
  2795         case SE_RadioButtonFocusRect:
       
  2796             ret = opt->rect;
       
  2797             break;
  2664         case SE_LineEditContents: {
  2798         case SE_LineEditContents: {
  2665                 // in S60 the input text box doesn't start from line Edit's TL, but
  2799                 // in S60 the input text box doesn't start from line Edit's TL, but
  2666                 // a bit indented.
  2800                 // a bit indented (8 pixels).
  2667                 QRect lineEditRect = opt->rect;
  2801                 const int KLineEditDefaultIndention = 8;
  2668                 const int adjustment = opt->rect.height()>>2;
  2802                 ret = visualRect(
  2669                 lineEditRect.adjust(adjustment,0,0,0);
  2803                     opt->direction, opt->rect, opt->rect.adjusted(KLineEditDefaultIndention, 0, 0, 0));
  2670                 ret = lineEditRect;
       
  2671             }
  2804             }
  2672             break;
  2805             break;
  2673         case SE_TabBarTearIndicator:
  2806         case SE_TabBarTearIndicator:
  2674             ret = QRect(0,0,0,0);
  2807             ret = QRect(0, 0, 0, 0);
  2675             break;
  2808             break;
  2676         case SE_TabWidgetTabBar:
  2809         case SE_TabWidgetTabBar:
  2677             if (const QStyleOptionTabWidgetFrame *optionTab = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) {
  2810             if (const QStyleOptionTabWidgetFrame *optionTab = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) {
  2678                 ret = QCommonStyle::subElementRect(element, opt, widget);
  2811                 ret = QCommonStyle::subElementRect(element, opt, widget);
  2679 
  2812 
  2680                 if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) {
  2813                 if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) {
  2681                     const int tabOverlapNoBorder =
  2814                     const int tabOverlapNoBorder =
  2682                         QS60StylePrivate::pixelMetric(QStyle::PM_TabBarTabOverlap);
  2815                         QS60StylePrivate::pixelMetric(PM_TabBarTabOverlap);
  2683                     const int tabOverlap =
  2816                     const int tabOverlap =
  2684                         tabOverlapNoBorder-QS60StylePrivate::pixelMetric(QStyle::PM_DefaultFrameWidth);
  2817                         tabOverlapNoBorder-QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth);
  2685                     const QTabWidget *tab = qobject_cast<const QTabWidget *>(widget);
  2818                     const QTabWidget *tab = qobject_cast<const QTabWidget *>(widget);
  2686                     int gain = (tab) ? tabOverlap * tab->count() : 0;
  2819                     int gain = (tab) ? tabOverlap * tab->count() : 0;
  2687                     switch (twf->shape) {
  2820                     switch (twf->shape) {
  2688                         case QTabBar::RoundedNorth:
  2821                         case QTabBar::RoundedNorth:
  2689                         case QTabBar::TriangularNorth:
  2822                         case QTabBar::TriangularNorth:
  2691                         case QTabBar::TriangularSouth: {
  2824                         case QTabBar::TriangularSouth: {
  2692                             if (widget) {
  2825                             if (widget) {
  2693                                 // make sure that gain does not set the rect outside of widget boundaries
  2826                                 // make sure that gain does not set the rect outside of widget boundaries
  2694                                 if (twf->direction == Qt::RightToLeft) {
  2827                                 if (twf->direction == Qt::RightToLeft) {
  2695                                     if ((ret.left() - gain) < widget->rect().left())
  2828                                     if ((ret.left() - gain) < widget->rect().left())
  2696                                         gain = widget->rect().left()-ret.left();
  2829                                         gain = widget->rect().left() - ret.left();
  2697                                     ret.adjust(-gain,0,0,0);
  2830                                     ret.adjust(-gain, 0, 0, 0);
  2698                                 } else {
  2831                                 } else {
  2699                                     if ((ret.right() + gain) > widget->rect().right())
  2832                                     if ((ret.right() + gain) > widget->rect().right())
  2700                                         gain = widget->rect().right()-ret.right();
  2833                                         gain = widget->rect().right() - ret.right();
  2701                                     ret.adjust(0,0,gain,0);
  2834                                     ret.adjust(0, 0, gain, 0);
  2702                                     }
  2835                                     }
  2703                             }
  2836                             }
  2704                             break;
  2837                             break;
  2705                         }
  2838                         }
  2706                         default: {
  2839                         default: {
  2707                             if (widget) {
  2840                             if (widget) {
  2708                                 if ((ret.bottom() + gain) > widget->rect().bottom())
  2841                                 if ((ret.bottom() + gain) > widget->rect().bottom())
  2709                                     gain = widget->rect().bottom()-ret.bottom();
  2842                                     gain = widget->rect().bottom() - ret.bottom();
  2710                                 ret.adjust(0,0,0,gain);
  2843                                 ret.adjust(0, 0, 0, gain);
  2711                             }
  2844                             }
  2712                             break;
  2845                             break;
  2713                         }
  2846                         }
  2714                     }
  2847                     }
  2715                 }
  2848                 }
  2728                 // text and decoration towards the beginning
  2861                 // text and decoration towards the beginning
  2729                 if (listItem &&
  2862                 if (listItem &&
  2730                     multiSelection &&
  2863                     multiSelection &&
  2731                     (vopt->features & QStyleOptionViewItemV2::HasCheckIndicator)) {
  2864                     (vopt->features & QStyleOptionViewItemV2::HasCheckIndicator)) {
  2732                     const int verticalSpacing =
  2865                     const int verticalSpacing =
  2733                         QS60StylePrivate::pixelMetric(QStyle::PM_LayoutVerticalSpacing);
  2866                         QS60StylePrivate::pixelMetric(PM_LayoutVerticalSpacing);
  2734                     //const int horizontalSpacing = QS60StylePrivate::pixelMetric(QStyle::PM_LayoutHorizontalSpacing);
  2867                     //const int horizontalSpacing = QS60StylePrivate::pixelMetric(PM_LayoutHorizontalSpacing);
  2735                     const int checkBoxRectWidth = subElementRect(SE_ItemViewItemCheckIndicator, opt, widget).width();
  2868                     const int checkBoxRectWidth = subElementRect(SE_ItemViewItemCheckIndicator, opt, widget).width();
  2736                     ret.adjust(-checkBoxRectWidth-verticalSpacing,0,-checkBoxRectWidth-verticalSpacing,0);
  2869                     ret.adjust(-checkBoxRectWidth - verticalSpacing, 0, -checkBoxRectWidth - verticalSpacing, 0);
  2737                 }
  2870                 }
  2738             } else if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
  2871             } else if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
  2739                 const bool checkable = menuItem->checkType != QStyleOptionMenuItem::NotCheckable;
  2872                 const bool checkable = menuItem->checkType != QStyleOptionMenuItem::NotCheckable;
  2740                 const int indicatorWidth = checkable ?
  2873                 const int indicatorWidth = checkable ?
  2741                     pixelMetric(PM_ListViewIconSize, opt, widget) :
  2874                     pixelMetric(PM_ListViewIconSize, opt, widget) :
  2742                     pixelMetric(PM_SmallIconSize, opt, widget);
  2875                     pixelMetric(PM_SmallIconSize, opt, widget);
  2743                 ret = menuItem->rect;
  2876                 ret = menuItem->rect;
  2744 
  2877 
  2745                 if (element == SE_ItemViewItemDecoration) {
  2878                 if (element == SE_ItemViewItemDecoration) {
  2746                     if (menuItem->direction == Qt::RightToLeft)
  2879                     if (menuItem->icon.isNull()) {
  2747                         ret.translate(ret.width()-indicatorWidth, 0);
  2880                         ret = QRect();
  2748                     ret.setWidth(indicatorWidth);
  2881                     } else {
       
  2882                         if (menuItem->direction == Qt::RightToLeft)
       
  2883                             ret.translate(ret.width()-indicatorWidth, 0);
       
  2884                         ret.setWidth(indicatorWidth);
       
  2885                     }
  2749                 } else {
  2886                 } else {
  2750                     ret = menuItem->rect;
  2887                     ret = menuItem->rect;
  2751                     if (!menuItem->icon.isNull())
  2888                     if (!menuItem->icon.isNull())
  2752                         if (menuItem->direction == Qt::LeftToRight)
  2889                         if (menuItem->direction == Qt::LeftToRight)
  2753                             ret.adjust(indicatorWidth, 0, 0, 0);
  2890                             ret.adjust(indicatorWidth, 0, 0, 0);
  2756 
  2893 
  2757                     // Make room for submenu indicator
  2894                     // Make room for submenu indicator
  2758                     if (menuItem->menuItemType == QStyleOptionMenuItem::SubMenu){
  2895                     if (menuItem->menuItemType == QStyleOptionMenuItem::SubMenu){
  2759                         // submenu indicator is very small, so lets halve the rect
  2896                         // submenu indicator is very small, so lets halve the rect
  2760                         if (menuItem->direction == Qt::LeftToRight)
  2897                         if (menuItem->direction == Qt::LeftToRight)
  2761                             ret.adjust(0,0,-(indicatorWidth >> 1),0);
  2898                             ret.adjust(0, 0, -(indicatorWidth >> 1), 0);
  2762                         else
  2899                         else
  2763                             ret.adjust((indicatorWidth >> 1),0,0,0);
  2900                             ret.adjust((indicatorWidth >> 1), 0, 0, 0);
  2764                     }
  2901                     }
  2765                 }
  2902                 }
  2766             }
  2903             }
  2767             break;
  2904             break;
  2768         case SE_ItemViewItemCheckIndicator:
  2905         case SE_ItemViewItemCheckIndicator:
  2775                 const bool checkBoxOnly = (vopt->features & QStyleOptionViewItemV2::HasCheckIndicator) &&
  2912                 const bool checkBoxOnly = (vopt->features & QStyleOptionViewItemV2::HasCheckIndicator) &&
  2776                     listItem &&
  2913                     listItem &&
  2777                     singleSelection;
  2914                     singleSelection;
  2778 
  2915 
  2779                 // Selection check mark rect.
  2916                 // Selection check mark rect.
  2780                 const int indicatorWidth = QS60StylePrivate::pixelMetric(QStyle::PM_IndicatorWidth);
  2917                 const int indicatorWidth = QS60StylePrivate::pixelMetric(PM_IndicatorWidth);
  2781                 const int indicatorHeight = QS60StylePrivate::pixelMetric(QStyle::PM_IndicatorHeight);
  2918                 const int indicatorHeight = QS60StylePrivate::pixelMetric(PM_IndicatorHeight);
  2782                 const int spacing = QS60StylePrivate::pixelMetric(QStyle::PM_CheckBoxLabelSpacing);
  2919                 const int spacing = QS60StylePrivate::pixelMetric(PM_CheckBoxLabelSpacing);
  2783 
  2920 
  2784                 const int itemHeight = opt->rect.height();
  2921                 const int itemHeight = opt->rect.height();
  2785                 int heightOffset = 0;
  2922                 int heightOffset = 0;
  2786                 if (indicatorHeight < itemHeight)
  2923                 if (indicatorHeight < itemHeight)
  2787                     heightOffset = ((itemHeight - indicatorHeight)>>1);
  2924                     heightOffset = ((itemHeight - indicatorHeight) >> 1);
  2788                 if (checkBoxOnly) {
  2925                 if (checkBoxOnly) {
  2789                     // Move rect and make it slightly smaller, so that
  2926                     // Move rect and make it slightly smaller, so that
  2790                     // a) highlight border does not cross the rect
  2927                     // a) highlight border does not cross the rect
  2791                     // b) in s60 list checkbox is smaller than normal checkbox
  2928                     // b) in s60 list checkbox is smaller than normal checkbox
  2792                     //todo; magic three
  2929                     //todo; magic three
  2793                     ret.setRect(opt->rect.left()+3, opt->rect.top() + heightOffset,
  2930                     ret.setRect(opt->rect.left() + 3, opt->rect.top() + heightOffset,
  2794                         indicatorWidth-3, indicatorHeight-3);
  2931                         indicatorWidth - 3, indicatorHeight - 3);
  2795                 } else {
  2932                 } else {
  2796                     ret.setRect(opt->rect.right() - indicatorWidth - spacing, opt->rect.top() + heightOffset,
  2933                     ret.setRect(opt->rect.right() - indicatorWidth - spacing, opt->rect.top() + heightOffset,
  2797                         indicatorWidth, indicatorHeight);
  2934                         indicatorWidth, indicatorHeight);
  2798                 }
  2935                 }
  2799             } else  {
  2936             } else  {
  2803         case SE_HeaderLabel:
  2940         case SE_HeaderLabel:
  2804             ret = QCommonStyle::subElementRect(element, opt, widget);
  2941             ret = QCommonStyle::subElementRect(element, opt, widget);
  2805             if (qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
  2942             if (qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
  2806                 // Subtract area needed for line
  2943                 // Subtract area needed for line
  2807                 if (opt->state & State_Horizontal)
  2944                 if (opt->state & State_Horizontal)
  2808                     ret.setHeight(ret.height() - QS60StylePrivate::pixelMetric(PM_Custom_BoldLineWidth));
  2945                     ret.setHeight(ret.height() - QS60StylePrivate::pixelMetric(PM_BoldLineWidth));
  2809                 else
  2946                 else
  2810                     ret.setWidth(ret.width() - QS60StylePrivate::pixelMetric(PM_Custom_ThinLineWidth));
  2947                     ret.setWidth(ret.width() - QS60StylePrivate::pixelMetric(PM_ThinLineWidth));
  2811                 }
  2948                 }
  2812             ret = visualRect(opt->direction, opt->rect, ret);
  2949             ret = visualRect(opt->direction, opt->rect, ret);
       
  2950             break;
       
  2951         case SE_RadioButtonIndicator: {
       
  2952                 const int height = pixelMetric(PM_ExclusiveIndicatorHeight, opt, widget);
       
  2953                 ret.setRect(opt->rect.x(), opt->rect.y() + ((opt->rect.height() - height) >> 1),
       
  2954                         pixelMetric(PM_ExclusiveIndicatorWidth, opt, widget), height);
       
  2955                 ret.translate(2, 0); //move indicator slightly to avoid highlight crossing over it
       
  2956                 ret = visualRect(opt->direction, opt->rect, ret);
       
  2957             }
       
  2958             break;
       
  2959         case SE_CheckBoxIndicator: {
       
  2960                 const int height = pixelMetric(PM_IndicatorHeight, opt, widget);
       
  2961                 ret.setRect(opt->rect.x(), opt->rect.y() + ((opt->rect.height() - height) >> 1),
       
  2962                           pixelMetric(PM_IndicatorWidth, opt, widget), height);
       
  2963                 ret.translate(2, 0); //move indicator slightly to avoid highlight crossing over it
       
  2964                 ret = visualRect(opt->direction, opt->rect, ret);
       
  2965             }
       
  2966             break;
       
  2967         case SE_CheckBoxFocusRect:
       
  2968             ret = opt->rect;
  2813             break;
  2969             break;
  2814         default:
  2970         default:
  2815             ret = QCommonStyle::subElementRect(element, opt, widget);
  2971             ret = QCommonStyle::subElementRect(element, opt, widget);
  2816     }
  2972     }
  2817     return ret;
  2973     return ret;
  2825     Q_D(const QS60Style);
  2981     Q_D(const QS60Style);
  2826     QCommonStyle::polish(widget);
  2982     QCommonStyle::polish(widget);
  2827 
  2983 
  2828     if (!widget)
  2984     if (!widget)
  2829         return;
  2985         return;
       
  2986 
       
  2987     //Currently we only support animations in QProgressBar.
       
  2988 #ifndef QT_NO_PROGRESSBAR
       
  2989     if (qobject_cast<QProgressBar *>(widget))
       
  2990         widget->installEventFilter(this);
       
  2991 #endif
  2830 
  2992 
  2831     if (false
  2993     if (false
  2832 #ifndef QT_NO_SCROLLBAR
  2994 #ifndef QT_NO_SCROLLBAR
  2833         || qobject_cast<QScrollBar *>(widget)
  2995         || qobject_cast<QScrollBar *>(widget)
  2834 #endif
  2996 #endif
  2858 /*!
  3020 /*!
  2859   \reimp
  3021   \reimp
  2860  */
  3022  */
  2861 void QS60Style::unpolish(QWidget *widget)
  3023 void QS60Style::unpolish(QWidget *widget)
  2862 {
  3024 {
       
  3025     Q_D(QS60Style);
       
  3026 
  2863     if (false
  3027     if (false
  2864     #ifndef QT_NO_SCROLLBAR
  3028     #ifndef QT_NO_SCROLLBAR
  2865         || qobject_cast<QScrollBar *>(widget)
  3029         || qobject_cast<QScrollBar *>(widget)
  2866     #endif
  3030     #endif
  2867         )
  3031         )
  2884     }
  3048     }
  2885 
  3049 
  2886     if (widget)
  3050     if (widget)
  2887         widget->setPalette(QPalette());
  3051         widget->setPalette(QPalette());
  2888 
  3052 
       
  3053 #if defined(Q_WS_S60) && !defined(QT_NO_PROGRESSBAR)
       
  3054     if (QProgressBar *bar = qobject_cast<QProgressBar *>(widget)) {
       
  3055         widget->removeEventFilter(this);
       
  3056         d->m_bars.removeAll(bar);
       
  3057     }
       
  3058 #else
       
  3059     Q_UNUSED(d)
       
  3060 #endif
  2889     QCommonStyle::unpolish(widget);
  3061     QCommonStyle::unpolish(widget);
  2890 }
  3062 }
  2891 
  3063 
  2892 /*!
  3064 /*!
  2893   \reimp
  3065   \reimp
  2915   \reimp
  3087   \reimp
  2916  */
  3088  */
  2917 bool QS60Style::event(QEvent *e)
  3089 bool QS60Style::event(QEvent *e)
  2918 {
  3090 {
  2919 #ifdef QT_KEYPAD_NAVIGATION
  3091 #ifdef QT_KEYPAD_NAVIGATION
  2920     if (QS60StylePrivate::isTouchSupported())
       
  2921         return false;
       
  2922     Q_D(QS60Style);
  3092     Q_D(QS60Style);
       
  3093     const QEvent::Type eventType = e->type();
       
  3094     if ((eventType == QEvent::FocusIn ||
       
  3095          eventType == QEvent::FocusOut ||
       
  3096          eventType == QEvent::EnterEditFocus ||
       
  3097          eventType == QEvent::LeaveEditFocus) &&
       
  3098         QS60StylePrivate::isTouchSupported())
       
  3099             return false;
       
  3100 #endif
       
  3101 
  2923     switch (e->type()) {
  3102     switch (e->type()) {
       
  3103     case QEvent::Timer: {
       
  3104         QTimerEvent *te = static_cast<QTimerEvent*>(e);
       
  3105         timerEvent(te);
       
  3106         }
       
  3107         break;
       
  3108 #ifdef QT_KEYPAD_NAVIGATION
  2924     case QEvent::FocusIn:
  3109     case QEvent::FocusIn:
  2925         if (QWidget *focusWidget = QApplication::focusWidget()) {
  3110         if (QWidget *focusWidget = QApplication::focusWidget()) {
  2926             if (!d->m_focusFrame)
  3111             if (!d->m_focusFrame)
  2927                 d->m_focusFrame = new QFocusFrame(focusWidget);
  3112                 d->m_focusFrame = new QFocusFrame(focusWidget);
  2928             d->m_focusFrame->setWidget(focusWidget);
  3113             d->m_focusFrame->setWidget(focusWidget);
  2937     case QEvent::EnterEditFocus:
  3122     case QEvent::EnterEditFocus:
  2938     case QEvent::LeaveEditFocus:
  3123     case QEvent::LeaveEditFocus:
  2939         if (d->m_focusFrame)
  3124         if (d->m_focusFrame)
  2940             d->m_focusFrame->update();
  3125             d->m_focusFrame->update();
  2941         break;
  3126         break;
       
  3127 #endif
  2942     default:
  3128     default:
  2943         break;
  3129         break;
  2944     }
  3130     }
  2945 #else
       
  2946     Q_UNUSED(e)
       
  2947 #endif
       
  2948     return false;
  3131     return false;
  2949 }
  3132 }
  2950 
  3133 
  2951 /*!
  3134 /*!
  2952     \internal
  3135     \internal
  2953  */
  3136  */
  2954 QIcon QS60Style::standardIconImplementation(StandardPixmap standardIcon,
  3137 QIcon QS60Style::standardIconImplementation(StandardPixmap standardIcon,
  2955     const QStyleOption *option, const QWidget *widget) const
  3138     const QStyleOption *option, const QWidget *widget) const
  2956 {
  3139 {
  2957     const int iconDimension = QS60StylePrivate::pixelMetric(QStyle::PM_ToolBarIconSize);
  3140     const int iconDimension = QS60StylePrivate::pixelMetric(PM_ToolBarIconSize);
  2958     const QRect iconSize = (!option) ? QRect(0,0,iconDimension,iconDimension) : option->rect;
  3141     const QRect iconSize = (!option) ? QRect(0, 0, iconDimension, iconDimension) : option->rect;
  2959     QS60StyleEnums::SkinParts part;
  3142     QS60StyleEnums::SkinParts part;
  2960     QS60StylePrivate::SkinElementFlags adjustedFlags;
  3143     QS60StylePrivate::SkinElementFlags adjustedFlags;
  2961     if (option)
  3144     if (option)
  2962         adjustedFlags = (option->state & State_Enabled || option->state == 0) ?
  3145         adjustedFlags = (option->state & State_Enabled || option->state == 0) ?
  2963             QS60StylePrivate::SF_StateEnabled :
  3146             QS60StylePrivate::SF_StateEnabled :
  2964             QS60StylePrivate::SF_StateDisabled;
  3147             QS60StylePrivate::SF_StateDisabled;
  2965 
  3148 
  2966     switch(standardIcon) {
  3149     switch(standardIcon) {
  2967         case QStyle::SP_MessageBoxWarning:
  3150         case SP_MessageBoxWarning:
  2968             part = QS60StyleEnums::SP_QgnNoteWarning;
  3151             part = QS60StyleEnums::SP_QgnNoteWarning;
  2969             break;
  3152             break;
  2970         case QStyle::SP_MessageBoxInformation:
  3153         case SP_MessageBoxInformation:
  2971             part = QS60StyleEnums::SP_QgnNoteInfo;
  3154             part = QS60StyleEnums::SP_QgnNoteInfo;
  2972             break;
  3155             break;
  2973         case QStyle::SP_MessageBoxCritical:
  3156         case SP_MessageBoxCritical:
  2974             part = QS60StyleEnums::SP_QgnNoteError;
  3157             part = QS60StyleEnums::SP_QgnNoteError;
  2975             break;
  3158             break;
  2976         case QStyle::SP_MessageBoxQuestion:
  3159         case SP_MessageBoxQuestion:
  2977             part = QS60StyleEnums::SP_QgnNoteQuery;
  3160             part = QS60StyleEnums::SP_QgnNoteQuery;
  2978             break;
  3161             break;
  2979         case QStyle::SP_ArrowRight:
  3162         case SP_ArrowRight:
  2980             part = QS60StyleEnums::SP_QgnIndiNaviArrowRight;
  3163             part = QS60StyleEnums::SP_QgnIndiNaviArrowRight;
  2981             break;
  3164             break;
  2982         case QStyle::SP_ArrowLeft:
  3165         case SP_ArrowLeft:
  2983             part = QS60StyleEnums::SP_QgnIndiNaviArrowLeft;
  3166             part = QS60StyleEnums::SP_QgnIndiNaviArrowLeft;
  2984             break;
  3167             break;
  2985         case QStyle::SP_ArrowUp:
  3168         case SP_ArrowUp:
  2986             part = QS60StyleEnums::SP_QgnIndiNaviArrowLeft;
  3169             part = QS60StyleEnums::SP_QgnIndiNaviArrowLeft;
  2987             adjustedFlags |= QS60StylePrivate::SF_PointEast;
  3170             adjustedFlags |= QS60StylePrivate::SF_PointEast;
  2988             break;
  3171             break;
  2989         case QStyle::SP_ArrowDown:
  3172         case SP_ArrowDown:
  2990             part = QS60StyleEnums::SP_QgnIndiNaviArrowLeft;
  3173             part = QS60StyleEnums::SP_QgnIndiNaviArrowLeft;
  2991             adjustedFlags |= QS60StylePrivate::SF_PointWest;
  3174             adjustedFlags |= QS60StylePrivate::SF_PointWest;
  2992             break;
  3175             break;
  2993         case QStyle::SP_ArrowBack:
  3176         case SP_ArrowBack:
  2994             if (QApplication::layoutDirection() == Qt::RightToLeft)
  3177             if (QApplication::layoutDirection() == Qt::RightToLeft)
  2995                 return QS60Style::standardIcon(SP_ArrowRight, option, widget);
  3178                 return QS60Style::standardIcon(SP_ArrowRight, option, widget);
  2996             return QS60Style::standardIcon(SP_ArrowLeft, option, widget);
  3179             return QS60Style::standardIcon(SP_ArrowLeft, option, widget);
  2997         case QStyle::SP_ArrowForward:
  3180         case SP_ArrowForward:
  2998             if (QApplication::layoutDirection() == Qt::RightToLeft)
  3181             if (QApplication::layoutDirection() == Qt::RightToLeft)
  2999                 return QS60Style::standardIcon(SP_ArrowLeft, option, widget);
  3182                 return QS60Style::standardIcon(SP_ArrowLeft, option, widget);
  3000             return QS60Style::standardIcon(SP_ArrowRight, option, widget);
  3183             return QS60Style::standardIcon(SP_ArrowRight, option, widget);
  3001         case QStyle::SP_ComputerIcon:
  3184         case SP_ComputerIcon:
  3002             part = QS60StyleEnums::SP_QgnPropPhoneMemcLarge;
  3185             part = QS60StyleEnums::SP_QgnPropPhoneMemcLarge;
  3003             break;
  3186             break;
  3004         case QStyle::SP_DirClosedIcon:
  3187         case SP_DirClosedIcon:
  3005             part = QS60StyleEnums::SP_QgnPropFolderSmall;
  3188             part = QS60StyleEnums::SP_QgnPropFolderSmall;
  3006             break;
  3189             break;
  3007         case QStyle::SP_DirOpenIcon:
  3190         case SP_DirOpenIcon:
  3008             part = QS60StyleEnums::SP_QgnPropFolderCurrent;
  3191             part = QS60StyleEnums::SP_QgnPropFolderCurrent;
  3009             break;
  3192             break;
  3010         case QStyle::SP_DirIcon:
  3193         case SP_DirIcon:
  3011             part = QS60StyleEnums::SP_QgnPropFolderSmall;
  3194             part = QS60StyleEnums::SP_QgnPropFolderSmall;
  3012             break;
  3195             break;
  3013         case QStyle::SP_FileDialogNewFolder:
  3196         case SP_FileDialogNewFolder:
  3014             part = QS60StyleEnums::SP_QgnPropFolderSmallNew;
  3197             part = QS60StyleEnums::SP_QgnPropFolderSmallNew;
  3015             break;
  3198             break;
  3016         case QStyle::SP_FileIcon:
  3199         case SP_FileIcon:
  3017             part = QS60StyleEnums::SP_QgnPropFileSmall;
  3200             part = QS60StyleEnums::SP_QgnPropFileSmall;
  3018             break;
  3201             break;
  3019         case QStyle::SP_TrashIcon:
  3202         case SP_TrashIcon:
  3020             part = QS60StyleEnums::SP_QgnNoteErased;
  3203             part = QS60StyleEnums::SP_QgnNoteErased;
  3021             break;
  3204             break;
  3022         case QStyle::SP_ToolBarHorizontalExtensionButton:
  3205         case SP_ToolBarHorizontalExtensionButton:
  3023             part = QS60StyleEnums::SP_QgnIndiSubMenu;
  3206             part = QS60StyleEnums::SP_QgnIndiSubMenu;
  3024             if (QApplication::layoutDirection() == Qt::RightToLeft)
  3207             if (QApplication::layoutDirection() == Qt::RightToLeft)
  3025                 adjustedFlags |= QS60StylePrivate::SF_PointSouth;
  3208                 adjustedFlags |= QS60StylePrivate::SF_PointSouth;
  3026             break;
  3209             break;
  3027         case QStyle::SP_ToolBarVerticalExtensionButton:
  3210         case SP_ToolBarVerticalExtensionButton:
  3028             adjustedFlags |= QS60StylePrivate::SF_PointEast;
  3211             adjustedFlags |= QS60StylePrivate::SF_PointEast;
  3029             part = QS60StyleEnums::SP_QgnIndiSubMenu;
  3212             part = QS60StyleEnums::SP_QgnIndiSubMenu;
  3030             break;
  3213             break;
  3031 
  3214 
  3032         default:
  3215         default:
  3036     const QPixmap cachedPixMap(QS60StylePrivate::cachedPart(part, iconSize.size(), 0, flags));
  3219     const QPixmap cachedPixMap(QS60StylePrivate::cachedPart(part, iconSize.size(), 0, flags));
  3037     return cachedPixMap.isNull() ?
  3220     return cachedPixMap.isNull() ?
  3038         QCommonStyle::standardIconImplementation(standardIcon, option, widget) : QIcon(cachedPixMap);
  3221         QCommonStyle::standardIconImplementation(standardIcon, option, widget) : QIcon(cachedPixMap);
  3039 }
  3222 }
  3040 
  3223 
       
  3224 /*!
       
  3225     \internal
       
  3226     Animate indeterminate progress bars only when visible
       
  3227 */
       
  3228 bool QS60Style::eventFilter(QObject *object, QEvent *event)
       
  3229 {
       
  3230 #ifdef Q_WS_S60
       
  3231 #ifndef QT_NO_PROGRESSBAR
       
  3232     Q_D(QS60Style);
       
  3233     switch(event->type()) {
       
  3234     case QEvent::StyleChange:
       
  3235     case QEvent::Show:
       
  3236         if (QProgressBar *bar = qobject_cast<QProgressBar *>(object)) {
       
  3237             if (!d->m_bars.contains(bar))
       
  3238                 d->m_bars << bar;
       
  3239             if (d->m_bars.size() == 1) //only start with first animated progressbar
       
  3240                 d->startAnimation(QS60StyleEnums::SP_QgnGrafBarWaitAnim);
       
  3241         }
       
  3242         break;
       
  3243     case QEvent::Destroy:
       
  3244     case QEvent::Hide:
       
  3245         d->stopAnimation(QS60StyleEnums::SP_QgnGrafBarWaitAnim);
       
  3246         d->m_bars.removeAll(reinterpret_cast<QProgressBar *>(object));
       
  3247         break;
       
  3248     default:
       
  3249         break;
       
  3250     }
       
  3251 #endif // QT_NO_PROGRESSBAR
       
  3252 #endif // Q_WS_S60
       
  3253     return QStyle::eventFilter(object, event);
       
  3254 }
       
  3255 
       
  3256 /*!
       
  3257     \internal
       
  3258     Handle the timer \a event.
       
  3259 */
       
  3260 void QS60Style::timerEvent(QTimerEvent *event)
       
  3261 {
       
  3262 #ifdef Q_WS_S60
       
  3263 #ifndef QT_NO_PROGRESSBAR
       
  3264     Q_D(QS60Style);
       
  3265 
       
  3266     QS60StyleAnimation *progressBarAnimation =
       
  3267         QS60StylePrivate::animationDefinition(QS60StyleEnums::SP_QgnGrafBarWaitAnim);
       
  3268 
       
  3269     if (event->timerId() == progressBarAnimation->timerId()) {
       
  3270 
       
  3271         Q_ASSERT(progressBarAnimation->interval() > 0);
       
  3272 
       
  3273         if (progressBarAnimation->currentFrame() == progressBarAnimation->frameCount() )
       
  3274             if (progressBarAnimation->playMode() == QS60StyleEnums::AM_Looping)
       
  3275                 progressBarAnimation->setCurrentFrame(0);
       
  3276             else
       
  3277                 d->stopAnimation(progressBarAnimation->animationId());
       
  3278 
       
  3279         foreach (QProgressBar *bar, d->m_bars) {
       
  3280             if ((bar->minimum() == 0 && bar->maximum() == 0))
       
  3281                 bar->update();
       
  3282         }
       
  3283         progressBarAnimation->setCurrentFrame(progressBarAnimation->currentFrame() + 1);
       
  3284     }
       
  3285 #endif // QT_NO_PROGRESSBAR
       
  3286 #endif // Q_WS_S60
       
  3287     event->ignore();
       
  3288 }
       
  3289 
  3041 extern QPoint qt_s60_fill_background_offset(const QWidget *targetWidget);
  3290 extern QPoint qt_s60_fill_background_offset(const QWidget *targetWidget);
  3042 
  3291 
  3043 bool qt_s60_fill_background(QPainter *painter, const QRegion &rgn, const QBrush &brush)
  3292 bool qt_s60_fill_background(QPainter *painter, const QRegion &rgn, const QBrush &brush)
  3044 {
  3293 {
  3045     const QPixmap backgroundTexture(QS60StylePrivate::backgroundTexture());
  3294     const QPixmap backgroundTexture(QS60StylePrivate::backgroundTexture());
  3047         return false;
  3296         return false;
  3048 
  3297 
  3049     const QPaintDevice *target = painter->device();
  3298     const QPaintDevice *target = painter->device();
  3050     if (target->devType() == QInternal::Widget) {
  3299     if (target->devType() == QInternal::Widget) {
  3051         const QWidget *widget = static_cast<const QWidget *>(target);
  3300         const QWidget *widget = static_cast<const QWidget *>(target);
  3052         const QVector<QRect> &rects = rgn.rects();
  3301         if (!widget->testAttribute(Qt::WA_TranslucentBackground)) {
  3053         for (int i = 0; i < rects.size(); ++i) {
  3302             const QVector<QRect> &rects = rgn.rects();
  3054             const QRect rect(rects.at(i));
  3303             for (int i = 0; i < rects.size(); ++i) {
  3055             painter->drawPixmap(rect.topLeft(), backgroundTexture,
  3304                 const QRect rect(rects.at(i));
  3056                                 rect.translated(qt_s60_fill_background_offset(widget)));
  3305                 painter->drawPixmap(rect.topLeft(), backgroundTexture,
       
  3306                                     rect.translated(qt_s60_fill_background_offset(widget)));
       
  3307             }
  3057         }
  3308         }
  3058     }
  3309     }
  3059     return true;
  3310     return true;
  3060 }
  3311 }
  3061 
  3312