src/gui/styles/qs60style.cpp
branchRCL_3
changeset 5 d3bac044e0f0
parent 4 3b1da2848fc7
child 8 3f74d0d4af4c
equal deleted inserted replaced
4:3b1da2848fc7 5:d3bac044e0f0
    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,16,"QVGA Landscape"},
    92 {320,240,1,15,"QVGA Portrait"},
    96 {320,240,1,16,"QVGA Portrait"},
    93 {360,640,1,15,"NHD Landscape"},
    97 {360,640,1,16,"NHD Landscape"},
    94 {640,360,1,15,"NHD Portrait"},
    98 {640,360,1,16,"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,-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,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},
   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,-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,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},
   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,-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,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},
   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,-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,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},
   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,-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}
   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];
   562 
   566 
   563 QPixmap QS60StylePrivate::cachedPart(QS60StyleEnums::SkinParts part,
   567 QPixmap QS60StylePrivate::cachedPart(QS60StyleEnums::SkinParts part,
   564     const QSize &size, QPainter *painter, SkinElementFlags flags)
   568     const QSize &size, QPainter *painter, SkinElementFlags flags)
   565 {
   569 {
   566     QPixmap result;
   570     QPixmap result;
       
   571     const int animationFrame = (flags & SF_Animation) ? currentAnimationFrame(part) : 0;
       
   572 
   567     const QString cacheKey =
   573     const QString cacheKey =
   568         QString::fromLatin1("S60Style: SkinParts=%1 QSize=%2|%3 SkinPartFlags=%4")
   574         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);
   575             .arg((int)part).arg(size.width()).arg(size.height()).arg((int)flags).arg(animationFrame);
   570     if (!QPixmapCache::find(cacheKey, result)) {
   576     if (!QPixmapCache::find(cacheKey, result)) {
   571         result = QS60StylePrivate::part(part, size, painter, flags);
   577         result = QS60StylePrivate::part(part, size, painter, flags);
   572         QPixmapCache::insert(cacheKey, result);
   578         QPixmapCache::insert(cacheKey, result);
   573     }
   579     }
   574     return result;
   580     return result;
   670     palette->setColor(QPalette::LinkVisited, palette->color(QPalette::Link).darker());
   676     palette->setColor(QPalette::LinkVisited, palette->color(QPalette::Link).darker());
   671     palette->setColor(QPalette::Highlight,
   677     palette->setColor(QPalette::Highlight,
   672         s60Color(QS60StyleEnums::CL_QsnHighlightColors, 2, 0));
   678         s60Color(QS60StyleEnums::CL_QsnHighlightColors, 2, 0));
   673     // set background image as a texture brush
   679     // set background image as a texture brush
   674     palette->setBrush(QPalette::Window, backgroundTexture());
   680     palette->setBrush(QPalette::Window, backgroundTexture());
   675     // set these as transparent so that styled full screen theme background is visible
   681     // set as transparent so that styled full screen theme background is visible
   676     palette->setColor(QPalette::AlternateBase, Qt::transparent);
       
   677     palette->setBrush(QPalette::Base, Qt::transparent);
   682     palette->setBrush(QPalette::Base, Qt::transparent);
   678     // set button and tooltipbase based on pixel colors
   683     // set button and tooltipbase based on pixel colors
   679     const QColor buttonColor = colorFromFrameGraphics(SF_ButtonNormal);
   684     const QColor buttonColor = colorFromFrameGraphics(SF_ButtonNormal);
   680     palette->setColor(QPalette::Button, buttonColor);
   685     palette->setColor(QPalette::Button, buttonColor);
   681     const QColor toolTipColor = colorFromFrameGraphics(SF_ToolTip);
   686     const QColor toolTipColor = colorFromFrameGraphics(SF_ToolTip);
   683     palette->setColor(QPalette::Light, palette->color(QPalette::Button).lighter());
   688     palette->setColor(QPalette::Light, palette->color(QPalette::Button).lighter());
   684     palette->setColor(QPalette::Dark, palette->color(QPalette::Button).darker());
   689     palette->setColor(QPalette::Dark, palette->color(QPalette::Button).darker());
   685     palette->setColor(QPalette::Midlight, palette->color(QPalette::Button).lighter(125));
   690     palette->setColor(QPalette::Midlight, palette->color(QPalette::Button).lighter(125));
   686     palette->setColor(QPalette::Mid, palette->color(QPalette::Button).darker(150));
   691     palette->setColor(QPalette::Mid, palette->color(QPalette::Button).darker(150));
   687     palette->setColor(QPalette::Shadow, Qt::black);
   692     palette->setColor(QPalette::Shadow, Qt::black);
       
   693     QColor alternateBase = palette->light().color();
       
   694     alternateBase.setAlphaF(0.8);
       
   695     palette->setColor(QPalette::AlternateBase, alternateBase);
   688 
   696 
   689     QApplication::setPalette(*palette); //calling QApplication::setPalette clears palette hash
   697     QApplication::setPalette(*palette); //calling QApplication::setPalette clears palette hash
   690     setThemePaletteHash(palette);
   698     setThemePaletteHash(palette);
   691     storeThemePalette(palette);
   699     storeThemePalette(palette);
   692 }
   700 }
   771     widgetPalette = *palette;
   779     widgetPalette = *palette;
   772 
   780 
   773     widgetPalette.setColor(QPalette::HighlightedText,
   781     widgetPalette.setColor(QPalette::HighlightedText,
   774         s60Color(QS60StyleEnums::CL_QsnTextColors, 24, 0));
   782         s60Color(QS60StyleEnums::CL_QsnTextColors, 24, 0));
   775     QApplication::setPalette(widgetPalette, "QComboBox");
   783     QApplication::setPalette(widgetPalette, "QComboBox");
       
   784     widgetPalette = *palette;
       
   785 
       
   786     widgetPalette.setColor(QPalette::WindowText, s60Color(QS60StyleEnums::CL_QsnTextColors, 7, 0));
       
   787     QApplication::setPalette(widgetPalette, "QRadioButton");
       
   788     QApplication::setPalette(widgetPalette, "QCheckBox");
   776     widgetPalette = *palette;
   789     widgetPalette = *palette;
   777 
   790 
   778     widgetPalette.setColor(QPalette::WindowText, mainAreaTextColor);
   791     widgetPalette.setColor(QPalette::WindowText, mainAreaTextColor);
   779     widgetPalette.setColor(QPalette::Button, QApplication::palette().color(QPalette::Button));
   792     widgetPalette.setColor(QPalette::Button, QApplication::palette().color(QPalette::Button));
   780     widgetPalette.setColor(QPalette::Dark, mainAreaTextColor.darker());
   793     widgetPalette.setColor(QPalette::Dark, mainAreaTextColor.darker());
   811         case QS60StyleEnums::SP_QgnGrafTabActiveL:
   824         case QS60StyleEnums::SP_QgnGrafTabActiveL:
   812             //Returned QSize for tabs must not be square, but narrow rectangle with width:height
   825             //Returned QSize for tabs must not be square, but narrow rectangle with width:height
   813             //ratio of 1:2 for horizontal tab bars (and 2:1 for vertical ones).
   826             //ratio of 1:2 for horizontal tab bars (and 2:1 for vertical ones).
   814             result.setWidth(result.height() >> 1);
   827             result.setWidth(result.height() >> 1);
   815             break;
   828             break;
   816             
   829 
   817         case QS60StyleEnums::SP_QgnGrafNsliderEndLeft:
   830         case QS60StyleEnums::SP_QgnGrafNsliderEndLeft:
   818         case QS60StyleEnums::SP_QgnGrafNsliderEndRight:
   831         case QS60StyleEnums::SP_QgnGrafNsliderEndRight:
   819         case QS60StyleEnums::SP_QgnGrafNsliderMiddle:
   832         case QS60StyleEnums::SP_QgnGrafNsliderMiddle:
   820             result.setWidth(result.height() >> 1);
   833             result.setWidth(result.height() >> 1);
   821             break;
   834             break;
   822             
   835 
   823         case QS60StyleEnums::SP_QgnGrafNsliderMarker:
   836         case QS60StyleEnums::SP_QgnGrafNsliderMarker:
   824         case QS60StyleEnums::SP_QgnGrafNsliderMarkerSelected:
   837         case QS60StyleEnums::SP_QgnGrafNsliderMarkerSelected:
   825             result.scale(pixelMetric(QStyle::PM_SliderLength),
   838             result.scale(pixelMetric(QStyle::PM_SliderLength),
   826                 pixelMetric(QStyle::PM_SliderControlThickness), Qt::IgnoreAspectRatio);
   839                 pixelMetric(QStyle::PM_SliderControlThickness), Qt::IgnoreAspectRatio);
   827             break;
   840             break;
   920 
   933 
   921             const QS60StylePrivate::SkinElements grooveElement =
   934             const QS60StylePrivate::SkinElements grooveElement =
   922                 horizontal ? QS60StylePrivate::SE_ScrollBarGrooveHorizontal : QS60StylePrivate::SE_ScrollBarGrooveVertical;
   935                 horizontal ? QS60StylePrivate::SE_ScrollBarGrooveHorizontal : QS60StylePrivate::SE_ScrollBarGrooveVertical;
   923             QS60StylePrivate::drawSkinElement(grooveElement, painter, grooveRect, flags);
   936             QS60StylePrivate::drawSkinElement(grooveElement, painter, grooveRect, flags);
   924 
   937 
   925             const QStyle::SubControls subControls = optionSlider->subControls;
   938             const SubControls subControls = optionSlider->subControls;
   926 
   939 
   927             // select correct slider (horizontal/vertical/pressed)
   940             // select correct slider (horizontal/vertical/pressed)
   928             const bool sliderPressed = ((optionSlider->state & QStyle::State_Sunken) && (subControls & SC_ScrollBarSlider));
   941             const bool sliderPressed = ((optionSlider->state & State_Sunken) && (subControls & SC_ScrollBarSlider));
   929             const QS60StylePrivate::SkinElements handleElement =
   942             const QS60StylePrivate::SkinElements handleElement =
   930                 horizontal ?
   943                 horizontal ?
   931                     ( sliderPressed ?
   944                     ( sliderPressed ?
   932                         QS60StylePrivate::SE_ScrollBarHandlePressedHorizontal :
   945                         QS60StylePrivate::SE_ScrollBarHandlePressedHorizontal :
   933                         QS60StylePrivate::SE_ScrollBarHandleHorizontal ) :
   946                         QS60StylePrivate::SE_ScrollBarHandleHorizontal ) :
   944 
   957 
   945             const QRect sliderGroove = subControlRect(control, optionSlider, SC_SliderGroove, widget);
   958             const QRect sliderGroove = subControlRect(control, optionSlider, SC_SliderGroove, widget);
   946             const bool horizontal = optionSlider->orientation == Qt::Horizontal;
   959             const bool horizontal = optionSlider->orientation == Qt::Horizontal;
   947 
   960 
   948             //Highlight
   961             //Highlight
   949 /*            if (optionSlider->state & QStyle::State_HasFocus)
   962 /*            if (optionSlider->state & State_HasFocus)
   950                 drawPrimitive(PE_FrameFocusRect, optionSlider, painter, widget);*/
   963                 drawPrimitive(PE_FrameFocusRect, optionSlider, painter, widget);*/
   951             
   964 
   952             //Groove graphics
   965             //Groove graphics
   953             if (QS60StylePrivate::hasSliderGrooveGraphic()) {
   966             if (QS60StylePrivate::hasSliderGrooveGraphic()) {
   954                 const QS60StylePrivate::SkinElements grooveElement = horizontal ? 
   967                 const QS60StylePrivate::SkinElements grooveElement = horizontal ?
   955                     QS60StylePrivate::SE_SliderGrooveHorizontal : 
   968                     QS60StylePrivate::SE_SliderGrooveHorizontal :
   956                     QS60StylePrivate::SE_SliderGrooveVertical;
   969                     QS60StylePrivate::SE_SliderGrooveVertical;
   957                 QS60StylePrivate::drawSkinElement(grooveElement, painter, sliderGroove, flags);
   970                 QS60StylePrivate::drawSkinElement(grooveElement, painter, sliderGroove, flags);
   958             } else {
   971             } else {
   959                 const QRect sliderGroove = subControlRect(control, optionSlider, SC_SliderGroove, widget);
   972                 const QRect sliderGroove = subControlRect(control, optionSlider, SC_SliderGroove, widget);
   960                 const QPoint sliderGrooveCenter = sliderGroove.center();
   973                 const QPoint sliderGrooveCenter = sliderGroove.center();
   970             }
   983             }
   971 
   984 
   972             //Handle graphics
   985             //Handle graphics
   973             const QRect sliderHandle = subControlRect(control, optionSlider, SC_SliderHandle, widget);
   986             const QRect sliderHandle = subControlRect(control, optionSlider, SC_SliderHandle, widget);
   974             QS60StylePrivate::SkinElements handleElement;
   987             QS60StylePrivate::SkinElements handleElement;
   975             if (optionSlider->state & QStyle::State_Sunken)
   988             if (optionSlider->state & State_Sunken)
   976                 handleElement =
   989                 handleElement =
   977                         horizontal ? QS60StylePrivate::SE_SliderHandleSelectedHorizontal : QS60StylePrivate::SE_SliderHandleSelectedVertical;
   990                         horizontal ? QS60StylePrivate::SE_SliderHandleSelectedHorizontal : QS60StylePrivate::SE_SliderHandleSelectedVertical;
   978             else    
   991             else
   979                 handleElement =
   992                 handleElement =
   980                     horizontal ? QS60StylePrivate::SE_SliderHandleHorizontal : QS60StylePrivate::SE_SliderHandleVertical;
   993                     horizontal ? QS60StylePrivate::SE_SliderHandleHorizontal : QS60StylePrivate::SE_SliderHandleVertical;
   981             QS60StylePrivate::drawSkinElement(handleElement, painter, sliderHandle, flags);
   994             QS60StylePrivate::drawSkinElement(handleElement, painter, sliderHandle, flags);
   982         }
   995         }
   983         break;
   996         break;
   992             // Button frame
  1005             // Button frame
   993             QStyleOptionFrame  buttonOption;
  1006             QStyleOptionFrame  buttonOption;
   994             buttonOption.QStyleOption::operator=(*cmb);
  1007             buttonOption.QStyleOption::operator=(*cmb);
   995             const int maxHeight = cmbxFrame.height();
  1008             const int maxHeight = cmbxFrame.height();
   996             const int maxWidth = cmbxFrame.width() - cmbxEditField.width();
  1009             const int maxWidth = cmbxFrame.width() - cmbxEditField.width();
   997             const int topLeftPoint = direction ? 
  1010             const int topLeftPoint = direction ?
   998                 (cmbxEditField.right() + 1) : (cmbxEditField.left() + 1 - maxWidth);
  1011                 (cmbxEditField.right() + 1) : (cmbxEditField.left() + 1 - maxWidth);
   999             const QRect buttonRect(topLeftPoint, cmbxEditField.top(), maxWidth, maxHeight);
  1012             const QRect buttonRect(topLeftPoint, cmbxEditField.top(), maxWidth, maxHeight);
  1000             buttonOption.rect = buttonRect;
  1013             buttonOption.rect = buttonRect;
  1001             buttonOption.state = cmb->state;
  1014             buttonOption.state = cmb->state;
  1002             drawPrimitive(PE_PanelButtonCommand, &buttonOption, painter, widget);
  1015             drawPrimitive(PE_PanelButtonCommand, &buttonOption, painter, widget);
  1018         break;
  1031         break;
  1019 #endif // QT_NO_COMBOBOX
  1032 #endif // QT_NO_COMBOBOX
  1020 #ifndef QT_NO_TOOLBUTTON
  1033 #ifndef QT_NO_TOOLBUTTON
  1021     case CC_ToolButton:
  1034     case CC_ToolButton:
  1022         if (const QStyleOptionToolButton *toolBtn = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
  1035         if (const QStyleOptionToolButton *toolBtn = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
  1023             const State bflags = toolBtn->state;
  1036             State bflags = toolBtn->state & ~State_Sunken;
       
  1037 
       
  1038             if (bflags & State_AutoRaise) {
       
  1039                 if (!(bflags & State_MouseOver) || !(bflags & State_Enabled)) {
       
  1040                     bflags &= ~State_Raised;
       
  1041                 }
       
  1042             }
       
  1043             State mflags = bflags;
       
  1044             if (toolBtn->state & State_Sunken) {
       
  1045                 if (toolBtn->activeSubControls & SC_ToolButton)
       
  1046                     bflags |= State_Sunken;
       
  1047                 mflags |= State_Sunken;
       
  1048             }
       
  1049 
  1024             const QRect button(subControlRect(control, toolBtn, SC_ToolButton, widget));
  1050             const QRect button(subControlRect(control, toolBtn, SC_ToolButton, widget));
  1025             QRect menuRect = QRect();
  1051             QRect menuRect = QRect();
  1026             if (toolBtn->subControls & SC_ToolButtonMenu)
  1052             if (toolBtn->subControls & SC_ToolButtonMenu)
  1027                 menuRect = subControlRect(control, toolBtn, SC_ToolButtonMenu, widget);
  1053                 menuRect = subControlRect(control, toolBtn, SC_ToolButtonMenu, widget);
  1028 
  1054 
  1029             QStyleOptionToolButton toolButton = *toolBtn;
  1055             if (toolBtn->subControls & SC_ToolButton) {
  1030 
       
  1031             if (sub&SC_ToolButton) {
       
  1032                 QStyleOption tool(0);
  1056                 QStyleOption tool(0);
  1033                 tool.palette = toolBtn->palette;
  1057                 tool.palette = toolBtn->palette;
  1034 
  1058 
  1035                 // Check if toolbutton is in toolbar.
  1059                 if (bflags & (State_Sunken | State_On | State_Raised | State_Enabled)) {
  1036                 QToolBar *toolBar = 0;
       
  1037                 if (widget)
       
  1038                     toolBar = qobject_cast<QToolBar *>(widget->parentWidget());
       
  1039 
       
  1040                 if (bflags & (State_Sunken | State_On | State_Raised)) {
       
  1041                     tool.rect = button.unite(menuRect);
  1060                     tool.rect = button.unite(menuRect);
  1042                     tool.state = bflags;
  1061                     tool.state = bflags;
  1043 
  1062                     const QToolButton *toolButtonWidget = qobject_cast<const QToolButton *>(widget);
  1044                     // todo: I'd like to move extension button next to where last button is
  1063                     QS60StylePrivate::SkinElements element;
  1045                     // however, the painter seems to want to clip the button rect even if I turn of the clipping.
  1064                     if (toolButtonWidget)
  1046                     if (toolBar && (qobject_cast<const QToolBarExtension *>(widget))){
  1065                         element = (toolButtonWidget->isDown()) ? QS60StylePrivate::SE_ToolBarButtonPressed : QS60StylePrivate::SE_ToolBarButton;
  1047                         /*QList<QAction *> actionList = toolBar->actions();
  1066                     else
  1048                         const int actionCount = actionList.count();
  1067                         element = (option->state & State_Sunken) ? QS60StylePrivate::SE_ToolBarButtonPressed : QS60StylePrivate::SE_ToolBarButton;
  1049                         const int toolbarWidth = toolBar->width();
  1068                     QS60StylePrivate::drawSkinElement(element, painter, tool.rect, flags);
  1050                         const int extButtonWidth = pixelMetric(PM_ToolBarExtensionExtent, option, widget);
  1069                     drawPrimitive(PE_PanelButtonTool, &tool, painter, widget);
  1051                         const int toolBarButtonWidth = pixelMetric(PM_ToolBarIconSize, option, widget);
       
  1052                         const int frame = pixelMetric(PM_ToolBarFrameWidth, option, widget);
       
  1053                         const int margin = pixelMetric(PM_ToolBarItemMargin, option, widget);
       
  1054                         const int border = frame + margin;
       
  1055                         const int spacing = pixelMetric(PM_ToolBarItemSpacing, option, widget);
       
  1056                         const int toolBarButtonArea = toolbarWidth - extButtonWidth - spacing - 2*border;
       
  1057                         const int numberOfVisibleButtons = toolBarButtonArea / toolBarButtonWidth;
       
  1058                         // new extension button place is after border and all the other visible buttons (with spacings)
       
  1059                         const int newXForExtensionButton = numberOfVisibleButtons * toolBarButtonWidth + (numberOfVisibleButtons-1)*spacing + border;
       
  1060                         painter->save();
       
  1061                         painter->setClipping(false);
       
  1062                         tool.rect.translate(-newXForExtensionButton,0);
       
  1063                         painter->restore();*/
       
  1064                     }
       
  1065 
       
  1066                     if (toolBar){
       
  1067                         /*if (toolBar->orientation() == Qt::Vertical){
       
  1068                             // todo: I'd like to make all vertical buttons the same size, but again the painter
       
  1069                             // prefers to use clipping for button rects, even though clipping has been set off.
       
  1070                             painter->save();
       
  1071                             painter->setClipping(false);
       
  1072 
       
  1073                             const int origWidth = tool.rect.width();
       
  1074                             const int newWidth = toolBar->width()-2*pixelMetric(PM_ToolBarFrameWidth, option, widget);
       
  1075                             painter->translate(origWidth-newWidth,0);
       
  1076                             tool.rect.translate(origWidth-tool.rect.width(),0);
       
  1077                             tool.rect.setWidth(newWidth);
       
  1078 
       
  1079                             if (option->state & QStyle::State_Sunken)
       
  1080                                 QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ToolBarButtonPressed, painter, tool.rect, flags);
       
  1081                             else
       
  1082                                 QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ToolBarButton, painter, tool.rect, flags);
       
  1083 
       
  1084                         }*/
       
  1085                         if (option->state & QStyle::State_Sunken)
       
  1086                             QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ToolBarButtonPressed, painter, tool.rect, flags);
       
  1087                         else
       
  1088                             QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ToolBarButton, painter, tool.rect, flags);
       
  1089                         /*
       
  1090                         if (toolBar->orientation() == Qt::Vertical)
       
  1091                             painter->restore();
       
  1092                             */
       
  1093                     } else {
       
  1094                         drawPrimitive(PE_PanelButtonTool, &tool, painter, widget);
       
  1095                     }
       
  1096 
       
  1097                     if (toolButton.subControls & SC_ToolButtonMenu) {
       
  1098                         tool.rect = menuRect;
       
  1099                         tool.state = bflags;
       
  1100                         drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget);
       
  1101                     }
       
  1102                 }
  1070                 }
  1103             }
  1071                 if (toolBtn->subControls & SC_ToolButtonMenu) {
  1104 
  1072                     tool.rect = menuRect;
       
  1073                     tool.state = mflags;
       
  1074                     drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget);
       
  1075                 }
       
  1076             }
       
  1077             QStyleOptionToolButton toolButton = *toolBtn;
  1105             if (toolBtn->features & QStyleOptionToolButton::Arrow) {
  1078             if (toolBtn->features & QStyleOptionToolButton::Arrow) {
  1106                 QStyle::PrimitiveElement pe;
  1079                 PrimitiveElement pe;
  1107                 switch (toolBtn->arrowType) {
  1080                 switch (toolBtn->arrowType) {
  1108                     case Qt::LeftArrow:
  1081                     case Qt::LeftArrow:
  1109                         pe = QStyle::PE_IndicatorArrowLeft;
  1082                         pe = PE_IndicatorArrowLeft;
  1110                         break;
  1083                         break;
  1111                     case Qt::RightArrow:
  1084                     case Qt::RightArrow:
  1112                         pe = QStyle::PE_IndicatorArrowRight;
  1085                         pe = PE_IndicatorArrowRight;
  1113                         break;
  1086                         break;
  1114                     case Qt::UpArrow:
  1087                     case Qt::UpArrow:
  1115                         pe = QStyle::PE_IndicatorArrowUp;
  1088                         pe = PE_IndicatorArrowUp;
  1116                         break;
  1089                         break;
  1117                     case Qt::DownArrow:
  1090                     case Qt::DownArrow:
  1118                         pe = QStyle::PE_IndicatorArrowDown;
  1091                         pe = PE_IndicatorArrowDown;
  1119                         break;
  1092                         break;
  1120                     default:
  1093                     default:
  1121                         break; }
  1094                         break; }
  1122                 toolButton.rect = button;
  1095                 toolButton.rect = button;
  1123                 drawPrimitive(pe, &toolButton, painter, widget);
  1096                 drawPrimitive(pe, &toolButton, painter, widget);
  1197     case CC_GroupBox:
  1170     case CC_GroupBox:
  1198         if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
  1171         if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
  1199             // Draw frame
  1172             // Draw frame
  1200             const QRect textRect = subControlRect(CC_GroupBox, option, SC_GroupBoxLabel, widget);
  1173             const QRect textRect = subControlRect(CC_GroupBox, option, SC_GroupBoxLabel, widget);
  1201             const QRect checkBoxRect = subControlRect(CC_GroupBox, option, SC_GroupBoxCheckBox, widget);
  1174             const QRect checkBoxRect = subControlRect(CC_GroupBox, option, SC_GroupBoxCheckBox, widget);
  1202             if (groupBox->subControls & QStyle::SC_GroupBoxFrame) {
  1175             if (groupBox->subControls & SC_GroupBoxFrame) {
  1203                 QStyleOptionFrameV2 frame;
  1176                 QStyleOptionFrameV2 frame;
  1204                 frame.QStyleOption::operator=(*groupBox);
  1177                 frame.QStyleOption::operator=(*groupBox);
  1205                 frame.features = groupBox->features;
  1178                 frame.features = groupBox->features;
  1206                 frame.lineWidth = groupBox->lineWidth;
  1179                 frame.lineWidth = groupBox->lineWidth;
  1207                 frame.midLineWidth = groupBox->midLineWidth;
  1180                 frame.midLineWidth = groupBox->midLineWidth;
  1208                 frame.rect = subControlRect(CC_GroupBox, option, SC_GroupBoxFrame, widget);
  1181                 frame.rect = subControlRect(CC_GroupBox, option, SC_GroupBoxFrame, widget);
  1209                 drawPrimitive(PE_FrameGroupBox, &frame, painter, widget);
  1182                 drawPrimitive(PE_FrameGroupBox, &frame, painter, widget);
  1210             }
  1183             }
  1211 
  1184 
  1212             // Draw title
  1185             // Draw title
  1213             if ((groupBox->subControls & QStyle::SC_GroupBoxLabel) && !groupBox->text.isEmpty()) {
  1186             if ((groupBox->subControls & SC_GroupBoxLabel) && !groupBox->text.isEmpty()) {
  1214                 const QColor textColor = groupBox->textColor;
  1187                 const QColor textColor = groupBox->textColor;
  1215                 painter->save();
  1188                 painter->save();
  1216 
  1189 
  1217                 if (textColor.isValid())
  1190                 if (textColor.isValid())
  1218                     painter->setPen(textColor);
  1191                     painter->setPen(textColor);
  1219                 int alignment = int(groupBox->textAlignment);
  1192                 int alignment = int(groupBox->textAlignment);
  1220                 if (!styleHint(QStyle::SH_UnderlineShortcut, option, widget))
  1193                 if (!styleHint(SH_UnderlineShortcut, option, widget))
  1221                     alignment |= Qt::TextHideMnemonic;
  1194                     alignment |= Qt::TextHideMnemonic;
  1222 
  1195 
  1223                 drawItemText(painter, textRect,  Qt::TextShowMnemonic | Qt::AlignHCenter | Qt::AlignVCenter | alignment,
  1196                 drawItemText(painter, textRect,  Qt::TextShowMnemonic | Qt::AlignHCenter | Qt::AlignVCenter | alignment,
  1224                              groupBox->palette, groupBox->state & State_Enabled, groupBox->text,
  1197                              groupBox->palette, groupBox->state & State_Enabled, groupBox->text,
  1225                              textColor.isValid() ? QPalette::NoRole : QPalette::WindowText);
  1198                              textColor.isValid() ? QPalette::NoRole : QPalette::WindowText);
  1247 void QS60Style::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
  1220 void QS60Style::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
  1248 {
  1221 {
  1249     Q_D(const QS60Style);
  1222     Q_D(const QS60Style);
  1250     const QS60StylePrivate::SkinElementFlags flags = (option->state & State_Enabled) ?  QS60StylePrivate::SF_StateEnabled : QS60StylePrivate::SF_StateDisabled;
  1223     const QS60StylePrivate::SkinElementFlags flags = (option->state & State_Enabled) ?  QS60StylePrivate::SF_StateEnabled : QS60StylePrivate::SF_StateDisabled;
  1251     switch (element) {
  1224     switch (element) {
       
  1225         case CE_CheckBox:
       
  1226         case CE_RadioButton:
       
  1227             if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
       
  1228                 bool isRadio = (element == CE_RadioButton);
       
  1229                 // Highlight needs to be drawn first, as it goes "underneath" the text and indicator.
       
  1230                 if (btn->state & State_HasFocus) {
       
  1231                     QStyleOptionFocusRect fropt;
       
  1232                     fropt.QStyleOption::operator=(*btn);
       
  1233                     fropt.rect = subElementRect(isRadio ? SE_RadioButtonFocusRect
       
  1234                                                         : SE_CheckBoxFocusRect, btn, widget);
       
  1235                     drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
       
  1236                 }
       
  1237                 QStyleOptionButton subopt = *btn;
       
  1238 
       
  1239                 subopt.rect = subElementRect(isRadio ? SE_RadioButtonIndicator
       
  1240                                                      : SE_CheckBoxIndicator, btn, widget);
       
  1241                 drawPrimitive(isRadio ? PE_IndicatorRadioButton : PE_IndicatorCheckBox,
       
  1242                               &subopt, painter, widget);
       
  1243                 subopt.rect = subElementRect(isRadio ? SE_RadioButtonContents
       
  1244                                                      : SE_CheckBoxContents, btn, widget);
       
  1245 
       
  1246                 drawControl(isRadio ? CE_RadioButtonLabel : CE_CheckBoxLabel, &subopt, painter, widget);
       
  1247             }
       
  1248             break;
       
  1249 
  1252     case CE_PushButton:
  1250     case CE_PushButton:
  1253         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
  1251         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
  1254 
  1252 
  1255             drawControl(CE_PushButtonBevel, btn, painter, widget);
  1253             drawControl(CE_PushButtonBevel, btn, painter, widget);
  1256             QStyleOptionButton subopt = *btn;
  1254             QStyleOptionButton subopt = *btn;
  1259             drawControl(CE_PushButtonLabel, &subopt, painter, widget);
  1257             drawControl(CE_PushButtonLabel, &subopt, painter, widget);
  1260         }
  1258         }
  1261         break;
  1259         break;
  1262     case CE_PushButtonBevel:
  1260     case CE_PushButtonBevel:
  1263         if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
  1261         if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
  1264             const bool isDisabled = !(option->state & QStyle::State_Enabled);
  1262             const bool isDisabled = !(option->state & State_Enabled);
  1265             const bool isFlat = button->features & QStyleOptionButton::Flat;
  1263             const bool isFlat = button->features & QStyleOptionButton::Flat;
  1266             QS60StyleEnums::SkinParts skinPart;
  1264             QS60StyleEnums::SkinParts skinPart;
  1267             QS60StylePrivate::SkinElements skinElement;
  1265             QS60StylePrivate::SkinElements skinElement;
  1268             if (!isDisabled) {
  1266             if (!isDisabled) {
  1269                 const bool isPressed = (option->state & QStyle::State_Sunken) ||
  1267                 const bool isPressed = (option->state & State_Sunken) ||
  1270                                        (option->state & QStyle::State_On);
  1268                                        (option->state & State_On);
  1271                 if (isFlat) {
  1269                 if (isFlat) {
  1272                     skinPart =
  1270                     skinPart =
  1273                         isPressed ? QS60StyleEnums::SP_QsnFrButtonTbCenterPressed : QS60StyleEnums::SP_QsnFrButtonTbCenter;
  1271                         isPressed ? QS60StyleEnums::SP_QsnFrButtonTbCenterPressed : QS60StyleEnums::SP_QsnFrButtonTbCenter;
  1274                 } else {
  1272                 } else {
  1275                     skinElement =
  1273                     skinElement =
  1290 #ifndef QT_NO_TOOLBUTTON
  1288 #ifndef QT_NO_TOOLBUTTON
  1291     case CE_ToolButtonLabel:
  1289     case CE_ToolButtonLabel:
  1292         if (const QStyleOptionToolButton *toolBtn = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
  1290         if (const QStyleOptionToolButton *toolBtn = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
  1293             QStyleOptionToolButton optionToolButton = *toolBtn;
  1291             QStyleOptionToolButton optionToolButton = *toolBtn;
  1294 
  1292 
  1295             if (!optionToolButton.icon.isNull() && (optionToolButton.state & QStyle::State_Sunken)
  1293             if (!optionToolButton.icon.isNull() && (optionToolButton.state & State_Sunken)
  1296                     && (optionToolButton.state & State_Enabled)) {
  1294                     && (optionToolButton.state & State_Enabled)) {
  1297 
  1295 
  1298                     const QIcon::State state = optionToolButton.state & State_On ? QIcon::On : QIcon::Off;
  1296                     const QIcon::State state = optionToolButton.state & State_On ? QIcon::On : QIcon::Off;
  1299                     const QPixmap pm(optionToolButton.icon.pixmap(optionToolButton.rect.size().boundedTo(optionToolButton.iconSize),
  1297                     const QPixmap pm(optionToolButton.icon.pixmap(optionToolButton.rect.size().boundedTo(optionToolButton.iconSize),
  1300                             QIcon::Normal, state));
  1298                             QIcon::Normal, state));
  1349         if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(option)) {
  1347         if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(option)) {
  1350             QStyleOptionViewItemV4 voptAdj = *vopt;
  1348             QStyleOptionViewItemV4 voptAdj = *vopt;
  1351             painter->save();
  1349             painter->save();
  1352 
  1350 
  1353             painter->setClipRect(voptAdj.rect);
  1351             painter->setClipRect(voptAdj.rect);
  1354             const bool isSelected = (vopt->state & QStyle::State_Selected);
  1352             const bool isSelected = (vopt->state & State_Selected);
  1355             const bool hasFocus = (vopt->state & QStyle::State_HasFocus);
  1353             const bool hasFocus = (vopt->state & State_HasFocus);
  1356 
  1354 
  1357             bool isScrollBarVisible = false;
  1355             bool isScrollBarVisible = false;
  1358             int scrollBarWidth = 0;
  1356             int scrollBarWidth = 0;
  1359             QList<QScrollBar *> scrollBars = qFindChildren<QScrollBar *>(widget);
  1357             QList<QScrollBar *> scrollBars = qFindChildren<QScrollBar *>(widget);
  1360             for (int i = 0; i < scrollBars.size(); ++i) {
  1358             for (int i = 0; i < scrollBars.size(); ++i) {
  1424                 else
  1422                 else
  1425                     painter->fillRect(highlightRect, vopt->palette.highlight());
  1423                     painter->fillRect(highlightRect, vopt->palette.highlight());
  1426             }
  1424             }
  1427 
  1425 
  1428              // draw the icon
  1426              // draw the icon
  1429              const QIcon::Mode mode = (voptAdj.state & QStyle::State_Enabled) ? QIcon::Normal : QIcon::Disabled;
  1427              const QIcon::Mode mode = (voptAdj.state & State_Enabled) ? QIcon::Normal : QIcon::Disabled;
  1430              const QIcon::State state = voptAdj.state & QStyle::State_Open ? QIcon::On : QIcon::Off;
  1428              const QIcon::State state = voptAdj.state & State_Open ? QIcon::On : QIcon::Off;
  1431              voptAdj.icon.paint(painter, iconRect, voptAdj.decorationAlignment, mode, state);
  1429              voptAdj.icon.paint(painter, iconRect, voptAdj.decorationAlignment, mode, state);
  1432 
  1430 
  1433              // Draw selection check mark. Show check mark only in multi selection modes.
  1431              // Draw selection check mark. Show check mark only in multi selection modes.
  1434              if (itemView) {
  1432              if (itemView) {
  1435                  const bool singleSelection =
  1433                  const bool singleSelection =
  1437                       itemView->selectionMode() == QAbstractItemView::NoSelection);
  1435                       itemView->selectionMode() == QAbstractItemView::NoSelection);
  1438                  const QRect selectionRect = subElementRect(SE_ItemViewItemCheckIndicator, &voptAdj, widget);
  1436                  const QRect selectionRect = subElementRect(SE_ItemViewItemCheckIndicator, &voptAdj, widget);
  1439 
  1437 
  1440                  QStyleOptionViewItemV4 checkMarkOption(voptAdj);
  1438                  QStyleOptionViewItemV4 checkMarkOption(voptAdj);
  1441                  // Draw selection mark.
  1439                  // Draw selection mark.
  1442                  if (voptAdj.state & QStyle::State_Selected && !singleSelection) {
  1440                  if (voptAdj.state & State_Selected && !singleSelection) {
  1443                      checkMarkOption.rect = selectionRect;
  1441                      checkMarkOption.rect = selectionRect;
  1444                      drawPrimitive(QStyle::PE_IndicatorViewItemCheck, &checkMarkOption, painter, widget);
  1442                      drawPrimitive(PE_IndicatorViewItemCheck, &checkMarkOption, painter, widget);
  1445                      if ( textRect.right() > selectionRect.left() )
  1443                      if ( textRect.right() > selectionRect.left() )
  1446                          textRect.setRight(selectionRect.left());
  1444                          textRect.setRight(selectionRect.left());
  1447                  } else if (singleSelection &&
  1445                  } else if (singleSelection &&
  1448                      voptAdj.features & QStyleOptionViewItemV2::HasCheckIndicator &&
  1446                      voptAdj.features & QStyleOptionViewItemV2::HasCheckIndicator &&
  1449                      selectionRect.isValid()) {
  1447                      selectionRect.isValid()) {
  1450                      checkMarkOption.rect = selectionRect;
  1448                      checkMarkOption.rect = selectionRect;
  1451                      checkMarkOption.state = checkMarkOption.state & ~QStyle::State_HasFocus;
  1449                      checkMarkOption.state = checkMarkOption.state & ~State_HasFocus;
  1452 
  1450 
  1453                      switch (vopt->checkState) {
  1451                      switch (vopt->checkState) {
  1454                      case Qt::Unchecked:
  1452                      case Qt::Unchecked:
  1455                          checkMarkOption.state |= QStyle::State_Off;
  1453                          checkMarkOption.state |= State_Off;
  1456                          break;
  1454                          break;
  1457                      case Qt::PartiallyChecked:
  1455                      case Qt::PartiallyChecked:
  1458                          checkMarkOption.state |= QStyle::State_NoChange;
  1456                          checkMarkOption.state |= State_NoChange;
  1459                          break;
  1457                          break;
  1460                      case Qt::Checked:
  1458                      case Qt::Checked:
  1461                          checkMarkOption.state |= QStyle::State_On;
  1459                          checkMarkOption.state |= State_On;
  1462                          break;
  1460                          break;
  1463                      }
  1461                      }
  1464                      drawPrimitive(QStyle::PE_IndicatorViewItemCheck, &checkMarkOption, painter, widget);
  1462                      drawPrimitive(PE_IndicatorViewItemCheck, &checkMarkOption, painter, widget);
  1465                  }
  1463                  }
  1466              }
  1464              }
  1467 
  1465 
  1468              // draw the text
  1466              // draw the text
  1469             if (!voptAdj.text.isEmpty()) {
  1467             if (!voptAdj.text.isEmpty()) {
  1484 #endif // QT_NO_ITEMVIEWS
  1482 #endif // QT_NO_ITEMVIEWS
  1485 #ifndef QT_NO_TABBAR
  1483 #ifndef QT_NO_TABBAR
  1486     case CE_TabBarTabShape:
  1484     case CE_TabBarTabShape:
  1487         if (const QStyleOptionTabV3 *optionTab = qstyleoption_cast<const QStyleOptionTabV3 *>(option)) {
  1485         if (const QStyleOptionTabV3 *optionTab = qstyleoption_cast<const QStyleOptionTabV3 *>(option)) {
  1488             QStyleOptionTabV3 optionTabAdj = *optionTab;
  1486             QStyleOptionTabV3 optionTabAdj = *optionTab;
  1489             const bool isSelected = optionTab->state & QStyle::State_Selected;
  1487             const bool isSelected = optionTab->state & State_Selected;
  1490             const bool directionMirrored = (optionTab->direction == Qt::RightToLeft);
  1488             const bool directionMirrored = (optionTab->direction == Qt::RightToLeft);
  1491             QS60StylePrivate::SkinElements skinElement;
  1489             QS60StylePrivate::SkinElements skinElement;
  1492             switch (optionTab->shape) {
  1490             switch (optionTab->shape) {
  1493                 case QTabBar::TriangularEast:
  1491                 case QTabBar::TriangularEast:
  1494                 case QTabBar::RoundedEast:
  1492                 case QTabBar::RoundedEast:
  1519                     skinElement==QS60StylePrivate::SE_TabBarTabEastActive||
  1517                     skinElement==QS60StylePrivate::SE_TabBarTabEastActive||
  1520                     skinElement==QS60StylePrivate::SE_TabBarTabNorthActive||
  1518                     skinElement==QS60StylePrivate::SE_TabBarTabNorthActive||
  1521                     skinElement==QS60StylePrivate::SE_TabBarTabSouthActive||
  1519                     skinElement==QS60StylePrivate::SE_TabBarTabSouthActive||
  1522                     skinElement==QS60StylePrivate::SE_TabBarTabWestActive) {
  1520                     skinElement==QS60StylePrivate::SE_TabBarTabWestActive) {
  1523                 const int borderThickness =
  1521                 const int borderThickness =
  1524                     QS60StylePrivate::pixelMetric(QStyle::PM_DefaultFrameWidth);
  1522                     QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth);
  1525                 const int tabOverlap =
  1523                 const int tabOverlap =
  1526                     QS60StylePrivate::pixelMetric(QStyle::PM_TabBarTabOverlap) - borderThickness;
  1524                     QS60StylePrivate::pixelMetric(PM_TabBarTabOverlap) - borderThickness;
  1527                 //todo: draw navi wipe behind tabbar - must be drawn with first draw
  1525                 //todo: draw navi wipe behind tabbar - must be drawn with first draw
  1528 
  1526 
  1529                 if (skinElement==QS60StylePrivate::SE_TabBarTabEastInactive||
  1527                 if (skinElement==QS60StylePrivate::SE_TabBarTabEastInactive||
  1530                         skinElement==QS60StylePrivate::SE_TabBarTabEastActive||
  1528                         skinElement==QS60StylePrivate::SE_TabBarTabEastActive||
  1531                         skinElement==QS60StylePrivate::SE_TabBarTabWestInactive||
  1529                         skinElement==QS60StylePrivate::SE_TabBarTabWestInactive||
  1544     case CE_TabBarTabLabel:
  1542     case CE_TabBarTabLabel:
  1545         if (const QStyleOptionTabV3 *tab = qstyleoption_cast<const QStyleOptionTabV3 *>(option)) {
  1543         if (const QStyleOptionTabV3 *tab = qstyleoption_cast<const QStyleOptionTabV3 *>(option)) {
  1546             QStyleOptionTabV3 optionTab = *tab;
  1544             QStyleOptionTabV3 optionTab = *tab;
  1547             QRect tr = optionTab.rect;
  1545             QRect tr = optionTab.rect;
  1548             const bool directionMirrored = (optionTab.direction == Qt::RightToLeft);
  1546             const bool directionMirrored = (optionTab.direction == Qt::RightToLeft);
  1549             const int borderThickness = QS60StylePrivate::pixelMetric(QStyle::PM_DefaultFrameWidth);
  1547             const int borderThickness = QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth);
  1550             const int tabOverlap =
  1548             const int tabOverlap =
  1551                 QS60StylePrivate::pixelMetric(QStyle::PM_TabBarTabOverlap) - borderThickness;
  1549                 QS60StylePrivate::pixelMetric(PM_TabBarTabOverlap) - borderThickness;
  1552             const QRect windowRect = painter->window();
  1550             const QRect windowRect = painter->window();
  1553 
  1551 
  1554             switch (tab->shape) {
  1552             switch (tab->shape) {
  1555                 case QTabBar::TriangularWest:
  1553                 case QTabBar::TriangularWest:
  1556                 case QTabBar::RoundedWest:
  1554                 case QTabBar::RoundedWest:
  1600                 QTransform m;
  1598                 QTransform m;
  1601                 m.translate(newX, newY);
  1599                 m.translate(newX, newY);
  1602                 m.rotate(newRotation);
  1600                 m.rotate(newRotation);
  1603                 painter->setTransform(m, true);
  1601                 painter->setTransform(m, true);
  1604             }
  1602             }
  1605             tr.adjust(0, 0, pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, tab, widget),
  1603             tr.adjust(0, 0, pixelMetric(PM_TabBarTabShiftHorizontal, tab, widget),
  1606                             pixelMetric(QStyle::PM_TabBarTabShiftVertical, tab, widget));
  1604                             pixelMetric(PM_TabBarTabShiftVertical, tab, widget));
  1607 
  1605 
  1608             if (selected) {
  1606             if (selected) {
  1609                 tr.setBottom(tr.bottom() - pixelMetric(QStyle::PM_TabBarTabShiftVertical, tab, widget));
  1607                 tr.setBottom(tr.bottom() - pixelMetric(PM_TabBarTabShiftVertical, tab, widget));
  1610                 tr.setRight(tr.right() - pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, tab, widget));
  1608                 tr.setRight(tr.right() - pixelMetric(PM_TabBarTabShiftHorizontal, tab, widget));
  1611             }
  1609             }
  1612 
  1610 
  1613             int alignment = Qt::AlignCenter | Qt::TextShowMnemonic;
  1611             int alignment = Qt::AlignCenter | Qt::TextShowMnemonic;
  1614             if (!styleHint(SH_UnderlineShortcut, &optionTab, widget))
  1612             if (!styleHint(SH_UnderlineShortcut, &optionTab, widget))
  1615                 alignment |= Qt::TextHideMnemonic;
  1613                 alignment |= Qt::TextHideMnemonic;
  1646 
  1644 
  1647             if (optionProgressBar->minimum == optionProgressBar->maximum && optionProgressBar->minimum == 0) {
  1645             if (optionProgressBar->minimum == optionProgressBar->maximum && optionProgressBar->minimum == 0) {
  1648                 // busy indicator
  1646                 // busy indicator
  1649                 const QS60StylePrivate::SkinElementFlag orientationFlag = optionProgressBar->orientation == Qt::Horizontal ?
  1647                 const QS60StylePrivate::SkinElementFlag orientationFlag = optionProgressBar->orientation == Qt::Horizontal ?
  1650                     QS60StylePrivate::SF_PointNorth : QS60StylePrivate::SF_PointWest;
  1648                     QS60StylePrivate::SF_PointNorth : QS60StylePrivate::SF_PointWest;
  1651                 QS60StylePrivate::drawSkinPart(QS60StyleEnums::SP_QgnGrafBarWait, painter, progressRect, flags | orientationFlag);
  1649 
       
  1650                 QS60StylePrivate::drawSkinPart(QS60StyleEnums::SP_QgnGrafBarWaitAnim,
       
  1651                         painter, progressRect, flags | orientationFlag | QS60StylePrivate::SF_Animation );
  1652             } else {
  1652             } else {
  1653                 const qreal progressFactor = (optionProgressBar->minimum == optionProgressBar->maximum) ? 1.0
  1653                 const qreal progressFactor = (optionProgressBar->minimum == optionProgressBar->maximum) ? 1.0
  1654                     : (qreal)optionProgressBar->progress / optionProgressBar->maximum;
  1654                     : (qreal)optionProgressBar->progress / optionProgressBar->maximum;
       
  1655                 const int frameWidth = pixelMetric(PM_DefaultFrameWidth, option, widget);
  1655                 if (optionProgressBar->orientation == Qt::Horizontal) {
  1656                 if (optionProgressBar->orientation == Qt::Horizontal) {
  1656                     progressRect.setWidth(int(progressRect.width() * progressFactor));
  1657                     progressRect.setWidth(int(progressRect.width() * progressFactor));
  1657                     if(optionProgressBar->direction == Qt::RightToLeft)
  1658                     if(optionProgressBar->direction == Qt::RightToLeft)
  1658                         progressRect.translate(optionProgressBar->rect.width()-progressRect.width(), 0);
  1659                         progressRect.translate(optionProgressBar->rect.width() - progressRect.width(), 0);
  1659                     progressRect.adjust(1, 0, -1, 0);
  1660                     progressRect.adjust(frameWidth, 0, -frameWidth, 0);
  1660                 } else {
  1661                 } else {
  1661                     progressRect.adjust(0, 1, 0, -1);
  1662                     progressRect.adjust(0, frameWidth, 0, -frameWidth);
  1662                     progressRect.setTop(progressRect.bottom() - int(progressRect.height() * progressFactor));
  1663                     progressRect.setTop(progressRect.bottom() - int(progressRect.height() * progressFactor));
  1663                 }
  1664                 }
  1664 
  1665 
  1665                 const QS60StylePrivate::SkinElements skinElement = optionProgressBar->orientation == Qt::Horizontal ?
  1666                 const QS60StylePrivate::SkinElements skinElement = optionProgressBar->orientation == Qt::Horizontal ?
  1666                     QS60StylePrivate::SE_ProgressBarIndicatorHorizontal : QS60StylePrivate::SE_ProgressBarIndicatorVertical;
  1667                     QS60StylePrivate::SE_ProgressBarIndicatorHorizontal : QS60StylePrivate::SE_ProgressBarIndicatorVertical;
  1712 
  1713 
  1713             QRect iconRect = subElementRect(SE_ItemViewItemDecoration, &optionMenuItem, widget);
  1714             QRect iconRect = subElementRect(SE_ItemViewItemDecoration, &optionMenuItem, widget);
  1714             QRect textRect = subElementRect(SE_ItemViewItemText, &optionMenuItem, widget);
  1715             QRect textRect = subElementRect(SE_ItemViewItemText, &optionMenuItem, widget);
  1715 
  1716 
  1716             //todo: move the vertical spacing stuff into subElementRect
  1717             //todo: move the vertical spacing stuff into subElementRect
  1717             const int vSpacing = QS60StylePrivate::pixelMetric(QStyle::PM_LayoutVerticalSpacing);
  1718             const int vSpacing = QS60StylePrivate::pixelMetric(PM_LayoutVerticalSpacing);
  1718             if (checkable){
  1719             if (checkable){
  1719                 const int hSpacing = QS60StylePrivate::pixelMetric(QStyle::PM_LayoutHorizontalSpacing);
  1720                 const int hSpacing = QS60StylePrivate::pixelMetric(PM_LayoutHorizontalSpacing);
  1720                 QStyleOptionMenuItem optionCheckBox;
  1721                 QStyleOptionMenuItem optionCheckBox;
  1721                 optionCheckBox.QStyleOptionMenuItem::operator=(*menuItem);
  1722                 optionCheckBox.QStyleOptionMenuItem::operator=(*menuItem);
  1722                 optionCheckBox.rect.setWidth(pixelMetric(PM_IndicatorWidth));
  1723                 optionCheckBox.rect.setWidth(pixelMetric(PM_IndicatorWidth));
  1723                 optionCheckBox.rect.setHeight(pixelMetric(PM_IndicatorHeight));
  1724                 optionCheckBox.rect.setHeight(pixelMetric(PM_IndicatorHeight));
  1724                 const int moveByX = optionCheckBox.rect.width() + vSpacing;
  1725                 const int moveByX = optionCheckBox.rect.width() + vSpacing;
  1752             //draw indicators
  1753             //draw indicators
  1753             if (drawSubMenuIndicator) {
  1754             if (drawSubMenuIndicator) {
  1754                 QStyleOptionMenuItem arrowOptions;
  1755                 QStyleOptionMenuItem arrowOptions;
  1755                 arrowOptions.QStyleOption::operator=(*menuItem);
  1756                 arrowOptions.QStyleOption::operator=(*menuItem);
  1756                 const int indicatorWidth = (pixelMetric(PM_ListViewIconSize, option, widget) >> 1) +
  1757                 const int indicatorWidth = (pixelMetric(PM_ListViewIconSize, option, widget) >> 1) +
  1757                     pixelMetric(QStyle::PM_LayoutVerticalSpacing, option, widget);
  1758                     pixelMetric(PM_LayoutVerticalSpacing, option, widget);
  1758                 if (optionMenuItem.direction == Qt::LeftToRight)
  1759                 if (optionMenuItem.direction == Qt::LeftToRight)
  1759                     arrowOptions.rect.setLeft(textRect.right());
  1760                     arrowOptions.rect.setLeft(textRect.right());
  1760                 arrowOptions.rect.setWidth(indicatorWidth);
  1761                 arrowOptions.rect.setWidth(indicatorWidth);
  1761                 //by default sub menu indicator in S60 points to east,so here icon
  1762                 //by default sub menu indicator in S60 points to east,so here icon
  1762                 // direction is set to north (and south when in RightToLeft)
  1763                 // direction is set to north (and south when in RightToLeft)
  1923             QCommonStyle::drawControl(element, option, painter, widget);
  1924             QCommonStyle::drawControl(element, option, painter, widget);
  1924         }
  1925         }
  1925         break;
  1926         break;
  1926     case CE_MenuScroller:
  1927     case CE_MenuScroller:
  1927         break;
  1928         break;
  1928     case CE_FocusFrame:
  1929     case CE_FocusFrame: {
  1929         {
       
  1930             // The pen width should nearly fill the layoutspacings around the widget
  1930             // The pen width should nearly fill the layoutspacings around the widget
  1931             const int penWidth =
  1931             const int penWidth =
  1932                 qMin(pixelMetric(QS60Style::PM_LayoutVerticalSpacing), pixelMetric(QS60Style::PM_LayoutHorizontalSpacing))
  1932                 qMin(pixelMetric(QS60Style::PM_LayoutVerticalSpacing), pixelMetric(QS60Style::PM_LayoutHorizontalSpacing))
  1933                 - 2; // But keep 1 pixel distance to the focus widget and 1 pixel to the adjacent widgets
  1933                 - 2; // But keep 1 pixel distance to the focus widget and 1 pixel to the adjacent widgets
  1934 
  1934 
  1983 /*!
  1983 /*!
  1984   \reimp
  1984   \reimp
  1985 */
  1985 */
  1986 void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
  1986 void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
  1987 {
  1987 {
  1988     Q_D(const QS60Style);
       
  1989     const QS60StylePrivate::SkinElementFlags flags = (option->state & State_Enabled) ?  QS60StylePrivate::SF_StateEnabled : QS60StylePrivate::SF_StateDisabled;
  1988     const QS60StylePrivate::SkinElementFlags flags = (option->state & State_Enabled) ?  QS60StylePrivate::SF_StateEnabled : QS60StylePrivate::SF_StateDisabled;
  1990     bool commonStyleDraws = false;
  1989     bool commonStyleDraws = false;
  1991 
  1990 
  1992     switch (element) {
  1991     switch (element) {
       
  1992         case PE_FrameFocusRect: {
       
  1993             //Draw themed highlight to radiobuttons and checkboxes.
       
  1994             //For other widgets skip, unless palette has been modified. In that case, draw with commonstyle.
       
  1995             if (option->palette.highlight().color() == QS60StylePrivate::themePalette()->highlight().color())
       
  1996                 if ((qstyleoption_cast<const QStyleOptionFocusRect *>(option) &&
       
  1997                     (qobject_cast<const QRadioButton *>(widget) || qobject_cast<const QCheckBox *>(widget))))
       
  1998                         QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ListHighlight, painter, option->rect, flags);
       
  1999             else
       
  2000                 commonStyleDraws = true;
       
  2001             }
       
  2002         break;
  1993 #ifndef QT_NO_LINEEDIT
  2003 #ifndef QT_NO_LINEEDIT
  1994     case PE_PanelLineEdit:
  2004     case PE_PanelLineEdit:
  1995         if (const QStyleOptionFrame *lineEdit = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
  2005         if (const QStyleOptionFrame *lineEdit = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
  1996 #ifndef QT_NO_COMBOBOX
  2006 #ifndef QT_NO_COMBOBOX
  1997             if (widget && qobject_cast<const QComboBox *>(widget->parentWidget()))
  2007             if (widget && qobject_cast<const QComboBox *>(widget->parentWidget()))
  2002             else
  2012             else
  2003                 commonStyleDraws = true;
  2013                 commonStyleDraws = true;
  2004         }
  2014         }
  2005     break;
  2015     break;
  2006 #endif // QT_NO_LINEEDIT
  2016 #endif // QT_NO_LINEEDIT
  2007     case PE_IndicatorCheckBox:
  2017     case PE_IndicatorCheckBox: {
  2008         {
       
  2009             // Draw checkbox indicator as color skinned graphics.
  2018             // Draw checkbox indicator as color skinned graphics.
  2010             const QS60StyleEnums::SkinParts skinPart = (option->state & QStyle::State_On) ?
  2019             const QS60StyleEnums::SkinParts skinPart = (option->state & State_On) ?
  2011                 QS60StyleEnums::SP_QgnIndiCheckboxOn : QS60StyleEnums::SP_QgnIndiCheckboxOff;
  2020                 QS60StyleEnums::SP_QgnIndiCheckboxOn : QS60StyleEnums::SP_QgnIndiCheckboxOff;
  2012             painter->save();
  2021             painter->save();
  2013 
  2022 
  2014             QColor themeColor = QS60StylePrivate::themePalette()->windowText().color();
  2023             const QColor themeColor = QS60StylePrivate::themePalette()->windowText().color();
  2015             QColor windowTextColor = option->palette.windowText().color();
  2024             const QColor windowTextColor = option->palette.windowText().color();
  2016 
  2025 
  2017             if (themeColor != windowTextColor)
  2026             if (themeColor != windowTextColor)
  2018                 painter->setPen(windowTextColor);
  2027                 painter->setPen(windowTextColor);
  2019 
  2028 
  2020             QS60StylePrivate::drawSkinPart(skinPart, painter, option->rect, flags | QS60StylePrivate::SF_ColorSkinned );
  2029             QS60StylePrivate::drawSkinPart(skinPart, painter, option->rect, flags | QS60StylePrivate::SF_ColorSkinned );
  2030                     QAbstractItemView::SingleSelection || listItem->selectionMode() == QAbstractItemView::NoSelection;
  2039                     QAbstractItemView::SingleSelection || listItem->selectionMode() == QAbstractItemView::NoSelection;
  2031                 // draw either checkbox at the beginning
  2040                 // draw either checkbox at the beginning
  2032                 if (checkBoxVisible && singleSelection) {
  2041                 if (checkBoxVisible && singleSelection) {
  2033                     drawPrimitive(PE_IndicatorCheckBox, option, painter, widget);
  2042                     drawPrimitive(PE_IndicatorCheckBox, option, painter, widget);
  2034                 // ... or normal "tick" selection at the end.
  2043                 // ... or normal "tick" selection at the end.
  2035                 } else if (option->state & QStyle::State_Selected) {
  2044                 } else if (option->state & State_Selected) {
  2036                     QRect tickRect = option->rect;
  2045                     QRect tickRect = option->rect;
  2037                     const int frameBorderWidth = QS60StylePrivate::pixelMetric(PM_Custom_FrameCornerWidth);
  2046                     const int frameBorderWidth = QS60StylePrivate::pixelMetric(PM_Custom_FrameCornerWidth);
  2038                     // adjust tickmark rect to exclude frame border
  2047                     // adjust tickmark rect to exclude frame border
  2039                     tickRect.adjust(0, -frameBorderWidth, 0, -frameBorderWidth);
  2048                     tickRect.adjust(0, -frameBorderWidth, 0, -frameBorderWidth);
  2040                     QS60StyleEnums::SkinParts skinPart = QS60StyleEnums::SP_QgnIndiMarkedAdd;
  2049                     QS60StyleEnums::SkinParts skinPart = QS60StyleEnums::SP_QgnIndiMarkedAdd;
  2057             // move the rect up for half of the new height-gain
  2066             // move the rect up for half of the new height-gain
  2058             const int newY = (buttonRect.bottomRight().y() - option->rect.bottomRight().y()) >> 1 ;
  2067             const int newY = (buttonRect.bottomRight().y() - option->rect.bottomRight().y()) >> 1 ;
  2059             buttonRect.adjust(0, -newY, -1, -newY);
  2068             buttonRect.adjust(0, -newY, -1, -newY);
  2060 
  2069 
  2061             painter->save();
  2070             painter->save();
  2062             QColor themeColor = d->s60Color(QS60StyleEnums::CL_QsnTextColors, 6, option);
  2071             const QColor themeColor = QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnTextColors, 6, option);
  2063             QColor buttonTextColor = option->palette.buttonText().color();
  2072             const QColor buttonTextColor = option->palette.buttonText().color();
  2064             if (themeColor != buttonTextColor)
  2073             if (themeColor != buttonTextColor)
  2065                 painter->setPen(buttonTextColor);
  2074                 painter->setPen(buttonTextColor);
  2066             else
  2075             else
  2067                 painter->setPen(themeColor);
  2076                 painter->setPen(themeColor);
  2068 
  2077 
  2069             // Draw radiobutton indicator as color skinned graphics.
  2078             // Draw radiobutton indicator as color skinned graphics.
  2070             QS60StyleEnums::SkinParts skinPart = (option->state & QStyle::State_On) ?
  2079             QS60StyleEnums::SkinParts skinPart = (option->state & State_On) ?
  2071                 QS60StyleEnums::SP_QgnIndiRadiobuttOn : QS60StyleEnums::SP_QgnIndiRadiobuttOff;
  2080                 QS60StyleEnums::SP_QgnIndiRadiobuttOn : QS60StyleEnums::SP_QgnIndiRadiobuttOff;
  2072             QS60StylePrivate::drawSkinPart(skinPart, painter, buttonRect,
  2081             QS60StylePrivate::drawSkinPart(skinPart, painter, buttonRect,
  2073                 (flags | QS60StylePrivate::SF_ColorSkinned));
  2082                 (flags | QS60StylePrivate::SF_ColorSkinned));
  2074             painter->restore();
  2083             painter->restore();
  2075         }
  2084         }
  2076         break;
  2085         break;
  2077     case PE_PanelButtonCommand:
  2086     case PE_PanelButtonCommand:
  2078     case PE_PanelButtonTool:
  2087     case PE_PanelButtonTool:
  2079     case PE_PanelButtonBevel:
  2088     case PE_PanelButtonBevel:
  2080     case PE_FrameButtonBevel: {
  2089     case PE_FrameButtonBevel:
  2081         if (QS60StylePrivate::canDrawThemeBackground(option->palette.base())) {
  2090         if (QS60StylePrivate::canDrawThemeBackground(option->palette.base())) {
  2082             const bool isPressed = option->state & QStyle::State_Sunken;
  2091             const bool isPressed = option->state & State_Sunken;
  2083             const QS60StylePrivate::SkinElements skinElement =
  2092             const QS60StylePrivate::SkinElements skinElement =
  2084                 isPressed ? QS60StylePrivate::SE_ButtonPressed : QS60StylePrivate::SE_ButtonNormal;
  2093                 isPressed ? QS60StylePrivate::SE_ButtonPressed : QS60StylePrivate::SE_ButtonNormal;
  2085             QS60StylePrivate::drawSkinElement(skinElement, painter, option->rect, flags);
  2094             QS60StylePrivate::drawSkinElement(skinElement, painter, option->rect, flags);
  2086         } else {
  2095         } else {
  2087             commonStyleDraws = true;
  2096             commonStyleDraws = true;
  2088             }
       
  2089         }
  2097         }
  2090         break;
  2098         break;
  2091 #ifndef QT_NO_TOOLBUTTON
  2099 #ifndef QT_NO_TOOLBUTTON
  2092     case PE_IndicatorArrowDown:
  2100     case PE_IndicatorArrowDown:
  2093     case PE_IndicatorArrowLeft:
  2101     case PE_IndicatorArrowLeft:
  2205         break;
  2213         break;
  2206     case PE_Frame:
  2214     case PE_Frame:
  2207         break;
  2215         break;
  2208 #ifndef QT_NO_ITEMVIEWS
  2216 #ifndef QT_NO_ITEMVIEWS
  2209     case PE_PanelItemViewItem:
  2217     case PE_PanelItemViewItem:
  2210     case PE_PanelItemViewRow: // ### Qt 5: remove
       
  2211         break;
  2218         break;
  2212 #endif //QT_NO_ITEMVIEWS
  2219 #endif //QT_NO_ITEMVIEWS
  2213 
  2220 
  2214     case PE_IndicatorMenuCheckMark:
  2221     case PE_IndicatorMenuCheckMark:
  2215         if (const QStyleOptionMenuItem *checkBox = qstyleoption_cast<const QStyleOptionMenuItem *>(option)){
  2222         if (const QStyleOptionMenuItem *checkBox = qstyleoption_cast<const QStyleOptionMenuItem *>(option)){
  2274                 iconRect.translate(3, verticalMagic - resizeValue);
  2281                 iconRect.translate(3, verticalMagic - resizeValue);
  2275                 QS60StylePrivate::drawSkinPart(skinPart, painter, iconRect, flags);
  2282                 QS60StylePrivate::drawSkinPart(skinPart, painter, iconRect, flags);
  2276             }
  2283             }
  2277         }
  2284         }
  2278         break;
  2285         break;
  2279 
  2286     case PE_PanelItemViewRow: // ### Qt 5: remove
       
  2287 #ifndef QT_NO_ITEMVIEWS
       
  2288         if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(option)) {
       
  2289             if (vopt->palette.base().texture().cacheKey() != QS60StylePrivate::m_themePalette->base().texture().cacheKey()) {
       
  2290                 //QPalette::Base has been changed, let commonstyle draw the item
       
  2291                 commonStyleDraws = true;
       
  2292             } else {
       
  2293                 QPalette::ColorGroup cg = vopt->state & State_Enabled ? QPalette::Normal : QPalette::Disabled;
       
  2294                 if (cg == QPalette::Normal && !(vopt->state & State_Active))
       
  2295                     cg = QPalette::Inactive;
       
  2296                 if (vopt->features & QStyleOptionViewItemV2::Alternate)
       
  2297                     painter->fillRect(vopt->rect, vopt->palette.brush(cg, QPalette::AlternateBase));
       
  2298                 //apart from alternate base, no background for list item is drawn for S60Style
       
  2299             }
       
  2300         }
       
  2301 #endif
       
  2302         break;
  2280     case PE_PanelScrollAreaCorner:
  2303     case PE_PanelScrollAreaCorner:
  2281         break;
  2304         break;
  2282 
  2305 
  2283         // todo: items are below with #ifdefs "just in case". in final version, remove all non-required cases
  2306         // todo: items are below with #ifdefs "just in case". in final version, remove all non-required cases
  2284     case PE_FrameLineEdit:
  2307     case PE_FrameLineEdit:
  2359             break;
  2382             break;
  2360         case CT_LineEdit:
  2383         case CT_LineEdit:
  2361             if (const QStyleOptionFrame *f = qstyleoption_cast<const QStyleOptionFrame *>(opt))
  2384             if (const QStyleOptionFrame *f = qstyleoption_cast<const QStyleOptionFrame *>(opt))
  2362                 sz += QSize(2 * f->lineWidth, 4 * f->lineWidth);
  2385                 sz += QSize(2 * f->lineWidth, 4 * f->lineWidth);
  2363             break;
  2386             break;
  2364         case CT_TabBarTab:
  2387         case CT_TabBarTab: {
  2365             {
       
  2366                 const QSize naviPaneSize = QS60StylePrivate::naviPaneSize();
  2388                 const QSize naviPaneSize = QS60StylePrivate::naviPaneSize();
  2367                 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
  2389                 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
  2368                 if (naviPaneSize.height() > sz.height())
  2390                 if (naviPaneSize.height() > sz.height())
  2369                     sz.setHeight(naviPaneSize.height());
  2391                     sz.setHeight(naviPaneSize.height());
  2370             }
  2392             }
  2372         case CT_ItemViewItem:
  2394         case CT_ItemViewItem:
  2373             sz = QCommonStyle::sizeFromContents( ct, opt, csz, widget);
  2395             sz = QCommonStyle::sizeFromContents( ct, opt, csz, widget);
  2374             if (QS60StylePrivate::isTouchSupported())
  2396             if (QS60StylePrivate::isTouchSupported())
  2375                 //Make itemview easier to use in touch devices
  2397                 //Make itemview easier to use in touch devices
  2376                 //QCommonStyle does not adjust height with horizontal margin, it only adjusts width
  2398                 //QCommonStyle does not adjust height with horizontal margin, it only adjusts width
  2377                 sz.setHeight(sz.height() + 2 * pixelMetric(QStyle::PM_FocusFrameVMargin));
  2399                 sz.setHeight(sz.height() + 2 * pixelMetric(PM_FocusFrameVMargin));
  2378             break;
  2400             break;
       
  2401 #ifndef QT_NO_COMBOBOX
       
  2402         case CT_ComboBox: {
       
  2403                 // Fixing Ui design issues with too wide QComboBoxes and greedy SizeHints
       
  2404                 // Make sure, that the combobox says within the screen.
       
  2405                 const QSize desktopContentSize = QApplication::desktop()->availableGeometry().size()
       
  2406                         -QSize(pixelMetric(PM_LayoutLeftMargin) + pixelMetric(PM_LayoutRightMargin), 0);
       
  2407                 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget).
       
  2408                         boundedTo(desktopContentSize);
       
  2409             }
       
  2410             break;
       
  2411 #endif
  2379         default:
  2412         default:
  2380             sz = QCommonStyle::sizeFromContents( ct, opt, csz, widget);
  2413             sz = QCommonStyle::sizeFromContents( ct, opt, csz, widget);
  2381             break;
  2414             break;
  2382     }
  2415     }
  2383     return sz;
  2416     return sz;
  2412             break;
  2445             break;
  2413         case SH_Dial_BackgroundRole:
  2446         case SH_Dial_BackgroundRole:
  2414             retValue = QPalette::Base;
  2447             retValue = QPalette::Base;
  2415             break;
  2448             break;
  2416         case SH_ItemView_ActivateItemOnSingleClick:
  2449         case SH_ItemView_ActivateItemOnSingleClick:
  2417             retValue = true;
  2450             retValue = QS60StylePrivate::isSingleClickUi();
  2418             break;
  2451             break;
  2419         case SH_ProgressDialog_TextLabelAlignment:
  2452         case SH_ProgressDialog_TextLabelAlignment:
  2420             retValue = (QApplication::layoutDirection() == Qt::LeftToRight) ?
  2453             retValue = (QApplication::layoutDirection() == Qt::LeftToRight) ?
  2421                 Qt::AlignLeft :
  2454                 Qt::AlignLeft :
  2422                 Qt::AlignRight;
  2455                 Qt::AlignRight;
  2524 #endif // QT_NO_SCROLLBAR
  2557 #endif // QT_NO_SCROLLBAR
  2525     case CC_SpinBox:
  2558     case CC_SpinBox:
  2526         if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
  2559         if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
  2527             const int frameThickness = spinbox->frame ? pixelMetric(PM_SpinBoxFrameWidth, spinbox, widget) : 0;
  2560             const int frameThickness = spinbox->frame ? pixelMetric(PM_SpinBoxFrameWidth, spinbox, widget) : 0;
  2528             const int buttonMargin = spinbox->frame ? 2 : 0;
  2561             const int buttonMargin = spinbox->frame ? 2 : 0;
  2529             const int buttonWidth = QS60StylePrivate::pixelMetric(QStyle::PM_ButtonIconSize) + 2 * buttonMargin;
  2562             const int buttonWidth = QS60StylePrivate::pixelMetric(PM_ButtonIconSize) + 2 * buttonMargin;
  2530             QSize buttonSize;
  2563             QSize buttonSize;
  2531             buttonSize.setHeight(qMax(8, spinbox->rect.height() - frameThickness));
  2564             buttonSize.setHeight(qMax(8, spinbox->rect.height() - frameThickness));
  2532             //width should at least be equal to height
  2565             //width should at least be equal to height
  2533             buttonSize.setWidth(qMax(buttonSize.height(), buttonWidth));
  2566             buttonSize.setWidth(qMax(buttonSize.height(), buttonWidth));
  2534             buttonSize = buttonSize.expandedTo(QApplication::globalStrut());
  2567             buttonSize = buttonSize.expandedTo(QApplication::globalStrut());
  2573     case CC_ComboBox:
  2606     case CC_ComboBox:
  2574         if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
  2607         if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
  2575             ret = cmb->rect;
  2608             ret = cmb->rect;
  2576             const int width = cmb->rect.width();
  2609             const int width = cmb->rect.width();
  2577             const int height = cmb->rect.height();
  2610             const int height = cmb->rect.height();
  2578             const int buttonIconSize = QS60StylePrivate::pixelMetric(QStyle::PM_ButtonIconSize);
  2611             const int buttonIconSize = QS60StylePrivate::pixelMetric(PM_ButtonIconSize);
  2579             const int buttonMargin = cmb->frame ? 2 : 0;
  2612             const int buttonMargin = cmb->frame ? 2 : 0;
  2580             // lets use spinbox frame here as well, as no combobox specific value available.
  2613             // lets use spinbox frame here as well, as no combobox specific value available.
  2581             const int frameThickness = cmb->frame ? pixelMetric(PM_SpinBoxFrameWidth, cmb, widget) : 0;
  2614             const int frameThickness = cmb->frame ? pixelMetric(PM_SpinBoxFrameWidth, cmb, widget) : 0;
  2582             const int buttonWidth = qMax(cmb->rect.height(), buttonIconSize);
  2615             const int buttonWidth = qMax(cmb->rect.height(), buttonIconSize);
  2583             const int xposMod = (cmb->rect.x()) + width - buttonMargin - buttonWidth;
       
  2584             const int ypos = cmb->rect.y();
       
  2585 
  2616 
  2586             QSize buttonSize;
  2617             QSize buttonSize;
  2587             buttonSize.setWidth(buttonWidth + 2 * buttonMargin);
  2618             buttonSize.setWidth(buttonWidth + 2 * buttonMargin);
  2588             buttonSize.setHeight(qMax(8, (cmb->rect.height() >> 1) - frameThickness)); //buttons should be squares
  2619             buttonSize.setHeight(qMax(8, (cmb->rect.height() >> 1) - frameThickness)); //buttons should be squares
  2589             buttonSize = buttonSize.expandedTo(QApplication::globalStrut());
  2620             buttonSize = buttonSize.expandedTo(QApplication::globalStrut());
  2590             switch (scontrol) {
  2621             switch (scontrol) {
  2591                 case SC_ComboBoxArrow:
  2622                 case SC_ComboBoxArrow: {
       
  2623                     const int xposMod = cmb->rect.x() + width - buttonMargin - buttonWidth;
       
  2624                     const int ypos = cmb->rect.y();
  2592                     ret.setRect(xposMod, ypos + buttonMargin, buttonWidth, height - 2 * buttonMargin);
  2625                     ret.setRect(xposMod, ypos + buttonMargin, buttonWidth, height - 2 * buttonMargin);
       
  2626                     }
  2593                     break;
  2627                     break;
  2594                 case SC_ComboBoxEditField: {
  2628                 case SC_ComboBoxEditField: {
  2595                     const int withFrameX = cmb->rect.x() + cmb->rect.width() - frameThickness - buttonSize.width();
  2629                     const int withFrameX = cmb->rect.x() + width - frameThickness - buttonSize.width();
  2596                     ret = QRect(
  2630                     ret = QRect(
  2597                         frameThickness,
  2631                         frameThickness,
  2598                         frameThickness,
  2632                         frameThickness,
  2599                         withFrameX - frameThickness,
  2633                         withFrameX - frameThickness,
  2600                         cmb->rect.height() - 2 * frameThickness);
  2634                         height - 2 * frameThickness);
  2601                     }
  2635                     }
  2602                 break;
  2636                 break;
  2603             default:
  2637             default:
  2604                 break;
  2638                 break;
  2605             }
  2639             }
       
  2640             ret = visualRect(cmb->direction, cmb->rect, ret);
  2606         }
  2641         }
  2607         break;
  2642         break;
  2608     case CC_GroupBox:
  2643     case CC_GroupBox:
  2609         if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
  2644         if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
  2610             ret = QCommonStyle::subControlRect(control, option, scontrol, widget);
  2645             ret = QCommonStyle::subControlRect(control, option, scontrol, widget);
  2611             switch (scontrol) {
  2646             switch (scontrol) {
  2612                 case SC_GroupBoxCheckBox: //fallthrough
  2647                 case SC_GroupBoxCheckBox: //fallthrough
  2613                 case SC_GroupBoxLabel: {
  2648                 case SC_GroupBoxLabel: {
  2614                     //slightly indent text and boxes, so that dialog border does not mess with them.
  2649                     //slightly indent text and boxes, so that dialog border does not mess with them.
  2615                     const int horizontalSpacing =
  2650                     const int horizontalSpacing =
  2616                         QS60StylePrivate::pixelMetric(QStyle::PM_LayoutHorizontalSpacing);
  2651                         QS60StylePrivate::pixelMetric(PM_LayoutHorizontalSpacing);
  2617                     ret.adjust(2, horizontalSpacing - 3, 0, 0);
  2652                     ret.adjust(2, horizontalSpacing - 3, 0, 0);
  2618                     }
  2653                     }
  2619                     break;
  2654                     break;
  2620                 case SC_GroupBoxFrame: {
  2655                 case SC_GroupBoxFrame: {
  2621                     const QRect textBox = subControlRect(control, option, SC_GroupBoxLabel, widget);
  2656                     const QRect textBox = subControlRect(control, option, SC_GroupBoxLabel, widget);
  2666 */
  2701 */
  2667 QRect QS60Style::subElementRect(SubElement element, const QStyleOption *opt, const QWidget *widget) const
  2702 QRect QS60Style::subElementRect(SubElement element, const QStyleOption *opt, const QWidget *widget) const
  2668 {
  2703 {
  2669     QRect ret;
  2704     QRect ret;
  2670     switch (element) {
  2705     switch (element) {
       
  2706         case SE_RadioButtonFocusRect:
       
  2707             ret = opt->rect;
       
  2708             break;
  2671         case SE_LineEditContents: {
  2709         case SE_LineEditContents: {
  2672                 // in S60 the input text box doesn't start from line Edit's TL, but
  2710                 // in S60 the input text box doesn't start from line Edit's TL, but
  2673                 // a bit indented.
  2711                 // a bit indented.
  2674                 QRect lineEditRect = opt->rect;
  2712                 QRect lineEditRect = opt->rect;
  2675                 const int adjustment = opt->rect.height() >> 2;
  2713                 const int adjustment = opt->rect.height() >> 2;
  2684             if (const QStyleOptionTabWidgetFrame *optionTab = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) {
  2722             if (const QStyleOptionTabWidgetFrame *optionTab = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) {
  2685                 ret = QCommonStyle::subElementRect(element, opt, widget);
  2723                 ret = QCommonStyle::subElementRect(element, opt, widget);
  2686 
  2724 
  2687                 if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) {
  2725                 if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) {
  2688                     const int tabOverlapNoBorder =
  2726                     const int tabOverlapNoBorder =
  2689                         QS60StylePrivate::pixelMetric(QStyle::PM_TabBarTabOverlap);
  2727                         QS60StylePrivate::pixelMetric(PM_TabBarTabOverlap);
  2690                     const int tabOverlap =
  2728                     const int tabOverlap =
  2691                         tabOverlapNoBorder-QS60StylePrivate::pixelMetric(QStyle::PM_DefaultFrameWidth);
  2729                         tabOverlapNoBorder-QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth);
  2692                     const QTabWidget *tab = qobject_cast<const QTabWidget *>(widget);
  2730                     const QTabWidget *tab = qobject_cast<const QTabWidget *>(widget);
  2693                     int gain = (tab) ? tabOverlap * tab->count() : 0;
  2731                     int gain = (tab) ? tabOverlap * tab->count() : 0;
  2694                     switch (twf->shape) {
  2732                     switch (twf->shape) {
  2695                         case QTabBar::RoundedNorth:
  2733                         case QTabBar::RoundedNorth:
  2696                         case QTabBar::TriangularNorth:
  2734                         case QTabBar::TriangularNorth:
  2735                 // text and decoration towards the beginning
  2773                 // text and decoration towards the beginning
  2736                 if (listItem &&
  2774                 if (listItem &&
  2737                     multiSelection &&
  2775                     multiSelection &&
  2738                     (vopt->features & QStyleOptionViewItemV2::HasCheckIndicator)) {
  2776                     (vopt->features & QStyleOptionViewItemV2::HasCheckIndicator)) {
  2739                     const int verticalSpacing =
  2777                     const int verticalSpacing =
  2740                         QS60StylePrivate::pixelMetric(QStyle::PM_LayoutVerticalSpacing);
  2778                         QS60StylePrivate::pixelMetric(PM_LayoutVerticalSpacing);
  2741                     //const int horizontalSpacing = QS60StylePrivate::pixelMetric(QStyle::PM_LayoutHorizontalSpacing);
  2779                     //const int horizontalSpacing = QS60StylePrivate::pixelMetric(PM_LayoutHorizontalSpacing);
  2742                     const int checkBoxRectWidth = subElementRect(SE_ItemViewItemCheckIndicator, opt, widget).width();
  2780                     const int checkBoxRectWidth = subElementRect(SE_ItemViewItemCheckIndicator, opt, widget).width();
  2743                     ret.adjust(-checkBoxRectWidth - verticalSpacing, 0, -checkBoxRectWidth - verticalSpacing, 0);
  2781                     ret.adjust(-checkBoxRectWidth - verticalSpacing, 0, -checkBoxRectWidth - verticalSpacing, 0);
  2744                 }
  2782                 }
  2745             } else if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
  2783             } else if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
  2746                 const bool checkable = menuItem->checkType != QStyleOptionMenuItem::NotCheckable;
  2784                 const bool checkable = menuItem->checkType != QStyleOptionMenuItem::NotCheckable;
  2782                 const bool checkBoxOnly = (vopt->features & QStyleOptionViewItemV2::HasCheckIndicator) &&
  2820                 const bool checkBoxOnly = (vopt->features & QStyleOptionViewItemV2::HasCheckIndicator) &&
  2783                     listItem &&
  2821                     listItem &&
  2784                     singleSelection;
  2822                     singleSelection;
  2785 
  2823 
  2786                 // Selection check mark rect.
  2824                 // Selection check mark rect.
  2787                 const int indicatorWidth = QS60StylePrivate::pixelMetric(QStyle::PM_IndicatorWidth);
  2825                 const int indicatorWidth = QS60StylePrivate::pixelMetric(PM_IndicatorWidth);
  2788                 const int indicatorHeight = QS60StylePrivate::pixelMetric(QStyle::PM_IndicatorHeight);
  2826                 const int indicatorHeight = QS60StylePrivate::pixelMetric(PM_IndicatorHeight);
  2789                 const int spacing = QS60StylePrivate::pixelMetric(QStyle::PM_CheckBoxLabelSpacing);
  2827                 const int spacing = QS60StylePrivate::pixelMetric(PM_CheckBoxLabelSpacing);
  2790 
  2828 
  2791                 const int itemHeight = opt->rect.height();
  2829                 const int itemHeight = opt->rect.height();
  2792                 int heightOffset = 0;
  2830                 int heightOffset = 0;
  2793                 if (indicatorHeight < itemHeight)
  2831                 if (indicatorHeight < itemHeight)
  2794                     heightOffset = ((itemHeight - indicatorHeight) >> 1);
  2832                     heightOffset = ((itemHeight - indicatorHeight) >> 1);
  2816                 else
  2854                 else
  2817                     ret.setWidth(ret.width() - QS60StylePrivate::pixelMetric(PM_Custom_ThinLineWidth));
  2855                     ret.setWidth(ret.width() - QS60StylePrivate::pixelMetric(PM_Custom_ThinLineWidth));
  2818                 }
  2856                 }
  2819             ret = visualRect(opt->direction, opt->rect, ret);
  2857             ret = visualRect(opt->direction, opt->rect, ret);
  2820             break;
  2858             break;
       
  2859         case SE_RadioButtonIndicator: {
       
  2860                 const int height = pixelMetric(PM_ExclusiveIndicatorHeight, opt, widget);
       
  2861                 ret.setRect(opt->rect.x(), opt->rect.y() + ((opt->rect.height() - height) >> 1),
       
  2862                         pixelMetric(PM_ExclusiveIndicatorWidth, opt, widget), height);
       
  2863                 ret.translate(2, 0); //move indicator slightly to avoid highlight crossing over it
       
  2864                 ret = visualRect(opt->direction, opt->rect, ret);
       
  2865             }
       
  2866             break;
       
  2867         case SE_CheckBoxIndicator: {
       
  2868                 const int height = pixelMetric(PM_IndicatorHeight, opt, widget);
       
  2869                 ret.setRect(opt->rect.x(), opt->rect.y() + ((opt->rect.height() - height) >> 1),
       
  2870                           pixelMetric(PM_IndicatorWidth, opt, widget), height);
       
  2871                 ret.translate(2, 0); //move indicator slightly to avoid highlight crossing over it
       
  2872                 ret = visualRect(opt->direction, opt->rect, ret);
       
  2873             }
       
  2874             break;
       
  2875         case SE_CheckBoxFocusRect:
       
  2876             ret = opt->rect;
       
  2877             break;
  2821         default:
  2878         default:
  2822             ret = QCommonStyle::subElementRect(element, opt, widget);
  2879             ret = QCommonStyle::subElementRect(element, opt, widget);
  2823     }
  2880     }
  2824     return ret;
  2881     return ret;
  2825 }
  2882 }
  2832     Q_D(const QS60Style);
  2889     Q_D(const QS60Style);
  2833     QCommonStyle::polish(widget);
  2890     QCommonStyle::polish(widget);
  2834 
  2891 
  2835     if (!widget)
  2892     if (!widget)
  2836         return;
  2893         return;
       
  2894 
       
  2895     //Currently we only support animations in QProgressBar.
       
  2896 #ifndef QT_NO_PROGRESSBAR
       
  2897     if (qobject_cast<QProgressBar *>(widget))
       
  2898         widget->installEventFilter(this);
       
  2899 #endif
  2837 
  2900 
  2838     if (false
  2901     if (false
  2839 #ifndef QT_NO_SCROLLBAR
  2902 #ifndef QT_NO_SCROLLBAR
  2840         || qobject_cast<QScrollBar *>(widget)
  2903         || qobject_cast<QScrollBar *>(widget)
  2841 #endif
  2904 #endif
  2865 /*!
  2928 /*!
  2866   \reimp
  2929   \reimp
  2867  */
  2930  */
  2868 void QS60Style::unpolish(QWidget *widget)
  2931 void QS60Style::unpolish(QWidget *widget)
  2869 {
  2932 {
       
  2933     Q_D(QS60Style);
       
  2934 
  2870     if (false
  2935     if (false
  2871     #ifndef QT_NO_SCROLLBAR
  2936     #ifndef QT_NO_SCROLLBAR
  2872         || qobject_cast<QScrollBar *>(widget)
  2937         || qobject_cast<QScrollBar *>(widget)
  2873     #endif
  2938     #endif
  2874         )
  2939         )
  2891     }
  2956     }
  2892 
  2957 
  2893     if (widget)
  2958     if (widget)
  2894         widget->setPalette(QPalette());
  2959         widget->setPalette(QPalette());
  2895 
  2960 
       
  2961 #if defined(Q_WS_S60) && !defined(QT_NO_PROGRESSBAR)
       
  2962     if (QProgressBar *bar = qobject_cast<QProgressBar *>(widget)) {
       
  2963         widget->removeEventFilter(this);
       
  2964         d->m_bars.removeAll(bar);
       
  2965     }
       
  2966 #else
       
  2967     Q_UNUSED(d)
       
  2968 #endif
  2896     QCommonStyle::unpolish(widget);
  2969     QCommonStyle::unpolish(widget);
  2897 }
  2970 }
  2898 
  2971 
  2899 /*!
  2972 /*!
  2900   \reimp
  2973   \reimp
  2922   \reimp
  2995   \reimp
  2923  */
  2996  */
  2924 bool QS60Style::event(QEvent *e)
  2997 bool QS60Style::event(QEvent *e)
  2925 {
  2998 {
  2926 #ifdef QT_KEYPAD_NAVIGATION
  2999 #ifdef QT_KEYPAD_NAVIGATION
  2927     if (QS60StylePrivate::isTouchSupported())
       
  2928         return false;
       
  2929     Q_D(QS60Style);
  3000     Q_D(QS60Style);
       
  3001     const QEvent::Type eventType = e->type();
       
  3002     if ((eventType == QEvent::FocusIn ||
       
  3003          eventType == QEvent::FocusOut ||
       
  3004          eventType == QEvent::EnterEditFocus ||
       
  3005          eventType == QEvent::LeaveEditFocus) &&
       
  3006         QS60StylePrivate::isTouchSupported())
       
  3007             return false;
       
  3008 #endif
       
  3009 
  2930     switch (e->type()) {
  3010     switch (e->type()) {
       
  3011     case QEvent::Timer: {
       
  3012         QTimerEvent *te = static_cast<QTimerEvent*>(e);
       
  3013         timerEvent(te);
       
  3014         }
       
  3015         break;
       
  3016 #ifdef QT_KEYPAD_NAVIGATION
  2931     case QEvent::FocusIn:
  3017     case QEvent::FocusIn:
  2932         if (QWidget *focusWidget = QApplication::focusWidget()) {
  3018         if (QWidget *focusWidget = QApplication::focusWidget()) {
  2933             if (!d->m_focusFrame)
  3019             if (!d->m_focusFrame)
  2934                 d->m_focusFrame = new QFocusFrame(focusWidget);
  3020                 d->m_focusFrame = new QFocusFrame(focusWidget);
  2935             d->m_focusFrame->setWidget(focusWidget);
  3021             d->m_focusFrame->setWidget(focusWidget);
  2944     case QEvent::EnterEditFocus:
  3030     case QEvent::EnterEditFocus:
  2945     case QEvent::LeaveEditFocus:
  3031     case QEvent::LeaveEditFocus:
  2946         if (d->m_focusFrame)
  3032         if (d->m_focusFrame)
  2947             d->m_focusFrame->update();
  3033             d->m_focusFrame->update();
  2948         break;
  3034         break;
       
  3035 #endif
  2949     default:
  3036     default:
  2950         break;
  3037         break;
  2951     }
  3038     }
  2952 #else
       
  2953     Q_UNUSED(e)
       
  2954 #endif
       
  2955     return false;
  3039     return false;
  2956 }
  3040 }
  2957 
  3041 
  2958 /*!
  3042 /*!
  2959     \internal
  3043     \internal
  2960  */
  3044  */
  2961 QIcon QS60Style::standardIconImplementation(StandardPixmap standardIcon,
  3045 QIcon QS60Style::standardIconImplementation(StandardPixmap standardIcon,
  2962     const QStyleOption *option, const QWidget *widget) const
  3046     const QStyleOption *option, const QWidget *widget) const
  2963 {
  3047 {
  2964     const int iconDimension = QS60StylePrivate::pixelMetric(QStyle::PM_ToolBarIconSize);
  3048     const int iconDimension = QS60StylePrivate::pixelMetric(PM_ToolBarIconSize);
  2965     const QRect iconSize = (!option) ? QRect(0, 0, iconDimension, iconDimension) : option->rect;
  3049     const QRect iconSize = (!option) ? QRect(0, 0, iconDimension, iconDimension) : option->rect;
  2966     QS60StyleEnums::SkinParts part;
  3050     QS60StyleEnums::SkinParts part;
  2967     QS60StylePrivate::SkinElementFlags adjustedFlags;
  3051     QS60StylePrivate::SkinElementFlags adjustedFlags;
  2968     if (option)
  3052     if (option)
  2969         adjustedFlags = (option->state & State_Enabled || option->state == 0) ?
  3053         adjustedFlags = (option->state & State_Enabled || option->state == 0) ?
  2970             QS60StylePrivate::SF_StateEnabled :
  3054             QS60StylePrivate::SF_StateEnabled :
  2971             QS60StylePrivate::SF_StateDisabled;
  3055             QS60StylePrivate::SF_StateDisabled;
  2972 
  3056 
  2973     switch(standardIcon) {
  3057     switch(standardIcon) {
  2974         case QStyle::SP_MessageBoxWarning:
  3058         case SP_MessageBoxWarning:
  2975             part = QS60StyleEnums::SP_QgnNoteWarning;
  3059             part = QS60StyleEnums::SP_QgnNoteWarning;
  2976             break;
  3060             break;
  2977         case QStyle::SP_MessageBoxInformation:
  3061         case SP_MessageBoxInformation:
  2978             part = QS60StyleEnums::SP_QgnNoteInfo;
  3062             part = QS60StyleEnums::SP_QgnNoteInfo;
  2979             break;
  3063             break;
  2980         case QStyle::SP_MessageBoxCritical:
  3064         case SP_MessageBoxCritical:
  2981             part = QS60StyleEnums::SP_QgnNoteError;
  3065             part = QS60StyleEnums::SP_QgnNoteError;
  2982             break;
  3066             break;
  2983         case QStyle::SP_MessageBoxQuestion:
  3067         case SP_MessageBoxQuestion:
  2984             part = QS60StyleEnums::SP_QgnNoteQuery;
  3068             part = QS60StyleEnums::SP_QgnNoteQuery;
  2985             break;
  3069             break;
  2986         case QStyle::SP_ArrowRight:
  3070         case SP_ArrowRight:
  2987             part = QS60StyleEnums::SP_QgnIndiNaviArrowRight;
  3071             part = QS60StyleEnums::SP_QgnIndiNaviArrowRight;
  2988             break;
  3072             break;
  2989         case QStyle::SP_ArrowLeft:
  3073         case SP_ArrowLeft:
  2990             part = QS60StyleEnums::SP_QgnIndiNaviArrowLeft;
  3074             part = QS60StyleEnums::SP_QgnIndiNaviArrowLeft;
  2991             break;
  3075             break;
  2992         case QStyle::SP_ArrowUp:
  3076         case SP_ArrowUp:
  2993             part = QS60StyleEnums::SP_QgnIndiNaviArrowLeft;
  3077             part = QS60StyleEnums::SP_QgnIndiNaviArrowLeft;
  2994             adjustedFlags |= QS60StylePrivate::SF_PointEast;
  3078             adjustedFlags |= QS60StylePrivate::SF_PointEast;
  2995             break;
  3079             break;
  2996         case QStyle::SP_ArrowDown:
  3080         case SP_ArrowDown:
  2997             part = QS60StyleEnums::SP_QgnIndiNaviArrowLeft;
  3081             part = QS60StyleEnums::SP_QgnIndiNaviArrowLeft;
  2998             adjustedFlags |= QS60StylePrivate::SF_PointWest;
  3082             adjustedFlags |= QS60StylePrivate::SF_PointWest;
  2999             break;
  3083             break;
  3000         case QStyle::SP_ArrowBack:
  3084         case SP_ArrowBack:
  3001             if (QApplication::layoutDirection() == Qt::RightToLeft)
  3085             if (QApplication::layoutDirection() == Qt::RightToLeft)
  3002                 return QS60Style::standardIcon(SP_ArrowRight, option, widget);
  3086                 return QS60Style::standardIcon(SP_ArrowRight, option, widget);
  3003             return QS60Style::standardIcon(SP_ArrowLeft, option, widget);
  3087             return QS60Style::standardIcon(SP_ArrowLeft, option, widget);
  3004         case QStyle::SP_ArrowForward:
  3088         case SP_ArrowForward:
  3005             if (QApplication::layoutDirection() == Qt::RightToLeft)
  3089             if (QApplication::layoutDirection() == Qt::RightToLeft)
  3006                 return QS60Style::standardIcon(SP_ArrowLeft, option, widget);
  3090                 return QS60Style::standardIcon(SP_ArrowLeft, option, widget);
  3007             return QS60Style::standardIcon(SP_ArrowRight, option, widget);
  3091             return QS60Style::standardIcon(SP_ArrowRight, option, widget);
  3008         case QStyle::SP_ComputerIcon:
  3092         case SP_ComputerIcon:
  3009             part = QS60StyleEnums::SP_QgnPropPhoneMemcLarge;
  3093             part = QS60StyleEnums::SP_QgnPropPhoneMemcLarge;
  3010             break;
  3094             break;
  3011         case QStyle::SP_DirClosedIcon:
  3095         case SP_DirClosedIcon:
  3012             part = QS60StyleEnums::SP_QgnPropFolderSmall;
  3096             part = QS60StyleEnums::SP_QgnPropFolderSmall;
  3013             break;
  3097             break;
  3014         case QStyle::SP_DirOpenIcon:
  3098         case SP_DirOpenIcon:
  3015             part = QS60StyleEnums::SP_QgnPropFolderCurrent;
  3099             part = QS60StyleEnums::SP_QgnPropFolderCurrent;
  3016             break;
  3100             break;
  3017         case QStyle::SP_DirIcon:
  3101         case SP_DirIcon:
  3018             part = QS60StyleEnums::SP_QgnPropFolderSmall;
  3102             part = QS60StyleEnums::SP_QgnPropFolderSmall;
  3019             break;
  3103             break;
  3020         case QStyle::SP_FileDialogNewFolder:
  3104         case SP_FileDialogNewFolder:
  3021             part = QS60StyleEnums::SP_QgnPropFolderSmallNew;
  3105             part = QS60StyleEnums::SP_QgnPropFolderSmallNew;
  3022             break;
  3106             break;
  3023         case QStyle::SP_FileIcon:
  3107         case SP_FileIcon:
  3024             part = QS60StyleEnums::SP_QgnPropFileSmall;
  3108             part = QS60StyleEnums::SP_QgnPropFileSmall;
  3025             break;
  3109             break;
  3026         case QStyle::SP_TrashIcon:
  3110         case SP_TrashIcon:
  3027             part = QS60StyleEnums::SP_QgnNoteErased;
  3111             part = QS60StyleEnums::SP_QgnNoteErased;
  3028             break;
  3112             break;
  3029         case QStyle::SP_ToolBarHorizontalExtensionButton:
  3113         case SP_ToolBarHorizontalExtensionButton:
  3030             part = QS60StyleEnums::SP_QgnIndiSubMenu;
  3114             part = QS60StyleEnums::SP_QgnIndiSubMenu;
  3031             if (QApplication::layoutDirection() == Qt::RightToLeft)
  3115             if (QApplication::layoutDirection() == Qt::RightToLeft)
  3032                 adjustedFlags |= QS60StylePrivate::SF_PointSouth;
  3116                 adjustedFlags |= QS60StylePrivate::SF_PointSouth;
  3033             break;
  3117             break;
  3034         case QStyle::SP_ToolBarVerticalExtensionButton:
  3118         case SP_ToolBarVerticalExtensionButton:
  3035             adjustedFlags |= QS60StylePrivate::SF_PointEast;
  3119             adjustedFlags |= QS60StylePrivate::SF_PointEast;
  3036             part = QS60StyleEnums::SP_QgnIndiSubMenu;
  3120             part = QS60StyleEnums::SP_QgnIndiSubMenu;
  3037             break;
  3121             break;
  3038 
  3122 
  3039         default:
  3123         default:
  3043     const QPixmap cachedPixMap(QS60StylePrivate::cachedPart(part, iconSize.size(), 0, flags));
  3127     const QPixmap cachedPixMap(QS60StylePrivate::cachedPart(part, iconSize.size(), 0, flags));
  3044     return cachedPixMap.isNull() ?
  3128     return cachedPixMap.isNull() ?
  3045         QCommonStyle::standardIconImplementation(standardIcon, option, widget) : QIcon(cachedPixMap);
  3129         QCommonStyle::standardIconImplementation(standardIcon, option, widget) : QIcon(cachedPixMap);
  3046 }
  3130 }
  3047 
  3131 
       
  3132 /*!
       
  3133     \internal
       
  3134     Animate indeterminate progress bars only when visible
       
  3135 */
       
  3136 bool QS60Style::eventFilter(QObject *object, QEvent *event)
       
  3137 {
       
  3138 #ifdef Q_WS_S60
       
  3139 #ifndef QT_NO_PROGRESSBAR
       
  3140     Q_D(QS60Style);
       
  3141     switch(event->type()) {
       
  3142     case QEvent::StyleChange:
       
  3143     case QEvent::Show:
       
  3144         if (QProgressBar *bar = qobject_cast<QProgressBar *>(object)) {
       
  3145             if (!d->m_bars.contains(bar))
       
  3146                 d->m_bars << bar;
       
  3147             if (d->m_bars.size() == 1) //only start with first animated progressbar
       
  3148                 d->startAnimation(QS60StyleEnums::SP_QgnGrafBarWaitAnim);
       
  3149         }
       
  3150         break;
       
  3151     case QEvent::Destroy:
       
  3152     case QEvent::Hide:
       
  3153         d->stopAnimation(QS60StyleEnums::SP_QgnGrafBarWaitAnim);
       
  3154         d->m_bars.removeAll(reinterpret_cast<QProgressBar *>(object));
       
  3155         break;
       
  3156     default:
       
  3157         break;
       
  3158     }
       
  3159 #endif // QT_NO_PROGRESSBAR
       
  3160 #endif // Q_WS_S60
       
  3161     return QStyle::eventFilter(object, event);
       
  3162 }
       
  3163 
       
  3164 /*!
       
  3165     \internal
       
  3166     Handle the timer \a event. 
       
  3167 */
       
  3168 void QS60Style::timerEvent(QTimerEvent *event)
       
  3169 {
       
  3170 #ifdef Q_WS_S60
       
  3171 #ifndef QT_NO_PROGRESSBAR
       
  3172     Q_D(QS60Style);
       
  3173 
       
  3174     QS60StyleAnimation *progressBarAnimation =
       
  3175         QS60StylePrivate::animationDefinition(QS60StyleEnums::SP_QgnGrafBarWaitAnim);
       
  3176 
       
  3177     if (event->timerId() == progressBarAnimation->timerId()) {
       
  3178 
       
  3179         Q_ASSERT(progressBarAnimation->interval() > 0);
       
  3180 
       
  3181         if (progressBarAnimation->currentFrame() == progressBarAnimation->frameCount() )
       
  3182             if (progressBarAnimation->playMode() == QS60StyleEnums::AM_Looping)
       
  3183                 progressBarAnimation->setCurrentFrame(0);
       
  3184             else
       
  3185                 d->stopAnimation(progressBarAnimation->animationId());
       
  3186 
       
  3187         foreach (QProgressBar *bar, d->m_bars) {
       
  3188             if ((bar->minimum() == 0 && bar->maximum() == 0))
       
  3189                 bar->update();
       
  3190         }
       
  3191         progressBarAnimation->setCurrentFrame(progressBarAnimation->currentFrame() + 1);
       
  3192     }
       
  3193 #endif // QT_NO_PROGRESSBAR
       
  3194 #endif // Q_WS_S60
       
  3195     event->ignore();
       
  3196 }
       
  3197 
  3048 extern QPoint qt_s60_fill_background_offset(const QWidget *targetWidget);
  3198 extern QPoint qt_s60_fill_background_offset(const QWidget *targetWidget);
  3049 
  3199 
  3050 bool qt_s60_fill_background(QPainter *painter, const QRegion &rgn, const QBrush &brush)
  3200 bool qt_s60_fill_background(QPainter *painter, const QRegion &rgn, const QBrush &brush)
  3051 {
  3201 {
  3052     const QPixmap backgroundTexture(QS60StylePrivate::backgroundTexture());
  3202     const QPixmap backgroundTexture(QS60StylePrivate::backgroundTexture());
  3054         return false;
  3204         return false;
  3055 
  3205 
  3056     const QPaintDevice *target = painter->device();
  3206     const QPaintDevice *target = painter->device();
  3057     if (target->devType() == QInternal::Widget) {
  3207     if (target->devType() == QInternal::Widget) {
  3058         const QWidget *widget = static_cast<const QWidget *>(target);
  3208         const QWidget *widget = static_cast<const QWidget *>(target);
  3059         const QVector<QRect> &rects = rgn.rects();
  3209         if (!widget->testAttribute(Qt::WA_TranslucentBackground)) {
  3060         for (int i = 0; i < rects.size(); ++i) {
  3210             const QVector<QRect> &rects = rgn.rects();
  3061             const QRect rect(rects.at(i));
  3211             for (int i = 0; i < rects.size(); ++i) {
  3062             painter->drawPixmap(rect.topLeft(), backgroundTexture,
  3212                 const QRect rect(rects.at(i));
  3063                                 rect.translated(qt_s60_fill_background_offset(widget)));
  3213                 painter->drawPixmap(rect.topLeft(), backgroundTexture,
       
  3214                                     rect.translated(qt_s60_fill_background_offset(widget)));
       
  3215             }
  3064         }
  3216         }
  3065     }
  3217     }
  3066     return true;
  3218     return true;
  3067 }
  3219 }
  3068 
  3220