Introduce ListWidget.
[dorian] / chaptersdialog.cpp
1 #include <QtGui>
2
3 #include "chaptersdialog.h"
4 #include "book.h"
5
6 ChaptersDialog::ChaptersDialog(Book *book, QWidget *parent): ListWindow(parent)
7 {
8     setWindowTitle(tr("Chapters"));
9
10     list = new QListWidget(this);
11     list->setSelectionMode(QAbstractItemView::SingleSelection);
12     if (book) {
13         foreach (QString id, book->toc) {
14             QString contentTitle = book->content[id].name;
15             (void)new QListWidgetItem(contentTitle, list);
16         }
17     }
18     addList(list);
19     connect(list, SIGNAL(itemActivated(QListWidgetItem*)),
20             this, SLOT(onItemActivated(QListWidgetItem*)));
21
22 #ifndef Q_WS_MAEMO_5
23     addAction(tr("Close"), this, SLOT(close()), QDialogButtonBox::RejectRole);
24 #endif // Q_WS_MAEMO_5
25 }
26
27 void ChaptersDialog::onItemActivated(QListWidgetItem *item)
28 {
29     emit goToChapter(list->row(item));
30     close();
31 }