#include "chaptersdialog.h"
#include "book.h"
+#include "listview.h"
-ChaptersDialog::ChaptersDialog(Book *b, QWidget *parent):
- QMainWindow(parent), book(b)
+ChaptersDialog::ChaptersDialog(Book *book, QWidget *parent): ListWindow(parent)
{
-#ifdef Q_WS_MAEMO_5
- setAttribute(Qt::WA_Maemo5StackedWindow, true);
-#endif
- setWindowTitle(tr("Bookmarks"));
+ setWindowTitle(tr("Chapters"));
- QFrame *frame = new QFrame(this);
- setCentralWidget(frame);
- QHBoxLayout *horizontalLayout = new QHBoxLayout(this);
- frame->setLayout(horizontalLayout);
-
- list = new QListWidget(this);
- list->setSelectionMode(QAbstractItemView::SingleSelection);
- foreach (QString id, book->toc) {
- QString contentTitle = book->content[id].name;
- (void)new QListWidgetItem(contentTitle, list);
+ if (book) {
+ foreach (QString id, book->chapters) {
+ QString contentTitle = book->content[id].name;
+ data.append(contentTitle);
+ }
}
- horizontalLayout->addWidget(list);
- connect(list, SIGNAL(itemActivated(QListWidgetItem*)),
- this, SLOT(onItemActivated(QListWidgetItem*)));
-
-#ifndef Q_WS_MAEMO_5
- QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
- QPushButton *closeButton = buttonBox->addButton(QDialogButtonBox::Close);
- connect(closeButton, SIGNAL(clicked()), this, SLOT(onClose()));
- horizontalLayout->addWidget(buttonBox);
-#endif // Q_WS_MAEMO_5
-}
-
-void ChaptersDialog::onItemActivated(QListWidgetItem *item)
-{
- emit goToChapter(list->row(item));
- close();
+ QStringListModel *model = new QStringListModel(data, this);
+ list = new ListView;
+ list->setSelectionMode(QAbstractItemView::SingleSelection);
+ list->setModel(model);
+ list->setUniformItemSizes(true);
+ addList(list);
+ connect(list, SIGNAL(activated(const QModelIndex &)),
+ this, SLOT(onItemActivated(const QModelIndex &)));
}
-void ChaptersDialog::onClose()
+void ChaptersDialog::onItemActivated(const QModelIndex &index)
{
+ emit goToChapter(index.row());
close();
}