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 buttonBox = new QDialogButtonBox(Qt::Vertical, this);
36 contentLayout->addWidget(buttonBox);
37 #endif // Q_OS_SYMBIAN
38 #endif // Q_WS_MAEMO_5
41 void ListWindow::addList(ListView *listView)
43 Trace t("ListWindow::addList");
46 list->installEventFilter(this);
47 list->setMinimumHeight(list->contentsHeight());
48 contentLayout->addWidget(list);
49 connect(list->model(),
50 SIGNAL(rowsInserted(const QModelIndex &, int, int)),
51 this, SLOT(onModelChanged()));
52 connect(list->model(),
53 SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
54 this, SLOT(onModelChanged()));
56 contentLayout->insertWidget(0, list);
58 connect(list->selectionModel(),
59 SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
61 SLOT(onSelectionChanged(const QItemSelection &, const QItemSelection &)));
64 void ListWindow::addAction(const QString &title, QObject *receiver,
65 const char *slot, const QString &iconPath,
66 QDialogButtonBox::ButtonRole role)
68 Trace t("ListWindow::addAction");
71 QPushButton *button = new QPushButton(QIcon(iconPath), title, this);
72 contentLayout->addWidget(button);
73 connect(button, SIGNAL(clicked()), receiver, slot);
74 #elif defined(Q_OS_SYMBIAN)
76 QAction *action = new QAction(title, this);
77 connect(action, SIGNAL(triggered()), receiver, slot);
78 action->setSoftKeyRole(QAction::PositiveSoftKey);
79 menuBar()->addAction(action);
82 QPushButton *button = buttonBox->addButton(title, role);
83 connect(button, SIGNAL(clicked()), receiver, slot);
84 #endif // Q_WS_MAEMO_5
87 void ListWindow::addItemAction(const QString &title, QObject *receiver,
90 Trace t("ListWindow::addItemAction");
92 popup->addAction(title, receiver, slot);
93 #elif defined Q_OS_SYMBIAN
94 QAction *action = new QAction(title, this);
95 connect(action, SIGNAL(triggered()), receiver, slot);
96 action->setSoftKeyRole(QAction::PositiveSoftKey);
97 menuBar()->addAction(action);
98 // FIXME: Add action to the list of item specific actions
100 QPushButton *button =
101 buttonBox->addButton(title, QDialogButtonBox::ActionRole);
102 connect(button, SIGNAL(clicked()), receiver, slot);
103 itemButtons.append(button);
104 activateItemButtons();
105 #endif // Q_WS_MAEMO_5
110 void ListWindow::closeEvent(QCloseEvent *event)
112 // Work around Maemo/Qt but: Menu items are not removed on close
117 #endif // Q_WS_MAEMO_5
119 void ListWindow::onSelectionChanged(const QItemSelection &selected,
120 const QItemSelection &deselected)
123 Q_UNUSED(deselected);
125 activateItemButtons();
131 void ListWindow::activateItemButtons()
135 enable = list->selectionModel()->hasSelection();
137 foreach (QPushButton *button, itemButtons) {
138 button->setEnabled(enable);
142 #endif // ! Q_WS_MAEMO_5
146 bool ListWindow::eventFilter(QObject *obj, QEvent *event)
148 if (event->type() == QEvent::ContextMenu) {
149 qDebug() << "ListWindow::eventFiler: Received QEvent::ContextMenu";
150 if (popup->actions().size()) {
151 QMouseEvent *mouseEvent = static_cast<QMouseEvent*> (event);
152 QPoint pos = mouseEvent->globalPos();
153 pos.setX(pos.x() - 150);
161 return QObject::eventFilter(obj, event);
165 void ListWindow::onModelChanged()
167 qDebug() << "ListWindow::onModelChanged";
168 list->setMinimumHeight(list->contentsHeight());
171 #endif // Q_WS_MAEMO_5
175 void ListWindow::show()
180 #endif // Q_OS_SYMBIAN