Clean up book view decorations code.
[dorian] / adopterwindow.h
1 #ifndef ADOPTERWINDOW_H
2 #define ADOPTERWINDOW_H
3
4 #include <QMainWindow>
5 #include <QList>
6
7 class QWidget;
8 class QToolBar;
9 class QAction;
10 class BookView;
11 class QVBoxLayout;
12 class Progress;
13 class TranslucentButton;
14
15 /**
16  * A toplevel window that can adopt a BookView and other children.
17  * On Maemo, it can also grab the volume keys.
18  */
19 class AdopterWindow: public QMainWindow
20 {
21     Q_OBJECT
22
23 public:
24     explicit AdopterWindow(QWidget *parent = 0);
25
26     /** Adopt book view and decorations. */
27     void takeBookView(BookView *bookView, Progress *prog,
28                       TranslucentButton *prev, TranslucentButton *next);
29
30     /** Release book view and decorations. */
31     void leaveBookView();
32
33     /** Return true if the book view is currently adopted. */
34     bool hasBookView();
35
36     /**
37      * Add action that is visible on the tool bar.
38      * @param   receiver    Object receiving "activated" signal.
39      * @param   slot        Slot receiving "activated" signal.
40      * @param   iconName    Base name of tool bar icon in resource file.
41      * @param   text        Tool bar item text.
42      * @param   important   On Symbian, only "important" actions are added to
43      *                      the tool bar. All actions are added to the Options
44      *                      menu though.
45      */
46     QAction *addToolBarAction(QObject *receiver, const char *slot,
47                               const QString &iconName, const QString &text,
48                               bool important = false);
49
50     /** Add spacing to tool bar. */
51     void addToolBarSpace();
52
53     /** Show window. */
54     void show();
55
56     /** If grab is true, volume keys will navigate the book view. */
57     void grabVolumeKeys(bool grab);
58
59 public slots:
60     /** Handle settings changes. */
61     void onSettingsChanged(const QString &key);
62
63 protected:
64     /** Return true, if we are in portrait mode. */
65     bool portrait();
66
67     /** Handle key press events. */
68     void keyPressEvent(QKeyEvent *event);
69
70     /**
71      * Handle show events.
72      * On Symbian, volume keys can only be grabbed, if the window is shown.
73      */
74     void showEvent(QShowEvent *event);
75
76     /** Handle resize events. */
77     void resizeEvent(QResizeEvent *event);
78
79 #ifdef Q_WS_MAEMO_5
80     /** Actually grab the volume keys. */
81     void doGrabVolumeKeys(bool grab);
82 #endif
83
84 protected slots:
85     void placeDecorations();
86
87 private:
88     BookView *bookView;     /**< Book view widget. */
89     bool grabbingVolumeKeys;/**< True, if volume keys should be grabbed. */
90     QToolBar *toolBar;      /**< Tool bar. */
91     Progress *progress;     /**< Reading progress indicator. */
92     TranslucentButton *previousButton;  /**< Previous page indicator. */
93     TranslucentButton *nextButton;      /**< Next page indicator. */
94 };
95
96 #endif // ADOPTERWINDOW_H