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)
59 Trace t("ListWindow::addList");
61 #if defined(Q_WS_MAEMO_5)
62 list->installEventFilter(this);
63 list->setMinimumHeight(list->contentsHeight());
64 contentLayout->addWidget(list);
65 connect(list->model(),
66 SIGNAL(rowsInserted(const QModelIndex &, int, int)),
67 this, SLOT(onModelChanged()));
68 connect(list->model(),
69 SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
70 this, SLOT(onModelChanged()));
72 contentLayout->insertWidget(0, list);
77 charm = new FlickCharm(this);
79 // FIXME: Charm's need more work...: charm->activateOn(list);
80 #endif // Q_OS_SYMBIAN
82 connect(list->selectionModel(),
83 SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
85 SLOT(onSelectionChanged(const QItemSelection &, const QItemSelection &)));
88 void ListWindow::addAction(const QString &title, QObject *receiver,
89 const char *slot, const QString &iconName,
90 QDialogButtonBox::ButtonRole role)
92 Trace t("ListWindow::addAction");
96 new QPushButton(QIcon(Platform::icon(iconName)), title, this);
97 contentLayout->addWidget(button);
98 connect(button, SIGNAL(clicked()), receiver, slot);
99 #elif defined(Q_OS_SYMBIAN)
102 QAction *action = new QAction(title, this);
103 connect(action, SIGNAL(triggered()), receiver, slot);
104 action->setSoftKeyRole(QAction::PositiveSoftKey);
105 menuBar()->addAction(action);
108 QPushButton *button = buttonBox->addButton(title, role);
109 connect(button, SIGNAL(clicked()), receiver, slot);
110 #endif // Q_WS_MAEMO_5
113 void ListWindow::addItemAction(const QString &title, QObject *receiver,
116 Trace t("ListWindow::addItemAction");
118 popup->addAction(title, receiver, slot);
119 #elif defined Q_OS_SYMBIAN
120 QAction *action = new QAction(title, this);
121 connect(action, SIGNAL(triggered()), receiver, slot);
122 action->setSoftKeyRole(QAction::PositiveSoftKey);
123 menuBar()->addAction(action);
124 // FIXME: Add action to the list of item specific actions
126 QPushButton *button =
127 buttonBox->addButton(title, QDialogButtonBox::ActionRole);
128 connect(button, SIGNAL(clicked()), receiver, slot);
129 itemButtons.append(button);
130 activateItemButtons();
131 #endif // Q_WS_MAEMO_5
136 void ListWindow::closeEvent(QCloseEvent *event)
138 // Work around Maemo/Qt but: Menu items are not removed on close
143 #endif // Q_WS_MAEMO_5
145 void ListWindow::onSelectionChanged(const QItemSelection &selected,
146 const QItemSelection &deselected)
149 Q_UNUSED(deselected);
151 activateItemButtons();
157 void ListWindow::activateItemButtons()
161 enable = list->selectionModel()->hasSelection();
163 foreach (QPushButton *button, itemButtons) {
164 button->setEnabled(enable);
168 #endif // ! Q_WS_MAEMO_5
172 bool ListWindow::eventFilter(QObject *obj, QEvent *event)
174 if (event->type() == QEvent::ContextMenu) {
175 qDebug() << "ListWindow::eventFiler: Received QEvent::ContextMenu";
176 if (popup->actions().size()) {
177 QMouseEvent *mouseEvent = static_cast<QMouseEvent*> (event);
178 QPoint pos = mouseEvent->globalPos();
179 pos.setX(pos.x() - 150);
187 return QObject::eventFilter(obj, event);
191 void ListWindow::onModelChanged()
193 qDebug() << "ListWindow::onModelChanged";
194 list->setMinimumHeight(list->contentsHeight());
197 #endif // Q_WS_MAEMO_5
201 void ListWindow::show()
203 foreach (QWidget *w, QApplication::allWidgets()) {
204 w->setContextMenuPolicy(Qt::NoContextMenu);
209 #endif // Q_OS_SYMBIAN