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