New version. Have and overlap between current/next page.
[dorian] / bookmarksdialog.cpp
index 6e22e93..f125ed9 100644 (file)
@@ -3,53 +3,46 @@
 #include "bookmarksdialog.h"
 #include "book.h"
 #include "bookmarkinfodialog.h"
-#include "listview.h"
+#include "trace.h"
 
 BookmarksDialog::BookmarksDialog(Book *book_, QWidget *parent):
-    ListWindow(parent), book(book_)
+    ListWindow(tr("(No bookmarks)\n"), parent), book(book_)
 {
     setWindowTitle(tr("Bookmarks"));
     if (!book) {
         return;
     }
 
-    addAction(tr("Add bookmark"), this, SLOT(onAdd()), ":/icons/add.png");
-#ifndef Q_WS_MAEMO_5
-    addItemAction(tr("Go to"), this, SLOT(onGo()));
-    addItemAction(tr("Delete"), this, SLOT(onDelete()));
-#endif // ! Q_WS_MAEMO_5
-
-    // Build bookmark list
+    // Build and set bookmark model
     // FIXME: Localize me
     foreach (Book::Bookmark bookmark, book_->bookmarks()) {
         QString label("At ");
         label += QString::number((int)(100 * book_->
             getProgress(bookmark.part, bookmark.pos))) + "%";
+        if (!bookmark.note.isEmpty()) {
+            label += ": " + bookmark.note;
+        }
+        label += "\n";
         int chapterIndex = book_->chapterFromPart(bookmark.part);
         if (chapterIndex != -1) {
             QString chapterId = book_->chapters[chapterIndex];
-            label += ", in \"" + book_->content[chapterId].name + "\"";
-        }
-        if (!bookmark.note.isEmpty()) {
-            label += "\n" + bookmark.note;
+            label += "In \"" + book_->content[chapterId].name + "\"";
         }
         data.append(label);
     }
-
-    // Create bookmark list view
     QStringListModel *model = new QStringListModel(data, this);
-    list = new ListView;
-    list->setSelectionMode(QAbstractItemView::SingleSelection);
-    list->setModel(model);
-    addList(list);
-    connect(list, SIGNAL(activated(const QModelIndex &)),
+    setModel(model);
+
+    addButton(tr("Add bookmark"), this, SLOT(onAdd()), "add");
+
+    connect(this, SIGNAL(activated(const QModelIndex &)),
             this, SLOT(onItemActivated(const QModelIndex &)));
-    addList(list);
 }
 
 void BookmarksDialog::onGo()
 {
-    QModelIndex current = list->currentIndex();
+    TRACE;
+    QModelIndex current = currentItem();
     if (current.isValid()) {
         emit goToBookmark(current.row());
         close();
@@ -74,8 +67,7 @@ void BookmarksDialog::onAdd()
 {
     bool ok;
     QString text = QInputDialog::getText(this, tr("Add bookmark"),
-                                         tr("Note:"), QLineEdit::Normal,
-                                         QString(), &ok);
+        tr("Note (optional):"), QLineEdit::Normal, QString(), &ok);
     if (ok) {
         emit addBookmark(text);
         close();
@@ -84,7 +76,7 @@ void BookmarksDialog::onAdd()
 
 void BookmarksDialog::onDelete(bool really)
 {
-    QModelIndex current = list->currentIndex();
+    QModelIndex current = currentItem();
     if (!current.isValid()) {
         return;
     }
@@ -96,6 +88,6 @@ void BookmarksDialog::onDelete(bool really)
         }
     }
     int row = current.row();
-    list->model()->removeRow(row);
+    model()->removeRow(row);
     book->deleteBookmark(row);
 }