X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=chaptersdialog.cpp;h=85f0d92e52a0392a84e7366f31a0f7104628eaed;hb=91982ba06cca87105e1174e5e167c0b1771cf159;hp=c74983d59cf5c4b2544f5b7486995688d40f7d06;hpb=934bb6663f5cda53d52bced9be0576665218599b;p=dorian diff --git a/chaptersdialog.cpp b/chaptersdialog.cpp index c74983d..85f0d92 100644 --- a/chaptersdialog.cpp +++ b/chaptersdialog.cpp @@ -2,45 +2,35 @@ #include "chaptersdialog.h" #include "book.h" +#include "listview.h" -ChaptersDialog::ChaptersDialog(Book *b, QWidget *parent): - QMainWindow(parent), book(b) +ChaptersDialog::ChaptersDialog(Book *book, QWidget *parent): ListWindow(parent) { -#ifdef Q_WS_MAEMO_5 - setAttribute(Qt::WA_Maemo5StackedWindow, true); -#endif - setWindowTitle(tr("Bookmarks")); + setWindowTitle(tr("Chapters")); - QFrame *frame = new QFrame(this); - setCentralWidget(frame); - QHBoxLayout *horizontalLayout = new QHBoxLayout(frame); - 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); + 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*))); + QStringListModel *model = new QStringListModel(data, this); + list = new ListView; + list->setSelectionMode(QAbstractItemView::SingleSelection); + list->setModel(model); + list->setUniformItemSizes(true); + addList(list); + connect(list, SIGNAL(activated(const QModelIndex &)), + this, SLOT(onItemActivated(const QModelIndex &))); -#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); +#if !defined(Q_WS_MAEMO_5) && !defined(Q_OS_SYMBIAN) + addAction(tr("Close"), this, SLOT(close()), QString(), + QDialogButtonBox::RejectRole); #endif // Q_WS_MAEMO_5 } -void ChaptersDialog::onItemActivated(QListWidgetItem *item) -{ - emit goToChapter(list->row(item)); - close(); -} - -void ChaptersDialog::onClose() +void ChaptersDialog::onItemActivated(const QModelIndex &index) { + emit goToChapter(index.row()); close(); }