Jump to exact position on page, as identified by TOC entry. Handle
[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 class QModelIndex;
14 class Progress;
15 class QAbstractKineticScroller;
16 class ProgressDialog;
17
18 /** Visual representation of a book. */
19 class BookView: public QWebView
20 {
21     Q_OBJECT
22
23 public:
24     explicit BookView(QWidget *parent = 0);
25     virtual ~BookView();
26     void setBook(Book *book);
27     Book *book();
28     void goToBookmark(const Book::Bookmark &bookmark);
29     void addBookmark(const QString &note);
30     void setLastBookmark();
31     void restoreLastBookmark();
32     void goToPart(int part, const QString &fragment);
33     void goToFragment(const QString &fragment);
34
35 signals:
36     void partLoadStart(int index);
37     void partLoadEnd(int index);
38
39     /** Signal button press, when the real event has been suppressed. */
40     void suppressedMouseButtonPress();
41
42     /** Signal progress in reading the book. */
43     void progress(qreal p);
44
45 public slots:
46     /** Go to next part. */
47     void goPrevious();
48
49     /** Go to previous part. */
50     void goNext();
51
52     void onLoadFinished(bool ok);
53     void onSettingsChanged(const QString &key);
54
55     /** Add QObjects to the main frame. */
56     void addJavaScriptObjects();
57
58     /** Handle main frame contents size changes. */
59     void onContentsSizeChanged(const QSize &size);
60
61     /** Go to previous page. */
62     void goPreviousPage();
63
64     /** Go to next page. */
65     void goNextPage();
66
67 protected:
68     void paintEvent(QPaintEvent *e);
69     void mousePressEvent(QMouseEvent *e);
70     void wheelEvent(QWheelEvent *);
71     bool eventFilter(QObject *o, QEvent *e);
72 #ifdef Q_WS_MAEMO_5
73     void leaveEvent(QEvent *e);
74     void enterEvent(QEvent *e);
75 #endif // Q_WS_MAEMO_5
76     void timerEvent(QTimerEvent *e);
77     void keyPressEvent(QKeyEvent *e);
78
79 private:
80     /** Load given part. */
81     void loadContent(int index);
82
83     /** Get temporary directory for extracting book contents. */
84     QString tmpPath();
85
86     /** Go to a given (relative) position in current part. */
87     void goToPosition(qreal position);
88
89     /** Show reading progress. */
90     void showProgress();
91
92     int contentIndex;   /**< Current part in book. */
93     Book *mBook;        /**< Book to show. */
94     bool restorePositionAfterLoad;
95                         /**< If true, restore current position after load. */
96     qreal positionAfterLoad;
97                         /**< Position to be restored after load. */
98     bool restoreFragmentAfterLoad;
99                         /**< If true, restore fragment location after load. */
100     QString fragmentAfterLoad;
101                         /**< Fragment location to be restored after load. */
102     QImage bookmarkImage;
103                         /**< Bookmark icon pre-loaded. */
104     bool loaded;        /**< True if content has been loaded. */
105     bool mousePressed;
106     int contentsHeight; /**< Last know height of the frame. */
107
108 #if defined(Q_WS_MAEMO_5)
109     int scrollerMonitor;
110     QAbstractKineticScroller *scroller;
111 #endif
112 };
113
114 #endif // BOOKVIEW_H