1917d7825eb0d785133ec3c85344ffa4e09a976a
[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(bool fast = false);
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 progress in reading the book. */
63     void progress(qreal p);
64
65 public slots:
66     /** Go to next part. */
67     void goPrevious();
68
69     /** Go to previous part. */
70     void goNext();
71
72     /** Actions to perform after URL loading finished. */
73     void onLoadFinished(bool ok);
74
75     /** Handle settings changes. */
76     void onSettingsChanged(const QString &key);
77
78     /** Add QObjects to the main frame. */
79     void addJavaScriptObjects();
80
81     /** Go to previous page. */
82     void goPreviousPage();
83
84     /** Go to next page. */
85     void goNextPage();
86
87     /** Restore saved position after URL loading finished. */
88     void restoreAfterLoad();
89
90     /** Restore book's last reading position. */
91     void restoreLastBookmark();
92
93 #ifdef Q_OS_SYMBIAN
94     /** Adjust web view position after orientation change. */
95     void adjustPosition();
96 #endif
97
98 protected slots:
99 #ifdef Q_OS_SYMBIAN
100     /** Observe media keys. */
101     void onMediaKeysPressed(MediaKeysObserver::MediaKeys key);
102 #endif
103
104 protected:
105     void paintEvent(QPaintEvent *e);
106     void mousePressEvent(QMouseEvent *e);
107     void wheelEvent(QWheelEvent *);
108     bool eventFilter(QObject *o, QEvent *e);
109     void timerEvent(QTimerEvent *e);
110
111     /** Load given part. */
112     void loadContent(int index);
113
114     /** Get temporary directory for extracting book contents. */
115     QString tmpPath();
116
117     /** Go to a given (relative) position in current part. */
118     void goToPosition(qreal position);
119
120     /** Show reading progress. */
121     void showProgress();
122
123 private:
124     int contentIndex;       /**< Current part in book. */
125     Book *mBook;            /**< Book to show. */
126     bool restorePositionAfterLoad;
127                             /**< If true, restore current position after load. */
128     qreal positionAfterLoad;/**< Position to be restored after load. */
129     bool restoreFragmentAfterLoad;
130                             /**< If true, restore fragment location after load. */
131     QString fragmentAfterLoad;
132                             /**< Fragment location to be restored after load. */
133     QImage bookmarkImage;   /**< Bookmark icon pre-loaded. */
134     bool loaded;            /**< True, if content has been loaded. */
135     bool mousePressed;      /**< Event filter's mouse button state. */
136     bool grabbingVolumeKeys;/**< True, if volume keys should be grabbed. */
137
138 #if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
139     int scrollerMonitor;    /**< ID of timer monitoring kinetic scroll. */
140 #endif
141
142 #if defined(Q_WS_MAEMO_5)
143     QAbstractKineticScroller *scroller;
144 #endif
145
146 #if defined(Q_OS_SYMBIAN)
147     FlickCharm *charm;      /**< Kinetic scroller. */
148 #endif
149 };
150
151 #endif // BOOKVIEW_H