841b527b4b73fabb9eb4cfa5d2897c97b6032f1e
[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     /** Handle key press events. */
65     void keyPressEvent(QKeyEvent *event);
66
67     /**
68      * Handle show events.
69      * On Symbian, volume keys can only be grabbed, if the window is shown.
70      */
71     void showEvent(QShowEvent *event);
72
73     /** Handle resize events. */
74     void resizeEvent(QResizeEvent *event);
75
76 #ifdef Q_OS_SYMBIAN
77     /** Update toolbar visibility. */
78     void updateToolBar();
79
80     /** Return true in portrait mode. */
81     bool portrait();
82 #endif // Q_OS_SYMBIAN
83
84 #ifdef Q_WS_MAEMO_5
85     /** Actually grab the volume keys. */
86     void doGrabVolumeKeys(bool grab);
87 #endif // Q_WS_MAEMO_5
88
89 protected slots:
90     void placeDecorations();
91
92 private:
93     BookView *bookView;     /**< Book view widget. */
94     bool grabbingVolumeKeys;/**< True, if volume keys should be grabbed. */
95     QToolBar *toolBar;      /**< Tool bar. */
96     Progress *progress;     /**< Reading progress indicator. */
97     TranslucentButton *previousButton;  /**< Previous page indicator. */
98     TranslucentButton *nextButton;      /**< Next page indicator. */
99 };
100
101 #endif // ADOPTERWINDOW_H