3 #include "bookmarksdialog.h"
5 #include "bookmarkinfodialog.h"
8 BookmarksDialog::BookmarksDialog(Book *book_, QWidget *parent):
9 ListWindow(tr("(No bookmarks)\n"), parent), book(book_)
11 setWindowTitle(tr("Bookmarks"));
16 // Build and set bookmark model
18 foreach (Book::Bookmark bookmark, book_->bookmarks()) {
20 label += QString::number((int)(100 * book_->
21 getProgress(bookmark.part, bookmark.pos))) + "%";
22 if (!bookmark.note.isEmpty()) {
23 label += ": " + bookmark.note;
26 int chapterIndex = book_->chapterFromPart(bookmark.part);
27 if (chapterIndex != -1) {
28 QString chapterId = book_->chapters[chapterIndex];
29 label += "In \"" + book_->content[chapterId].name + "\"";
33 QStringListModel *model = new QStringListModel(data, this);
36 addButton(tr("Add bookmark"), this, SLOT(onAdd()), "add");
38 connect(this, SIGNAL(activated(const QModelIndex &)),
39 this, SLOT(onItemActivated(const QModelIndex &)));
42 void BookmarksDialog::onGo()
45 QModelIndex current = currentItem();
46 if (current.isValid()) {
47 emit goToBookmark(current.row());
52 void BookmarksDialog::onItemActivated(const QModelIndex &index)
54 switch ((new BookmarkInfoDialog(book, index.row(), this))->exec()) {
55 case BookmarkInfoDialog::GoTo:
58 case BookmarkInfoDialog::Delete:
66 void BookmarksDialog::onAdd()
69 QString text = QInputDialog::getText(this, tr("Add bookmark"),
70 tr("Note (optional):"), QLineEdit::Normal, QString(), &ok);
72 emit addBookmark(text);
77 void BookmarksDialog::onDelete(bool really)
79 QModelIndex current = currentItem();
80 if (!current.isValid()) {
84 if (QMessageBox::Yes !=
85 QMessageBox::question(this, tr("Delete bookmark"),
86 tr("Delete bookmark?"), QMessageBox::Yes | QMessageBox::No)) {
90 int row = current.row();
91 model()->removeRow(row);
92 book->deleteBookmark(row);