3 #include "bookmarksdialog.h"
5 #include "bookmarkinfodialog.h"
7 BookmarksDialog::BookmarksDialog(Book *book_, QWidget *parent):
8 QMainWindow(parent), book(book_)
11 setAttribute(Qt::WA_Maemo5StackedWindow, true);
13 setWindowTitle(tr("Bookmarks"));
15 QFrame *frame = new QFrame(this);
16 setCentralWidget(frame);
17 QHBoxLayout *horizontalLayout = new QHBoxLayout(frame);
18 frame->setLayout(horizontalLayout);
20 list = new QListWidget(this);
21 list->setSelectionMode(QAbstractItemView::SingleSelection);
22 foreach (Book::Bookmark bookmark, book_->bookmarks()) {
24 label += QString::number((int)(100 * book_->
25 getProgress(bookmark.part, bookmark.pos))) + "%";
26 int chapterIndex = book_->chapterFromPart(bookmark.part);
27 if (chapterIndex != -1) {
28 QString chapterId = book_->chapters[chapterIndex];
29 label += "\nIn \"" + book_->content[chapterId].name + "\"";
31 (void)new QListWidgetItem(QIcon(":icons/bookmark.png"), label, list);
34 horizontalLayout->addWidget(list);
37 QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
39 QPushButton *goButton = new QPushButton(tr("Go to"), this);
40 buttonBox->addButton(goButton, QDialogButtonBox::ActionRole);
41 connect(goButton, SIGNAL(clicked()), this, SLOT(onGo()));
43 QPushButton *closeButton = buttonBox->addButton(QDialogButtonBox::Close);
44 connect(closeButton, SIGNAL(clicked()), this, SLOT(onClose()));
46 QPushButton *addButton = new QPushButton(tr("Add"), this);
47 buttonBox->addButton(addButton, QDialogButtonBox::ActionRole);
48 connect(addButton, SIGNAL(clicked()), this, SLOT(onAdd()));
50 QPushButton *deleteButton = new QPushButton(tr("Delete"), this);
51 buttonBox->addButton(deleteButton, QDialogButtonBox::DestructiveRole);
52 connect(deleteButton, SIGNAL(clicked()), this, SLOT(onDelete()));
54 horizontalLayout->addWidget(buttonBox);
56 QAction *addBookmarkAction = menuBar()->addAction(tr("Add bookmark"));
57 connect(addBookmarkAction, SIGNAL(triggered()), this, SLOT(onAdd()));
58 #endif // Q_WS_MAEMO_5
59 connect(list, SIGNAL(itemActivated(QListWidgetItem *)),
60 this, SLOT(onItemActivated(QListWidgetItem *)));
63 void BookmarksDialog::onGo()
65 if (!list->selectedItems().isEmpty()) {
66 QListWidgetItem *item = list->selectedItems()[0];
67 emit goToBookmark(list->row(item));
72 void BookmarksDialog::onItemActivated(QListWidgetItem *item)
74 switch ((new BookmarkInfoDialog(book, list->row(item), this))->exec()) {
75 case BookmarkInfoDialog::GoTo:
78 case BookmarkInfoDialog::Delete:
86 void BookmarksDialog::onAdd()
92 void BookmarksDialog::onClose()
97 void BookmarksDialog::onDelete(bool really)
99 if (list->selectedItems().isEmpty()) {
103 if (QMessageBox::Yes !=
104 QMessageBox::question(this, tr("Delete bookmark"),
105 tr("Delete bookmark?"),
106 QMessageBox::Yes | QMessageBox::No)) {
110 QListWidgetItem *item = list->selectedItems()[0];
111 int row = list->row(item);
112 book->deleteBookmark(row);
116 void BookmarksDialog::closeEvent(QCloseEvent *event)