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()), ":/icons/add.png");
18 addItemAction(tr("Go to"), this, SLOT(onGo()));
19 addItemAction(tr("Delete"), this, SLOT(onDelete()));
20 #endif // ! Q_WS_MAEMO_5
22 // Build bookmark list
24 foreach (Book::Bookmark bookmark, book_->bookmarks()) {
26 label += QString::number((int)(100 * book_->
27 getProgress(bookmark.part, bookmark.pos))) + "%";
28 int chapterIndex = book_->chapterFromPart(bookmark.part);
29 if (chapterIndex != -1) {
30 QString chapterId = book_->chapters[chapterIndex];
31 label += ", in \"" + book_->content[chapterId].name + "\"";
33 if (!bookmark.note.isEmpty()) {
34 label += "\n" + bookmark.note;
39 // Create bookmark list view
40 QStringListModel *model = new QStringListModel(data, this);
42 list->setSelectionMode(QAbstractItemView::SingleSelection);
43 list->setModel(model);
45 connect(list, SIGNAL(activated(const QModelIndex &)),
46 this, SLOT(onItemActivated(const QModelIndex &)));
50 void BookmarksDialog::onGo()
52 QModelIndex current = list->currentIndex();
53 if (current.isValid()) {
54 emit goToBookmark(current.row());
59 void BookmarksDialog::onItemActivated(const QModelIndex &index)
61 switch ((new BookmarkInfoDialog(book, index.row(), this))->exec()) {
62 case BookmarkInfoDialog::GoTo:
65 case BookmarkInfoDialog::Delete:
73 void BookmarksDialog::onAdd()
76 QString text = QInputDialog::getText(this, tr("Add bookmark"),
77 tr("Note:"), QLineEdit::Normal,
80 emit addBookmark(text);
85 void BookmarksDialog::onDelete(bool really)
87 QModelIndex current = list->currentIndex();
88 if (!current.isValid()) {
92 if (QMessageBox::Yes !=
93 QMessageBox::question(this, tr("Delete bookmark"),
94 tr("Delete bookmark?"), QMessageBox::Yes | QMessageBox::No)) {
98 int row = current.row();
99 list->model()->removeRow(row);
100 book->deleteBookmark(row);