Navigate by pages instead of book parts.
authorAkos Polster <polster@nolove.pipacs.com>
Wed, 1 Sep 2010 12:26:59 +0000 (14:26 +0200)
committerAkos Polster <polster@nolove.pipacs.com>
Wed, 1 Sep 2010 12:26:59 +0000 (14:26 +0200)
bookview.cpp
bookview.h
mainwindow.cpp
mainwindow.h
widgets/translucentbutton.cpp
widgets/translucentbutton.h

index 3003165..0acbdb3 100644 (file)
@@ -78,7 +78,6 @@ BookView::BookView(QWidget *parent):
     s->setValue("scheme", s->value("scheme", "default"));
     setBook(0);
 
-    extractIcons();
 #ifdef Q_WS_MAEMO_5
     scroller = property("kineticScroller").value<QAbstractKineticScroller *>();
 #endif
@@ -87,7 +86,6 @@ BookView::BookView(QWidget *parent):
 BookView::~BookView()
 {
     Trace t("BookView::~BookView");
-    removeIcons();
 }
 
 void BookView::loadContent(int index)
@@ -299,40 +297,6 @@ void BookView::addBookmark()
 
 void BookView::addNavigationBar()
 {
-    Trace t("BookView::addNavigationBar");
-    if (!mBook) {
-        return;
-    }
-
-    QString naviPrev =
-            "<a href=\"javascript:bv.goPrevious();\">"
-            "<img width=\"95\" height=\"95\" style=\"float:left;clear:none;\" "
-            "src=\"file://"
-            + tmpPath() +
-            "/previous.png\" />"
-            "</a>";
-    QString naviNext =
-            "<a href=\"javascript:bv.goNext();\">"
-            "<img width=\"95\" height=\"95\" style=\"float:right;clear:none;\" "
-            "src=\"file://"
-            + tmpPath() +
-            "/next.png\" />"
-            "</a>";
-    if (contentIndex == 0) {
-        naviPrev = "";
-    }
-    if (contentIndex >= mBook->parts.size() - 1) {
-        naviNext = "";
-    }
-
-    QWebFrame *frame = page()->currentFrame();
-    QString headerScript = "document.body.innerHTML = '" +
-        naviPrev + naviNext + "<br />" + "' + document.body.innerHTML;";
-    QString trailerScript = "document.body.innerHTML += '<br /><br />" +
-        naviPrev + naviNext + "';";
-
-    frame->evaluateJavaScript(headerScript);
-    frame->evaluateJavaScript(trailerScript);
     decorated = true;
 }
 
@@ -341,23 +305,6 @@ QString BookView::tmpPath()
     return QDir::tempPath() + "/dorian";
 }
 
-void BookView::extractIcons()
-{
-    QFile next(ICON_PREFIX + QString("/next.png"));
-    QFile prev(ICON_PREFIX + QString("/previous.png"));
-
-    QDir().mkpath(tmpPath());
-    next.copy(tmpPath() + "/next.png");
-    prev.copy(tmpPath() + "/previous.png");
-}
-
-void BookView::removeIcons()
-{
-    QFile(ICON_PREFIX + QString("/next.png")).remove();
-    QFile(ICON_PREFIX + QString("/previous.png")).remove();
-    QDir().rmpath(tmpPath());
-}
-
 bool BookView::eventFilter(QObject *o, QEvent *e)
 {
     if (e->type() != QEvent::Paint && e->type() != QEvent::MouseMove) {
@@ -484,7 +431,9 @@ void BookView::goPreviousPage()
     frame->scroll(0, -height());
     if (pos == frame->scrollPosition().y()) {
         if (contentIndex > 0) {
-            goToBookmark(Book::Bookmark(contentIndex - 1, 1.0));
+            Book::Bookmark bookmark(contentIndex - 1, 1.0);
+            mBook->setLastBookmark(contentIndex - 1, 1.0);
+            goToBookmark(bookmark);
         }
     } else {
         showProgress();
@@ -500,6 +449,7 @@ void BookView::goNextPage()
     if (pos == frame->scrollPosition().y()) {
         goNext();
     } else {
+        setLastBookmark();
         showProgress();
     }
 }
index 54c13ad..4202ac1 100644 (file)
@@ -39,8 +39,12 @@ signals:
     void progress(qreal p);
 
 public slots:
+    /** Go to next part. */
     void goPrevious();
+
+    /** Go to previous part. */
     void goNext();
+
     void onLoadFinished(bool ok);
     void onSettingsChanged(const QString &key);
 
@@ -50,6 +54,12 @@ public slots:
     /** Handle main frame contents size changes. */
     void onContentsSizeChanged(const QSize &size);
 
+    /** Go to previous page. */
+    void goPreviousPage();
+
+    /** Go to next page. */
+    void goNextPage();
+
 protected:
     void paintEvent(QPaintEvent *e);
     void mousePressEvent(QMouseEvent *e);
@@ -61,12 +71,6 @@ protected:
     void keyPressEvent(QKeyEvent *e);
 
 private:
-    /** Save navigation icons from resource to the file system. */
-    void extractIcons();
-
-    /** Remove extracted icons. */
-    void removeIcons();
-
     /** Load given part. */
     void loadContent(int index);
 
@@ -82,12 +86,6 @@ private:
     /** Show progress. */
     void showProgress();
 
-    /** Go to previous page. */
-    void goPreviousPage();
-
-    /** Go to next page. */
-    void goNextPage();
-
     int contentIndex;   /**< Current part in book. */
     Book *mBook;        /**< Book to show. */
     bool restorePositionAfterLoad;
index 46da063..aad12c5 100755 (executable)
@@ -31,6 +31,7 @@
 #include "bookfinder.h"
 #include "progress.h"
 #include "dyalog.h"
+#include "translucentbutton.h"
 
 #ifdef DORIAN_TEST_MODEL
 #include "modeltest.h"
@@ -113,7 +114,12 @@ MainWindow::MainWindow(QWidget *parent):
     frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
     toolBar->addWidget(frame);
 
-    fullScreenAction = addToolBarAction(this, SLOT(showBig()), "view-fullscreen");
+    fullScreenAction = addToolBarAction(this, SLOT(showBig()),
+                                        "view-fullscreen");
+
+    // Buttons for paging
+    previousButton = new TranslucentButton("back", this);
+    nextButton = new TranslucentButton("forward", this);
 
     // Handle model changes
     connect(Library::instance(), SIGNAL(nowReadingChanged()),
@@ -161,6 +167,10 @@ MainWindow::MainWindow(QWidget *parent):
     settings->setValue("lightson", settings->value("lightson"));
     settings->setValue("usevolumekeys", settings->value("usevolumekeys"));
 
+    // Handle next/previous buttons
+    connect(nextButton, SIGNAL(triggered()), view, SLOT(goNextPage()));
+    connect(previousButton, SIGNAL(triggered()), view, SLOT(goPreviousPage()));
+
 #ifdef DORIAN_TEST_MODEL
     (void)new ModelTest(Library::instance(), this);
 #endif
@@ -180,11 +190,16 @@ void MainWindow::showRegular()
     Trace t("MainWindow::showRegular");
     fullScreenWindow->hide();
     fullScreenWindow->leaveChildren();
-    progress->setGeometry(0, 0, geometry().width(), PROGRESS_HEIGHT);
+    QRect geo = geometry();
+    progress->setGeometry(0, 0, geo.width(), PROGRESS_HEIGHT);
+    nextButton->setGeometry(geo.width() - 95, 0, 95, 95);
+    previousButton->setGeometry(0, geo.height() - 95, 95, 95);
     QList<QWidget *> otherChildren;
-    otherChildren.append(progress);
+    otherChildren << progress << previousButton << nextButton;
     takeChildren(view, otherChildren);
     progress->flash();
+    nextButton->flash();
+    previousButton->flash();
 }
 
 void MainWindow::showBig()
@@ -192,12 +207,17 @@ void MainWindow::showBig()
     Trace t("MainWindow::showBig");
     leaveChildren();
     QList<QWidget *> otherChildren;
-    otherChildren.append(progress);
-    progress->setGeometry(0, 0, QApplication::desktop()->screenGeometry().width(),
-                          PROGRESS_HEIGHT);
+    otherChildren << progress << nextButton << previousButton;
+    QRect screen = QApplication::desktop()->screenGeometry();
+    progress->setGeometry(0, 0, screen.width(), PROGRESS_HEIGHT);
+    nextButton->setGeometry(screen.width() - 95, 0, 95, 95);
+    previousButton->setGeometry(0, screen.height() - 95, 95, 95);
+
     fullScreenWindow->takeChildren(view, otherChildren);
     fullScreenWindow->showFullScreen();
     progress->flash();
+    nextButton->flash();
+    previousButton->flash();
 }
 
 void MainWindow::setCurrentBook(const QModelIndex &current)
@@ -375,7 +395,13 @@ void MainWindow::timerEvent(QTimerEvent *event)
 
 void MainWindow::resizeEvent(QResizeEvent *e)
 {
+    Trace t("MainWindow::resizeEvent");
     progress->setGeometry(QRect(0, 0, e->size().width(), PROGRESS_HEIGHT));
+    qDebug() << "Toolbar height" << toolBar->height();
+    previousButton->setGeometry(0, e->size().height() - 95, 95, 95);
+    nextButton->setGeometry(e->size().width() - 95, toolBar->height(), 95, 95);
+    previousButton->flash();
+    nextButton->flash();
     QMainWindow::resizeEvent(e);
 }
 
index 4c4af45..c380a26 100755 (executable)
@@ -12,6 +12,7 @@ class BookView;
 class Book;
 class FullScreenWindow;
 class Progress;
+class TranslucentButton;
 
 class MainWindow: public BookWindow
 {
@@ -67,6 +68,8 @@ private:
     FullScreenWindow *fullScreenWindow;
     int preventBlankingTimer;
     Progress *progress;
+    TranslucentButton *previousButton;
+    TranslucentButton *nextButton;
 };
 
 #endif // MAINWINDOW_H
index 7a6d6fe..fdd9d46 100644 (file)
@@ -1,4 +1,5 @@
 #include "translucentbutton.h"
+#include "trace.h"
 
 #ifdef Q_WS_MAC
 #   define ICON_PREFIX ":/icons/mac/"
@@ -9,7 +10,7 @@
 TranslucentButton::TranslucentButton(const QString &name_, QWidget *parent):
     QWidget(parent), name(name_), opacity(1)
 {
-    setGeometry(0, 0, 50, 50);
+    setGeometry(0, 0, 95, 95);
     timer = new QTimer(this);
     timer->setSingleShot(true);
     connect(timer, SIGNAL(timeout()), this, SLOT(stopFlash()));
@@ -40,3 +41,10 @@ void TranslucentButton::stopFlash()
     opacity = 1;
     update();
 }
+
+void TranslucentButton::mousePressEvent(QMouseEvent *e)
+{
+    Q_UNUSED(e);
+    Trace t("TranslucentButton::mousePressEvent");
+    emit triggered();
+}
index 44b56c2..00035c1 100644 (file)
@@ -15,8 +15,12 @@ public slots:
     void flash(int duration = 3000);
     void stopFlash();
 
+signals:
+    void triggered();
+
 protected:
-    virtual void paintEvent(QPaintEvent *);
+    void paintEvent(QPaintEvent *);
+    void mousePressEvent(QMouseEvent *);
     QString name;
     int opacity;
     QTimer *timer;