Handle nested TOC items.
[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
33 signals:
34     void partLoadStart(int index);
35     void partLoadEnd(int index);
36
37     /** Signal button press when the real event has been suppressed. */
38     void suppressedMouseButtonPress();
39
40     /** Signal progress in reading the book. */
41     void progress(qreal p);
42
43 public slots:
44     /** Go to next part. */
45     void goPrevious();
46
47     /** Go to previous part. */
48     void goNext();
49
50     void onLoadFinished(bool ok);
51     void onSettingsChanged(const QString &key);
52
53     /** Add QObjects to the main frame. */
54     void addJavaScriptObjects();
55
56     /** Handle main frame contents size changes. */
57     void onContentsSizeChanged(const QSize &size);
58
59     /** Go to previous page. */
60     void goPreviousPage();
61
62     /** Go to next page. */
63     void goNextPage();
64
65 protected:
66     void paintEvent(QPaintEvent *e);
67     void mousePressEvent(QMouseEvent *e);
68     void wheelEvent(QWheelEvent *);
69     bool eventFilter(QObject *o, QEvent *e);
70     void leaveEvent(QEvent *e);
71     void enterEvent(QEvent *e);
72     void timerEvent(QTimerEvent *e);
73     void keyPressEvent(QKeyEvent *e);
74
75 private:
76     /** Load given part. */
77     void loadContent(int index);
78
79     /** Get temporary directory for extracting book contents. */
80     QString tmpPath();
81
82     /** Go to a given (relative) position in current part. */
83     void goToPosition(qreal position);
84
85     /** Show reading progress. */
86     void showProgress();
87
88     int contentIndex;   /**< Current part in book. */
89     Book *mBook;        /**< Book to show. */
90     bool restorePositionAfterLoad;
91                         /**< If true, restore current position after load. */
92     qreal positionAfterLoad;
93                         /**< Position to be restored after load. */
94     QImage bookmarkImage;
95                         /**< Bookmark icon pre-loaded. */
96     bool loaded;        /**< True if content has been loaded. */
97     bool mousePressed;
98     int contentsHeight; /**< Last know height of the frame. */
99
100 #if defined(Q_WS_MAEMO_5)
101     int scrollerMonitor;
102     QAbstractKineticScroller *scroller;
103 #endif
104 };
105
106 #endif // BOOKVIEW_H