From 9f29e40a91e0adf35bee94726c5e8c925fed059f Mon Sep 17 00:00:00 2001 From: Akos Polster Date: Tue, 20 Jul 2010 16:56:58 +0200 Subject: [PATCH] Make library full screen on Maemo. Show busy indicator while loading book. --- bookview.cpp | 3 ++- bookview.h | 3 ++- infodialog.cpp | 11 +++-------- librarydialog.cpp | 46 ++++++++++++++++++++++++++-------------------- librarydialog.h | 8 ++++++-- mainwindow.cpp | 19 +++++++++++++++---- mainwindow.h | 3 ++- 7 files changed, 56 insertions(+), 37 deletions(-) diff --git a/bookview.cpp b/bookview.cpp index 933bb4f..d960e26 100644 --- a/bookview.cpp +++ b/bookview.cpp @@ -79,6 +79,7 @@ void BookView::loadContent(int index) } else { loadFinished = false; + emit chapterLoadStart(index); load(QUrl(contentFile)); } contentIndex = index; @@ -147,7 +148,7 @@ void BookView::onLoadFinished(bool ok) loadFinished = true; addNavigationBar(); onSettingsChanged("scheme"); - emit chapterLoaded(contentIndex); + emit chapterLoadEnd(contentIndex); if (restore) { restore = false; if (ok && mBook) { diff --git a/bookview.h b/bookview.h index fc42344..b333228 100644 --- a/bookview.h +++ b/bookview.h @@ -26,7 +26,8 @@ public: void setLastBookmark(); signals: - void chapterLoaded(int index); + void chapterLoadStart(int index); + void chapterLoadEnd(int index); public slots: void goPrevious(); diff --git a/infodialog.cpp b/infodialog.cpp index 6bd9e01..7deb3c5 100644 --- a/infodialog.cpp +++ b/infodialog.cpp @@ -34,16 +34,11 @@ void InfoDialog::onReadBook() void InfoDialog::onRemoveBook() { - QString title = book->name(); if (QMessageBox::Yes == QMessageBox::question(this, - "Delete book", - "Delete book \"" + title + "\"", - QMessageBox::Yes -#ifndef Q_WS_MAEMO_5 - , QMessageBox::No -#endif - )) { + tr("Delete book"), + "Delete book \"" + book->name() + "\"?", + QMessageBox::Yes | QMessageBox::No)) { Library::instance()->remove(Library::instance()->find(book)); close(); } diff --git a/librarydialog.cpp b/librarydialog.cpp index fd7777b..32b4a04 100644 --- a/librarydialog.cpp +++ b/librarydialog.cpp @@ -15,43 +15,44 @@ #include "infodialog.h" #include "settings.h" -LibraryDialog::LibraryDialog(QWidget *parent): - QDialog(parent, Qt::Dialog | Qt::WindowTitleHint | - Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint) +LibraryDialog::LibraryDialog(QWidget *parent): QMainWindow(parent) { +#ifdef Q_WS_MAEMO_5 + setAttribute(Qt::WA_Maemo5StackedWindow, true); +#endif setWindowTitle(tr("Library")); + + QFrame *frame = new QFrame(this); + setCentralWidget(frame); + QHBoxLayout *horizontalLayout = new QHBoxLayout(this); + frame->setLayout(horizontalLayout); + list = new QListView(this); sortedLibrary = new SortedLibrary(this); list->setModel(sortedLibrary); list->setSelectionMode(QAbstractItemView::SingleSelection); list->setUniformItemSizes(true); -#ifndef Q_WS_MAEMO_5 - setSizeGripEnabled(true); -#endif Library *library = Library::instance(); QModelIndex current = library->nowReading(); setSelected(current); - - QHBoxLayout *horizontalLayout = new QHBoxLayout(this); horizontalLayout->addWidget(list); - QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical); #ifndef Q_WS_MAEMO_5 + QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical); detailsButton = new QPushButton(tr("Details"), this); readButton = new QPushButton(tr("Read"), this); removeButton = new QPushButton(tr("Delete"), this); -#endif // Q_WS_MAEMO_5 addButton = new QPushButton(tr("Add"), this); -#ifndef Q_WS_MAEMO_5 buttonBox->addButton(detailsButton, QDialogButtonBox::ActionRole); buttonBox->addButton(readButton, QDialogButtonBox::AcceptRole); buttonBox->addButton(removeButton, QDialogButtonBox::ActionRole); -#endif // Q_WS_MAEMO_5 buttonBox->addButton(addButton, QDialogButtonBox::ActionRole); - horizontalLayout->addWidget(buttonBox); +#else + QAction *addBookAction = menuBar()->addAction(tr("Add book")); +#endif // Q_WS_MAEMO_5 connect(Library::instance(), SIGNAL(nowReadingChanged()), this, SLOT(onCurrentBookChanged())); @@ -59,12 +60,12 @@ LibraryDialog::LibraryDialog(QWidget *parent): SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(onBookAdded())); - connect(addButton, SIGNAL(clicked()), this, SLOT(onAdd())); connect(list, SIGNAL(activated(const QModelIndex &)), this, SLOT(onItemActivated(const QModelIndex &))); #ifndef Q_WS_MAEMO_5 connect(list, SIGNAL(itemSelectionChanged()), this, SLOT(onItemSelectionChanged())); + connect(addButton, SIGNAL(clicked()), this, SLOT(onAdd())); connect(detailsButton, SIGNAL(clicked()), this, SLOT(onDetails())); connect(readButton, SIGNAL(clicked()), this, SLOT(onRead())); connect(removeButton, SIGNAL(clicked()), this, SLOT(onRemove())); @@ -73,6 +74,8 @@ LibraryDialog::LibraryDialog(QWidget *parent): const QItemSelection &)), this, SLOT(onItemSelectionChanged())); onItemSelectionChanged(); +#else + connect(addBookAction, SIGNAL(triggered()), this, SLOT(onAdd())); #endif // !Q_WS_MAEMO_5 } @@ -124,7 +127,6 @@ void LibraryDialog::onBookAdded() void LibraryDialog::onRemove() { - qDebug() << "LibraryDialog::onRemove"; QModelIndex current = sortedLibrary->mapToSource(list->currentIndex()); if (current.isValid()) { Book *currentBook = Library::instance()->book(current); @@ -132,7 +134,7 @@ void LibraryDialog::onRemove() if (QMessageBox::Yes == QMessageBox::question(this, "Delete book", "Delete book \"" + title + "\"?", - QMessageBox::Yes, QMessageBox::No)) { + QMessageBox::Yes | QMessageBox::No)) { Library::instance()->remove(current); } } @@ -179,13 +181,9 @@ QString LibraryDialog::createItemText(const Book *book) void LibraryDialog::onItemSelectionChanged() { bool enable = selected().isValid(); - qDebug() << "LibraryDialog::onItemSelectionChanged" << enable; readButton->setEnabled(enable); - qDebug() << " readButton"; detailsButton->setEnabled(enable); - qDebug() << " detailsButton"; removeButton->setEnabled(enable); - qDebug() << " removeButton"; } #endif // Q_WS_MAEMO_5 @@ -214,3 +212,11 @@ QModelIndex LibraryDialog::selected() const } return QModelIndex(); } + +void LibraryDialog::closeEvent(QCloseEvent *event) +{ +#ifdef Q_WS_MAEMO_5 + menuBar()->clear(); +#endif + event->accept(); +} diff --git a/librarydialog.h b/librarydialog.h index 1424ead..bef71fc 100644 --- a/librarydialog.h +++ b/librarydialog.h @@ -4,16 +4,17 @@ #include #include #include +#include -class QMainWindow; class QListView; class QPushButton; class QModelIndex; +class QCloseEvent; class Book; class InfoWindow; class SortedLibrary; -class LibraryDialog: public QDialog +class LibraryDialog: public QMainWindow { Q_OBJECT @@ -32,6 +33,9 @@ public slots: void onItemActivated(const QModelIndex &index); void onCurrentBookChanged(); +protected: + void closeEvent(QCloseEvent *event); + private: QString createItemText(const Book *book); void setSelected(const QModelIndex &index); diff --git a/mainwindow.cpp b/mainwindow.cpp index 34d56b5..ca97ee2 100755 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -116,7 +116,10 @@ MainWindow::MainWindow(QWidget *parent): Settings::instance()->value("orientation")); // Handle loading chapters - connect(view, SIGNAL(chapterLoaded(int)), this, SLOT(onChapterLoaded(int))); + connect(view, SIGNAL(chapterLoadStart(int)), + this, SLOT(onChapterLoadStart())); + connect(view, SIGNAL(chapterLoadEnd(int)), + this, SLOT(onChapterLoadEnd(int))); #ifdef DORIAN_TEST_MODEL (void)new ModelTest(Library::instance(), this); @@ -169,8 +172,8 @@ QAction *MainWindow::addToolBarAction(const QObject *receiver, void MainWindow::showLibrary() { - LibraryDialog *dialog = new LibraryDialog(); - dialog->exec(); + LibraryDialog *dialog = new LibraryDialog(this); + dialog->show(); } void MainWindow::showSettings() @@ -258,7 +261,14 @@ void MainWindow::onSettingsChanged(const QString &key) #endif // Q_WS_MAEMO_5 } -void MainWindow::onChapterLoaded(int index) +void MainWindow::onChapterLoadStart() +{ +#ifdef Q_WS_MAEMO_5 + setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true); +#endif +} + +void MainWindow::onChapterLoadEnd(int index) { bool enablePrevious = false; bool enableNext = false; @@ -272,6 +282,7 @@ void MainWindow::onChapterLoaded(int index) } } #ifdef Q_WS_MAEMO_5 + setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false); previousAction->setIcon(QIcon(enablePrevious? ":/icons/previous.png" : ":/icons/previous-disabled.png")); nextAction->setIcon(QIcon(enableNext? diff --git a/mainwindow.h b/mainwindow.h index 1959965..628fd18 100755 --- a/mainwindow.h +++ b/mainwindow.h @@ -28,7 +28,8 @@ public slots: void showNormal(); void showFullScreen(); void onSettingsChanged(const QString &key); - void onChapterLoaded(int index); + void onChapterLoadStart(); + void onChapterLoadEnd(int index); protected: #ifdef Q_WS_MAEMO5 -- 1.7.9.5