3 #include "listwindow.h"
9 #include "flickcharm.h"
12 ListWindow::ListWindow(QWidget *parent): QMainWindow(parent), list(0)
14 #if defined(Q_WS_MAEMO_5)
15 setAttribute(Qt::WA_Maemo5StackedWindow, true);
16 popup = new QMenu(this);
18 QScrollArea *scroller = new QScrollArea(this);
19 setCentralWidget(scroller);
20 scroller->setProperty("FingerScrollable", true);
21 // scroller->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
22 // scroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
23 scroller->setFrameStyle(QFrame::NoFrame);
26 QWidget *content = new QWidget(scroller);
27 contentLayout = new QVBoxLayout(content);
28 contentLayout->setMargin(0);
29 content->setLayout(contentLayout);
32 scroller->setWidget(content);
33 scroller->setWidgetResizable(true);
35 QFrame *frame = new QFrame(this);
36 setCentralWidget(frame);
37 contentLayout = new QHBoxLayout();
38 frame->setLayout(contentLayout);
39 buttonBox = new QDialogButtonBox(Qt::Vertical, this);
40 contentLayout->addWidget(buttonBox);
41 #endif // Q_WS_MAEMO_5
45 QAction *closeAction = new QAction(parent? tr("Back"): tr("Exit"), this);
46 closeAction->setSoftKeyRole(QAction::NegativeSoftKey);
47 connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
48 QMainWindow::addAction(closeAction);
49 #endif // Q_OS_SYMBIAN
52 addAction(tr("Close"), this, SLOT(close()), QString(),
53 QDialogButtonBox::RejectRole);
57 void ListWindow::addList(ListView *listView)
61 #if defined(Q_WS_MAEMO_5)
62 // FIXME: list->installEventFilter(this);
63 list->setProperty("FingerScrollable", false);
64 int height = list->sizeHintForRow(0) * list->model()->rowCount();
65 qDebug() << "Minimum height" << height;
66 list->setMinimumHeight(height);
67 contentLayout->addWidget(list);
68 connect(list->model(),
69 SIGNAL(rowsInserted(const QModelIndex &, int, int)),
70 this, SLOT(onModelChanged()));
71 connect(list->model(),
72 SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
73 this, SLOT(onModelChanged()));
75 contentLayout->insertWidget(0, list);
80 charm = new FlickCharm(this);
82 // FIXME: Charms need more work...: charm->activateOn(list);
83 #endif // Q_OS_SYMBIAN
85 connect(list->selectionModel(),
86 SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
88 SLOT(onSelectionChanged(const QItemSelection &, const QItemSelection &)));
91 void ListWindow::addAction(const QString &title, QObject *receiver,
92 const char *slot, const QString &iconName,
93 QDialogButtonBox::ButtonRole role)
98 QPushButton *button = new QPushButton(QIcon(Platform::instance()->
99 icon(iconName)), title, this);
100 contentLayout->addWidget(button);
101 connect(button, SIGNAL(clicked()), receiver, slot);
102 #elif defined(Q_OS_SYMBIAN)
105 QAction *action = new QAction(title, this);
106 connect(action, SIGNAL(triggered()), receiver, slot);
107 action->setSoftKeyRole(QAction::PositiveSoftKey);
108 menuBar()->addAction(action);
111 QPushButton *button = buttonBox->addButton(title, role);
112 connect(button, SIGNAL(clicked()), receiver, slot);
113 #endif // Q_WS_MAEMO_5
116 void ListWindow::addItemAction(const QString &title, QObject *receiver,
121 popup->addAction(title, receiver, slot);
122 #elif defined Q_OS_SYMBIAN
123 QAction *action = new QAction(title, this);
124 connect(action, SIGNAL(triggered()), receiver, slot);
125 action->setSoftKeyRole(QAction::PositiveSoftKey);
126 menuBar()->addAction(action);
127 // FIXME: Add action to the list of item specific actions
129 QPushButton *button =
130 buttonBox->addButton(title, QDialogButtonBox::ActionRole);
131 connect(button, SIGNAL(clicked()), receiver, slot);
132 itemButtons.append(button);
133 activateItemButtons();
134 #endif // Q_WS_MAEMO_5
137 QAction *ListWindow::addMenuAction(const QString &title, QObject *receiver,
142 #if defined(Q_WS_MAEMO_5)
143 action = menuBar()->addAction(title);
144 connect(action, SIGNAL(triggered()), receiver, slot);
145 #elif defined(Q_OS_SYMBIAN)
146 action = new QAction(title, this);
147 connect(action, SIGNAL(triggered()), receiver, slot);
148 action->setSoftKeyRole(QAction::PositiveSoftKey);
149 menuBar()->addAction(action);
154 action = new QAction(this);
156 action->setCheckable(true);
162 void ListWindow::closeEvent(QCloseEvent *event)
164 // Work around Maemo/Qt but: Menu items are not removed on close
169 #endif // Q_WS_MAEMO_5
171 void ListWindow::onSelectionChanged(const QItemSelection &selected,
172 const QItemSelection &deselected)
175 Q_UNUSED(deselected);
177 activateItemButtons();
183 void ListWindow::activateItemButtons()
187 enable = list->selectionModel()->hasSelection();
189 foreach (QPushButton *button, itemButtons) {
190 button->setEnabled(enable);
194 #endif // ! Q_WS_MAEMO_5
198 bool ListWindow::eventFilter(QObject *obj, QEvent *event)
200 if (event->type() == QEvent::ContextMenu) {
201 qDebug() << "ListWindow::eventFiler: Received QEvent::ContextMenu";
202 if (popup->actions().size()) {
203 QMouseEvent *mouseEvent = static_cast<QMouseEvent*> (event);
204 QPoint pos = mouseEvent->globalPos();
205 pos.setX(pos.x() - 150);
213 return QObject::eventFilter(obj, event);
217 void ListWindow::onModelChanged()
219 list->setMinimumHeight(list->contentsHeight());
222 #endif // Q_WS_MAEMO_5
226 void ListWindow::show()
228 foreach (QWidget *w, QApplication::allWidgets()) {
229 w->setContextMenuPolicy(Qt::NoContextMenu);
234 #endif // Q_OS_SYMBIAN