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 list->addItem("Chapter " + QString::number(bookmark.chapter) + ", at " +
19 QString::number((int)(bookmark.pos * 100)) + "%");
22 QHBoxLayout *horizontalLayout = new QHBoxLayout(this);
23 horizontalLayout->addWidget(list);
25 QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
27 QPushButton *goButton = new QPushButton(tr("Go"), this);
28 buttonBox->addButton(goButton, QDialogButtonBox::AcceptRole);
29 connect(goButton, SIGNAL(clicked()), this, SLOT(onGo()));
31 QPushButton *addButton = new QPushButton(tr("Add"), this);
32 buttonBox->addButton(addButton, QDialogButtonBox::ActionRole);
33 connect(addButton, SIGNAL(clicked()), this, SLOT(onAdd()));
35 horizontalLayout->addWidget(buttonBox);
38 connect(list, SIGNAL(itemActivated(QListWidgetItem *)),
39 this, SLOT(onItemActivated(QListWidgetItem *)));
43 void BookmarksDialog::onGo()
45 if (list->selectedItems().isEmpty()) {
48 QListWidgetItem *item = list->selectedItems()[0];
49 int index = list->row(item) + 1;
53 void BookmarksDialog::onItemActivated(QListWidgetItem *item)
55 done(list->row(item) + 1);
58 void BookmarksDialog::onAdd()