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