Struggle...
authorAkos Polster <akos@pipacs.com>
Wed, 29 Dec 2010 20:46:20 +0000 (21:46 +0100)
committerAkos Polster <akos@pipacs.com>
Wed, 29 Dec 2010 20:46:20 +0000 (21:46 +0100)
adopterwindow.cpp
bookview.cpp
bookview.h
model/book.cpp
model/book.h

index 0ed8670..2cdf4dd 100644 (file)
@@ -135,11 +135,18 @@ void AdopterWindow::showEvent(QShowEvent *e)
 void AdopterWindow::resizeEvent(QResizeEvent *event)
 {
     Trace t("AdopterWindow::resizeEvent");
+#if defined(Q_OS_SYMBIAN)
+    if (bookView) {
+        bookView->setLastBookmark();
+    }
+#endif
     MainBase::resizeEvent(event);
     placeDecorations();
+#if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
     if (bookView) {
         QTimer::singleShot(110, bookView, SLOT(restoreLastBookmark()));
     }
+#endif
 }
 
 void AdopterWindow::closeEvent(QCloseEvent *event)
index fda10b9..3e38ea6 100644 (file)
@@ -157,7 +157,7 @@ void BookView::goNext()
     }
 }
 
-void BookView::setLastBookmark()
+void BookView::setLastBookmark(bool fast)
 {
     TRACE;
     if (mBook) {
@@ -166,7 +166,7 @@ void BookView::setLastBookmark()
         int pos = frame->scrollPosition().y();
         qDebug() << QString("At %1 (%2%, height %3)").
                 arg(pos).arg((qreal)pos / (qreal)height * 100).arg(height);
-        mBook->setLastBookmark(contentIndex, (qreal)pos / (qreal)height);
+        mBook->setLastBookmark(contentIndex, (qreal)pos / (qreal)height, fast);
     }
 }
 
@@ -341,14 +341,16 @@ void BookView::mousePressEvent(QMouseEvent *e)
     if (scroller) {
         scrollerMonitor = startTimer(500);
     }
+#elif defined(Q_OS_SYMBIAN)
+    // Do nothing
 #else
-    // Handle mouse presses on the scroll bar
+    // Handle mouse press on the scroll bar
     QWebFrame *frame = page()->mainFrame();
     if (frame->scrollBarGeometry(Qt::Vertical).contains(e->pos())) {
         e->accept();
         return;
     }
-#endif // Q_WS_MAEMO_5
+#endif
     e->ignore();
 }
 
@@ -395,7 +397,6 @@ bool BookView::eventFilter(QObject *o, QEvent *e)
     // Work around Qt bug that sometimes selects web view contents during swipe
     switch (e->type()) {
     case QEvent::MouseButtonPress:
-        emit suppressedMouseButtonPress();
         mousePressed = true;
         break;
     case QEvent::MouseButtonRelease:
@@ -454,7 +455,8 @@ void BookView::timerEvent(QTimerEvent *e)
             scrollerMonitor = -1;
         }
     }
-#endif
+#endif // Q_WS_MAEMO_5
+
     QWebView::timerEvent(e);
 }
 
@@ -483,7 +485,6 @@ void BookView::goNextPage()
     if (pos == frame->scrollPosition().y()) {
         goNext();
     } else {
-        // setLastBookmark();
         showProgress();
     }
 }
@@ -512,3 +513,14 @@ void BookView::onMediaKeysPressed(MediaKeysObserver::MediaKeys key)
 }
 
 #endif // Q_OS_SYMBIAN
+
+void BookView::adjustPosition(const QSize &size, const QSize &oldSize)
+{
+    if (mBook) {
+        QWebFrame *frame = page()->mainFrame();
+        int height = frame->contentsSize().height();
+        int pos = frame->scrollPosition().y();
+        qDebug() << QString("At %1 (%2%, height %3)").
+                arg(pos).arg((qreal)pos / (qreal)height * 100).arg(height);
+    }
+}
index 9d25d2d..4a5e447 100644 (file)
@@ -41,7 +41,7 @@ public:
     void addBookmark(const QString &note);
 
     /** Save current reading position into book. */
-    void setLastBookmark();
+    void setLastBookmark(bool fast = false);
 
     /** Go to given part + part fragment URL. */
     void goToPart(int part, const QString &fragment);
@@ -59,9 +59,6 @@ signals:
     /** Part loading finished. */
     void partLoadEnd(int index);
 
-    /** Signal button press, when the real event has been suppressed. */
-    void suppressedMouseButtonPress();
-
     /** Signal progress in reading the book. */
     void progress(qreal p);
 
@@ -93,6 +90,9 @@ public slots:
     /** Restore book's last reading position. */
     void restoreLastBookmark();
 
+    /** Adjust web view position after orientation change. */
+    void adjustPosition(const QSize &size, const QSize &oldSize);
+
 protected slots:
 #ifdef Q_OS_SYMBIAN
     /** Observe media keys. */
@@ -118,6 +118,7 @@ protected:
     /** Show reading progress. */
     void showProgress();
 
+private:
     int contentIndex;       /**< Current part in book. */
     Book *mBook;            /**< Book to show. */
     bool restorePositionAfterLoad;
@@ -135,10 +136,13 @@ protected:
 #if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
     int scrollerMonitor;    /**< ID of timer monitoring kinetic scroll. */
 #endif
+
 #if defined(Q_WS_MAEMO_5)
     QAbstractKineticScroller *scroller;
-#elif defined(Q_OS_SYMBIAN)
-    FlickCharm *charm;
+#endif
+
+#if defined(Q_OS_SYMBIAN)
+    FlickCharm *charm;      /**< Kinetic scroller. */
 #endif
 };
 
index 94bb9e9..8aa4022 100644 (file)
@@ -336,13 +336,17 @@ void Book::save()
     BookDb::instance()->save(path(), data);
 }
 
-void Book::setLastBookmark(int part, qreal position)
+void Book::setLastBookmark(int part, qreal position, bool fast)
 {
     TRACE;
-    load();
+    if (!fast) {
+        load();
+    }
     mLastBookmark.part = part;
     mLastBookmark.pos = position;
-    save();
+    if (!fast) {
+        save();
+    }
 }
 
 Book::Bookmark Book::lastBookmark()
index bfce66b..7d9ed84 100644 (file)
@@ -84,7 +84,7 @@ public:
     bool clearDir(const QString &directory);
 
     /** Set last bookmark. */
-    void setLastBookmark(int part, qreal position);
+    void setLastBookmark(int part, qreal position, bool fast = false);
 
     /** Get last bookmark. */
     Bookmark lastBookmark();