Show progress during kinetic scrolling, too.
[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
62 private:
63     /** Save navigation icons from resource to the file system. */
64     void extractIcons();
65
66     /** Remove extracted icons. */
67     void removeIcons();
68
69     /** Load given part. */
70     void loadContent(int index);
71
72     /** Decorate web page frame with navigation icons. */
73     void addNavigationBar();
74
75     /** Get temporary directory for extracting book contents. */
76     QString tmpPath();
77
78     /** Go to a given (relative) position in current part. */
79     void goToPosition(qreal position);
80
81     /** Show progress. */
82     void showProgress();
83
84     int contentIndex;   /**< Current part in book. */
85     Book *mBook;        /**< Book to show. */
86     bool restorePositionAfterLoad;
87                         /**< If true, restoring position after load is needed. */
88     qreal positionAfterLoad;
89                         /**< Position to be restored after load. */
90     QImage bookmarkImage;
91                         /**< Bookmark icon pre-loaded. */
92     bool loaded;        /**< True if content has been loaded. */
93     bool mousePressed;
94     int contentsHeight; /**< Last know height of the frame. */
95     bool decorated;     /**< True after adding the arrows to the frame contents. */
96
97     int scrollerMonitor;
98 #ifdef Q_WS_MAEMO_5
99     QAbstractKineticScroller *scroller;
100 #endif
101 };
102
103 #endif // BOOKVIEW_H