3 #include "listwindow.h"
6 ListWindow::ListWindow(QWidget *parent): QMainWindow(parent), list(0)
9 setAttribute(Qt::WA_Maemo5StackedWindow, true);
12 QFrame *frame = new QFrame(this);
13 setCentralWidget(frame);
14 frameLayout = new QHBoxLayout(frame);
15 frame->setLayout(frameLayout);
18 buttonBox = new QDialogButtonBox(Qt::Vertical, this);
19 frameLayout->addWidget(buttonBox);
23 void ListWindow::addList(QListView *listView)
26 frameLayout->insertWidget(0, list);
27 connect(list->selectionModel(),
28 SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
30 SLOT(onSelectionChanged(const QItemSelection &, const QItemSelection&)));
33 void ListWindow::addAction(const QString &title, QObject *receiver,
34 const char *slot, QDialogButtonBox::ButtonRole role)
37 QPushButton *button = buttonBox->addButton(title, role);
38 connect(button, SIGNAL(clicked()), receiver, slot);
41 QAction *action = menuBar()->addAction(title);
42 connect(action, SIGNAL(triggered()), receiver, slot);
43 #endif // ! Q_WS_MAEMO_5
46 void ListWindow::addItemAction(const QString &title, QObject *receiver,
51 buttonBox->addButton(title, QDialogButtonBox::ActionRole);
52 connect(button, SIGNAL(clicked()), receiver, slot);
53 itemButtons.append(button);
54 activateItemButtons();
57 #endif // ! Q_WS_MAEMO_5
62 void ListWindow::closeEvent(QCloseEvent *event)
64 // Work around Maemo/Qt but: Menu items are not removed on close
69 #endif // Q_WS_MAEMO_5
71 void ListWindow::onSelectionChanged(const QItemSelection &selected,
72 const QItemSelection &deselected)
77 activateItemButtons();
83 void ListWindow::activateItemButtons()
87 enable = list->selectionModel()->hasSelection();
89 foreach (QPushButton *button, itemButtons) {
90 button->setEnabled(enable);
94 #endif // ! Q_WS_MAEMO_5