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; }
static inline pbnjson::JValue createJSONItemList(const QWebSelectData& listData, int& selectedIndex) { pbnjson::JValue result = pbnjson::Array(); for (int i = 0; i < listData.itemCount(); ++i) { if (listData.itemIsSelected(i)) selectedIndex = i; result.append(createJSONItem(listData, i)); } return result; }
void QtFallbackWebPopup::show(const QWebSelectData& data) { if (!pageClient()) return; #if ENABLE(SYMBIAN_DIALOG_PROVIDERS) TRAP_IGNORE(showS60BrowserDialog()); #else destroyPopup(); m_combo = new QtFallbackWebPopupCombo(*this); connect(m_combo, SIGNAL(activated(int)), SLOT(activeChanged(int)), Qt::QueuedConnection); populate(data); QColor backgroundColor = data.backgroundColor(); QColor foregroundColor = data.foregroundColor(); QPalette palette = m_combo->palette(); if (backgroundColor.isValid()) palette.setColor(QPalette::Background, backgroundColor); if (foregroundColor.isValid()) palette.setColor(QPalette::Foreground, foregroundColor); m_combo->setPalette(palette); QRect rect = geometry(); if (QGraphicsWebView *webView = qobject_cast<QGraphicsWebView*>(pageClient()->pluginParent())) { QGraphicsProxyWidget* proxy = new QGraphicsProxyWidget(webView); proxy->setWidget(m_combo); proxy->setGeometry(rect); } else { m_combo->setParent(pageClient()->ownerWidget()); m_combo->setGeometry(QRect(rect.left(), rect.top(), rect.width(), m_combo->sizeHint().height())); } QMouseEvent event(QEvent::MouseButtonPress, QCursor::pos(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); QCoreApplication::sendEvent(m_combo, &event); #endif }
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); }