Navigate with volume keys.
authorAkos Polster <polster@marzipan.pipacs.com>
Sun, 8 Aug 2010 12:31:39 +0000 (14:31 +0200)
committerAkos Polster <polster@marzipan.pipacs.com>
Sun, 8 Aug 2010 12:31:39 +0000 (14:31 +0200)
bookview.cpp
bookview.h
mainwindow.cpp
mainwindow.h
pkg/changelog

index a5bbfe0..59c0949 100644 (file)
@@ -79,12 +79,8 @@ BookView::BookView(QWidget *parent):
     setBook(0);
 
     extractIcons();
-
 #ifdef Q_WS_MAEMO_5
     scroller = property("kineticScroller").value<QAbstractKineticScroller *>();
-    if (scroller) {
-        t.trace("Got scroller");
-    }
 #endif
 }
 
@@ -356,7 +352,6 @@ void BookView::removeIcons()
 
 bool BookView::eventFilter(QObject *o, QEvent *e)
 {
-#if 0
     if (e->type() != QEvent::Paint && e->type() != QEvent::MouseMove) {
         if (e->type() == QEvent::Resize) {
             Trace::trace(QString("BookView::eventFilter QEvent::Resize to %1").
@@ -366,7 +361,6 @@ bool BookView::eventFilter(QObject *o, QEvent *e)
                          arg(Trace::event(e->type())));
         }
     }
-#endif
 
     switch (e->type()) {
     case QEvent::MouseButtonPress:
@@ -454,6 +448,50 @@ void BookView::timerEvent(QTimerEvent *e)
         } else {
             killTimer(scrollerMonitor);
         }
-    }
 #endif // Q_WS_MAEMO_5
+    }
+}
+
+void BookView::keyPressEvent(QKeyEvent* event)
+{
+    switch (event->key()) {
+    case Qt::Key_F7:
+        goNextPage();
+        event->accept();
+        break;
+    case Qt::Key_F8:
+        goPreviousPage();
+        event->accept();
+        break;
+    default:
+        ;
+    }
+    QWebView::keyPressEvent(event);
+}
+
+void BookView::goPreviousPage()
+{
+    QWebFrame *frame = page()->mainFrame();
+    int pos = frame->scrollPosition().y();
+    frame->scroll(0, -height());
+    if (pos == frame->scrollPosition().y()) {
+        if (contentIndex > 0) {
+            goToBookmark(Book::Bookmark(contentIndex - 1, 1.0));
+        }
+    } else {
+        showProgress();
+    }
+}
+
+void BookView::goNextPage()
+{
+    Trace t("BookView::goNextPage");
+    QWebFrame *frame = page()->mainFrame();
+    int pos = frame->scrollPosition().y();
+    frame->scroll(0, height());
+    if (pos == frame->scrollPosition().y()) {
+        goNext();
+    } else {
+        showProgress();
+    }
 }
index 635363a..54c13ad 100644 (file)
@@ -58,6 +58,7 @@ protected:
     void leaveEvent(QEvent *e);
     void enterEvent(QEvent *e);
     void timerEvent(QTimerEvent *e);
+    void keyPressEvent(QKeyEvent *e);
 
 private:
     /** Save navigation icons from resource to the file system. */
@@ -81,6 +82,12 @@ 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 b7ebb8e..d327214 100755 (executable)
@@ -8,6 +8,9 @@
 #ifdef Q_WS_MAEMO_5
 #   include <QtMaemo5/QMaemo5InformationBox>
 #   include <QtDBus>
+#   include <QtGui/QX11Info>
+#   include <X11/Xlib.h>
+#   include <X11/Xatom.h>
 #   include <mce/mode-names.h>
 #   include <mce/dbus-names.h>
 #endif // Q_WS_MAEMO_5
@@ -46,6 +49,7 @@ MainWindow::MainWindow(QWidget *parent):
     Trace t("MainWindow::MainWindow");
 #ifdef Q_WS_MAEMO_5
     setAttribute(Qt::WA_Maemo5StackedWindow, true);
+    grabZoomKeys();
 #endif
     setWindowTitle("Dorian");
 
@@ -377,3 +381,27 @@ void MainWindow::resizeEvent(QResizeEvent *e)
     progress->setGeometry(QRect(0, 0, e->size().width(), PROGRESS_HEIGHT));
     QMainWindow::resizeEvent(e);
 }
+
+void MainWindow::grabZoomKeys()
+{
+#ifdef Q_WS_MAEMO_5
+    if (!winId()) {
+        qCritical() << "Can't grab keys unless we have a window id";
+        return;
+    }
+    unsigned long val = 1;
+    Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
+    if (!atom) {
+        qCritical() << "Unable to obtain _HILDON_ZOOM_KEY_ATOM";
+        return;
+    }
+    XChangeProperty(QX11Info::display(),
+        winId(),
+        atom,
+        XA_INTEGER,
+        32,
+        PropModeReplace,
+        reinterpret_cast<unsigned char *>(&val),
+        1);
+#endif // Q_WS_MAEMO_5
+}
index 1f1557d..327b334 100755 (executable)
@@ -46,6 +46,7 @@ private:
     void setCurrentBook(const QModelIndex &current);
     QAction *addToolBarAction(const QObject *receiver, const char *member,
                               const QString &name);
+    void grabZoomKeys();
     BookView *view;
     QAction *settingsAction;
     QAction *libraryAction;
index d5598ee..8a0fb85 100644 (file)
@@ -3,8 +3,9 @@ dorian (0.1.2-1) unstable; urgency=low
   * Improve cover image display
   * Fix naming: book parts vs. chapters
   * Show reading progress
+  * Navigate with volume keys
 
- -- Akos Polster <akos@pipacs.com>  Sat,  7 Aug 2010 20:00:00 +0200
+ -- Akos Polster <akos@pipacs.com>  Sat,  8 Aug 2010 20:00:00 +0200
 
 dorian (0.1.1-1) unstable; urgency=low