Navigate with volume keys.
[dorian] / bookview.h
1 #ifndef BOOKVIEW_H
2 #define BOOKVIEW_H
3
4 #include <QWebView>
5 #include <QString>
6 #include <QStringList>
7 #include <QHash>
8 #include <QImage>
9
10 #include "book.h"
11
12 class QModelIndex;
13 class Progress;
14 class QAbstractKineticScroller;
15
16 /** Visual representation of a book. */
17 class BookView: public QWebView
18 {
19     Q_OBJECT
20
21 public:
22     explicit BookView(QWidget *parent = 0);
23     virtual ~BookView();
24     void setBook(Book *book);
25     Book *book();
26     void goToBookmark(const Book::Bookmark &bookmark);
27     void addBookmark();
28     void setLastBookmark();
29     void restoreLastBookmark();
30
31 signals:
32     void partLoadStart(int index);
33     void partLoadEnd(int index);
34
35     /** Signal button press when the real event has been suppressed. */
36     void suppressedMouseButtonPress();
37
38     /** Signal progress in reading the book. */
39     void progress(qreal p);
40
41 public slots:
42     void goPrevious();
43     void goNext();
44     void onLoadFinished(bool ok);
45     void onSettingsChanged(const QString &key);
46
47     /** Add QObjects to the main frame. */
48     void addJavaScriptObjects();
49
50     /** Handle main frame contents size changes. */
51     void onContentsSizeChanged(const QSize &size);
52
53 protected:
54     void paintEvent(QPaintEvent *e);
55     void mousePressEvent(QMouseEvent *e);
56     void wheelEvent(QWheelEvent *);
57     bool eventFilter(QObject *o, QEvent *e);
58     void leaveEvent(QEvent *e);
59     void enterEvent(QEvent *e);
60     void timerEvent(QTimerEvent *e);
61     void keyPressEvent(QKeyEvent *e);
62
63 private:
64     /** Save navigation icons from resource to the file system. */
65     void extractIcons();
66
67     /** Remove extracted icons. */
68     void removeIcons();
69
70     /** Load given part. */
71     void loadContent(int index);
72
73     /** Decorate web page frame with navigation icons. */
74     void addNavigationBar();
75
76     /** Get temporary directory for extracting book contents. */
77     QString tmpPath();
78
79     /** Go to a given (relative) position in current part. */
80     void goToPosition(qreal position);
81
82     /** Show progress. */
83     void showProgress();
84
85     /** Go to previous page. */
86     void goPreviousPage();
87
88     /** Go to next page. */
89     void goNextPage();
90
91     int contentIndex;   /**< Current part in book. */
92     Book *mBook;        /**< Book to show. */
93     bool restorePositionAfterLoad;
94                         /**< If true, restoring position after load is needed. */
95     qreal positionAfterLoad;
96                         /**< Position to be restored after load. */
97     QImage bookmarkImage;
98                         /**< Bookmark icon pre-loaded. */
99     bool loaded;        /**< True if content has been loaded. */
100     bool mousePressed;
101     int contentsHeight; /**< Last know height of the frame. */
102     bool decorated;     /**< True after adding the arrows to the frame contents. */
103
104     int scrollerMonitor;
105 #ifdef Q_WS_MAEMO_5
106     QAbstractKineticScroller *scroller;
107 #endif
108 };
109
110 #endif // BOOKVIEW_H