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 addAction(tr("Add bookmark"), this, SLOT(onAdd()), "add");
18 // Build bookmark list
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 + "\"";
36 // Create bookmark list view
37 QStringListModel *model = new QStringListModel(data, this);
39 list->setSelectionMode(QAbstractItemView::SingleSelection);
40 list->setModel(model);
42 connect(list, SIGNAL(activated(const QModelIndex &)),
43 this, SLOT(onItemActivated(const QModelIndex &)));
47 void BookmarksDialog::onGo()
49 QModelIndex current = list->currentIndex();
50 if (current.isValid()) {
51 emit goToBookmark(current.row());
56 void BookmarksDialog::onItemActivated(const QModelIndex &index)
58 switch ((new BookmarkInfoDialog(book, index.row(), this))->exec()) {
59 case BookmarkInfoDialog::GoTo:
62 case BookmarkInfoDialog::Delete:
70 void BookmarksDialog::onAdd()
73 QString text = QInputDialog::getText(this, tr("Add bookmark"),
74 tr("Note (optional):"), QLineEdit::Normal, QString(), &ok);
76 emit addBookmark(text);
81 void BookmarksDialog::onDelete(bool really)
83 QModelIndex current = list->currentIndex();
84 if (!current.isValid()) {
88 if (QMessageBox::Yes !=
89 QMessageBox::question(this, tr("Delete bookmark"),
90 tr("Delete bookmark?"), QMessageBox::Yes | QMessageBox::No)) {
94 int row = current.row();
95 list->model()->removeRow(row);
96 book->deleteBookmark(row);