3 #include "listwindow.h"
7 ListWindow::ListWindow(QWidget *parent): QMainWindow(parent), list(0)
10 setAttribute(Qt::WA_Maemo5StackedWindow, true);
11 popup = new QMenu(this);
13 QScrollArea *scroller = new QScrollArea(this);
14 setCentralWidget(scroller);
15 scroller->setProperty("FingerScrollable", true);
16 // scroller->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
17 // scroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
18 scroller->setFrameStyle(QFrame::NoFrame);
21 QWidget *content = new QWidget(scroller);
22 contentLayout = new QVBoxLayout(content);
23 contentLayout->setMargin(0);
24 content->setLayout(contentLayout);
27 scroller->setWidget(content);
28 scroller->setWidgetResizable(true);
30 QFrame *frame = new QFrame(this);
31 setCentralWidget(frame);
32 contentLayout = new QHBoxLayout();
33 frame->setLayout(contentLayout);
35 QAction *closeAction = new QAction(parent? tr("Back"): tr("Exit"), this);
36 closeAction->setSoftKeyRole(QAction::NegativeSoftKey);
37 connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
38 QMainWindow::addAction(closeAction);
40 buttonBox = new QDialogButtonBox(Qt::Vertical, this);
41 contentLayout->addWidget(buttonBox);
42 #endif // Q_OS_SYMBIAN
43 #endif // Q_WS_MAEMO_5
46 void ListWindow::addList(ListView *listView)
48 Trace t("ListWindow::addList");
51 list->installEventFilter(this);
52 list->setMinimumHeight(list->contentsHeight());
53 contentLayout->addWidget(list);
54 connect(list->model(),
55 SIGNAL(rowsInserted(const QModelIndex &, int, int)),
56 this, SLOT(onModelChanged()));
57 connect(list->model(),
58 SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
59 this, SLOT(onModelChanged()));
61 contentLayout->insertWidget(0, list);
63 connect(list->selectionModel(),
64 SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
66 SLOT(onSelectionChanged(const QItemSelection &, const QItemSelection &)));
69 void ListWindow::addAction(const QString &title, QObject *receiver,
70 const char *slot, const QString &iconPath,
71 QDialogButtonBox::ButtonRole role)
73 Trace t("ListWindow::addAction");
76 QPushButton *button = new QPushButton(QIcon(iconPath), title, this);
77 contentLayout->addWidget(button);
78 connect(button, SIGNAL(clicked()), receiver, slot);
79 #elif defined(Q_OS_SYMBIAN)
81 QAction *action = new QAction(title, this);
82 connect(action, SIGNAL(triggered()), receiver, slot);
83 action->setSoftKeyRole(QAction::PositiveSoftKey);
84 menuBar()->addAction(action);
87 QPushButton *button = buttonBox->addButton(title, role);
88 connect(button, SIGNAL(clicked()), receiver, slot);
89 #endif // Q_WS_MAEMO_5
92 void ListWindow::addItemAction(const QString &title, QObject *receiver,
95 Trace t("ListWindow::addItemAction");
97 popup->addAction(title, receiver, slot);
98 #elif defined Q_OS_SYMBIAN
99 QAction *action = new QAction(title, this);
100 connect(action, SIGNAL(triggered()), receiver, slot);
101 action->setSoftKeyRole(QAction::PositiveSoftKey);
102 menuBar()->addAction(action);
103 // FIXME: Add action to the list of item specific actions
105 QPushButton *button =
106 buttonBox->addButton(title, QDialogButtonBox::ActionRole);
107 connect(button, SIGNAL(clicked()), receiver, slot);
108 itemButtons.append(button);
109 activateItemButtons();
110 #endif // Q_WS_MAEMO_5
115 void ListWindow::closeEvent(QCloseEvent *event)
117 // Work around Maemo/Qt but: Menu items are not removed on close
122 #endif // Q_WS_MAEMO_5
124 void ListWindow::onSelectionChanged(const QItemSelection &selected,
125 const QItemSelection &deselected)
128 Q_UNUSED(deselected);
130 activateItemButtons();
136 void ListWindow::activateItemButtons()
140 enable = list->selectionModel()->hasSelection();
142 foreach (QPushButton *button, itemButtons) {
143 button->setEnabled(enable);
147 #endif // ! Q_WS_MAEMO_5
151 bool ListWindow::eventFilter(QObject *obj, QEvent *event)
153 if (event->type() == QEvent::ContextMenu) {
154 qDebug() << "ListWindow::eventFiler: Received QEvent::ContextMenu";
155 if (popup->actions().size()) {
156 QMouseEvent *mouseEvent = static_cast<QMouseEvent*> (event);
157 QPoint pos = mouseEvent->globalPos();
158 pos.setX(pos.x() - 150);
166 return QObject::eventFilter(obj, event);
170 void ListWindow::onModelChanged()
172 qDebug() << "ListWindow::onModelChanged";
173 list->setMinimumHeight(list->contentsHeight());
176 #endif // Q_WS_MAEMO_5
180 void ListWindow::show()
182 foreach (QWidget *w, QApplication::allWidgets()) {
183 w->setContextMenuPolicy(Qt::NoContextMenu);
188 #endif // Q_OS_SYMBIAN