3 #include <QAbstractItemModel>
5 #include "listwindow.h"
10 #include "flickcharm.h"
13 ListWindow::ListWindow(QWidget *parent): QMainWindow(parent), model(0)
15 #if defined(Q_WS_MAEMO_5)
16 setAttribute(Qt::WA_Maemo5StackedWindow, true);
19 list = new QListWidget(this);
21 setCentralWidget(list);
24 charm = new FlickCharm(this);
25 charm->activateOn(list);
26 QAction *closeAction = new QAction(parent? tr("Back"): tr("Exit"), this);
27 closeAction->setSoftKeyRole(QAction::NegativeSoftKey);
28 connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
29 QMainWindow::addAction(closeAction);
30 #endif // Q_OS_SYMBIAN
34 // addAction(tr("Close"), this, SLOT(close()), QString(),
35 // QDialogButtonBox::RejectRole);
38 connect(list, SIGNAL(activated(const QModelIndex &)),
39 this, SLOT(onItemActicvated(const QModelIndex &)));
42 void ListWindow::populateList()
47 list->setIconSize(QSize(48, 48)); // FIXME
48 list->setUniformItemSizes(true);
50 for (int i = 0; i < model->rowCount(); i++) {
51 QModelIndex index = model->index(i, 0);
52 QString text = model->data(index, Qt::DisplayRole).toString();
53 QVariant imageData = model->data(index, Qt::DecorationRole);
54 QIcon icon(QPixmap::fromImage(imageData.value<QImage>()));
55 (void)new QListWidgetItem(icon, text, list);
58 for (int i = 0; i < buttons.count(); i++) {
59 QListWidgetItem *item = new QListWidgetItem();
60 item->setFlags(Qt::NoItemFlags);
61 list->insertItem(i, item);
62 list->setItemWidget(item, buttons[i]);
66 void ListWindow::setModel(QAbstractItemModel *model_)
72 SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
73 this, SLOT(populateList()));
77 void ListWindow::addButton(const QString &title, QObject *receiver,
78 const char *slot, const QString &iconName)
82 QPushButton *button = new QPushButton(QIcon(Platform::instance()->
83 icon(iconName)), title, this);
84 connect(button, SIGNAL(clicked()), receiver, slot);
85 buttons.append(button);
87 int pos = buttons.length() - 1;
88 QListWidgetItem *item = new QListWidgetItem();
89 list->insertItem(pos, item);
90 list->setItemWidget(item, button);
93 QAction *ListWindow::addMenuAction(const QString &title, QObject *receiver,
98 #if defined(Q_WS_MAEMO_5)
99 action = menuBar()->addAction(title);
100 connect(action, SIGNAL(triggered()), receiver, slot);
101 #elif defined(Q_OS_SYMBIAN)
102 action = new QAction(title, this);
103 connect(action, SIGNAL(triggered()), receiver, slot);
104 action->setSoftKeyRole(QAction::PositiveSoftKey);
105 menuBar()->addAction(action);
110 action = new QAction(this);
112 action->setCheckable(true);
116 void ListWindow::onItemActivated(const QModelIndex &)
124 void ListWindow::closeEvent(QCloseEvent *event)
126 // Work around Maemo/Qt bug: Menu items are not removed on close
128 // FIXME: Is this needed? event->accept();
129 QMainWindow::closeEvent(event);
132 #endif // Q_WS_MAEMO_5
136 void ListWindow::show()
138 foreach (QWidget *w, QApplication::allWidgets()) {
139 w->setContextMenuPolicy(Qt::NoContextMenu);
144 #endif // Q_OS_SYMBIAN