Restore bookmarks to the correct position.
[dorian] / chaptersdialog.cpp
1 #include <QtGui>
2
3 #include "chaptersdialog.h"
4 #include "book.h"
5
6 ChaptersDialog::ChaptersDialog(Book *b, QWidget *parent):
7     QMainWindow(parent), book(b)
8 {
9 #ifdef Q_WS_MAEMO_5
10     setAttribute(Qt::WA_Maemo5StackedWindow, true);
11 #endif
12     setWindowTitle(tr("Bookmarks"));
13
14     QFrame *frame = new QFrame(this);
15     setCentralWidget(frame);
16     QHBoxLayout *horizontalLayout = new QHBoxLayout(frame);
17     frame->setLayout(horizontalLayout);
18
19     list = new QListWidget(this);
20     list->setSelectionMode(QAbstractItemView::SingleSelection);
21     foreach (QString id, book->toc) {
22         QString contentTitle = book->content[id].name;
23         (void)new QListWidgetItem(contentTitle, list);
24     }
25     horizontalLayout->addWidget(list);
26     connect(list, SIGNAL(itemActivated(QListWidgetItem*)),
27             this, SLOT(onItemActivated(QListWidgetItem*)));
28
29 #ifndef Q_WS_MAEMO_5
30     QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
31     QPushButton *closeButton = buttonBox->addButton(QDialogButtonBox::Close);
32     connect(closeButton, SIGNAL(clicked()), this, SLOT(onClose()));
33     horizontalLayout->addWidget(buttonBox);
34 #endif // Q_WS_MAEMO_5
35 }
36
37 void ChaptersDialog::onItemActivated(QListWidgetItem *item)
38 {
39     emit goToChapter(list->row(item));
40     close();
41 }
42
43 void ChaptersDialog::onClose()
44 {
45     close();
46 }