3 #include "bookmarksdialog.h"
6 BookmarksDialog::BookmarksDialog(Book *book_, QWidget *parent):
7 QDialog(parent, Qt::Dialog | Qt::WindowTitleHint |
8 Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint)
10 setWindowTitle(tr("Bookmarks"));
12 setSizeGripEnabled(true);
15 list = new QListWidget(this);
16 list->setSelectionMode(QAbstractItemView::SingleSelection);
17 foreach (Book::Bookmark bookmark, book_->bookmarks()) {
18 QString contentId = book_->toc[bookmark.chapter];
19 QString contentTitle = book_->content[contentId].name;
20 list->addItem(contentTitle + ", at " +
21 QString::number((int)(bookmark.pos * 100)) + "%");
24 QHBoxLayout *horizontalLayout = new QHBoxLayout(this);
25 horizontalLayout->addWidget(list);
27 QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
29 QPushButton *goButton = new QPushButton(tr("Go"), this);
30 buttonBox->addButton(goButton, QDialogButtonBox::AcceptRole);
31 connect(goButton, SIGNAL(clicked()), this, SLOT(onGo()));
33 QPushButton *addButton = new QPushButton(tr("Add"), this);
34 buttonBox->addButton(addButton, QDialogButtonBox::ActionRole);
35 connect(addButton, SIGNAL(clicked()), this, SLOT(onAdd()));
37 horizontalLayout->addWidget(buttonBox);
40 connect(list, SIGNAL(itemActivated(QListWidgetItem *)),
41 this, SLOT(onItemActivated(QListWidgetItem *)));
45 void BookmarksDialog::onGo()
47 if (list->selectedItems().isEmpty()) {
50 QListWidgetItem *item = list->selectedItems()[0];
51 int index = list->row(item) + 1;
55 void BookmarksDialog::onItemActivated(QListWidgetItem *item)
57 done(list->row(item) + 1);
60 void BookmarksDialog::onAdd()