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