3b3c23518cbb8bc50db424d363308becd9a4f0ff
[dorian] / widgets / listwindow.h
1 #ifndef LISTWINDOW_H
2 #define LISTWINDOW_H
3
4 #include <QMainWindow>
5 #include <QDialogButtonBox>
6 #include <QList>
7
8 class QString;
9 class QPushButton;
10 class FlickCharm;
11 class QAbstractItemModel;
12 class QListWidget;
13 class QModelIndex;
14
15 /** A window with a list and menu actions (Maemo) or buttons (non-Maemo). */
16 class ListWindow: public QMainWindow
17 {
18     Q_OBJECT
19
20 public:
21     /**
22      * Constructor.
23      * @param   noItems Text to display when the list has no items.
24      * @param   parent  Parent widget.
25      */
26     explicit ListWindow(const QString &noItems, QWidget *parent = 0);
27
28     /** Set the model for the list. */
29     void setModel(QAbstractItemModel *model);
30
31     /** Get model. */
32     QAbstractItemModel *model() const;
33
34     /** Add an action button to the beginning of the list. */
35     void addButton(const QString &title, QObject *receiver, const char *slot,
36                    const QString &iconPath = QString());
37
38     /** Add an action to the menu. */
39     QAction *addMenuAction(const QString &title, QObject *receiver,
40                            const char *slot);
41
42     /** Get current (selected) item. */
43     QModelIndex currentItem() const;
44
45 signals:
46     /** Emitted when a list item is activated. */
47     void activated(const QModelIndex &index);
48
49 public slots:
50     /** Set the current (selected) item. */
51     void setCurrentItem(const QModelIndex &item);
52
53 #ifdef Q_OS_SYMBIAN
54     void show();
55 #endif
56
57 protected slots:
58     void onItemActivated(const QModelIndex &);
59     void populateList();
60
61 protected:
62     struct Button {
63         QString title;
64         QObject *receiver;
65         const char *slot;
66         QString iconName;
67     };
68     void insertButton(int row, const Button &button);
69 #ifdef Q_WS_MAEMO_5
70     void closeEvent(QCloseEvent *event);
71 #endif
72
73 private:
74     QListWidget *list;
75     QAbstractItemModel *mModel;
76     QList<Button> buttons;
77     QString noItems;
78 #ifdef Q_OS_SYMBIAN
79     FlickCharm *charm;
80 #endif
81 };
82
83 #endif // LISTWINDOW_H