-#include <QtGui>
+#include <QStringListModel>
#include "chaptersdialog.h"
#include "book.h"
-ChaptersDialog::ChaptersDialog(Book *book, QWidget *parent): ListWindow(parent)
+ChaptersDialog::ChaptersDialog(Book *book, QWidget *parent):
+ ListWindow(tr("(No chapters)"), parent)
{
setWindowTitle(tr("Chapters"));
-
- list = new QListWidget(this);
- list->setSelectionMode(QAbstractItemView::SingleSelection);
if (book) {
foreach (QString id, book->chapters) {
QString contentTitle = book->content[id].name;
- (void)new QListWidgetItem(contentTitle, list);
+ data.append(contentTitle);
}
}
- addList(list);
- connect(list, SIGNAL(itemActivated(QListWidgetItem*)),
- this, SLOT(onItemActivated(QListWidgetItem*)));
-
-#ifndef Q_WS_MAEMO_5
- addAction(tr("Close"), this, SLOT(close()), QDialogButtonBox::RejectRole);
-#endif // Q_WS_MAEMO_5
+ QStringListModel *model = new QStringListModel(data, this);
+ setModel(model);
+ connect(this, SIGNAL(activated(const QModelIndex &)),
+ this, SLOT(onItemActivated(const QModelIndex &)));
}
-void ChaptersDialog::onItemActivated(QListWidgetItem *item)
+void ChaptersDialog::onItemActivated(const QModelIndex &index)
{
- emit goToChapter(list->row(item));
+ emit goToChapter(index.row());
close();
}