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("Go to bookmark"), this, SLOT(onGo()), "goto");
38 addItemButton(tr("Edit bookmark"), this, SLOT(onEdit()), "edit");
39 addItemButton(tr("Delete bookmark"), this, SLOT(onDelete()), "delete");
41 connect(this, SIGNAL(activated(const QModelIndex &)),
42 this, SLOT(onItemActivated(const QModelIndex &)));
45 void BookmarksDialog::onGo()
48 QModelIndex current = currentItem();
49 if (current.isValid()) {
50 emit goToBookmark(current.row());
55 void BookmarksDialog::onItemActivated(const QModelIndex &index)
59 switch ((new BookmarkInfoDialog(book, index.row(), this))->exec()) {
60 case BookmarkInfoDialog::GoTo:
63 case BookmarkInfoDialog::Delete:
74 void BookmarksDialog::onAdd()
78 QString text = QInputDialog::getText(this, tr("Add bookmark"),
79 tr("Note (optional):"), QLineEdit::Normal, QString(), &ok);
81 emit addBookmark(text);
86 void BookmarksDialog::onDelete()
89 if (!currentItem().isValid()) {
92 if (QMessageBox::Yes !=
93 QMessageBox::question(this, tr("Delete bookmark"),
94 tr("Delete bookmark?"), QMessageBox::Yes | QMessageBox::No)) {
100 void BookmarksDialog::reallyDelete()
103 QModelIndex current = currentItem();
104 if (!current.isValid()) {
107 int row = current.row();
108 model()->removeRow(row);
109 book->deleteBookmark(row);
112 void BookmarksDialog::onEdit()
114 // FIXME: Implement me