3 #include "listwindow.h"
8 ListWindow::ListWindow(QWidget *parent): QMainWindow(parent), list(0)
11 setAttribute(Qt::WA_Maemo5StackedWindow, true);
12 popup = new QMenu(this);
14 QScrollArea *scroller = new QScrollArea(this);
15 setCentralWidget(scroller);
16 scroller->setProperty("FingerScrollable", true);
17 // scroller->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
18 // scroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
19 scroller->setFrameStyle(QFrame::NoFrame);
22 QWidget *content = new QWidget(scroller);
23 contentLayout = new QVBoxLayout(content);
24 contentLayout->setMargin(0);
25 content->setLayout(contentLayout);
28 scroller->setWidget(content);
29 scroller->setWidgetResizable(true);
31 QFrame *frame = new QFrame(this);
32 setCentralWidget(frame);
33 contentLayout = new QHBoxLayout();
34 frame->setLayout(contentLayout);
36 QAction *closeAction = new QAction(parent? tr("Back"): tr("Exit"), this);
37 closeAction->setSoftKeyRole(QAction::NegativeSoftKey);
38 connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
39 QMainWindow::addAction(closeAction);
41 buttonBox = new QDialogButtonBox(Qt::Vertical, this);
42 contentLayout->addWidget(buttonBox);
43 # endif // Q_OS_SYMBIAN
44 #endif // Q_WS_MAEMO_5
47 addAction(tr("Close"), this, SLOT(close()), QString(),
48 QDialogButtonBox::RejectRole);
52 void ListWindow::addList(ListView *listView)
54 Trace t("ListWindow::addList");
57 list->installEventFilter(this);
58 list->setMinimumHeight(list->contentsHeight());
59 contentLayout->addWidget(list);
60 connect(list->model(),
61 SIGNAL(rowsInserted(const QModelIndex &, int, int)),
62 this, SLOT(onModelChanged()));
63 connect(list->model(),
64 SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
65 this, SLOT(onModelChanged()));
67 contentLayout->insertWidget(0, list);
69 connect(list->selectionModel(),
70 SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
72 SLOT(onSelectionChanged(const QItemSelection &, const QItemSelection &)));
75 void ListWindow::addAction(const QString &title, QObject *receiver,
76 const char *slot, const QString &iconName,
77 QDialogButtonBox::ButtonRole role)
79 Trace t("ListWindow::addAction");
83 new QPushButton(QIcon(Platform::icon(iconName)), title, this);
84 contentLayout->addWidget(button);
85 connect(button, SIGNAL(clicked()), receiver, slot);
86 #elif defined(Q_OS_SYMBIAN)
89 QAction *action = new QAction(title, this);
90 connect(action, SIGNAL(triggered()), receiver, slot);
91 action->setSoftKeyRole(QAction::PositiveSoftKey);
92 menuBar()->addAction(action);
95 QPushButton *button = buttonBox->addButton(title, role);
96 connect(button, SIGNAL(clicked()), receiver, slot);
97 #endif // Q_WS_MAEMO_5
100 void ListWindow::addItemAction(const QString &title, QObject *receiver,
103 Trace t("ListWindow::addItemAction");
105 popup->addAction(title, receiver, slot);
106 #elif defined Q_OS_SYMBIAN
107 QAction *action = new QAction(title, this);
108 connect(action, SIGNAL(triggered()), receiver, slot);
109 action->setSoftKeyRole(QAction::PositiveSoftKey);
110 menuBar()->addAction(action);
111 // FIXME: Add action to the list of item specific actions
113 QPushButton *button =
114 buttonBox->addButton(title, QDialogButtonBox::ActionRole);
115 connect(button, SIGNAL(clicked()), receiver, slot);
116 itemButtons.append(button);
117 activateItemButtons();
118 #endif // Q_WS_MAEMO_5
123 void ListWindow::closeEvent(QCloseEvent *event)
125 // Work around Maemo/Qt but: Menu items are not removed on close
130 #endif // Q_WS_MAEMO_5
132 void ListWindow::onSelectionChanged(const QItemSelection &selected,
133 const QItemSelection &deselected)
136 Q_UNUSED(deselected);
138 activateItemButtons();
144 void ListWindow::activateItemButtons()
148 enable = list->selectionModel()->hasSelection();
150 foreach (QPushButton *button, itemButtons) {
151 button->setEnabled(enable);
155 #endif // ! Q_WS_MAEMO_5
159 bool ListWindow::eventFilter(QObject *obj, QEvent *event)
161 if (event->type() == QEvent::ContextMenu) {
162 qDebug() << "ListWindow::eventFiler: Received QEvent::ContextMenu";
163 if (popup->actions().size()) {
164 QMouseEvent *mouseEvent = static_cast<QMouseEvent*> (event);
165 QPoint pos = mouseEvent->globalPos();
166 pos.setX(pos.x() - 150);
174 return QObject::eventFilter(obj, event);
178 void ListWindow::onModelChanged()
180 qDebug() << "ListWindow::onModelChanged";
181 list->setMinimumHeight(list->contentsHeight());
184 #endif // Q_WS_MAEMO_5
188 void ListWindow::show()
190 foreach (QWidget *w, QApplication::allWidgets()) {
191 w->setContextMenuPolicy(Qt::NoContextMenu);
196 #endif // Q_OS_SYMBIAN