From 4f46de1a517b4d92eed3debb8f3f7012c51a5653 Mon Sep 17 00:00:00 2001 From: Akos Polster Date: Sun, 2 Jan 2011 18:05:42 +0100 Subject: [PATCH] Only adjust reading positon during orientation switch. --- adopterwindow.cpp | 27 +++++++++++++++++++++------ bookview.cpp | 9 ++++++++- bookview.h | 2 ++ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/adopterwindow.cpp b/adopterwindow.cpp index 735d37c..173ed8b 100644 --- a/adopterwindow.cpp +++ b/adopterwindow.cpp @@ -137,15 +137,30 @@ void AdopterWindow::resizeEvent(QResizeEvent *event) Trace t("AdopterWindow::resizeEvent"); MainBase::resizeEvent(event); placeDecorations(); + #if defined(Q_WS_MAEMO_5) - if (bookView) { - QTimer::singleShot(110, bookView, SLOT(restoreLastBookmark())); + // Restore previous reading position + if (!bookView) { + return; } -#elif defined(Q_OS_SYMBIAN) - if (bookView) { - QTimer::singleShot(1000, bookView, SLOT(adjustPosition())); + QTimer::singleShot(110, bookView, SLOT(restoreLastBookmark())); +#endif // Q_WS_MAEMO_5 + +#if defined(Q_OS_SYMBIAN) + // Adjust reading position after orientation change + if (!bookView) { + return; } -#endif + if (event->oldSize().width() == -1) { + return; + } + bool oldPortrait = event->oldSize().width() < event->oldSize().height(); + bool portrait = event->size().width() < event->size().height(); + if (oldPortrait == portrait) { + return; + } + QTimer::singleShot(990, bookView, SLOT(adjustPosition())); +#endif // Q_OS_SYMBIAN } void AdopterWindow::closeEvent(QCloseEvent *event) diff --git a/bookview.cpp b/bookview.cpp index c3b3166..3964afa 100644 --- a/bookview.cpp +++ b/bookview.cpp @@ -517,9 +517,15 @@ void BookView::onMediaKeysPressed(MediaKeysObserver::MediaKeys key) #endif // Q_OS_SYMBIAN +#ifdef Q_OS_SYMBIAN + void BookView::adjustPosition() { TRACE; + + // QWebView widget doesn't maintain reading positon during orientation + // switch. This heuristics tries to work around it. + const qreal portraitMagic = 1.66; const qreal landscapeMagic = 0.655; if (mBook) { @@ -529,7 +535,8 @@ void BookView::adjustPosition() qreal ratio = (screenWidthmainFrame(); int current = frame->scrollPosition().y(); - qDebug() << "From" << current << "to" << (int)(current * ratio); frame->scroll(0, (int)(current * ratio) - current); } } + +#endif // Q_OS_SYMBIAN diff --git a/bookview.h b/bookview.h index c636230..1917d78 100644 --- a/bookview.h +++ b/bookview.h @@ -90,8 +90,10 @@ public slots: /** Restore book's last reading position. */ void restoreLastBookmark(); +#ifdef Q_OS_SYMBIAN /** Adjust web view position after orientation change. */ void adjustPosition(); +#endif protected slots: #ifdef Q_OS_SYMBIAN -- 1.7.9.5