Restore bookmarks to the correct position.
[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
14 /** Visual representation of a book. */
15 class BookView: public QWebView
16 {
17     Q_OBJECT
18
19 public:
20     explicit BookView(QWidget *parent = 0);
21     virtual ~BookView();
22     void setBook(Book *book);
23     Book *book();
24     void goToBookmark(const Book::Bookmark &bookmark);
25     void addBookmark();
26     void setLastBookmark();
27
28 signals:
29     void chapterLoadStart(int index);
30     void chapterLoadEnd(int index);
31
32     /** Signal button press when the real event has been suppressed. */
33     void suppressedMouseButtonPress();
34
35 public slots:
36     void goPrevious();
37     void goNext();
38     void onLoadFinished(bool ok);
39     void onSettingsChanged(const QString &key);
40
41     /** Add QObjects to the main frame. */
42     void addJavaScriptObjects();
43
44     /** Handle main frame contents size changes. */
45     void onContentsSizeChanged(const QSize &size);
46
47 protected:
48     virtual void paintEvent(QPaintEvent *e);
49     virtual void mousePressEvent(QMouseEvent *e);
50     bool eventFilter(QObject *o, QEvent *e);
51
52 private:
53     /** Save navigation icons from resource to the file system. */
54     void extractIcons();
55
56     /** Remove extracted icons. */
57     void removeIcons();
58
59     /** Load given chapter. */
60     void loadContent(int index);
61
62     /** Decorate web page frame with navigation icons. */
63     void addNavigationBar();
64
65     /** Get temporary directory for extracting book contents. */
66     QString tmpPath();
67
68     int contentIndex;   /**< Current chapter in book. */
69     Book *mBook;        /**< Book to show. */
70     bool restore;       /**< Restoring position after load is needed. */
71     qreal positionAfterLoad;
72                         /**< Position to be restored after load. */
73     QImage bookmarkImage;
74                         /**< Bookmark icon pre-loaded. */
75     bool loaded;        /**< True if content has been loaded. */
76     bool mousePressed;
77     int contentsHeight; /**< Last know height of the frame. */
78     bool decorated;     /**< True after adding the arrows to the frame contents. */
79 };
80
81 #endif // BOOKVIEW_H