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