Improve traces. Simplify folder management.
[dorian] / chaptersdialog.cpp
index 0b972d7..2f279e0 100644 (file)
@@ -2,30 +2,34 @@
 
 #include "chaptersdialog.h"
 #include "book.h"
+#include "listview.h"
 
 ChaptersDialog::ChaptersDialog(Book *book, QWidget *parent): ListWindow(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);
         }
     }
+    QStringListModel *model = new QStringListModel(data, this);
+    list = new ListView;
+    list->setSelectionMode(QAbstractItemView::SingleSelection);
+    list->setModel(model);
+    list->setUniformItemSizes(true);
     addList(list);
-    connect(list, SIGNAL(itemActivated(QListWidgetItem*)),
-            this, SLOT(onItemActivated(QListWidgetItem*)));
+    connect(list, SIGNAL(activated(const QModelIndex &)),
+            this, SLOT(onItemActivated(const QModelIndex &)));
 
 #ifndef Q_WS_MAEMO_5
     addAction(tr("Close"), this, SLOT(close()), QDialogButtonBox::RejectRole);
 #endif // Q_WS_MAEMO_5
 }
 
-void ChaptersDialog::onItemActivated(QListWidgetItem *item)
+void ChaptersDialog::onItemActivated(const QModelIndex &index)
 {
-    emit goToChapter(list->row(item));
+    emit goToChapter(index.row());
     close();
 }