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()) {
23 QString contentId = book_->toc[bookmark.part];
24 QString contentTitle = book_->content[contentId].name;
25 (void)new QListWidgetItem(QIcon(":icons/bookmark.png"), contentTitle +
26 "\nAt " + QString::number((int)(bookmark.pos*100)) + "%", list);
29 horizontalLayout->addWidget(list);
32 QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
34 QPushButton *goButton = new QPushButton(tr("Go to"), this);
35 buttonBox->addButton(goButton, QDialogButtonBox::ActionRole);
36 connect(goButton, SIGNAL(clicked()), this, SLOT(onGo()));
38 QPushButton *closeButton = buttonBox->addButton(QDialogButtonBox::Close);
39 connect(closeButton, SIGNAL(clicked()), this, SLOT(onClose()));
41 QPushButton *addButton = new QPushButton(tr("Add"), this);
42 buttonBox->addButton(addButton, QDialogButtonBox::ActionRole);
43 connect(addButton, SIGNAL(clicked()), this, SLOT(onAdd()));
45 QPushButton *deleteButton = new QPushButton(tr("Delete"), this);
46 buttonBox->addButton(deleteButton, QDialogButtonBox::DestructiveRole);
47 connect(deleteButton, SIGNAL(clicked()), this, SLOT(onDelete()));
49 horizontalLayout->addWidget(buttonBox);
51 QAction *addBookmarkAction = menuBar()->addAction(tr("Add bookmark"));
52 connect(addBookmarkAction, SIGNAL(triggered()), this, SLOT(onAdd()));
53 #endif // Q_WS_MAEMO_5
54 connect(list, SIGNAL(itemActivated(QListWidgetItem *)),
55 this, SLOT(onItemActivated(QListWidgetItem *)));
58 void BookmarksDialog::onGo()
60 if (!list->selectedItems().isEmpty()) {
61 QListWidgetItem *item = list->selectedItems()[0];
62 emit goToBookmark(list->row(item));
67 void BookmarksDialog::onItemActivated(QListWidgetItem *item)
69 switch ((new BookmarkInfoDialog(book, list->row(item), this))->exec()) {
70 case BookmarkInfoDialog::GoTo:
73 case BookmarkInfoDialog::Delete:
81 void BookmarksDialog::onAdd()
87 void BookmarksDialog::onClose()
92 void BookmarksDialog::onDelete(bool really)
94 if (list->selectedItems().isEmpty()) {
98 if (QMessageBox::Yes !=
99 QMessageBox::question(this, tr("Delete bookmark"),
100 tr("Delete bookmark?"),
101 QMessageBox::Yes | QMessageBox::No)) {
105 QListWidgetItem *item = list->selectedItems()[0];
106 int row = list->row(item);
107 book->deleteBookmark(row);
111 void BookmarksDialog::closeEvent(QCloseEvent *event)