Allow editing bookmarks.
[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     /** Emitted when selection has changed. */
62     void itemSelectionChanged();
63
64 public slots:
65     /** Set the current (selected) item. */
66     void setCurrentItem(const QModelIndex &item);
67
68 protected slots:
69     void onItemActivated(const QModelIndex &);
70     void populateList();
71     void onItemSelectionChanged();
72
73 protected:
74     struct Button {
75         QString title;
76         QObject *receiver;
77         const char *slot;
78         QString iconName;
79     };
80     void insertButton(int row, const Button &button);
81 #ifdef Q_WS_MAEMO_5
82     void closeEvent(QCloseEvent *event);
83 #endif
84
85 private:
86     QListWidget *list;
87     QAbstractItemModel *mModel;
88     QList<Button> buttons;
89     QString noItems;
90 #ifdef Q_OS_SYMBIAN
91     FlickCharm *charm;
92 #endif
93     QList<QAction *>itemActions;
94 };
95
96 #endif // LISTWINDOW_H