Bookmarks with notes, first attempt.
[dorian] / bookmarkinfodialog.cpp
1 #include <QtGui>
2
3 #include "bookmarkinfodialog.h"
4 #include "book.h"
5
6 BookmarkInfoDialog::BookmarkInfoDialog(Book *b, int i, QWidget *parent):
7     Dyalog(parent, true),
8     book(b),
9     index(i)
10 {
11     setWindowTitle(tr("Bookmark Details"));
12
13     Book::Bookmark bookmark = book->bookmarks()[index];
14     QString label("At ");
15     label += QString::number((int)(100 * book->
16         getProgress(bookmark.part, bookmark.pos))) + "%";
17     int chapterIndex = book->chapterFromPart(bookmark.part);
18     if (chapterIndex != -1) {
19         QString chapterId = book->chapters[chapterIndex];
20         label += ", in\"" + book->content[chapterId].name + "\"";
21     }
22     if (!bookmark.note.isEmpty()) {
23         label += "\n" + bookmark.note;
24     }
25     QLabel *info = new QLabel(label, this);
26     addWidget(info);
27     addStretch();
28     addButton(tr("Go to"), this, SLOT(onRead()), QDialogButtonBox::ActionRole);
29     addButton(tr("Delete"), this, SLOT(onRemove()),
30               QDialogButtonBox::DestructiveRole);
31 }
32
33 void BookmarkInfoDialog::onRead()
34 {
35     done(GoTo);
36 }
37
38 void BookmarkInfoDialog::onRemove()
39 {
40     if (QMessageBox::Yes ==
41         QMessageBox::question(this, tr("Delete bookmark"),
42                               tr("Delete bookmark?"),
43                               QMessageBox::Yes | QMessageBox::No)) {
44         done(Delete);
45     }
46 }