| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). | 
|---|
| 4 | ** All rights reserved. | 
|---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | 
|---|
| 6 | ** | 
|---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | 
|---|
| 8 | ** | 
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | 
|---|
| 10 | ** Commercial Usage | 
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in | 
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the | 
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in | 
|---|
| 14 | ** a written agreement between you and Nokia. | 
|---|
| 15 | ** | 
|---|
| 16 | ** GNU Lesser General Public License Usage | 
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software | 
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | 
|---|
| 20 | ** packaging of this file.  Please review the following information to | 
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | 
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | 
|---|
| 23 | ** | 
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | 
|---|
| 25 | ** rights.  These rights are described in the Nokia Qt LGPL Exception | 
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | 
|---|
| 27 | ** | 
|---|
| 28 | ** GNU General Public License Usage | 
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU | 
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software | 
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the | 
|---|
| 32 | ** packaging of this file.  Please review the following information to | 
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be | 
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html. | 
|---|
| 35 | ** | 
|---|
| 36 | ** If you have questions regarding the use of this file, please contact | 
|---|
| 37 | ** Nokia at qt-info@nokia.com. | 
|---|
| 38 | ** $QT_END_LICENSE$ | 
|---|
| 39 | ** | 
|---|
| 40 | ****************************************************************************/ | 
|---|
| 41 |  | 
|---|
| 42 | #include "qs60style_p.h" | 
|---|
| 43 |  | 
|---|
| 44 | #include "qapplication.h" | 
|---|
| 45 | #include "qpainter.h" | 
|---|
| 46 | #include "qstyleoption.h" | 
|---|
| 47 | #include "qevent.h" | 
|---|
| 48 | #include "qpixmapcache.h" | 
|---|
| 49 |  | 
|---|
| 50 | #include "qcalendarwidget.h" | 
|---|
| 51 | #include "qdial.h" | 
|---|
| 52 | #include "qdialog.h" | 
|---|
| 53 | #include "qmessagebox.h" | 
|---|
| 54 | #include "qgroupbox.h" | 
|---|
| 55 | #include "qheaderview.h" | 
|---|
| 56 | #include "qlist.h" | 
|---|
| 57 | #include "qlistwidget.h" | 
|---|
| 58 | #include "qlistview.h" | 
|---|
| 59 | #include "qmenu.h" | 
|---|
| 60 | #include "qmenubar.h" | 
|---|
| 61 | #include "qpushbutton.h" | 
|---|
| 62 | #include "qscrollarea.h" | 
|---|
| 63 | #include "qscrollbar.h" | 
|---|
| 64 | #include "qtabbar.h" | 
|---|
| 65 | #include "qtableview.h" | 
|---|
| 66 | #include "qtextedit.h" | 
|---|
| 67 | #include "qtoolbar.h" | 
|---|
| 68 | #include "qtoolbutton.h" | 
|---|
| 69 | #include "qfocusframe.h" | 
|---|
| 70 | #include "qformlayout.h" | 
|---|
| 71 | #include "qradiobutton.h" | 
|---|
| 72 | #include "qcheckbox.h" | 
|---|
| 73 | #include "qdesktopwidget.h" | 
|---|
| 74 | #include "qprogressbar.h" | 
|---|
| 75 |  | 
|---|
| 76 | #include "private/qtoolbarextension_p.h" | 
|---|
| 77 | #include "private/qcombobox_p.h" | 
|---|
| 78 | #include "private/qwidget_p.h" | 
|---|
| 79 | #include "private/qapplication_p.h" | 
|---|
| 80 |  | 
|---|
| 81 | #if !defined(QT_NO_STYLE_S60) || defined(QT_PLUGIN) | 
|---|
| 82 |  | 
|---|
| 83 | QT_BEGIN_NAMESPACE | 
|---|
| 84 |  | 
|---|
| 85 | // from text/qfont.cpp | 
|---|
| 86 | extern Q_GUI_EXPORT int qt_defaultDpiY(); | 
|---|
| 87 |  | 
|---|
| 88 | const QS60StylePrivate::SkinElementFlags QS60StylePrivate::KDefaultSkinElementFlags = | 
|---|
| 89 | SkinElementFlags(SF_PointNorth | SF_StateEnabled); | 
|---|
| 90 |  | 
|---|
| 91 | static const qreal goldenRatio = 1.618; | 
|---|
| 92 |  | 
|---|
| 93 | const layoutHeader QS60StylePrivate::m_layoutHeaders[] = { | 
|---|
| 94 | // *** generated layout data *** | 
|---|
| 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 | {352,800,1,12,"E90 Landscape"}, | 
|---|
| 100 | {480,640,1,19,"VGA Landscape"} | 
|---|
| 101 | // *** End of generated data *** | 
|---|
| 102 | }; | 
|---|
| 103 | const int QS60StylePrivate::m_numberOfLayouts = | 
|---|
| 104 | (int)sizeof(QS60StylePrivate::m_layoutHeaders)/sizeof(QS60StylePrivate::m_layoutHeaders[0]); | 
|---|
| 105 |  | 
|---|
| 106 | const short QS60StylePrivate::data[][MAX_PIXELMETRICS] = { | 
|---|
| 107 | // *** generated pixel metrics *** | 
|---|
| 108 | {5,0,-909,0,0,2,0,2,-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}, | 
|---|
| 109 | {5,0,-909,0,0,1,0,2,-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}, | 
|---|
| 110 | {7,0,-909,0,0,2,0,5,-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,3,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}, | 
|---|
| 111 | {7,0,-909,0,0,2,0,5,-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,3,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}, | 
|---|
| 112 | {7,0,-909,0,0,2,0,2,-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}, | 
|---|
| 113 | {9,0,-909,0,0,2,0,5,-1,34,99,76,51,51,25,352,-909,-909,-909,29,25,7,0,0,43,34,42,76,7,7,2,-909,-909,0,9,14,0,23,39,30,30,37,37,9,391,40,0,-909,-909,-909,-909,0,0,29,2,-909,0,0,-909,29,-909,-909,-909,-909,115,37,96,48,96,19,19,9,1,25,-909,9,101,24,9,0,7,7,7,16,7,7,-909,3,-909,-909,-909,-909,9,9,3,1,184} | 
|---|
| 114 | // *** End of generated data *** | 
|---|
| 115 | }; | 
|---|
| 116 |  | 
|---|
| 117 | const short *QS60StylePrivate::m_pmPointer = QS60StylePrivate::data[0]; | 
|---|
| 118 |  | 
|---|
| 119 | // theme background texture | 
|---|
| 120 | QPixmap *QS60StylePrivate::m_background = 0; | 
|---|
| 121 |  | 
|---|
| 122 | // theme palette | 
|---|
| 123 | QPalette *QS60StylePrivate::m_themePalette = 0; | 
|---|
| 124 |  | 
|---|
| 125 | qint64 QS60StylePrivate::m_webPaletteKey = 0; | 
|---|
| 126 |  | 
|---|
| 127 | QPointer<QWidget> QS60StylePrivate::m_pressedWidget = 0; | 
|---|
| 128 |  | 
|---|
| 129 | const struct QS60StylePrivate::frameElementCenter QS60StylePrivate::m_frameElementsData[] = { | 
|---|
| 130 | {SE_ButtonNormal,           QS60StyleEnums::SP_QsnFrButtonTbCenter}, | 
|---|
| 131 | {SE_ButtonPressed,          QS60StyleEnums::SP_QsnFrButtonTbCenterPressed}, | 
|---|
| 132 | {SE_FrameLineEdit,          QS60StyleEnums::SP_QsnFrInputCenter}, | 
|---|
| 133 | {SE_ListHighlight,          QS60StyleEnums::SP_QsnFrListCenter}, | 
|---|
| 134 | {SE_PopupBackground,        QS60StyleEnums::SP_QsnFrPopupCenter}, | 
|---|
| 135 | {SE_SettingsList,           QS60StyleEnums::SP_QsnFrSetOptCenter}, | 
|---|
| 136 | {SE_TableItem,              QS60StyleEnums::SP_QsnFrCaleCenter}, | 
|---|
| 137 | {SE_TableHeaderItem,        QS60StyleEnums::SP_QsnFrCaleHeadingCenter}, | 
|---|
| 138 | {SE_ToolTip,                QS60StyleEnums::SP_QsnFrPopupPreviewCenter}, | 
|---|
| 139 | {SE_ToolBar,                QS60StyleEnums::SP_QsnFrPopupSubCenter}, | 
|---|
| 140 | {SE_ToolBarButton,          QS60StyleEnums::SP_QgnFrSctrlButtonCenter}, | 
|---|
| 141 | {SE_ToolBarButtonPressed,   QS60StyleEnums::SP_QgnFrSctrlButtonCenterPressed}, | 
|---|
| 142 | {SE_PanelBackground,        QS60StyleEnums::SP_QsnFrSetOptCenter}, | 
|---|
| 143 | {SE_ButtonInactive,         QS60StyleEnums::SP_QsnFrButtonCenterInactive}, | 
|---|
| 144 | {SE_Editor,                 QS60StyleEnums::SP_QsnFrInputCenter}, | 
|---|
| 145 | {SE_TableItemPressed,       QS60StyleEnums::SP_QsnFrGridCenterPressed}, | 
|---|
| 146 | {SE_ListItemPressed,        QS60StyleEnums::SP_QsnFrListCenterPressed}, | 
|---|
| 147 | }; | 
|---|
| 148 |  | 
|---|
| 149 | static const int frameElementsCount = | 
|---|
| 150 | int(sizeof(QS60StylePrivate::m_frameElementsData)/sizeof(QS60StylePrivate::m_frameElementsData[0])); | 
|---|
| 151 |  | 
|---|
| 152 | const int KNotFound = -909; | 
|---|
| 153 | const double KTabFontMul = 0.72; | 
|---|
| 154 |  | 
|---|
| 155 | QS60StylePrivate::~QS60StylePrivate() | 
|---|
| 156 | { | 
|---|
| 157 | clearCaches(); //deletes also background image | 
|---|
| 158 | deleteThemePalette(); | 
|---|
| 159 | #ifdef Q_WS_S60 | 
|---|
| 160 | removeAnimations(); | 
|---|
| 161 | #endif | 
|---|
| 162 | } | 
|---|
| 163 |  | 
|---|
| 164 | void QS60StylePrivate::drawSkinElement(SkinElements element, QPainter *painter, | 
|---|
| 165 | const QRect &rect, SkinElementFlags flags) | 
|---|
| 166 | { | 
|---|
| 167 | switch (element) { | 
|---|
| 168 | case SE_ButtonNormal: | 
|---|
| 169 | drawFrame(SF_ButtonNormal, painter, rect, flags | SF_PointNorth); | 
|---|
| 170 | break; | 
|---|
| 171 | case SE_ButtonPressed: | 
|---|
| 172 | drawFrame(SF_ButtonPressed, painter, rect, flags | SF_PointNorth); | 
|---|
| 173 | break; | 
|---|
| 174 | case SE_FrameLineEdit: | 
|---|
| 175 | drawFrame(SF_FrameLineEdit, painter, rect, flags | SF_PointNorth); | 
|---|
| 176 | break; | 
|---|
| 177 | case SE_ProgressBarGrooveHorizontal: | 
|---|
| 178 | drawRow(QS60StyleEnums::SP_QgnGrafBarFrameSideL, QS60StyleEnums::SP_QgnGrafBarFrameCenter, | 
|---|
| 179 | QS60StyleEnums::SP_QgnGrafBarFrameSideR, Qt::Horizontal, painter, rect, flags | SF_PointNorth); | 
|---|
| 180 | break; | 
|---|
| 181 | case SE_ProgressBarGrooveVertical: | 
|---|
| 182 | drawRow(QS60StyleEnums::SP_QgnGrafBarFrameSideL, QS60StyleEnums::SP_QgnGrafBarFrameCenter, | 
|---|
| 183 | QS60StyleEnums::SP_QgnGrafBarFrameSideR, Qt::Vertical, painter, rect, flags | SF_PointEast); | 
|---|
| 184 | break; | 
|---|
| 185 | case SE_ProgressBarIndicatorHorizontal: | 
|---|
| 186 | drawPart(QS60StyleEnums::SP_QgnGrafBarProgress, painter, rect, flags | SF_PointNorth); | 
|---|
| 187 | break; | 
|---|
| 188 | case SE_ProgressBarIndicatorVertical: | 
|---|
| 189 | drawPart(QS60StyleEnums::SP_QgnGrafBarProgress, painter, rect, flags | SF_PointWest); | 
|---|
| 190 | break; | 
|---|
| 191 | case SE_ScrollBarGrooveHorizontal: | 
|---|
| 192 | drawRow(QS60StyleEnums::SP_QsnCpScrollBgBottom, QS60StyleEnums::SP_QsnCpScrollBgMiddle, | 
|---|
| 193 | QS60StyleEnums::SP_QsnCpScrollBgTop, Qt::Horizontal, painter, rect, flags | SF_PointEast); | 
|---|
| 194 | break; | 
|---|
| 195 | case SE_ScrollBarGrooveVertical: | 
|---|
| 196 | drawRow(QS60StyleEnums::SP_QsnCpScrollBgTop, QS60StyleEnums::SP_QsnCpScrollBgMiddle, | 
|---|
| 197 | QS60StyleEnums::SP_QsnCpScrollBgBottom, Qt::Vertical, painter, rect, flags | SF_PointNorth); | 
|---|
| 198 | break; | 
|---|
| 199 | case SE_ScrollBarHandleHorizontal: | 
|---|
| 200 | drawRow(QS60StyleEnums::SP_QsnCpScrollHandleBottom, QS60StyleEnums::SP_QsnCpScrollHandleMiddle, | 
|---|
| 201 | QS60StyleEnums::SP_QsnCpScrollHandleTop, Qt::Horizontal, painter, rect, flags | SF_PointEast); | 
|---|
| 202 | break; | 
|---|
| 203 | case SE_ScrollBarHandleVertical: | 
|---|
| 204 | drawRow(QS60StyleEnums::SP_QsnCpScrollHandleTop, QS60StyleEnums::SP_QsnCpScrollHandleMiddle, | 
|---|
| 205 | QS60StyleEnums::SP_QsnCpScrollHandleBottom, Qt::Vertical, painter, rect, flags | SF_PointNorth); | 
|---|
| 206 | break; | 
|---|
| 207 | case SE_SliderHandleHorizontal: | 
|---|
| 208 | drawPart(QS60StyleEnums::SP_QgnGrafNsliderMarker, painter, rect, flags | SF_PointNorth); | 
|---|
| 209 | break; | 
|---|
| 210 | case SE_SliderHandleVertical: | 
|---|
| 211 | drawPart(QS60StyleEnums::SP_QgnGrafNsliderMarker, painter, rect, flags | SF_PointEast); | 
|---|
| 212 | break; | 
|---|
| 213 | case SE_SliderHandleSelectedHorizontal: | 
|---|
| 214 | drawPart(QS60StyleEnums::SP_QgnGrafNsliderMarkerSelected, painter, rect, flags | SF_PointNorth); | 
|---|
| 215 | break; | 
|---|
| 216 | case SE_SliderHandleSelectedVertical: | 
|---|
| 217 | drawPart(QS60StyleEnums::SP_QgnGrafNsliderMarkerSelected, painter, rect, flags | SF_PointEast); | 
|---|
| 218 | break; | 
|---|
| 219 | case SE_SliderGrooveVertical: | 
|---|
| 220 | drawRow(QS60StyleEnums::SP_QgnGrafNsliderEndLeft, QS60StyleEnums::SP_QgnGrafNsliderMiddle, | 
|---|
| 221 | QS60StyleEnums::SP_QgnGrafNsliderEndRight, Qt::Vertical, painter, rect, flags | SF_PointEast); | 
|---|
| 222 | break; | 
|---|
| 223 | case SE_SliderGrooveHorizontal: | 
|---|
| 224 | drawRow(QS60StyleEnums::SP_QgnGrafNsliderEndLeft, QS60StyleEnums::SP_QgnGrafNsliderMiddle, | 
|---|
| 225 | QS60StyleEnums::SP_QgnGrafNsliderEndRight, Qt::Horizontal, painter, rect, flags | SF_PointNorth); | 
|---|
| 226 | break; | 
|---|
| 227 | case SE_TabBarTabEastActive: | 
|---|
| 228 | drawRow(QS60StyleEnums::SP_QgnGrafTabActiveL, QS60StyleEnums::SP_QgnGrafTabActiveM, | 
|---|
| 229 | QS60StyleEnums::SP_QgnGrafTabActiveR, Qt::Vertical, painter, rect, flags | SF_PointEast); | 
|---|
| 230 | break; | 
|---|
| 231 | case SE_TabBarTabEastInactive: | 
|---|
| 232 | drawRow(QS60StyleEnums::SP_QgnGrafTabPassiveL, QS60StyleEnums::SP_QgnGrafTabPassiveM, | 
|---|
| 233 | QS60StyleEnums::SP_QgnGrafTabPassiveR, Qt::Vertical, painter, rect, flags | SF_PointEast); | 
|---|
| 234 | break; | 
|---|
| 235 | case SE_TabBarTabNorthActive: | 
|---|
| 236 | drawRow(QS60StyleEnums::SP_QgnGrafTabActiveL, QS60StyleEnums::SP_QgnGrafTabActiveM, | 
|---|
| 237 | QS60StyleEnums::SP_QgnGrafTabActiveR, Qt::Horizontal, painter, rect, flags | SF_PointNorth); | 
|---|
| 238 | break; | 
|---|
| 239 | case SE_TabBarTabNorthInactive: | 
|---|
| 240 | drawRow(QS60StyleEnums::SP_QgnGrafTabPassiveL, QS60StyleEnums::SP_QgnGrafTabPassiveM, | 
|---|
| 241 | QS60StyleEnums::SP_QgnGrafTabPassiveR, Qt::Horizontal, painter, rect, flags | SF_PointNorth); | 
|---|
| 242 | break; | 
|---|
| 243 | case SE_TabBarTabSouthActive: | 
|---|
| 244 | drawRow(QS60StyleEnums::SP_QgnGrafTabActiveR, QS60StyleEnums::SP_QgnGrafTabActiveM, | 
|---|
| 245 | QS60StyleEnums::SP_QgnGrafTabActiveL, Qt::Horizontal, painter, rect, flags | SF_PointSouth); | 
|---|
| 246 | break; | 
|---|
| 247 | case SE_TabBarTabSouthInactive: | 
|---|
| 248 | drawRow(QS60StyleEnums::SP_QgnGrafTabPassiveR, QS60StyleEnums::SP_QgnGrafTabPassiveM, | 
|---|
| 249 | QS60StyleEnums::SP_QgnGrafTabPassiveL, Qt::Horizontal, painter, rect, flags | SF_PointSouth); | 
|---|
| 250 | break; | 
|---|
| 251 | case SE_TabBarTabWestActive: | 
|---|
| 252 | drawRow(QS60StyleEnums::SP_QgnGrafTabActiveR, QS60StyleEnums::SP_QgnGrafTabActiveM, | 
|---|
| 253 | QS60StyleEnums::SP_QgnGrafTabActiveL, Qt::Vertical, painter, rect, flags | SF_PointWest); | 
|---|
| 254 | break; | 
|---|
| 255 | case SE_TabBarTabWestInactive: | 
|---|
| 256 | drawRow(QS60StyleEnums::SP_QgnGrafTabPassiveR, QS60StyleEnums::SP_QgnGrafTabPassiveM, | 
|---|
| 257 | QS60StyleEnums::SP_QgnGrafTabPassiveL, Qt::Vertical, painter, rect, flags | SF_PointWest); | 
|---|
| 258 | break; | 
|---|
| 259 | case SE_ListHighlight: | 
|---|
| 260 | drawFrame(SF_ListHighlight, painter, rect, flags | SF_PointNorth); | 
|---|
| 261 | break; | 
|---|
| 262 | case SE_PopupBackground: | 
|---|
| 263 | drawFrame(SF_PopupBackground, painter, rect, flags | SF_PointNorth); | 
|---|
| 264 | break; | 
|---|
| 265 | case SE_SettingsList: | 
|---|
| 266 | drawFrame(SF_SettingsList, painter, rect, flags | SF_PointNorth); | 
|---|
| 267 | break; | 
|---|
| 268 | case SE_TableItem: | 
|---|
| 269 | drawFrame(SF_TableItem, painter, rect, flags | SF_PointNorth); | 
|---|
| 270 | break; | 
|---|
| 271 | case SE_TableHeaderItem: | 
|---|
| 272 | drawFrame(SF_TableHeaderItem, painter, rect, flags | SF_PointNorth); | 
|---|
| 273 | break; | 
|---|
| 274 | case SE_ToolTip: | 
|---|
| 275 | drawFrame(SF_ToolTip, painter, rect, flags | SF_PointNorth); | 
|---|
| 276 | break; | 
|---|
| 277 | case SE_ToolBar: | 
|---|
| 278 | drawFrame(SF_ToolBar, painter, rect, flags | SF_PointNorth); | 
|---|
| 279 | break; | 
|---|
| 280 | case SE_ToolBarButton: | 
|---|
| 281 | drawFrame(SF_ToolBarButton, painter, rect, flags | SF_PointNorth); | 
|---|
| 282 | break; | 
|---|
| 283 | case SE_ToolBarButtonPressed: | 
|---|
| 284 | drawFrame(SF_ToolBarButtonPressed, painter, rect, flags | SF_PointNorth); | 
|---|
| 285 | break; | 
|---|
| 286 | case SE_PanelBackground: | 
|---|
| 287 | drawFrame(SF_PanelBackground, painter, rect, flags | SF_PointNorth); | 
|---|
| 288 | break; | 
|---|
| 289 | case SE_ScrollBarHandlePressedHorizontal: | 
|---|
| 290 | drawRow(QS60StyleEnums::SP_QsnCpScrollHandleBottomPressed, QS60StyleEnums::SP_QsnCpScrollHandleMiddlePressed, | 
|---|
| 291 | QS60StyleEnums::SP_QsnCpScrollHandleTopPressed, Qt::Horizontal, painter, rect, flags | SF_PointEast); | 
|---|
| 292 | break; | 
|---|
| 293 | case SE_ScrollBarHandlePressedVertical: | 
|---|
| 294 | drawRow(QS60StyleEnums::SP_QsnCpScrollHandleTopPressed, QS60StyleEnums::SP_QsnCpScrollHandleMiddlePressed, | 
|---|
| 295 | QS60StyleEnums::SP_QsnCpScrollHandleBottomPressed, Qt::Vertical, painter, rect, flags | SF_PointNorth); | 
|---|
| 296 | break; | 
|---|
| 297 | case SE_ButtonInactive: | 
|---|
| 298 | drawFrame(SF_ButtonInactive, painter, rect, flags | SF_PointNorth); | 
|---|
| 299 | break; | 
|---|
| 300 | case SE_Editor: | 
|---|
| 301 | drawFrame(SF_FrameLineEdit, painter, rect, flags | SF_PointNorth); | 
|---|
| 302 | break; | 
|---|
| 303 | case SE_DropArea: | 
|---|
| 304 | drawPart(QS60StyleEnums::SP_QgnGrafOrgBgGrid, painter, rect, flags | SF_PointNorth); | 
|---|
| 305 | break; | 
|---|
| 306 | case SE_TableItemPressed: | 
|---|
| 307 | drawFrame(SF_TableItemPressed, painter, rect, flags | SF_PointNorth); | 
|---|
| 308 | break; | 
|---|
| 309 | case SE_ListItemPressed: | 
|---|
| 310 | drawFrame(SF_ListItemPressed, painter, rect, flags | SF_PointNorth); | 
|---|
| 311 | break; | 
|---|
| 312 | default: | 
|---|
| 313 | break; | 
|---|
| 314 | } | 
|---|
| 315 | } | 
|---|
| 316 |  | 
|---|
| 317 | void QS60StylePrivate::drawSkinPart(QS60StyleEnums::SkinParts part, | 
|---|
| 318 | QPainter *painter, const QRect &rect, SkinElementFlags flags) | 
|---|
| 319 | { | 
|---|
| 320 | drawPart(part, painter, rect, flags); | 
|---|
| 321 | } | 
|---|
| 322 |  | 
|---|
| 323 | short QS60StylePrivate::pixelMetric(int metric) | 
|---|
| 324 | { | 
|---|
| 325 | //If it is a custom value, need to strip away the base to map to internal | 
|---|
| 326 | //pixel metric value table | 
|---|
| 327 | if (metric & QStyle::PM_CustomBase) { | 
|---|
| 328 | metric -= QStyle::PM_CustomBase; | 
|---|
| 329 | metric += MAX_NON_CUSTOM_PIXELMETRICS - 1; | 
|---|
| 330 | } | 
|---|
| 331 |  | 
|---|
| 332 | Q_ASSERT(metric < MAX_PIXELMETRICS); | 
|---|
| 333 | const short returnValue = m_pmPointer[metric]; | 
|---|
| 334 | return returnValue; | 
|---|
| 335 | } | 
|---|
| 336 |  | 
|---|
| 337 | QColor QS60StylePrivate::stateColor(const QColor &color, const QStyleOption *option) | 
|---|
| 338 | { | 
|---|
| 339 | QColor retColor (color); | 
|---|
| 340 | if (option && !(option->state & QStyle::State_Enabled)) { | 
|---|
| 341 | QColor hsvColor = retColor.toHsv(); | 
|---|
| 342 | int colorSat = hsvColor.saturation(); | 
|---|
| 343 | int colorVal = hsvColor.value(); | 
|---|
| 344 | colorSat = (colorSat != 0) ? (colorSat >> 1) : 128; | 
|---|
| 345 | colorVal = (colorVal != 0) ? (colorVal >> 1) : 128; | 
|---|
| 346 | hsvColor.setHsv(hsvColor.hue(), colorSat, colorVal); | 
|---|
| 347 | retColor = hsvColor.toRgb(); | 
|---|
| 348 | } | 
|---|
| 349 | return retColor; | 
|---|
| 350 | } | 
|---|
| 351 |  | 
|---|
| 352 | QColor QS60StylePrivate::lighterColor(const QColor &baseColor) | 
|---|
| 353 | { | 
|---|
| 354 | QColor result(baseColor); | 
|---|
| 355 | bool modifyColor = false; | 
|---|
| 356 | if (result.saturation() == 0) { | 
|---|
| 357 | result.setHsv(result.hue(), 128, result.value()); | 
|---|
| 358 | modifyColor = true; | 
|---|
| 359 | } | 
|---|
| 360 | if (result.value() == 0) { | 
|---|
| 361 | result.setHsv(result.hue(), result.saturation(), 128); | 
|---|
| 362 | modifyColor = true; | 
|---|
| 363 | } | 
|---|
| 364 | if (modifyColor) | 
|---|
| 365 | result = result.lighter(175); | 
|---|
| 366 | else | 
|---|
| 367 | result = result.lighter(225); | 
|---|
| 368 | return result; | 
|---|
| 369 | } | 
|---|
| 370 |  | 
|---|
| 371 | bool QS60StylePrivate::drawsOwnThemeBackground(const QWidget *widget) | 
|---|
| 372 | { | 
|---|
| 373 | return (widget ? (widget->windowType() == Qt::Dialog) : false); | 
|---|
| 374 | } | 
|---|
| 375 |  | 
|---|
| 376 | QFont QS60StylePrivate::s60Font( | 
|---|
| 377 | QS60StyleEnums::FontCategories fontCategory, | 
|---|
| 378 | int pointSize, bool resolveFontSize) const | 
|---|
| 379 | { | 
|---|
| 380 | QFont result; | 
|---|
| 381 | int actualPointSize = pointSize; | 
|---|
| 382 | if (actualPointSize <= 0) { | 
|---|
| 383 | const QFont appFont = QApplication::font(); | 
|---|
| 384 | actualPointSize = appFont.pointSize(); | 
|---|
| 385 | if (actualPointSize <= 0) | 
|---|
| 386 | actualPointSize = appFont.pixelSize() * 72 / qt_defaultDpiY(); | 
|---|
| 387 | } | 
|---|
| 388 | Q_ASSERT(actualPointSize > 0); | 
|---|
| 389 | const QPair<QS60StyleEnums::FontCategories, int> key(fontCategory, actualPointSize); | 
|---|
| 390 | if (!m_mappedFontsCache.contains(key)) { | 
|---|
| 391 | result = s60Font_specific(fontCategory, actualPointSize, resolveFontSize); | 
|---|
| 392 | m_mappedFontsCache.insert(key, result); | 
|---|
| 393 | } else { | 
|---|
| 394 | result = m_mappedFontsCache.value(key); | 
|---|
| 395 | if (result.pointSize() != actualPointSize) | 
|---|
| 396 | result.setPointSize(actualPointSize); | 
|---|
| 397 | } | 
|---|
| 398 | return result; | 
|---|
| 399 | } | 
|---|
| 400 |  | 
|---|
| 401 | void QS60StylePrivate::clearCaches(CacheClearReason reason) | 
|---|
| 402 | { | 
|---|
| 403 | switch(reason){ | 
|---|
| 404 | case CC_LayoutChange: | 
|---|
| 405 | // when layout changes, the colors remain in cache, but graphics and fonts can change | 
|---|
| 406 | m_mappedFontsCache.clear(); | 
|---|
| 407 | QPixmapCache::clear(); | 
|---|
| 408 | break; | 
|---|
| 409 | case CC_ThemeChange: | 
|---|
| 410 | QPixmapCache::clear(); | 
|---|
| 411 | #ifdef Q_WS_S60 | 
|---|
| 412 | deleteStoredSettings(); | 
|---|
| 413 | #endif | 
|---|
| 414 | deleteBackground(); | 
|---|
| 415 | break; | 
|---|
| 416 | case CC_UndefinedChange: | 
|---|
| 417 | default: | 
|---|
| 418 | m_mappedFontsCache.clear(); | 
|---|
| 419 | QPixmapCache::clear(); | 
|---|
| 420 | deleteBackground(); | 
|---|
| 421 | break; | 
|---|
| 422 | } | 
|---|
| 423 | } | 
|---|
| 424 |  | 
|---|
| 425 | QColor QS60StylePrivate::calculatedColor(SkinFrameElements frame) const | 
|---|
| 426 | { | 
|---|
| 427 | const int frameCornerWidth = pixelMetric(PM_FrameCornerWidth); | 
|---|
| 428 | const int frameCornerHeight = pixelMetric(PM_FrameCornerHeight); | 
|---|
| 429 | Q_ASSERT(2 * frameCornerWidth < 32); | 
|---|
| 430 | Q_ASSERT(2 * frameCornerHeight < 32); | 
|---|
| 431 |  | 
|---|
| 432 | const QImage frameImage = QS60StylePrivate::frame(frame, QSize(32, 32)).toImage(); | 
|---|
| 433 | Q_ASSERT(frameImage.bytesPerLine() > 0); | 
|---|
| 434 | if (frameImage.isNull()) | 
|---|
| 435 | return Qt::black; | 
|---|
| 436 |  | 
|---|
| 437 | const QRgb *pixelRgb = (const QRgb*)frameImage.constBits(); | 
|---|
| 438 | const int pixels = frameImage.byteCount() / sizeof(QRgb); | 
|---|
| 439 |  | 
|---|
| 440 | int estimatedRed = 0; | 
|---|
| 441 | int estimatedGreen = 0; | 
|---|
| 442 | int estimatedBlue = 0; | 
|---|
| 443 |  | 
|---|
| 444 | int skips = 0; | 
|---|
| 445 | int estimations = 0; | 
|---|
| 446 |  | 
|---|
| 447 | const int topBorderLastPixel = frameCornerHeight * frameImage.width() - 1; | 
|---|
| 448 | const int bottomBorderFirstPixel = frameImage.width() * frameImage.height() - topBorderLastPixel; | 
|---|
| 449 | const int rightBorderFirstPixel = frameImage.width() - frameCornerWidth; | 
|---|
| 450 | const int leftBorderLastPixel = frameCornerWidth; | 
|---|
| 451 |  | 
|---|
| 452 | while ((skips + estimations) < pixels) { | 
|---|
| 453 | if ((skips + estimations) > topBorderLastPixel && | 
|---|
| 454 | (skips + estimations) < bottomBorderFirstPixel) { | 
|---|
| 455 | for (int rowIndex = 0; rowIndex < frameImage.width(); rowIndex++) { | 
|---|
| 456 | if (rowIndex > leftBorderLastPixel && | 
|---|
| 457 | rowIndex < rightBorderFirstPixel) { | 
|---|
| 458 | estimatedRed += qRed(*pixelRgb); | 
|---|
| 459 | estimatedGreen += qGreen(*pixelRgb); | 
|---|
| 460 | estimatedBlue += qBlue(*pixelRgb); | 
|---|
| 461 | } | 
|---|
| 462 | pixelRgb++; | 
|---|
| 463 | estimations++; | 
|---|
| 464 | } | 
|---|
| 465 | } else { | 
|---|
| 466 | pixelRgb++; | 
|---|
| 467 | skips++; | 
|---|
| 468 | } | 
|---|
| 469 | } | 
|---|
| 470 | QColor frameColor(estimatedRed/estimations, estimatedGreen/estimations, estimatedBlue/estimations); | 
|---|
| 471 | return !estimations ? Qt::black : frameColor; | 
|---|
| 472 | } | 
|---|
| 473 |  | 
|---|
| 474 | void QS60StylePrivate::setThemePalette(QApplication *app) const | 
|---|
| 475 | { | 
|---|
| 476 | Q_UNUSED(app) | 
|---|
| 477 | QPalette widgetPalette = QPalette(Qt::white); | 
|---|
| 478 | setThemePalette(&widgetPalette); | 
|---|
| 479 | } | 
|---|
| 480 |  | 
|---|
| 481 | QPalette* QS60StylePrivate::themePalette() | 
|---|
| 482 | { | 
|---|
| 483 | return m_themePalette; | 
|---|
| 484 | } | 
|---|
| 485 |  | 
|---|
| 486 | bool QS60StylePrivate::equalToThemePalette(QColor color, QPalette::ColorRole role) | 
|---|
| 487 | { | 
|---|
| 488 | if (!m_themePalette) | 
|---|
| 489 | return false; | 
|---|
| 490 | if (color == m_themePalette->color(role)) | 
|---|
| 491 | return true; | 
|---|
| 492 | return false; | 
|---|
| 493 | } | 
|---|
| 494 |  | 
|---|
| 495 | bool QS60StylePrivate::equalToThemePalette(qint64 cacheKey, QPalette::ColorRole role) | 
|---|
| 496 | { | 
|---|
| 497 | if (!m_themePalette) | 
|---|
| 498 | return false; | 
|---|
| 499 | if (cacheKey == m_themePalette->brush(role).texture().cacheKey()) | 
|---|
| 500 | return true; | 
|---|
| 501 | return false; | 
|---|
| 502 | } | 
|---|
| 503 |  | 
|---|
| 504 | void QS60StylePrivate::setBackgroundTexture(QApplication *app) const | 
|---|
| 505 | { | 
|---|
| 506 | Q_UNUSED(app) | 
|---|
| 507 | QPalette applicationPalette = QApplication::palette(); | 
|---|
| 508 | applicationPalette.setBrush(QPalette::Window, backgroundTexture()); | 
|---|
| 509 | setThemePalette(&applicationPalette); | 
|---|
| 510 | } | 
|---|
| 511 |  | 
|---|
| 512 | void QS60StylePrivate::deleteBackground() | 
|---|
| 513 | { | 
|---|
| 514 | if (m_background) { | 
|---|
| 515 | delete m_background; | 
|---|
| 516 | m_background = 0; | 
|---|
| 517 | } | 
|---|
| 518 | } | 
|---|
| 519 |  | 
|---|
| 520 | void QS60StylePrivate::setCurrentLayout(int index) | 
|---|
| 521 | { | 
|---|
| 522 | m_pmPointer = data[index]; | 
|---|
| 523 | } | 
|---|
| 524 |  | 
|---|
| 525 | void QS60StylePrivate::drawPart(QS60StyleEnums::SkinParts skinPart, | 
|---|
| 526 | QPainter *painter, const QRect &rect, SkinElementFlags flags) | 
|---|
| 527 | { | 
|---|
| 528 | static const bool doCache = | 
|---|
| 529 | #if defined(Q_WS_S60) | 
|---|
| 530 | // Freezes on 3.1. Anyways, caching is only really needed on touch UI | 
|---|
| 531 | !(QSysInfo::s60Version() == QSysInfo::SV_S60_3_1 || QSysInfo::s60Version() == QSysInfo::SV_S60_3_2); | 
|---|
| 532 | #else | 
|---|
| 533 | true; | 
|---|
| 534 | #endif | 
|---|
| 535 |  | 
|---|
| 536 | const QPixmap skinPartPixMap((doCache ? cachedPart : part)(skinPart, rect.size(), painter, flags)); | 
|---|
| 537 | if (!skinPartPixMap.isNull()) | 
|---|
| 538 | painter->drawPixmap(rect.topLeft(), skinPartPixMap); | 
|---|
| 539 | } | 
|---|
| 540 |  | 
|---|
| 541 | void QS60StylePrivate::drawFrame(SkinFrameElements frameElement, QPainter *painter, const QRect &rect, SkinElementFlags flags) | 
|---|
| 542 | { | 
|---|
| 543 | static const bool doCache = | 
|---|
| 544 | #if defined(Q_WS_S60) | 
|---|
| 545 | // Freezes on 3.1. Anyways, caching is only really needed on touch UI | 
|---|
| 546 | !(QSysInfo::s60Version() == QSysInfo::SV_S60_3_1 || QSysInfo::s60Version() == QSysInfo::SV_S60_3_2); | 
|---|
| 547 | #else | 
|---|
| 548 | true; | 
|---|
| 549 | #endif | 
|---|
| 550 | const QPixmap frameElementPixMap((doCache ? cachedFrame : frame)(frameElement, rect.size(), flags)); | 
|---|
| 551 | if (!frameElementPixMap.isNull()) | 
|---|
| 552 | painter->drawPixmap(rect.topLeft(), frameElementPixMap); | 
|---|
| 553 | } | 
|---|
| 554 |  | 
|---|
| 555 | void QS60StylePrivate::drawRow(QS60StyleEnums::SkinParts start, | 
|---|
| 556 | QS60StyleEnums::SkinParts middle, QS60StyleEnums::SkinParts end, | 
|---|
| 557 | Qt::Orientation orientation, QPainter *painter, const QRect &rect, | 
|---|
| 558 | SkinElementFlags flags) | 
|---|
| 559 | { | 
|---|
| 560 | QSize startEndSize(partSize(start, flags)); | 
|---|
| 561 | startEndSize.scale(rect.size(), Qt::KeepAspectRatio); | 
|---|
| 562 |  | 
|---|
| 563 | QRect startRect = QRect(rect.topLeft(), startEndSize); | 
|---|
| 564 | QRect middleRect = rect; | 
|---|
| 565 | QRect endRect; | 
|---|
| 566 |  | 
|---|
| 567 | if (orientation == Qt::Horizontal) { | 
|---|
| 568 | startRect.setHeight(rect.height()); | 
|---|
| 569 | startRect.setWidth(qMin((rect.width() >> 1) - 1, startRect.width())); | 
|---|
| 570 | endRect = startRect.translated(rect.width() - startRect.width(), 0); | 
|---|
| 571 | middleRect.adjust(startRect.width(), 0, -startRect.width(), 0); | 
|---|
| 572 | if (startRect.bottomRight().x() > endRect.topLeft().x()) { | 
|---|
| 573 | const int overlap = (startRect.bottomRight().x() -  endRect.topLeft().x()) >> 1; | 
|---|
| 574 | startRect.setWidth(startRect.width() - overlap); | 
|---|
| 575 | endRect.adjust(overlap, 0, 0, 0); | 
|---|
| 576 | } | 
|---|
| 577 | } else { | 
|---|
| 578 | startRect.setWidth(rect.width()); | 
|---|
| 579 | startRect.setHeight(qMin((rect.height() >> 1) - 1, startRect.height())); | 
|---|
| 580 | endRect = startRect.translated(0, rect.height() - startRect.height()); | 
|---|
| 581 | middleRect.adjust(0, startRect.height(), 0, -startRect.height()); | 
|---|
| 582 | if (startRect.topRight().y() > endRect.bottomLeft().y()) { | 
|---|
| 583 | const int overlap = (startRect.topRight().y() - endRect.bottomLeft().y()) >> 1; | 
|---|
| 584 | startRect.setHeight(startRect.height() - overlap); | 
|---|
| 585 | endRect.adjust(0, overlap, 0, 0); | 
|---|
| 586 | } | 
|---|
| 587 | } | 
|---|
| 588 |  | 
|---|
| 589 | #if 0 | 
|---|
| 590 | painter->save(); | 
|---|
| 591 | painter->setOpacity(.3); | 
|---|
| 592 | painter->fillRect(startRect, Qt::red); | 
|---|
| 593 | painter->fillRect(middleRect, Qt::green); | 
|---|
| 594 | painter->fillRect(endRect, Qt::blue); | 
|---|
| 595 | painter->restore(); | 
|---|
| 596 | #else | 
|---|
| 597 | drawPart(start, painter, startRect, flags); | 
|---|
| 598 | if (middleRect.isValid()) | 
|---|
| 599 | drawPart(middle, painter, middleRect, flags); | 
|---|
| 600 | drawPart(end, painter, endRect, flags); | 
|---|
| 601 | #endif | 
|---|
| 602 | } | 
|---|
| 603 |  | 
|---|
| 604 | QPixmap QS60StylePrivate::cachedPart(QS60StyleEnums::SkinParts part, | 
|---|
| 605 | const QSize &size, QPainter *painter, SkinElementFlags flags) | 
|---|
| 606 | { | 
|---|
| 607 | QPixmap result; | 
|---|
| 608 | const int animationFrame = (flags & SF_Animation) ? currentAnimationFrame(part) : 0; | 
|---|
| 609 |  | 
|---|
| 610 | const QString cacheKey = | 
|---|
| 611 | QString::fromLatin1("S60Style: SkinParts=%1 QSize=%2|%3 SkinPartFlags=%4 AnimationFrame=%5") | 
|---|
| 612 | .arg((int)part).arg(size.width()).arg(size.height()).arg((int)flags).arg(animationFrame); | 
|---|
| 613 | if (!QPixmapCache::find(cacheKey, result)) { | 
|---|
| 614 | result = QS60StylePrivate::part(part, size, painter, flags); | 
|---|
| 615 | QPixmapCache::insert(cacheKey, result); | 
|---|
| 616 | } | 
|---|
| 617 | return result; | 
|---|
| 618 | } | 
|---|
| 619 |  | 
|---|
| 620 | QPixmap QS60StylePrivate::cachedFrame(SkinFrameElements frame, const QSize &size, SkinElementFlags flags) | 
|---|
| 621 | { | 
|---|
| 622 | QPixmap result; | 
|---|
| 623 | const QString cacheKey = | 
|---|
| 624 | QString::fromLatin1("S60Style: SkinFrameElements=%1 QSize=%2|%3 SkinElementFlags=%4") | 
|---|
| 625 | .arg((int)frame).arg(size.width()).arg(size.height()).arg((int)flags); | 
|---|
| 626 | if (!QPixmapCache::find(cacheKey, result)) { | 
|---|
| 627 | result = QS60StylePrivate::frame(frame, size, flags); | 
|---|
| 628 | QPixmapCache::insert(cacheKey, result); | 
|---|
| 629 | } | 
|---|
| 630 | return result; | 
|---|
| 631 | } | 
|---|
| 632 |  | 
|---|
| 633 | void QS60StylePrivate::refreshUI() | 
|---|
| 634 | { | 
|---|
| 635 | QList<QWidget *> widgets = QApplication::allWidgets(); | 
|---|
| 636 |  | 
|---|
| 637 | for (int i = 0; i < widgets.size(); ++i) { | 
|---|
| 638 | QWidget *widget = widgets.at(i); | 
|---|
| 639 | if (widget == 0) | 
|---|
| 640 | continue; | 
|---|
| 641 |  | 
|---|
| 642 | if (widget->style()) { | 
|---|
| 643 | widget->style()->polish(widget); | 
|---|
| 644 | QEvent event(QEvent::StyleChange); | 
|---|
| 645 | qApp->sendEvent(widget, &event); | 
|---|
| 646 | } | 
|---|
| 647 | widget->update(); | 
|---|
| 648 | widget->updateGeometry(); | 
|---|
| 649 | } | 
|---|
| 650 | } | 
|---|
| 651 |  | 
|---|
| 652 | void QS60StylePrivate::setFont(QWidget *widget) const | 
|---|
| 653 | { | 
|---|
| 654 | QS60StyleEnums::FontCategories fontCategory = QS60StyleEnums::FC_Undefined; | 
|---|
| 655 | if (!widget) | 
|---|
| 656 | return; | 
|---|
| 657 | if (qobject_cast<QPushButton *>(widget)){ | 
|---|
| 658 | fontCategory = QS60StyleEnums::FC_Primary; | 
|---|
| 659 | } else if (qobject_cast<QToolButton *>(widget)){ | 
|---|
| 660 | fontCategory = QS60StyleEnums::FC_Primary; | 
|---|
| 661 | } else if (qobject_cast<QHeaderView *>(widget)){ | 
|---|
| 662 | fontCategory = QS60StyleEnums::FC_Secondary; | 
|---|
| 663 | } else if (qobject_cast<QGroupBox *>(widget)){ | 
|---|
| 664 | fontCategory = QS60StyleEnums::FC_Title; | 
|---|
| 665 | } else if (qobject_cast<QMessageBox *>(widget)){ | 
|---|
| 666 | fontCategory = QS60StyleEnums::FC_Primary; | 
|---|
| 667 | } else if (qobject_cast<QMenu *>(widget)){ | 
|---|
| 668 | fontCategory = QS60StyleEnums::FC_Primary; | 
|---|
| 669 | } else if (qobject_cast<QCalendarWidget *>(widget)){ | 
|---|
| 670 | fontCategory = QS60StyleEnums::FC_Secondary; | 
|---|
| 671 | } | 
|---|
| 672 | if (fontCategory != QS60StyleEnums::FC_Undefined) { | 
|---|
| 673 | const bool resolveFontSize = widget->testAttribute(Qt::WA_SetFont) | 
|---|
| 674 | && (widget->font().resolve() & QFont::SizeResolved); | 
|---|
| 675 | const QFont suggestedFont = | 
|---|
| 676 | s60Font(fontCategory, widget->font().pointSizeF(), resolveFontSize); | 
|---|
| 677 | widget->setFont(suggestedFont); | 
|---|
| 678 | } | 
|---|
| 679 | } | 
|---|
| 680 |  | 
|---|
| 681 | void QS60StylePrivate::setThemePalette(QWidget *widget) const | 
|---|
| 682 | { | 
|---|
| 683 | if(!widget) | 
|---|
| 684 | return; | 
|---|
| 685 |  | 
|---|
| 686 | //header view and its viewport need to be set 100% transparent button color, since drawing code will | 
|---|
| 687 | //draw transparent theme graphics to table column and row headers. | 
|---|
| 688 | if (qobject_cast<QHeaderView *>(widget)){ | 
|---|
| 689 | QPalette widgetPalette = QApplication::palette(widget); | 
|---|
| 690 | widgetPalette.setColor(QPalette::Active, QPalette::ButtonText, | 
|---|
| 691 | s60Color(QS60StyleEnums::CL_QsnTextColors, 23, 0)); | 
|---|
| 692 | QHeaderView* header = qobject_cast<QHeaderView *>(widget); | 
|---|
| 693 | widgetPalette.setColor(QPalette::Button, Qt::transparent ); | 
|---|
| 694 | if (header->viewport()) | 
|---|
| 695 | header->viewport()->setPalette(widgetPalette); | 
|---|
| 696 | QApplication::setPalette(widgetPalette, "QHeaderView"); | 
|---|
| 697 | } | 
|---|
| 698 | } | 
|---|
| 699 |  | 
|---|
| 700 | void QS60StylePrivate::setThemePalette(QPalette *palette) const | 
|---|
| 701 | { | 
|---|
| 702 | if (!palette) | 
|---|
| 703 | return; | 
|---|
| 704 |  | 
|---|
| 705 | // basic colors | 
|---|
| 706 | palette->setColor(QPalette::WindowText, | 
|---|
| 707 | s60Color(QS60StyleEnums::CL_QsnTextColors, 6, 0)); | 
|---|
| 708 | palette->setColor(QPalette::ButtonText, | 
|---|
| 709 | s60Color(QS60StyleEnums::CL_QsnTextColors, 20, 0)); | 
|---|
| 710 | palette->setColor(QPalette::Text, | 
|---|
| 711 | s60Color(QS60StyleEnums::CL_QsnTextColors, 6, 0)); | 
|---|
| 712 | palette->setColor(QPalette::ToolTipText, | 
|---|
| 713 | s60Color(QS60StyleEnums::CL_QsnTextColors, 55, 0)); | 
|---|
| 714 | palette->setColor(QPalette::BrightText, palette->color(QPalette::WindowText).lighter()); | 
|---|
| 715 | palette->setColor(QPalette::HighlightedText, | 
|---|
| 716 | s60Color(QS60StyleEnums::CL_QsnTextColors, 24, 0)); | 
|---|
| 717 | palette->setColor(QPalette::Link, | 
|---|
| 718 | s60Color(QS60StyleEnums::CL_QsnHighlightColors, 3, 0)); | 
|---|
| 719 | palette->setColor(QPalette::LinkVisited, palette->color(QPalette::Link).darker()); | 
|---|
| 720 | palette->setColor(QPalette::Highlight, | 
|---|
| 721 | s60Color(QS60StyleEnums::CL_QsnHighlightColors, 2, 0)); | 
|---|
| 722 | // set background image as a texture brush | 
|---|
| 723 | palette->setBrush(QPalette::Window, backgroundTexture()); | 
|---|
| 724 | // set as transparent so that styled full screen theme background is visible | 
|---|
| 725 | palette->setBrush(QPalette::Base, Qt::transparent); | 
|---|
| 726 | // set button color based on pixel colors | 
|---|
| 727 | #ifndef Q_WS_S60 | 
|---|
| 728 | //For emulated style, just calculate the color every time | 
|---|
| 729 | const QColor buttonColor = calculatedColor(SF_ButtonNormal); | 
|---|
| 730 | #else | 
|---|
| 731 | const QColor buttonColor = colorFromFrameGraphics(SF_ButtonNormal); | 
|---|
| 732 | #endif | 
|---|
| 733 | palette->setColor(QPalette::Button, buttonColor); | 
|---|
| 734 | palette->setColor(QPalette::Light, palette->color(QPalette::Button).lighter()); | 
|---|
| 735 | palette->setColor(QPalette::Dark, palette->color(QPalette::Button).darker()); | 
|---|
| 736 | palette->setColor(QPalette::Midlight, palette->color(QPalette::Button).lighter(125)); | 
|---|
| 737 | palette->setColor(QPalette::Mid, palette->color(QPalette::Button).darker(150)); | 
|---|
| 738 | palette->setColor(QPalette::Shadow, Qt::black); | 
|---|
| 739 | QColor alternateBase = palette->light().color(); | 
|---|
| 740 | alternateBase.setAlphaF(0.8); | 
|---|
| 741 | palette->setColor(QPalette::AlternateBase, alternateBase); | 
|---|
| 742 |  | 
|---|
| 743 | QApplication::setPalette(*palette); //calling QApplication::setPalette clears palette hash | 
|---|
| 744 | setThemePaletteHash(palette); | 
|---|
| 745 | storeThemePalette(palette); | 
|---|
| 746 | } | 
|---|
| 747 |  | 
|---|
| 748 | void QS60StylePrivate::deleteThemePalette() | 
|---|
| 749 | { | 
|---|
| 750 | if (m_themePalette) { | 
|---|
| 751 | delete m_themePalette; | 
|---|
| 752 | m_themePalette = 0; | 
|---|
| 753 | } | 
|---|
| 754 | } | 
|---|
| 755 |  | 
|---|
| 756 | void QS60StylePrivate::storeThemePalette(QPalette *palette) | 
|---|
| 757 | { | 
|---|
| 758 | deleteThemePalette(); | 
|---|
| 759 | //store specified palette for latter use. | 
|---|
| 760 | m_themePalette = new QPalette(*palette); | 
|---|
| 761 | } | 
|---|
| 762 |  | 
|---|
| 763 | // set widget specific palettes | 
|---|
| 764 | void QS60StylePrivate::setThemePaletteHash(QPalette *palette) const | 
|---|
| 765 | { | 
|---|
| 766 | if (!palette) | 
|---|
| 767 | return; | 
|---|
| 768 |  | 
|---|
| 769 | //store the original palette | 
|---|
| 770 | QPalette widgetPalette = *palette; | 
|---|
| 771 | const QColor mainAreaTextColor = | 
|---|
| 772 | s60Color(QS60StyleEnums::CL_QsnTextColors, 6, 0); | 
|---|
| 773 |  | 
|---|
| 774 | widgetPalette.setColor(QPalette::WindowText, | 
|---|
| 775 | s60Color(QS60StyleEnums::CL_QsnLineColors, 8, 0)); | 
|---|
| 776 | QApplication::setPalette(widgetPalette, "QSlider"); | 
|---|
| 777 | // return to original palette after each widget | 
|---|
| 778 | widgetPalette = *palette; | 
|---|
| 779 |  | 
|---|
| 780 | widgetPalette.setColor(QPalette::Active, QPalette::ButtonText, mainAreaTextColor); | 
|---|
| 781 | widgetPalette.setColor(QPalette::Inactive, QPalette::ButtonText, mainAreaTextColor); | 
|---|
| 782 | const QStyleOption opt; | 
|---|
| 783 | widgetPalette.setColor(QPalette::Disabled, QPalette::ButtonText, | 
|---|
| 784 | s60Color(QS60StyleEnums::CL_QsnTextColors, 6, &opt)); | 
|---|
| 785 | QApplication::setPalette(widgetPalette, "QPushButton"); | 
|---|
| 786 | widgetPalette = *palette; | 
|---|
| 787 |  | 
|---|
| 788 | widgetPalette.setColor(QPalette::Active, QPalette::ButtonText, mainAreaTextColor); | 
|---|
| 789 | widgetPalette.setColor(QPalette::Inactive, QPalette::ButtonText, mainAreaTextColor); | 
|---|
| 790 | QApplication::setPalette(widgetPalette, "QToolButton"); | 
|---|
| 791 | widgetPalette = *palette; | 
|---|
| 792 |  | 
|---|
| 793 | widgetPalette.setColor(QPalette::Active, QPalette::ButtonText, | 
|---|
| 794 | s60Color(QS60StyleEnums::CL_QsnTextColors, 23, 0)); | 
|---|
| 795 | QApplication::setPalette(widgetPalette, "QHeaderView"); | 
|---|
| 796 | widgetPalette = *palette; | 
|---|
| 797 |  | 
|---|
| 798 | widgetPalette.setColor(QPalette::ButtonText, | 
|---|
| 799 | s60Color(QS60StyleEnums::CL_QsnTextColors, 8, 0)); | 
|---|
| 800 | QApplication::setPalette(widgetPalette, "QMenuBar"); | 
|---|
| 801 | widgetPalette = *palette; | 
|---|
| 802 |  | 
|---|
| 803 | widgetPalette.setColor(QPalette::Text, | 
|---|
| 804 | s60Color(QS60StyleEnums::CL_QsnTextColors, 22, 0)); | 
|---|
| 805 | widgetPalette.setColor(QPalette::HighlightedText, | 
|---|
| 806 | s60Color(QS60StyleEnums::CL_QsnTextColors, 11, 0)); | 
|---|
| 807 | QApplication::setPalette(widgetPalette, "QMenu"); | 
|---|
| 808 | widgetPalette = *palette; | 
|---|
| 809 |  | 
|---|
| 810 | widgetPalette.setColor(QPalette::WindowText, | 
|---|
| 811 | s60Color(QS60StyleEnums::CL_QsnTextColors, 4, 0)); | 
|---|
| 812 | widgetPalette.setColor(QPalette::HighlightedText, | 
|---|
| 813 | s60Color(QS60StyleEnums::CL_QsnTextColors, 3, 0)); | 
|---|
| 814 | QApplication::setPalette(widgetPalette, "QTabBar"); | 
|---|
| 815 | widgetPalette = *palette; | 
|---|
| 816 |  | 
|---|
| 817 | widgetPalette.setColor(QPalette::HighlightedText, | 
|---|
| 818 | s60Color(QS60StyleEnums::CL_QsnTextColors, 10, 0)); | 
|---|
| 819 | QApplication::setPalette(widgetPalette, "QListView"); | 
|---|
| 820 | widgetPalette = *palette; | 
|---|
| 821 |  | 
|---|
| 822 | widgetPalette.setColor(QPalette::Text, | 
|---|
| 823 | s60Color(QS60StyleEnums::CL_QsnTextColors, 22, 0)); | 
|---|
| 824 | widgetPalette.setColor(QPalette::HighlightedText, | 
|---|
| 825 | s60Color(QS60StyleEnums::CL_QsnTextColors, 11, 0)); | 
|---|
| 826 | QApplication::setPalette(widgetPalette, "QTableView"); | 
|---|
| 827 | widgetPalette = *palette; | 
|---|
| 828 |  | 
|---|
| 829 | widgetPalette.setColor(QPalette::Text, | 
|---|
| 830 | s60Color(QS60StyleEnums::CL_QsnTextColors, 27, 0)); | 
|---|
| 831 | widgetPalette.setColor(QPalette::HighlightedText, | 
|---|
| 832 | s60Color(QS60StyleEnums::CL_QsnTextColors, 24, 0)); | 
|---|
| 833 | QApplication::setPalette(widgetPalette, "QLineEdit"); | 
|---|
| 834 | QApplication::setPalette(widgetPalette, "QTextEdit"); | 
|---|
| 835 | QApplication::setPalette(widgetPalette, "QComboBox"); | 
|---|
| 836 | QApplication::setPalette(widgetPalette, "QSpinBox"); | 
|---|
| 837 | widgetPalette = *palette; | 
|---|
| 838 |  | 
|---|
| 839 | widgetPalette.setColor(QPalette::WindowText, s60Color(QS60StyleEnums::CL_QsnTextColors, 7, 0)); | 
|---|
| 840 | widgetPalette.setColor(QPalette::HighlightedText, | 
|---|
| 841 | s60Color(QS60StyleEnums::CL_QsnTextColors, 11, 0)); | 
|---|
| 842 | QApplication::setPalette(widgetPalette, "QRadioButton"); | 
|---|
| 843 | QApplication::setPalette(widgetPalette, "QCheckBox"); | 
|---|
| 844 | widgetPalette = *palette; | 
|---|
| 845 |  | 
|---|
| 846 | widgetPalette.setColor(QPalette::WindowText, mainAreaTextColor); | 
|---|
| 847 | widgetPalette.setColor(QPalette::Button, QApplication::palette().color(QPalette::Button)); | 
|---|
| 848 | widgetPalette.setColor(QPalette::Dark, mainAreaTextColor.darker()); | 
|---|
| 849 | widgetPalette.setColor(QPalette::Light, mainAreaTextColor.lighter()); | 
|---|
| 850 | QApplication::setPalette(widgetPalette, "QDial"); | 
|---|
| 851 | widgetPalette = *palette; | 
|---|
| 852 |  | 
|---|
| 853 | widgetPalette.setBrush(QPalette::Window, QBrush()); | 
|---|
| 854 | QApplication::setPalette(widgetPalette, "QScrollArea"); | 
|---|
| 855 | widgetPalette = *palette; | 
|---|
| 856 |  | 
|---|
| 857 | //Webpages should not use S60 theme colors as they are designed to work | 
|---|
| 858 | //with themeBackground and do not generally mesh well with web page backgrounds. | 
|---|
| 859 | QPalette webPalette = *palette; | 
|---|
| 860 | webPalette.setColor(QPalette::WindowText, Qt::black); | 
|---|
| 861 | webPalette.setColor(QPalette::Text, Qt::black); | 
|---|
| 862 | webPalette.setBrush(QPalette::Base, Qt::white); | 
|---|
| 863 |  | 
|---|
| 864 | QApplication::setPalette(webPalette, "QWebView"); | 
|---|
| 865 | QApplication::setPalette(webPalette, "QGraphicsWebView"); | 
|---|
| 866 |  | 
|---|
| 867 | m_webPaletteKey = webPalette.cacheKey(); | 
|---|
| 868 | } | 
|---|
| 869 |  | 
|---|
| 870 | QSize QS60StylePrivate::partSize(QS60StyleEnums::SkinParts part, SkinElementFlags flags) | 
|---|
| 871 | { | 
|---|
| 872 | QSize result(20, 20); | 
|---|
| 873 | switch (part) | 
|---|
| 874 | { | 
|---|
| 875 | case QS60StyleEnums::SP_QgnGrafBarProgress: | 
|---|
| 876 | result.setWidth(pixelMetric(QStyle::PM_ProgressBarChunkWidth)); | 
|---|
| 877 | break; | 
|---|
| 878 | case QS60StyleEnums::SP_QgnGrafTabActiveM: | 
|---|
| 879 | case QS60StyleEnums::SP_QgnGrafTabPassiveM: | 
|---|
| 880 | case QS60StyleEnums::SP_QgnGrafTabActiveR: | 
|---|
| 881 | case QS60StyleEnums::SP_QgnGrafTabPassiveR: | 
|---|
| 882 | case QS60StyleEnums::SP_QgnGrafTabPassiveL: | 
|---|
| 883 | case QS60StyleEnums::SP_QgnGrafTabActiveL: | 
|---|
| 884 | //Returned QSize for tabs must not be square, but narrow rectangle with width:height | 
|---|
| 885 | //ratio of 1:2 for horizontal tab bars (and 2:1 for vertical ones). | 
|---|
| 886 | result.setWidth(result.height() >> 1); | 
|---|
| 887 | break; | 
|---|
| 888 |  | 
|---|
| 889 | case QS60StyleEnums::SP_QgnGrafNsliderEndLeft: | 
|---|
| 890 | case QS60StyleEnums::SP_QgnGrafNsliderEndRight: | 
|---|
| 891 | case QS60StyleEnums::SP_QgnGrafNsliderMiddle: | 
|---|
| 892 | break; | 
|---|
| 893 |  | 
|---|
| 894 | case QS60StyleEnums::SP_QgnGrafNsliderMarker: | 
|---|
| 895 | case QS60StyleEnums::SP_QgnGrafNsliderMarkerSelected: | 
|---|
| 896 | result.scale(pixelMetric(QStyle::PM_SliderLength), | 
|---|
| 897 | pixelMetric(QStyle::PM_SliderControlThickness), Qt::IgnoreAspectRatio); | 
|---|
| 898 | break; | 
|---|
| 899 |  | 
|---|
| 900 | case QS60StyleEnums::SP_QgnGrafBarFrameSideL: | 
|---|
| 901 | case QS60StyleEnums::SP_QgnGrafBarFrameSideR: | 
|---|
| 902 | result.setWidth(pixelMetric(PM_FrameCornerWidth)); | 
|---|
| 903 | break; | 
|---|
| 904 |  | 
|---|
| 905 | case QS60StyleEnums::SP_QsnCpScrollHandleTopPressed: | 
|---|
| 906 | case QS60StyleEnums::SP_QsnCpScrollBgBottom: | 
|---|
| 907 | case QS60StyleEnums::SP_QsnCpScrollBgTop: | 
|---|
| 908 | case QS60StyleEnums::SP_QsnCpScrollHandleBottom: | 
|---|
| 909 | case QS60StyleEnums::SP_QsnCpScrollHandleTop: | 
|---|
| 910 | case QS60StyleEnums::SP_QsnCpScrollHandleBottomPressed: | 
|---|
| 911 | result.setHeight(pixelMetric(QStyle::PM_ScrollBarExtent)); | 
|---|
| 912 | result.setWidth(pixelMetric(QStyle::PM_ScrollBarExtent)); | 
|---|
| 913 | break; | 
|---|
| 914 | case QS60StyleEnums::SP_QsnCpScrollHandleMiddlePressed: | 
|---|
| 915 | case QS60StyleEnums::SP_QsnCpScrollBgMiddle: | 
|---|
| 916 | case QS60StyleEnums::SP_QsnCpScrollHandleMiddle: | 
|---|
| 917 | result.setHeight(pixelMetric(QStyle::PM_ScrollBarExtent)); | 
|---|
| 918 | result.setWidth(pixelMetric(QStyle::PM_ScrollBarSliderMin)); | 
|---|
| 919 | break; | 
|---|
| 920 | default: | 
|---|
| 921 | // Generic frame part size gathering. | 
|---|
| 922 | for (int i = 0; i < frameElementsCount; ++i) | 
|---|
| 923 | { | 
|---|
| 924 | switch (m_frameElementsData[i].center - part) { | 
|---|
| 925 | case 8: /* CornerTl */ | 
|---|
| 926 | case 7: /* CornerTr */ | 
|---|
| 927 | case 6: /* CornerBl */ | 
|---|
| 928 | case 5: /* CornerBr */ | 
|---|
| 929 | result.setWidth(pixelMetric(PM_FrameCornerWidth)); | 
|---|
| 930 | // Falltrough intended... | 
|---|
| 931 | case 4: /* SideT */ | 
|---|
| 932 | case 3: /* SideB */ | 
|---|
| 933 | result.setHeight(pixelMetric(PM_FrameCornerHeight)); | 
|---|
| 934 | break; | 
|---|
| 935 | case 2: /* SideL */ | 
|---|
| 936 | case 1: /* SideR */ | 
|---|
| 937 | result.setWidth(pixelMetric(PM_FrameCornerWidth)); | 
|---|
| 938 | break; | 
|---|
| 939 | case 0: /* center */ | 
|---|
| 940 | default: | 
|---|
| 941 | break; | 
|---|
| 942 | } | 
|---|
| 943 | } | 
|---|
| 944 | break; | 
|---|
| 945 | } | 
|---|
| 946 | if (flags & (SF_PointEast | SF_PointWest)) { | 
|---|
| 947 | const int temp = result.width(); | 
|---|
| 948 | result.setWidth(result.height()); | 
|---|
| 949 | result.setHeight(temp); | 
|---|
| 950 | } | 
|---|
| 951 | return result; | 
|---|
| 952 | } | 
|---|
| 953 |  | 
|---|
| 954 | bool QS60StylePrivate::canDrawThemeBackground(const QBrush &backgroundBrush, const QWidget *widget) | 
|---|
| 955 | { | 
|---|
| 956 | // Always return true for web pages. | 
|---|
| 957 | if (widget && m_webPaletteKey == QApplication::palette(widget).cacheKey()) | 
|---|
| 958 | return true; | 
|---|
| 959 | //If brush is not changed from style's default values, draw theme graphics. | 
|---|
| 960 | return (backgroundBrush.color() == Qt::transparent || | 
|---|
| 961 | backgroundBrush.style() == Qt::NoBrush) ? true : false; | 
|---|
| 962 | } | 
|---|
| 963 |  | 
|---|
| 964 | bool QS60StylePrivate::isWidgetPressed(const QWidget *widget) | 
|---|
| 965 | { | 
|---|
| 966 | return (widget && widget == m_pressedWidget); | 
|---|
| 967 | } | 
|---|
| 968 |  | 
|---|
| 969 | /*! | 
|---|
| 970 | \class QS60Style | 
|---|
| 971 | \brief The QS60Style class provides a look and feel suitable for applications on S60. | 
|---|
| 972 | \since 4.6 | 
|---|
| 973 | \ingroup appearance | 
|---|
| 974 |  | 
|---|
| 975 | \sa QMacStyle, QWindowsStyle, QWindowsXPStyle, QWindowsVistaStyle, QPlastiqueStyle, QCleanlooksStyle, QMotifStyle | 
|---|
| 976 | */ | 
|---|
| 977 |  | 
|---|
| 978 |  | 
|---|
| 979 | /*! | 
|---|
| 980 | Destroys the style. | 
|---|
| 981 | */ | 
|---|
| 982 | QS60Style::~QS60Style() | 
|---|
| 983 | { | 
|---|
| 984 | } | 
|---|
| 985 |  | 
|---|
| 986 | /*! | 
|---|
| 987 | \reimp | 
|---|
| 988 | */ | 
|---|
| 989 | void QS60Style::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const | 
|---|
| 990 | { | 
|---|
| 991 | const QS60StylePrivate::SkinElementFlags flags = (option->state & State_Enabled) ?  QS60StylePrivate::SF_StateEnabled : QS60StylePrivate::SF_StateDisabled; | 
|---|
| 992 | SubControls sub = option->subControls; | 
|---|
| 993 |  | 
|---|
| 994 | switch (control) { | 
|---|
| 995 | #ifndef QT_NO_SCROLLBAR | 
|---|
| 996 | case CC_ScrollBar: | 
|---|
| 997 | if (const QStyleOptionSlider *optionSlider = qstyleoption_cast<const QStyleOptionSlider *>(option)) { | 
|---|
| 998 | const bool horizontal = optionSlider->orientation == Qt::Horizontal; | 
|---|
| 999 |  | 
|---|
| 1000 | const QRect scrollBarSlider = subControlRect(control, optionSlider, SC_ScrollBarSlider, widget); | 
|---|
| 1001 | const QRect grooveRect = subControlRect(control, optionSlider, SC_ScrollBarGroove, widget); | 
|---|
| 1002 |  | 
|---|
| 1003 | const QS60StylePrivate::SkinElements grooveElement = | 
|---|
| 1004 | horizontal ? QS60StylePrivate::SE_ScrollBarGrooveHorizontal : QS60StylePrivate::SE_ScrollBarGrooveVertical; | 
|---|
| 1005 | QS60StylePrivate::drawSkinElement(grooveElement, painter, grooveRect, flags); | 
|---|
| 1006 |  | 
|---|
| 1007 | const SubControls subControls = optionSlider->subControls; | 
|---|
| 1008 |  | 
|---|
| 1009 | // select correct slider (horizontal/vertical/pressed) | 
|---|
| 1010 | const bool sliderPressed = ((optionSlider->state & State_Sunken) && (subControls & SC_ScrollBarSlider)); | 
|---|
| 1011 | const QS60StylePrivate::SkinElements handleElement = | 
|---|
| 1012 | horizontal ? | 
|---|
| 1013 | ( sliderPressed ? | 
|---|
| 1014 | QS60StylePrivate::SE_ScrollBarHandlePressedHorizontal : | 
|---|
| 1015 | QS60StylePrivate::SE_ScrollBarHandleHorizontal ) : | 
|---|
| 1016 | ( sliderPressed ? | 
|---|
| 1017 | QS60StylePrivate::SE_ScrollBarHandlePressedVertical : | 
|---|
| 1018 | QS60StylePrivate::SE_ScrollBarHandleVertical); | 
|---|
| 1019 | QS60StylePrivate::drawSkinElement(handleElement, painter, scrollBarSlider, flags); | 
|---|
| 1020 | } | 
|---|
| 1021 | break; | 
|---|
| 1022 | #endif // QT_NO_SCROLLBAR | 
|---|
| 1023 | #ifndef QT_NO_SLIDER | 
|---|
| 1024 | case CC_Slider: | 
|---|
| 1025 | if (const QStyleOptionSlider *optionSlider = qstyleoption_cast<const QStyleOptionSlider *>(option)) { | 
|---|
| 1026 |  | 
|---|
| 1027 | const QRect sliderGroove = subControlRect(control, optionSlider, SC_SliderGroove, widget); | 
|---|
| 1028 | const bool horizontal = optionSlider->orientation == Qt::Horizontal; | 
|---|
| 1029 |  | 
|---|
| 1030 | //Highlight | 
|---|
| 1031 | /*            if (optionSlider->state & State_HasFocus) | 
|---|
| 1032 | drawPrimitive(PE_FrameFocusRect, optionSlider, painter, widget);*/ | 
|---|
| 1033 |  | 
|---|
| 1034 | //Groove graphics | 
|---|
| 1035 | if (QS60StylePrivate::hasSliderGrooveGraphic()) { | 
|---|
| 1036 | const QS60StylePrivate::SkinElements grooveElement = horizontal ? | 
|---|
| 1037 | QS60StylePrivate::SE_SliderGrooveHorizontal : | 
|---|
| 1038 | QS60StylePrivate::SE_SliderGrooveVertical; | 
|---|
| 1039 | QS60StylePrivate::drawSkinElement(grooveElement, painter, sliderGroove, flags); | 
|---|
| 1040 | } else { | 
|---|
| 1041 | const QPoint sliderGrooveCenter = sliderGroove.center(); | 
|---|
| 1042 | const bool horizontal = optionSlider->orientation == Qt::Horizontal; | 
|---|
| 1043 | painter->save(); | 
|---|
| 1044 | if (widget) | 
|---|
| 1045 | painter->setPen(widget->palette().windowText().color()); | 
|---|
| 1046 | if (horizontal) | 
|---|
| 1047 | painter->drawLine(0, sliderGrooveCenter.y(), sliderGroove.right(), sliderGrooveCenter.y()); | 
|---|
| 1048 | else | 
|---|
| 1049 | painter->drawLine(sliderGrooveCenter.x(), 0, sliderGrooveCenter.x(), sliderGroove.bottom()); | 
|---|
| 1050 | painter->restore(); | 
|---|
| 1051 | } | 
|---|
| 1052 |  | 
|---|
| 1053 | //Handle graphics | 
|---|
| 1054 | const QRect sliderHandle = subControlRect(control, optionSlider, SC_SliderHandle, widget); | 
|---|
| 1055 | QS60StylePrivate::SkinElements handleElement; | 
|---|
| 1056 | if (optionSlider->state & State_Sunken) | 
|---|
| 1057 | handleElement = | 
|---|
| 1058 | horizontal ? QS60StylePrivate::SE_SliderHandleSelectedHorizontal : QS60StylePrivate::SE_SliderHandleSelectedVertical; | 
|---|
| 1059 | else | 
|---|
| 1060 | handleElement = | 
|---|
| 1061 | horizontal ? QS60StylePrivate::SE_SliderHandleHorizontal : QS60StylePrivate::SE_SliderHandleVertical; | 
|---|
| 1062 | QS60StylePrivate::drawSkinElement(handleElement, painter, sliderHandle, flags); | 
|---|
| 1063 | } | 
|---|
| 1064 | break; | 
|---|
| 1065 | #endif // QT_NO_SLIDER | 
|---|
| 1066 | #ifndef QT_NO_COMBOBOX | 
|---|
| 1067 | case CC_ComboBox: | 
|---|
| 1068 | if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) { | 
|---|
| 1069 | const QRect cmbxEditField = subControlRect(CC_ComboBox, option, SC_ComboBoxEditField, widget); | 
|---|
| 1070 | const QRect cmbxFrame = subControlRect(CC_ComboBox, option, SC_ComboBoxFrame, widget); | 
|---|
| 1071 | const bool direction = cmb->direction == Qt::LeftToRight; | 
|---|
| 1072 |  | 
|---|
| 1073 | // Button frame | 
|---|
| 1074 | QStyleOptionFrame  buttonOption; | 
|---|
| 1075 | buttonOption.QStyleOption::operator=(*cmb); | 
|---|
| 1076 | const int maxButtonSide = cmbxFrame.width() - cmbxEditField.width(); | 
|---|
| 1077 | const int newTop = cmbxEditField.center().y() - maxButtonSide / 2; | 
|---|
| 1078 | const int topLeftPoint = direction ? | 
|---|
| 1079 | (cmbxEditField.right() + 1) : (cmbxEditField.left() + 1 - maxButtonSide); | 
|---|
| 1080 | const QRect buttonRect(topLeftPoint, newTop, maxButtonSide, maxButtonSide); | 
|---|
| 1081 | buttonOption.rect = buttonRect; | 
|---|
| 1082 | buttonOption.state = cmb->state; | 
|---|
| 1083 | drawPrimitive(PE_PanelButtonCommand, &buttonOption, painter, widget); | 
|---|
| 1084 |  | 
|---|
| 1085 | // draw label background - label itself is drawn separately | 
|---|
| 1086 | const QS60StylePrivate::SkinElements skinElement = QS60StylePrivate::SE_FrameLineEdit; | 
|---|
| 1087 | QS60StylePrivate::drawSkinElement(skinElement, painter, cmbxEditField, flags); | 
|---|
| 1088 |  | 
|---|
| 1089 | // Draw the combobox arrow | 
|---|
| 1090 | if (sub & SC_ComboBoxArrow) { | 
|---|
| 1091 | // Make rect slightly smaller | 
|---|
| 1092 | buttonOption.rect.adjust(1, 1, -1, -1); | 
|---|
| 1093 | painter->save(); | 
|---|
| 1094 | painter->setPen(option->palette.buttonText().color()); | 
|---|
| 1095 | drawPrimitive(PE_IndicatorSpinDown, &buttonOption, painter, widget); | 
|---|
| 1096 | painter->restore(); | 
|---|
| 1097 | } | 
|---|
| 1098 | } | 
|---|
| 1099 | break; | 
|---|
| 1100 | #endif // QT_NO_COMBOBOX | 
|---|
| 1101 | #ifndef QT_NO_TOOLBUTTON | 
|---|
| 1102 | case CC_ToolButton: | 
|---|
| 1103 | if (const QStyleOptionToolButton *toolBtn = qstyleoption_cast<const QStyleOptionToolButton *>(option)) { | 
|---|
| 1104 | State bflags = toolBtn->state & ~State_Sunken; | 
|---|
| 1105 |  | 
|---|
| 1106 | if (bflags & State_AutoRaise) { | 
|---|
| 1107 | if (!(bflags & State_MouseOver) || !(bflags & State_Enabled)) { | 
|---|
| 1108 | bflags &= ~State_Raised; | 
|---|
| 1109 | } | 
|---|
| 1110 | } | 
|---|
| 1111 | State mflags = bflags; | 
|---|
| 1112 | if (toolBtn->state & State_Sunken) { | 
|---|
| 1113 | bflags |= State_Sunken; | 
|---|
| 1114 | mflags |= State_Sunken; | 
|---|
| 1115 | } | 
|---|
| 1116 |  | 
|---|
| 1117 | const QRect button(subControlRect(control, toolBtn, SC_ToolButton, widget)); | 
|---|
| 1118 | QRect menuRect = QRect(); | 
|---|
| 1119 | if (toolBtn->subControls & SC_ToolButtonMenu) | 
|---|
| 1120 | menuRect = subControlRect(control, toolBtn, SC_ToolButtonMenu, widget); | 
|---|
| 1121 |  | 
|---|
| 1122 | if (toolBtn->subControls & SC_ToolButton) { | 
|---|
| 1123 | QStyleOption tool(0); | 
|---|
| 1124 | tool.palette = toolBtn->palette; | 
|---|
| 1125 |  | 
|---|
| 1126 | if (bflags & (State_Sunken | State_On | State_Raised | State_Enabled)) { | 
|---|
| 1127 | tool.rect = button.unite(menuRect); | 
|---|
| 1128 | tool.state = bflags; | 
|---|
| 1129 | drawPrimitive(PE_PanelButtonTool, &tool, painter, widget); | 
|---|
| 1130 | } | 
|---|
| 1131 | if (toolBtn->subControls & SC_ToolButtonMenu) { | 
|---|
| 1132 | tool.rect = menuRect; | 
|---|
| 1133 | tool.state = mflags; | 
|---|
| 1134 | drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget); | 
|---|
| 1135 | } | 
|---|
| 1136 | } | 
|---|
| 1137 | QStyleOptionToolButton toolButton = *toolBtn; | 
|---|
| 1138 | if (toolBtn->features & QStyleOptionToolButton::Arrow) { | 
|---|
| 1139 | PrimitiveElement pe; | 
|---|
| 1140 | switch (toolBtn->arrowType) { | 
|---|
| 1141 | case Qt::LeftArrow: | 
|---|
| 1142 | pe = PE_IndicatorArrowLeft; | 
|---|
| 1143 | break; | 
|---|
| 1144 | case Qt::RightArrow: | 
|---|
| 1145 | pe = PE_IndicatorArrowRight; | 
|---|
| 1146 | break; | 
|---|
| 1147 | case Qt::UpArrow: | 
|---|
| 1148 | pe = PE_IndicatorArrowUp; | 
|---|
| 1149 | break; | 
|---|
| 1150 | case Qt::DownArrow: | 
|---|
| 1151 | pe = PE_IndicatorArrowDown; | 
|---|
| 1152 | break; | 
|---|
| 1153 | default: | 
|---|
| 1154 | break; } | 
|---|
| 1155 | toolButton.rect = button; | 
|---|
| 1156 | drawPrimitive(pe, &toolButton, painter, widget); | 
|---|
| 1157 | } | 
|---|
| 1158 |  | 
|---|
| 1159 | if (toolBtn->text.length() > 0 || | 
|---|
| 1160 | !toolBtn->icon.isNull()) { | 
|---|
| 1161 | const int frameWidth = pixelMetric(PM_DefaultFrameWidth, option, widget); | 
|---|
| 1162 | toolButton.rect = button.adjusted(frameWidth, frameWidth, -frameWidth, -frameWidth); | 
|---|
| 1163 | drawControl(CE_ToolButtonLabel, &toolButton, painter, widget); | 
|---|
| 1164 | } | 
|---|
| 1165 | } | 
|---|
| 1166 | break; | 
|---|
| 1167 | #endif //QT_NO_TOOLBUTTON | 
|---|
| 1168 | #ifndef QT_NO_SPINBOX | 
|---|
| 1169 | case CC_SpinBox: | 
|---|
| 1170 | if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) { | 
|---|
| 1171 | QStyleOptionSpinBox copy = *spinBox; | 
|---|
| 1172 | PrimitiveElement pe; | 
|---|
| 1173 |  | 
|---|
| 1174 | if (spinBox->subControls & SC_SpinBoxUp) { | 
|---|
| 1175 | copy.subControls = SC_SpinBoxUp; | 
|---|
| 1176 | QPalette spinBoxPal = spinBox->palette; | 
|---|
| 1177 | if (!(spinBox->stepEnabled & QAbstractSpinBox::StepUpEnabled)) { | 
|---|
| 1178 | spinBoxPal.setCurrentColorGroup(QPalette::Disabled); | 
|---|
| 1179 | copy.state &= ~State_Enabled; | 
|---|
| 1180 | copy.palette = spinBoxPal; | 
|---|
| 1181 | } | 
|---|
| 1182 |  | 
|---|
| 1183 | if (spinBox->activeSubControls == SC_SpinBoxUp && (spinBox->state & State_Sunken)) { | 
|---|
| 1184 | copy.state |= State_On; | 
|---|
| 1185 | copy.state |= State_Sunken; | 
|---|
| 1186 | } else { | 
|---|
| 1187 | copy.state |= State_Raised; | 
|---|
| 1188 | copy.state &= ~State_Sunken; | 
|---|
| 1189 | } | 
|---|
| 1190 | pe = (spinBox->buttonSymbols == QAbstractSpinBox::PlusMinus) ? | 
|---|
| 1191 | PE_IndicatorSpinPlus : | 
|---|
| 1192 | PE_IndicatorSpinUp; | 
|---|
| 1193 |  | 
|---|
| 1194 | copy.rect = subControlRect(CC_SpinBox, spinBox, SC_SpinBoxUp, widget); | 
|---|
| 1195 | drawPrimitive(PE_PanelButtonBevel, ©, painter, widget); | 
|---|
| 1196 | copy.rect.adjust(1, 1, -1, -1); | 
|---|
| 1197 | drawPrimitive(pe, ©, painter, widget); | 
|---|
| 1198 | } | 
|---|
| 1199 |  | 
|---|
| 1200 | if (spinBox->subControls & SC_SpinBoxDown) { | 
|---|
| 1201 | copy.subControls = SC_SpinBoxDown; | 
|---|
| 1202 | copy.state = spinBox->state; | 
|---|
| 1203 | QPalette spinBoxPal = spinBox->palette; | 
|---|
| 1204 | if (!(spinBox->stepEnabled & QAbstractSpinBox::StepDownEnabled)) { | 
|---|
| 1205 | spinBoxPal.setCurrentColorGroup(QPalette::Disabled); | 
|---|
| 1206 | copy.state &= ~State_Enabled; | 
|---|
| 1207 | copy.palette = spinBoxPal; | 
|---|
| 1208 | } | 
|---|
| 1209 |  | 
|---|
| 1210 | if (spinBox->activeSubControls == SC_SpinBoxDown && (spinBox->state & State_Sunken)) { | 
|---|
| 1211 | copy.state |= State_On; | 
|---|
| 1212 | copy.state |= State_Sunken; | 
|---|
| 1213 | } else { | 
|---|
| 1214 | copy.state |= State_Raised; | 
|---|
| 1215 | copy.state &= ~State_Sunken; | 
|---|
| 1216 | } | 
|---|
| 1217 | pe = (spinBox->buttonSymbols == QAbstractSpinBox::PlusMinus) ? | 
|---|
| 1218 | PE_IndicatorSpinMinus : | 
|---|
| 1219 | PE_IndicatorSpinDown; | 
|---|
| 1220 |  | 
|---|
| 1221 | copy.rect = subControlRect(CC_SpinBox, spinBox, SC_SpinBoxDown, widget); | 
|---|
| 1222 | drawPrimitive(PE_PanelButtonBevel, ©, painter, widget); | 
|---|
| 1223 | copy.rect.adjust(1, 1, -1, -1); | 
|---|
| 1224 | drawPrimitive(pe, ©, painter, widget); | 
|---|
| 1225 | } | 
|---|
| 1226 | } | 
|---|
| 1227 | break; | 
|---|
| 1228 | #endif //QT_NO_SPINBOX | 
|---|
| 1229 | #ifndef QT_NO_GROUPBOX | 
|---|
| 1230 | case CC_GroupBox: | 
|---|
| 1231 | if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) { | 
|---|
| 1232 | // Draw frame | 
|---|
| 1233 | const QRect textRect = subControlRect(CC_GroupBox, option, SC_GroupBoxLabel, widget); | 
|---|
| 1234 | const QRect checkBoxRect = subControlRect(CC_GroupBox, option, SC_GroupBoxCheckBox, widget); | 
|---|
| 1235 | if (groupBox->subControls & SC_GroupBoxFrame) { | 
|---|
| 1236 | QStyleOptionFrameV2 frame; | 
|---|
| 1237 | frame.QStyleOption::operator=(*groupBox); | 
|---|
| 1238 | frame.features = groupBox->features; | 
|---|
| 1239 | frame.lineWidth = groupBox->lineWidth; | 
|---|
| 1240 | frame.midLineWidth = groupBox->midLineWidth; | 
|---|
| 1241 | frame.rect = subControlRect(CC_GroupBox, option, SC_GroupBoxFrame, widget); | 
|---|
| 1242 | drawPrimitive(PE_FrameGroupBox, &frame, painter, widget); | 
|---|
| 1243 | } | 
|---|
| 1244 |  | 
|---|
| 1245 | // Draw title | 
|---|
| 1246 | if ((groupBox->subControls & SC_GroupBoxLabel) && !groupBox->text.isEmpty()) { | 
|---|
| 1247 | const QColor textColor = groupBox->textColor; | 
|---|
| 1248 | painter->save(); | 
|---|
| 1249 |  | 
|---|
| 1250 | if (textColor.isValid()) | 
|---|
| 1251 | painter->setPen(textColor); | 
|---|
| 1252 | int alignment = int(groupBox->textAlignment); | 
|---|
| 1253 | if (!styleHint(SH_UnderlineShortcut, option, widget)) | 
|---|
| 1254 | alignment |= Qt::TextHideMnemonic; | 
|---|
| 1255 |  | 
|---|
| 1256 | drawItemText(painter, textRect,  Qt::TextShowMnemonic | Qt::AlignHCenter | Qt::AlignVCenter | alignment, | 
|---|
| 1257 | groupBox->palette, groupBox->state & State_Enabled, groupBox->text, | 
|---|
| 1258 | textColor.isValid() ? QPalette::NoRole : QPalette::WindowText); | 
|---|
| 1259 | painter->restore(); | 
|---|
| 1260 | } | 
|---|
| 1261 |  | 
|---|
| 1262 | // Draw checkbox | 
|---|
| 1263 | if (groupBox->subControls & SC_GroupBoxCheckBox) { | 
|---|
| 1264 | QStyleOptionButton box; | 
|---|
| 1265 | box.QStyleOption::operator=(*groupBox); | 
|---|
| 1266 | box.rect = checkBoxRect; | 
|---|
| 1267 | drawPrimitive(PE_IndicatorCheckBox, &box, painter, widget); | 
|---|
| 1268 | } | 
|---|
| 1269 | } | 
|---|
| 1270 | break; | 
|---|
| 1271 | #endif //QT_NO_GROUPBOX | 
|---|
| 1272 | default: | 
|---|
| 1273 | QCommonStyle::drawComplexControl(control, option, painter, widget); | 
|---|
| 1274 | } | 
|---|
| 1275 | } | 
|---|
| 1276 |  | 
|---|
| 1277 | /*! | 
|---|
| 1278 | \reimp | 
|---|
| 1279 | */ | 
|---|
| 1280 | void QS60Style::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const | 
|---|
| 1281 | { | 
|---|
| 1282 | Q_D(const QS60Style); | 
|---|
| 1283 | const QS60StylePrivate::SkinElementFlags flags = (option->state & State_Enabled) ?  QS60StylePrivate::SF_StateEnabled : QS60StylePrivate::SF_StateDisabled; | 
|---|
| 1284 | switch (element) { | 
|---|
| 1285 | case CE_CheckBox: | 
|---|
| 1286 | case CE_RadioButton: | 
|---|
| 1287 | if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) { | 
|---|
| 1288 | bool isRadio = (element == CE_RadioButton); | 
|---|
| 1289 | QStyleOptionButton subopt = *btn; | 
|---|
| 1290 |  | 
|---|
| 1291 | // Highlight needs to be drawn first, as it goes "underneath" the text and indicator. | 
|---|
| 1292 | if (btn->state & State_HasFocus) { | 
|---|
| 1293 | QStyleOptionFocusRect fropt; | 
|---|
| 1294 | fropt.QStyleOption::operator=(*btn); | 
|---|
| 1295 | fropt.rect = subElementRect(isRadio ? SE_RadioButtonFocusRect | 
|---|
| 1296 | : SE_CheckBoxFocusRect, btn, widget); | 
|---|
| 1297 | drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget); | 
|---|
| 1298 |  | 
|---|
| 1299 | subopt.palette.setColor(QPalette::Active, QPalette::WindowText, | 
|---|
| 1300 | subopt.palette.highlightedText().color()); | 
|---|
| 1301 | } | 
|---|
| 1302 |  | 
|---|
| 1303 | subopt.rect = subElementRect(isRadio ? SE_RadioButtonIndicator | 
|---|
| 1304 | : SE_CheckBoxIndicator, btn, widget); | 
|---|
| 1305 | drawPrimitive(isRadio ? PE_IndicatorRadioButton : PE_IndicatorCheckBox, | 
|---|
| 1306 | &subopt, painter, widget); | 
|---|
| 1307 | subopt.rect = subElementRect(isRadio ? SE_RadioButtonContents | 
|---|
| 1308 | : SE_CheckBoxContents, btn, widget); | 
|---|
| 1309 |  | 
|---|
| 1310 | drawControl(isRadio ? CE_RadioButtonLabel : CE_CheckBoxLabel, &subopt, painter, widget); | 
|---|
| 1311 | } | 
|---|
| 1312 | break; | 
|---|
| 1313 |  | 
|---|
| 1314 | case CE_PushButton: | 
|---|
| 1315 | if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) { | 
|---|
| 1316 |  | 
|---|
| 1317 | drawControl(CE_PushButtonBevel, btn, painter, widget); | 
|---|
| 1318 | QStyleOptionButton subopt = *btn; | 
|---|
| 1319 | subopt.rect = subElementRect(SE_PushButtonContents, btn, widget); | 
|---|
| 1320 |  | 
|---|
| 1321 | drawControl(CE_PushButtonLabel, &subopt, painter, widget); | 
|---|
| 1322 | } | 
|---|
| 1323 | break; | 
|---|
| 1324 | case CE_PushButtonBevel: | 
|---|
| 1325 | if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) { | 
|---|
| 1326 | const bool isDisabled = !(option->state & State_Enabled); | 
|---|
| 1327 | const bool isFlat = button->features & QStyleOptionButton::Flat; | 
|---|
| 1328 | QS60StyleEnums::SkinParts skinPart; | 
|---|
| 1329 | QS60StylePrivate::SkinElements skinElement; | 
|---|
| 1330 | if (!isDisabled) { | 
|---|
| 1331 | const bool isPressed = (option->state & State_Sunken) || | 
|---|
| 1332 | (option->state & State_On); | 
|---|
| 1333 | if (isFlat) { | 
|---|
| 1334 | skinPart = | 
|---|
| 1335 | isPressed ? QS60StyleEnums::SP_QsnFrButtonTbCenterPressed : QS60StyleEnums::SP_QsnFrButtonTbCenter; | 
|---|
| 1336 | } else { | 
|---|
| 1337 | skinElement = | 
|---|
| 1338 | isPressed ? QS60StylePrivate::SE_ButtonPressed : QS60StylePrivate::SE_ButtonNormal; | 
|---|
| 1339 | } | 
|---|
| 1340 | } else { | 
|---|
| 1341 | if (isFlat) | 
|---|
| 1342 | skinPart =QS60StyleEnums::SP_QsnFrButtonCenterInactive; | 
|---|
| 1343 | else | 
|---|
| 1344 | skinElement = QS60StylePrivate::SE_ButtonInactive; | 
|---|
| 1345 | } | 
|---|
| 1346 | if (isFlat) | 
|---|
| 1347 | QS60StylePrivate::drawSkinPart(skinPart, painter, option->rect, flags); | 
|---|
| 1348 | else | 
|---|
| 1349 | QS60StylePrivate::drawSkinElement(skinElement, painter, option->rect, flags); | 
|---|
| 1350 | } | 
|---|
| 1351 | break; | 
|---|
| 1352 | #ifndef QT_NO_TOOLBUTTON | 
|---|
| 1353 | case CE_ToolButtonLabel: | 
|---|
| 1354 | if (const QStyleOptionToolButton *toolBtn = qstyleoption_cast<const QStyleOptionToolButton *>(option)) { | 
|---|
| 1355 | QStyleOptionToolButton optionToolButton = *toolBtn; | 
|---|
| 1356 |  | 
|---|
| 1357 | if (!optionToolButton.icon.isNull() && (optionToolButton.state & State_Sunken) | 
|---|
| 1358 | && (optionToolButton.state & State_Enabled)) { | 
|---|
| 1359 |  | 
|---|
| 1360 | const QIcon::State state = optionToolButton.state & State_On ? QIcon::On : QIcon::Off; | 
|---|
| 1361 | const QPixmap pm(optionToolButton.icon.pixmap(optionToolButton.rect.size().boundedTo(optionToolButton.iconSize), | 
|---|
| 1362 | QIcon::Normal, state)); | 
|---|
| 1363 | optionToolButton.icon = generatedIconPixmap(QIcon::Selected, pm, &optionToolButton); | 
|---|
| 1364 | } | 
|---|
| 1365 |  | 
|---|
| 1366 | QCommonStyle::drawControl(element, &optionToolButton, painter, widget); | 
|---|
| 1367 | } | 
|---|
| 1368 | break; | 
|---|
| 1369 | #endif //QT_NO_TOOLBUTTON | 
|---|
| 1370 | #ifndef QT_NO_COMBOBOX | 
|---|
| 1371 | case CE_ComboBoxLabel: | 
|---|
| 1372 | if (const QStyleOptionComboBox *comboBox = qstyleoption_cast<const QStyleOptionComboBox *>(option)) { | 
|---|
| 1373 | QStyleOption optionComboBox = *comboBox; | 
|---|
| 1374 | optionComboBox.palette.setColor(QPalette::Active, QPalette::WindowText, | 
|---|
| 1375 | optionComboBox.palette.text().color() ); | 
|---|
| 1376 | optionComboBox.palette.setColor(QPalette::Inactive, QPalette::WindowText, | 
|---|
| 1377 | optionComboBox.palette.text().color() ); | 
|---|
| 1378 | QRect editRect = subControlRect(CC_ComboBox, comboBox, SC_ComboBoxEditField, widget); | 
|---|
| 1379 | const int frameW = proxy()->pixelMetric(PM_DefaultFrameWidth, option, widget); | 
|---|
| 1380 |  | 
|---|
| 1381 | if (!comboBox->currentIcon.isNull()) { | 
|---|
| 1382 | const QIcon::Mode mode = comboBox->state & State_Enabled ? QIcon::Normal : QIcon::Disabled; | 
|---|
| 1383 | const QPixmap pixmap = comboBox->currentIcon.pixmap(comboBox->iconSize, mode); | 
|---|
| 1384 | QRect iconRect(editRect); | 
|---|
| 1385 | iconRect.setWidth(comboBox->iconSize.width() + frameW); | 
|---|
| 1386 | iconRect = alignedRect(comboBox->direction, | 
|---|
| 1387 | Qt::AlignLeft | Qt::AlignVCenter, | 
|---|
| 1388 | iconRect.size(), editRect); | 
|---|
| 1389 | if (comboBox->editable) | 
|---|
| 1390 | painter->fillRect(iconRect, optionComboBox.palette.brush(QPalette::Base)); | 
|---|
| 1391 | drawItemPixmap(painter, iconRect, Qt::AlignCenter, pixmap); | 
|---|
| 1392 |  | 
|---|
| 1393 | if (comboBox->direction == Qt::RightToLeft) | 
|---|
| 1394 | editRect.setRight(editRect.right() - frameW - comboBox->iconSize.width()); | 
|---|
| 1395 | else | 
|---|
| 1396 | editRect.setLeft(comboBox->iconSize.width() + frameW); | 
|---|
| 1397 | } | 
|---|
| 1398 | if (!comboBox->currentText.isEmpty() && !comboBox->editable) { | 
|---|
| 1399 | const Qt::TextElideMode elideMode = (comboBox->direction == Qt::LeftToRight) ? Qt::ElideRight : Qt::ElideLeft; | 
|---|
| 1400 | const QString text = comboBox->fontMetrics.elidedText(comboBox->currentText, elideMode, editRect.width()); | 
|---|
| 1401 |  | 
|---|
| 1402 | QCommonStyle::drawItemText(painter, | 
|---|
| 1403 | editRect.adjusted(QS60StylePrivate::pixelMetric(PM_FrameCornerWidth), 0, -1, 0), | 
|---|
| 1404 | visualAlignment(comboBox->direction, Qt::AlignLeft | Qt::AlignVCenter), | 
|---|
| 1405 | comboBox->palette, comboBox->state & State_Enabled, text); | 
|---|
| 1406 | } | 
|---|
| 1407 | } | 
|---|
| 1408 | break; | 
|---|
| 1409 | #endif //QT_NO_COMBOBOX | 
|---|
| 1410 | #ifndef QT_NO_ITEMVIEWS | 
|---|
| 1411 | case CE_ItemViewItem: | 
|---|
| 1412 | if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(option)) { | 
|---|
| 1413 | QStyleOptionViewItemV4 voptAdj = *vopt; | 
|---|
| 1414 | painter->save(); | 
|---|
| 1415 |  | 
|---|
| 1416 | painter->setClipRect(voptAdj.rect); | 
|---|
| 1417 | const bool isSelected = (vopt->state & State_Selected); | 
|---|
| 1418 | const bool hasFocus = (vopt->state & State_HasFocus); | 
|---|
| 1419 |  | 
|---|
| 1420 | bool isScrollBarVisible = false; | 
|---|
| 1421 | int scrollBarWidth = 0; | 
|---|
| 1422 | QList<QScrollBar *> scrollBars = qFindChildren<QScrollBar *>(widget); | 
|---|
| 1423 | for (int i = 0; i < scrollBars.size(); ++i) { | 
|---|
| 1424 | QScrollBar *scrollBar = scrollBars.at(i); | 
|---|
| 1425 | if (scrollBar && scrollBar->orientation() == Qt::Vertical) { | 
|---|
| 1426 | isScrollBarVisible = scrollBar->isVisible(); | 
|---|
| 1427 | scrollBarWidth = scrollBar->size().width(); | 
|---|
| 1428 | break; | 
|---|
| 1429 | } | 
|---|
| 1430 | } | 
|---|
| 1431 |  | 
|---|
| 1432 | int rightValue = widget ? widget->contentsRect().right() : voptAdj.rect.right(); | 
|---|
| 1433 |  | 
|---|
| 1434 | if (isScrollBarVisible) | 
|---|
| 1435 | rightValue -= scrollBarWidth; | 
|---|
| 1436 |  | 
|---|
| 1437 | if (voptAdj.rect.right() > rightValue) | 
|---|
| 1438 | voptAdj.rect.setRight(rightValue); | 
|---|
| 1439 |  | 
|---|
| 1440 | const QRect iconRect = subElementRect(SE_ItemViewItemDecoration, &voptAdj, widget); | 
|---|
| 1441 | QRect textRect = subElementRect(SE_ItemViewItemText, &voptAdj, widget); | 
|---|
| 1442 | const QAbstractItemView *itemView = qobject_cast<const QAbstractItemView *>(widget); | 
|---|
| 1443 |  | 
|---|
| 1444 | const bool singleSelection = itemView && | 
|---|
| 1445 | ((itemView->selectionMode() == QAbstractItemView::SingleSelection || | 
|---|
| 1446 | itemView->selectionMode() == QAbstractItemView::NoSelection)); | 
|---|
| 1447 | const bool selectItems = itemView && (itemView->selectionBehavior() == QAbstractItemView::SelectItems); | 
|---|
| 1448 |  | 
|---|
| 1449 | // draw themed background for itemview unless background brush has been defined. | 
|---|
| 1450 | if (vopt->backgroundBrush == Qt::NoBrush) { | 
|---|
| 1451 | if (itemView) { | 
|---|
| 1452 | //With single item selection, use highlight focus as selection indicator. | 
|---|
| 1453 | if (singleSelection && isSelected){ | 
|---|
| 1454 | voptAdj.state = voptAdj.state | State_HasFocus; | 
|---|
| 1455 | if (!hasFocus && selectItems) { | 
|---|
| 1456 | painter->save(); | 
|---|
| 1457 | painter->setOpacity(0.5); | 
|---|
| 1458 | } | 
|---|
| 1459 | } | 
|---|
| 1460 | drawPrimitive(PE_PanelItemViewItem, &voptAdj, painter, widget); | 
|---|
| 1461 | if (singleSelection && isSelected && !hasFocus && selectItems) | 
|---|
| 1462 | painter->restore(); | 
|---|
| 1463 | } | 
|---|
| 1464 | } else { QCommonStyle::drawPrimitive(PE_PanelItemViewItem, &voptAdj, painter, widget);} | 
|---|
| 1465 |  | 
|---|
| 1466 | // draw the icon | 
|---|
| 1467 | const QIcon::Mode mode = (voptAdj.state & State_Enabled) ? QIcon::Normal : QIcon::Disabled; | 
|---|
| 1468 | const QIcon::State state = (voptAdj.state & State_Open) ? QIcon::On : QIcon::Off; | 
|---|
| 1469 | voptAdj.icon.paint(painter, iconRect, voptAdj.decorationAlignment, mode, state); | 
|---|
| 1470 |  | 
|---|
| 1471 | // Draw selection check mark or checkbox | 
|---|
| 1472 | if (itemView && (!singleSelection || (vopt->features & QStyleOptionViewItemV2::HasCheckIndicator))) { | 
|---|
| 1473 | const QRect selectionRect = subElementRect(SE_ItemViewItemCheckIndicator, &voptAdj, widget); | 
|---|
| 1474 |  | 
|---|
| 1475 | QStyleOptionViewItemV4 checkMarkOption(voptAdj); | 
|---|
| 1476 | if (selectionRect.isValid()) | 
|---|
| 1477 | checkMarkOption.rect = selectionRect; | 
|---|
| 1478 | // Draw selection mark. | 
|---|
| 1479 | if (isSelected && selectItems) { | 
|---|
| 1480 | proxy()->drawPrimitive(PE_IndicatorViewItemCheck, &checkMarkOption, painter, widget); | 
|---|
| 1481 | // @todo: this should happen in the rect retrievel i.e. subElementRect() | 
|---|
| 1482 | if (textRect.right() > selectionRect.left()) | 
|---|
| 1483 | textRect.setRight(selectionRect.left()); | 
|---|
| 1484 | } else if (voptAdj.features & QStyleOptionViewItemV2::HasCheckIndicator) { | 
|---|
| 1485 | checkMarkOption.state = checkMarkOption.state & ~State_HasFocus; | 
|---|
| 1486 |  | 
|---|
| 1487 | switch (vopt->checkState) { | 
|---|
| 1488 | case Qt::Unchecked: | 
|---|
| 1489 | checkMarkOption.state |= State_Off; | 
|---|
| 1490 | break; | 
|---|
| 1491 | case Qt::PartiallyChecked: | 
|---|
| 1492 | checkMarkOption.state |= State_NoChange; | 
|---|
| 1493 | break; | 
|---|
| 1494 | case Qt::Checked: | 
|---|
| 1495 | checkMarkOption.state |= State_On; | 
|---|
| 1496 | break; | 
|---|
| 1497 | } | 
|---|
| 1498 | drawPrimitive(PE_IndicatorViewItemCheck, &checkMarkOption, painter, widget); | 
|---|
| 1499 | } | 
|---|
| 1500 | } | 
|---|
| 1501 |  | 
|---|
| 1502 | // draw the text | 
|---|
| 1503 | if (!voptAdj.text.isEmpty()) { | 
|---|
| 1504 | if (hasFocus) | 
|---|
| 1505 | painter->setPen(voptAdj.palette.highlightedText().color()); | 
|---|
| 1506 | else | 
|---|
| 1507 | painter->setPen(voptAdj.palette.text().color()); | 
|---|
| 1508 | d->viewItemDrawText(painter, &voptAdj, textRect); | 
|---|
| 1509 | } | 
|---|
| 1510 | painter->restore(); | 
|---|
| 1511 | } | 
|---|
| 1512 | break; | 
|---|
| 1513 | #endif // QT_NO_ITEMVIEWS | 
|---|
| 1514 | #ifndef QT_NO_TABBAR | 
|---|
| 1515 | case CE_TabBarTabShape: | 
|---|
| 1516 | if (const QStyleOptionTabV3 *optionTab = qstyleoption_cast<const QStyleOptionTabV3 *>(option)) { | 
|---|
| 1517 | QStyleOptionTabV3 optionTabAdj = *optionTab; | 
|---|
| 1518 | const bool isSelected = optionTab->state & State_Selected; | 
|---|
| 1519 | const bool directionMirrored = (optionTab->direction == Qt::RightToLeft); | 
|---|
| 1520 | QS60StylePrivate::SkinElements skinElement; | 
|---|
| 1521 | switch (optionTab->shape) { | 
|---|
| 1522 | case QTabBar::TriangularEast: | 
|---|
| 1523 | case QTabBar::RoundedEast: | 
|---|
| 1524 | skinElement = isSelected ? QS60StylePrivate::SE_TabBarTabEastActive: | 
|---|
| 1525 | QS60StylePrivate::SE_TabBarTabEastInactive; | 
|---|
| 1526 | break; | 
|---|
| 1527 | case QTabBar::TriangularSouth: | 
|---|
| 1528 | case QTabBar::RoundedSouth: | 
|---|
| 1529 | skinElement = isSelected ? QS60StylePrivate::SE_TabBarTabSouthActive: | 
|---|
| 1530 | QS60StylePrivate::SE_TabBarTabSouthInactive; | 
|---|
| 1531 | break; | 
|---|
| 1532 | case QTabBar::TriangularWest: | 
|---|
| 1533 | case QTabBar::RoundedWest: | 
|---|
| 1534 | skinElement = isSelected ? QS60StylePrivate::SE_TabBarTabWestActive: | 
|---|
| 1535 | QS60StylePrivate::SE_TabBarTabWestInactive; | 
|---|
| 1536 | break; | 
|---|
| 1537 | case QTabBar::TriangularNorth: | 
|---|
| 1538 | case QTabBar::RoundedNorth: | 
|---|
| 1539 | default: | 
|---|
| 1540 | skinElement = isSelected ? QS60StylePrivate::SE_TabBarTabNorthActive: | 
|---|
| 1541 | QS60StylePrivate::SE_TabBarTabNorthInactive; | 
|---|
| 1542 | break; | 
|---|
| 1543 | } | 
|---|
| 1544 | if (skinElement == QS60StylePrivate::SE_TabBarTabEastInactive || | 
|---|
| 1545 | skinElement == QS60StylePrivate::SE_TabBarTabNorthInactive || | 
|---|
| 1546 | skinElement == QS60StylePrivate::SE_TabBarTabSouthInactive || | 
|---|
| 1547 | skinElement == QS60StylePrivate::SE_TabBarTabWestInactive || | 
|---|
| 1548 | skinElement == QS60StylePrivate::SE_TabBarTabEastActive || | 
|---|
| 1549 | skinElement == QS60StylePrivate::SE_TabBarTabNorthActive || | 
|---|
| 1550 | skinElement == QS60StylePrivate::SE_TabBarTabSouthActive || | 
|---|
| 1551 | skinElement==QS60StylePrivate::SE_TabBarTabWestActive) { | 
|---|
| 1552 | const int borderThickness = | 
|---|
| 1553 | QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth); | 
|---|
| 1554 | const int tabOverlap = | 
|---|
| 1555 | QS60StylePrivate::pixelMetric(PM_TabBarTabOverlap) - borderThickness; | 
|---|
| 1556 | const bool usesScrollButtons = | 
|---|
| 1557 | (widget) ? (qobject_cast<const QTabBar*>(widget))->usesScrollButtons() : false; | 
|---|
| 1558 | const int roomForScrollButton = | 
|---|
| 1559 | usesScrollButtons ? QS60StylePrivate::pixelMetric(PM_TabBarScrollButtonWidth) : 0; | 
|---|
| 1560 |  | 
|---|
| 1561 | // adjust for overlapping tabs and scrollbuttons, if necessary | 
|---|
| 1562 | if (skinElement == QS60StylePrivate::SE_TabBarTabEastInactive || | 
|---|
| 1563 | skinElement == QS60StylePrivate::SE_TabBarTabEastActive || | 
|---|
| 1564 | skinElement == QS60StylePrivate::SE_TabBarTabWestInactive || | 
|---|
| 1565 | skinElement == QS60StylePrivate::SE_TabBarTabWestActive){ | 
|---|
| 1566 | if (optionTabAdj.position == QStyleOptionTabV3::Beginning) | 
|---|
| 1567 | optionTabAdj.rect.adjust(0, roomForScrollButton, 0, tabOverlap); | 
|---|
| 1568 | else if (optionTabAdj.position == QStyleOptionTabV3::End) | 
|---|
| 1569 | optionTabAdj.rect.adjust(0, 0, 0, tabOverlap); | 
|---|
| 1570 | else | 
|---|
| 1571 | optionTabAdj.rect.adjust(0, 0, 0, tabOverlap); | 
|---|
| 1572 | } else { | 
|---|
| 1573 | if (directionMirrored) { | 
|---|
| 1574 | if (optionTabAdj.position == QStyleOptionTabV3::Beginning) | 
|---|
| 1575 | optionTabAdj.rect.adjust(-tabOverlap, 0, -roomForScrollButton, 0); | 
|---|
| 1576 | else | 
|---|
| 1577 | optionTabAdj.rect.adjust(-tabOverlap, 0, 0, 0); | 
|---|
| 1578 | } else { | 
|---|
| 1579 | if (optionTabAdj.position == QStyleOptionTabV3::Beginning) | 
|---|
| 1580 | optionTabAdj.rect.adjust(roomForScrollButton, 0, tabOverlap, 0); | 
|---|
| 1581 | else | 
|---|
| 1582 | optionTabAdj.rect.adjust(0, 0, tabOverlap, 0); | 
|---|
| 1583 | } | 
|---|
| 1584 | } | 
|---|
| 1585 | } | 
|---|
| 1586 | QS60StylePrivate::drawSkinElement(skinElement, painter, optionTabAdj.rect, flags); | 
|---|
| 1587 | } | 
|---|
| 1588 | break; | 
|---|
| 1589 | case CE_TabBarTabLabel: | 
|---|
| 1590 | if (const QStyleOptionTabV3 *tab = qstyleoption_cast<const QStyleOptionTabV3 *>(option)) { | 
|---|
| 1591 | QStyleOptionTabV3 optionTab = *tab; | 
|---|
| 1592 | QRect tr = optionTab.rect; | 
|---|
| 1593 | const bool directionMirrored = (optionTab.direction == Qt::RightToLeft); | 
|---|
| 1594 | const int borderThickness = QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth); | 
|---|
| 1595 | const int tabOverlap = | 
|---|
| 1596 | QS60StylePrivate::pixelMetric(PM_TabBarTabOverlap) - borderThickness; | 
|---|
| 1597 | const bool usesScrollButtons = | 
|---|
| 1598 | (widget) ? (qobject_cast<const QTabBar*>(widget))->usesScrollButtons() : false; | 
|---|
| 1599 | const int roomForScrollButton = | 
|---|
| 1600 | usesScrollButtons ? QS60StylePrivate::pixelMetric(PM_TabBarScrollButtonWidth) : 0; | 
|---|
| 1601 |  | 
|---|
| 1602 | switch (tab->shape) { | 
|---|
| 1603 | case QTabBar::TriangularWest: | 
|---|
| 1604 | case QTabBar::RoundedWest: | 
|---|
| 1605 | case QTabBar::TriangularEast: | 
|---|
| 1606 | case QTabBar::RoundedEast: | 
|---|
| 1607 | tr.adjust(0, 0, 0, tabOverlap); | 
|---|
| 1608 | break; | 
|---|
| 1609 | case QTabBar::TriangularSouth: | 
|---|
| 1610 | case QTabBar::RoundedSouth: | 
|---|
| 1611 | case QTabBar::TriangularNorth: | 
|---|
| 1612 | case QTabBar::RoundedNorth: | 
|---|
| 1613 | default: | 
|---|
| 1614 | if (directionMirrored) | 
|---|
| 1615 | tr.adjust(-tabOverlap, 0, 0, 0); | 
|---|
| 1616 | else | 
|---|
| 1617 | tr.adjust(0, 0, tabOverlap, 0); | 
|---|
| 1618 | break; | 
|---|
| 1619 | } | 
|---|
| 1620 | painter->save(); | 
|---|
| 1621 | QFont f = painter->font(); | 
|---|
| 1622 | f.setPointSizeF(f.pointSizeF() * KTabFontMul); | 
|---|
| 1623 | painter->setFont(f); | 
|---|
| 1624 |  | 
|---|
| 1625 | const bool selected = optionTab.state & State_Selected; | 
|---|
| 1626 | if (selected) | 
|---|
| 1627 | optionTab.palette.setColor(QPalette::Active, QPalette::WindowText, | 
|---|
| 1628 | optionTab.palette.highlightedText().color()); | 
|---|
| 1629 |  | 
|---|
| 1630 | const bool verticalTabs = optionTab.shape == QTabBar::RoundedEast | 
|---|
| 1631 | || optionTab.shape == QTabBar::RoundedWest | 
|---|
| 1632 | || optionTab.shape == QTabBar::TriangularEast | 
|---|
| 1633 | || optionTab.shape == QTabBar::TriangularWest; | 
|---|
| 1634 |  | 
|---|
| 1635 | //make room for scrollbuttons | 
|---|
| 1636 | if (!verticalTabs) { | 
|---|
| 1637 | if ((tab->position == QStyleOptionTabV3::Beginning && !directionMirrored)) | 
|---|
| 1638 | tr.adjust(roomForScrollButton, 0, 0, 0); | 
|---|
| 1639 | else if ((tab->position == QStyleOptionTabV3::Beginning && directionMirrored)) | 
|---|
| 1640 | tr.adjust(0, 0, -roomForScrollButton, 0); | 
|---|
| 1641 | } else { | 
|---|
| 1642 | if (tab->position == QStyleOptionTabV3::Beginning) | 
|---|
| 1643 | tr.adjust(0, roomForScrollButton, 0, 0); | 
|---|
| 1644 | } | 
|---|
| 1645 |  | 
|---|
| 1646 | if (verticalTabs) { | 
|---|
| 1647 | painter->save(); | 
|---|
| 1648 | int newX, newY, newRotation; | 
|---|
| 1649 | if (optionTab.shape == QTabBar::RoundedEast || optionTab.shape == QTabBar::TriangularEast) { | 
|---|
| 1650 | newX = tr.width(); | 
|---|
| 1651 | newY = tr.y(); | 
|---|
| 1652 | newRotation = 90; | 
|---|
| 1653 | } else { | 
|---|
| 1654 | newX = 0; | 
|---|
| 1655 | newY = tr.y() + tr.height(); | 
|---|
| 1656 | newRotation = -90; | 
|---|
| 1657 | } | 
|---|
| 1658 | tr.setRect(0, 0, tr.height(), tr.width()); | 
|---|
| 1659 | QTransform m; | 
|---|
| 1660 | m.translate(newX, newY); | 
|---|
| 1661 | m.rotate(newRotation); | 
|---|
| 1662 | painter->setTransform(m, true); | 
|---|
| 1663 | } | 
|---|
| 1664 | tr.adjust(0, 0, pixelMetric(PM_TabBarTabShiftHorizontal, tab, widget), | 
|---|
| 1665 | pixelMetric(PM_TabBarTabShiftVertical, tab, widget)); | 
|---|
| 1666 |  | 
|---|
| 1667 | if (selected) { | 
|---|
| 1668 | tr.setBottom(tr.bottom() - pixelMetric(PM_TabBarTabShiftVertical, tab, widget)); | 
|---|
| 1669 | tr.setRight(tr.right() - pixelMetric(PM_TabBarTabShiftHorizontal, tab, widget)); | 
|---|
| 1670 | } | 
|---|
| 1671 |  | 
|---|
| 1672 | int alignment = Qt::AlignCenter | Qt::TextShowMnemonic; | 
|---|
| 1673 | if (!styleHint(SH_UnderlineShortcut, &optionTab, widget)) | 
|---|
| 1674 | alignment |= Qt::TextHideMnemonic; | 
|---|
| 1675 | if (!optionTab.icon.isNull()) { | 
|---|
| 1676 | QSize iconSize = optionTab.iconSize; | 
|---|
| 1677 | if (!iconSize.isValid()) { | 
|---|
| 1678 | const int iconExtent = pixelMetric(PM_TabBarIconSize); | 
|---|
| 1679 | iconSize = QSize(iconExtent, iconExtent); | 
|---|
| 1680 | } | 
|---|
| 1681 | QPixmap tabIcon = optionTab.icon.pixmap(iconSize, | 
|---|
| 1682 | (optionTab.state & State_Enabled) ? QIcon::Normal : QIcon::Disabled); | 
|---|
| 1683 | if (tab->text.isEmpty()) | 
|---|
| 1684 | painter->drawPixmap(tr.center().x() - (tabIcon.height() >> 1), | 
|---|
| 1685 | tr.center().y() - (tabIcon.height() >> 1), | 
|---|
| 1686 | tabIcon); | 
|---|
| 1687 | else | 
|---|
| 1688 | painter->drawPixmap(tr.left() + tabOverlap, | 
|---|
| 1689 | tr.center().y() - (tabIcon.height() >> 1), | 
|---|
| 1690 | tabIcon); | 
|---|
| 1691 | tr.setLeft(tr.left() + iconSize.width() + 4); //todo: magic four | 
|---|
| 1692 | } | 
|---|
| 1693 |  | 
|---|
| 1694 | QCommonStyle::drawItemText(painter, tr, alignment, optionTab.palette, tab->state & State_Enabled, tab->text, QPalette::WindowText); | 
|---|
| 1695 | if (verticalTabs) | 
|---|
| 1696 | painter->restore(); | 
|---|
| 1697 |  | 
|---|
| 1698 | painter->restore(); | 
|---|
| 1699 | } | 
|---|
| 1700 | break; | 
|---|
| 1701 | #endif // QT_NO_TABBAR | 
|---|
| 1702 | #ifndef QT_NO_PROGRESSBAR | 
|---|
| 1703 | case CE_ProgressBarContents: | 
|---|
| 1704 | if (const QStyleOptionProgressBarV2 *optionProgressBar = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(option)) { | 
|---|
| 1705 | QRect progressRect = optionProgressBar->rect; | 
|---|
| 1706 |  | 
|---|
| 1707 | if (optionProgressBar->minimum == optionProgressBar->maximum && optionProgressBar->minimum == 0) { | 
|---|
| 1708 | // busy indicator | 
|---|
| 1709 | const QS60StylePrivate::SkinElementFlag orientationFlag = optionProgressBar->orientation == Qt::Horizontal ? | 
|---|
| 1710 | QS60StylePrivate::SF_PointNorth : QS60StylePrivate::SF_PointWest; | 
|---|
| 1711 |  | 
|---|
| 1712 | QS60StylePrivate::drawSkinPart(QS60StyleEnums::SP_QgnGrafBarWaitAnim, | 
|---|
| 1713 | painter, progressRect, flags | orientationFlag | QS60StylePrivate::SF_Animation ); | 
|---|
| 1714 | } else { | 
|---|
| 1715 | const qreal progressFactor = (optionProgressBar->minimum == optionProgressBar->maximum) ? 1.0 | 
|---|
| 1716 | : (qreal)optionProgressBar->progress / optionProgressBar->maximum; | 
|---|
| 1717 | const int frameWidth = pixelMetric(PM_DefaultFrameWidth, option, widget); | 
|---|
| 1718 | if (optionProgressBar->orientation == Qt::Horizontal) { | 
|---|
| 1719 | progressRect.setWidth(int(progressRect.width() * progressFactor)); | 
|---|
| 1720 | if(optionProgressBar->direction == Qt::RightToLeft) | 
|---|
| 1721 | progressRect.translate(optionProgressBar->rect.width() - progressRect.width(), 0); | 
|---|
| 1722 | progressRect.adjust(frameWidth, 0, -frameWidth, 0); | 
|---|
| 1723 | } else { | 
|---|
| 1724 | progressRect.adjust(0, frameWidth, 0, -frameWidth); | 
|---|
| 1725 | progressRect.setTop(progressRect.bottom() - int(progressRect.height() * progressFactor)); | 
|---|
| 1726 | } | 
|---|
| 1727 |  | 
|---|
| 1728 | const QS60StylePrivate::SkinElements skinElement = optionProgressBar->orientation == Qt::Horizontal ? | 
|---|
| 1729 | QS60StylePrivate::SE_ProgressBarIndicatorHorizontal : QS60StylePrivate::SE_ProgressBarIndicatorVertical; | 
|---|
| 1730 | QS60StylePrivate::drawSkinElement(skinElement, painter, progressRect, flags); | 
|---|
| 1731 | } | 
|---|
| 1732 | } | 
|---|
| 1733 | break; | 
|---|
| 1734 | case CE_ProgressBarGroove: | 
|---|
| 1735 | if (const QStyleOptionProgressBarV2 *optionProgressBar = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(option)) { | 
|---|
| 1736 | const QS60StylePrivate::SkinElements skinElement = optionProgressBar->orientation == Qt::Horizontal ? | 
|---|
| 1737 | QS60StylePrivate::SE_ProgressBarGrooveHorizontal : QS60StylePrivate::SE_ProgressBarGrooveVertical; | 
|---|
| 1738 | QS60StylePrivate::drawSkinElement(skinElement, painter, option->rect, flags); | 
|---|
| 1739 | } | 
|---|
| 1740 | break; | 
|---|
| 1741 | case CE_ProgressBarLabel: | 
|---|
| 1742 | if (const QStyleOptionProgressBarV2 *progressbar = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(option)) { | 
|---|
| 1743 | QStyleOptionProgressBarV2 optionProgressBar = *progressbar; | 
|---|
| 1744 | QCommonStyle::drawItemText(painter, progressbar->rect, flags | Qt::AlignCenter | Qt::TextSingleLine, optionProgressBar.palette, | 
|---|
| 1745 | progressbar->state & State_Enabled, progressbar->text, QPalette::WindowText); | 
|---|
| 1746 | } | 
|---|
| 1747 | break; | 
|---|
| 1748 | #endif // QT_NO_PROGRESSBAR | 
|---|
| 1749 | #ifndef QT_NO_MENU | 
|---|
| 1750 | case CE_MenuItem: | 
|---|
| 1751 | if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) { | 
|---|
| 1752 | QStyleOptionMenuItem optionMenuItem = *menuItem; | 
|---|
| 1753 |  | 
|---|
| 1754 | bool drawSubMenuIndicator = false; | 
|---|
| 1755 | switch(menuItem->menuItemType) { | 
|---|
| 1756 | case QStyleOptionMenuItem::Scroller: | 
|---|
| 1757 | case QStyleOptionMenuItem::Separator: | 
|---|
| 1758 | return; // no separators or scrollers in S60 menus | 
|---|
| 1759 | case QStyleOptionMenuItem::SubMenu: | 
|---|
| 1760 | drawSubMenuIndicator = true; | 
|---|
| 1761 | break; | 
|---|
| 1762 | default: | 
|---|
| 1763 | break; | 
|---|
| 1764 | } | 
|---|
| 1765 | const bool enabled = optionMenuItem.state & State_Enabled; | 
|---|
| 1766 | const bool checkable = optionMenuItem.checkType != QStyleOptionMenuItem::NotCheckable; | 
|---|
| 1767 | bool ignoreCheckMark = false; | 
|---|
| 1768 |  | 
|---|
| 1769 | #ifndef QT_NO_COMBOBOX | 
|---|
| 1770 | if (qobject_cast<const QComboBox*>(widget)) | 
|---|
| 1771 | ignoreCheckMark = true; //ignore the checkmarks provided by the QComboMenuDelegate | 
|---|
| 1772 | #endif | 
|---|
| 1773 |  | 
|---|
| 1774 | uint text_flags = Qt::AlignLeading | Qt::TextShowMnemonic | Qt::TextDontClip | 
|---|
| 1775 | | Qt::TextSingleLine | Qt::AlignVCenter; | 
|---|
| 1776 | if (!styleHint(SH_UnderlineShortcut, menuItem, widget)) | 
|---|
| 1777 | text_flags |= Qt::TextHideMnemonic; | 
|---|
| 1778 |  | 
|---|
| 1779 | QRect iconRect = subElementRect(SE_ItemViewItemDecoration, &optionMenuItem, widget); | 
|---|
| 1780 | QRect textRect = subElementRect(SE_ItemViewItemText, &optionMenuItem, widget); | 
|---|
| 1781 |  | 
|---|
| 1782 | QStyleOptionMenuItem optionCheckBox; | 
|---|
| 1783 |  | 
|---|
| 1784 | //Regardless of checkbox visibility, make room for it, this mirrors native implementation, | 
|---|
| 1785 | //where text and icon placement is static regardless of content of menu item. | 
|---|
| 1786 | optionCheckBox.QStyleOptionMenuItem::operator=(*menuItem); | 
|---|
| 1787 | optionCheckBox.rect.setWidth(pixelMetric(PM_IndicatorWidth)); | 
|---|
| 1788 | optionCheckBox.rect.setHeight(pixelMetric(PM_IndicatorHeight)); | 
|---|
| 1789 |  | 
|---|
| 1790 | const int vSpacing = QS60StylePrivate::pixelMetric(PM_LayoutVerticalSpacing); | 
|---|
| 1791 | //The vertical spacing is doubled; it needs one spacing to separate checkbox from | 
|---|
| 1792 | //highlight and then it needs one to separate it whatever is shown after it (text/icon/both). | 
|---|
| 1793 | const int moveByX = optionCheckBox.rect.width() + 2 * vSpacing; | 
|---|
| 1794 | optionCheckBox.rect.moveCenter(QPoint( | 
|---|
| 1795 | optionCheckBox.rect.center().x() + moveByX >> 1, | 
|---|
| 1796 | menuItem->rect.center().y())); | 
|---|
| 1797 |  | 
|---|
| 1798 | if (optionMenuItem.direction != Qt::LeftToRight) | 
|---|
| 1799 | optionCheckBox.rect.translate(textRect.width() + iconRect.width(), 0); | 
|---|
| 1800 |  | 
|---|
| 1801 |  | 
|---|
| 1802 | const bool selected = (option->state & State_Selected) && (option->state & State_Enabled); | 
|---|
| 1803 | if (selected) { | 
|---|
| 1804 | const int spacing = ignoreCheckMark ? (vSpacing + QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth)) : 0; | 
|---|
| 1805 | const int start = optionMenuItem.rect.left() + spacing; | 
|---|
| 1806 | const int end = optionMenuItem.rect.right() - spacing; | 
|---|
| 1807 | //-1 adjustment to avoid highlight being on top of possible separator item | 
|---|
| 1808 | const QRect highlightRect = QRect( | 
|---|
| 1809 | QPoint(start, option->rect.top()), | 
|---|
| 1810 | QPoint(end, option->rect.bottom() - 1)); | 
|---|
| 1811 | QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ListHighlight, painter, highlightRect, flags); | 
|---|
| 1812 | } | 
|---|
| 1813 |  | 
|---|
| 1814 | if (checkable && !ignoreCheckMark) | 
|---|
| 1815 | drawPrimitive(PE_IndicatorMenuCheckMark, &optionCheckBox, painter, widget); | 
|---|
| 1816 |  | 
|---|
| 1817 | //draw icon and/or checkState | 
|---|
| 1818 | QPixmap pix = menuItem->icon.pixmap(pixelMetric(PM_SmallIconSize), | 
|---|
| 1819 | enabled ? QIcon::Normal : QIcon::Disabled); | 
|---|
| 1820 | const bool itemWithIcon = !pix.isNull(); | 
|---|
| 1821 | if (itemWithIcon) { | 
|---|
| 1822 | drawItemPixmap(painter, iconRect, text_flags, pix); | 
|---|
| 1823 | if (optionMenuItem.direction == Qt::LeftToRight) | 
|---|
| 1824 | textRect.translate(vSpacing, 0); | 
|---|
| 1825 | else | 
|---|
| 1826 | textRect.translate(-vSpacing, 0); | 
|---|
| 1827 | textRect.setWidth(textRect.width() - vSpacing); | 
|---|
| 1828 | } | 
|---|
| 1829 |  | 
|---|
| 1830 | //draw indicators | 
|---|
| 1831 | if (drawSubMenuIndicator) { | 
|---|
| 1832 | QStyleOptionMenuItem arrowOptions; | 
|---|
| 1833 | arrowOptions.QStyleOption::operator=(*menuItem); | 
|---|
| 1834 | const int indicatorWidth = (pixelMetric(PM_ListViewIconSize, option, widget) >> 1) + | 
|---|
| 1835 | pixelMetric(PM_LayoutVerticalSpacing, option, widget); | 
|---|
| 1836 | if (optionMenuItem.direction == Qt::LeftToRight) | 
|---|
| 1837 | arrowOptions.rect.setLeft(textRect.right()); | 
|---|
| 1838 | arrowOptions.rect.setWidth(indicatorWidth); | 
|---|
| 1839 | //by default sub menu indicator in S60 points to east,so here icon | 
|---|
| 1840 | // direction is set to north (and south when in RightToLeft) | 
|---|
| 1841 | const QS60StylePrivate::SkinElementFlag arrowDirection = (arrowOptions.direction == Qt::LeftToRight) ? | 
|---|
| 1842 | QS60StylePrivate::SF_PointNorth : QS60StylePrivate::SF_PointSouth; | 
|---|
| 1843 | painter->save(); | 
|---|
| 1844 | painter->setPen(option->palette.windowText().color()); | 
|---|
| 1845 | QS60StylePrivate::drawSkinPart(QS60StyleEnums::SP_QgnIndiSubmenu, painter, arrowOptions.rect, | 
|---|
| 1846 | (flags | QS60StylePrivate::SF_ColorSkinned | arrowDirection)); | 
|---|
| 1847 | painter->restore(); | 
|---|
| 1848 | } | 
|---|
| 1849 |  | 
|---|
| 1850 | //draw text | 
|---|
| 1851 | if (!enabled){ | 
|---|
| 1852 | //In s60, if something becomes disabled, it is removed from menu, so no native look-alike available. | 
|---|
| 1853 | optionMenuItem.palette.setColor(QPalette::Disabled, QPalette::Text, QS60StylePrivate::lighterColor( | 
|---|
| 1854 | optionMenuItem.palette.color(QPalette::Disabled, QPalette::Text))); | 
|---|
| 1855 | painter->save(); | 
|---|
| 1856 | painter->setOpacity(0.5); | 
|---|
| 1857 | } | 
|---|
| 1858 | if (selected) | 
|---|
| 1859 | optionMenuItem.palette.setColor( | 
|---|
| 1860 | QPalette::Active, QPalette::Text, optionMenuItem.palette.highlightedText().color()); | 
|---|
| 1861 |  | 
|---|
| 1862 | QCommonStyle::drawItemText(painter, textRect, text_flags, | 
|---|
| 1863 | optionMenuItem.palette, enabled, | 
|---|
| 1864 | optionMenuItem.text, QPalette::Text); | 
|---|
| 1865 |  | 
|---|
| 1866 | //In Sym^3, native menu items have "lines" between them | 
|---|
| 1867 | if (QS60StylePrivate::isSingleClickUi()) { | 
|---|
| 1868 | const QColor lineColorAlpha = QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnLineColors, 15, 0); | 
|---|
| 1869 | const int spacing = QS60StylePrivate::pixelMetric(PM_FrameCornerWidth); | 
|---|
| 1870 | //native platform sets each color byte to same value for "line 16" which just defines alpha for | 
|---|
| 1871 | //menuitem lines; lets use first byte "red". | 
|---|
| 1872 | QColor lineColor = optionMenuItem.palette.text().color(); | 
|---|
| 1873 | if (lineColorAlpha.isValid()) | 
|---|
| 1874 | lineColor.setAlpha(lineColorAlpha.red()); | 
|---|
| 1875 | painter->save(); | 
|---|
| 1876 | painter->setPen(lineColor); | 
|---|
| 1877 |  | 
|---|
| 1878 | const int lineStartX = optionMenuItem.rect.left() + (QS60StylePrivate::pixelMetric(PM_FrameCornerWidth) - 2) + spacing; | 
|---|
| 1879 | const int lineEndX = optionMenuItem.rect.right() - (QS60StylePrivate::pixelMetric(PM_FrameCornerWidth) - 2) - spacing; | 
|---|
| 1880 | painter->drawLine(QPoint(lineStartX, optionMenuItem.rect.bottom()), QPoint(lineEndX, optionMenuItem.rect.bottom())); | 
|---|
| 1881 | painter->restore(); | 
|---|
| 1882 | } | 
|---|
| 1883 | if (!enabled) | 
|---|
| 1884 | painter->restore(); | 
|---|
| 1885 | } | 
|---|
| 1886 | break; | 
|---|
| 1887 | case CE_MenuEmptyArea: | 
|---|
| 1888 | break; | 
|---|
| 1889 | #endif //QT_NO_MENU | 
|---|
| 1890 |  | 
|---|
| 1891 | #ifndef QT_NO_MENUBAR | 
|---|
| 1892 | case CE_MenuBarEmptyArea: | 
|---|
| 1893 | break; | 
|---|
| 1894 | #endif //QT_NO_MENUBAR | 
|---|
| 1895 |  | 
|---|
| 1896 | case CE_HeaderSection: | 
|---|
| 1897 | if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) { | 
|---|
| 1898 | painter->save(); | 
|---|
| 1899 | QPen linePen = QPen(QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnLineColors, 1, header)); | 
|---|
| 1900 | const int penWidth = (header->orientation == Qt::Horizontal) ? | 
|---|
| 1901 | linePen.width() + QS60StylePrivate::pixelMetric(PM_BoldLineWidth) | 
|---|
| 1902 | : linePen.width() + QS60StylePrivate::pixelMetric(PM_ThinLineWidth); | 
|---|
| 1903 | linePen.setWidth(penWidth); | 
|---|
| 1904 | painter->setPen(linePen); | 
|---|
| 1905 | if (header->orientation == Qt::Horizontal){ | 
|---|
| 1906 | painter->drawLine(header->rect.bottomLeft(), header->rect.bottomRight()); | 
|---|
| 1907 | } else { | 
|---|
| 1908 | if ( header->direction == Qt::LeftToRight ) { | 
|---|
| 1909 | painter->drawLine(header->rect.topRight(), header->rect.bottomRight()); | 
|---|
| 1910 | } else { | 
|---|
| 1911 | painter->drawLine(header->rect.topLeft(), header->rect.bottomLeft()); | 
|---|
| 1912 | } | 
|---|
| 1913 | } | 
|---|
| 1914 | painter->restore(); | 
|---|
| 1915 |  | 
|---|
| 1916 | //Draw corner button as normal pushButton. | 
|---|
| 1917 | if (qobject_cast<const QAbstractButton *>(widget)) { | 
|---|
| 1918 | //Make cornerButton slightly smaller so that it is not on top of table border graphic. | 
|---|
| 1919 | QStyleOptionHeader subopt = *header; | 
|---|
| 1920 | const int borderTweak = | 
|---|
| 1921 | QS60StylePrivate::pixelMetric(PM_FrameCornerWidth) >> 1; | 
|---|
| 1922 | if (subopt.direction == Qt::LeftToRight) | 
|---|
| 1923 | subopt.rect.adjust(borderTweak, borderTweak, 0, -borderTweak); | 
|---|
| 1924 | else | 
|---|
| 1925 | subopt.rect.adjust(0, borderTweak, -borderTweak, -borderTweak); | 
|---|
| 1926 | drawPrimitive(PE_PanelButtonBevel, &subopt, painter, widget); | 
|---|
| 1927 | } else if ((header->palette.brush(QPalette::Button) != Qt::transparent)) { | 
|---|
| 1928 | //Draw non-themed background. Background for theme is drawn in CE_ShapedFrame | 
|---|
| 1929 | //to get continuous theme graphic across all the header cells. | 
|---|
| 1930 | qDrawShadePanel(painter, header->rect, header->palette, | 
|---|
| 1931 | header->state & (State_Sunken | State_On), penWidth, | 
|---|
| 1932 | &header->palette.brush(QPalette::Button)); | 
|---|
| 1933 | } | 
|---|
| 1934 | } | 
|---|
| 1935 | break; | 
|---|
| 1936 | case CE_HeaderEmptyArea: // no need to draw this | 
|---|
| 1937 | break; | 
|---|
| 1938 | case CE_Header: | 
|---|
| 1939 | if ( const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) { | 
|---|
| 1940 | drawControl(CE_HeaderSection, header, painter, widget); | 
|---|
| 1941 | QStyleOptionHeader subopt = *header; | 
|---|
| 1942 | subopt.rect = subElementRect(SE_HeaderLabel, header, widget); | 
|---|
| 1943 | if (subopt.rect.isValid()) | 
|---|
| 1944 | drawControl(CE_HeaderLabel, &subopt, painter, widget); | 
|---|
| 1945 | if (header->sortIndicator != QStyleOptionHeader::None) { | 
|---|
| 1946 | subopt.rect = subElementRect(SE_HeaderArrow, option, widget); | 
|---|
| 1947 | drawPrimitive(PE_IndicatorHeaderArrow, &subopt, painter, widget); | 
|---|
| 1948 | } | 
|---|
| 1949 | } | 
|---|
| 1950 | break; | 
|---|
| 1951 | #ifndef QT_NO_TOOLBAR | 
|---|
| 1952 | case CE_ToolBar: | 
|---|
| 1953 | if (const QStyleOptionToolBar *toolBar = qstyleoption_cast<const QStyleOptionToolBar *>(option)) { | 
|---|
| 1954 | const QToolBar *tbWidget = qobject_cast<const QToolBar *>(widget); | 
|---|
| 1955 |  | 
|---|
| 1956 | //toolbar within a toolbar, skip | 
|---|
| 1957 | if (!tbWidget || (widget && qobject_cast<QToolBar *>(widget->parentWidget()))) | 
|---|
| 1958 | break; | 
|---|
| 1959 |  | 
|---|
| 1960 | // Normally in S60 5.0+ there is no background for toolbar, but in some cases with versatile QToolBar, | 
|---|
| 1961 | // it looks a bit strange. So, lets fillRect with Button. | 
|---|
| 1962 | if (!QS60StylePrivate::isToolBarBackground()) { | 
|---|
| 1963 | QList<QAction *> actions = tbWidget->actions(); | 
|---|
| 1964 | bool justToolButtonsInToolBar = true; | 
|---|
| 1965 | for (int i = 0; i < actions.size(); ++i) { | 
|---|
| 1966 | QWidget *childWidget = tbWidget->widgetForAction(actions.at(i)); | 
|---|
| 1967 | const QToolButton *button = qobject_cast<const QToolButton *>(childWidget); | 
|---|
| 1968 | if (!button){ | 
|---|
| 1969 | justToolButtonsInToolBar = false; | 
|---|
| 1970 | } | 
|---|
| 1971 | } | 
|---|
| 1972 |  | 
|---|
| 1973 | // Draw frame background | 
|---|
| 1974 | // for vertical toolbars with text only and | 
|---|
| 1975 | // for toolbars with extension buttons and | 
|---|
| 1976 | // for toolbars with widgets in them. | 
|---|
| 1977 | if (!justToolButtonsInToolBar || | 
|---|
| 1978 | (tbWidget && | 
|---|
| 1979 | (tbWidget->orientation() == Qt::Vertical) && | 
|---|
| 1980 | (tbWidget->toolButtonStyle() == Qt::ToolButtonTextOnly))) { | 
|---|
| 1981 | painter->save(); | 
|---|
| 1982 | if (widget) | 
|---|
| 1983 | painter->setBrush(widget->palette().button()); | 
|---|
| 1984 | painter->setOpacity(0.3); | 
|---|
| 1985 | painter->fillRect(toolBar->rect, painter->brush()); | 
|---|
| 1986 | painter->restore(); | 
|---|
| 1987 | } | 
|---|
| 1988 | } else { | 
|---|
| 1989 | QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ToolBar, painter, toolBar->rect, flags); | 
|---|
| 1990 | } | 
|---|
| 1991 | } | 
|---|
| 1992 | break; | 
|---|
| 1993 | #endif //QT_NO_TOOLBAR | 
|---|
| 1994 | case CE_ShapedFrame: | 
|---|
| 1995 | if (const QTextEdit *textEdit = qobject_cast<const QTextEdit *>(widget)) { | 
|---|
| 1996 | const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(option); | 
|---|
| 1997 | if (frame && QS60StylePrivate::canDrawThemeBackground(frame->palette.base(), widget)) | 
|---|
| 1998 | QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_Editor, painter, option->rect, flags); | 
|---|
| 1999 | else | 
|---|
| 2000 | QCommonStyle::drawControl(element, option, painter, widget); | 
|---|
| 2001 | } else if (qobject_cast<const QTableView *>(widget)) { | 
|---|
| 2002 | QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_TableItem, painter, option->rect, flags); | 
|---|
| 2003 | } else if (const QHeaderView *header = qobject_cast<const QHeaderView *>(widget)) { | 
|---|
| 2004 | //QS60style draws header background here instead of in each headersection, to get | 
|---|
| 2005 | //continuous graphic from section to section. | 
|---|
| 2006 | QS60StylePrivate::SkinElementFlags adjustableFlags = flags; | 
|---|
| 2007 | QRect headerRect = option->rect; | 
|---|
| 2008 | if (header->orientation() != Qt::Horizontal) { | 
|---|
| 2009 | //todo: update to horizontal table graphic | 
|---|
| 2010 | adjustableFlags = (adjustableFlags | QS60StylePrivate::SF_PointWest); | 
|---|
| 2011 | } else { | 
|---|
| 2012 | const int frameWidth = QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth); | 
|---|
| 2013 | if (option->direction == Qt::LeftToRight) | 
|---|
| 2014 | headerRect.adjust(-2 * frameWidth, 0, 0, 0); | 
|---|
| 2015 | else | 
|---|
| 2016 | headerRect.adjust(0, 0, 2 * frameWidth, 0); | 
|---|
| 2017 | } | 
|---|
| 2018 | if (option->palette.brush(QPalette::Button).color() == Qt::transparent) | 
|---|
| 2019 | QS60StylePrivate::drawSkinElement( | 
|---|
| 2020 | QS60StylePrivate::SE_TableHeaderItem, painter, headerRect, adjustableFlags); | 
|---|
| 2021 |  | 
|---|
| 2022 | } else if (qobject_cast<const QFrame *>(widget)) { | 
|---|
| 2023 | QCommonStyle::drawControl(element, option, painter, widget); | 
|---|
| 2024 | } | 
|---|
| 2025 | break; | 
|---|
| 2026 | case CE_MenuScroller: | 
|---|
| 2027 | break; | 
|---|
| 2028 | case CE_FocusFrame: { | 
|---|
| 2029 | #ifdef QT_KEYPAD_NAVIGATION | 
|---|
| 2030 | bool editFocus = false; | 
|---|
| 2031 | if (const QFocusFrame *focusFrame = qobject_cast<const QFocusFrame*>(widget)) { | 
|---|
| 2032 | if (focusFrame->widget() && focusFrame->widget()->hasEditFocus()) | 
|---|
| 2033 | editFocus = true; | 
|---|
| 2034 | } | 
|---|
| 2035 | const qreal opacity = editFocus ? 1 : 0.75; // Trial and error factors. Feel free to improve. | 
|---|
| 2036 | #else | 
|---|
| 2037 | const qreal opacity = 0.85; | 
|---|
| 2038 | #endif | 
|---|
| 2039 | // We need to reduce the focus frame size if LayoutSpacing is smaller than FocusFrameMargin | 
|---|
| 2040 | // Otherwise, we would overlay adjacent widgets. | 
|---|
| 2041 | const int frameHeightReduction = | 
|---|
| 2042 | qMin(0, pixelMetric(PM_LayoutVerticalSpacing) | 
|---|
| 2043 | - pixelMetric(PM_FocusFrameVMargin)); | 
|---|
| 2044 | const int frameWidthReduction = | 
|---|
| 2045 | qMin(0, pixelMetric(PM_LayoutHorizontalSpacing) | 
|---|
| 2046 | - pixelMetric(PM_FocusFrameHMargin)); | 
|---|
| 2047 | const int rounding = | 
|---|
| 2048 | qMin(pixelMetric(PM_FocusFrameVMargin), | 
|---|
| 2049 | pixelMetric(PM_LayoutVerticalSpacing)); | 
|---|
| 2050 | const QRect frameRect = | 
|---|
| 2051 | option->rect.adjusted(-frameWidthReduction, -frameHeightReduction, | 
|---|
| 2052 | frameWidthReduction, frameHeightReduction); | 
|---|
| 2053 | QPainterPath framePath; | 
|---|
| 2054 | framePath.addRoundedRect(frameRect, rounding, rounding); | 
|---|
| 2055 |  | 
|---|
| 2056 | painter->save(); | 
|---|
| 2057 | painter->setRenderHint(QPainter::Antialiasing); | 
|---|
| 2058 | painter->setOpacity(opacity); | 
|---|
| 2059 | painter->fillPath(framePath, option->palette.color(QPalette::Text)); | 
|---|
| 2060 | painter->restore(); | 
|---|
| 2061 | } | 
|---|
| 2062 | break; | 
|---|
| 2063 | case CE_Splitter: | 
|---|
| 2064 | if (option->state & State_Sunken && option->state & State_Enabled && QS60StylePrivate::themePalette()) { | 
|---|
| 2065 | painter->save(); | 
|---|
| 2066 | painter->setOpacity(0.5); | 
|---|
| 2067 | painter->setBrush(QS60StylePrivate::themePalette()->light()); | 
|---|
| 2068 | painter->setRenderHint(QPainter::Antialiasing); | 
|---|
| 2069 | const qreal roundRectRadius = 4 * goldenRatio; | 
|---|
| 2070 | painter->drawRoundedRect(option->rect, roundRectRadius, roundRectRadius); | 
|---|
| 2071 | painter->restore(); | 
|---|
| 2072 | } | 
|---|
| 2073 | break; | 
|---|
| 2074 | default: | 
|---|
| 2075 | QCommonStyle::drawControl(element, option, painter, widget); | 
|---|
| 2076 | } | 
|---|
| 2077 | } | 
|---|
| 2078 |  | 
|---|
| 2079 | /*! | 
|---|
| 2080 | \reimp | 
|---|
| 2081 | */ | 
|---|
| 2082 | void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const | 
|---|
| 2083 | { | 
|---|
| 2084 | const QS60StylePrivate::SkinElementFlags flags = (option->state & State_Enabled) ?  QS60StylePrivate::SF_StateEnabled : QS60StylePrivate::SF_StateDisabled; | 
|---|
| 2085 | bool commonStyleDraws = false; | 
|---|
| 2086 |  | 
|---|
| 2087 | switch (element) { | 
|---|
| 2088 | case PE_FrameFocusRect: { | 
|---|
| 2089 | //Draw themed highlight to radiobuttons and checkboxes. | 
|---|
| 2090 | //For other widgets skip, unless palette has been modified. In that case, draw with commonstyle. | 
|---|
| 2091 | if (QS60StylePrivate::equalToThemePalette(option->palette.highlight().color(), QPalette::Highlight)) { | 
|---|
| 2092 | if ((qstyleoption_cast<const QStyleOptionFocusRect *>(option) && | 
|---|
| 2093 | (qobject_cast<const QRadioButton *>(widget) || qobject_cast<const QCheckBox *>(widget)))) | 
|---|
| 2094 | QS60StylePrivate::drawSkinElement( | 
|---|
| 2095 | QS60StylePrivate::isWidgetPressed(widget) ? | 
|---|
| 2096 | QS60StylePrivate::SE_ListItemPressed : | 
|---|
| 2097 | QS60StylePrivate::SE_ListHighlight, painter, option->rect, flags); | 
|---|
| 2098 | } else { | 
|---|
| 2099 | commonStyleDraws = true; | 
|---|
| 2100 | } | 
|---|
| 2101 | } | 
|---|
| 2102 | break; | 
|---|
| 2103 | #ifndef QT_NO_LINEEDIT | 
|---|
| 2104 | case PE_PanelLineEdit: | 
|---|
| 2105 | if (const QStyleOptionFrame *lineEdit = qstyleoption_cast<const QStyleOptionFrame *>(option)) { | 
|---|
| 2106 | #ifndef QT_NO_COMBOBOX | 
|---|
| 2107 | if (widget && qobject_cast<const QComboBox *>(widget->parentWidget())) | 
|---|
| 2108 | break; | 
|---|
| 2109 | #endif | 
|---|
| 2110 | if (QS60StylePrivate::canDrawThemeBackground(option->palette.base(), widget)) | 
|---|
| 2111 | QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_FrameLineEdit, painter, option->rect, flags); | 
|---|
| 2112 | else | 
|---|
| 2113 | commonStyleDraws = true; | 
|---|
| 2114 | } | 
|---|
| 2115 | break; | 
|---|
| 2116 | #endif // QT_NO_LINEEDIT | 
|---|
| 2117 | case PE_IndicatorCheckBox: { | 
|---|
| 2118 | // Draw checkbox indicator as color skinned graphics. | 
|---|
| 2119 | const QS60StyleEnums::SkinParts skinPart = (option->state & State_On) ? | 
|---|
| 2120 | QS60StyleEnums::SP_QgnIndiCheckboxOn : QS60StyleEnums::SP_QgnIndiCheckboxOff; | 
|---|
| 2121 | painter->save(); | 
|---|
| 2122 |  | 
|---|
| 2123 | if (QS60StylePrivate::equalToThemePalette(option->palette.windowText().color(), QPalette::WindowText)) | 
|---|
| 2124 | painter->setPen(option->palette.windowText().color()); | 
|---|
| 2125 |  | 
|---|
| 2126 | QS60StylePrivate::drawSkinPart(skinPart, painter, option->rect, flags | QS60StylePrivate::SF_ColorSkinned ); | 
|---|
| 2127 | painter->restore(); | 
|---|
| 2128 | } | 
|---|
| 2129 | break; | 
|---|
| 2130 | case PE_IndicatorViewItemCheck: | 
|---|
| 2131 | #ifndef QT_NO_ITEMVIEWS | 
|---|
| 2132 | if (const QAbstractItemView *itemView = (qobject_cast<const QAbstractItemView *>(widget))) { | 
|---|
| 2133 | if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(option)) { | 
|---|
| 2134 | const bool checkBoxVisible = vopt->features & QStyleOptionViewItemV2::HasCheckIndicator; | 
|---|
| 2135 | const bool singleSelection = itemView->selectionMode() == | 
|---|
| 2136 | QAbstractItemView::SingleSelection || itemView->selectionMode() == QAbstractItemView::NoSelection; | 
|---|
| 2137 | // draw either checkbox at the beginning | 
|---|
| 2138 | if (checkBoxVisible && singleSelection) { | 
|---|
| 2139 | drawPrimitive(PE_IndicatorCheckBox, option, painter, widget); | 
|---|
| 2140 | // ... or normal "tick" selection at the end. | 
|---|
| 2141 | } else if (option->state & State_Selected) { | 
|---|
| 2142 | QRect tickRect = option->rect; | 
|---|
| 2143 | const int frameBorderWidth = QS60StylePrivate::pixelMetric(PM_FrameCornerWidth); | 
|---|
| 2144 | // adjust tickmark rect to exclude frame border | 
|---|
| 2145 | tickRect.adjust(0, -frameBorderWidth, 0, -frameBorderWidth); | 
|---|
| 2146 | QS60StyleEnums::SkinParts skinPart = QS60StyleEnums::SP_QgnIndiMarkedAdd; | 
|---|
| 2147 | QS60StylePrivate::drawSkinPart(skinPart, painter, tickRect, | 
|---|
| 2148 | (flags | QS60StylePrivate::SF_ColorSkinned)); | 
|---|
| 2149 | } | 
|---|
| 2150 | } | 
|---|
| 2151 | } | 
|---|
| 2152 | #endif //QT_NO_ITEMVIEWS | 
|---|
| 2153 | break; | 
|---|
| 2154 | case PE_IndicatorRadioButton: { | 
|---|
| 2155 | QRect buttonRect = option->rect; | 
|---|
| 2156 | //there is empty (a. 33%) space in svg graphics for radiobutton | 
|---|
| 2157 | const qreal reduceWidth = (qreal)buttonRect.width() / 3.0; | 
|---|
| 2158 | const qreal rectWidth = (qreal)option->rect.width() != 0 ? option->rect.width() : 1.0; | 
|---|
| 2159 | // Try to occupy the full area | 
|---|
| 2160 | const qreal scaler = 1 + (reduceWidth/rectWidth); | 
|---|
| 2161 | buttonRect.setWidth((int)((buttonRect.width()-reduceWidth) * scaler)); | 
|---|
| 2162 | buttonRect.setHeight((int)(buttonRect.height() * scaler)); | 
|---|
| 2163 | // move the rect up for half of the new height-gain | 
|---|
| 2164 | const int newY = (buttonRect.bottomRight().y() - option->rect.bottomRight().y()) >> 1 ; | 
|---|
| 2165 | buttonRect.adjust(0, -newY, -1, -newY); | 
|---|
| 2166 |  | 
|---|
| 2167 | painter->save(); | 
|---|
| 2168 | const QColor themeColor = QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnTextColors, 6, option); | 
|---|
| 2169 | const QColor buttonTextColor = option->palette.buttonText().color(); | 
|---|
| 2170 | if (themeColor != buttonTextColor) | 
|---|
| 2171 | painter->setPen(buttonTextColor); | 
|---|
| 2172 | else | 
|---|
| 2173 | painter->setPen(themeColor); | 
|---|
| 2174 |  | 
|---|
| 2175 | // Draw radiobutton indicator as color skinned graphics. | 
|---|
| 2176 | QS60StyleEnums::SkinParts skinPart = (option->state & State_On) ? | 
|---|
| 2177 | QS60StyleEnums::SP_QgnIndiRadiobuttOn : QS60StyleEnums::SP_QgnIndiRadiobuttOff; | 
|---|
| 2178 | QS60StylePrivate::drawSkinPart(skinPart, painter, buttonRect, | 
|---|
| 2179 | (flags | QS60StylePrivate::SF_ColorSkinned)); | 
|---|
| 2180 | painter->restore(); | 
|---|
| 2181 | } | 
|---|
| 2182 | break; | 
|---|
| 2183 | case PE_PanelButtonCommand: | 
|---|
| 2184 | case PE_PanelButtonTool: | 
|---|
| 2185 | case PE_PanelButtonBevel: | 
|---|
| 2186 | case PE_FrameButtonBevel: | 
|---|
| 2187 | if (QS60StylePrivate::canDrawThemeBackground(option->palette.base(), widget)) { | 
|---|
| 2188 | const bool isPressed = (option->state & State_Sunken) || (option->state & State_On); | 
|---|
| 2189 | QS60StylePrivate::SkinElements skinElement; | 
|---|
| 2190 | if (element == PE_PanelButtonTool) | 
|---|
| 2191 | skinElement = isPressed ? QS60StylePrivate::SE_ToolBarButtonPressed : QS60StylePrivate::SE_ToolBarButton; | 
|---|
| 2192 | else | 
|---|
| 2193 | skinElement = isPressed ? QS60StylePrivate::SE_ButtonPressed : QS60StylePrivate::SE_ButtonNormal; | 
|---|
| 2194 | QS60StylePrivate::drawSkinElement(skinElement, painter, option->rect, flags); | 
|---|
| 2195 | } else { | 
|---|
| 2196 | commonStyleDraws = true; | 
|---|
| 2197 | } | 
|---|
| 2198 | break; | 
|---|
| 2199 | #ifndef QT_NO_TOOLBUTTON | 
|---|
| 2200 | case PE_IndicatorArrowDown: | 
|---|
| 2201 | case PE_IndicatorArrowLeft: | 
|---|
| 2202 | case PE_IndicatorArrowRight: | 
|---|
| 2203 | case PE_IndicatorArrowUp: { | 
|---|
| 2204 | QS60StyleEnums::SkinParts skinPart; | 
|---|
| 2205 | if (element==PE_IndicatorArrowDown) | 
|---|
| 2206 | skinPart = QS60StyleEnums::SP_QgnGrafScrollArrowDown; | 
|---|
| 2207 | else if (element==PE_IndicatorArrowLeft) | 
|---|
| 2208 | skinPart = QS60StyleEnums::SP_QgnGrafScrollArrowLeft; | 
|---|
| 2209 | else if (element==PE_IndicatorArrowRight) | 
|---|
| 2210 | skinPart = QS60StyleEnums::SP_QgnGrafScrollArrowRight; | 
|---|
| 2211 | else if (element==PE_IndicatorArrowUp) | 
|---|
| 2212 | skinPart = QS60StyleEnums::SP_QgnGrafScrollArrowUp; | 
|---|
| 2213 |  | 
|---|
| 2214 | QS60StylePrivate::drawSkinPart(skinPart, painter, option->rect, flags); | 
|---|
| 2215 | } | 
|---|
| 2216 | break; | 
|---|
| 2217 | #endif //QT_NO_TOOLBUTTON | 
|---|
| 2218 | #ifndef QT_NO_SPINBOX | 
|---|
| 2219 | case PE_IndicatorSpinDown: | 
|---|
| 2220 | case PE_IndicatorSpinUp: | 
|---|
| 2221 | if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) { | 
|---|
| 2222 | if (QS60StylePrivate::canDrawThemeBackground(spinBox->palette.base(), widget)) { | 
|---|
| 2223 | QStyleOptionSpinBox optionSpinBox = *spinBox; | 
|---|
| 2224 | const QS60StyleEnums::SkinParts part = (element == PE_IndicatorSpinUp) ? | 
|---|
| 2225 | QS60StyleEnums::SP_QgnGrafScrollArrowUp : | 
|---|
| 2226 | QS60StyleEnums::SP_QgnGrafScrollArrowDown; | 
|---|
| 2227 | const int iconMargin = QS60StylePrivate::pixelMetric(PM_FrameCornerWidth) >> 1; | 
|---|
| 2228 | optionSpinBox.rect.translate(0, (element == PE_IndicatorSpinDown) ? iconMargin : -iconMargin ); | 
|---|
| 2229 | QS60StylePrivate::drawSkinPart(part, painter, optionSpinBox.rect, flags); | 
|---|
| 2230 | } else { | 
|---|
| 2231 | commonStyleDraws = true; | 
|---|
| 2232 | } | 
|---|
| 2233 | } | 
|---|
| 2234 | #endif //QT_NO_SPINBOX | 
|---|
| 2235 | #ifndef QT_NO_COMBOBOX | 
|---|
| 2236 | if (const QStyleOptionFrame *cmb = qstyleoption_cast<const QStyleOptionFrame *>(option)) { | 
|---|
| 2237 | if (QS60StylePrivate::canDrawThemeBackground( option->palette.base(), widget)) { | 
|---|
| 2238 | // We want to draw down arrow here for comboboxes as well. | 
|---|
| 2239 | QStyleOptionFrame optionsComboBox = *cmb; | 
|---|
| 2240 | const QS60StyleEnums::SkinParts part = QS60StyleEnums::SP_QgnGrafScrollArrowDown; | 
|---|
| 2241 | const int iconMargin = QS60StylePrivate::pixelMetric(PM_FrameCornerWidth) >> 1; | 
|---|
| 2242 | optionsComboBox.rect.translate(0, (element == PE_IndicatorSpinDown) ? iconMargin : -iconMargin ); | 
|---|
| 2243 | QS60StylePrivate::drawSkinPart(part, painter, optionsComboBox.rect, flags); | 
|---|
| 2244 | } else { | 
|---|
| 2245 | commonStyleDraws = true; | 
|---|
| 2246 | } | 
|---|
| 2247 | } | 
|---|
| 2248 | #endif //QT_NO_COMBOBOX | 
|---|
| 2249 | break; | 
|---|
| 2250 | case PE_IndicatorSpinMinus: | 
|---|
| 2251 | case PE_IndicatorSpinPlus: | 
|---|
| 2252 | if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) { | 
|---|
| 2253 | QStyleOptionSpinBox optionSpinBox = *spinBox; | 
|---|
| 2254 | QCommonStyle::drawPrimitive(element, &optionSpinBox, painter, widget); | 
|---|
| 2255 | } | 
|---|
| 2256 | #ifndef QT_NO_COMBOBOX | 
|---|
| 2257 | else if (const QStyleOptionFrame *cmb = qstyleoption_cast<const QStyleOptionFrame *>(option)) { | 
|---|
| 2258 | // We want to draw down arrow here for comboboxes as well. | 
|---|
| 2259 | QStyleOptionFrame comboBox = *cmb; | 
|---|
| 2260 | const int frameWidth = QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth); | 
|---|
| 2261 | comboBox.rect.adjust(0, frameWidth, 0, -frameWidth); | 
|---|
| 2262 | QCommonStyle::drawPrimitive(element, &comboBox, painter, widget); | 
|---|
| 2263 | } | 
|---|
| 2264 | #endif //QT_NO_COMBOBOX | 
|---|
| 2265 | break; | 
|---|
| 2266 | case PE_Widget: | 
|---|
| 2267 | if (QS60StylePrivate::drawsOwnThemeBackground(widget) | 
|---|
| 2268 | #ifndef QT_NO_COMBOBOX | 
|---|
| 2269 | || qobject_cast<const QComboBoxListView *>(widget) | 
|---|
| 2270 | #endif //QT_NO_COMBOBOX | 
|---|
| 2271 | #ifndef QT_NO_MENU | 
|---|
| 2272 | || qobject_cast<const QMenu *> (widget) | 
|---|
| 2273 | #endif //QT_NO_MENU | 
|---|
| 2274 | ) { | 
|---|
| 2275 | //Need extra check since dialogs have their own theme background | 
|---|
| 2276 | if (QS60StylePrivate::canDrawThemeBackground(option->palette.base(), widget) && | 
|---|
| 2277 | QS60StylePrivate::equalToThemePalette(option->palette.window().texture().cacheKey(), QPalette::Window)) | 
|---|
| 2278 | //todo: for combobox listviews, the background should include area for menu scrollers, | 
|---|
| 2279 | //but this produces drawing issues as we need to turn clipping off. | 
|---|
| 2280 | QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_PopupBackground, painter, option->rect, flags); | 
|---|
| 2281 | else | 
|---|
| 2282 | commonStyleDraws = true; | 
|---|
| 2283 | } | 
|---|
| 2284 | break; | 
|---|
| 2285 | case PE_FrameWindow: | 
|---|
| 2286 | case PE_FrameTabWidget: | 
|---|
| 2287 | if (const QStyleOptionTabWidgetFrame *tabFrame = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(option)) { | 
|---|
| 2288 | QStyleOptionTabWidgetFrame optionTabFrame = *tabFrame; | 
|---|
| 2289 | QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_PanelBackground, painter, optionTabFrame.rect, flags); | 
|---|
| 2290 | } | 
|---|
| 2291 | break; | 
|---|
| 2292 | case PE_IndicatorHeaderArrow: | 
|---|
| 2293 | if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) { | 
|---|
| 2294 | if (header->sortIndicator & QStyleOptionHeader::SortUp) | 
|---|
| 2295 | drawPrimitive(PE_IndicatorArrowUp, header, painter, widget); | 
|---|
| 2296 | else if (header->sortIndicator & QStyleOptionHeader::SortDown) | 
|---|
| 2297 | drawPrimitive(PE_IndicatorArrowDown, header, painter, widget); | 
|---|
| 2298 | } // QStyleOptionHeader::None is not drawn => not needed | 
|---|
| 2299 | break; | 
|---|
| 2300 | #ifndef QT_NO_GROUPBOX | 
|---|
| 2301 | case PE_FrameGroupBox: | 
|---|
| 2302 | if (const QStyleOptionFrameV2 *frame = qstyleoption_cast<const QStyleOptionFrameV2 *>(option)) | 
|---|
| 2303 | QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_SettingsList, painter, frame->rect, flags); | 
|---|
| 2304 | break; | 
|---|
| 2305 | #endif //QT_NO_GROUPBOX | 
|---|
| 2306 |  | 
|---|
| 2307 | // Qt3 primitives are not supported | 
|---|
| 2308 | case PE_Q3CheckListController: | 
|---|
| 2309 | case PE_Q3CheckListExclusiveIndicator: | 
|---|
| 2310 | case PE_Q3CheckListIndicator: | 
|---|
| 2311 | case PE_Q3DockWindowSeparator: | 
|---|
| 2312 | case PE_Q3Separator: | 
|---|
| 2313 | Q_ASSERT(false); | 
|---|
| 2314 | break; | 
|---|
| 2315 | case PE_Frame: | 
|---|
| 2316 | break; | 
|---|
| 2317 | #ifndef QT_NO_ITEMVIEWS | 
|---|
| 2318 | case PE_PanelItemViewItem: | 
|---|
| 2319 | if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(option)) { | 
|---|
| 2320 | const bool isSelected = (vopt->state & State_Selected); | 
|---|
| 2321 | const bool hasFocus = (vopt->state & State_HasFocus); | 
|---|
| 2322 | const bool isPressed = QS60StylePrivate::isWidgetPressed(widget); | 
|---|
| 2323 |  | 
|---|
| 2324 | if (QS60StylePrivate::equalToThemePalette(option->palette.highlight().color(), QPalette::Highlight)) { | 
|---|
| 2325 | QRect highlightRect = vopt->rect.adjusted(1,1,-1,-1); | 
|---|
| 2326 | const QAbstractItemView *itemView = qobject_cast<const QAbstractItemView *>(widget); | 
|---|
| 2327 | QAbstractItemView::SelectionBehavior selectionBehavior = | 
|---|
| 2328 | itemView ? itemView->selectionBehavior() : QAbstractItemView::SelectItems; | 
|---|
| 2329 | // Set the draw area for highlights (focus, select rect or pressed rect) | 
|---|
| 2330 | if (hasFocus || isPressed) { | 
|---|
| 2331 | if (selectionBehavior != QAbstractItemView::SelectItems) { | 
|---|
| 2332 | // set highlight rect so that it is continuous from cell to cell, yet sligthly | 
|---|
| 2333 | // smaller than cell rect | 
|---|
| 2334 | int xBeginning = 0, yBeginning = 0, xEnd = 0, yEnd = 0; | 
|---|
| 2335 | if (selectionBehavior == QAbstractItemView::SelectRows) { | 
|---|
| 2336 | yBeginning = 1; yEnd = -1; | 
|---|
| 2337 | if (vopt->viewItemPosition == QStyleOptionViewItemV4::Beginning) | 
|---|
| 2338 | xBeginning = 1; | 
|---|
| 2339 | else if (vopt->viewItemPosition == QStyleOptionViewItemV4::End) | 
|---|
| 2340 | xEnd = -1; | 
|---|
| 2341 | } else if (selectionBehavior == QAbstractItemView::SelectColumns) { | 
|---|
| 2342 | xBeginning = 1; xEnd = -1; | 
|---|
| 2343 | if (vopt->viewItemPosition == QStyleOptionViewItemV4::Beginning) | 
|---|
| 2344 | yBeginning = 1; | 
|---|
| 2345 | else if (vopt->viewItemPosition == QStyleOptionViewItemV4::End) | 
|---|
| 2346 | yEnd = -1; | 
|---|
| 2347 | } | 
|---|
| 2348 | highlightRect = option->rect.adjusted(xBeginning, yBeginning, xEnd, yEnd); | 
|---|
| 2349 | } | 
|---|
| 2350 | } | 
|---|
| 2351 | bool tableView = false; | 
|---|
| 2352 | if (itemView && qobject_cast<const QTableView *>(widget)) | 
|---|
| 2353 | tableView = true; | 
|---|
| 2354 |  | 
|---|
| 2355 | QS60StylePrivate::SkinElements element; | 
|---|
| 2356 | bool themeGraphicDefined = false; | 
|---|
| 2357 | QRect elementRect = option->rect; | 
|---|
| 2358 |  | 
|---|
| 2359 | //draw item is drawn as pressed, if it already has focus. | 
|---|
| 2360 | if (isPressed && hasFocus) { | 
|---|
| 2361 | themeGraphicDefined = true; | 
|---|
| 2362 | element = tableView ? QS60StylePrivate::SE_TableItemPressed : QS60StylePrivate::SE_ListItemPressed; | 
|---|
| 2363 | } else if (hasFocus || (isSelected && selectionBehavior != QAbstractItemView::SelectItems)) { | 
|---|
| 2364 | element = QS60StylePrivate::SE_ListHighlight; | 
|---|
| 2365 | elementRect = highlightRect; | 
|---|
| 2366 | themeGraphicDefined = true; | 
|---|
| 2367 | } | 
|---|
| 2368 | if (themeGraphicDefined) | 
|---|
| 2369 | QS60StylePrivate::drawSkinElement(element, painter, elementRect, flags); | 
|---|
| 2370 | } else { | 
|---|
| 2371 | QCommonStyle::drawPrimitive(element, option, painter, widget); | 
|---|
| 2372 | } | 
|---|
| 2373 | } | 
|---|
| 2374 | break; | 
|---|
| 2375 | #endif //QT_NO_ITEMVIEWS | 
|---|
| 2376 |  | 
|---|
| 2377 | case PE_IndicatorMenuCheckMark: | 
|---|
| 2378 | if (const QStyleOptionMenuItem *checkBox = qstyleoption_cast<const QStyleOptionMenuItem *>(option)){ | 
|---|
| 2379 | QStyleOptionMenuItem optionCheckBox = *checkBox; | 
|---|
| 2380 | if (optionCheckBox.checked) | 
|---|
| 2381 | optionCheckBox.state = (optionCheckBox.state | State_On); | 
|---|
| 2382 | drawPrimitive(PE_IndicatorCheckBox, &optionCheckBox, painter, widget); | 
|---|
| 2383 | } | 
|---|
| 2384 | break; | 
|---|
| 2385 | #ifndef QT_NO_TOOLBAR | 
|---|
| 2386 | case PE_IndicatorToolBarHandle: | 
|---|
| 2387 | // no toolbar handles in S60/AVKON UI | 
|---|
| 2388 | case PE_IndicatorToolBarSeparator: | 
|---|
| 2389 | // no separators in S60/AVKON UI | 
|---|
| 2390 | break; | 
|---|
| 2391 | #endif //QT_NO_TOOLBAR | 
|---|
| 2392 |  | 
|---|
| 2393 | case PE_PanelMenuBar: | 
|---|
| 2394 | case PE_FrameMenu: | 
|---|
| 2395 | break; //disable frame in menu | 
|---|
| 2396 |  | 
|---|
| 2397 | case PE_IndicatorBranch: | 
|---|
| 2398 | #if defined(Q_WS_S60) | 
|---|
| 2399 | // 3.1 AVKON UI does not have tree view component, use common style for drawing there | 
|---|
| 2400 | if (QSysInfo::s60Version() == QSysInfo::SV_S60_3_1) { | 
|---|
| 2401 | #else | 
|---|
| 2402 | if (true) { | 
|---|
| 2403 | #endif | 
|---|
| 2404 | QCommonStyle::drawPrimitive(element, option, painter, widget); | 
|---|
| 2405 | } else { | 
|---|
| 2406 | if (const QStyleOptionViewItemV2 *vopt = qstyleoption_cast<const QStyleOptionViewItemV2 *>(option)) { | 
|---|
| 2407 | const bool rightLine = option->state & State_Item; | 
|---|
| 2408 | const bool downLine = option->state & State_Sibling; | 
|---|
| 2409 | const bool upLine = option->state & (State_Open | State_Children | State_Item | State_Sibling); | 
|---|
| 2410 | QS60StylePrivate::SkinElementFlags adjustedFlags = flags; | 
|---|
| 2411 |  | 
|---|
| 2412 | QS60StyleEnums::SkinParts skinPart; | 
|---|
| 2413 | bool drawSkinPart = false; | 
|---|
| 2414 | if (rightLine && downLine && upLine) { | 
|---|
| 2415 | skinPart = QS60StyleEnums::SP_QgnIndiHlLineBranch; | 
|---|
| 2416 | drawSkinPart = true; | 
|---|
| 2417 | } else if (rightLine && upLine) { | 
|---|
| 2418 | skinPart = QS60StyleEnums::SP_QgnIndiHlLineEnd; | 
|---|
| 2419 | drawSkinPart = true; | 
|---|
| 2420 | } else if (upLine && downLine) { | 
|---|
| 2421 | skinPart = QS60StyleEnums::SP_QgnIndiHlLineStraight; | 
|---|
| 2422 | drawSkinPart = true; | 
|---|
| 2423 | } | 
|---|
| 2424 |  | 
|---|
| 2425 | if (option->direction == Qt::RightToLeft) | 
|---|
| 2426 | adjustedFlags |= QS60StylePrivate::SF_Mirrored_X_Axis; | 
|---|
| 2427 |  | 
|---|
| 2428 | if (drawSkinPart) | 
|---|
| 2429 | QS60StylePrivate::drawSkinPart(skinPart, painter, option->rect, adjustedFlags); | 
|---|
| 2430 |  | 
|---|
| 2431 | if (option->state & State_Children) { | 
|---|
| 2432 | QS60StyleEnums::SkinParts skinPart = | 
|---|
| 2433 | (option->state & State_Open) ? QS60StyleEnums::SP_QgnIndiHlColSuper : QS60StyleEnums::SP_QgnIndiHlExpSuper; | 
|---|
| 2434 | const QRect selectionRect = subElementRect(SE_ItemViewItemCheckIndicator, vopt, widget); | 
|---|
| 2435 | const int minDimension = qMin(option->rect.width(), option->rect.height()); | 
|---|
| 2436 | const int magicTweak = (option->direction == Qt::RightToLeft) ? -3 : 3; //@todo: magic | 
|---|
| 2437 | //The branch indicator icon in S60 is supposed to be superimposed on top of branch lines. | 
|---|
| 2438 | QRect iconRect(QPoint(option->rect.left() + magicTweak, selectionRect.top() + 1), QSize(minDimension, minDimension)); | 
|---|
| 2439 | if (!QS60StylePrivate::isTouchSupported()) | 
|---|
| 2440 | iconRect.translate(0, -4); //@todo: magic | 
|---|
| 2441 | QS60StylePrivate::drawSkinPart(skinPart, painter, iconRect, adjustedFlags); | 
|---|
| 2442 | } | 
|---|
| 2443 | } | 
|---|
| 2444 | } | 
|---|
| 2445 | break; | 
|---|
| 2446 | case PE_PanelItemViewRow: // ### Qt 5: remove | 
|---|
| 2447 | #ifndef QT_NO_ITEMVIEWS | 
|---|
| 2448 | if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(option)) { | 
|---|
| 2449 | if (!QS60StylePrivate::equalToThemePalette(vopt->palette.base().texture().cacheKey(), QPalette::Base)) { | 
|---|
| 2450 | //QPalette::Base has been changed, let commonstyle draw the item | 
|---|
| 2451 | commonStyleDraws = true; | 
|---|
| 2452 | } else { | 
|---|
| 2453 | QPalette::ColorGroup cg = vopt->state & State_Enabled ? QPalette::Normal : QPalette::Disabled; | 
|---|
| 2454 | if (cg == QPalette::Normal && !(vopt->state & State_Active)) | 
|---|
| 2455 | cg = QPalette::Inactive; | 
|---|
| 2456 | if (vopt->features & QStyleOptionViewItemV2::Alternate) | 
|---|
| 2457 | painter->fillRect(vopt->rect, vopt->palette.brush(cg, QPalette::AlternateBase)); | 
|---|
| 2458 | //apart from alternate base, no background for list item is drawn for S60Style | 
|---|
| 2459 | } | 
|---|
| 2460 | } | 
|---|
| 2461 | #endif | 
|---|
| 2462 | break; | 
|---|
| 2463 | case PE_PanelScrollAreaCorner: | 
|---|
| 2464 | break; | 
|---|
| 2465 | case PE_IndicatorItemViewItemDrop: | 
|---|
| 2466 | if (QS60StylePrivate::isTouchSupported()) | 
|---|
| 2467 | QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_DropArea, painter, option->rect, flags); | 
|---|
| 2468 | else | 
|---|
| 2469 | commonStyleDraws = true; | 
|---|
| 2470 | break; | 
|---|
| 2471 | // todo: items are below with #ifdefs "just in case". in final version, remove all non-required cases | 
|---|
| 2472 | case PE_FrameLineEdit: | 
|---|
| 2473 | case PE_IndicatorDockWidgetResizeHandle: | 
|---|
| 2474 | case PE_PanelTipLabel: | 
|---|
| 2475 |  | 
|---|
| 2476 | #ifndef QT_NO_TABBAR | 
|---|
| 2477 | case PE_IndicatorTabTear: // No tab tear in S60 | 
|---|
| 2478 | #endif // QT_NO_TABBAR | 
|---|
| 2479 | case PE_FrameDefaultButton: | 
|---|
| 2480 | #ifndef QT_NO_DOCKWIDGET | 
|---|
| 2481 | case PE_FrameDockWidget: | 
|---|
| 2482 | #endif //QT_NO_DOCKWIDGET | 
|---|
| 2483 | #ifndef QT_NO_PROGRESSBAR | 
|---|
| 2484 | case PE_IndicatorProgressChunk: | 
|---|
| 2485 | #endif //QT_NO_PROGRESSBAR | 
|---|
| 2486 | #ifndef QT_NO_TOOLBAR | 
|---|
| 2487 | case PE_PanelToolBar: | 
|---|
| 2488 | #endif //QT_NO_TOOLBAR | 
|---|
| 2489 | #ifndef QT_NO_COLUMNVIEW | 
|---|
| 2490 | case PE_IndicatorColumnViewArrow: | 
|---|
| 2491 | #endif //QT_NO_COLUMNVIEW | 
|---|
| 2492 | case PE_FrameTabBarBase: // since tabs are in S60 always in navipane, let's use common style for tab base in Qt. | 
|---|
| 2493 | default: | 
|---|
| 2494 | commonStyleDraws = true; | 
|---|
| 2495 | } | 
|---|
| 2496 | if (commonStyleDraws) { | 
|---|
| 2497 | QCommonStyle::drawPrimitive(element, option, painter, widget); | 
|---|
| 2498 | } | 
|---|
| 2499 | } | 
|---|
| 2500 |  | 
|---|
| 2501 | /*! \reimp */ | 
|---|
| 2502 | int QS60Style::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const | 
|---|
| 2503 | { | 
|---|
| 2504 | int metricValue = QS60StylePrivate::pixelMetric(metric); | 
|---|
| 2505 | if (metricValue == KNotFound) | 
|---|
| 2506 | metricValue = QCommonStyle::pixelMetric(metric, option, widget); | 
|---|
| 2507 |  | 
|---|
| 2508 | // Menu scrollers should be set to zero height for combobox popups | 
|---|
| 2509 | if (metric == PM_MenuScrollerHeight && !qobject_cast<const QMenu *>(widget)) | 
|---|
| 2510 | metricValue = 0; | 
|---|
| 2511 |  | 
|---|
| 2512 | //if layout direction is mirrored, switch left and right border margins | 
|---|
| 2513 | if (option && option->direction == Qt::RightToLeft) { | 
|---|
| 2514 | if (metric == PM_LayoutLeftMargin) | 
|---|
| 2515 | metricValue = QS60StylePrivate::pixelMetric(PM_LayoutRightMargin); | 
|---|
| 2516 | else if (metric == PM_LayoutRightMargin) | 
|---|
| 2517 | metricValue = QS60StylePrivate::pixelMetric(PM_LayoutLeftMargin); | 
|---|
| 2518 | } | 
|---|
| 2519 |  | 
|---|
| 2520 | if (widget && (metric == PM_LayoutTopMargin || metric == PM_LayoutLeftMargin || metric == PM_LayoutRightMargin)) | 
|---|
| 2521 | if (widget->windowType() == Qt::Dialog) | 
|---|
| 2522 | //double the layout margins (except bottom) for dialogs, it is very close to real value | 
|---|
| 2523 | //without having to define custom pixel metric | 
|---|
| 2524 | metricValue *= 2; | 
|---|
| 2525 |  | 
|---|
| 2526 | return metricValue; | 
|---|
| 2527 | } | 
|---|
| 2528 |  | 
|---|
| 2529 | /*! \reimp */ | 
|---|
| 2530 | QSize QS60Style::sizeFromContents(ContentsType ct, const QStyleOption *opt, | 
|---|
| 2531 | const QSize &csz, const QWidget *widget) const | 
|---|
| 2532 | { | 
|---|
| 2533 | QSize sz(csz); | 
|---|
| 2534 | switch (ct) { | 
|---|
| 2535 | case CT_ToolButton: | 
|---|
| 2536 | sz = QCommonStyle::sizeFromContents( ct, opt, csz, widget); | 
|---|
| 2537 | //FIXME properly - style should calculate the location of border frame-part | 
|---|
| 2538 | sz += QSize(2 * pixelMetric(PM_ButtonMargin), 2 * pixelMetric(PM_ButtonMargin)); | 
|---|
| 2539 | if (const QStyleOptionToolButton *toolBtn = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) | 
|---|
| 2540 | if (toolBtn->subControls & SC_ToolButtonMenu) | 
|---|
| 2541 | sz += QSize(pixelMetric(PM_MenuButtonIndicator), 0); | 
|---|
| 2542 |  | 
|---|
| 2543 | //Make toolbuttons in toolbar stretch the whole screen area | 
|---|
| 2544 | if (widget && qobject_cast<const QToolBar *>(widget->parentWidget())) { | 
|---|
| 2545 | const QToolBar *tb = qobject_cast<const QToolBar *>(widget->parentWidget()); | 
|---|
| 2546 | const bool parentCanGrowHorizontally = !(tb->sizePolicy().horizontalPolicy() == QSizePolicy::Fixed || | 
|---|
| 2547 | tb->sizePolicy().horizontalPolicy() == QSizePolicy::Maximum) && tb->orientation() == Qt::Horizontal; | 
|---|
| 2548 |  | 
|---|
| 2549 | if (parentCanGrowHorizontally) { | 
|---|
| 2550 | int visibleButtons = 0; | 
|---|
| 2551 | //Make the auto-stretch to happen only for horizontal orientation | 
|---|
| 2552 | if (tb && tb->orientation() == Qt::Horizontal) { | 
|---|
| 2553 | QList<QAction*> actionList =  tb->actions(); | 
|---|
| 2554 | for (int i = 0; i < actionList.count(); i++) { | 
|---|
| 2555 | if (actionList.at(i)->isVisible()) | 
|---|
| 2556 | visibleButtons++; | 
|---|
| 2557 | } | 
|---|
| 2558 | } | 
|---|
| 2559 |  | 
|---|
| 2560 | if (widget->parentWidget() && visibleButtons > 0) { | 
|---|
| 2561 | QWidget *w = const_cast<QWidget *>(widget); | 
|---|
| 2562 | int toolBarMaxWidth = 0; | 
|---|
| 2563 | int totalMargin = 0; | 
|---|
| 2564 | while (w) { | 
|---|
| 2565 | //honor fixed width parents | 
|---|
| 2566 | if (w->maximumWidth() == w->minimumWidth()) | 
|---|
| 2567 | toolBarMaxWidth = qMax(toolBarMaxWidth, w->maximumWidth()); | 
|---|
| 2568 | if (w->layout() && w->windowType() == Qt::Widget) { | 
|---|
| 2569 | totalMargin += w->layout()->contentsMargins().left() + | 
|---|
| 2570 | w->layout()->contentsMargins().right(); | 
|---|
| 2571 | } | 
|---|
| 2572 | w = w->parentWidget(); | 
|---|
| 2573 | } | 
|---|
| 2574 | totalMargin += 2 * pixelMetric(QStyle::PM_ToolBarFrameWidth); | 
|---|
| 2575 |  | 
|---|
| 2576 | if (toolBarMaxWidth == 0) | 
|---|
| 2577 | toolBarMaxWidth = | 
|---|
| 2578 | QApplication::desktop()->availableGeometry(widget->parentWidget()).width(); | 
|---|
| 2579 | //Reduce the margins, toolbar frame, item spacing and internal margin from available area | 
|---|
| 2580 | toolBarMaxWidth -= totalMargin; | 
|---|
| 2581 |  | 
|---|
| 2582 | //ensure that buttons are side-by-side and not on top of each other | 
|---|
| 2583 | const int toolButtonWidth = (toolBarMaxWidth / visibleButtons) | 
|---|
| 2584 | - pixelMetric(QStyle::PM_ToolBarItemSpacing) | 
|---|
| 2585 | - pixelMetric(QStyle::PM_ToolBarItemMargin) | 
|---|
| 2586 | //toolbar frame needs to be reduced again, since QToolBarLayout adds it for each toolbar action | 
|---|
| 2587 | - 2 * pixelMetric(QStyle::PM_ToolBarFrameWidth) - 1; | 
|---|
| 2588 | sz.setWidth(qMax(toolButtonWidth, sz.width())); | 
|---|
| 2589 | } | 
|---|
| 2590 | } | 
|---|
| 2591 | } | 
|---|
| 2592 | break; | 
|---|
| 2593 | case CT_PushButton: | 
|---|
| 2594 | sz = QCommonStyle::sizeFromContents( ct, opt, csz, widget); | 
|---|
| 2595 | //FIXME properly - style should calculate the location of border frame-part | 
|---|
| 2596 | if (const QAbstractButton *buttonWidget = (qobject_cast<const QAbstractButton *>(widget)))  { | 
|---|
| 2597 | if (buttonWidget->isCheckable()) | 
|---|
| 2598 | sz += QSize(pixelMetric(PM_IndicatorWidth) + pixelMetric(PM_CheckBoxLabelSpacing), 0); | 
|---|
| 2599 | const int iconHeight = (!buttonWidget->icon().isNull()) ? buttonWidget->iconSize().height() : 0; | 
|---|
| 2600 | const int textHeight = (buttonWidget->text().length() > 0) ? | 
|---|
| 2601 | buttonWidget->fontMetrics().size(Qt::TextSingleLine, buttonWidget->text()).height() : opt->fontMetrics.height(); | 
|---|
| 2602 | const int decoratorHeight = (buttonWidget->isCheckable()) ? pixelMetric(PM_IndicatorHeight) : 0; | 
|---|
| 2603 |  | 
|---|
| 2604 | const int contentHeight = | 
|---|
| 2605 | qMax(qMax(iconHeight, decoratorHeight) + pixelMetric(PM_ButtonMargin), | 
|---|
| 2606 | textHeight + 2*pixelMetric(PM_ButtonMargin)); | 
|---|
| 2607 | sz.setHeight(qMax(sz.height(), contentHeight)); | 
|---|
| 2608 | sz += QSize(2 * pixelMetric(PM_ButtonMargin), 0); | 
|---|
| 2609 | } | 
|---|
| 2610 | break; | 
|---|
| 2611 | case CT_LineEdit: | 
|---|
| 2612 | if (const QStyleOptionFrame *f = qstyleoption_cast<const QStyleOptionFrame *>(opt)) | 
|---|
| 2613 | sz += QSize(2 * f->lineWidth, 4 * f->lineWidth); | 
|---|
| 2614 | break; | 
|---|
| 2615 | case CT_TabBarTab: { | 
|---|
| 2616 | const QSize naviPaneSize = QS60StylePrivate::naviPaneSize(); | 
|---|
| 2617 | sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget); | 
|---|
| 2618 | if (naviPaneSize.height() > sz.height()) | 
|---|
| 2619 | sz.setHeight(naviPaneSize.height()); | 
|---|
| 2620 | // Adjust beginning tabbar item size, if scrollbuttons are used. This is to ensure that the | 
|---|
| 2621 | // tabbar item content fits, since scrollbuttons are making beginning tabbar item smaller. | 
|---|
| 2622 | int scrollButtonSize = 0; | 
|---|
| 2623 | if (const QTabBar *tabBar = qobject_cast<const QTabBar *>(widget)) | 
|---|
| 2624 | scrollButtonSize = tabBar->usesScrollButtons() ? pixelMetric(PM_TabBarScrollButtonWidth) : 0; | 
|---|
| 2625 | if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) { | 
|---|
| 2626 | const bool verticalTabs = tab->shape == QTabBar::RoundedEast | 
|---|
| 2627 | || tab->shape == QTabBar::RoundedWest | 
|---|
| 2628 | || tab->shape == QTabBar::TriangularEast | 
|---|
| 2629 | || tab->shape == QTabBar::TriangularWest; | 
|---|
| 2630 | if (tab->position == QStyleOptionTab::Beginning) | 
|---|
| 2631 | sz += QSize(verticalTabs ? 0 : scrollButtonSize, !verticalTabs ? 0 : scrollButtonSize); | 
|---|
| 2632 | } | 
|---|
| 2633 | } | 
|---|
| 2634 | break; | 
|---|
| 2635 | case CT_MenuItem: | 
|---|
| 2636 | case CT_ItemViewItem: | 
|---|
| 2637 | if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) { | 
|---|
| 2638 | if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) { | 
|---|
| 2639 | sz = QSize(); | 
|---|
| 2640 | break; | 
|---|
| 2641 | } | 
|---|
| 2642 | } | 
|---|
| 2643 | sz = QCommonStyle::sizeFromContents( ct, opt, csz, widget); | 
|---|
| 2644 | //native items have small empty areas at the beginning and end of menu item | 
|---|
| 2645 | sz.setWidth(sz.width() + 2 * pixelMetric(PM_MenuHMargin) + 2 * QS60StylePrivate::pixelMetric(PM_FrameCornerWidth)); | 
|---|
| 2646 | if (QS60StylePrivate::isTouchSupported()) | 
|---|
| 2647 | //Make itemview easier to use in touch devices | 
|---|
| 2648 | //QCommonStyle does not adjust height with horizontal margin, it only adjusts width | 
|---|
| 2649 | sz.setHeight(sz.height() + 2 * pixelMetric(PM_FocusFrameVMargin) - 8); //QCommonstyle adds 8 to height that this style handles through PM values | 
|---|
| 2650 | break; | 
|---|
| 2651 | #ifndef QT_NO_COMBOBOX | 
|---|
| 2652 | case CT_ComboBox: { | 
|---|
| 2653 | // Fixing Ui design issues with too wide QComboBoxes and greedy SizeHints | 
|---|
| 2654 | // Make sure, that the combobox stays within the screen. | 
|---|
| 2655 | const QSize desktopContentSize = QApplication::desktop()->availableGeometry().size() | 
|---|
| 2656 | - QSize(pixelMetric(PM_LayoutLeftMargin) + pixelMetric(PM_LayoutRightMargin), 0); | 
|---|
| 2657 | sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget). | 
|---|
| 2658 | boundedTo(desktopContentSize); | 
|---|
| 2659 | } | 
|---|
| 2660 | break; | 
|---|
| 2661 | #endif | 
|---|
| 2662 | default: | 
|---|
| 2663 | sz = QCommonStyle::sizeFromContents( ct, opt, csz, widget); | 
|---|
| 2664 | break; | 
|---|
| 2665 | } | 
|---|
| 2666 | if (!sz.isValid()) | 
|---|
| 2667 | sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget); | 
|---|
| 2668 | return sz; | 
|---|
| 2669 | } | 
|---|
| 2670 |  | 
|---|
| 2671 | /*! \reimp */ | 
|---|
| 2672 | int QS60Style::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *widget, | 
|---|
| 2673 | QStyleHintReturn *hret) const | 
|---|
| 2674 | { | 
|---|
| 2675 | int retValue = 0; | 
|---|
| 2676 | switch (sh) { | 
|---|
| 2677 | case SH_RequestSoftwareInputPanel: | 
|---|
| 2678 | if (QS60StylePrivate::isSingleClickUi()) | 
|---|
| 2679 | retValue = RSIP_OnMouseClick; | 
|---|
| 2680 | else | 
|---|
| 2681 | retValue = RSIP_OnMouseClickAndAlreadyFocused; | 
|---|
| 2682 | break; | 
|---|
| 2683 | case SH_ComboBox_Popup: | 
|---|
| 2684 | retValue = true; | 
|---|
| 2685 | break; | 
|---|
| 2686 | case SH_Table_GridLineColor: | 
|---|
| 2687 | retValue = int(QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnLineColors, 2, 0).rgba()); | 
|---|
| 2688 | break; | 
|---|
| 2689 | case SH_GroupBox_TextLabelColor: | 
|---|
| 2690 | retValue = int(QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnTextColors, 6, 0).rgba()); | 
|---|
| 2691 | break; | 
|---|
| 2692 | case SH_ScrollBar_ScrollWhenPointerLeavesControl: | 
|---|
| 2693 | retValue = true; | 
|---|
| 2694 | break; | 
|---|
| 2695 | case SH_Slider_SnapToValue: | 
|---|
| 2696 | retValue = true; | 
|---|
| 2697 | break; | 
|---|
| 2698 | case SH_Slider_StopMouseOverSlider: | 
|---|
| 2699 | retValue = true; | 
|---|
| 2700 | break; | 
|---|
| 2701 | case SH_LineEdit_PasswordCharacter: | 
|---|
| 2702 | retValue = '*'; | 
|---|
| 2703 | break; | 
|---|
| 2704 | case SH_ComboBox_PopupFrameStyle: | 
|---|
| 2705 | retValue = QFrame::NoFrame | QFrame::Plain; | 
|---|
| 2706 | break; | 
|---|
| 2707 | case SH_Dial_BackgroundRole: | 
|---|
| 2708 | retValue = QPalette::Base; | 
|---|
| 2709 | break; | 
|---|
| 2710 | case SH_ItemView_ActivateItemOnSingleClick: { | 
|---|
| 2711 | if (QS60StylePrivate::isSingleClickUi()) | 
|---|
| 2712 | retValue = true; | 
|---|
| 2713 | else if (opt && opt->state & QStyle::State_Selected) | 
|---|
| 2714 | retValue = true; | 
|---|
| 2715 | break; | 
|---|
| 2716 | } | 
|---|
| 2717 | case SH_ProgressDialog_TextLabelAlignment: | 
|---|
| 2718 | retValue = (QApplication::layoutDirection() == Qt::LeftToRight) ? | 
|---|
| 2719 | Qt::AlignLeft : | 
|---|
| 2720 | Qt::AlignRight; | 
|---|
| 2721 | break; | 
|---|
| 2722 | case SH_Menu_SubMenuPopupDelay: | 
|---|
| 2723 | retValue = 300; | 
|---|
| 2724 | break; | 
|---|
| 2725 | case SH_Menu_Scrollable: | 
|---|
| 2726 | retValue = true; | 
|---|
| 2727 | break; | 
|---|
| 2728 | case SH_Menu_SelectionWrap: | 
|---|
| 2729 | retValue = true; | 
|---|
| 2730 | break; | 
|---|
| 2731 | case SH_Menu_MouseTracking: | 
|---|
| 2732 | retValue = true; | 
|---|
| 2733 | break; | 
|---|
| 2734 | case SH_ItemView_ShowDecorationSelected: | 
|---|
| 2735 | retValue = true; | 
|---|
| 2736 | break; | 
|---|
| 2737 | case SH_ToolBar_Movable: | 
|---|
| 2738 | retValue = false; | 
|---|
| 2739 | break; | 
|---|
| 2740 | case SH_BlinkCursorWhenTextSelected: | 
|---|
| 2741 | retValue = true; | 
|---|
| 2742 | break; | 
|---|
| 2743 | case SH_UnderlineShortcut: | 
|---|
| 2744 | retValue = 0; | 
|---|
| 2745 | break; | 
|---|
| 2746 | case SH_FormLayoutWrapPolicy: | 
|---|
| 2747 | retValue = QFormLayout::WrapLongRows; | 
|---|
| 2748 | break; | 
|---|
| 2749 | case SH_ScrollBar_ContextMenu: | 
|---|
| 2750 | retValue = false; | 
|---|
| 2751 | break; | 
|---|
| 2752 | default: | 
|---|
| 2753 | retValue = QCommonStyle::styleHint(sh, opt, widget, hret); | 
|---|
| 2754 | break; | 
|---|
| 2755 | } | 
|---|
| 2756 | return retValue; | 
|---|
| 2757 | } | 
|---|
| 2758 |  | 
|---|
| 2759 | /*! \reimp */ | 
|---|
| 2760 | QRect QS60Style::subControlRect(ComplexControl control, const QStyleOptionComplex *option, SubControl scontrol, const QWidget *widget) const | 
|---|
| 2761 | { | 
|---|
| 2762 | QRect ret; | 
|---|
| 2763 | switch (control) { | 
|---|
| 2764 | #ifndef QT_NO_SCROLLBAR | 
|---|
| 2765 | // This implementation of subControlRect(CC_ScrollBar..) basically just removes the SC_ScrollBarSubLine and SC_ScrollBarAddLine | 
|---|
| 2766 | case CC_ScrollBar: | 
|---|
| 2767 | if (const QStyleOptionSlider *scrollbarOption = qstyleoption_cast<const QStyleOptionSlider *>(option)) { | 
|---|
| 2768 | const QRect scrollBarRect = scrollbarOption->rect; | 
|---|
| 2769 | const bool isHorizontal = scrollbarOption->orientation == Qt::Horizontal; | 
|---|
| 2770 | const int maxlen = isHorizontal ? scrollBarRect.width() : scrollBarRect.height(); | 
|---|
| 2771 | int sliderlen; | 
|---|
| 2772 |  | 
|---|
| 2773 | // calculate slider length | 
|---|
| 2774 | if (scrollbarOption->maximum != scrollbarOption->minimum) { | 
|---|
| 2775 | const uint range = scrollbarOption->maximum - scrollbarOption->minimum; | 
|---|
| 2776 | sliderlen = (qint64(scrollbarOption->pageStep) * maxlen) / (range + scrollbarOption->pageStep); | 
|---|
| 2777 |  | 
|---|
| 2778 | const int slidermin = pixelMetric(PM_ScrollBarSliderMin, scrollbarOption, widget); | 
|---|
| 2779 | if (sliderlen < slidermin || range > (INT_MAX >> 1)) | 
|---|
| 2780 | sliderlen = slidermin; | 
|---|
| 2781 | if (sliderlen > maxlen) | 
|---|
| 2782 | sliderlen = maxlen; | 
|---|
| 2783 | } else { | 
|---|
| 2784 | sliderlen = maxlen; | 
|---|
| 2785 | } | 
|---|
| 2786 |  | 
|---|
| 2787 | const int sliderstart = sliderPositionFromValue(scrollbarOption->minimum, | 
|---|
| 2788 | scrollbarOption->maximum, | 
|---|
| 2789 | scrollbarOption->sliderPosition, | 
|---|
| 2790 | maxlen - sliderlen, | 
|---|
| 2791 | scrollbarOption->upsideDown); | 
|---|
| 2792 |  | 
|---|
| 2793 | switch (scontrol) { | 
|---|
| 2794 | case SC_ScrollBarSubPage:            // between top/left button and slider | 
|---|
| 2795 | if (isHorizontal) | 
|---|
| 2796 | ret.setRect(0, 0, sliderstart, scrollBarRect.height()); | 
|---|
| 2797 | else | 
|---|
| 2798 | ret.setRect(0, 0, scrollBarRect.width(), sliderstart); | 
|---|
| 2799 | break; | 
|---|
| 2800 | case SC_ScrollBarAddPage: {         // between bottom/right button and slider | 
|---|
| 2801 | const int addPageLength = sliderstart + sliderlen; | 
|---|
| 2802 | if (isHorizontal) | 
|---|
| 2803 | ret = scrollBarRect.adjusted(addPageLength, 0, 0, 0); | 
|---|
| 2804 | else | 
|---|
| 2805 | ret = scrollBarRect.adjusted(0, addPageLength, 0, 0); | 
|---|
| 2806 | } | 
|---|
| 2807 | break; | 
|---|
| 2808 | case SC_ScrollBarGroove: | 
|---|
| 2809 | ret = scrollBarRect; | 
|---|
| 2810 | break; | 
|---|
| 2811 | case SC_ScrollBarSlider: | 
|---|
| 2812 | if (scrollbarOption->orientation == Qt::Horizontal) | 
|---|
| 2813 | ret.setRect(sliderstart, 0, sliderlen, scrollBarRect.height()); | 
|---|
| 2814 | else | 
|---|
| 2815 | ret.setRect(0, sliderstart, scrollBarRect.width(), sliderlen); | 
|---|
| 2816 | break; | 
|---|
| 2817 | case SC_ScrollBarSubLine:            // top/left button | 
|---|
| 2818 | case SC_ScrollBarAddLine:            // bottom/right button | 
|---|
| 2819 | default: | 
|---|
| 2820 | break; | 
|---|
| 2821 | } | 
|---|
| 2822 | ret = visualRect(scrollbarOption->direction, scrollBarRect, ret); | 
|---|
| 2823 | } | 
|---|
| 2824 | break; | 
|---|
| 2825 | #endif // QT_NO_SCROLLBAR | 
|---|
| 2826 | case CC_SpinBox: | 
|---|
| 2827 | if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) { | 
|---|
| 2828 | const int frameThickness = spinbox->frame ? pixelMetric(PM_SpinBoxFrameWidth, spinbox, widget) : 0; | 
|---|
| 2829 | const int buttonMargin = spinbox->frame ? 2 : 0; | 
|---|
| 2830 | const int buttonContentWidth = QS60StylePrivate::pixelMetric(PM_ButtonIconSize) + 2 * buttonMargin; | 
|---|
| 2831 | // Spinbox buttons should be no larger than one fourth of total width. | 
|---|
| 2832 | // Thus, side-by-side buttons would take half of the total width. | 
|---|
| 2833 | const int maxSize = qMax(spinbox->rect.width() / 4, buttonContentWidth); | 
|---|
| 2834 | QSize buttonSize; | 
|---|
| 2835 | buttonSize.setHeight(qMin(maxSize, qMax(8, spinbox->rect.height() - frameThickness))); | 
|---|
| 2836 | //width should at least be equal to height | 
|---|
| 2837 | buttonSize.setWidth(qMax(buttonSize.height(), buttonContentWidth)); | 
|---|
| 2838 | buttonSize = buttonSize.expandedTo(QApplication::globalStrut()); | 
|---|
| 2839 |  | 
|---|
| 2840 | // Normally spinbuttons should be side-by-side, but if spinbox grows very big | 
|---|
| 2841 | // and spinbuttons reach their maximum size, they can be deployed one top of the other. | 
|---|
| 2842 | const bool sideBySide = (buttonSize.height() * 2 < spinbox->rect.height()) ? false : true; | 
|---|
| 2843 | const int y = frameThickness + spinbox->rect.y() + | 
|---|
| 2844 | (spinbox->rect.height() - (sideBySide ? 1 : 2) * buttonSize.height()) / 2; | 
|---|
| 2845 | const int x = spinbox->rect.x() + | 
|---|
| 2846 | spinbox->rect.width() - frameThickness - (sideBySide ? 2 : 1) * buttonSize.width(); | 
|---|
| 2847 |  | 
|---|
| 2848 | switch (scontrol) { | 
|---|
| 2849 | case SC_SpinBoxUp: | 
|---|
| 2850 | if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons) | 
|---|
| 2851 | return QRect(); | 
|---|
| 2852 | ret = QRect(x, y, buttonSize.width(), buttonSize.height()); | 
|---|
| 2853 | break; | 
|---|
| 2854 | case SC_SpinBoxDown: | 
|---|
| 2855 | if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons) | 
|---|
| 2856 | return QRect(); | 
|---|
| 2857 | ret = QRect(x + (sideBySide ? buttonSize.width() : 0), | 
|---|
| 2858 | y + (sideBySide ? 0 : buttonSize.height()), | 
|---|
| 2859 | buttonSize.width(), buttonSize.height()); | 
|---|
| 2860 | break; | 
|---|
| 2861 | case SC_SpinBoxEditField: | 
|---|
| 2862 | if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons) | 
|---|
| 2863 | ret = QRect( | 
|---|
| 2864 | frameThickness, | 
|---|
| 2865 | frameThickness, | 
|---|
| 2866 | spinbox->rect.width() - 2 * frameThickness, | 
|---|
| 2867 | spinbox->rect.height() - 2 * frameThickness); | 
|---|
| 2868 | else | 
|---|
| 2869 | ret = QRect( | 
|---|
| 2870 | frameThickness, | 
|---|
| 2871 | frameThickness, | 
|---|
| 2872 | x - frameThickness, | 
|---|
| 2873 | spinbox->rect.height() - 2 * frameThickness); | 
|---|
| 2874 | break; | 
|---|
| 2875 | case SC_SpinBoxFrame: | 
|---|
| 2876 | ret = spinbox->rect; | 
|---|
| 2877 | break; | 
|---|
| 2878 | default: | 
|---|
| 2879 | break; | 
|---|
| 2880 | } | 
|---|
| 2881 | ret = visualRect(spinbox->direction, spinbox->rect, ret); | 
|---|
| 2882 | } | 
|---|
| 2883 | break; | 
|---|
| 2884 | case CC_ComboBox: | 
|---|
| 2885 | if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) { | 
|---|
| 2886 | ret = cmb->rect; | 
|---|
| 2887 | const int width = cmb->rect.width(); | 
|---|
| 2888 | const int height = cmb->rect.height(); | 
|---|
| 2889 | const int buttonMargin = cmb->frame ? 2 : 0; | 
|---|
| 2890 | // lets use spinbox frame here as well, as no combobox specific value available. | 
|---|
| 2891 | const int frameThickness = cmb->frame ? pixelMetric(PM_SpinBoxFrameWidth, cmb, widget) : 0; | 
|---|
| 2892 | const int buttonMinSize = QS60StylePrivate::pixelMetric(PM_ButtonIconSize) + 2 * buttonMargin; | 
|---|
| 2893 | QSize buttonSize; | 
|---|
| 2894 | //allow button to grow to one fourth of the frame height, if the frame is really tall | 
|---|
| 2895 | buttonSize.setHeight(qMin(height, qMax(width / 4, buttonMinSize))); | 
|---|
| 2896 | buttonSize.setWidth(buttonSize.height()); | 
|---|
| 2897 | buttonSize = buttonSize.expandedTo(QApplication::globalStrut()); | 
|---|
| 2898 | switch (scontrol) { | 
|---|
| 2899 | case SC_ComboBoxArrow: { | 
|---|
| 2900 | const int xposMod = cmb->rect.x() + width - buttonMargin - buttonSize.width(); | 
|---|
| 2901 | const int ypos = cmb->rect.y(); | 
|---|
| 2902 | ret.setRect(xposMod, ypos + buttonMargin, buttonSize.width(), height - 2 * buttonMargin); | 
|---|
| 2903 | } | 
|---|
| 2904 | break; | 
|---|
| 2905 | case SC_ComboBoxEditField: { | 
|---|
| 2906 | ret = QRect(0, 0, cmb->rect.x() + width - buttonSize.width(), height); | 
|---|
| 2907 | } | 
|---|
| 2908 | break; | 
|---|
| 2909 | case SC_ComboBoxListBoxPopup: { | 
|---|
| 2910 | ret = QApplication::desktop()->availableGeometry(); | 
|---|
| 2911 | } | 
|---|
| 2912 | break; | 
|---|
| 2913 | default: | 
|---|
| 2914 | break; | 
|---|
| 2915 | } | 
|---|
| 2916 | ret = visualRect(cmb->direction, cmb->rect, ret); | 
|---|
| 2917 | } | 
|---|
| 2918 | break; | 
|---|
| 2919 | case CC_GroupBox: | 
|---|
| 2920 | if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) { | 
|---|
| 2921 | ret = QCommonStyle::subControlRect(control, option, scontrol, widget); | 
|---|
| 2922 | switch (scontrol) { | 
|---|
| 2923 | case SC_GroupBoxCheckBox: //fallthrough | 
|---|
| 2924 | case SC_GroupBoxLabel: { | 
|---|
| 2925 | //slightly indent text and boxes, so that dialog border does not mess with them. | 
|---|
| 2926 | const int horizontalSpacing = | 
|---|
| 2927 | QS60StylePrivate::pixelMetric(PM_LayoutHorizontalSpacing); | 
|---|
| 2928 | ret.adjust(2, horizontalSpacing - 3, 0, 0); | 
|---|
| 2929 | } | 
|---|
| 2930 | break; | 
|---|
| 2931 | case SC_GroupBoxFrame: { | 
|---|
| 2932 | const QRect textBox = subControlRect(control, option, SC_GroupBoxLabel, widget); | 
|---|
| 2933 | const int tbHeight = textBox.height(); | 
|---|
| 2934 | ret.translate(0, -ret.y()); | 
|---|
| 2935 | // include title to within the groupBox frame | 
|---|
| 2936 | ret.setHeight(ret.height() + tbHeight); | 
|---|
| 2937 | if (widget && ret.bottom() > widget->rect().bottom()) | 
|---|
| 2938 | ret.setBottom(widget->rect().bottom()); | 
|---|
| 2939 | } | 
|---|
| 2940 | break; | 
|---|
| 2941 | default: | 
|---|
| 2942 | break; | 
|---|
| 2943 | } | 
|---|
| 2944 | } | 
|---|
| 2945 | break; | 
|---|
| 2946 | case CC_ToolButton: | 
|---|
| 2947 | if (const QStyleOptionToolButton *toolButton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) { | 
|---|
| 2948 | const int indicatorRect = pixelMetric(PM_MenuButtonIndicator) + 2 * pixelMetric(PM_ButtonMargin); | 
|---|
| 2949 | const int border = pixelMetric(PM_ButtonMargin) + pixelMetric(PM_DefaultFrameWidth); | 
|---|
| 2950 | ret = toolButton->rect; | 
|---|
| 2951 | const bool popup = (toolButton->features & | 
|---|
| 2952 | (QStyleOptionToolButton::MenuButtonPopup | QStyleOptionToolButton::PopupDelay)) | 
|---|
| 2953 | == QStyleOptionToolButton::MenuButtonPopup; | 
|---|
| 2954 | switch (scontrol) { | 
|---|
| 2955 | case SC_ToolButton: | 
|---|
| 2956 | if (popup) | 
|---|
| 2957 | ret.adjust(0, 0, -indicatorRect, 0); | 
|---|
| 2958 | break; | 
|---|
| 2959 | case SC_ToolButtonMenu: | 
|---|
| 2960 | if (popup) | 
|---|
| 2961 | ret.adjust(ret.width() - indicatorRect, border, -pixelMetric(PM_ButtonMargin), -border); | 
|---|
| 2962 | break; | 
|---|
| 2963 | default: | 
|---|
| 2964 | break; | 
|---|
| 2965 | } | 
|---|
| 2966 | ret = visualRect(toolButton->direction, toolButton->rect, ret); | 
|---|
| 2967 | } | 
|---|
| 2968 | break; | 
|---|
| 2969 | default: | 
|---|
| 2970 | ret = QCommonStyle::subControlRect(control, option, scontrol, widget); | 
|---|
| 2971 | } | 
|---|
| 2972 | return ret; | 
|---|
| 2973 | } | 
|---|
| 2974 |  | 
|---|
| 2975 | /*! | 
|---|
| 2976 | \reimp | 
|---|
| 2977 | */ | 
|---|
| 2978 | QRect QS60Style::subElementRect(SubElement element, const QStyleOption *opt, const QWidget *widget) const | 
|---|
| 2979 | { | 
|---|
| 2980 | QRect ret; | 
|---|
| 2981 | switch (element) { | 
|---|
| 2982 | case SE_RadioButtonFocusRect: | 
|---|
| 2983 | ret = opt->rect; | 
|---|
| 2984 | break; | 
|---|
| 2985 | case SE_LineEditContents: { | 
|---|
| 2986 | // in S60 the input text box doesn't start from line Edit's TL, but | 
|---|
| 2987 | // a bit indented (8 pixels). | 
|---|
| 2988 | const int KLineEditDefaultIndention = 8; | 
|---|
| 2989 | ret = visualRect( | 
|---|
| 2990 | opt->direction, opt->rect, opt->rect.adjusted(KLineEditDefaultIndention, 0, 0, 0)); | 
|---|
| 2991 | } | 
|---|
| 2992 | break; | 
|---|
| 2993 | case SE_TabBarTearIndicator: | 
|---|
| 2994 | ret = QRect(0, 0, 0, 0); | 
|---|
| 2995 | break; | 
|---|
| 2996 | case SE_TabWidgetTabBar: | 
|---|
| 2997 | if (const QStyleOptionTabWidgetFrame *optionTab = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) { | 
|---|
| 2998 | ret = QCommonStyle::subElementRect(element, opt, widget); | 
|---|
| 2999 |  | 
|---|
| 3000 | if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) { | 
|---|
| 3001 | const int tabOverlapNoBorder = | 
|---|
| 3002 | QS60StylePrivate::pixelMetric(PM_TabBarTabOverlap); | 
|---|
| 3003 | const int tabOverlap = | 
|---|
| 3004 | tabOverlapNoBorder - QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth); | 
|---|
| 3005 | const QTabWidget *tab = qobject_cast<const QTabWidget *>(widget); | 
|---|
| 3006 | int gain = (tab) ? tabOverlap * tab->count() : 0; | 
|---|
| 3007 | switch (twf->shape) { | 
|---|
| 3008 | case QTabBar::RoundedNorth: | 
|---|
| 3009 | case QTabBar::TriangularNorth: | 
|---|
| 3010 | case QTabBar::RoundedSouth: | 
|---|
| 3011 | case QTabBar::TriangularSouth: { | 
|---|
| 3012 | if (widget) { | 
|---|
| 3013 | // make sure that gain does not set the rect outside of widget boundaries | 
|---|
| 3014 | if (twf->direction == Qt::RightToLeft) { | 
|---|
| 3015 | if ((ret.left() - gain) < widget->rect().left()) | 
|---|
| 3016 | gain = widget->rect().left() - ret.left(); | 
|---|
| 3017 | ret.adjust(-gain, 0, 0, 0); | 
|---|
| 3018 | } else { | 
|---|
| 3019 | if ((ret.right() + gain) > widget->rect().right()) | 
|---|
| 3020 | gain = widget->rect().right() - ret.right(); | 
|---|
| 3021 | ret.adjust(0, 0, gain, 0); | 
|---|
| 3022 | } | 
|---|
| 3023 | } | 
|---|
| 3024 | break; | 
|---|
| 3025 | } | 
|---|
| 3026 | default: { | 
|---|
| 3027 | if (widget) { | 
|---|
| 3028 | if ((ret.bottom() + gain) > widget->rect().bottom()) | 
|---|
| 3029 | gain = widget->rect().bottom() - ret.bottom(); | 
|---|
| 3030 | ret.adjust(0, 0, 0, gain); | 
|---|
| 3031 | } | 
|---|
| 3032 | break; | 
|---|
| 3033 | } | 
|---|
| 3034 | } | 
|---|
| 3035 | } | 
|---|
| 3036 | } | 
|---|
| 3037 | break; | 
|---|
| 3038 | case SE_ItemViewItemText: | 
|---|
| 3039 | case SE_ItemViewItemDecoration: | 
|---|
| 3040 | if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(opt)) { | 
|---|
| 3041 | const QAbstractItemView *listItem = qobject_cast<const QAbstractItemView *>(widget); | 
|---|
| 3042 | const bool multiSelection = !listItem ? false : | 
|---|
| 3043 | listItem->selectionMode() == QAbstractItemView::MultiSelection || | 
|---|
| 3044 | listItem->selectionMode() == QAbstractItemView::ExtendedSelection || | 
|---|
| 3045 | listItem->selectionMode() == QAbstractItemView::ContiguousSelection; | 
|---|
| 3046 | ret = QCommonStyle::subElementRect(element, opt, widget); | 
|---|
| 3047 | // If both multiselect & check-state, then remove checkbox and move | 
|---|
| 3048 | // text and decoration towards the beginning | 
|---|
| 3049 | if (listItem && | 
|---|
| 3050 | multiSelection && | 
|---|
| 3051 | (vopt->features & QStyleOptionViewItemV2::HasCheckIndicator)) { | 
|---|
| 3052 | const int verticalSpacing = | 
|---|
| 3053 | QS60StylePrivate::pixelMetric(PM_LayoutVerticalSpacing); | 
|---|
| 3054 | //const int horizontalSpacing = QS60StylePrivate::pixelMetric(PM_LayoutHorizontalSpacing); | 
|---|
| 3055 | const int checkBoxRectWidth = subElementRect(SE_ItemViewItemCheckIndicator, opt, widget).width(); | 
|---|
| 3056 | ret.adjust(-checkBoxRectWidth - verticalSpacing, 0, -checkBoxRectWidth - verticalSpacing, 0); | 
|---|
| 3057 | } | 
|---|
| 3058 | } else if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) { | 
|---|
| 3059 | const bool checkable = menuItem->checkType != QStyleOptionMenuItem::NotCheckable; | 
|---|
| 3060 | const int indicatorWidth = checkable ? | 
|---|
| 3061 | pixelMetric(PM_ListViewIconSize, opt, widget) : | 
|---|
| 3062 | pixelMetric(PM_SmallIconSize, opt, widget); | 
|---|
| 3063 | ret = menuItem->rect; | 
|---|
| 3064 |  | 
|---|
| 3065 | QRect checkBoxRect = checkable ? menuItem->rect : QRect(); | 
|---|
| 3066 | if (checkable) { | 
|---|
| 3067 | checkBoxRect.setWidth(pixelMetric(PM_IndicatorWidth)); | 
|---|
| 3068 | checkBoxRect.setHeight(pixelMetric(PM_IndicatorHeight)); | 
|---|
| 3069 | } | 
|---|
| 3070 |  | 
|---|
| 3071 | const int vSpacing = QS60StylePrivate::pixelMetric(PM_LayoutVerticalSpacing); | 
|---|
| 3072 | //The vertical spacing is doubled; it needs one spacing to separate checkbox from | 
|---|
| 3073 | //highlight and then it needs one to separate it whatever is shown after it (text/icon/both). | 
|---|
| 3074 | const int moveByX = checkBoxRect.width() + 2 * vSpacing; | 
|---|
| 3075 |  | 
|---|
| 3076 | if (element == SE_ItemViewItemDecoration) { | 
|---|
| 3077 | if (menuItem->icon.isNull()) { | 
|---|
| 3078 | ret = QRect(); | 
|---|
| 3079 | } else { | 
|---|
| 3080 | if (menuItem->direction == Qt::RightToLeft) | 
|---|
| 3081 | ret.translate(ret.width() - indicatorWidth - moveByX, 0); | 
|---|
| 3082 | else | 
|---|
| 3083 | ret.translate(moveByX, 0); | 
|---|
| 3084 | ret.setWidth(indicatorWidth); | 
|---|
| 3085 | } | 
|---|
| 3086 | } else { | 
|---|
| 3087 | if (!menuItem->icon.isNull()) { | 
|---|
| 3088 | if (menuItem->direction == Qt::LeftToRight) | 
|---|
| 3089 | ret.adjust(indicatorWidth, 0, 0, 0); | 
|---|
| 3090 | else | 
|---|
| 3091 | ret.adjust(0, 0, -indicatorWidth, 0); | 
|---|
| 3092 | } | 
|---|
| 3093 | if (menuItem->direction == Qt::LeftToRight) | 
|---|
| 3094 | ret.adjust(moveByX, 0, 0, 0); | 
|---|
| 3095 | else | 
|---|
| 3096 | ret.adjust(0, 0, -moveByX, 0); | 
|---|
| 3097 |  | 
|---|
| 3098 | // Make room for submenu indicator | 
|---|
| 3099 | if (menuItem->menuItemType == QStyleOptionMenuItem::SubMenu){ | 
|---|
| 3100 | // submenu indicator is very small, so lets halve the rect | 
|---|
| 3101 | if (menuItem->direction == Qt::LeftToRight) | 
|---|
| 3102 | ret.adjust(0, 0, -(indicatorWidth >> 1), 0); | 
|---|
| 3103 | else | 
|---|
| 3104 | ret.adjust((indicatorWidth >> 1), 0, 0, 0); | 
|---|
| 3105 | } | 
|---|
| 3106 | } | 
|---|
| 3107 | } | 
|---|
| 3108 | break; | 
|---|
| 3109 | case SE_ItemViewItemCheckIndicator: | 
|---|
| 3110 | if (const QStyleOptionViewItemV2 *vopt = qstyleoption_cast<const QStyleOptionViewItemV2 *>(opt)) { | 
|---|
| 3111 | const QAbstractItemView *listItem = qobject_cast<const QAbstractItemView *>(widget); | 
|---|
| 3112 |  | 
|---|
| 3113 | const bool singleSelection = listItem && | 
|---|
| 3114 | (listItem->selectionMode() == QAbstractItemView::SingleSelection || | 
|---|
| 3115 | listItem->selectionMode() == QAbstractItemView::NoSelection); | 
|---|
| 3116 | const bool checkBoxOnly = (vopt->features & QStyleOptionViewItemV2::HasCheckIndicator) && | 
|---|
| 3117 | listItem && | 
|---|
| 3118 | singleSelection; | 
|---|
| 3119 |  | 
|---|
| 3120 | // Selection check mark rect. | 
|---|
| 3121 | const int indicatorWidth = QS60StylePrivate::pixelMetric(PM_IndicatorWidth); | 
|---|
| 3122 | const int indicatorHeight = QS60StylePrivate::pixelMetric(PM_IndicatorHeight); | 
|---|
| 3123 | const int spacing = QS60StylePrivate::pixelMetric(PM_CheckBoxLabelSpacing); | 
|---|
| 3124 |  | 
|---|
| 3125 | const int itemHeight = opt->rect.height(); | 
|---|
| 3126 | int heightOffset = 0; | 
|---|
| 3127 | if (indicatorHeight < itemHeight) | 
|---|
| 3128 | heightOffset = ((itemHeight - indicatorHeight) >> 1); | 
|---|
| 3129 | if (checkBoxOnly) { | 
|---|
| 3130 | // Move rect and make it slightly smaller, so that | 
|---|
| 3131 | // a) highlight border does not cross the rect | 
|---|
| 3132 | // b) in s60 list checkbox is smaller than normal checkbox | 
|---|
| 3133 | //todo; magic three | 
|---|
| 3134 | ret.setRect(opt->rect.left() + 3, opt->rect.top() + heightOffset, | 
|---|
| 3135 | indicatorWidth - 3, indicatorHeight - 3); | 
|---|
| 3136 | } else { | 
|---|
| 3137 | ret.setRect(opt->rect.right() - indicatorWidth - spacing, opt->rect.top() + heightOffset, | 
|---|
| 3138 | indicatorWidth, indicatorHeight); | 
|---|
| 3139 | } | 
|---|
| 3140 | } else  { | 
|---|
| 3141 | ret = QCommonStyle::subElementRect(element, opt, widget); | 
|---|
| 3142 | } | 
|---|
| 3143 | break; | 
|---|
| 3144 | case SE_HeaderLabel: | 
|---|
| 3145 | ret = QCommonStyle::subElementRect(element, opt, widget); | 
|---|
| 3146 | if (qstyleoption_cast<const QStyleOptionHeader *>(opt)) { | 
|---|
| 3147 | // Subtract area needed for line | 
|---|
| 3148 | if (opt->state & State_Horizontal) | 
|---|
| 3149 | ret.setHeight(ret.height() - QS60StylePrivate::pixelMetric(PM_BoldLineWidth)); | 
|---|
| 3150 | else | 
|---|
| 3151 | ret.setWidth(ret.width() - QS60StylePrivate::pixelMetric(PM_ThinLineWidth)); | 
|---|
| 3152 | } | 
|---|
| 3153 | ret = visualRect(opt->direction, opt->rect, ret); | 
|---|
| 3154 | break; | 
|---|
| 3155 | case SE_RadioButtonIndicator: { | 
|---|
| 3156 | const int height = pixelMetric(PM_ExclusiveIndicatorHeight, opt, widget); | 
|---|
| 3157 | ret.setRect(opt->rect.x(), opt->rect.y() + ((opt->rect.height() - height) >> 1), | 
|---|
| 3158 | pixelMetric(PM_ExclusiveIndicatorWidth, opt, widget), height); | 
|---|
| 3159 | ret.translate(2, 0); //move indicator slightly to avoid highlight crossing over it | 
|---|
| 3160 | ret = visualRect(opt->direction, opt->rect, ret); | 
|---|
| 3161 | } | 
|---|
| 3162 | break; | 
|---|
| 3163 | case SE_CheckBoxIndicator: { | 
|---|
| 3164 | const int height = pixelMetric(PM_IndicatorHeight, opt, widget); | 
|---|
| 3165 | ret.setRect(opt->rect.x(), opt->rect.y() + ((opt->rect.height() - height) >> 1), | 
|---|
| 3166 | pixelMetric(PM_IndicatorWidth, opt, widget), height); | 
|---|
| 3167 | ret.translate(2, 0); //move indicator slightly to avoid highlight crossing over it | 
|---|
| 3168 | ret = visualRect(opt->direction, opt->rect, ret); | 
|---|
| 3169 | } | 
|---|
| 3170 | break; | 
|---|
| 3171 | case SE_CheckBoxFocusRect: | 
|---|
| 3172 | ret = opt->rect; | 
|---|
| 3173 | break; | 
|---|
| 3174 | case SE_ProgressBarLabel: | 
|---|
| 3175 | case SE_ProgressBarContents: | 
|---|
| 3176 | case SE_ProgressBarGroove: | 
|---|
| 3177 | ret = opt->rect; | 
|---|
| 3178 | break; | 
|---|
| 3179 | default: | 
|---|
| 3180 | ret = QCommonStyle::subElementRect(element, opt, widget); | 
|---|
| 3181 | } | 
|---|
| 3182 | return ret; | 
|---|
| 3183 | } | 
|---|
| 3184 |  | 
|---|
| 3185 | /*! | 
|---|
| 3186 | \reimp | 
|---|
| 3187 | */ | 
|---|
| 3188 | void QS60Style::polish(QWidget *widget) | 
|---|
| 3189 | { | 
|---|
| 3190 | Q_D(const QS60Style); | 
|---|
| 3191 | QCommonStyle::polish(widget); | 
|---|
| 3192 |  | 
|---|
| 3193 | if (!widget) | 
|---|
| 3194 | return; | 
|---|
| 3195 |  | 
|---|
| 3196 | //Currently we only support animations in QProgressBar. | 
|---|
| 3197 | #ifndef QT_NO_PROGRESSBAR | 
|---|
| 3198 | if (qobject_cast<QProgressBar *>(widget)) | 
|---|
| 3199 | widget->installEventFilter(this); | 
|---|
| 3200 | #endif | 
|---|
| 3201 |  | 
|---|
| 3202 | if (false | 
|---|
| 3203 | #ifndef QT_NO_SCROLLBAR | 
|---|
| 3204 | || qobject_cast<QScrollBar *>(widget) | 
|---|
| 3205 | #endif | 
|---|
| 3206 | ) { | 
|---|
| 3207 | widget->setAttribute(Qt::WA_OpaquePaintEvent, false); | 
|---|
| 3208 | } | 
|---|
| 3209 |  | 
|---|
| 3210 | if (QS60StylePrivate::drawsOwnThemeBackground(widget)) { | 
|---|
| 3211 | widget->setAttribute(Qt::WA_StyledBackground); | 
|---|
| 3212 | } else if (false | 
|---|
| 3213 | #ifndef QT_NO_MENU | 
|---|
| 3214 | || qobject_cast<const QMenu *> (widget) | 
|---|
| 3215 | #endif // QT_NO_MENU | 
|---|
| 3216 | ) { | 
|---|
| 3217 | widget->setAttribute(Qt::WA_StyledBackground); | 
|---|
| 3218 | } else if (false | 
|---|
| 3219 | #ifndef QT_NO_COMBOBOX | 
|---|
| 3220 | || qobject_cast<const QComboBoxListView *>(widget) | 
|---|
| 3221 | #endif //QT_NO_COMBOBOX | 
|---|
| 3222 | ) { | 
|---|
| 3223 | widget->setAttribute(Qt::WA_StyledBackground); | 
|---|
| 3224 | } | 
|---|
| 3225 | d->setThemePalette(widget); | 
|---|
| 3226 | d->setFont(widget); | 
|---|
| 3227 | } | 
|---|
| 3228 |  | 
|---|
| 3229 | /*! | 
|---|
| 3230 | \reimp | 
|---|
| 3231 | */ | 
|---|
| 3232 | void QS60Style::unpolish(QWidget *widget) | 
|---|
| 3233 | { | 
|---|
| 3234 | Q_D(QS60Style); | 
|---|
| 3235 |  | 
|---|
| 3236 | if (false | 
|---|
| 3237 | #ifndef QT_NO_SCROLLBAR | 
|---|
| 3238 | || qobject_cast<QScrollBar *>(widget) | 
|---|
| 3239 | #endif | 
|---|
| 3240 | ) | 
|---|
| 3241 | widget->setAttribute(Qt::WA_OpaquePaintEvent); | 
|---|
| 3242 |  | 
|---|
| 3243 | if (QS60StylePrivate::drawsOwnThemeBackground(widget)) { | 
|---|
| 3244 | widget->setAttribute(Qt::WA_StyledBackground, false); | 
|---|
| 3245 | } else if (false | 
|---|
| 3246 | #ifndef QT_NO_MENU | 
|---|
| 3247 | || qobject_cast<const QMenu *> (widget) | 
|---|
| 3248 | #endif // QT_NO_MENU | 
|---|
| 3249 | ) { | 
|---|
| 3250 | widget->setAttribute(Qt::WA_StyledBackground, false); | 
|---|
| 3251 | } else if (false | 
|---|
| 3252 | #ifndef QT_NO_COMBOBOX | 
|---|
| 3253 | || qobject_cast<const QComboBoxListView *>(widget) | 
|---|
| 3254 | #endif //QT_NO_COMBOBOX | 
|---|
| 3255 | ) { | 
|---|
| 3256 | widget->setAttribute(Qt::WA_StyledBackground, false); | 
|---|
| 3257 | } | 
|---|
| 3258 |  | 
|---|
| 3259 | if (widget) | 
|---|
| 3260 | widget->setPalette(QPalette()); | 
|---|
| 3261 |  | 
|---|
| 3262 | #if defined(Q_WS_S60) && !defined(QT_NO_PROGRESSBAR) | 
|---|
| 3263 | if (QProgressBar *bar = qobject_cast<QProgressBar *>(widget)) { | 
|---|
| 3264 | widget->removeEventFilter(this); | 
|---|
| 3265 | d->m_bars.removeAll(bar); | 
|---|
| 3266 | } | 
|---|
| 3267 | #else | 
|---|
| 3268 | Q_UNUSED(d) | 
|---|
| 3269 | #endif | 
|---|
| 3270 | QCommonStyle::unpolish(widget); | 
|---|
| 3271 | } | 
|---|
| 3272 |  | 
|---|
| 3273 | /*! | 
|---|
| 3274 | \reimp | 
|---|
| 3275 | */ | 
|---|
| 3276 | void QS60Style::polish(QApplication *application) | 
|---|
| 3277 | { | 
|---|
| 3278 | Q_D(QS60Style); | 
|---|
| 3279 | QCommonStyle::polish(qApp); | 
|---|
| 3280 | d->m_originalPalette = application->palette(); | 
|---|
| 3281 | d->setThemePalette(application); | 
|---|
| 3282 | if (QS60StylePrivate::isTouchSupported()) | 
|---|
| 3283 | qApp->installEventFilter(this); | 
|---|
| 3284 | } | 
|---|
| 3285 |  | 
|---|
| 3286 | /*! | 
|---|
| 3287 | \reimp | 
|---|
| 3288 | */ | 
|---|
| 3289 | void QS60Style::unpolish(QApplication *application) | 
|---|
| 3290 | { | 
|---|
| 3291 | Q_UNUSED(application) | 
|---|
| 3292 |  | 
|---|
| 3293 | Q_D(QS60Style); | 
|---|
| 3294 | QCommonStyle::unpolish(qApp); | 
|---|
| 3295 | const QPalette newPalette = QApplication::style()->standardPalette(); | 
|---|
| 3296 | QApplication::setPalette(newPalette); | 
|---|
| 3297 | QApplicationPrivate::setSystemPalette(d->m_originalPalette); | 
|---|
| 3298 | if (QS60StylePrivate::isTouchSupported()) | 
|---|
| 3299 | qApp->removeEventFilter(this); | 
|---|
| 3300 | } | 
|---|
| 3301 |  | 
|---|
| 3302 | /*! | 
|---|
| 3303 | \reimp | 
|---|
| 3304 | */ | 
|---|
| 3305 | bool QS60Style::event(QEvent *e) | 
|---|
| 3306 | { | 
|---|
| 3307 | #ifdef QT_KEYPAD_NAVIGATION | 
|---|
| 3308 | Q_D(QS60Style); | 
|---|
| 3309 | const QEvent::Type eventType = e->type(); | 
|---|
| 3310 | if ((eventType == QEvent::FocusIn || | 
|---|
| 3311 | eventType == QEvent::FocusOut || | 
|---|
| 3312 | eventType == QEvent::EnterEditFocus || | 
|---|
| 3313 | eventType == QEvent::LeaveEditFocus) && | 
|---|
| 3314 | QS60StylePrivate::isTouchSupported()) | 
|---|
| 3315 | return false; | 
|---|
| 3316 | #endif | 
|---|
| 3317 |  | 
|---|
| 3318 | switch (e->type()) { | 
|---|
| 3319 | case QEvent::Timer: { | 
|---|
| 3320 | QTimerEvent *te = static_cast<QTimerEvent*>(e); | 
|---|
| 3321 | timerEvent(te); | 
|---|
| 3322 | } | 
|---|
| 3323 | break; | 
|---|
| 3324 | #ifdef QT_KEYPAD_NAVIGATION | 
|---|
| 3325 | case QEvent::FocusIn: | 
|---|
| 3326 | if (QWidget *focusWidget = QApplication::focusWidget()) { | 
|---|
| 3327 |  | 
|---|
| 3328 | // Menus and combobox popups do not draw focus frame around them | 
|---|
| 3329 | if (qobject_cast<QComboBoxListView *>(focusWidget) || | 
|---|
| 3330 | qobject_cast<QMenu *>(focusWidget)) | 
|---|
| 3331 | break; | 
|---|
| 3332 |  | 
|---|
| 3333 | if (!d->m_focusFrame) | 
|---|
| 3334 | d->m_focusFrame = new QFocusFrame(focusWidget); | 
|---|
| 3335 | d->m_focusFrame->setWidget(focusWidget); | 
|---|
| 3336 | } else if (d->m_focusFrame) { | 
|---|
| 3337 | d->m_focusFrame->setWidget(0); | 
|---|
| 3338 | } | 
|---|
| 3339 | break; | 
|---|
| 3340 | case QEvent::FocusOut: | 
|---|
| 3341 | if (d->m_focusFrame) | 
|---|
| 3342 | d->m_focusFrame->setWidget(0); | 
|---|
| 3343 | break; | 
|---|
| 3344 | case QEvent::EnterEditFocus: | 
|---|
| 3345 | case QEvent::LeaveEditFocus: | 
|---|
| 3346 | if (d->m_focusFrame) | 
|---|
| 3347 | d->m_focusFrame->update(); | 
|---|
| 3348 | break; | 
|---|
| 3349 | #endif | 
|---|
| 3350 | default: | 
|---|
| 3351 | break; | 
|---|
| 3352 | } | 
|---|
| 3353 | return false; | 
|---|
| 3354 | } | 
|---|
| 3355 |  | 
|---|
| 3356 | /*! | 
|---|
| 3357 | \internal | 
|---|
| 3358 | */ | 
|---|
| 3359 | QIcon QS60Style::standardIconImplementation(StandardPixmap standardIcon, | 
|---|
| 3360 | const QStyleOption *option, const QWidget *widget) const | 
|---|
| 3361 | { | 
|---|
| 3362 | const int iconDimension = QS60StylePrivate::pixelMetric(PM_ToolBarIconSize); | 
|---|
| 3363 | const QRect iconSize = (!option) ? QRect(0, 0, iconDimension, iconDimension) : option->rect; | 
|---|
| 3364 | QS60StyleEnums::SkinParts part; | 
|---|
| 3365 | QS60StylePrivate::SkinElementFlags adjustedFlags; | 
|---|
| 3366 | if (option) | 
|---|
| 3367 | adjustedFlags = (option->state & State_Enabled || option->state == 0) ? | 
|---|
| 3368 | QS60StylePrivate::SF_StateEnabled : | 
|---|
| 3369 | QS60StylePrivate::SF_StateDisabled; | 
|---|
| 3370 |  | 
|---|
| 3371 | switch(standardIcon) { | 
|---|
| 3372 | case SP_MessageBoxWarning: | 
|---|
| 3373 | part = QS60StyleEnums::SP_QgnNoteWarning; | 
|---|
| 3374 | break; | 
|---|
| 3375 | case SP_MessageBoxInformation: | 
|---|
| 3376 | part = QS60StyleEnums::SP_QgnNoteInfo; | 
|---|
| 3377 | break; | 
|---|
| 3378 | case SP_MessageBoxCritical: | 
|---|
| 3379 | part = QS60StyleEnums::SP_QgnNoteError; | 
|---|
| 3380 | break; | 
|---|
| 3381 | case SP_MessageBoxQuestion: | 
|---|
| 3382 | part = QS60StyleEnums::SP_QgnNoteQuery; | 
|---|
| 3383 | break; | 
|---|
| 3384 | case SP_ArrowRight: | 
|---|
| 3385 | part = QS60StyleEnums::SP_QgnIndiNaviArrowRight; | 
|---|
| 3386 | break; | 
|---|
| 3387 | case SP_ArrowLeft: | 
|---|
| 3388 | part = QS60StyleEnums::SP_QgnIndiNaviArrowLeft; | 
|---|
| 3389 | break; | 
|---|
| 3390 | case SP_ArrowUp: | 
|---|
| 3391 | part = QS60StyleEnums::SP_QgnIndiNaviArrowLeft; | 
|---|
| 3392 | adjustedFlags |= QS60StylePrivate::SF_PointEast; | 
|---|
| 3393 | break; | 
|---|
| 3394 | case SP_ArrowDown: | 
|---|
| 3395 | part = QS60StyleEnums::SP_QgnIndiNaviArrowLeft; | 
|---|
| 3396 | adjustedFlags |= QS60StylePrivate::SF_PointWest; | 
|---|
| 3397 | break; | 
|---|
| 3398 | case SP_ArrowBack: | 
|---|
| 3399 | if (QApplication::layoutDirection() == Qt::RightToLeft) | 
|---|
| 3400 | return QS60Style::standardIcon(SP_ArrowRight, option, widget); | 
|---|
| 3401 | return QS60Style::standardIcon(SP_ArrowLeft, option, widget); | 
|---|
| 3402 | case SP_ArrowForward: | 
|---|
| 3403 | if (QApplication::layoutDirection() == Qt::RightToLeft) | 
|---|
| 3404 | return QS60Style::standardIcon(SP_ArrowLeft, option, widget); | 
|---|
| 3405 | return QS60Style::standardIcon(SP_ArrowRight, option, widget); | 
|---|
| 3406 | case SP_ComputerIcon: | 
|---|
| 3407 | part = QS60StyleEnums::SP_QgnPropPhoneMemcLarge; | 
|---|
| 3408 | break; | 
|---|
| 3409 | case SP_DirClosedIcon: | 
|---|
| 3410 | part = QS60StyleEnums::SP_QgnPropFolderSmall; | 
|---|
| 3411 | break; | 
|---|
| 3412 | case SP_DirOpenIcon: | 
|---|
| 3413 | part = QS60StyleEnums::SP_QgnPropFolderCurrent; | 
|---|
| 3414 | break; | 
|---|
| 3415 | case SP_DirIcon: | 
|---|
| 3416 | part = QS60StyleEnums::SP_QgnPropFolderSmall; | 
|---|
| 3417 | break; | 
|---|
| 3418 | case SP_FileDialogNewFolder: | 
|---|
| 3419 | part = QS60StyleEnums::SP_QgnPropFolderSmallNew; | 
|---|
| 3420 | break; | 
|---|
| 3421 | case SP_FileIcon: | 
|---|
| 3422 | part = QS60StyleEnums::SP_QgnPropFileSmall; | 
|---|
| 3423 | break; | 
|---|
| 3424 | case SP_TrashIcon: | 
|---|
| 3425 | part = QS60StyleEnums::SP_QgnNoteErased; | 
|---|
| 3426 | break; | 
|---|
| 3427 | case SP_ToolBarHorizontalExtensionButton: | 
|---|
| 3428 | part = QS60StyleEnums::SP_QgnIndiSubmenu; | 
|---|
| 3429 | if (QApplication::layoutDirection() == Qt::RightToLeft) | 
|---|
| 3430 | adjustedFlags |= QS60StylePrivate::SF_PointSouth; | 
|---|
| 3431 | break; | 
|---|
| 3432 | case SP_ToolBarVerticalExtensionButton: | 
|---|
| 3433 | adjustedFlags |= QS60StylePrivate::SF_PointEast; | 
|---|
| 3434 | part = QS60StyleEnums::SP_QgnIndiSubmenu; | 
|---|
| 3435 | break; | 
|---|
| 3436 |  | 
|---|
| 3437 | default: | 
|---|
| 3438 | return QCommonStyle::standardIconImplementation(standardIcon, option, widget); | 
|---|
| 3439 | } | 
|---|
| 3440 | const QS60StylePrivate::SkinElementFlags flags = adjustedFlags; | 
|---|
| 3441 | const QPixmap cachedPixMap(QS60StylePrivate::cachedPart(part, iconSize.size(), 0, flags)); | 
|---|
| 3442 | return cachedPixMap.isNull() ? | 
|---|
| 3443 | QCommonStyle::standardIconImplementation(standardIcon, option, widget) : QIcon(cachedPixMap); | 
|---|
| 3444 | } | 
|---|
| 3445 |  | 
|---|
| 3446 | /*! | 
|---|
| 3447 | \internal | 
|---|
| 3448 | Animate indeterminate progress bars only when visible | 
|---|
| 3449 | */ | 
|---|
| 3450 | bool QS60Style::eventFilter(QObject *object, QEvent *event) | 
|---|
| 3451 | { | 
|---|
| 3452 | Q_D(QS60Style); | 
|---|
| 3453 | switch(event->type()) { | 
|---|
| 3454 | case QEvent::MouseButtonPress: { | 
|---|
| 3455 | QWidget *w = QApplication::widgetAt(QCursor::pos()); | 
|---|
| 3456 | if (w) { | 
|---|
| 3457 | QWidget *focusW = w->focusProxy(); | 
|---|
| 3458 | if (qobject_cast<QAbstractItemView *>(focusW) || | 
|---|
| 3459 | qobject_cast<QRadioButton *>(focusW) || | 
|---|
| 3460 | qobject_cast<QCheckBox *>(focusW)) | 
|---|
| 3461 | d->m_pressedWidget = focusW; | 
|---|
| 3462 | else if (qobject_cast<QAbstractItemView *>(w)|| | 
|---|
| 3463 | qobject_cast<QRadioButton *>(w) || | 
|---|
| 3464 | qobject_cast<QCheckBox *>(w)) | 
|---|
| 3465 | d->m_pressedWidget = w; | 
|---|
| 3466 |  | 
|---|
| 3467 | if (d->m_pressedWidget) | 
|---|
| 3468 | d->m_pressedWidget->update(); | 
|---|
| 3469 | } | 
|---|
| 3470 | break; | 
|---|
| 3471 | } | 
|---|
| 3472 | case QEvent::MouseButtonRelease: { | 
|---|
| 3473 | if (d->m_pressedWidget) { | 
|---|
| 3474 | d->m_pressedWidget->update(); | 
|---|
| 3475 | d->m_pressedWidget = 0; | 
|---|
| 3476 | } | 
|---|
| 3477 | break; | 
|---|
| 3478 | } | 
|---|
| 3479 | default: | 
|---|
| 3480 | break; | 
|---|
| 3481 | } | 
|---|
| 3482 |  | 
|---|
| 3483 | #ifdef Q_WS_S60 | 
|---|
| 3484 | #ifndef QT_NO_PROGRESSBAR | 
|---|
| 3485 | switch(event->type()) { | 
|---|
| 3486 | case QEvent::StyleChange: | 
|---|
| 3487 | case QEvent::Show: | 
|---|
| 3488 | if (QProgressBar *bar = qobject_cast<QProgressBar *>(object)) { | 
|---|
| 3489 | if (!d->m_bars.contains(bar)) | 
|---|
| 3490 | d->m_bars << bar; | 
|---|
| 3491 | if (d->m_bars.size() == 1) //only start with first animated progressbar | 
|---|
| 3492 | d->startAnimation(QS60StyleEnums::SP_QgnGrafBarWaitAnim); | 
|---|
| 3493 | } | 
|---|
| 3494 | break; | 
|---|
| 3495 | case QEvent::Destroy: | 
|---|
| 3496 | case QEvent::Hide: | 
|---|
| 3497 | if (QProgressBar *bar = reinterpret_cast<QProgressBar *>(object)) { | 
|---|
| 3498 | d->stopAnimation(QS60StyleEnums::SP_QgnGrafBarWaitAnim); | 
|---|
| 3499 | d->m_bars.removeAll(bar); | 
|---|
| 3500 | } | 
|---|
| 3501 | break; | 
|---|
| 3502 | default: | 
|---|
| 3503 | break; | 
|---|
| 3504 | } | 
|---|
| 3505 | #endif // QT_NO_PROGRESSBAR | 
|---|
| 3506 | #endif // Q_WS_S60 | 
|---|
| 3507 | return QCommonStyle::eventFilter(object, event); | 
|---|
| 3508 | } | 
|---|
| 3509 |  | 
|---|
| 3510 | /*! | 
|---|
| 3511 | \internal | 
|---|
| 3512 | Handle the timer \a event. | 
|---|
| 3513 | */ | 
|---|
| 3514 | void QS60Style::timerEvent(QTimerEvent *event) | 
|---|
| 3515 | { | 
|---|
| 3516 | #ifdef Q_WS_S60 | 
|---|
| 3517 | #ifndef QT_NO_PROGRESSBAR | 
|---|
| 3518 | Q_D(QS60Style); | 
|---|
| 3519 |  | 
|---|
| 3520 | QS60StyleAnimation *progressBarAnimation = | 
|---|
| 3521 | QS60StylePrivate::animationDefinition(QS60StyleEnums::SP_QgnGrafBarWaitAnim); | 
|---|
| 3522 |  | 
|---|
| 3523 | if (event->timerId() == progressBarAnimation->timerId()) { | 
|---|
| 3524 |  | 
|---|
| 3525 | Q_ASSERT(progressBarAnimation->interval() > 0); | 
|---|
| 3526 |  | 
|---|
| 3527 | if (progressBarAnimation->currentFrame() == progressBarAnimation->frameCount() ) | 
|---|
| 3528 | if (progressBarAnimation->playMode() == QS60StyleEnums::AM_Looping) | 
|---|
| 3529 | progressBarAnimation->setCurrentFrame(0); | 
|---|
| 3530 | else | 
|---|
| 3531 | d->stopAnimation(progressBarAnimation->animationId()); | 
|---|
| 3532 |  | 
|---|
| 3533 | foreach (QProgressBar *bar, d->m_bars) { | 
|---|
| 3534 | if ((bar->minimum() == 0 && bar->maximum() == 0)) | 
|---|
| 3535 | bar->update(); | 
|---|
| 3536 | } | 
|---|
| 3537 | progressBarAnimation->setCurrentFrame(progressBarAnimation->currentFrame() + 1); | 
|---|
| 3538 | } | 
|---|
| 3539 | #endif // QT_NO_PROGRESSBAR | 
|---|
| 3540 | #endif // Q_WS_S60 | 
|---|
| 3541 | event->ignore(); | 
|---|
| 3542 | } | 
|---|
| 3543 |  | 
|---|
| 3544 | extern QPoint qt_s60_fill_background_offset(const QWidget *targetWidget); | 
|---|
| 3545 |  | 
|---|
| 3546 | bool qt_s60_fill_background(QPainter *painter, const QRegion &rgn, const QBrush &brush) | 
|---|
| 3547 | { | 
|---|
| 3548 | const QPixmap backgroundTexture(QS60StylePrivate::backgroundTexture()); | 
|---|
| 3549 | if (backgroundTexture.cacheKey() != brush.texture().cacheKey()) | 
|---|
| 3550 | return false; | 
|---|
| 3551 |  | 
|---|
| 3552 | const QPaintDevice *target = painter->device(); | 
|---|
| 3553 | if (target->devType() == QInternal::Widget) { | 
|---|
| 3554 | const QWidget *widget = static_cast<const QWidget *>(target); | 
|---|
| 3555 | if (!widget->testAttribute(Qt::WA_TranslucentBackground)) { | 
|---|
| 3556 | const QVector<QRect> &rects = rgn.rects(); | 
|---|
| 3557 | for (int i = 0; i < rects.size(); ++i) { | 
|---|
| 3558 | const QRect rect(rects.at(i)); | 
|---|
| 3559 | painter->drawPixmap(rect.topLeft(), backgroundTexture, | 
|---|
| 3560 | rect.translated(qt_s60_fill_background_offset(widget))); | 
|---|
| 3561 | } | 
|---|
| 3562 | } | 
|---|
| 3563 | } | 
|---|
| 3564 | return true; | 
|---|
| 3565 | } | 
|---|
| 3566 |  | 
|---|
| 3567 | QT_END_NAMESPACE | 
|---|
| 3568 |  | 
|---|
| 3569 | #endif // QT_NO_STYLE_S60 || QT_PLUGIN | 
|---|