Speed up paging through the book. Clean up code for saving/restoring
[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 #ifdef Q_OS_SYMBIAN
14 #   include "mediakeysobserver.h"
15 #endif
16
17 class QModelIndex;
18 class Progress;
19 class QAbstractKineticScroller;
20 class ProgressDialog;
21 class FlickCharm;
22
23 /** Visual representation of a book. */
24 class BookView: public QWebView
25 {
26     Q_OBJECT
27
28 public:
29     explicit BookView(QWidget *parent = 0);
30
31     /** Set current book. */
32     void setBook(Book *book);
33
34     /** Get current book. */
35     Book *book();
36
37     /** Go to the position decribed by "bookmark". */
38     void goToBookmark(const Book::Bookmark &bookmark);
39
40     /** Add bookmark to book at the current position. */
41     void addBookmark(const QString &note);
42
43     /** Save current reading position into book. */
44     void setLastBookmark();
45
46     /** Go to given part + part fragment URL. */
47     void goToPart(int part, const QString &fragment);
48
49     /** Go to given fragment URL in current part. */
50     void goToFragment(const QString &fragment);
51
52     /** If grab is true, volume keys will generate act as page up/down. */
53     void grabVolumeKeys(bool grab);
54
55 signals:
56     /** Part loading started. */
57     void partLoadStart(int index);
58
59     /** Part loading finished. */
60     void partLoadEnd(int index);
61
62     /** Signal button press, when the real event has been suppressed. */
63     void suppressedMouseButtonPress();
64
65     /** Signal progress in reading the book. */
66     void progress(qreal p);
67
68 public slots:
69     /** Go to next part. */
70     void goPrevious();
71
72     /** Go to previous part. */
73     void goNext();
74
75     /** Actions to perform after URL loading finished. */
76     void onLoadFinished(bool ok);
77
78     /** Handle settings changes. */
79     void onSettingsChanged(const QString &key);
80
81     /** Add QObjects to the main frame. */
82     void addJavaScriptObjects();
83
84     /** Go to previous page. */
85     void goPreviousPage();
86
87     /** Go to next page. */
88     void goNextPage();
89
90     /** Restore saved position after URL loading finished. */
91     void restoreAfterLoad();
92
93     /** Restore book's last reading position. */
94     void restoreLastBookmark();
95
96 protected slots:
97 #ifdef Q_OS_SYMBIAN
98     /** Observe media keys. */
99     void onMediaKeysPressed(MediaKeysObserver::MediaKeys key);
100 #endif
101
102 protected:
103     void paintEvent(QPaintEvent *e);
104     void mousePressEvent(QMouseEvent *e);
105     void wheelEvent(QWheelEvent *);
106     bool eventFilter(QObject *o, QEvent *e);
107     void timerEvent(QTimerEvent *e);
108
109     /** Load given part. */
110     void loadContent(int index);
111
112     /** Get temporary directory for extracting book contents. */
113     QString tmpPath();
114
115     /** Go to a given (relative) position in current part. */
116     void goToPosition(qreal position);
117
118     /** Show reading progress. */
119     void showProgress();
120
121     int contentIndex;       /**< Current part in book. */
122     Book *mBook;            /**< Book to show. */
123     bool restorePositionAfterLoad;
124                             /**< If true, restore current position after load. */
125     qreal positionAfterLoad;/**< Position to be restored after load. */
126     bool restoreFragmentAfterLoad;
127                             /**< If true, restore fragment location after load. */
128     QString fragmentAfterLoad;
129                             /**< Fragment location to be restored after load. */
130     QImage bookmarkImage;   /**< Bookmark icon pre-loaded. */
131     bool loaded;            /**< True, if content has been loaded. */
132     bool mousePressed;      /**< Event filter's mouse button state. */
133     bool grabbingVolumeKeys;/**< True, if volume keys should be grabbed. */
134
135 #if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
136     int scrollerMonitor;    /**< ID of timer monitoring kinetic scroll. */
137 #endif
138 #if defined(Q_WS_MAEMO_5)
139     QAbstractKineticScroller *scroller;
140 #elif defined(Q_OS_SYMBIAN)
141     FlickCharm *charm;
142 #endif
143 };
144
145 #endif // BOOKVIEW_H