X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=widgets%2Flistwindow.h;h=f8d8ab4d42272b7152996d58c2ed3d1d59dcb2e2;hb=a972500f457b9d2259d3e7f6ea87624bd9a6f7d2;hp=c9c958e7b6afc9c8c66161edae87ba31af416476;hpb=1b87d7b714dec027c3e188ac1b11c6f3fb4810d8;p=dorian diff --git a/widgets/listwindow.h b/widgets/listwindow.h index c9c958e..f8d8ab4 100644 --- a/widgets/listwindow.h +++ b/widgets/listwindow.h @@ -1,77 +1,92 @@ #ifndef LISTWINDOW_H #define LISTWINDOW_H -#include +#include "mainbase.h" + #include #include -class QListView; class QString; -class QBoxLayout; class QPushButton; -class QModelIndex; -class QItemSelection; -class QEvent; -class ListView; class FlickCharm; +class QAbstractItemModel; +class QListWidget; +class QModelIndex; +class QListWidgetItem; /** A window with a list and menu actions (Maemo) or buttons (non-Maemo). */ -class ListWindow: public QMainWindow +class ListWindow: public MainBase { Q_OBJECT public: - explicit ListWindow(QWidget *parent = 0); + /** + * Constructor. + * @param noItems Text to display when the list has no items. + * @param parent Parent widget. + */ + explicit ListWindow(const QString &noItems, QWidget *parent = 0); + + /** Set the model for the list. */ + void setModel(QAbstractItemModel *model); - /** Add a list view to the window. */ - void addList(ListView *list); + /** Get model. */ + QAbstractItemModel *model() const; /** - * Add an action to the window: either a button, or, on Maemo, a top - * level menu item. - * Activating the action invokes the slot with no parameters. + * Add an action button to the beginning of the list (Maemo) or to the + * tool bar (non-Maemo). */ - void addAction(const QString &title, QObject *receiver, const char *slot, - const QString &iconPath = QString(), - QDialogButtonBox::ButtonRole role = QDialogButtonBox::ActionRole); + void addButton(const QString &title, QObject *receiver, const char *slot, + const QString &iconPath = QString()); /** - * Add an action to the selected item in the list: either a button which is - * enabled when a list item is selected, or, on Maemo, a pop-up menu item - * which is displayed when a list item is long-pressed. - * Activating the action invokes the slot with no parameters. + * Add an action button to the tool bar, which is only active if a list + * item is selected. */ - void addItemAction(const QString &title, QObject *receiver, - const char *slot); + void addItemButton(const QString &title, QObject *receiver, + const char *slot, const QString &iconPath = QString()); + + /** Add an action to the menu. */ + QAction *addMenuAction(const QString &title, QObject *receiver, + const char *slot); + + /** Get current (selected) item. */ + QModelIndex currentItem() const; + +signals: + /** Emitted when a list item is activated. */ + void activated(const QModelIndex &index); public slots: -#ifdef Q_OS_SYMBIAN - void show(); -#endif + /** Set the current (selected) item. */ + void setCurrentItem(const QModelIndex &item); protected slots: - void onSelectionChanged(const QItemSelection &selected, - const QItemSelection &deselected); -#ifdef Q_WS_MAEMO_5 - void onModelChanged(); -#else - void activateItemButtons(); -#endif + void onItemActivated(const QModelIndex &); + void populateList(); protected: + struct Button { + QString title; + QObject *receiver; + const char *slot; + QString iconName; + }; + void insertButton(int row, const Button &button); #ifdef Q_WS_MAEMO_5 - bool eventFilter(QObject *obj, QEvent *event); void closeEvent(QCloseEvent *event); - QMenu *popup; -#else - QDialogButtonBox *buttonBox; - QList itemButtons; -#endif // Q_WS_MAEMO_5 +#endif + +private: + QListWidget *list; + QAbstractItemModel *mModel; + QList