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(this);
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.chapter];
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"), this);
35 buttonBox->addButton(goButton, QDialogButtonBox::ActionRole);
36 connect(goButton, SIGNAL(clicked()), this, SLOT(onGo()));
38 QPushButton *closeButton = new QPushButton(tr("Close"), this);
39 buttonBox->addButton(closeButton, QDialogButtonBox::AcceptRole);
40 connect(closeButton, SIGNAL(clicked()), this, SLOT(onClose()));
42 QPushButton *addButton = new QPushButton(tr("Add"), this);
43 buttonBox->addButton(addButton, QDialogButtonBox::ActionRole);
44 connect(addButton, SIGNAL(clicked()), this, SLOT(onAdd()));
46 QPushButton *deleteButton = new QPushButton(tr("Delete"), this);
47 buttonBox->addButton(deleteButton, QDialogButtonBox::DestructiveRole);
48 connect(deleteButton, SIGNAL(clicked()), this, SLOT(onDelete()));
50 horizontalLayout->addWidget(buttonBox);
52 QAction *addBookmarkAction = menuBar()->addAction(tr("Add bookmark"));
53 connect(addBookmarkAction, SIGNAL(triggered()), this, SLOT(onAdd()));
54 #endif // Q_WS_MAEMO_5
55 connect(list, SIGNAL(itemActivated(QListWidgetItem *)),
56 this, SLOT(onItemActivated(QListWidgetItem *)));
59 void BookmarksDialog::onGo()
61 if (!list->selectedItems().isEmpty()) {
62 QListWidgetItem *item = list->selectedItems()[0];
63 emit goToBookmark(list->row(item));
68 void BookmarksDialog::onItemActivated(QListWidgetItem *item)
70 switch ((new BookmarkInfoDialog(book, list->row(item), this))->exec()) {
71 case BookmarkInfoDialog::GoTo:
74 case BookmarkInfoDialog::Delete:
82 void BookmarksDialog::onAdd()
88 void BookmarksDialog::onClose()
93 void BookmarksDialog::onDelete()
95 if (!list->selectedItems().isEmpty()) {
96 QListWidgetItem *item = list->selectedItems()[0];
97 int row = list->row(item);
98 book->deleteBookmark(row);
103 void BookmarksDialog::closeEvent(QCloseEvent *event)