Changeset 56970 in webkit


Ignore:
Timestamp:
Apr 1, 2010 10:33:53 PM (14 years ago)
Author:
eric@webkit.org
Message:

2010-04-01 Luiz Agostini <luiz.agostini@openbossa.org>

Reviewed by Kenneth Rohde Christiansen.

[Qt] Maemo5 theme - <select multiple> custom rendering
https://bugs.webkit.org/show_bug.cgi?id=36369

Customizing rendering of <select multiple> elements in Maemo5.

  • platform/qt/Maemo5Webstyle.cpp: (Maemo5WebStyle::drawMultipleComboButton): (Maemo5WebStyle::drawSimpleComboButton): (Maemo5WebStyle::getButtonImageSize): (Maemo5WebStyle::findComboButton): (Maemo5WebStyle::drawComplexControl):
  • platform/qt/Maemo5Webstyle.h:
Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r56968 r56970  
     12010-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
    1182010-04-01  Kinuko Yasuda  <kinuko@chromium.org>
    219
  • trunk/WebCore/platform/qt/Maemo5Webstyle.cpp

    r56860 r56970  
    2020#include "config.h"
    2121#include "Maemo5Webstyle.h"
     22
     23#include "QtStyleOptionWebComboBox.h"
    2224
    2325#include <QPainter>
     
    154156}
    155157
     158void 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
     173void 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
     183QSize 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
     201QPixmap 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
    156225void Maemo5WebStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget) const
    157226{
    158227    switch (control) {
    159228    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);
    161241
    162242        if (!cmb) {
     
    168248            break;
    169249
    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
    177263        break;
    178264    }
  • trunk/WebCore/platform/qt/Maemo5Webstyle.h

    r56860 r56970  
    3838    QPixmap findRadio(const QSize& size, bool checked, bool disabled) const;
    3939
     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
    4045};
    4146
Note: See TracChangeset for help on using the changeset viewer.