2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #include "WebPlugin.h"
23 #include <QHBoxLayout>
25 #include <QListWidget>
26 #include <QListWidgetItem>
29 #include <QPushButton>
30 #include <QStyledItemDelegate>
31 #include <QVBoxLayout>
33 static const int gMaemoListItemSize = 70;
34 static const int gMaemoListPadding = 38;
35 static const int gMaemoMaxVisibleItems = 5;
37 void Popup::populateList()
39 QListWidgetItem* listItem;
40 for (int i = 0; i < m_data.itemCount(); ++i) {
41 if (m_data.itemType(i) == QWebSelectData::Option) {
42 listItem = new QListWidgetItem(m_data.itemText(i));
43 m_list->addItem(listItem);
44 listItem->setSelected(m_data.itemIsSelected(i));
45 } else if (m_data.itemType(i) == QWebSelectData::Group) {
46 listItem = new QListWidgetItem(m_data.itemText(i));
47 m_list->addItem(listItem);
48 listItem->setSelected(false);
49 listItem->setFlags(Qt::NoItemFlags);
52 connect(m_list, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(onItemSelected(QListWidgetItem*)));
55 void Popup::onItemSelected(QListWidgetItem* item)
57 if (item->flags() != Qt::NoItemFlags)
58 emit itemClicked(m_list->row(item));
69 m_popup->deleteLater();
72 Popup* WebPopup::createSingleSelectionPopup(const QWebSelectData& data)
74 return new SingleSelectionPopup(data);
77 Popup* WebPopup::createMultipleSelectionPopup(const QWebSelectData& data)
79 return new MultipleSelectionPopup(data);
82 Popup* WebPopup::createPopup(const QWebSelectData& data)
84 Popup* result = data.multiple() ? createMultipleSelectionPopup(data) : createSingleSelectionPopup(data);
85 connect(result, SIGNAL(finished(int)), this, SLOT(popupClosed()));
86 connect(result, SIGNAL(itemClicked(int)), this, SLOT(itemClicked(int)));
90 void WebPopup::show(const QWebSelectData& data)
95 m_popup = createPopup(data);
107 void WebPopup::popupClosed()
112 m_popup->deleteLater();
117 void WebPopup::itemClicked(int idx)
119 emit selectItem(idx, true, false);
122 SingleSelectionPopup::SingleSelectionPopup(const QWebSelectData& data)
125 const char* title = "select";
126 if (qstrcmp(title, "weba_ti_texlist_single"))
127 setWindowTitle(QString::fromUtf8(title));
129 setWindowTitle("Select item");
131 QHBoxLayout* hLayout = new QHBoxLayout(this);
132 hLayout->setContentsMargins(0, 0, 0, 0);
134 m_list = new QListWidget(this);
137 hLayout->addSpacing(gMaemoListPadding);
138 hLayout->addWidget(m_list);
139 hLayout->addSpacing(gMaemoListPadding);
141 connect(m_list, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(accept()));
143 const int visibleItemCount = (m_list->count() > gMaemoMaxVisibleItems) ? gMaemoMaxVisibleItems : m_list->count();
144 resize(size().width(), visibleItemCount * gMaemoListItemSize);
148 class MultipleItemListDelegate : public QStyledItemDelegate {
150 MultipleItemListDelegate(QObject* parent = 0)
151 : QStyledItemDelegate(parent)
153 tickMark = QIcon::fromTheme("widgets_tickmark_list").pixmap(48, 48);
156 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
158 QStyledItemDelegate::paint(painter, option, index);
160 if (option.state & QStyle::State_Selected)
161 painter->drawPixmap(option.rect.width() - tickMark.rect().width(), option.rect.y() + (option.rect.height() / 2 - tickMark.rect().height() / 2), tickMark);
168 MultipleSelectionPopup::MultipleSelectionPopup(const QWebSelectData& data)
171 const char* title = "select";
172 if (qstrcmp(title, "weba_ti_textlist_multi"))
173 setWindowTitle(QString::fromUtf8(title));
175 setWindowTitle("Select items");
177 QHBoxLayout* hLayout = new QHBoxLayout(this);
178 hLayout->setContentsMargins(0, 0, 0, 0);
180 m_list = new QListWidget(this);
181 m_list->setSelectionMode(QAbstractItemView::MultiSelection);
184 MultipleItemListDelegate* delegate = new MultipleItemListDelegate(this);
185 m_list->setItemDelegate(delegate);
187 hLayout->addSpacing(gMaemoListPadding);
188 hLayout->addWidget(m_list);
190 QVBoxLayout* vLayout = new QVBoxLayout();
192 const int visibleItemCount = (m_list->count() > gMaemoMaxVisibleItems) ? gMaemoMaxVisibleItems : m_list->count();
193 vLayout->addSpacing((visibleItemCount - 1) * gMaemoListItemSize);
195 QPushButton* done = new QPushButton(this);
197 if (qstrcmp(title, "wdgt_bd_done"))
198 done->setText(QString::fromUtf8(title));
200 done->setText("Done");
202 done->setMinimumWidth(178);
203 vLayout->addWidget(done);
205 hLayout->addSpacing(8);
206 hLayout->addLayout(vLayout);
207 hLayout->addSpacing(18);
209 connect(done, SIGNAL(clicked()), this, SLOT(accept()));
210 resize(size().width(), visibleItemCount * gMaemoListItemSize);
213 #if defined(WTF_USE_QT_MULTIMEDIA) && WTF_USE_QT_MULTIMEDIA
214 FullScreenVideoWidget::FullScreenVideoWidget(QMediaPlayer* player)
216 , m_mediaPlayer(player)
218 Q_ASSERT(m_mediaPlayer);
221 m_mediaPlayer->setVideoOutput(this);
224 bool FullScreenVideoWidget::event(QEvent* ev)
226 if (ev->type() == QEvent::MouseButtonDblClick) {
227 emit fullScreenClosed();
231 return QWidget::event(ev);
234 void FullScreenVideoWidget::keyPressEvent(QKeyEvent* ev)
236 if (ev->key() == Qt::Key_Space) {
237 if (m_mediaPlayer->state() == QMediaPlayer::PlayingState)
238 m_mediaPlayer->pause();
240 m_mediaPlayer->play();
246 FullScreenVideoHandler::FullScreenVideoHandler()
251 FullScreenVideoHandler::~FullScreenVideoHandler()
253 delete m_mediaWidget;
256 bool FullScreenVideoHandler::requiresFullScreenForVideoPlayback() const
261 void FullScreenVideoHandler::enterFullScreen(QMediaPlayer* player)
265 m_mediaWidget = new FullScreenVideoWidget(player);
266 connect(m_mediaWidget, SIGNAL(fullScreenClosed()), this, SIGNAL(fullScreenClosed()));
267 m_mediaWidget->showFullScreen();
270 void FullScreenVideoHandler::exitFullScreen()
272 m_mediaWidget->hide();
273 delete m_mediaWidget;
278 bool WebPlugin::supportsExtension(Extension extension) const
281 case MultipleSelections:
283 #if ENABLE_NOTIFICATIONS
287 case TouchInteraction:
289 #if defined(WTF_USE_QT_MULTIMEDIA) && WTF_USE_QT_MULTIMEDIA
290 case FullScreenVideoPlayer:
298 QObject* WebPlugin::createExtension(Extension extension) const
301 case MultipleSelections:
302 return new WebPopup();
303 #if ENABLE_NOTIFICATIONS
305 return new WebNotificationPresenter();
307 case TouchInteraction:
308 return new TouchModifier();
309 #if defined(WTF_USE_QT_MULTIMEDIA) && WTF_USE_QT_MULTIMEDIA
310 case FullScreenVideoPlayer:
311 return new FullScreenVideoHandler();
318 Q_EXPORT_PLUGIN2(platformplugin, WebPlugin)