Handle nested TOC items.
[dorian] / bookview.cpp
index 121fa50..101f0d1 100644 (file)
@@ -1,12 +1,11 @@
-#include <QDebug>
-#include <QWebFrame>
-#include <QMouseEvent>
-#include <QFile>
 #include <QDir>
-#include <QTimer>
+#include <QtGui>
+#include <QWebFrame>
 
-#ifdef Q_WS_MAEMO_5
+#if defined(Q_WS_MAEMO_5)
 #   include <QAbstractKineticScroller>
+#elif defined(Q_OS_SYMBIAN)
+#   include "flickcharm.h"
 #endif
 
 #include "book.h"
 #include "settings.h"
 #include "trace.h"
 #include "progress.h"
+#include "progressdialog.h"
 
 BookView::BookView(QWidget *parent):
     QWebView(parent), contentIndex(-1), mBook(0),
     restorePositionAfterLoad(false), positionAfterLoad(0), loaded(false),
     contentsHeight(0)
 {
-    Trace t("BookView::BookView");
+    TRACE;
     settings()->setAttribute(QWebSettings::AutoLoadImages, true);
     settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
     settings()->setAttribute(QWebSettings::JavaEnabled, false);
@@ -72,20 +72,23 @@ BookView::BookView(QWidget *parent):
     s->setValue("scheme", s->value("scheme", "default"));
     setBook(0);
 
-#ifdef Q_WS_MAEMO_5
+#if defined(Q_WS_MAEMO_5)
     scrollerMonitor = 0;
     scroller = property("kineticScroller").value<QAbstractKineticScroller *>();
+#elif defined(Q_OS_SYMBIAN)
+    FlickCharm *charm = new FlickCharm(this);
+    charm->activateOn(this);
 #endif
 }
 
 BookView::~BookView()
 {
-    Trace t("BookView::~BookView");
+    TRACE;
 }
 
 void BookView::loadContent(int index)
 {
-    Trace t("BookView::loadContent");
+    TRACE;
     if (!mBook) {
         return;
     }
@@ -110,7 +113,7 @@ void BookView::loadContent(int index)
 
 void BookView::setBook(Book *book)
 {
-    Trace t("BookView::setBook");
+    TRACE;
 
     // Save position in current book
     setLastBookmark();
@@ -142,7 +145,7 @@ Book *BookView::book()
 
 void BookView::goPrevious()
 {
-    Trace t("BookView::goPrevious");
+    TRACE;
     if (mBook && (contentIndex > 0)) {
         mBook->setLastBookmark(contentIndex - 1, 0);
         loadContent(contentIndex - 1);
@@ -151,7 +154,7 @@ void BookView::goPrevious()
 
 void BookView::goNext()
 {
-    Trace t("BookView::goNext");
+    TRACE;
     if (mBook && (contentIndex < (mBook->parts.size() - 1))) {
         mBook->setLastBookmark(contentIndex + 1, 0);
         loadContent(contentIndex + 1);
@@ -160,7 +163,7 @@ void BookView::goNext()
 
 void BookView::setLastBookmark()
 {
-    Trace t("BookView::setLastBookmark");
+    TRACE;
     if (mBook) {
         int height = contentsHeight;
         int pos = page()->mainFrame()->scrollPosition().y();
@@ -172,7 +175,7 @@ void BookView::setLastBookmark()
 
 void BookView::restoreLastBookmark()
 {
-    Trace t("BookView::restoreLastBookmark");
+    TRACE;
     if (mBook) {
         goToBookmark(mBook->lastBookmark());
     }
@@ -180,7 +183,7 @@ void BookView::restoreLastBookmark()
 
 void BookView::goToBookmark(const Book::Bookmark &bookmark)
 {
-    Trace t("BookView::goToBookmark");
+    TRACE;
     if (mBook) {
         if (bookmark.part != contentIndex) {
             qDebug () << "Loading new part" << bookmark.part;
@@ -196,7 +199,7 @@ void BookView::goToBookmark(const Book::Bookmark &bookmark)
 
 void BookView::onLoadFinished(bool ok)
 {
-    Trace t("BookView::onLoadFinished");
+    TRACE;
     if (!ok) {
         qDebug() << "Not OK";
         return;
@@ -209,7 +212,7 @@ void BookView::onLoadFinished(bool ok)
 
 void BookView::onSettingsChanged(const QString &key)
 {
-    Trace t("BookView::onSettingsChanged " + key);
+    TRACE;
     if (key == "zoom") {
         setZoomFactor(Settings::instance()->value(key).toFloat() / 100.);
     }
@@ -282,16 +285,16 @@ void BookView::wheelEvent(QWheelEvent *e)
     showProgress();
 }
 
-void BookView::addBookmark()
+void BookView::addBookmark(const QString &note)
 {
-    Trace t("BookView::addBookmark");
+    TRACE;
     if (!mBook) {
         return;
     }
     int y = page()->mainFrame()->scrollPosition().y();
     int height = page()->mainFrame()->contentsSize().height();
     qDebug() << ((qreal)y / (qreal)height);
-    mBook->addBookmark(contentIndex, (qreal)y / (qreal)height);
+    mBook->addBookmark(contentIndex, (qreal)y / (qreal)height, note);
     update();
 }
 
@@ -355,7 +358,7 @@ void BookView::onContentsSizeChanged(const QSize &size)
 
 void BookView::leaveEvent(QEvent *e)
 {
-    Trace t("BookView::leaveEvent");
+    TRACE;
     // Save current position, to be restored later
     setLastBookmark();
     QWebView::leaveEvent(e);
@@ -363,7 +366,7 @@ void BookView::leaveEvent(QEvent *e)
 
 void BookView::enterEvent(QEvent *e)
 {
-    Trace t("BookView::enterEvent");
+    TRACE;
     // Restore position saved at Leave event. This seems to be required,
     // after temporarily switching from portrait to landscape and back
     restoreLastBookmark();
@@ -400,9 +403,8 @@ void BookView::timerEvent(QTimerEvent *e)
             killTimer(scrollerMonitor);
         }
     }
-#else
-    Q_UNUSED(e);
-#endif // Q_WS_MAEMO_5
+#endif
+    QWebView::timerEvent(e);
 }
 
 void BookView::keyPressEvent(QKeyEvent* event)
@@ -440,7 +442,7 @@ void BookView::goPreviousPage()
 
 void BookView::goNextPage()
 {
-    Trace t("BookView::goNextPage");
+    TRACE;
     QWebFrame *frame = page()->mainFrame();
     int pos = frame->scrollPosition().y();
     frame->scroll(0, height());