Much ado about nothing.
[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     void restoreLastBookmark();
28
29 signals:
30     void chapterLoadStart(int index);
31     void chapterLoadEnd(int index);
32
33     /** Signal button press when the real event has been suppressed. */
34     void suppressedMouseButtonPress();
35
36 public slots:
37     void goPrevious();
38     void goNext();
39     void onLoadFinished(bool ok);
40     void onSettingsChanged(const QString &key);
41
42     /** Add QObjects to the main frame. */
43     void addJavaScriptObjects();
44
45     /** Handle main frame contents size changes. */
46     void onContentsSizeChanged(const QSize &size);
47
48 protected:
49     virtual void paintEvent(QPaintEvent *e);
50     virtual void mousePressEvent(QMouseEvent *e);
51     bool eventFilter(QObject *o, QEvent *e);
52     virtual void leaveEvent(QEvent *);
53     virtual void enterEvent(QEvent *);
54
55 private:
56     /** Save navigation icons from resource to the file system. */
57     void extractIcons();
58
59     /** Remove extracted icons. */
60     void removeIcons();
61
62     /** Load given chapter. */
63     void loadContent(int index);
64
65     /** Decorate web page frame with navigation icons. */
66     void addNavigationBar();
67
68     /** Get temporary directory for extracting book contents. */
69     QString tmpPath();
70
71     /** Go to a given (relative) position in current chapter. */
72     void goToPosition(qreal position);
73
74     int contentIndex;   /**< Current chapter in book. */
75     Book *mBook;        /**< Book to show. */
76     bool restorePositionAfterLoad;
77                         /**< If true, restoring position after load is needed. */
78     qreal positionAfterLoad;
79                         /**< Position to be restored after load. */
80     QImage bookmarkImage;
81                         /**< Bookmark icon pre-loaded. */
82     bool loaded;        /**< True if content has been loaded. */
83     bool mousePressed;
84     int contentsHeight; /**< Last know height of the frame. */
85     bool decorated;     /**< True after adding the arrows to the frame contents. */
86 };
87
88 #endif // BOOKVIEW_H