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