Changeset 56929 in webkit


Ignore:
Timestamp:
Apr 1, 2010 12:36:06 PM (14 years ago)
Author:
eric@webkit.org
Message:

2010-04-01 Jesus Sanchez-Palencia <jesus.palencia@openbossa.org>

Reviewed by Kenneth Rohde Christiansen.

Add Single and Multiple Selection Popup for Maemo 5.

[Qt] Maemo5 theme - popup dialogs
https://bugs.webkit.org/show_bug.cgi?id=36789

  • WebCoreSupport/QtMaemoWebPopup.cpp: (WebCore::Maemo5Popup::populateList): (WebCore::Maemo5Popup::onItemSelected): (WebCore::QtMaemoWebPopup::createSingleSelectionPopup): (WebCore::QtMaemoWebPopup::createMultipleSelectionPopup): (WebCore::Maemo5SingleSelectionPopup::Maemo5SingleSelectionPopup): (WebCore::MultipleItemListDelegate::MultipleItemListDelegate): (WebCore::MultipleItemListDelegate::paint): (WebCore::Maemo5MultipleSelectionPopup::Maemo5MultipleSelectionPopup):
  • WebCoreSupport/QtMaemoWebPopup.h:
Location:
trunk/WebKit/qt
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/qt/ChangeLog

    r56851 r56929  
     12010-04-01  Jesus Sanchez-Palencia  <jesus.palencia@openbossa.org>
     2
     3        Reviewed by Kenneth Rohde Christiansen.
     4
     5        Add Single and Multiple Selection Popup for Maemo 5.
     6
     7        [Qt] Maemo5 theme - popup dialogs
     8        https://bugs.webkit.org/show_bug.cgi?id=36789
     9
     10        * WebCoreSupport/QtMaemoWebPopup.cpp:
     11        (WebCore::Maemo5Popup::populateList):
     12        (WebCore::Maemo5Popup::onItemSelected):
     13        (WebCore::QtMaemoWebPopup::createSingleSelectionPopup):
     14        (WebCore::QtMaemoWebPopup::createMultipleSelectionPopup):
     15        (WebCore::Maemo5SingleSelectionPopup::Maemo5SingleSelectionPopup):
     16        (WebCore::MultipleItemListDelegate::MultipleItemListDelegate):
     17        (WebCore::MultipleItemListDelegate::paint):
     18        (WebCore::Maemo5MultipleSelectionPopup::Maemo5MultipleSelectionPopup):
     19        * WebCoreSupport/QtMaemoWebPopup.h:
     20
    1212010-03-31  Marcus Bulach  <bulach@chromium.org>
    222
  • trunk/WebKit/qt/WebCoreSupport/QtMaemoWebPopup.cpp

    r56784 r56929  
    2121#include "QtMaemoWebPopup.h"
    2222
     23#include <QHBoxLayout>
     24#include <QListWidget>
     25#include <QListWidgetItem>
     26#include <QPainter>
     27#include <QPushButton>
     28#include <QStyledItemDelegate>
     29#include <QVBoxLayout>
     30
     31#include <libintl.h>
     32
     33
    2334namespace WebCore {
     35
     36static const int gMaemoListItemSize = 70;
     37static const int gMaemoListPadding = 38;
     38static const int gMaemoMaxVisibleItems = 5;
     39
     40void Maemo5Popup::populateList()
     41{
     42    QListWidgetItem* listItem;
     43    for (int i = 0; i < m_data.itemCount(); ++i) {
     44        if (m_data.itemType(i) == QtAbstractWebPopup::Option) {
     45            listItem = new QListWidgetItem(m_data.itemText(i));
     46            m_list->addItem(listItem);
     47            listItem->setSelected(m_data.itemIsSelected(i));
     48        } else if (m_data.itemType(i) == QtAbstractWebPopup::Group) {
     49            listItem = new QListWidgetItem(m_data.itemText(i));
     50            m_list->addItem(listItem);
     51            listItem->setSelected(false);
     52            listItem->setFlags(Qt::NoItemFlags);
     53        }
     54    }
     55    connect(m_list, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(onItemSelected(QListWidgetItem*)));
     56}
     57
     58void Maemo5Popup::onItemSelected(QListWidgetItem* item)
     59{
     60    if (item->flags() != Qt::NoItemFlags)
     61        emit itemClicked(m_list->row(item));
     62}
    2463
    2564QtMaemoWebPopup::QtMaemoWebPopup()
     
    3776Maemo5Popup* QtMaemoWebPopup::createSingleSelectionPopup()
    3877{
     78    return new Maemo5SingleSelectionPopup(*this);
    3979}
    4080
    4181Maemo5Popup* QtMaemoWebPopup::createMultipleSelectionPopup()
    4282{
     83    return new Maemo5MultipleSelectionPopup(*this);
    4384}
    4485
     
    5192}
    5293
    53 
    5494void QtMaemoWebPopup::show()
    5595{
     
    84124}
    85125
    86 }
     126Maemo5SingleSelectionPopup::Maemo5SingleSelectionPopup(QtAbstractWebPopup& data)
     127    : Maemo5Popup(data)
     128{
     129    // we try to get the standard list title the web browser is using
     130    const char* title = ::dgettext("osso-browser-ui", "weba_ti_texlist_single");
     131    if (qstrcmp(title, "weba_ti_texlist_single"))
     132        setWindowTitle(QString::fromUtf8(title));
     133    else
     134        setWindowTitle("Select item");
     135
     136    QHBoxLayout* hLayout = new QHBoxLayout(this);
     137    hLayout->setContentsMargins(0, 0, 0, 0);
     138
     139    m_list = new QListWidget(this);
     140    populateList();
     141
     142    hLayout->addSpacing(gMaemoListPadding);
     143    hLayout->addWidget(m_list);
     144    hLayout->addSpacing(gMaemoListPadding);
     145
     146    connect(m_list, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(accept()));
     147
     148    const int visibleItemCount = (m_list->count() > gMaemoMaxVisibleItems) ? gMaemoMaxVisibleItems : m_list->count();
     149    resize(size().width(), visibleItemCount * gMaemoListItemSize);
     150}
     151
     152
     153class MultipleItemListDelegate : public QStyledItemDelegate {
     154public:
     155    MultipleItemListDelegate(QObject* parent = 0)
     156           : QStyledItemDelegate(parent)
     157    {
     158        tickMark = QIcon::fromTheme("widgets_tickmark_list").pixmap(48, 48);
     159    }
     160
     161    void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
     162    {
     163        QStyledItemDelegate::paint(painter, option, index);
     164
     165        if (option.state & QStyle::State_Selected)
     166            painter->drawPixmap(option.rect.width() - tickMark.rect().width(), option.rect.y() + (option.rect.height() / 2 - tickMark.rect().height() / 2), tickMark);
     167    }
     168
     169private:
     170    QPixmap tickMark;
     171};
     172
     173Maemo5MultipleSelectionPopup::Maemo5MultipleSelectionPopup(QtAbstractWebPopup& data)
     174    : Maemo5Popup(data)
     175{
     176    // we try to get the standard list title the web browser is using
     177    const char* title = ::dgettext("osso-browser-ui", "weba_ti_textlist_multi");
     178    if (qstrcmp(title, "weba_ti_textlist_multi"))
     179        setWindowTitle(QString::fromUtf8(title));
     180    else
     181        setWindowTitle("Select items");
     182
     183    QHBoxLayout* hLayout = new QHBoxLayout(this);
     184    hLayout->setContentsMargins(0, 0, 0, 0);
     185
     186    m_list = new QListWidget(this);
     187    m_list->setSelectionMode(QAbstractItemView::MultiSelection);
     188    populateList();
     189
     190    MultipleItemListDelegate* delegate = new MultipleItemListDelegate(this);
     191    m_list->setItemDelegate(delegate);
     192
     193    hLayout->addSpacing(gMaemoListPadding);
     194    hLayout->addWidget(m_list);
     195
     196    QVBoxLayout* vLayout = new QVBoxLayout();
     197
     198    const int visibleItemCount = (m_list->count() > gMaemoMaxVisibleItems) ? gMaemoMaxVisibleItems : m_list->count();
     199    vLayout->addSpacing((visibleItemCount - 1) * gMaemoListItemSize);
     200
     201    // we try to get the standard Done button title
     202    QPushButton* done = new QPushButton(this);
     203    title = ::dgettext("hildon-libs", "wdgt_bd_done");
     204    if (qstrcmp(title, "wdgt_bd_done"))
     205        done->setText(QString::fromUtf8(title));
     206    else
     207        done->setText("Done");
     208
     209    done->setMinimumWidth(178);
     210    vLayout->addWidget(done);
     211
     212    hLayout->addSpacing(8);
     213    hLayout->addLayout(vLayout);
     214    hLayout->addSpacing(18);
     215
     216    connect(done, SIGNAL(clicked()), this, SLOT(accept()));
     217    resize(size().width(), visibleItemCount * gMaemoListItemSize);
     218}
     219
     220}
  • trunk/WebKit/qt/WebCoreSupport/QtMaemoWebPopup.h

    r56784 r56929  
    2525#include <QDialog>
    2626
     27class QListWidgetItem;
     28class QListWidget;
     29
     30
    2731namespace WebCore {
    2832
     
    3539    void itemClicked(int idx);
    3640
     41protected slots:
     42    void onItemSelected(QListWidgetItem* item);
     43
    3744protected:
     45    void populateList();
     46
    3847    QtAbstractWebPopup& m_data;
     48    QListWidget* m_list;
    3949};
     50
    4051
    4152class QtMaemoWebPopup : public QObject, public QtAbstractWebPopup {
     
    6071};
    6172
     73
     74class Maemo5SingleSelectionPopup : public Maemo5Popup {
     75    Q_OBJECT
     76public:
     77    Maemo5SingleSelectionPopup(QtAbstractWebPopup& data);
     78};
     79
     80
     81class Maemo5MultipleSelectionPopup : public Maemo5Popup {
     82    Q_OBJECT
     83public:
     84    Maemo5MultipleSelectionPopup(QtAbstractWebPopup& data);
     85};
     86
    6287}
    6388
Note: See TracChangeset for help on using the changeset viewer.