src/gui/styles/qs60style.cpp
changeset 25 e24348a560a6
parent 23 89e065397ea6
child 29 b72c6db6890b
equal deleted inserted replaced
23:89e065397ea6 25:e24348a560a6
    90 
    90 
    91 static const qreal goldenRatio = 1.618;
    91 static const qreal goldenRatio = 1.618;
    92 
    92 
    93 const layoutHeader QS60StylePrivate::m_layoutHeaders[] = {
    93 const layoutHeader QS60StylePrivate::m_layoutHeaders[] = {
    94 // *** generated layout data ***
    94 // *** generated layout data ***
    95 {240,320,1,18,"QVGA Landscape"},
    95 {240,320,1,19,"QVGA Landscape"},
    96 {320,240,1,18,"QVGA Portrait"},
    96 {320,240,1,19,"QVGA Portrait"},
    97 {360,640,1,18,"NHD Landscape"},
    97 {360,640,1,19,"NHD Landscape"},
    98 {640,360,1,18,"NHD Portrait"},
    98 {640,360,1,19,"NHD Portrait"},
    99 {352,800,1,12,"E90 Landscape"}
    99 {352,800,1,12,"E90 Landscape"}
   100 // *** End of generated data ***
   100 // *** End of generated data ***
   101 };
   101 };
   102 const int QS60StylePrivate::m_numberOfLayouts =
   102 const int QS60StylePrivate::m_numberOfLayouts =
   103     (int)sizeof(QS60StylePrivate::m_layoutHeaders)/sizeof(QS60StylePrivate::m_layoutHeaders[0]);
   103     (int)sizeof(QS60StylePrivate::m_layoutHeaders)/sizeof(QS60StylePrivate::m_layoutHeaders[0]);
   104 
   104 
   105 const short QS60StylePrivate::data[][MAX_PIXELMETRICS] = {
   105 const short QS60StylePrivate::data[][MAX_PIXELMETRICS] = {
   106 // *** generated pixel metrics ***
   106 // *** generated pixel metrics ***
   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,30,3,3,1,-909,-909,0,1,0,0,12,20,15,15,18,18,1,115,18,0,-909,-909,-909,-909,0,0,16,2,-909,0,0,-909,16,-909,-909,-909,-909,32,18,55,24,55,4,4,4,9,13,-909,5,51,11,5,0,3,3,6,8,3,3,-909,2,-909,-909,-909,-909,5,5,3,1, 106},
   107 {5,0,-909,0,0,2,0,0,-1,7,12,22,15,15,7,198,-909,-909,-909,20,13,2,0,0,21,7,18,30,3,3,1,-909,-909,0,1,0,0,12,20,15,15,18,18,1,115,18,0,-909,-909,-909,-909,0,0,16,2,-909,0,0,-909,16,-909,-909,-909,-909,32,18,55,24,55,4,4,4,9,13,-909,5,51,11,5,0,3,3,6,8,3,3,-909,2,-909,-909,-909,-909,5,5,3,1,106},
   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,28,4,4,1,-909,-909,0,7,6,0,13,23,17,17,21,21,7,115,21,0,-909,-909,-909,-909,0,0,15,1,-909,0,0,-909,15,-909,-909,-909,-909,32,21,65,27,65,3,3,5,10,15,-909,5,58,13,5,0,4,4,7,9,4,4,-909,2,-909,-909,-909,-909,6,6,3,1, 106},
   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,28,4,4,1,-909,-909,0,7,6,0,13,23,17,17,21,21,7,115,21,0,-909,-909,-909,-909,0,0,15,1,-909,0,0,-909,15,-909,-909,-909,-909,32,21,65,27,65,3,3,5,10,15,-909,5,58,13,5,0,4,4,7,9,4,4,-909,2,-909,-909,-909,-909,6,6,3,1,106},
   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,44,5,5,2,-909,-909,0,7,21,0,17,29,22,22,27,27,7,173,29,0,-909,-909,-909,-909,0,0,25,2,-909,0,0,-909,25,-909,-909,-909,-909,87,27,77,35,77,13,13,6,8,19,-909,7,74,19,7,0,5,5,8,12,5,5,-909,3,-909,-909,-909,-909,7,7,3,1, 135},
   109 {7,0,-909,0,0,2,0,0,-1,25,69,46,37,37,9,258,-909,-909,-909,23,19,26,0,0,32,25,72,44,5,5,2,-909,-909,0,7,21,0,17,29,22,22,27,27,7,173,29,0,-909,-909,-909,-909,0,0,25,2,-909,0,0,-909,25,-909,-909,-909,-909,87,27,77,35,77,13,13,6,8,19,-909,7,74,19,7,0,5,5,8,12,5,5,-909,3,-909,-909,-909,-909,7,7,3,1,135},
   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,52,5,5,2,-909,-909,0,7,32,0,17,29,22,22,27,27,7,173,29,0,-909,-909,-909,-909,0,0,26,2,-909,0,0,-909,26,-909,-909,-909,-909,87,27,96,35,96,12,12,6,8,19,-909,7,74,22,7,0,5,5,8,12,5,5,-909,3,-909,-909,-909,-909,7,7,3,1, 135},
   110 {7,0,-909,0,0,2,0,0,-1,25,68,46,37,37,9,258,-909,-909,-909,31,19,6,0,0,32,25,60,52,5,5,2,-909,-909,0,7,32,0,17,29,22,22,27,27,7,173,29,0,-909,-909,-909,-909,0,0,26,2,-909,0,0,-909,26,-909,-909,-909,-909,87,27,96,35,96,12,12,6,8,19,-909,7,74,22,7,0,5,5,8,12,5,5,-909,3,-909,-909,-909,-909,7,7,3,1,135},
   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,30,5,5,2,-909,-909,0,2,8,0,16,28,21,21,26,26,2,170,26,0,-909,-909,-909,-909,0,0,21,6,-909,0,0,-909,-909,-909,-909,-909,-909,54,26,265,34,265,5,5,6,3,18,-909,7,72,19,7,0,5,6,8,11,6,5,-909,2,-909,-909,-909,-909,5,5,3,1, 106}
   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,30,5,5,2,-909,-909,0,2,8,0,16,28,21,21,26,26,2,170,26,0,-909,-909,-909,-909,0,0,21,6,-909,0,0,-909,-909,-909,-909,-909,-909,54,26,265,34,265,5,5,6,3,18,-909,7,72,19,7,0,5,6,8,11,6,5,-909,2,-909,-909,-909,-909,5,5,3,1,106}
   112 // *** End of generated data ***
   112 // *** End of generated data ***
   113 };
   113 };
   114 
   114 
   115 const short *QS60StylePrivate::m_pmPointer = QS60StylePrivate::data[0];
   115 const short *QS60StylePrivate::m_pmPointer = QS60StylePrivate::data[0];
   116 
   116 
   651         fontCategory = QS60StyleEnums::FC_Title;
   651         fontCategory = QS60StyleEnums::FC_Title;
   652     } else if (qobject_cast<QMessageBox *>(widget)){
   652     } else if (qobject_cast<QMessageBox *>(widget)){
   653         fontCategory = QS60StyleEnums::FC_Primary;
   653         fontCategory = QS60StyleEnums::FC_Primary;
   654     } else if (qobject_cast<QMenu *>(widget)){
   654     } else if (qobject_cast<QMenu *>(widget)){
   655         fontCategory = QS60StyleEnums::FC_Primary;
   655         fontCategory = QS60StyleEnums::FC_Primary;
       
   656     } else if (qobject_cast<QCalendarWidget *>(widget)){
       
   657         fontCategory = QS60StyleEnums::FC_Secondary;
   656     }
   658     }
   657     if (fontCategory != QS60StyleEnums::FC_Undefined) {
   659     if (fontCategory != QS60StyleEnums::FC_Undefined) {
   658         const bool resolveFontSize = widget->testAttribute(Qt::WA_SetFont)
   660         const bool resolveFontSize = widget->testAttribute(Qt::WA_SetFont)
   659             && (widget->font().resolve() & QFont::SizeResolved);
   661             && (widget->font().resolve() & QFont::SizeResolved);
   660         const QFont suggestedFont =
   662         const QFont suggestedFont =
   811     widgetPalette.setColor(QPalette::Text,
   813     widgetPalette.setColor(QPalette::Text,
   812         s60Color(QS60StyleEnums::CL_QsnTextColors, 27, 0));
   814         s60Color(QS60StyleEnums::CL_QsnTextColors, 27, 0));
   813     widgetPalette.setColor(QPalette::HighlightedText,
   815     widgetPalette.setColor(QPalette::HighlightedText,
   814         s60Color(QS60StyleEnums::CL_QsnTextColors, 24, 0));
   816         s60Color(QS60StyleEnums::CL_QsnTextColors, 24, 0));
   815     QApplication::setPalette(widgetPalette, "QLineEdit");
   817     QApplication::setPalette(widgetPalette, "QLineEdit");
   816     widgetPalette = *palette;
       
   817 
       
   818     widgetPalette.setColor(QPalette::Text,
       
   819         s60Color(QS60StyleEnums::CL_QsnTextColors, 27, 0));
       
   820     widgetPalette.setColor(QPalette::HighlightedText,
       
   821         s60Color(QS60StyleEnums::CL_QsnTextColors, 24, 0));
       
   822     QApplication::setPalette(widgetPalette, "QTextEdit");
   818     QApplication::setPalette(widgetPalette, "QTextEdit");
   823     widgetPalette = *palette;
   819     widgetPalette = *palette;
   824 
   820 
   825     widgetPalette.setColor(QPalette::HighlightedText,
   821     widgetPalette.setColor(QPalette::HighlightedText,
   826         s60Color(QS60StyleEnums::CL_QsnTextColors, 24, 0));
   822         s60Color(QS60StyleEnums::CL_QsnTextColors, 24, 0));
   878             break;
   874             break;
   879 
   875 
   880         case QS60StyleEnums::SP_QgnGrafNsliderEndLeft:
   876         case QS60StyleEnums::SP_QgnGrafNsliderEndLeft:
   881         case QS60StyleEnums::SP_QgnGrafNsliderEndRight:
   877         case QS60StyleEnums::SP_QgnGrafNsliderEndRight:
   882         case QS60StyleEnums::SP_QgnGrafNsliderMiddle:
   878         case QS60StyleEnums::SP_QgnGrafNsliderMiddle:
   883             result.setWidth(result.height() >> 1);
       
   884             break;
   879             break;
   885 
   880 
   886         case QS60StyleEnums::SP_QgnGrafNsliderMarker:
   881         case QS60StyleEnums::SP_QgnGrafNsliderMarker:
   887         case QS60StyleEnums::SP_QgnGrafNsliderMarkerSelected:
   882         case QS60StyleEnums::SP_QgnGrafNsliderMarkerSelected:
   888             result.scale(pixelMetric(QStyle::PM_SliderLength),
   883             result.scale(pixelMetric(QStyle::PM_SliderLength),
  1118 
  1113 
  1119                 if (bflags & (State_Sunken | State_On | State_Raised | State_Enabled)) {
  1114                 if (bflags & (State_Sunken | State_On | State_Raised | State_Enabled)) {
  1120                     tool.rect = button.unite(menuRect);
  1115                     tool.rect = button.unite(menuRect);
  1121                     tool.state = bflags;
  1116                     tool.state = bflags;
  1122                     const QToolButton *toolButtonWidget = qobject_cast<const QToolButton *>(widget);
  1117                     const QToolButton *toolButtonWidget = qobject_cast<const QToolButton *>(widget);
  1123                     QS60StylePrivate::SkinElements element;
  1118                     const QS60StylePrivate::SkinElements element =
  1124                     if (toolButtonWidget)
  1119                         ((toolButtonWidget && toolButtonWidget->isDown()) || (option->state & State_Sunken)) ?
  1125                         element = (toolButtonWidget->isDown()) ? QS60StylePrivate::SE_ToolBarButtonPressed : QS60StylePrivate::SE_ToolBarButton;
  1120                             QS60StylePrivate::SE_ToolBarButtonPressed : QS60StylePrivate::SE_ToolBarButton;
  1126                     else
       
  1127                         element = (option->state & State_Sunken) ? QS60StylePrivate::SE_ToolBarButtonPressed : QS60StylePrivate::SE_ToolBarButton;
       
  1128                     QS60StylePrivate::drawSkinElement(element, painter, tool.rect, flags);
  1121                     QS60StylePrivate::drawSkinElement(element, painter, tool.rect, flags);
  1129                     drawPrimitive(PE_PanelButtonTool, &tool, painter, widget);
  1122                     drawPrimitive(PE_PanelButtonTool, &tool, painter, widget);
  1130                 }
  1123                 }
  1131                 if (toolBtn->subControls & SC_ToolButtonMenu) {
  1124                 if (toolBtn->subControls & SC_ToolButtonMenu) {
  1132                     tool.rect = menuRect;
  1125                     tool.rect = menuRect;
  1532                 default:
  1525                 default:
  1533                     skinElement = isSelected ? QS60StylePrivate::SE_TabBarTabNorthActive:
  1526                     skinElement = isSelected ? QS60StylePrivate::SE_TabBarTabNorthActive:
  1534                         QS60StylePrivate::SE_TabBarTabNorthInactive;
  1527                         QS60StylePrivate::SE_TabBarTabNorthInactive;
  1535                     break;
  1528                     break;
  1536             }
  1529             }
  1537             if (skinElement==QS60StylePrivate::SE_TabBarTabEastInactive||
  1530             if (skinElement == QS60StylePrivate::SE_TabBarTabEastInactive ||
  1538                     skinElement==QS60StylePrivate::SE_TabBarTabNorthInactive||
  1531                     skinElement == QS60StylePrivate::SE_TabBarTabNorthInactive ||
  1539                     skinElement==QS60StylePrivate::SE_TabBarTabSouthInactive||
  1532                     skinElement == QS60StylePrivate::SE_TabBarTabSouthInactive ||
  1540                     skinElement==QS60StylePrivate::SE_TabBarTabWestInactive||
  1533                     skinElement == QS60StylePrivate::SE_TabBarTabWestInactive ||
  1541                     skinElement==QS60StylePrivate::SE_TabBarTabEastActive||
  1534                     skinElement == QS60StylePrivate::SE_TabBarTabEastActive ||
  1542                     skinElement==QS60StylePrivate::SE_TabBarTabNorthActive||
  1535                     skinElement == QS60StylePrivate::SE_TabBarTabNorthActive ||
  1543                     skinElement==QS60StylePrivate::SE_TabBarTabSouthActive||
  1536                     skinElement == QS60StylePrivate::SE_TabBarTabSouthActive ||
  1544                     skinElement==QS60StylePrivate::SE_TabBarTabWestActive) {
  1537                     skinElement==QS60StylePrivate::SE_TabBarTabWestActive) {
  1545                 const int borderThickness =
  1538                 const int borderThickness =
  1546                     QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth);
  1539                     QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth);
  1547                 const int tabOverlap =
  1540                 const int tabOverlap =
  1548                     QS60StylePrivate::pixelMetric(PM_TabBarTabOverlap) - borderThickness;
  1541                     QS60StylePrivate::pixelMetric(PM_TabBarTabOverlap) - borderThickness;
  1549 
  1542                 const bool usesScrollButtons = 
  1550                 if (skinElement==QS60StylePrivate::SE_TabBarTabEastInactive||
  1543                     (widget) ? (qobject_cast<const QTabBar*>(widget))->usesScrollButtons() : false;
  1551                         skinElement==QS60StylePrivate::SE_TabBarTabEastActive||
  1544                 const int roomForScrollButton = 
  1552                         skinElement==QS60StylePrivate::SE_TabBarTabWestInactive||
  1545                     usesScrollButtons ? QS60StylePrivate::pixelMetric(PM_TabBarScrollButtonWidth) : 0;
  1553                         skinElement==QS60StylePrivate::SE_TabBarTabWestActive){
  1546 
  1554                     optionTabAdj.rect.adjust(0, 0, 0, tabOverlap);
  1547                 // adjust for overlapping tabs and scrollbuttons, if necessary
       
  1548                 if (skinElement == QS60StylePrivate::SE_TabBarTabEastInactive ||
       
  1549                         skinElement == QS60StylePrivate::SE_TabBarTabEastActive ||
       
  1550                         skinElement == QS60StylePrivate::SE_TabBarTabWestInactive ||
       
  1551                         skinElement == QS60StylePrivate::SE_TabBarTabWestActive){
       
  1552                     if (optionTabAdj.position == QStyleOptionTabV3::Beginning)
       
  1553                         optionTabAdj.rect.adjust(0, roomForScrollButton, 0, tabOverlap);
       
  1554                     else if (optionTabAdj.position == QStyleOptionTabV3::End)
       
  1555                         optionTabAdj.rect.adjust(0, 0, 0, tabOverlap);
       
  1556                     else
       
  1557                         optionTabAdj.rect.adjust(0, 0, 0, tabOverlap);
  1555                 } else {
  1558                 } else {
  1556                     if (directionMirrored)
  1559                     if (directionMirrored) {
  1557                         optionTabAdj.rect.adjust(-tabOverlap, 0, 0, 0);
  1560                         if (optionTabAdj.position == QStyleOptionTabV3::Beginning)
  1558                     else
  1561                             optionTabAdj.rect.adjust(-tabOverlap, 0, -roomForScrollButton, 0);
  1559                         optionTabAdj.rect.adjust(0, 0, tabOverlap, 0);
  1562                         else
       
  1563                             optionTabAdj.rect.adjust(-tabOverlap, 0, 0, 0);
       
  1564                     } else {
       
  1565                         if (optionTabAdj.position == QStyleOptionTabV3::Beginning)
       
  1566                             optionTabAdj.rect.adjust(roomForScrollButton, 0, tabOverlap, 0);
       
  1567                         else
       
  1568                             optionTabAdj.rect.adjust(0, 0, tabOverlap, 0);
  1560                     }
  1569                     }
       
  1570                 }
  1561             }
  1571             }
  1562             QS60StylePrivate::drawSkinElement(skinElement, painter, optionTabAdj.rect, flags);
  1572             QS60StylePrivate::drawSkinElement(skinElement, painter, optionTabAdj.rect, flags);
  1563         }
  1573         }
  1564         break;
  1574         break;
  1565     case CE_TabBarTabLabel:
  1575     case CE_TabBarTabLabel:
  1568             QRect tr = optionTab.rect;
  1578             QRect tr = optionTab.rect;
  1569             const bool directionMirrored = (optionTab.direction == Qt::RightToLeft);
  1579             const bool directionMirrored = (optionTab.direction == Qt::RightToLeft);
  1570             const int borderThickness = QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth);
  1580             const int borderThickness = QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth);
  1571             const int tabOverlap =
  1581             const int tabOverlap =
  1572                 QS60StylePrivate::pixelMetric(PM_TabBarTabOverlap) - borderThickness;
  1582                 QS60StylePrivate::pixelMetric(PM_TabBarTabOverlap) - borderThickness;
  1573             const QRect windowRect = painter->window();
  1583             const bool usesScrollButtons = 
       
  1584                 (widget) ? (qobject_cast<const QTabBar*>(widget))->usesScrollButtons() : false;
       
  1585             const int roomForScrollButton = 
       
  1586                 usesScrollButtons ? QS60StylePrivate::pixelMetric(PM_TabBarScrollButtonWidth) : 0;
  1574 
  1587 
  1575             switch (tab->shape) {
  1588             switch (tab->shape) {
  1576                 case QTabBar::TriangularWest:
  1589                 case QTabBar::TriangularWest:
  1577                 case QTabBar::RoundedWest:
  1590                 case QTabBar::RoundedWest:
  1578                 case QTabBar::TriangularEast:
  1591                 case QTabBar::TriangularEast:
  1603             const bool verticalTabs = optionTab.shape == QTabBar::RoundedEast
  1616             const bool verticalTabs = optionTab.shape == QTabBar::RoundedEast
  1604                                 || optionTab.shape == QTabBar::RoundedWest
  1617                                 || optionTab.shape == QTabBar::RoundedWest
  1605                                 || optionTab.shape == QTabBar::TriangularEast
  1618                                 || optionTab.shape == QTabBar::TriangularEast
  1606                                 || optionTab.shape == QTabBar::TriangularWest;
  1619                                 || optionTab.shape == QTabBar::TriangularWest;
  1607 
  1620 
       
  1621             //make room for scrollbuttons
       
  1622             if (!verticalTabs) {
       
  1623                 if ((tab->position == QStyleOptionTabV3::Beginning && !directionMirrored))
       
  1624                     tr.adjust(roomForScrollButton, 0, 0, 0);
       
  1625                 else if ((tab->position == QStyleOptionTabV3::Beginning && directionMirrored))
       
  1626                     tr.adjust(0, 0, -roomForScrollButton, 0);
       
  1627             } else {
       
  1628                 if (tab->position == QStyleOptionTabV3::Beginning)
       
  1629                     tr.adjust(0, roomForScrollButton, 0, 0);
       
  1630             }
       
  1631 
  1608             if (verticalTabs) {
  1632             if (verticalTabs) {
  1609                 painter->save();
  1633                 painter->save();
  1610                 int newX, newY, newRotation;
  1634                 int newX, newY, newRotation;
  1611                 if (optionTab.shape == QTabBar::RoundedEast || optionTab.shape == QTabBar::TriangularEast) {
  1635                 if (optionTab.shape == QTabBar::RoundedEast || optionTab.shape == QTabBar::TriangularEast) {
  1612                     newX = tr.width();
  1636                     newX = tr.width();
  1634             int alignment = Qt::AlignCenter | Qt::TextShowMnemonic;
  1658             int alignment = Qt::AlignCenter | Qt::TextShowMnemonic;
  1635             if (!styleHint(SH_UnderlineShortcut, &optionTab, widget))
  1659             if (!styleHint(SH_UnderlineShortcut, &optionTab, widget))
  1636                 alignment |= Qt::TextHideMnemonic;
  1660                 alignment |= Qt::TextHideMnemonic;
  1637             if (!optionTab.icon.isNull()) {
  1661             if (!optionTab.icon.isNull()) {
  1638                 QSize iconSize = optionTab.iconSize;
  1662                 QSize iconSize = optionTab.iconSize;
  1639                 int iconExtent = pixelMetric(PM_TabBarIconSize);
  1663                 if (!iconSize.isValid()) {
  1640                 if (iconSize.height() > iconExtent || iconSize.width() > iconExtent)
  1664                     const int iconExtent = pixelMetric(PM_TabBarIconSize);
  1641                     iconSize = QSize(iconExtent, iconExtent);
  1665                     iconSize = QSize(iconExtent, iconExtent);
       
  1666                 }
  1642                 QPixmap tabIcon = optionTab.icon.pixmap(iconSize,
  1667                 QPixmap tabIcon = optionTab.icon.pixmap(iconSize,
  1643                     (optionTab.state & State_Enabled) ? QIcon::Normal : QIcon::Disabled);
  1668                     (optionTab.state & State_Enabled) ? QIcon::Normal : QIcon::Disabled);
  1644                 if (tab->text.isEmpty())
  1669                 if (tab->text.isEmpty())
  1645                     painter->drawPixmap(tr.center().x() - (tabIcon.height() >> 1),
  1670                     painter->drawPixmap(tr.center().x() - (tabIcon.height() >> 1),
  1646                                         tr.center().y() - (tabIcon.height() >> 1),
  1671                                         tr.center().y() - (tabIcon.height() >> 1),
  2018 
  2043 
  2019     switch (element) {
  2044     switch (element) {
  2020         case PE_FrameFocusRect: {
  2045         case PE_FrameFocusRect: {
  2021             //Draw themed highlight to radiobuttons and checkboxes.
  2046             //Draw themed highlight to radiobuttons and checkboxes.
  2022             //For other widgets skip, unless palette has been modified. In that case, draw with commonstyle.
  2047             //For other widgets skip, unless palette has been modified. In that case, draw with commonstyle.
  2023             if (option->palette.highlight().color() == QS60StylePrivate::themePalette()->highlight().color())
  2048             if (option->palette.highlight().color() == QS60StylePrivate::themePalette()->highlight().color()) {
  2024                 if ((qstyleoption_cast<const QStyleOptionFocusRect *>(option) &&
  2049                 if ((qstyleoption_cast<const QStyleOptionFocusRect *>(option) &&
  2025                     (qobject_cast<const QRadioButton *>(widget) || qobject_cast<const QCheckBox *>(widget))))
  2050                     (qobject_cast<const QRadioButton *>(widget) || qobject_cast<const QCheckBox *>(widget))))
  2026                         QS60StylePrivate::drawSkinElement(
  2051                         QS60StylePrivate::drawSkinElement(
  2027                             QS60StylePrivate::isWidgetPressed(widget) ? 
  2052                             QS60StylePrivate::isWidgetPressed(widget) ? 
  2028                                 QS60StylePrivate::SE_ListItemPressed : 
  2053                                 QS60StylePrivate::SE_ListItemPressed : 
  2029                                 QS60StylePrivate::SE_ListHighlight, painter, option->rect, flags);
  2054                                 QS60StylePrivate::SE_ListHighlight, painter, option->rect, flags);
  2030             else
  2055             } else {
  2031                 commonStyleDraws = true;
  2056                 commonStyleDraws = true;
  2032             }
  2057             }
       
  2058         }
  2033         break;
  2059         break;
  2034 #ifndef QT_NO_LINEEDIT
  2060 #ifndef QT_NO_LINEEDIT
  2035     case PE_PanelLineEdit:
  2061     case PE_PanelLineEdit:
  2036         if (const QStyleOptionFrame *lineEdit = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
  2062         if (const QStyleOptionFrame *lineEdit = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
  2037 #ifndef QT_NO_COMBOBOX
  2063 #ifndef QT_NO_COMBOBOX
  2327 #else
  2353 #else
  2328         if (true) {
  2354         if (true) {
  2329 #endif
  2355 #endif
  2330             QCommonStyle::drawPrimitive(element, option, painter, widget);
  2356             QCommonStyle::drawPrimitive(element, option, painter, widget);
  2331         } else {
  2357         } else {
  2332             const bool rightLine = option->state & State_Item;
  2358             if (const QStyleOptionViewItemV2 *vopt = qstyleoption_cast<const QStyleOptionViewItemV2 *>(option)) {
  2333             const bool downLine = option->state & State_Sibling;
  2359                 const bool rightLine = option->state & State_Item;
  2334             const bool upLine = option->state & (State_Open | State_Children | State_Item | State_Sibling);
  2360                 const bool downLine = option->state & State_Sibling;
  2335 
  2361                 const bool upLine = option->state & (State_Open | State_Children | State_Item | State_Sibling);
  2336             QS60StyleEnums::SkinParts skinPart;
  2362                 QS60StylePrivate::SkinElementFlags adjustedFlags = flags;
  2337             bool drawSkinPart = false;
  2363 
  2338             if (rightLine && downLine && upLine) {
  2364                 QS60StyleEnums::SkinParts skinPart;
  2339                 skinPart = QS60StyleEnums::SP_QgnIndiHlLineBranch;
  2365                 bool drawSkinPart = false;
  2340                 drawSkinPart = true;
  2366                 if (rightLine && downLine && upLine) {
  2341             } else if (rightLine && upLine) {
  2367                     skinPart = QS60StyleEnums::SP_QgnIndiHlLineBranch;
  2342                 skinPart = QS60StyleEnums::SP_QgnIndiHlLineEnd;
  2368                     drawSkinPart = true;
  2343                 drawSkinPart = true;
  2369                 } else if (rightLine && upLine) {
  2344             } else if (upLine && downLine) {
  2370                     skinPart = QS60StyleEnums::SP_QgnIndiHlLineEnd;
  2345                 skinPart = QS60StyleEnums::SP_QgnIndiHlLineStraight;
  2371                     drawSkinPart = true;
  2346                 drawSkinPart = true;
  2372                 } else if (upLine && downLine) {
  2347             }
  2373                     skinPart = QS60StyleEnums::SP_QgnIndiHlLineStraight;
  2348 
  2374                     drawSkinPart = true;
  2349             if (drawSkinPart)
       
  2350                 QS60StylePrivate::drawSkinPart(skinPart, painter, option->rect, flags);
       
  2351 
       
  2352             if (option->state & State_Children) {
       
  2353                 QS60StyleEnums::SkinParts skinPart =
       
  2354                         (option->state & State_Open) ? QS60StyleEnums::SP_QgnIndiHlColSuper : QS60StyleEnums::SP_QgnIndiHlExpSuper;
       
  2355                 int minDimension = qMin(option->rect.width(), option->rect.height());
       
  2356                 QRect iconRect(option->rect.topLeft(), QSize(minDimension, minDimension));
       
  2357                 const int magicTweak = 3;
       
  2358                 int resizeValue = minDimension >> 1;
       
  2359                 if (!QS60StylePrivate::isTouchSupported()) {
       
  2360                     minDimension += resizeValue; // Adjust the icon bigger because of empty space in svg icon.
       
  2361                     iconRect.setSize(QSize(minDimension, minDimension));
       
  2362                     const int verticalMagic = (option->rect.width() <= option->rect.height()) ? magicTweak : 0;
       
  2363                     resizeValue = verticalMagic - resizeValue;
       
  2364                 }
  2375                 }
  2365                 iconRect.translate(magicTweak, resizeValue);
  2376 
  2366                 QS60StylePrivate::drawSkinPart(skinPart, painter, iconRect, flags);
  2377                 if (option->direction == Qt::RightToLeft)
       
  2378                     adjustedFlags |= QS60StylePrivate::SF_Mirrored_X_Axis;
       
  2379 
       
  2380                 if (drawSkinPart)
       
  2381                     QS60StylePrivate::drawSkinPart(skinPart, painter, option->rect, adjustedFlags);
       
  2382 
       
  2383                 if (option->state & State_Children) {
       
  2384                     QS60StyleEnums::SkinParts skinPart =
       
  2385                             (option->state & State_Open) ? QS60StyleEnums::SP_QgnIndiHlColSuper : QS60StyleEnums::SP_QgnIndiHlExpSuper;
       
  2386                     const QRect selectionRect = subElementRect(SE_ItemViewItemCheckIndicator, vopt, widget);
       
  2387                     const int minDimension = qMin(option->rect.width(), option->rect.height());
       
  2388                     const int magicTweak = (option->direction == Qt::RightToLeft) ? -3 : 3; //@todo: magic
       
  2389                     //The branch indicator icon in S60 is supposed to be superimposed on top of branch lines.
       
  2390                     QRect iconRect(QPoint(option->rect.left() + magicTweak, selectionRect.top() + 1), QSize(minDimension, minDimension));
       
  2391                     if (!QS60StylePrivate::isTouchSupported())
       
  2392                         iconRect.translate(0, -4); //@todo: magic
       
  2393                     QS60StylePrivate::drawSkinPart(skinPart, painter, iconRect, adjustedFlags);
       
  2394                 }
  2367             }
  2395             }
  2368         }
  2396         }
  2369         break;
  2397         break;
  2370     case PE_PanelItemViewRow: // ### Qt 5: remove
  2398     case PE_PanelItemViewRow: // ### Qt 5: remove
  2371 #ifndef QT_NO_ITEMVIEWS
  2399 #ifndef QT_NO_ITEMVIEWS
  2444     if (widget && (metric == PM_LayoutTopMargin))
  2472     if (widget && (metric == PM_LayoutTopMargin))
  2445         if (widget->windowType() == Qt::Dialog)
  2473         if (widget->windowType() == Qt::Dialog)
  2446             //double the top layout margin for dialogs, it is very close to real value
  2474             //double the top layout margin for dialogs, it is very close to real value
  2447             //without having to define custom pixel metric
  2475             //without having to define custom pixel metric
  2448             metricValue *= 2;
  2476             metricValue *= 2;
       
  2477 
       
  2478     if (widget && (metric == PM_FocusFrameHMargin))
       
  2479         if (qobject_cast<const QTableView *>(widget))
       
  2480             //Halve the focus frame margin for table items
       
  2481             metricValue /= 2;
       
  2482 
  2449     return metricValue;
  2483     return metricValue;
  2450 }
  2484 }
  2451 
  2485 
  2452 /*! \reimp */
  2486 /*! \reimp */
  2453 QSize QS60Style::sizeFromContents(ContentsType ct, const QStyleOption *opt,
  2487 QSize QS60Style::sizeFromContents(ContentsType ct, const QStyleOption *opt,
  2469             if (const QAbstractButton *buttonWidget = (qobject_cast<const QAbstractButton *>(widget)))  {
  2503             if (const QAbstractButton *buttonWidget = (qobject_cast<const QAbstractButton *>(widget)))  {
  2470                 if (buttonWidget->isCheckable())
  2504                 if (buttonWidget->isCheckable())
  2471                     sz += QSize(pixelMetric(PM_IndicatorWidth) + pixelMetric(PM_CheckBoxLabelSpacing), 0);
  2505                     sz += QSize(pixelMetric(PM_IndicatorWidth) + pixelMetric(PM_CheckBoxLabelSpacing), 0);
  2472                 const int iconHeight = (!buttonWidget->icon().isNull()) ? buttonWidget->iconSize().height() : 0;
  2506                 const int iconHeight = (!buttonWidget->icon().isNull()) ? buttonWidget->iconSize().height() : 0;
  2473                 const int textHeight = (buttonWidget->text().length() > 0) ?
  2507                 const int textHeight = (buttonWidget->text().length() > 0) ?
  2474                     buttonWidget->fontMetrics().size(Qt::TextSingleLine, buttonWidget->text()).height() : 0;
  2508                     buttonWidget->fontMetrics().size(Qt::TextSingleLine, buttonWidget->text()).height() : opt->fontMetrics.height();
  2475                 const int decoratorHeight = (buttonWidget->isCheckable()) ? pixelMetric(PM_IndicatorHeight) : 0;
  2509                 const int decoratorHeight = (buttonWidget->isCheckable()) ? pixelMetric(PM_IndicatorHeight) : 0;
  2476 
  2510 
  2477                 const int contentHeight =
  2511                 const int contentHeight =
  2478                         qMax(qMax(iconHeight, decoratorHeight) + pixelMetric(PM_ButtonMargin),
  2512                         qMax(qMax(iconHeight, decoratorHeight) + pixelMetric(PM_ButtonMargin),
  2479                              textHeight + 2*pixelMetric(PM_ButtonMargin));
  2513                              textHeight + 2*pixelMetric(PM_ButtonMargin));
  2488         case CT_TabBarTab: {
  2522         case CT_TabBarTab: {
  2489                 const QSize naviPaneSize = QS60StylePrivate::naviPaneSize();
  2523                 const QSize naviPaneSize = QS60StylePrivate::naviPaneSize();
  2490                 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
  2524                 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
  2491                 if (naviPaneSize.height() > sz.height())
  2525                 if (naviPaneSize.height() > sz.height())
  2492                     sz.setHeight(naviPaneSize.height());
  2526                     sz.setHeight(naviPaneSize.height());
       
  2527                 // Adjust beginning tabbar item size, if scrollbuttons are used. This is to ensure that the
       
  2528                 // tabbar item content fits, since scrollbuttons are making beginning tabbar item smaller.
       
  2529                 int scrollButtonSize = 0;
       
  2530                 if (const QTabBar *tabBar = qobject_cast<const QTabBar *>(widget))
       
  2531                     scrollButtonSize = tabBar->usesScrollButtons() ? pixelMetric(PM_TabBarScrollButtonWidth) : 0;
       
  2532                 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
       
  2533                     const bool verticalTabs = tab->shape == QTabBar::RoundedEast
       
  2534                             || tab->shape == QTabBar::RoundedWest
       
  2535                             || tab->shape == QTabBar::TriangularEast
       
  2536                             || tab->shape == QTabBar::TriangularWest;
       
  2537                     if (tab->position == QStyleOptionTab::Beginning)
       
  2538                         sz += QSize(verticalTabs ? 0 : scrollButtonSize, !verticalTabs ? 0 : scrollButtonSize);
       
  2539                 }
  2493             }
  2540             }
  2494             break;
  2541             break;
  2495         case CT_MenuItem:
  2542         case CT_MenuItem:
  2496         case CT_ItemViewItem:
  2543         case CT_ItemViewItem:
  2497             if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
  2544             if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
  2955                     }
  3002                     }
  2956                 }
  3003                 }
  2957             }
  3004             }
  2958             break;
  3005             break;
  2959         case SE_ItemViewItemCheckIndicator:
  3006         case SE_ItemViewItemCheckIndicator:
  2960             if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(opt)) {
  3007             if (const QStyleOptionViewItemV2 *vopt = qstyleoption_cast<const QStyleOptionViewItemV2 *>(opt)) {
  2961                 const QListWidget *listItem = qobject_cast<const QListWidget *>(widget);
  3008                 const QListWidget *listItem = qobject_cast<const QListWidget *>(widget);
  2962 
  3009 
  2963                 const bool singleSelection = listItem &&
  3010                 const bool singleSelection = listItem &&
  2964                     (listItem->selectionMode() == QAbstractItemView::SingleSelection ||
  3011                     (listItem->selectionMode() == QAbstractItemView::SingleSelection ||
  2965                      listItem->selectionMode() == QAbstractItemView::NoSelection);
  3012                      listItem->selectionMode() == QAbstractItemView::NoSelection);