Clean up volume key handling code.
[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     void setBook(Book *book);
31     Book *book();
32     void goToBookmark(const Book::Bookmark &bookmark);
33     void addBookmark(const QString &note);
34     void setLastBookmark();
35     void restoreLastBookmark();
36     void goToPart(int part, const QString &fragment);
37     void goToFragment(const QString &fragment);
38
39     /** If grab is true, volume keys will generate act as page up/down. */
40     void grabVolumeKeys(bool grab);
41
42 signals:
43     void partLoadStart(int index);
44     void partLoadEnd(int index);
45
46     /** Signal button press, when the real event has been suppressed. */
47     void suppressedMouseButtonPress();
48
49     /** Signal progress in reading the book. */
50     void progress(qreal p);
51
52 public slots:
53     /** Go to next part. */
54     void goPrevious();
55
56     /** Go to previous part. */
57     void goNext();
58
59     void onLoadFinished(bool ok);
60     void onSettingsChanged(const QString &key);
61
62     /** Add QObjects to the main frame. */
63     void addJavaScriptObjects();
64
65     /** Handle main frame contents size changes. */
66     void onContentsSizeChanged(const QSize &size);
67
68     /** Go to previous page. */
69     void goPreviousPage();
70
71     /** Go to next page. */
72     void goNextPage();
73
74 protected slots:
75 #ifdef Q_OS_SYMBIAN
76     /** Observe media keys. */
77     void onMediaKeysPressed(MediaKeysObserver::MediaKeys key);
78 #endif
79
80 protected:
81     void paintEvent(QPaintEvent *e);
82     void mousePressEvent(QMouseEvent *e);
83     void wheelEvent(QWheelEvent *);
84     bool eventFilter(QObject *o, QEvent *e);
85     void timerEvent(QTimerEvent *e);
86 #ifdef Q_WS_MAEMO_5
87     void leaveEvent(QEvent *e);
88     void enterEvent(QEvent *e);
89 #endif // Q_WS_MAEMO_5
90
91     /** Load given part. */
92     void loadContent(int index);
93
94     /** Get temporary directory for extracting book contents. */
95     QString tmpPath();
96
97     /** Go to a given (relative) position in current part. */
98     void goToPosition(qreal position);
99
100     /** Show reading progress. */
101     void showProgress();
102
103     int contentIndex;       /**< Current part in book. */
104     Book *mBook;            /**< Book to show. */
105     bool restorePositionAfterLoad;
106                             /**< If true, restore current position after load. */
107     qreal positionAfterLoad;/**< Position to be restored after load. */
108     bool restoreFragmentAfterLoad;
109                             /**< If true, restore fragment location after load. */
110     QString fragmentAfterLoad;
111                             /**< Fragment location to be restored after load. */
112     QImage bookmarkImage;   /**< Bookmark icon pre-loaded. */
113     bool loaded;            /**< True, if content has been loaded. */
114     bool mousePressed;      /**< Event filter's mouse button state. */
115     int contentsHeight;     /**< Last know height of the frame. */
116     bool grabbingVolumeKeys;/**< True, if volume keys should be grabbed. */
117
118 #if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
119     int scrollerMonitor;    /**< ID of timer monitoring kinetic scroll. */
120 #endif
121 #if defined(Q_WS_MAEMO_5)
122     QAbstractKineticScroller *scroller;
123 #elif defined(Q_OS_SYMBIAN)
124     FlickCharm *charm;
125 #endif
126 };
127
128 #endif // BOOKVIEW_H