Changeset 769 for trunk/src/gui/styles/qs60style.cpp
- Timestamp:
- Aug 2, 2010, 9:27:30 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.6.3 (added) merged: 768 /branches/vendor/nokia/qt/current merged: 767 /branches/vendor/nokia/qt/4.6.2 removed
- Property svn:mergeinfo changed
-
trunk/src/gui/styles/qs60style.cpp
r651 r769 51 51 #include "qdial.h" 52 52 #include "qdialog.h" 53 #include "qmessagebox.h" 53 54 #include "qgroupbox.h" 54 55 #include "qheaderview.h" … … 62 63 #include "qscrollbar.h" 63 64 #include "qtabbar.h" 64 #include "qtablewidget.h"65 65 #include "qtableview.h" 66 66 #include "qtextedit.h" … … 93 93 const layoutHeader QS60StylePrivate::m_layoutHeaders[] = { 94 94 // *** generated layout data *** 95 {240,320,1,1 5,"QVGA Landscape"},96 {320,240,1,1 5,"QVGA Portrait"},97 {360,640,1,1 5,"NHD Landscape"},98 {640,360,1,1 5,"NHD Portrait"},95 {240,320,1,19,"QVGA Landscape"}, 96 {320,240,1,19,"QVGA Portrait"}, 97 {360,640,1,19,"NHD Landscape"}, 98 {640,360,1,19,"NHD Portrait"}, 99 99 {352,800,1,12,"E90 Landscape"} 100 100 // *** End of generated data *** … … 105 105 const short QS60StylePrivate::data[][MAX_PIXELMETRICS] = { 106 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,-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},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,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},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,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},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,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},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}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}, 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,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} 112 112 // *** End of generated data *** 113 113 }; … … 120 120 // theme palette 121 121 QPalette *QS60StylePrivate::m_themePalette = 0; 122 123 qint64 QS60StylePrivate::m_webPaletteKey = 0; 124 125 QPointer<QWidget> QS60StylePrivate::m_pressedWidget = 0; 122 126 123 127 const struct QS60StylePrivate::frameElementCenter QS60StylePrivate::m_frameElementsData[] = { … … 126 130 {SE_FrameLineEdit, QS60StyleEnums::SP_QsnFrInputCenter}, 127 131 {SE_ListHighlight, QS60StyleEnums::SP_QsnFrListCenter}, 128 {SE_ OptionsMenu,QS60StyleEnums::SP_QsnFrPopupCenter},132 {SE_PopupBackground, QS60StyleEnums::SP_QsnFrPopupCenter}, 129 133 {SE_SettingsList, QS60StyleEnums::SP_QsnFrSetOptCenter}, 130 134 {SE_TableItem, QS60StyleEnums::SP_QsnFrCaleCenter}, … … 137 141 {SE_ButtonInactive, QS60StyleEnums::SP_QsnFrButtonCenterInactive}, 138 142 {SE_Editor, QS60StyleEnums::SP_QsnFrInputCenter}, 143 {SE_TableItemPressed, QS60StyleEnums::SP_QsnFrGridCenterPressed}, 144 {SE_ListItemPressed, QS60StyleEnums::SP_QsnFrListPressed}, 139 145 }; 140 146 … … 249 255 drawFrame(SF_ListHighlight, painter, rect, flags | SF_PointNorth); 250 256 break; 251 case SE_ OptionsMenu:252 drawFrame(SF_ OptionsMenu, painter, rect, flags | SF_PointNorth);257 case SE_PopupBackground: 258 drawFrame(SF_PopupBackground, painter, rect, flags | SF_PointNorth); 253 259 break; 254 260 case SE_SettingsList: … … 290 296 drawFrame(SF_FrameLineEdit, painter, rect, flags | SF_PointNorth); 291 297 break; 298 case SE_DropArea: 299 drawPart(QS60StyleEnums::SP_QgnGrafOrgBgGrid, painter, rect, flags | SF_PointNorth); 300 break; 301 case SE_TableItemPressed: 302 drawFrame(SF_TableItemPressed, painter, rect, flags | SF_PointNorth); 303 break; 304 case SE_ListItemPressed: 305 drawFrame(SF_ListItemPressed, painter, rect, flags | SF_PointNorth); 306 break; 292 307 default: 293 308 break; … … 303 318 short QS60StylePrivate::pixelMetric(int metric) 304 319 { 320 //If it is a custom value, need to strip away the base to map to internal 321 //pixel metric value table 322 if (metric & QStyle::PM_CustomBase) { 323 metric -= QStyle::PM_CustomBase; 324 metric += MAX_NON_CUSTOM_PIXELMETRICS - 1; 325 } 326 305 327 Q_ASSERT(metric < MAX_PIXELMETRICS); 306 328 const short returnValue = m_pmPointer[metric]; … … 403 425 const bool cachedColorExists = m_colorCache.contains(frame); 404 426 if (!cachedColorExists) { 405 const int frameCornerWidth = pixelMetric(PM_ Custom_FrameCornerWidth);406 const int frameCornerHeight = pixelMetric(PM_ Custom_FrameCornerHeight);427 const int frameCornerWidth = pixelMetric(PM_FrameCornerWidth); 428 const int frameCornerHeight = pixelMetric(PM_FrameCornerHeight); 407 429 Q_ASSERT(2 * frameCornerWidth < 32); 408 430 Q_ASSERT(2 * frameCornerHeight < 32); … … 531 553 532 554 if (orientation == Qt::Horizontal) { 555 startRect.setHeight(rect.height()); 533 556 startRect.setWidth(qMin((rect.width() >> 1) - 1, startRect.width())); 534 557 endRect = startRect.translated(rect.width() - startRect.width(), 0); … … 540 563 } 541 564 } else { 565 startRect.setWidth(rect.width()); 542 566 startRect.setHeight(qMin((rect.height() >> 1) - 1, startRect.height())); 543 567 endRect = startRect.translated(0, rect.height() - startRect.height()); … … 626 650 } else if (qobject_cast<QGroupBox *>(widget)){ 627 651 fontCategory = QS60StyleEnums::FC_Title; 652 } else if (qobject_cast<QMessageBox *>(widget)){ 653 fontCategory = QS60StyleEnums::FC_Primary; 654 } else if (qobject_cast<QMenu *>(widget)){ 655 fontCategory = QS60StyleEnums::FC_Primary; 656 } else if (qobject_cast<QCalendarWidget *>(widget)){ 657 fontCategory = QS60StyleEnums::FC_Secondary; 628 658 } 629 659 if (fontCategory != QS60StyleEnums::FC_Undefined) { … … 755 785 widgetPalette = *palette; 756 786 787 widgetPalette.setColor(QPalette::Text, 788 s60Color(QS60StyleEnums::CL_QsnTextColors, 22, 0)); 789 widgetPalette.setColor(QPalette::HighlightedText, 790 s60Color(QS60StyleEnums::CL_QsnTextColors, 11, 0)); 791 QApplication::setPalette(widgetPalette, "QMenu"); 792 widgetPalette = *palette; 793 757 794 widgetPalette.setColor(QPalette::WindowText, 758 795 s60Color(QS60StyleEnums::CL_QsnTextColors, 4, 0)); 796 widgetPalette.setColor(QPalette::HighlightedText, 797 s60Color(QS60StyleEnums::CL_QsnTextColors, 3, 0)); 759 798 QApplication::setPalette(widgetPalette, "QTabBar"); 760 799 widgetPalette = *palette; 761 800 801 widgetPalette.setColor(QPalette::HighlightedText, 802 s60Color(QS60StyleEnums::CL_QsnTextColors, 10, 0)); 803 QApplication::setPalette(widgetPalette, "QListView"); 804 widgetPalette = *palette; 805 762 806 widgetPalette.setColor(QPalette::Text, 763 807 s60Color(QS60StyleEnums::CL_QsnTextColors, 22, 0)); 808 widgetPalette.setColor(QPalette::HighlightedText, 809 s60Color(QS60StyleEnums::CL_QsnTextColors, 11, 0)); 764 810 QApplication::setPalette(widgetPalette, "QTableView"); 765 811 widgetPalette = *palette; … … 770 816 s60Color(QS60StyleEnums::CL_QsnTextColors, 24, 0)); 771 817 QApplication::setPalette(widgetPalette, "QLineEdit"); 772 widgetPalette = *palette;773 774 widgetPalette.setColor(QPalette::Text,775 s60Color(QS60StyleEnums::CL_QsnTextColors, 27, 0));776 widgetPalette.setColor(QPalette::HighlightedText,777 s60Color(QS60StyleEnums::CL_QsnTextColors, 24, 0));778 818 QApplication::setPalette(widgetPalette, "QTextEdit"); 779 819 widgetPalette = *palette; … … 785 825 786 826 widgetPalette.setColor(QPalette::WindowText, s60Color(QS60StyleEnums::CL_QsnTextColors, 7, 0)); 827 widgetPalette.setColor(QPalette::HighlightedText, 828 s60Color(QS60StyleEnums::CL_QsnTextColors, 11, 0)); 787 829 QApplication::setPalette(widgetPalette, "QRadioButton"); 788 830 QApplication::setPalette(widgetPalette, "QCheckBox"); … … 805 847 webPalette.setColor(QPalette::WindowText, Qt::black); 806 848 webPalette.setColor(QPalette::Text, Qt::black); 849 webPalette.setBrush(QPalette::Base, Qt::white); 850 807 851 QApplication::setPalette(webPalette, "QWebView"); 808 852 QApplication::setPalette(webPalette, "QGraphicsWebView"); 853 854 m_webPaletteKey = webPalette.cacheKey(); 809 855 } 810 856 … … 831 877 case QS60StyleEnums::SP_QgnGrafNsliderEndRight: 832 878 case QS60StyleEnums::SP_QgnGrafNsliderMiddle: 833 result.setWidth(result.height() >> 1);834 879 break; 835 880 … … 842 887 case QS60StyleEnums::SP_QgnGrafBarFrameSideL: 843 888 case QS60StyleEnums::SP_QgnGrafBarFrameSideR: 844 result.setWidth(pixelMetric(PM_Custom_FrameCornerWidth)); 845 break; 846 847 case QS60StyleEnums::SP_QsnCpScrollHandleBottomPressed: 889 result.setWidth(pixelMetric(PM_FrameCornerWidth)); 890 break; 891 848 892 case QS60StyleEnums::SP_QsnCpScrollHandleTopPressed: 849 case QS60StyleEnums::SP_QsnCpScrollHandleMiddlePressed:850 893 case QS60StyleEnums::SP_QsnCpScrollBgBottom: 851 case QS60StyleEnums::SP_QsnCpScrollBgMiddle:852 894 case QS60StyleEnums::SP_QsnCpScrollBgTop: 853 895 case QS60StyleEnums::SP_QsnCpScrollHandleBottom: 896 case QS60StyleEnums::SP_QsnCpScrollHandleTop: 897 case QS60StyleEnums::SP_QsnCpScrollHandleBottomPressed: 898 result.setHeight(pixelMetric(QStyle::PM_ScrollBarExtent)); 899 result.setWidth(pixelMetric(QStyle::PM_ScrollBarExtent)); 900 break; 901 case QS60StyleEnums::SP_QsnCpScrollHandleMiddlePressed: 902 case QS60StyleEnums::SP_QsnCpScrollBgMiddle: 854 903 case QS60StyleEnums::SP_QsnCpScrollHandleMiddle: 855 case QS60StyleEnums::SP_QsnCpScrollHandleTop:856 904 result.setHeight(pixelMetric(QStyle::PM_ScrollBarExtent)); 857 905 result.setWidth(pixelMetric(QStyle::PM_ScrollBarSliderMin)); … … 866 914 case 6: /* CornerBl */ 867 915 case 5: /* CornerBr */ 868 result.setWidth(pixelMetric(PM_ Custom_FrameCornerWidth));916 result.setWidth(pixelMetric(PM_FrameCornerWidth)); 869 917 // Falltrough intended... 870 918 case 4: /* SideT */ 871 919 case 3: /* SideB */ 872 result.setHeight(pixelMetric(PM_ Custom_FrameCornerHeight));920 result.setHeight(pixelMetric(PM_FrameCornerHeight)); 873 921 break; 874 922 case 2: /* SideL */ 875 923 case 1: /* SideR */ 876 result.setWidth(pixelMetric(PM_ Custom_FrameCornerWidth));924 result.setWidth(pixelMetric(PM_FrameCornerWidth)); 877 925 break; 878 926 case 0: /* center */ … … 891 939 } 892 940 893 bool QS60StylePrivate::canDrawThemeBackground(const QBrush &backgroundBrush) 894 { 941 bool QS60StylePrivate::canDrawThemeBackground(const QBrush &backgroundBrush, const QWidget *widget) 942 { 943 // Always return true for web pages. 944 if (widget && m_webPaletteKey == QApplication::palette(widget).cacheKey()) 945 return true; 895 946 //If brush is not changed from style's default values, draw theme graphics. 896 947 return (backgroundBrush.color() == Qt::transparent || 897 948 backgroundBrush.style() == Qt::NoBrush) ? true : false; 949 } 950 951 bool QS60StylePrivate::isWidgetPressed(const QWidget *widget) 952 { 953 return (widget && widget == m_pressedWidget); 898 954 } 899 955 … … 936 992 QS60StylePrivate::drawSkinElement(grooveElement, painter, grooveRect, flags); 937 993 938 const QStyle::SubControls subControls = optionSlider->subControls;994 const SubControls subControls = optionSlider->subControls; 939 995 940 996 // select correct slider (horizontal/vertical/pressed) 941 const bool sliderPressed = ((optionSlider->state & QStyle::State_Sunken) && (subControls & SC_ScrollBarSlider));997 const bool sliderPressed = ((optionSlider->state & State_Sunken) && (subControls & SC_ScrollBarSlider)); 942 998 const QS60StylePrivate::SkinElements handleElement = 943 999 horizontal ? … … 960 1016 961 1017 //Highlight 962 /* if (optionSlider->state & QStyle::State_HasFocus)1018 /* if (optionSlider->state & State_HasFocus) 963 1019 drawPrimitive(PE_FrameFocusRect, optionSlider, painter, widget);*/ 964 1020 … … 970 1026 QS60StylePrivate::drawSkinElement(grooveElement, painter, sliderGroove, flags); 971 1027 } else { 972 const QRect sliderGroove = subControlRect(control, optionSlider, SC_SliderGroove, widget);973 1028 const QPoint sliderGrooveCenter = sliderGroove.center(); 974 1029 const bool horizontal = optionSlider->orientation == Qt::Horizontal; … … 986 1041 const QRect sliderHandle = subControlRect(control, optionSlider, SC_SliderHandle, widget); 987 1042 QS60StylePrivate::SkinElements handleElement; 988 if (optionSlider->state & QStyle::State_Sunken)1043 if (optionSlider->state & State_Sunken) 989 1044 handleElement = 990 1045 horizontal ? QS60StylePrivate::SE_SliderHandleSelectedHorizontal : QS60StylePrivate::SE_SliderHandleSelectedVertical; … … 1061 1116 tool.state = bflags; 1062 1117 const QToolButton *toolButtonWidget = qobject_cast<const QToolButton *>(widget); 1063 QS60StylePrivate::SkinElements element; 1064 if (toolButtonWidget) 1065 element = (toolButtonWidget->isDown()) ? QS60StylePrivate::SE_ToolBarButtonPressed : QS60StylePrivate::SE_ToolBarButton; 1066 else 1067 element = (option->state & State_Sunken) ? QS60StylePrivate::SE_ToolBarButtonPressed : QS60StylePrivate::SE_ToolBarButton; 1118 const QS60StylePrivate::SkinElements element = 1119 ((toolButtonWidget && toolButtonWidget->isDown()) || (option->state & State_Sunken)) ? 1120 QS60StylePrivate::SE_ToolBarButtonPressed : QS60StylePrivate::SE_ToolBarButton; 1068 1121 QS60StylePrivate::drawSkinElement(element, painter, tool.rect, flags); 1069 1122 drawPrimitive(PE_PanelButtonTool, &tool, painter, widget); … … 1097 1150 } 1098 1151 1099 if (toolBtn->text.length() >0 ||1152 if (toolBtn->text.length() > 0 || 1100 1153 !toolBtn->icon.isNull()) { 1101 1154 const int frameWidth = pixelMetric(PM_DefaultFrameWidth, option, widget); … … 1173 1226 const QRect textRect = subControlRect(CC_GroupBox, option, SC_GroupBoxLabel, widget); 1174 1227 const QRect checkBoxRect = subControlRect(CC_GroupBox, option, SC_GroupBoxCheckBox, widget); 1175 if (groupBox->subControls & QStyle::SC_GroupBoxFrame) {1228 if (groupBox->subControls & SC_GroupBoxFrame) { 1176 1229 QStyleOptionFrameV2 frame; 1177 1230 frame.QStyleOption::operator=(*groupBox); … … 1184 1237 1185 1238 // Draw title 1186 if ((groupBox->subControls & QStyle::SC_GroupBoxLabel) && !groupBox->text.isEmpty()) {1239 if ((groupBox->subControls & SC_GroupBoxLabel) && !groupBox->text.isEmpty()) { 1187 1240 const QColor textColor = groupBox->textColor; 1188 1241 painter->save(); … … 1191 1244 painter->setPen(textColor); 1192 1245 int alignment = int(groupBox->textAlignment); 1193 if (!styleHint( QStyle::SH_UnderlineShortcut, option, widget))1246 if (!styleHint(SH_UnderlineShortcut, option, widget)) 1194 1247 alignment |= Qt::TextHideMnemonic; 1195 1248 … … 1227 1280 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) { 1228 1281 bool isRadio = (element == CE_RadioButton); 1282 QStyleOptionButton subopt = *btn; 1283 1229 1284 // Highlight needs to be drawn first, as it goes "underneath" the text and indicator. 1230 1285 if (btn->state & State_HasFocus) { … … 1234 1289 : SE_CheckBoxFocusRect, btn, widget); 1235 1290 drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget); 1291 1292 subopt.palette.setColor(QPalette::Active, QPalette::WindowText, 1293 subopt.palette.highlightedText().color()); 1236 1294 } 1237 QStyleOptionButton subopt = *btn;1238 1295 1239 1296 subopt.rect = subElementRect(isRadio ? SE_RadioButtonIndicator … … 1260 1317 case CE_PushButtonBevel: 1261 1318 if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) { 1262 const bool isDisabled = !(option->state & QStyle::State_Enabled);1319 const bool isDisabled = !(option->state & State_Enabled); 1263 1320 const bool isFlat = button->features & QStyleOptionButton::Flat; 1264 1321 QS60StyleEnums::SkinParts skinPart; 1265 1322 QS60StylePrivate::SkinElements skinElement; 1266 1323 if (!isDisabled) { 1267 const bool isPressed = (option->state & QStyle::State_Sunken) ||1268 (option->state & QStyle::State_On);1324 const bool isPressed = (option->state & State_Sunken) || 1325 (option->state & State_On); 1269 1326 if (isFlat) { 1270 1327 skinPart = … … 1291 1348 QStyleOptionToolButton optionToolButton = *toolBtn; 1292 1349 1293 if (!optionToolButton.icon.isNull() && (optionToolButton.state & QStyle::State_Sunken)1350 if (!optionToolButton.icon.isNull() && (optionToolButton.state & State_Sunken) 1294 1351 && (optionToolButton.state & State_Enabled)) { 1295 1352 … … 1313 1370 optionComboBox.palette.text().color() ); 1314 1371 QRect editRect = subControlRect(CC_ComboBox, comboBox, SC_ComboBoxEditField, widget); 1315 painter->save(); 1316 painter->setClipRect(editRect); 1372 const int frameW = proxy()->pixelMetric(PM_DefaultFrameWidth, option, widget); 1317 1373 1318 1374 if (!comboBox->currentIcon.isNull()) { 1319 QIcon::Mode mode = comboBox->state & State_Enabled ? QIcon::Normal : QIcon::Disabled;1320 QPixmap pixmap = comboBox->currentIcon.pixmap(comboBox->iconSize, mode);1375 const QIcon::Mode mode = comboBox->state & State_Enabled ? QIcon::Normal : QIcon::Disabled; 1376 const QPixmap pixmap = comboBox->currentIcon.pixmap(comboBox->iconSize, mode); 1321 1377 QRect iconRect(editRect); 1322 iconRect.setWidth(comboBox->iconSize.width() + 4);1378 iconRect.setWidth(comboBox->iconSize.width() + frameW); 1323 1379 iconRect = alignedRect(comboBox->direction, 1324 1380 Qt::AlignLeft | Qt::AlignVCenter, … … 1329 1385 1330 1386 if (comboBox->direction == Qt::RightToLeft) 1331 editRect. translate(-4 - comboBox->iconSize.width(), 0);1387 editRect.setRight(editRect.right() - frameW - comboBox->iconSize.width()); 1332 1388 else 1333 editRect. translate(comboBox->iconSize.width() + 4, 0);1389 editRect.setLeft(comboBox->iconSize.width() + frameW); 1334 1390 } 1335 1391 if (!comboBox->currentText.isEmpty() && !comboBox->editable) { 1392 const Qt::TextElideMode elideMode = (comboBox->direction == Qt::LeftToRight) ? Qt::ElideRight : Qt::ElideLeft; 1393 const QString text = comboBox->fontMetrics.elidedText(comboBox->currentText, elideMode, editRect.width()); 1394 1336 1395 QCommonStyle::drawItemText(painter, 1337 editRect.adjusted(QS60StylePrivate::pixelMetric(PM_ Custom_FrameCornerWidth), 0, -1, 0),1396 editRect.adjusted(QS60StylePrivate::pixelMetric(PM_FrameCornerWidth), 0, -1, 0), 1338 1397 visualAlignment(comboBox->direction, Qt::AlignLeft | Qt::AlignVCenter), 1339 comboBox->palette, comboBox->state & State_Enabled, comboBox->currentText); 1340 } 1341 painter->restore(); 1398 comboBox->palette, comboBox->state & State_Enabled, text); 1399 } 1342 1400 } 1343 1401 break; … … 1350 1408 1351 1409 painter->setClipRect(voptAdj.rect); 1352 const bool isSelected = (vopt->state & QStyle::State_Selected);1353 const bool hasFocus = (vopt->state & QStyle::State_HasFocus);1410 const bool isSelected = (vopt->state & State_Selected); 1411 const bool hasFocus = (vopt->state & State_HasFocus); 1354 1412 1355 1413 bool isScrollBarVisible = false; … … 1380 1438 if (vopt->backgroundBrush == Qt::NoBrush) { 1381 1439 if (itemView) { 1382 const QModelIndex index = vopt->index;1383 //todo: Draw cell background only once - for the first cell.1384 QStyleOptionViewItemV4 voptAdj2 = voptAdj;1385 const QModelIndex indexFirst = itemView->model()->index(0, 0);1386 const QModelIndex indexLast = itemView->model()->index(1387 itemView->model()->rowCount() - 1, itemView->model()->columnCount() -1);1388 if (itemView->viewport())1389 voptAdj2.rect = QRect( itemView->visualRect(indexFirst).topLeft(),1390 itemView->visualRect(indexLast).bottomRight()).intersect(itemView->viewport()->rect());1391 1440 drawPrimitive(PE_PanelItemViewItem, &voptAdj, painter, widget); 1392 1441 } 1393 1442 } else { QCommonStyle::drawPrimitive(PE_PanelItemViewItem, &voptAdj, painter, widget);} 1394 1443 1395 // draw the focus rect1396 if (isSelected | hasFocus) {1397 QRect highlightRect = option->rect.adjusted(1,1,-1,-1);1398 QAbstractItemView::SelectionBehavior selectionBehavior =1399 itemView ? itemView->selectionBehavior() : QAbstractItemView::SelectItems;1400 if (selectionBehavior != QAbstractItemView::SelectItems) {1401 // set highlight rect so that it is continuous from cell to cell, yet sligthly1402 // smaller than cell rect1403 int xBeginning = 0, yBeginning = 0, xEnd = 0, yEnd = 0;1404 if (selectionBehavior == QAbstractItemView::SelectRows) {1405 yBeginning = 1; yEnd = -1;1406 if (vopt->viewItemPosition == QStyleOptionViewItemV4::Beginning)1407 xBeginning = 1;1408 else if (vopt->viewItemPosition == QStyleOptionViewItemV4::End)1409 xEnd = -1;1410 } else if (selectionBehavior == QAbstractItemView::SelectColumns) {1411 xBeginning = 1; xEnd = -1;1412 if (vopt->viewItemPosition == QStyleOptionViewItemV4::Beginning)1413 yBeginning = 1;1414 else if (vopt->viewItemPosition == QStyleOptionViewItemV4::End)1415 yEnd = -1;1416 }1417 highlightRect = option->rect.adjusted(xBeginning, yBeginning, xEnd, yEnd);1418 }1419 if (vopt->showDecorationSelected &&1420 (vopt->palette.highlight().color() == QS60StylePrivate::themePalette()->highlight().color()))1421 QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ListHighlight, painter, highlightRect, flags);1422 else1423 painter->fillRect(highlightRect, vopt->palette.highlight());1424 }1425 1426 1444 // draw the icon 1427 const QIcon::Mode mode = (voptAdj.state & QStyle::State_Enabled) ? QIcon::Normal : QIcon::Disabled;1428 const QIcon::State state = voptAdj.state & QStyle::State_Open? QIcon::On : QIcon::Off;1445 const QIcon::Mode mode = (voptAdj.state & State_Enabled) ? QIcon::Normal : QIcon::Disabled; 1446 const QIcon::State state = (voptAdj.state & State_Open) ? QIcon::On : QIcon::Off; 1429 1447 voptAdj.icon.paint(painter, iconRect, voptAdj.decorationAlignment, mode, state); 1430 1448 … … 1433 1451 const bool singleSelection = 1434 1452 (itemView->selectionMode() == QAbstractItemView::SingleSelection || 1435 itemView->selectionMode() == QAbstractItemView::NoSelection); 1453 itemView->selectionMode() == QAbstractItemView::NoSelection)|| 1454 (itemView->selectionModel()->selectedIndexes().count() < 2 ); 1455 1456 const bool selectItemsOnly = (itemView->selectionBehavior() == QAbstractItemView::SelectItems); 1457 1436 1458 const QRect selectionRect = subElementRect(SE_ItemViewItemCheckIndicator, &voptAdj, widget); 1437 1459 1438 1460 QStyleOptionViewItemV4 checkMarkOption(voptAdj); 1461 if (selectionRect.isValid()) 1462 checkMarkOption.rect = selectionRect; 1439 1463 // Draw selection mark. 1440 if ( voptAdj.state & QStyle::State_Selected && !singleSelection) {1441 checkMarkOption.rect = selectionRect;1442 drawPrimitive(QStyle::PE_IndicatorViewItemCheck, &checkMarkOption, painter, widget);1443 if ( textRect.right() > selectionRect.left())1464 if (isSelected && !singleSelection && selectItemsOnly) { 1465 proxy()->drawPrimitive(PE_IndicatorViewItemCheck, &checkMarkOption, painter, widget); 1466 // @todo: this should happen in the rect retrievel i.e. subElementRect() 1467 if (textRect.right() > selectionRect.left()) 1444 1468 textRect.setRight(selectionRect.left()); 1445 1469 } else if (singleSelection && 1446 voptAdj.features & QStyleOptionViewItemV2::HasCheckIndicator && 1447 selectionRect.isValid()) { 1448 checkMarkOption.rect = selectionRect; 1449 checkMarkOption.state = checkMarkOption.state & ~QStyle::State_HasFocus; 1470 voptAdj.features & QStyleOptionViewItemV2::HasCheckIndicator) { 1471 checkMarkOption.state = checkMarkOption.state & ~State_HasFocus; 1450 1472 1451 1473 switch (vopt->checkState) { 1452 1474 case Qt::Unchecked: 1453 checkMarkOption.state |= QStyle::State_Off;1475 checkMarkOption.state |= State_Off; 1454 1476 break; 1455 1477 case Qt::PartiallyChecked: 1456 checkMarkOption.state |= QStyle::State_NoChange;1478 checkMarkOption.state |= State_NoChange; 1457 1479 break; 1458 1480 case Qt::Checked: 1459 checkMarkOption.state |= QStyle::State_On;1481 checkMarkOption.state |= State_On; 1460 1482 break; 1461 1483 } 1462 drawPrimitive( QStyle::PE_IndicatorViewItemCheck, &checkMarkOption, painter, widget);1484 drawPrimitive(PE_IndicatorViewItemCheck, &checkMarkOption, painter, widget); 1463 1485 } 1464 1486 } … … 1466 1488 // draw the text 1467 1489 if (!voptAdj.text.isEmpty()) { 1468 if (isSelected) { 1469 if (qobject_cast<const QTableView *>(widget)) 1470 voptAdj.palette.setColor( 1471 QPalette::Text, QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnTextColors, 11, 0)); 1472 else 1473 voptAdj.palette.setColor( 1474 QPalette::Text, QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnTextColors, 10, 0)); 1475 } 1476 painter->setPen(voptAdj.palette.text().color()); 1490 if (isSelected || hasFocus ) 1491 painter->setPen(voptAdj.palette.highlightedText().color()); 1492 else 1493 painter->setPen(voptAdj.palette.text().color()); 1477 1494 d->viewItemDrawText(painter, &voptAdj, textRect); 1478 1495 } … … 1485 1502 if (const QStyleOptionTabV3 *optionTab = qstyleoption_cast<const QStyleOptionTabV3 *>(option)) { 1486 1503 QStyleOptionTabV3 optionTabAdj = *optionTab; 1487 const bool isSelected = optionTab->state & QStyle::State_Selected;1504 const bool isSelected = optionTab->state & State_Selected; 1488 1505 const bool directionMirrored = (optionTab->direction == Qt::RightToLeft); 1489 1506 QS60StylePrivate::SkinElements skinElement; … … 1511 1528 break; 1512 1529 } 1513 if (skinElement ==QS60StylePrivate::SE_TabBarTabEastInactive||1514 skinElement ==QS60StylePrivate::SE_TabBarTabNorthInactive||1515 skinElement ==QS60StylePrivate::SE_TabBarTabSouthInactive||1516 skinElement ==QS60StylePrivate::SE_TabBarTabWestInactive||1517 skinElement ==QS60StylePrivate::SE_TabBarTabEastActive||1518 skinElement ==QS60StylePrivate::SE_TabBarTabNorthActive||1519 skinElement ==QS60StylePrivate::SE_TabBarTabSouthActive||1530 if (skinElement == QS60StylePrivate::SE_TabBarTabEastInactive || 1531 skinElement == QS60StylePrivate::SE_TabBarTabNorthInactive || 1532 skinElement == QS60StylePrivate::SE_TabBarTabSouthInactive || 1533 skinElement == QS60StylePrivate::SE_TabBarTabWestInactive || 1534 skinElement == QS60StylePrivate::SE_TabBarTabEastActive || 1535 skinElement == QS60StylePrivate::SE_TabBarTabNorthActive || 1536 skinElement == QS60StylePrivate::SE_TabBarTabSouthActive || 1520 1537 skinElement==QS60StylePrivate::SE_TabBarTabWestActive) { 1521 1538 const int borderThickness = 1522 QS60StylePrivate::pixelMetric( QStyle::PM_DefaultFrameWidth);1539 QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth); 1523 1540 const int tabOverlap = 1524 QS60StylePrivate::pixelMetric(QStyle::PM_TabBarTabOverlap) - borderThickness; 1525 //todo: draw navi wipe behind tabbar - must be drawn with first draw 1526 1527 if (skinElement==QS60StylePrivate::SE_TabBarTabEastInactive|| 1528 skinElement==QS60StylePrivate::SE_TabBarTabEastActive|| 1529 skinElement==QS60StylePrivate::SE_TabBarTabWestInactive|| 1530 skinElement==QS60StylePrivate::SE_TabBarTabWestActive){ 1531 optionTabAdj.rect.adjust(0, 0, 0, tabOverlap); 1541 QS60StylePrivate::pixelMetric(PM_TabBarTabOverlap) - borderThickness; 1542 const bool usesScrollButtons = 1543 (widget) ? (qobject_cast<const QTabBar*>(widget))->usesScrollButtons() : false; 1544 const int roomForScrollButton = 1545 usesScrollButtons ? QS60StylePrivate::pixelMetric(PM_TabBarScrollButtonWidth) : 0; 1546 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); 1532 1558 } else { 1533 if (directionMirrored) 1534 optionTabAdj.rect.adjust(-tabOverlap, 0, 0, 0); 1535 else 1536 optionTabAdj.rect.adjust(0, 0, tabOverlap, 0); 1559 if (directionMirrored) { 1560 if (optionTabAdj.position == QStyleOptionTabV3::Beginning) 1561 optionTabAdj.rect.adjust(-tabOverlap, 0, -roomForScrollButton, 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); 1537 1569 } 1570 } 1538 1571 } 1539 1572 QS60StylePrivate::drawSkinElement(skinElement, painter, optionTabAdj.rect, flags); … … 1545 1578 QRect tr = optionTab.rect; 1546 1579 const bool directionMirrored = (optionTab.direction == Qt::RightToLeft); 1547 const int borderThickness = QS60StylePrivate::pixelMetric( QStyle::PM_DefaultFrameWidth);1580 const int borderThickness = QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth); 1548 1581 const int tabOverlap = 1549 QS60StylePrivate::pixelMetric(QStyle::PM_TabBarTabOverlap) - borderThickness; 1550 const QRect windowRect = painter->window(); 1582 QS60StylePrivate::pixelMetric(PM_TabBarTabOverlap) - borderThickness; 1583 const bool usesScrollButtons = 1584 (widget) ? (qobject_cast<const QTabBar*>(widget))->usesScrollButtons() : false; 1585 const int roomForScrollButton = 1586 usesScrollButtons ? QS60StylePrivate::pixelMetric(PM_TabBarScrollButtonWidth) : 0; 1551 1587 1552 1588 switch (tab->shape) { … … 1576 1612 if (selected) 1577 1613 optionTab.palette.setColor(QPalette::Active, QPalette::WindowText, 1578 QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnTextColors, 3, option));1614 optionTab.palette.highlightedText().color()); 1579 1615 1580 1616 const bool verticalTabs = optionTab.shape == QTabBar::RoundedEast … … 1582 1618 || optionTab.shape == QTabBar::TriangularEast 1583 1619 || optionTab.shape == QTabBar::TriangularWest; 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 } 1584 1631 1585 1632 if (verticalTabs) { … … 1601 1648 painter->setTransform(m, true); 1602 1649 } 1603 tr.adjust(0, 0, pixelMetric( QStyle::PM_TabBarTabShiftHorizontal, tab, widget),1604 pixelMetric( QStyle::PM_TabBarTabShiftVertical, tab, widget));1650 tr.adjust(0, 0, pixelMetric(PM_TabBarTabShiftHorizontal, tab, widget), 1651 pixelMetric(PM_TabBarTabShiftVertical, tab, widget)); 1605 1652 1606 1653 if (selected) { 1607 tr.setBottom(tr.bottom() - pixelMetric( QStyle::PM_TabBarTabShiftVertical, tab, widget));1608 tr.setRight(tr.right() - pixelMetric( QStyle::PM_TabBarTabShiftHorizontal, tab, widget));1654 tr.setBottom(tr.bottom() - pixelMetric(PM_TabBarTabShiftVertical, tab, widget)); 1655 tr.setRight(tr.right() - pixelMetric(PM_TabBarTabShiftHorizontal, tab, widget)); 1609 1656 } 1610 1657 … … 1614 1661 if (!optionTab.icon.isNull()) { 1615 1662 QSize iconSize = optionTab.iconSize; 1616 i nt iconExtent = pixelMetric(PM_TabBarIconSize);1617 if (iconSize.height() > iconExtent || iconSize.width() > iconExtent)1663 if (!iconSize.isValid()) { 1664 const int iconExtent = pixelMetric(PM_TabBarIconSize); 1618 1665 iconSize = QSize(iconExtent, iconExtent); 1666 } 1619 1667 QPixmap tabIcon = optionTab.icon.pixmap(iconSize, 1620 1668 (optionTab.state & State_Enabled) ? QIcon::Normal : QIcon::Disabled); … … 1627 1675 tr.center().y() - (tabIcon.height() >> 1), 1628 1676 tabIcon); 1629 tr.setLeft(tr.left() + iconSize.width() + 4); 1677 tr.setLeft(tr.left() + iconSize.width() + 4); //todo: magic four 1630 1678 } 1631 1679 … … 1709 1757 text_flags |= Qt::TextHideMnemonic; 1710 1758 1711 if ((option->state & State_Selected) && (option->state & State_Enabled)) 1759 const bool selected = (option->state & State_Selected) && (option->state & State_Enabled); 1760 if (selected) 1712 1761 QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ListHighlight, painter, option->rect, flags); 1713 1762 … … 1716 1765 1717 1766 //todo: move the vertical spacing stuff into subElementRect 1718 const int vSpacing = QS60StylePrivate::pixelMetric( QStyle::PM_LayoutVerticalSpacing);1767 const int vSpacing = QS60StylePrivate::pixelMetric(PM_LayoutVerticalSpacing); 1719 1768 if (checkable){ 1720 const int hSpacing = QS60StylePrivate::pixelMetric( QStyle::PM_LayoutHorizontalSpacing);1769 const int hSpacing = QS60StylePrivate::pixelMetric(PM_LayoutHorizontalSpacing); 1721 1770 QStyleOptionMenuItem optionCheckBox; 1722 1771 optionCheckBox.QStyleOptionMenuItem::operator=(*menuItem); 1723 1772 optionCheckBox.rect.setWidth(pixelMetric(PM_IndicatorWidth)); 1724 1773 optionCheckBox.rect.setHeight(pixelMetric(PM_IndicatorHeight)); 1774 optionCheckBox.rect.moveCenter(QPoint( 1775 optionCheckBox.rect.center().x(), 1776 menuItem->rect.center().y())); 1725 1777 const int moveByX = optionCheckBox.rect.width() + vSpacing; 1726 1778 if (optionMenuItem.direction == Qt::LeftToRight) { … … 1756 1808 arrowOptions.QStyleOption::operator=(*menuItem); 1757 1809 const int indicatorWidth = (pixelMetric(PM_ListViewIconSize, option, widget) >> 1) + 1758 pixelMetric( QStyle::PM_LayoutVerticalSpacing, option, widget);1810 pixelMetric(PM_LayoutVerticalSpacing, option, widget); 1759 1811 if (optionMenuItem.direction == Qt::LeftToRight) 1760 1812 arrowOptions.rect.setLeft(textRect.right()); … … 1779 1831 painter->setOpacity(0.5); 1780 1832 } 1833 if (selected) 1834 optionMenuItem.palette.setColor( 1835 QPalette::Active, QPalette::Text, optionMenuItem.palette.highlightedText().color()); 1836 1781 1837 QCommonStyle::drawItemText(painter, textRect, text_flags, 1782 1838 optionMenuItem.palette, enabled, … … 1800 1856 QPen linePen = QPen(QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnLineColors, 1, header)); 1801 1857 const int penWidth = (header->orientation == Qt::Horizontal) ? 1802 linePen.width() + QS60StylePrivate::pixelMetric(PM_ Custom_BoldLineWidth)1803 : linePen.width() + QS60StylePrivate::pixelMetric(PM_ Custom_ThinLineWidth);1858 linePen.width() + QS60StylePrivate::pixelMetric(PM_BoldLineWidth) 1859 : linePen.width() + QS60StylePrivate::pixelMetric(PM_ThinLineWidth); 1804 1860 linePen.setWidth(penWidth); 1805 1861 painter->setPen(linePen); … … 1820 1876 QStyleOptionHeader subopt = *header; 1821 1877 const int borderTweak = 1822 QS60StylePrivate::pixelMetric(PM_ Custom_FrameCornerWidth) >> 1;1878 QS60StylePrivate::pixelMetric(PM_FrameCornerWidth) >> 1; 1823 1879 if (subopt.direction == Qt::LeftToRight) 1824 1880 subopt.rect.adjust(borderTweak, borderTweak, 0, -borderTweak); … … 1896 1952 if (const QTextEdit *textEdit = qobject_cast<const QTextEdit *>(widget)) { 1897 1953 const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(option); 1898 if (QS60StylePrivate::canDrawThemeBackground(frame->palette.base() ))1954 if (QS60StylePrivate::canDrawThemeBackground(frame->palette.base(), widget)) 1899 1955 QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_Editor, painter, option->rect, flags); 1900 1956 else … … 1928 1984 break; 1929 1985 case CE_FocusFrame: { 1930 // The pen width should nearly fill the layoutspacings around the widget1931 const int penWidth =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 widgets1934 1935 1986 #ifdef QT_KEYPAD_NAVIGATION 1936 1987 bool editFocus = false; … … 1939 1990 editFocus = true; 1940 1991 } 1941 const qreal opacity = editFocus ? 0.65 : 0.45; // Trial and error factors. Feel free to improve.1992 const qreal opacity = editFocus ? 1 : 0.75; // Trial and error factors. Feel free to improve. 1942 1993 #else 1943 const qreal opacity = 0. 5;1994 const qreal opacity = 0.85; 1944 1995 #endif 1945 // Because of Qts coordinate system, we need to tweak the rect by .5 pixels, otherwise it gets blurred. 1946 const qreal rectAdjustment = (penWidth % 2) ? -.5 : 0; 1947 1948 // Make sure that the pen stroke is inside the rect 1949 const QRectF adjustedRect = 1950 QRectF(option->rect).adjusted( 1951 rectAdjustment + penWidth, 1952 rectAdjustment + penWidth, 1953 -rectAdjustment - penWidth, 1954 -rectAdjustment - penWidth 1955 ); 1956 1957 const qreal roundRectRadius = penWidth * goldenRatio; 1996 // We need to reduce the focus frame size if LayoutSpacing is smaller than FocusFrameMargin 1997 // Otherwise, we would overlay adjacent widgets. 1998 const int frameHeightReduction = 1999 qMin(0, pixelMetric(PM_LayoutVerticalSpacing) 2000 - pixelMetric(PM_FocusFrameVMargin)); 2001 const int frameWidthReduction = 2002 qMin(0, pixelMetric(PM_LayoutHorizontalSpacing) 2003 - pixelMetric(PM_FocusFrameHMargin)); 2004 const int rounding = 2005 qMin(pixelMetric(PM_FocusFrameVMargin), 2006 pixelMetric(PM_LayoutVerticalSpacing)); 2007 const QRect frameRect = 2008 option->rect.adjusted(-frameWidthReduction, -frameHeightReduction, 2009 frameWidthReduction, frameHeightReduction); 2010 QPainterPath framePath; 2011 framePath.addRoundedRect(frameRect, rounding, rounding); 1958 2012 1959 2013 painter->save(); 1960 2014 painter->setRenderHint(QPainter::Antialiasing); 1961 2015 painter->setOpacity(opacity); 1962 painter->setPen(QPen(option->palette.color(QPalette::Text), penWidth)); 1963 painter->drawRoundedRect(adjustedRect, roundRectRadius, roundRectRadius); 2016 painter->fillPath(framePath, option->palette.color(QPalette::Text)); 1964 2017 painter->restore(); 1965 2018 } … … 1986 2039 void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const 1987 2040 { 1988 Q_D(const QS60Style);1989 2041 const QS60StylePrivate::SkinElementFlags flags = (option->state & State_Enabled) ? QS60StylePrivate::SF_StateEnabled : QS60StylePrivate::SF_StateDisabled; 1990 2042 bool commonStyleDraws = false; … … 1994 2046 //Draw themed highlight to radiobuttons and checkboxes. 1995 2047 //For other widgets skip, unless palette has been modified. In that case, draw with commonstyle. 1996 if (option->palette.highlight().color() == QS60StylePrivate::themePalette()->highlight().color()) 2048 if (option->palette.highlight().color() == QS60StylePrivate::themePalette()->highlight().color()) { 1997 2049 if ((qstyleoption_cast<const QStyleOptionFocusRect *>(option) && 1998 2050 (qobject_cast<const QRadioButton *>(widget) || qobject_cast<const QCheckBox *>(widget)))) 1999 QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ListHighlight, painter, option->rect, flags); 2000 else 2051 QS60StylePrivate::drawSkinElement( 2052 QS60StylePrivate::isWidgetPressed(widget) ? 2053 QS60StylePrivate::SE_ListItemPressed : 2054 QS60StylePrivate::SE_ListHighlight, painter, option->rect, flags); 2055 } else { 2001 2056 commonStyleDraws = true; 2002 2057 } 2058 } 2003 2059 break; 2004 2060 #ifndef QT_NO_LINEEDIT … … 2009 2065 break; 2010 2066 #endif 2011 if (QS60StylePrivate::canDrawThemeBackground(option->palette.base() ))2067 if (QS60StylePrivate::canDrawThemeBackground(option->palette.base(), widget)) 2012 2068 QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_FrameLineEdit, painter, option->rect, flags); 2013 2069 else … … 2018 2074 case PE_IndicatorCheckBox: { 2019 2075 // Draw checkbox indicator as color skinned graphics. 2020 const QS60StyleEnums::SkinParts skinPart = (option->state & QStyle::State_On) ?2076 const QS60StyleEnums::SkinParts skinPart = (option->state & State_On) ? 2021 2077 QS60StyleEnums::SP_QgnIndiCheckboxOn : QS60StyleEnums::SP_QgnIndiCheckboxOff; 2022 2078 painter->save(); 2023 2079 2024 QColor themeColor = QS60StylePrivate::themePalette()->windowText().color();2025 QColor windowTextColor = option->palette.windowText().color();2080 const QColor themeColor = QS60StylePrivate::themePalette()->windowText().color(); 2081 const QColor windowTextColor = option->palette.windowText().color(); 2026 2082 2027 2083 if (themeColor != windowTextColor) … … 2034 2090 case PE_IndicatorViewItemCheck: 2035 2091 #ifndef QT_NO_ITEMVIEWS 2036 if (const Q ListView *listItem = (qobject_cast<const QListView *>(widget))) {2092 if (const QAbstractItemView *itemView = (qobject_cast<const QAbstractItemView *>(widget))) { 2037 2093 if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(option)) { 2038 2094 const bool checkBoxVisible = vopt->features & QStyleOptionViewItemV2::HasCheckIndicator; 2039 const bool singleSelection = listItem->selectionMode() ==2040 QAbstractItemView::SingleSelection || listItem->selectionMode() == QAbstractItemView::NoSelection;2095 const bool singleSelection = itemView->selectionMode() == 2096 QAbstractItemView::SingleSelection || itemView->selectionMode() == QAbstractItemView::NoSelection; 2041 2097 // draw either checkbox at the beginning 2042 2098 if (checkBoxVisible && singleSelection) { 2043 2099 drawPrimitive(PE_IndicatorCheckBox, option, painter, widget); 2044 2100 // ... or normal "tick" selection at the end. 2045 } else if (option->state & QStyle::State_Selected) {2101 } else if (option->state & State_Selected) { 2046 2102 QRect tickRect = option->rect; 2047 const int frameBorderWidth = QS60StylePrivate::pixelMetric(PM_ Custom_FrameCornerWidth);2103 const int frameBorderWidth = QS60StylePrivate::pixelMetric(PM_FrameCornerWidth); 2048 2104 // adjust tickmark rect to exclude frame border 2049 2105 tickRect.adjust(0, -frameBorderWidth, 0, -frameBorderWidth); … … 2070 2126 2071 2127 painter->save(); 2072 QColor themeColor = d->s60Color(QS60StyleEnums::CL_QsnTextColors, 6, option);2073 QColor buttonTextColor = option->palette.buttonText().color();2128 const QColor themeColor = QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnTextColors, 6, option); 2129 const QColor buttonTextColor = option->palette.buttonText().color(); 2074 2130 if (themeColor != buttonTextColor) 2075 2131 painter->setPen(buttonTextColor); … … 2078 2134 2079 2135 // Draw radiobutton indicator as color skinned graphics. 2080 QS60StyleEnums::SkinParts skinPart = (option->state & QStyle::State_On) ?2136 QS60StyleEnums::SkinParts skinPart = (option->state & State_On) ? 2081 2137 QS60StyleEnums::SP_QgnIndiRadiobuttOn : QS60StyleEnums::SP_QgnIndiRadiobuttOff; 2082 2138 QS60StylePrivate::drawSkinPart(skinPart, painter, buttonRect, … … 2089 2145 case PE_PanelButtonBevel: 2090 2146 case PE_FrameButtonBevel: 2091 if (QS60StylePrivate::canDrawThemeBackground(option->palette.base() )) {2092 const bool isPressed = option->state & QStyle::State_Sunken;2147 if (QS60StylePrivate::canDrawThemeBackground(option->palette.base(), widget)) { 2148 const bool isPressed = option->state & State_Sunken; 2093 2149 const QS60StylePrivate::SkinElements skinElement = 2094 2150 isPressed ? QS60StylePrivate::SE_ButtonPressed : QS60StylePrivate::SE_ButtonNormal; … … 2121 2177 case PE_IndicatorSpinUp: 2122 2178 if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) { 2123 if (QS60StylePrivate::canDrawThemeBackground(spinBox->palette.base() )) {2179 if (QS60StylePrivate::canDrawThemeBackground(spinBox->palette.base(), widget)) { 2124 2180 QStyleOptionSpinBox optionSpinBox = *spinBox; 2125 2181 const QS60StyleEnums::SkinParts part = (element == PE_IndicatorSpinUp) ? 2126 2182 QS60StyleEnums::SP_QgnGrafScrollArrowUp : 2127 2183 QS60StyleEnums::SP_QgnGrafScrollArrowDown; 2128 const int iconMargin = QS60StylePrivate::pixelMetric(PM_ Custom_FrameCornerWidth) >> 1;2184 const int iconMargin = QS60StylePrivate::pixelMetric(PM_FrameCornerWidth) >> 1; 2129 2185 optionSpinBox.rect.translate(0, (element == PE_IndicatorSpinDown) ? iconMargin : -iconMargin ); 2130 2186 QS60StylePrivate::drawSkinPart(part, painter, optionSpinBox.rect, flags); … … 2136 2192 #ifndef QT_NO_COMBOBOX 2137 2193 if (const QStyleOptionFrame *cmb = qstyleoption_cast<const QStyleOptionFrame *>(option)) { 2138 if (QS60StylePrivate::canDrawThemeBackground( option->palette.base() )) {2194 if (QS60StylePrivate::canDrawThemeBackground( option->palette.base(), widget)) { 2139 2195 // We want to draw down arrow here for comboboxes as well. 2140 2196 QStyleOptionFrame optionsComboBox = *cmb; 2141 2197 const QS60StyleEnums::SkinParts part = QS60StyleEnums::SP_QgnGrafScrollArrowDown; 2142 const int iconMargin = QS60StylePrivate::pixelMetric(PM_ Custom_FrameCornerWidth) >> 1;2198 const int iconMargin = QS60StylePrivate::pixelMetric(PM_FrameCornerWidth) >> 1; 2143 2199 optionsComboBox.rect.translate(0, (element == PE_IndicatorSpinDown) ? iconMargin : -iconMargin ); 2144 2200 QS60StylePrivate::drawSkinPart(part, painter, optionsComboBox.rect, flags); … … 2175 2231 ) { 2176 2232 //Need extra check since dialogs have their own theme background 2177 if (QS60StylePrivate::canDrawThemeBackground(option->palette.base() ) &&2233 if (QS60StylePrivate::canDrawThemeBackground(option->palette.base(), widget) && 2178 2234 option->palette.window().texture().cacheKey() == 2179 2235 QS60StylePrivate::m_themePalette->window().texture().cacheKey()) 2180 QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ OptionsMenu, painter, option->rect, flags);2236 QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_PopupBackground, painter, option->rect, flags); 2181 2237 else 2182 2238 commonStyleDraws = true; … … 2217 2273 #ifndef QT_NO_ITEMVIEWS 2218 2274 case PE_PanelItemViewItem: 2275 if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(option)) { 2276 const bool isSelected = (vopt->state & State_Selected); 2277 const bool hasFocus = (vopt->state & State_HasFocus); 2278 const bool isPressed = QS60StylePrivate::isWidgetPressed(widget); 2279 2280 if (option->palette.highlight().color() == QS60StylePrivate::themePalette()->highlight().color()) { 2281 QRect highlightRect = vopt->rect.adjusted(1,1,-1,-1); 2282 const QAbstractItemView *itemView = qobject_cast<const QAbstractItemView *>(widget); 2283 QAbstractItemView::SelectionBehavior selectionBehavior = 2284 itemView ? itemView->selectionBehavior() : QAbstractItemView::SelectItems; 2285 // Set the draw area for highlights (focus, select rect or pressed rect) 2286 if (hasFocus || isSelected || isPressed) { 2287 if (selectionBehavior != QAbstractItemView::SelectItems) { 2288 // set highlight rect so that it is continuous from cell to cell, yet sligthly 2289 // smaller than cell rect 2290 int xBeginning = 0, yBeginning = 0, xEnd = 0, yEnd = 0; 2291 if (selectionBehavior == QAbstractItemView::SelectRows) { 2292 yBeginning = 1; yEnd = -1; 2293 if (vopt->viewItemPosition == QStyleOptionViewItemV4::Beginning) 2294 xBeginning = 1; 2295 else if (vopt->viewItemPosition == QStyleOptionViewItemV4::End) 2296 xEnd = -1; 2297 } else if (selectionBehavior == QAbstractItemView::SelectColumns) { 2298 xBeginning = 1; xEnd = -1; 2299 if (vopt->viewItemPosition == QStyleOptionViewItemV4::Beginning) 2300 yBeginning = 1; 2301 else if (vopt->viewItemPosition == QStyleOptionViewItemV4::End) 2302 yEnd = -1; 2303 } 2304 highlightRect = option->rect.adjusted(xBeginning, yBeginning, xEnd, yEnd); 2305 } 2306 } 2307 bool tableView = false; 2308 if (itemView && qobject_cast<const QTableView *>(widget)) 2309 tableView = true; 2310 2311 QS60StylePrivate::SkinElements element; 2312 QRect elementRect = option->rect; 2313 2314 //draw item is drawn as pressed, if it already has focus. 2315 if (isPressed && (hasFocus || isSelected)) { 2316 element = tableView ? QS60StylePrivate::SE_TableItemPressed : QS60StylePrivate::SE_ListItemPressed; 2317 } else if (hasFocus || (isSelected && selectionBehavior != QAbstractItemView::SelectItems)) { 2318 element = QS60StylePrivate::SE_ListHighlight; 2319 elementRect = highlightRect; 2320 } 2321 QS60StylePrivate::drawSkinElement(element, painter, elementRect, flags); 2322 } else { 2323 QCommonStyle::drawPrimitive(element, option, painter, widget); 2324 } 2325 } 2219 2326 break; 2220 2327 #endif //QT_NO_ITEMVIEWS … … 2249 2356 QCommonStyle::drawPrimitive(element, option, painter, widget); 2250 2357 } else { 2251 const bool rightLine = option->state & State_Item; 2252 const bool downLine = option->state & State_Sibling; 2253 const bool upLine = option->state & (State_Open | State_Children | State_Item | State_Sibling); 2254 2255 QS60StyleEnums::SkinParts skinPart; 2256 bool drawSkinPart = false; 2257 if (rightLine && downLine && upLine) { 2258 skinPart = QS60StyleEnums::SP_QgnIndiHlLineBranch; 2259 drawSkinPart = true; 2260 } else if (rightLine && upLine) { 2261 skinPart = QS60StyleEnums::SP_QgnIndiHlLineEnd; 2262 drawSkinPart = true; 2263 } else if (upLine && downLine) { 2264 skinPart = QS60StyleEnums::SP_QgnIndiHlLineStraight; 2265 drawSkinPart = true; 2266 } 2267 2268 if (drawSkinPart) 2269 QS60StylePrivate::drawSkinPart(skinPart, painter, option->rect, flags); 2270 2271 if (option->state & State_Children) { 2272 QS60StyleEnums::SkinParts skinPart = 2273 (option->state & State_Open) ? QS60StyleEnums::SP_QgnIndiHlColSuper : QS60StyleEnums::SP_QgnIndiHlExpSuper; 2274 int minDimension = qMin(option->rect.width(), option->rect.height()); 2275 const int resizeValue = minDimension >> 1; 2276 minDimension += resizeValue; // Adjust the icon bigger because of empty space in svg icon. 2277 QRect iconRect(option->rect.topLeft(), QSize(minDimension, minDimension)); 2278 int verticalMagic(0); 2279 // magic values for positioning svg icon. 2280 if (option->rect.width() <= option->rect.height()) 2281 verticalMagic = 3; 2282 iconRect.translate(3, verticalMagic - resizeValue); 2283 QS60StylePrivate::drawSkinPart(skinPart, painter, iconRect, flags); 2358 if (const QStyleOptionViewItemV2 *vopt = qstyleoption_cast<const QStyleOptionViewItemV2 *>(option)) { 2359 const bool rightLine = option->state & State_Item; 2360 const bool downLine = option->state & State_Sibling; 2361 const bool upLine = option->state & (State_Open | State_Children | State_Item | State_Sibling); 2362 QS60StylePrivate::SkinElementFlags adjustedFlags = flags; 2363 2364 QS60StyleEnums::SkinParts skinPart; 2365 bool drawSkinPart = false; 2366 if (rightLine && downLine && upLine) { 2367 skinPart = QS60StyleEnums::SP_QgnIndiHlLineBranch; 2368 drawSkinPart = true; 2369 } else if (rightLine && upLine) { 2370 skinPart = QS60StyleEnums::SP_QgnIndiHlLineEnd; 2371 drawSkinPart = true; 2372 } else if (upLine && downLine) { 2373 skinPart = QS60StyleEnums::SP_QgnIndiHlLineStraight; 2374 drawSkinPart = true; 2375 } 2376 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 } 2284 2395 } 2285 2396 } … … 2292 2403 commonStyleDraws = true; 2293 2404 } else { 2294 QPalette::ColorGroup cg = vopt->state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled;2295 if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active))2405 QPalette::ColorGroup cg = vopt->state & State_Enabled ? QPalette::Normal : QPalette::Disabled; 2406 if (cg == QPalette::Normal && !(vopt->state & State_Active)) 2296 2407 cg = QPalette::Inactive; 2297 2408 if (vopt->features & QStyleOptionViewItemV2::Alternate) … … 2304 2415 case PE_PanelScrollAreaCorner: 2305 2416 break; 2306 2417 case PE_IndicatorItemViewItemDrop: 2418 if (QS60StylePrivate::isTouchSupported()) 2419 QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_DropArea, painter, option->rect, flags); 2420 else 2421 commonStyleDraws = true; 2422 break; 2307 2423 // todo: items are below with #ifdefs "just in case". in final version, remove all non-required cases 2308 2424 case PE_FrameLineEdit: … … 2325 2441 #ifndef QT_NO_COLUMNVIEW 2326 2442 case PE_IndicatorColumnViewArrow: 2327 case PE_IndicatorItemViewItemDrop:2328 2443 #endif //QT_NO_COLUMNVIEW 2329 2444 case PE_FrameTabBarBase: // since tabs are in S60 always in navipane, let's use common style for tab base in Qt. … … 2343 2458 metricValue = QCommonStyle::pixelMetric(metric, option, widget); 2344 2459 2345 if (metric == PM_SubMenuOverlap && widget) { 2346 const QMenu *menu = qobject_cast<const QMenu *>(widget); 2347 if (menu && menu->activeAction() && menu->activeAction()->menu()) { 2348 const int menuWidth = menu->activeAction()->menu()->sizeHint().width(); 2349 metricValue = -menuWidth; 2350 } 2351 } 2460 // Menu scrollers should be set to zero height for combobox popups 2461 if (metric == PM_MenuScrollerHeight && !qobject_cast<const QMenu *>(widget)) 2462 metricValue = 0; 2463 2352 2464 //if layout direction is mirrored, switch left and right border margins 2353 2465 if (option && option->direction == Qt::RightToLeft) { … … 2357 2469 metricValue = QS60StylePrivate::pixelMetric(PM_LayoutLeftMargin); 2358 2470 } 2471 2472 if (widget && (metric == PM_LayoutTopMargin)) 2473 if (widget->windowType() == Qt::Dialog) 2474 //double the top layout margin for dialogs, it is very close to real value 2475 //without having to define custom pixel metric 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 2359 2483 return metricValue; 2360 2484 } … … 2377 2501 sz = QCommonStyle::sizeFromContents( ct, opt, csz, widget); 2378 2502 //FIXME properly - style should calculate the location of border frame-part 2379 sz += QSize(2 * pixelMetric(PM_ButtonMargin), 2 * pixelMetric(PM_ButtonMargin)); 2380 if (const QAbstractButton *buttonWidget = (qobject_cast<const QAbstractButton *>(widget))) 2503 if (const QAbstractButton *buttonWidget = (qobject_cast<const QAbstractButton *>(widget))) { 2381 2504 if (buttonWidget->isCheckable()) 2382 2505 sz += QSize(pixelMetric(PM_IndicatorWidth) + pixelMetric(PM_CheckBoxLabelSpacing), 0); 2506 const int iconHeight = (!buttonWidget->icon().isNull()) ? buttonWidget->iconSize().height() : 0; 2507 const int textHeight = (buttonWidget->text().length() > 0) ? 2508 buttonWidget->fontMetrics().size(Qt::TextSingleLine, buttonWidget->text()).height() : opt->fontMetrics.height(); 2509 const int decoratorHeight = (buttonWidget->isCheckable()) ? pixelMetric(PM_IndicatorHeight) : 0; 2510 2511 const int contentHeight = 2512 qMax(qMax(iconHeight, decoratorHeight) + pixelMetric(PM_ButtonMargin), 2513 textHeight + 2*pixelMetric(PM_ButtonMargin)); 2514 sz.setHeight(qMax(sz.height(), contentHeight)); 2515 sz += QSize(2 * pixelMetric(PM_ButtonMargin), 0); 2516 } 2383 2517 break; 2384 2518 case CT_LineEdit: … … 2391 2525 if (naviPaneSize.height() > sz.height()) 2392 2526 sz.setHeight(naviPaneSize.height()); 2393 } 2394 break; 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 } 2540 } 2541 break; 2542 case CT_MenuItem: 2395 2543 case CT_ItemViewItem: 2544 if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) { 2545 if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) { 2546 sz = QSize(); 2547 break; 2548 } 2549 } 2396 2550 sz = QCommonStyle::sizeFromContents( ct, opt, csz, widget); 2397 2551 if (QS60StylePrivate::isTouchSupported()) 2398 2552 //Make itemview easier to use in touch devices 2399 2553 //QCommonStyle does not adjust height with horizontal margin, it only adjusts width 2400 sz.setHeight(sz.height() + 2 * pixelMetric( QStyle::PM_FocusFrameVMargin));2554 sz.setHeight(sz.height() + 2 * pixelMetric(PM_FocusFrameVMargin)); 2401 2555 break; 2402 2556 #ifndef QT_NO_COMBOBOX 2403 case CT_ComboBox: 2404 if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) { 2405 const int frameWidth = cmb->frame ? pixelMetric(PM_ComboBoxFrameWidth, opt, widget) * 2 : 0; 2406 const int textMargins = 2*(pixelMetric(PM_FocusFrameHMargin) + 1); 2407 const int smallestExtraWidth = 23; 2408 // QItemDelegate::sizeHint expands the textMargins two times, thus the 2*textMargins... 2409 const int extra = 2410 qMax(smallestExtraWidth, 2*textMargins + pixelMetric(PM_ScrollBarExtent, opt, widget)); 2411 sz = QSize(sz.width() + frameWidth + extra, sz.height() + frameWidth); 2412 int maxScreenWidth = QApplication::desktop()->availableGeometry().size().width(); 2413 if (sz.width() > maxScreenWidth) { 2414 maxScreenWidth = maxScreenWidth - (extra + frameWidth); 2415 sz.setWidth(maxScreenWidth); 2416 } 2417 } 2418 break; 2557 case CT_ComboBox: { 2558 // Fixing Ui design issues with too wide QComboBoxes and greedy SizeHints 2559 // Make sure, that the combobox stays within the screen. 2560 const QSize desktopContentSize = QApplication::desktop()->availableGeometry().size() 2561 - QSize(pixelMetric(PM_LayoutLeftMargin) + pixelMetric(PM_LayoutRightMargin), 0); 2562 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget). 2563 boundedTo(desktopContentSize); 2564 } 2565 break; 2419 2566 #endif 2420 2567 default: … … 2429 2576 QStyleHintReturn *hret) const 2430 2577 { 2431 int retValue = -1;2578 int retValue = 0; 2432 2579 switch (sh) { 2580 case SH_RequestSoftwareInputPanel: 2581 if (QS60StylePrivate::isSingleClickUi()) 2582 retValue = RSIP_OnMouseClick; 2583 else 2584 retValue = RSIP_OnMouseClickAndAlreadyFocused; 2585 break; 2586 case SH_ComboBox_Popup: 2587 retValue = true; 2588 break; 2433 2589 case SH_Table_GridLineColor: 2434 2590 retValue = int(QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnLineColors, 2, 0).rgba()); … … 2455 2611 retValue = QPalette::Base; 2456 2612 break; 2457 case SH_ItemView_ActivateItemOnSingleClick: 2458 retValue = QS60StylePrivate::isSingleClickUi(); 2459 break; 2613 case SH_ItemView_ActivateItemOnSingleClick: { 2614 if (QS60StylePrivate::isSingleClickUi()) 2615 retValue = true; 2616 else if (opt && opt->state & QStyle::State_Selected) 2617 retValue = true; 2618 break; 2619 } 2460 2620 case SH_ProgressDialog_TextLabelAlignment: 2461 2621 retValue = (QApplication::layoutDirection() == Qt::LeftToRight) ? … … 2472 2632 retValue = true; 2473 2633 break; 2634 case SH_Menu_MouseTracking: 2635 retValue = true; 2636 break; 2474 2637 case SH_ItemView_ShowDecorationSelected: 2475 2638 retValue = true; … … 2484 2647 retValue = 0; 2485 2648 break; 2486 case SH_RequestSoftwareInputPanel:2487 retValue = RSIP_OnMouseClickAndAlreadyFocused;2488 break;2489 2649 case SH_FormLayoutWrapPolicy: 2490 2650 retValue = QFormLayout::WrapLongRows; 2651 break; 2652 case SH_ScrollBar_ContextMenu: 2653 retValue = false; 2491 2654 break; 2492 2655 default: … … 2568 2731 const int frameThickness = spinbox->frame ? pixelMetric(PM_SpinBoxFrameWidth, spinbox, widget) : 0; 2569 2732 const int buttonMargin = spinbox->frame ? 2 : 0; 2570 const int buttonWidth = QS60StylePrivate::pixelMetric(QStyle::PM_ButtonIconSize) + 2 * buttonMargin; 2733 const int buttonContentWidth = QS60StylePrivate::pixelMetric(PM_ButtonIconSize) + 2 * buttonMargin; 2734 // Spinbox buttons should be no larger than one fourth of total width. 2735 // Thus, side-by-side buttons would take half of the total width. 2736 const int maxSize = qMax(spinbox->rect.width() / 4, buttonContentWidth); 2571 2737 QSize buttonSize; 2572 buttonSize.setHeight(qM ax(8, spinbox->rect.height() - frameThickness));2738 buttonSize.setHeight(qMin(maxSize, qMax(8, spinbox->rect.height() - frameThickness))); 2573 2739 //width should at least be equal to height 2574 buttonSize.setWidth(qMax(buttonSize.height(), button Width));2740 buttonSize.setWidth(qMax(buttonSize.height(), buttonContentWidth)); 2575 2741 buttonSize = buttonSize.expandedTo(QApplication::globalStrut()); 2576 2742 2577 const int y = frameThickness + spinbox->rect.y(); 2578 const int x = spinbox->rect.x() + spinbox->rect.width() - frameThickness - 2 * buttonSize.width(); 2743 // Normally spinbuttons should be side-by-side, but if spinbox grows very big 2744 // and spinbuttons reach their maximum size, they can be deployed one top of the other. 2745 const bool sideBySide = (buttonSize.height() * 2 < spinbox->rect.height()) ? false : true; 2746 const int y = frameThickness + spinbox->rect.y() + 2747 (spinbox->rect.height() - (sideBySide ? 1 : 2) * buttonSize.height()) / 2; 2748 const int x = spinbox->rect.x() + 2749 spinbox->rect.width() - frameThickness - (sideBySide ? 2 : 1) * buttonSize.width(); 2579 2750 2580 2751 switch (scontrol) { … … 2587 2758 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons) 2588 2759 return QRect(); 2589 ret = QRect(x + buttonSize.width(), y, buttonSize.width(), buttonSize.height()); 2760 ret = QRect(x + (sideBySide ? buttonSize.width() : 0), 2761 y + (sideBySide ? 0 : buttonSize.height()), 2762 buttonSize.width(), buttonSize.height()); 2590 2763 break; 2591 2764 case SC_SpinBoxEditField: … … 2617 2790 const int width = cmb->rect.width(); 2618 2791 const int height = cmb->rect.height(); 2619 const int buttonIconSize = QS60StylePrivate::pixelMetric( QStyle::PM_ButtonIconSize);2792 const int buttonIconSize = QS60StylePrivate::pixelMetric(PM_ButtonIconSize); 2620 2793 const int buttonMargin = cmb->frame ? 2 : 0; 2621 2794 // lets use spinbox frame here as well, as no combobox specific value available. … … 2643 2816 } 2644 2817 break; 2818 case SC_ComboBoxListBoxPopup: { 2819 const QRect desktopContent = QApplication::desktop()->availableGeometry(); 2820 2821 // take the size of this and position bottom above available area 2822 QRect popupRect; 2823 const int width = desktopContent.width() - pixelMetric(PM_LayoutRightMargin) - pixelMetric(PM_LayoutLeftMargin); 2824 popupRect.setWidth(width); 2825 popupRect.setHeight(desktopContent.height()); //combobox resets height anyway based on content 2826 popupRect.setBottom(desktopContent.bottom()); 2827 popupRect.translate(pixelMetric(PM_LayoutLeftMargin), 0); 2828 ret = popupRect; 2829 } 2830 break; 2645 2831 default: 2646 2832 break; … … 2657 2843 //slightly indent text and boxes, so that dialog border does not mess with them. 2658 2844 const int horizontalSpacing = 2659 QS60StylePrivate::pixelMetric( QStyle::PM_LayoutHorizontalSpacing);2845 QS60StylePrivate::pixelMetric(PM_LayoutHorizontalSpacing); 2660 2846 ret.adjust(2, horizontalSpacing - 3, 0, 0); 2661 2847 } … … 2717 2903 case SE_LineEditContents: { 2718 2904 // in S60 the input text box doesn't start from line Edit's TL, but 2719 // a bit indented. 2720 QRect lineEditRect = opt->rect; 2721 const int adjustment = opt->rect.height() >> 2; 2722 lineEditRect.adjust(adjustment, 0, 0, 0); 2723 ret = lineEditRect; 2905 // a bit indented (8 pixels). 2906 const int KLineEditDefaultIndention = 8; 2907 ret = visualRect( 2908 opt->direction, opt->rect, opt->rect.adjusted(KLineEditDefaultIndention, 0, 0, 0)); 2724 2909 } 2725 2910 break; … … 2733 2918 if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) { 2734 2919 const int tabOverlapNoBorder = 2735 QS60StylePrivate::pixelMetric( QStyle::PM_TabBarTabOverlap);2920 QS60StylePrivate::pixelMetric(PM_TabBarTabOverlap); 2736 2921 const int tabOverlap = 2737 tabOverlapNoBorder -QS60StylePrivate::pixelMetric(QStyle::PM_DefaultFrameWidth);2922 tabOverlapNoBorder - QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth); 2738 2923 const QTabWidget *tab = qobject_cast<const QTabWidget *>(widget); 2739 2924 int gain = (tab) ? tabOverlap * tab->count() : 0; … … 2784 2969 (vopt->features & QStyleOptionViewItemV2::HasCheckIndicator)) { 2785 2970 const int verticalSpacing = 2786 QS60StylePrivate::pixelMetric( QStyle::PM_LayoutVerticalSpacing);2787 //const int horizontalSpacing = QS60StylePrivate::pixelMetric( QStyle::PM_LayoutHorizontalSpacing);2971 QS60StylePrivate::pixelMetric(PM_LayoutVerticalSpacing); 2972 //const int horizontalSpacing = QS60StylePrivate::pixelMetric(PM_LayoutHorizontalSpacing); 2788 2973 const int checkBoxRectWidth = subElementRect(SE_ItemViewItemCheckIndicator, opt, widget).width(); 2789 2974 ret.adjust(-checkBoxRectWidth - verticalSpacing, 0, -checkBoxRectWidth - verticalSpacing, 0); … … 2797 2982 2798 2983 if (element == SE_ItemViewItemDecoration) { 2799 if (menuItem->direction == Qt::RightToLeft) 2800 ret.translate(ret.width()-indicatorWidth, 0); 2801 ret.setWidth(indicatorWidth); 2984 if (menuItem->icon.isNull()) { 2985 ret = QRect(); 2986 } else { 2987 if (menuItem->direction == Qt::RightToLeft) 2988 ret.translate(ret.width() - indicatorWidth, 0); 2989 ret.setWidth(indicatorWidth); 2990 } 2802 2991 } else { 2803 2992 ret = menuItem->rect; … … 2820 3009 break; 2821 3010 case SE_ItemViewItemCheckIndicator: 2822 if (const QStyleOptionViewItemV 4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4*>(opt)) {3011 if (const QStyleOptionViewItemV2 *vopt = qstyleoption_cast<const QStyleOptionViewItemV2 *>(opt)) { 2823 3012 const QListWidget *listItem = qobject_cast<const QListWidget *>(widget); 2824 3013 … … 2831 3020 2832 3021 // Selection check mark rect. 2833 const int indicatorWidth = QS60StylePrivate::pixelMetric( QStyle::PM_IndicatorWidth);2834 const int indicatorHeight = QS60StylePrivate::pixelMetric( QStyle::PM_IndicatorHeight);2835 const int spacing = QS60StylePrivate::pixelMetric( QStyle::PM_CheckBoxLabelSpacing);3022 const int indicatorWidth = QS60StylePrivate::pixelMetric(PM_IndicatorWidth); 3023 const int indicatorHeight = QS60StylePrivate::pixelMetric(PM_IndicatorHeight); 3024 const int spacing = QS60StylePrivate::pixelMetric(PM_CheckBoxLabelSpacing); 2836 3025 2837 3026 const int itemHeight = opt->rect.height(); … … 2859 3048 // Subtract area needed for line 2860 3049 if (opt->state & State_Horizontal) 2861 ret.setHeight(ret.height() - QS60StylePrivate::pixelMetric(PM_ Custom_BoldLineWidth));3050 ret.setHeight(ret.height() - QS60StylePrivate::pixelMetric(PM_BoldLineWidth)); 2862 3051 else 2863 ret.setWidth(ret.width() - QS60StylePrivate::pixelMetric(PM_ Custom_ThinLineWidth));3052 ret.setWidth(ret.width() - QS60StylePrivate::pixelMetric(PM_ThinLineWidth)); 2864 3053 } 2865 3054 ret = visualRect(opt->direction, opt->rect, ret); … … 2967 3156 widget->setPalette(QPalette()); 2968 3157 2969 #if ndef QT_NO_PROGRESSBAR3158 #if defined(Q_WS_S60) && !defined(QT_NO_PROGRESSBAR) 2970 3159 if (QProgressBar *bar = qobject_cast<QProgressBar *>(widget)) { 2971 3160 widget->removeEventFilter(this); 2972 3161 d->m_bars.removeAll(bar); 2973 3162 } 3163 #else 3164 Q_UNUSED(d) 2974 3165 #endif 2975 3166 QCommonStyle::unpolish(widget); … … 2982 3173 { 2983 3174 Q_D(QS60Style); 3175 QCommonStyle::polish(qApp); 2984 3176 d->m_originalPalette = application->palette(); 2985 3177 d->setThemePalette(application); 3178 if (QS60StylePrivate::isTouchSupported()) 3179 qApp->installEventFilter(this); 2986 3180 } 2987 3181 … … 2992 3186 { 2993 3187 Q_UNUSED(application) 3188 2994 3189 Q_D(QS60Style); 3190 QCommonStyle::unpolish(qApp); 2995 3191 const QPalette newPalette = QApplication::style()->standardPalette(); 2996 3192 QApplication::setPalette(newPalette); 2997 3193 QApplicationPrivate::setSystemPalette(d->m_originalPalette); 3194 if (QS60StylePrivate::isTouchSupported()) 3195 qApp->removeEventFilter(this); 2998 3196 } 2999 3197 … … 3003 3201 bool QS60Style::event(QEvent *e) 3004 3202 { 3203 #ifdef QT_KEYPAD_NAVIGATION 3005 3204 Q_D(QS60Style); 3006 3007 #ifdef QT_KEYPAD_NAVIGATION3008 3205 const QEvent::Type eventType = e->type(); 3009 3206 if ((eventType == QEvent::FocusIn || … … 3024 3221 case QEvent::FocusIn: 3025 3222 if (QWidget *focusWidget = QApplication::focusWidget()) { 3223 3224 // Menus and combobox popups do not draw focus frame around them 3225 if (qobject_cast<QComboBoxListView *>(focusWidget) || 3226 qobject_cast<QMenu *>(focusWidget)) 3227 break; 3228 3026 3229 if (!d->m_focusFrame) 3027 3230 d->m_focusFrame = new QFocusFrame(focusWidget); … … 3053 3256 const QStyleOption *option, const QWidget *widget) const 3054 3257 { 3055 const int iconDimension = QS60StylePrivate::pixelMetric( QStyle::PM_ToolBarIconSize);3258 const int iconDimension = QS60StylePrivate::pixelMetric(PM_ToolBarIconSize); 3056 3259 const QRect iconSize = (!option) ? QRect(0, 0, iconDimension, iconDimension) : option->rect; 3057 3260 QS60StyleEnums::SkinParts part; … … 3063 3266 3064 3267 switch(standardIcon) { 3065 case QStyle::SP_MessageBoxWarning:3268 case SP_MessageBoxWarning: 3066 3269 part = QS60StyleEnums::SP_QgnNoteWarning; 3067 3270 break; 3068 case QStyle::SP_MessageBoxInformation:3271 case SP_MessageBoxInformation: 3069 3272 part = QS60StyleEnums::SP_QgnNoteInfo; 3070 3273 break; 3071 case QStyle::SP_MessageBoxCritical:3274 case SP_MessageBoxCritical: 3072 3275 part = QS60StyleEnums::SP_QgnNoteError; 3073 3276 break; 3074 case QStyle::SP_MessageBoxQuestion:3277 case SP_MessageBoxQuestion: 3075 3278 part = QS60StyleEnums::SP_QgnNoteQuery; 3076 3279 break; 3077 case QStyle::SP_ArrowRight:3280 case SP_ArrowRight: 3078 3281 part = QS60StyleEnums::SP_QgnIndiNaviArrowRight; 3079 3282 break; 3080 case QStyle::SP_ArrowLeft:3283 case SP_ArrowLeft: 3081 3284 part = QS60StyleEnums::SP_QgnIndiNaviArrowLeft; 3082 3285 break; 3083 case QStyle::SP_ArrowUp:3286 case SP_ArrowUp: 3084 3287 part = QS60StyleEnums::SP_QgnIndiNaviArrowLeft; 3085 3288 adjustedFlags |= QS60StylePrivate::SF_PointEast; 3086 3289 break; 3087 case QStyle::SP_ArrowDown:3290 case SP_ArrowDown: 3088 3291 part = QS60StyleEnums::SP_QgnIndiNaviArrowLeft; 3089 3292 adjustedFlags |= QS60StylePrivate::SF_PointWest; 3090 3293 break; 3091 case QStyle::SP_ArrowBack:3294 case SP_ArrowBack: 3092 3295 if (QApplication::layoutDirection() == Qt::RightToLeft) 3093 3296 return QS60Style::standardIcon(SP_ArrowRight, option, widget); 3094 3297 return QS60Style::standardIcon(SP_ArrowLeft, option, widget); 3095 case QStyle::SP_ArrowForward:3298 case SP_ArrowForward: 3096 3299 if (QApplication::layoutDirection() == Qt::RightToLeft) 3097 3300 return QS60Style::standardIcon(SP_ArrowLeft, option, widget); 3098 3301 return QS60Style::standardIcon(SP_ArrowRight, option, widget); 3099 case QStyle::SP_ComputerIcon:3302 case SP_ComputerIcon: 3100 3303 part = QS60StyleEnums::SP_QgnPropPhoneMemcLarge; 3101 3304 break; 3102 case QStyle::SP_DirClosedIcon:3305 case SP_DirClosedIcon: 3103 3306 part = QS60StyleEnums::SP_QgnPropFolderSmall; 3104 3307 break; 3105 case QStyle::SP_DirOpenIcon:3308 case SP_DirOpenIcon: 3106 3309 part = QS60StyleEnums::SP_QgnPropFolderCurrent; 3107 3310 break; 3108 case QStyle::SP_DirIcon:3311 case SP_DirIcon: 3109 3312 part = QS60StyleEnums::SP_QgnPropFolderSmall; 3110 3313 break; 3111 case QStyle::SP_FileDialogNewFolder:3314 case SP_FileDialogNewFolder: 3112 3315 part = QS60StyleEnums::SP_QgnPropFolderSmallNew; 3113 3316 break; 3114 case QStyle::SP_FileIcon:3317 case SP_FileIcon: 3115 3318 part = QS60StyleEnums::SP_QgnPropFileSmall; 3116 3319 break; 3117 case QStyle::SP_TrashIcon:3320 case SP_TrashIcon: 3118 3321 part = QS60StyleEnums::SP_QgnNoteErased; 3119 3322 break; 3120 case QStyle::SP_ToolBarHorizontalExtensionButton:3323 case SP_ToolBarHorizontalExtensionButton: 3121 3324 part = QS60StyleEnums::SP_QgnIndiSubMenu; 3122 3325 if (QApplication::layoutDirection() == Qt::RightToLeft) 3123 3326 adjustedFlags |= QS60StylePrivate::SF_PointSouth; 3124 3327 break; 3125 case QStyle::SP_ToolBarVerticalExtensionButton:3328 case SP_ToolBarVerticalExtensionButton: 3126 3329 adjustedFlags |= QS60StylePrivate::SF_PointEast; 3127 3330 part = QS60StyleEnums::SP_QgnIndiSubMenu; … … 3143 3346 bool QS60Style::eventFilter(QObject *object, QEvent *event) 3144 3347 { 3348 Q_D(QS60Style); 3349 switch(event->type()) { 3350 case QEvent::MouseButtonPress: { 3351 QWidget *w = QApplication::widgetAt(QCursor::pos()); 3352 if (w) { 3353 QWidget *focusW = w->focusProxy(); 3354 if (qobject_cast<QAbstractItemView *>(focusW) || 3355 qobject_cast<QRadioButton *>(focusW) || 3356 qobject_cast<QCheckBox *>(focusW)) 3357 d->m_pressedWidget = focusW; 3358 else if (qobject_cast<QAbstractItemView *>(w)|| 3359 qobject_cast<QRadioButton *>(w) || 3360 qobject_cast<QCheckBox *>(w)) 3361 d->m_pressedWidget = w; 3362 3363 if ( d->m_pressedWidget) 3364 d->m_pressedWidget->update(); 3365 } 3366 break; 3367 } 3368 case QEvent::MouseButtonRelease: { 3369 const QWidget *w = QApplication::widgetAt(QCursor::pos()); 3370 if (w && d->m_pressedWidget) { 3371 d->m_pressedWidget->update(); 3372 d->m_pressedWidget = 0; 3373 } 3374 break; 3375 } 3376 default: 3377 break; 3378 } 3379 3145 3380 #ifdef Q_WS_S60 3146 3381 #ifndef QT_NO_PROGRESSBAR 3147 Q_D(QS60Style);3148 3382 switch(event->type()) { 3149 3383 case QEvent::StyleChange: … … 3158 3392 case QEvent::Destroy: 3159 3393 case QEvent::Hide: 3160 d->stopAnimation(QS60StyleEnums::SP_QgnGrafBarWaitAnim); 3161 d->m_bars.removeAll(reinterpret_cast<QProgressBar *>(object)); 3394 if (QProgressBar *bar = reinterpret_cast<QProgressBar *>(object)) { 3395 d->stopAnimation(QS60StyleEnums::SP_QgnGrafBarWaitAnim); 3396 d->m_bars.removeAll(bar); 3397 } 3162 3398 break; 3163 3399 default: … … 3166 3402 #endif // QT_NO_PROGRESSBAR 3167 3403 #endif // Q_WS_S60 3168 return QStyle::eventFilter(object, event); 3169 } 3170 3404 return QCommonStyle::eventFilter(object, event); 3405 } 3406 3407 /*! 3408 \internal 3409 Handle the timer \a event. 3410 */ 3171 3411 void QS60Style::timerEvent(QTimerEvent *event) 3172 3412 {
Note:
See TracChangeset
for help on using the changeset viewer.