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");
37 addItemButton(tr("Delete bookmark"), this, SLOT(onDelete()), "remove");
39 connect(this, SIGNAL(activated(const QModelIndex &)),
40 this, SLOT(onItemActivated(const QModelIndex &)));
43 void BookmarksDialog::onGo()
46 QModelIndex current = currentItem();
47 if (current.isValid()) {
48 emit goToBookmark(current.row());
53 void BookmarksDialog::onItemActivated(const QModelIndex &index)
55 switch ((new BookmarkInfoDialog(book, index.row(), this))->exec()) {
56 case BookmarkInfoDialog::GoTo:
59 case BookmarkInfoDialog::Delete:
67 void BookmarksDialog::onAdd()
70 QString text = QInputDialog::getText(this, tr("Add bookmark"),
71 tr("Note (optional):"), QLineEdit::Normal, QString(), &ok);
73 emit addBookmark(text);
78 void BookmarksDialog::onDelete(bool really)
80 QModelIndex current = currentItem();
81 if (!current.isValid()) {
85 if (QMessageBox::Yes !=
86 QMessageBox::question(this, tr("Delete bookmark"),
87 tr("Delete bookmark?"), QMessageBox::Yes | QMessageBox::No)) {
91 int row = current.row();
92 model()->removeRow(row);
93 book->deleteBookmark(row);