Don't reload volume if bookmark is in the same volume.
[dorian] / bookmarksdialog.cpp
1 #include <QtGui>
2
3 #include "bookmarksdialog.h"
4 #include "book.h"
5
6 BookmarksDialog::BookmarksDialog(Book *book_, QWidget *parent):
7     QDialog(parent, Qt::Dialog | Qt::WindowTitleHint |
8             Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint)
9 {
10     setWindowTitle(tr("Bookmarks"));
11 #ifndef Q_WS_MAEMO_5
12     setSizeGripEnabled(true);
13 #endif
14
15     list = new QListWidget(this);
16     list->setSelectionMode(QAbstractItemView::SingleSelection);
17     foreach (Book::Bookmark bookmark, book_->bookmarks()) {
18         list->addItem("Volume " + QString::number(bookmark.chapter + 1) + ", at " +
19                       QString::number((int)(bookmark.pos * 100)) + "%");
20     }
21
22     QHBoxLayout *horizontalLayout = new QHBoxLayout(this);
23     horizontalLayout->addWidget(list);
24
25     QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
26 #ifndef Q_WS_MAEMO_5
27     QPushButton *goButton = new QPushButton(tr("Go"), this);
28     buttonBox->addButton(goButton, QDialogButtonBox::AcceptRole);
29     connect(goButton, SIGNAL(clicked()), this, SLOT(onGo()));
30 #endif
31     QPushButton *addButton = new QPushButton(tr("Add"), this);
32     buttonBox->addButton(addButton, QDialogButtonBox::ActionRole);
33     connect(addButton, SIGNAL(clicked()), this, SLOT(onAdd()));
34
35     horizontalLayout->addWidget(buttonBox);
36
37 #ifdef Q_WS_MAEMO_5
38     connect(list, SIGNAL(itemActivated(QListWidgetItem *)),
39             this, SLOT(onItemActivated(QListWidgetItem *)));
40 #endif
41 }
42
43 void BookmarksDialog::onGo()
44 {
45     if (list->selectedItems().isEmpty()) {
46         return;
47     }
48     QListWidgetItem *item = list->selectedItems()[0];
49     int index = list->row(item) + 1;
50     done(index);
51 }
52
53 void BookmarksDialog::onItemActivated(QListWidgetItem *item)
54 {
55     done(list->row(item) + 1);
56 }
57
58 void BookmarksDialog::onAdd()
59 {
60     done(-1);
61 }