3 #include "bookmarksdialog.h"
5 #include "bookmarkinfodialog.h"
8 BookmarksDialog::BookmarksDialog(Book *book_, QWidget *parent):
9 ListWindow(parent), book(book_)
11 setWindowTitle(tr("Bookmarks"));
16 addButton(tr("Add bookmark"), this, SLOT(onAdd()), "add");
18 // Build and set bookmark model
20 foreach (Book::Bookmark bookmark, book_->bookmarks()) {
22 label += QString::number((int)(100 * book_->
23 getProgress(bookmark.part, bookmark.pos))) + "%";
24 if (!bookmark.note.isEmpty()) {
25 label += ": " + bookmark.note;
28 int chapterIndex = book_->chapterFromPart(bookmark.part);
29 if (chapterIndex != -1) {
30 QString chapterId = book_->chapters[chapterIndex];
31 label += "In \"" + book_->content[chapterId].name + "\"";
35 QStringListModel *model = new QStringListModel(data, this);
39 // connect(list, SIGNAL(activated(const QModelIndex &)),
40 // this, SLOT(onItemActivated(const QModelIndex &)));
43 void BookmarksDialog::onGo()
47 // QModelIndex current = list->currentIndex();
48 // if (current.isValid()) {
49 // emit goToBookmark(current.row());
54 void BookmarksDialog::onItemActivated(const QModelIndex &index)
56 switch ((new BookmarkInfoDialog(book, index.row(), this))->exec()) {
57 case BookmarkInfoDialog::GoTo:
60 case BookmarkInfoDialog::Delete:
68 void BookmarksDialog::onAdd()
71 QString text = QInputDialog::getText(this, tr("Add bookmark"),
72 tr("Note (optional):"), QLineEdit::Normal, QString(), &ok);
74 emit addBookmark(text);
79 void BookmarksDialog::onDelete(bool really)
81 QModelIndex current = list->currentIndex();
82 if (!current.isValid()) {
86 if (QMessageBox::Yes !=
87 QMessageBox::question(this, tr("Delete bookmark"),
88 tr("Delete bookmark?"), QMessageBox::Yes | QMessageBox::No)) {
92 int row = current.row();
93 list->model()->removeRow(row);
94 book->deleteBookmark(row);