Introduce ListWidget.
[dorian] / widgets / listwindow.cpp
1 #include <QtGui>
2
3 #include "listwindow.h"
4 #include "trace.h"
5
6 ListWindow::ListWindow(QWidget *parent): QMainWindow(parent)
7 {
8 #ifdef Q_WS_MAEMO_5
9     setAttribute(Qt::WA_Maemo5StackedWindow, true);
10 #endif
11
12     QFrame *frame = new QFrame(this);
13     setCentralWidget(frame);
14     layout = new QHBoxLayout(frame);
15     frame->setLayout(layout);
16
17 #ifndef Q_WS_MAEMO_5
18     buttonBox = new QDialogButtonBox(Qt::Vertical, this);
19     layout->addWidget(buttonBox);
20 #endif
21 }
22
23 void ListWindow::addList(QListView *list)
24 {
25     layout->insertWidget(0, list);
26 }
27
28 void ListWindow::addAction(const QString &title, QObject *receiver,
29                            const char *slot, QDialogButtonBox::ButtonRole role)
30 {
31 #ifndef Q_WS_MAEMO_5
32     QPushButton *button = new QPushButton(title, this);
33     QList<QAction *> actions = button->actions();
34     Trace::trace(QString("ListWindow::addAction: Button has %1 default action(s)").arg(actions.length()));
35     buttonBox->addButton(button, role);
36     connect(button, SIGNAL(clicked()), receiver, slot);
37 #else
38     Q_UNUSED(role);
39     QAction *action = menuBar()->addAction(title);
40     connect(action, SIGNAL(triggered()), receiver, slot);
41 #endif // Q_WS_MAEMO_5
42 }
43
44 #ifdef Q_WS_MAEMO_5
45
46 void ListWindow::closeEvent(QCloseEvent *event)
47 {
48     // Work around Maemo/Qt but: Menu items are not removed on close
49     menuBar()->clear();
50     event->accept();
51 }
52
53 #endif // Q_WS_MAEMO_5