X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=chaptersdialog.cpp;h=20f7824c062fbdc039df8955a0ec9c74ed9b5786;hb=e5e113cbbbd0691ac179e311fe57082f992a63a0;hp=a769421dc5e61b8ac4f92a9d03b21aa4d3bbd617;hpb=d9df29af0dd817928532966e8728e6f41469671a;p=dorian diff --git a/chaptersdialog.cpp b/chaptersdialog.cpp index a769421..20f7824 100644 --- a/chaptersdialog.cpp +++ b/chaptersdialog.cpp @@ -1,46 +1,26 @@ -#include +#include #include "chaptersdialog.h" #include "book.h" -ChaptersDialog::ChaptersDialog(Book *b, QWidget *parent): - QMainWindow(parent), book(b) +ChaptersDialog::ChaptersDialog(Book *book, QWidget *parent): + ListWindow(tr("(No chapters)"), parent) { -#ifdef Q_WS_MAEMO_5 - setAttribute(Qt::WA_Maemo5StackedWindow, true); -#endif - setWindowTitle(tr("Bookmarks")); - - QFrame *frame = new QFrame(this); - setCentralWidget(frame); - QHBoxLayout *horizontalLayout = new QHBoxLayout(this); - frame->setLayout(horizontalLayout); - - list = new QListWidget(this); - list->setSelectionMode(QAbstractItemView::SingleSelection); - foreach (QString id, book->toc) { - QString contentTitle = book->content[id].name; - (void)new QListWidgetItem(contentTitle, list); + setWindowTitle(tr("Chapters")); + if (book) { + foreach (QString id, book->chapters) { + QString contentTitle = book->content[id].name; + data.append(contentTitle); + } } - horizontalLayout->addWidget(list); - connect(list, SIGNAL(itemActivated(QListWidgetItem*)), - this, SLOT(onItemActivated(QListWidgetItem*))); - -#ifndef Q_WS_MAEMO_5 - QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical); - QPushButton *closeButton = buttonBox->addButton(QDialogButtonBox::Close); - connect(closeButton, SIGNAL(clicked()), this, SLOT(onClose())); - horizontalLayout->addWidget(buttonBox); -#endif // Q_WS_MAEMO_5 -} - -void ChaptersDialog::onItemActivated(QListWidgetItem *item) -{ - emit goToChapter(list->row(item)); - close(); + QStringListModel *model = new QStringListModel(data, this); + setModel(model); + connect(this, SIGNAL(activated(const QModelIndex &)), + this, SLOT(onItemActivated(const QModelIndex &))); } -void ChaptersDialog::onClose() +void ChaptersDialog::onItemActivated(const QModelIndex &index) { + emit goToChapter(index.row()); close(); }