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