Changeset 56970 in webkit
- Timestamp:
- Apr 1, 2010 10:33:53 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r56968 r56970 1 2010-04-01 Luiz Agostini <luiz.agostini@openbossa.org> 2 3 Reviewed by Kenneth Rohde Christiansen. 4 5 [Qt] Maemo5 theme - <select multiple> custom rendering 6 https://bugs.webkit.org/show_bug.cgi?id=36369 7 8 Customizing rendering of <select multiple> elements in Maemo5. 9 10 * platform/qt/Maemo5Webstyle.cpp: 11 (Maemo5WebStyle::drawMultipleComboButton): 12 (Maemo5WebStyle::drawSimpleComboButton): 13 (Maemo5WebStyle::getButtonImageSize): 14 (Maemo5WebStyle::findComboButton): 15 (Maemo5WebStyle::drawComplexControl): 16 * platform/qt/Maemo5Webstyle.h: 17 1 18 2010-04-01 Kinuko Yasuda <kinuko@chromium.org> 2 19 -
trunk/WebCore/platform/qt/Maemo5Webstyle.cpp
r56860 r56970 20 20 #include "config.h" 21 21 #include "Maemo5Webstyle.h" 22 23 #include "QtStyleOptionWebComboBox.h" 22 24 23 25 #include <QPainter> … … 154 156 } 155 157 158 void Maemo5WebStyle::drawMultipleComboButton(QPainter* painter, const QSize& size, QColor color) const 159 { 160 int rectWidth = size.width() - 1; 161 int width = qMax(2, rectWidth >> 3); 162 int distance = (rectWidth - 3 * width) >> 1; 163 int top = (size.height() - width) >> 1; 164 165 painter->setPen(color); 166 painter->setBrush(color); 167 168 painter->drawRect(0, top, width, width); 169 painter->drawRect(width + distance, top, width, width); 170 painter->drawRect(2 * (width + distance), top, width, width); 171 } 172 173 void Maemo5WebStyle::drawSimpleComboButton(QPainter* painter, const QSize& size, QColor color) const 174 { 175 QPolygon polygon; 176 int width = size.width(); 177 polygon.setPoints(3, 0, 0, width - 1, 0, width >> 1, size.height()); 178 painter->setPen(color); 179 painter->setBrush(color); 180 painter->drawPolygon(polygon); 181 } 182 183 QSize Maemo5WebStyle::getButtonImageSize(const QSize& buttonSize) const 184 { 185 const int border = qMax(3, buttonSize.width() >> 3) << 1; 186 187 int width = buttonSize.width() - border; 188 int height = buttonSize.height() - border; 189 190 if (width < 0 || height < 0) 191 return QSize(); 192 193 if (height >= (width >> 1)) 194 width = width >> 1 << 1; 195 else 196 width = height << 1; 197 198 return QSize(width + 1, width >> 1); 199 } 200 201 QPixmap Maemo5WebStyle::findComboButton(const QSize& size, bool multiple, bool disabled) const 202 { 203 QPixmap result; 204 QSize imageSize = getButtonImageSize(size); 205 206 if (imageSize.isNull()) 207 return QPixmap(); 208 static const QString prefix = "$qt-maemo5-" + QLatin1String(metaObject()->className()) + "-combo-"; 209 QString key = prefix + (multiple ? "multiple-" : "simple-") + 210 QString::number(imageSize.width()) + "-" + QString::number(imageSize.height()) + 211 + "-" + (disabled ? "disabled" : "enabled"); 212 if (!QPixmapCache::find(key, result)) { 213 result = QPixmap(imageSize); 214 result.fill(Qt::transparent); 215 QPainter painter(&result); 216 if (multiple) 217 drawMultipleComboButton(&painter, imageSize, disabled ? Qt::gray : Qt::black); 218 else 219 drawSimpleComboButton(&painter, imageSize, disabled ? Qt::gray : Qt::black); 220 QPixmapCache::insert(key, result); 221 } 222 return result; 223 } 224 156 225 void Maemo5WebStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget) const 157 226 { 158 227 switch (control) { 159 228 case CC_ComboBox: { 160 const QStyleOptionComboBox* cmb = qstyleoption_cast<const QStyleOptionComboBox*>(option); 229 230 bool multiple = false; 231 const bool disabled = !(option->state & State_Enabled); 232 233 const QStyleOptionComboBox* cmb = 0; 234 const WebCore::QtStyleOptionWebComboBox* webCombo = static_cast<const WebCore::QtStyleOptionWebComboBox*>(option); 235 236 if (webCombo) { 237 multiple = webCombo->multiple(); 238 cmb = webCombo; 239 } else 240 cmb = qstyleoption_cast<const QStyleOptionComboBox*>(option); 161 241 162 242 if (!cmb) { … … 168 248 break; 169 249 170 QStyleOption arrowOpt(0); 171 arrowOpt.rect = subControlRect(CC_ComboBox, cmb, SC_ComboBoxArrow, widget); 172 173 arrowOpt.rect.adjust(3, 3, -3, -3); 174 arrowOpt.palette = cmb->palette; 175 arrowOpt.state = State_Enabled; 176 drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget); 250 QRect rect = subControlRect(CC_ComboBox, cmb, SC_ComboBoxArrow, widget); 251 QPixmap pic = findComboButton(rect.size(), multiple, disabled); 252 253 if (pic.isNull()) 254 break; 255 256 int x = (rect.width() - pic.width()) >> 1; 257 int y = (rect.height() - pic.height()) >> 1; 258 painter->drawPixmap(rect.x() + x, rect.y() + y, pic); 259 260 painter->setPen(disabled ? Qt::gray : Qt::darkGray); 261 painter->drawLine(rect.left() - 2, rect.top() + 2, rect.left() - 2, rect.bottom() - 2); 262 177 263 break; 178 264 } -
trunk/WebCore/platform/qt/Maemo5Webstyle.h
r56860 r56970 38 38 QPixmap findRadio(const QSize& size, bool checked, bool disabled) const; 39 39 40 QSize getButtonImageSize(const QSize& buttonSize) const; 41 void drawSimpleComboButton(QPainter* painter, const QSize& size, QColor color) const; 42 void drawMultipleComboButton(QPainter* painter, const QSize& size, QColor color) const; 43 QPixmap findComboButton(const QSize& size, bool multiple, bool disabled) const; 44 40 45 }; 41 46
Note: See TracChangeset
for help on using the changeset viewer.