Ejemplo n.º 1
0
static inline pbnjson::JValue createJSONItem(const QWebSelectData& listData, int index)
{
    pbnjson::JValue result = pbnjson::Object();

    result.put(const_cast<char*>("text"), listData.itemText(index).toUtf8().constData());
    result.put(const_cast<char*>("isEnabled"), listData.itemIsEnabled(index));
    result.put(const_cast<char*>("isSeparator"), listData.itemType(index) == QWebSelectData::Separator);
    result.put(const_cast<char*>("isLabel"), listData.itemType(index) == QWebSelectData::Group);

    return result;
}
void QtFallbackWebPopup::populate(const QWebSelectData& data)
{
    QStandardItemModel* model = qobject_cast<QStandardItemModel*>(m_combo->model());
    Q_ASSERT(model);

#if !defined(Q_OS_SYMBIAN)
    m_combo->setFont(font());
#endif

    int currentIndex = -1;
    for (int i = 0; i < data.itemCount(); ++i) {
        switch (data.itemType(i)) {
        case QWebSelectData::Separator:
            m_combo->insertSeparator(i);
            break;
        case QWebSelectData::Group:
            m_combo->insertItem(i, data.itemText(i));
            model->item(i)->setEnabled(false);
            break;
        case QWebSelectData::Option:
            m_combo->insertItem(i, data.itemText(i));
            model->item(i)->setEnabled(data.itemIsEnabled(i));
#ifndef QT_NO_TOOLTIP
            model->item(i)->setToolTip(data.itemToolTip(i));
#endif
            model->item(i)->setBackground(data.itemBackgroundColor(i));
            model->item(i)->setForeground(data.itemForegroundColor(i));
            if (data.itemIsSelected(i))
                currentIndex = i;
            break;
        }
    }

    if (currentIndex >= 0)
        m_combo->setCurrentIndex(currentIndex);
}