Fix progress and bookmark positions. Fix runaway scroll monitor timer.
[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     /** Go to next part. */
43     void goPrevious();
44
45     /** Go to previous part. */
46     void goNext();
47
48     void onLoadFinished(bool ok);
49     void onSettingsChanged(const QString &key);
50
51     /** Add QObjects to the main frame. */
52     void addJavaScriptObjects();
53
54     /** Handle main frame contents size changes. */
55     void onContentsSizeChanged(const QSize &size);
56
57     /** Go to previous page. */
58     void goPreviousPage();
59
60     /** Go to next page. */
61     void goNextPage();
62
63 protected:
64     void paintEvent(QPaintEvent *e);
65     void mousePressEvent(QMouseEvent *e);
66     void wheelEvent(QWheelEvent *);
67     bool eventFilter(QObject *o, QEvent *e);
68     void leaveEvent(QEvent *e);
69     void enterEvent(QEvent *e);
70     void timerEvent(QTimerEvent *e);
71     void keyPressEvent(QKeyEvent *e);
72
73 private:
74     /** Load given part. */
75     void loadContent(int index);
76
77     /** Get temporary directory for extracting book contents. */
78     QString tmpPath();
79
80     /** Go to a given (relative) position in current part. */
81     void goToPosition(qreal position);
82
83     /** Show progress. */
84     void showProgress();
85
86     int contentIndex;   /**< Current part in book. */
87     Book *mBook;        /**< Book to show. */
88     bool restorePositionAfterLoad;
89                         /**< If true, restoring position after load is needed. */
90     qreal positionAfterLoad;
91                         /**< Position to be restored after load. */
92     QImage bookmarkImage;
93                         /**< Bookmark icon pre-loaded. */
94     bool loaded;        /**< True if content has been loaded. */
95     bool mousePressed;
96     int contentsHeight; /**< Last know height of the frame. */
97
98 #ifdef Q_WS_MAEMO_5
99     int scrollerMonitor;
100     QAbstractKineticScroller *scroller;
101 #endif
102 };
103
104 #endif // BOOKVIEW_H