From: Akos Polster Date: Wed, 1 Dec 2010 22:15:57 +0000 (+0100) Subject: Speed up paging through the book. Clean up code for saving/restoring X-Git-Url: http://vcs.maemo.org/git/?p=dorian;a=commitdiff_plain;h=5b90676a3adb2b9df8504684093c165f684eac29 Speed up paging through the book. Clean up code for saving/restoring reading position. --- diff --git a/adopterwindow.cpp b/adopterwindow.cpp index 5e9ef64..29e8331 100644 --- a/adopterwindow.cpp +++ b/adopterwindow.cpp @@ -52,6 +52,7 @@ AdopterWindow::AdopterWindow(QWidget *parent): // Monitor settings connect(Settings::instance(), SIGNAL(valueChanged(const QString &)), this, SLOT(onSettingsChanged(const QString &))); + } void AdopterWindow::takeBookView(BookView *view, @@ -79,6 +80,12 @@ void AdopterWindow::takeBookView(BookView *view, progress->setParent(this); previousButton->setParent(this); nextButton->setParent(this); + + // Handle page and/or volume keys + connect(this, SIGNAL(pageUp()), this, SLOT(onPageUp()), + Qt::QueuedConnection); + connect(this, SIGNAL(pageDown()), this, SLOT(onPageDown()), + Qt::QueuedConnection); } void AdopterWindow::leaveBookView() @@ -92,6 +99,8 @@ void AdopterWindow::leaveBookView() progress = 0; nextButton = 0; previousButton = 0; + disconnect(this, SLOT(onPageUp())); + disconnect(this, SLOT(onPageDown())); } bool AdopterWindow::hasBookView() @@ -260,36 +269,49 @@ void AdopterWindow::resizeEvent(QResizeEvent *event) #endif QMainWindow::resizeEvent(event); placeDecorations(); + if (bookView) { + QTimer::singleShot(110, bookView, SLOT(restoreLastBookmark())); + } +} + +void AdopterWindow::closeEvent(QCloseEvent *event) +{ + Trace t("AdopterWindow::closeEvent"); + if (bookView) { + bookView->setLastBookmark(); + } + QMainWindow::closeEvent(event); +} + +void AdopterWindow::leaveEvent(QEvent *event) +{ + Trace t("AdopterWindow::leaveEvent"); + if (bookView) { + bookView->setLastBookmark(); + } + QMainWindow::leaveEvent(event); } void AdopterWindow::keyPressEvent(QKeyEvent *event) { TRACE; - if (bookView && grabbingVolumeKeys) { - switch (event->key()) { + switch (event->key()) { + case Qt::Key_PageDown: #ifdef Q_WS_MAEMO_5 - case Qt::Key_F7: - qDebug() << "F7"; - bookView->goNextPage(); - event->accept(); - break; - case Qt::Key_F8: - qDebug() << "F8"; - bookView->goPreviousPage(); - event->accept(); - break; -#endif // Q_WS_MAEMO_5 - case Qt::Key_PageUp: - bookView->goPreviousPage(); - event->accept(); - break; - case Qt::Key_PageDown: - bookView->goNextPage(); - event->accept(); - break; - default: - ; - } + case Qt::Key_F7: +#endif + emit pageDown(); + event->accept(); + break; + case Qt::Key_PageUp: +#ifdef Q_WS_MAEMO_5 + case Qt::Key_F8: +#endif + emit pageUp(); + event->accept(); + break; + default: + ; } QMainWindow::keyPressEvent(event); } @@ -346,3 +368,28 @@ void AdopterWindow::placeDecorations() nextButton->flash(); qDebug() << "progress:" << progress->geometry(); } + +void AdopterWindow::onPageUp() +{ + if (bookView && grabbingVolumeKeys) { + setEnabled(false); + bookView->goPreviousPage(); + setEnabled(true); + } +} + +void AdopterWindow::onPageDown() +{ + if (bookView && grabbingVolumeKeys) { + setEnabled(false); + bookView->goNextPage(); + setEnabled(true); + } +} + +void AdopterWindow::hideToolBar() +{ + if (toolBar) { + toolBar->hide(); + } +} diff --git a/adopterwindow.h b/adopterwindow.h index 841b527..c6c99cd 100644 --- a/adopterwindow.h +++ b/adopterwindow.h @@ -60,6 +60,13 @@ public slots: /** Handle settings changes. */ void onSettingsChanged(const QString &key); +signals: + /** Emitted when Page Up or Volume Up pressed. */ + void pageUp(); + + /** Emitted when Page Down or Volume Down pressed. */ + void pageDown(); + protected: /** Handle key press events. */ void keyPressEvent(QKeyEvent *event); @@ -70,9 +77,15 @@ protected: */ void showEvent(QShowEvent *event); - /** Handle resize events. */ + /** Handle resize event: Restore reading position. */ void resizeEvent(QResizeEvent *event); + /** Handle close event. */ + void closeEvent(QCloseEvent *event); + + /** Handle leave event: Save reading position. */ + void leaveEvent(QEvent *event); + #ifdef Q_OS_SYMBIAN /** Update toolbar visibility. */ void updateToolBar(); @@ -86,8 +99,13 @@ protected: void doGrabVolumeKeys(bool grab); #endif // Q_WS_MAEMO_5 + /** Hide tool bar if visible. */ + void hideToolBar(); + protected slots: void placeDecorations(); + void onPageDown(); + void onPageUp(); private: BookView *bookView; /**< Book view widget. */ diff --git a/bookview.cpp b/bookview.cpp index aaa3326..30a1499 100644 --- a/bookview.cpp +++ b/bookview.cpp @@ -406,18 +406,6 @@ void BookView::addJavaScriptObjects() page()->mainFrame()->addToJavaScriptWindowObject("bv", this); } -#ifdef Q_WS_MAEMO_5 - -void BookView::leaveEvent(QEvent *e) -{ - TRACE; - // Save current position, to be restored later, in MainWindow::resizeEvent() - setLastBookmark(); - QWebView::leaveEvent(e); -} - -#endif // Q_WS_MAEMO_5 - void BookView::goToPosition(qreal position) { int contentsHeight = page()->mainFrame()->contentsSize().height(); @@ -480,7 +468,7 @@ void BookView::goNextPage() if (pos == frame->scrollPosition().y()) { goNext(); } else { - setLastBookmark(); + // setLastBookmark(); showProgress(); } } diff --git a/bookview.h b/bookview.h index 8465f3c..9d25d2d 100644 --- a/bookview.h +++ b/bookview.h @@ -105,9 +105,6 @@ protected: void wheelEvent(QWheelEvent *); bool eventFilter(QObject *o, QEvent *e); void timerEvent(QTimerEvent *e); -#ifdef Q_WS_MAEMO_5 - void leaveEvent(QEvent *e); -#endif // Q_WS_MAEMO_5 /** Load given part. */ void loadContent(int index); diff --git a/fullscreenwindow.cpp b/fullscreenwindow.cpp index c9e16c2..c63f003 100644 --- a/fullscreenwindow.cpp +++ b/fullscreenwindow.cpp @@ -17,9 +17,7 @@ FullScreenWindow::FullScreenWindow(QWidget *parent): AdopterWindow(parent) setAttribute(Qt::WA_Maemo5StackedWindow, true); setAttribute(Qt::WA_Maemo5NonComposited, true); #endif // Q_WS_MAEMO_5 -#ifndef Q_OS_SYMBIAN - toolBar->hide(); -#endif + hideToolBar(); QFrame *frame = new QFrame(this); QVBoxLayout *layout = new QVBoxLayout(frame); layout->setMargin(0); diff --git a/mainwindow.cpp b/mainwindow.cpp index f45b950..2119452 100755 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -109,7 +109,8 @@ MainWindow::MainWindow(QWidget *parent): // Load library, upgrade it if needed libraryProgress = new ProgressDialog(tr("Upgrading library"), this); Library *library = Library::instance(); - connect(library, SIGNAL(beginUpgrade(int)), this, SLOT(onBeginUpgrade(int))); + connect(library, SIGNAL(beginUpgrade(int)), + this, SLOT(onBeginUpgrade(int))); connect(library, SIGNAL(upgrading(const QString &)), this, SLOT(onUpgrading(const QString &))); connect(library, SIGNAL(endUpgrade()), this, SLOT(onEndUpgrade())); @@ -254,13 +255,6 @@ void MainWindow::showBookmarks() } } -void MainWindow::closeEvent(QCloseEvent *event) -{ - TRACE; - view->setLastBookmark(); - AdopterWindow::closeEvent(event); -} - void MainWindow::onSettingsChanged(const QString &key) { #if defined(Q_WS_MAEMO_5) diff --git a/mainwindow.h b/mainwindow.h index 6e70740..9bfbab4 100755 --- a/mainwindow.h +++ b/mainwindow.h @@ -51,7 +51,6 @@ public slots: void onEndLoad(); protected: - void closeEvent(QCloseEvent *event); void timerEvent(QTimerEvent *event); private: diff --git a/pkg/changelog b/pkg/changelog index 87ec012..773065a 100644 --- a/pkg/changelog +++ b/pkg/changelog @@ -1,3 +1,9 @@ +dorian (0.4.2-1) unstable; urgency=low + + * Speed up paging through the book + + -- Akos Polster Fri, 1 Dec 2010 02:00:00 +0100 + dorian (0.4.1-1) unstable; urgency=low * Update home page link in About box diff --git a/pkg/version.txt b/pkg/version.txt index 722d7f3..c0aa84b 100644 --- a/pkg/version.txt +++ b/pkg/version.txt @@ -1 +1 @@ -"0.4.1" +"0.4.2"