Fix forward navigation control on Linux.
[dorian] / chaptersdialog.cpp
index a769421..20f7824 100644 (file)
@@ -1,46 +1,26 @@
-#include <QtGui>
+#include <QStringListModel>
 
 #include "chaptersdialog.h"
 #include "book.h"
 
-ChaptersDialog::ChaptersDialog(Book *b, QWidget *parent):
-    QMainWindow(parent), book(b)
+ChaptersDialog::ChaptersDialog(Book *book, QWidget *parent):
+        ListWindow(tr("(No chapters)"), parent)
 {
-#ifdef Q_WS_MAEMO_5
-    setAttribute(Qt::WA_Maemo5StackedWindow, true);
-#endif
-    setWindowTitle(tr("Bookmarks"));
-
-    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);
+    setWindowTitle(tr("Chapters"));
+    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);
+    setModel(model);
+    connect(this, SIGNAL(activated(const QModelIndex &)),
+            this, SLOT(onItemActivated(const QModelIndex &)));
 }
 
-void ChaptersDialog::onClose()
+void ChaptersDialog::onItemActivated(const QModelIndex &index)
 {
+    emit goToChapter(index.row());
     close();
 }