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);
34 buttonBox = new QDialogButtonBox(Qt::Vertical, this);
35 contentLayout->addWidget(buttonBox);
39 void ListWindow::addList(ListView *listView)
41 Trace t("ListWindow::addList");
44 list->installEventFilter(this);
45 list->setMinimumHeight(list->contentsHeight());
46 contentLayout->addWidget(list);
47 connect(list->model(),
48 SIGNAL(rowsInserted(const QModelIndex &, int, int)),
49 this, SLOT(onModelChanged()));
50 connect(list->model(),
51 SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
52 this, SLOT(onModelChanged()));
54 contentLayout->insertWidget(0, list);
56 connect(list->selectionModel(),
57 SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
59 SLOT(onSelectionChanged(const QItemSelection &, const QItemSelection &)));
62 void ListWindow::addAction(const QString &title, QObject *receiver,
63 const char *slot, QDialogButtonBox::ButtonRole role)
65 Trace t("ListWindow::addAction");
67 QPushButton *button = buttonBox->addButton(title, role);
68 connect(button, SIGNAL(clicked()), receiver, slot);
71 // QAction *action = menuBar()->addAction(title);
72 // connect(action, SIGNAL(triggered()), receiver, slot);
73 QPushButton *button = new QPushButton(title, this);
74 contentLayout->addWidget(button);
75 connect(button, SIGNAL(clicked()), receiver, slot);
76 #endif // ! Q_WS_MAEMO_5
79 void ListWindow::addItemAction(const QString &title, QObject *receiver,
82 Trace t("ListWindow::addItemAction");
85 buttonBox->addButton(title, QDialogButtonBox::ActionRole);
86 connect(button, SIGNAL(clicked()), receiver, slot);
87 itemButtons.append(button);
88 activateItemButtons();
90 popup->addAction(title, receiver, slot);
91 #endif // ! Q_WS_MAEMO_5
96 void ListWindow::closeEvent(QCloseEvent *event)
98 // Work around Maemo/Qt but: Menu items are not removed on close
103 #endif // Q_WS_MAEMO_5
105 void ListWindow::onSelectionChanged(const QItemSelection &selected,
106 const QItemSelection &deselected)
109 Q_UNUSED(deselected);
111 activateItemButtons();
117 void ListWindow::activateItemButtons()
121 enable = list->selectionModel()->hasSelection();
123 foreach (QPushButton *button, itemButtons) {
124 button->setEnabled(enable);
128 #endif // ! Q_WS_MAEMO_5
132 bool ListWindow::eventFilter(QObject *obj, QEvent *event)
134 if (event->type() == QEvent::ContextMenu) {
135 qDebug() << "ListWindow::eventFiler: Received QEvent::ContextMenu";
136 if (popup->actions().size()) {
137 QMouseEvent *mouseEvent = static_cast<QMouseEvent*> (event);
138 QPoint pos = mouseEvent->globalPos();
139 pos.setX(pos.x() - 150);
147 return QObject::eventFilter(obj, event);
151 void ListWindow::onModelChanged()
153 qDebug() << "ListWindow::onModelChanged";
154 list->setMinimumHeight(list->contentsHeight());
157 #endif // Q_WS_MAEMO_5