Show reading progress.
[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
10 #include "book.h"
11
12 class QModelIndex;
13 class Progress;
14
15 /** Visual representation of a book. */
16 class BookView: public QWebView
17 {
18     Q_OBJECT
19
20 public:
21     explicit BookView(QWidget *parent = 0);
22     virtual ~BookView();
23     void setBook(Book *book);
24     Book *book();
25     void goToBookmark(const Book::Bookmark &bookmark);
26     void addBookmark();
27     void setLastBookmark();
28     void restoreLastBookmark();
29
30 signals:
31     void partLoadStart(int index);
32     void partLoadEnd(int index);
33
34     /** Signal button press when the real event has been suppressed. */
35     void suppressedMouseButtonPress();
36
37     /** Signal progress in reading the book. */
38     void progress(qreal p);
39
40 public slots:
41     void goPrevious();
42     void goNext();
43     void onLoadFinished(bool ok);
44     void onSettingsChanged(const QString &key);
45
46     /** Add QObjects to the main frame. */
47     void addJavaScriptObjects();
48
49     /** Handle main frame contents size changes. */
50     void onContentsSizeChanged(const QSize &size);
51
52 protected:
53     void paintEvent(QPaintEvent *e);
54     void mousePressEvent(QMouseEvent *e);
55     void mouseReleaseEvent(QMouseEvent *e);
56     void wheelEvent(QWheelEvent *);
57     bool eventFilter(QObject *o, QEvent *e);
58     void leaveEvent(QEvent *e);
59     void enterEvent(QEvent *e);
60
61 private:
62     /** Save navigation icons from resource to the file system. */
63     void extractIcons();
64
65     /** Remove extracted icons. */
66     void removeIcons();
67
68     /** Load given part. */
69     void loadContent(int index);
70
71     /** Decorate web page frame with navigation icons. */
72     void addNavigationBar();
73
74     /** Get temporary directory for extracting book contents. */
75     QString tmpPath();
76
77     /** Go to a given (relative) position in current part. */
78     void goToPosition(qreal position);
79
80     /** Show progress. */
81     void showProgress();
82
83     int contentIndex;   /**< Current part in book. */
84     Book *mBook;        /**< Book to show. */
85     bool restorePositionAfterLoad;
86                         /**< If true, restoring position after load is needed. */
87     qreal positionAfterLoad;
88                         /**< Position to be restored after load. */
89     QImage bookmarkImage;
90                         /**< Bookmark icon pre-loaded. */
91     bool loaded;        /**< True if content has been loaded. */
92     bool mousePressed;
93     int contentsHeight; /**< Last know height of the frame. */
94     bool decorated;     /**< True after adding the arrows to the frame contents. */
95 };
96
97 #endif // BOOKVIEW_H