Avoid complex types as statics.
[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     /** Part loading started. */
44     void partLoadStart(int index);
45
46     /** Part loading finished. */
47     void partLoadEnd(int index);
48
49     /** Signal button press, when the real event has been suppressed. */
50     void suppressedMouseButtonPress();
51
52     /** Signal progress in reading the book. */
53     void progress(qreal p);
54
55 public slots:
56     /** Go to next part. */
57     void goPrevious();
58
59     /** Go to previous part. */
60     void goNext();
61
62     /** Actions to perform after URL loading finished. */
63     void onLoadFinished(bool ok);
64
65     /** Handle settings changes. */
66     void onSettingsChanged(const QString &key);
67
68     /** Add QObjects to the main frame. */
69     void addJavaScriptObjects();
70
71     /** Go to previous page. */
72     void goPreviousPage();
73
74     /** Go to next page. */
75     void goNextPage();
76
77     /** Restore saved position after URL loading finished. */
78     void restoreAfterLoad();
79
80 protected slots:
81 #ifdef Q_OS_SYMBIAN
82     /** Observe media keys. */
83     void onMediaKeysPressed(MediaKeysObserver::MediaKeys key);
84 #endif
85
86 protected:
87     void paintEvent(QPaintEvent *e);
88     void mousePressEvent(QMouseEvent *e);
89     void wheelEvent(QWheelEvent *);
90     bool eventFilter(QObject *o, QEvent *e);
91     void timerEvent(QTimerEvent *e);
92 #ifdef Q_WS_MAEMO_5
93     void leaveEvent(QEvent *e);
94     void resizeEvent(QEvent *e);
95 #endif // Q_WS_MAEMO_5
96
97     /** Load given part. */
98     void loadContent(int index);
99
100     /** Get temporary directory for extracting book contents. */
101     QString tmpPath();
102
103     /** Go to a given (relative) position in current part. */
104     void goToPosition(qreal position);
105
106     /** Show reading progress. */
107     void showProgress();
108
109     int contentIndex;       /**< Current part in book. */
110     Book *mBook;            /**< Book to show. */
111     bool restorePositionAfterLoad;
112                             /**< If true, restore current position after load. */
113     qreal positionAfterLoad;/**< Position to be restored after load. */
114     bool restoreFragmentAfterLoad;
115                             /**< If true, restore fragment location after load. */
116     QString fragmentAfterLoad;
117                             /**< Fragment location to be restored after load. */
118     QImage bookmarkImage;   /**< Bookmark icon pre-loaded. */
119     bool loaded;            /**< True, if content has been loaded. */
120     bool mousePressed;      /**< Event filter's mouse button state. */
121     bool grabbingVolumeKeys;/**< True, if volume keys should be grabbed. */
122
123 #if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
124     int scrollerMonitor;    /**< ID of timer monitoring kinetic scroll. */
125 #endif
126 #if defined(Q_WS_MAEMO_5)
127     QAbstractKineticScroller *scroller;
128 #elif defined(Q_OS_SYMBIAN)
129     FlickCharm *charm;
130 #endif
131 };
132
133 #endif // BOOKVIEW_H