ca8baba7f82256ef952b7e821dcfe8a07dd37d11
[dorian] / fullscreenwindow.cpp
1 #include <QtGui>
2
3 #include "fullscreenwindow.h"
4 #include "translucentbutton.h"
5 #include "progress.h"
6 #include "trace.h"
7 #include "settings.h"
8 #include "platform.h"
9
10 static const int MARGIN = 9;
11
12 FullScreenWindow::FullScreenWindow(QWidget *parent):
13         AdopterWindow(parent), progress(0), previousButton(0), nextButton(0)
14 {
15     TRACE;
16     Q_ASSERT(parent);
17 #ifdef Q_WS_MAEMO_5
18     setAttribute(Qt::WA_Maemo5StackedWindow, true);
19     setAttribute(Qt::WA_Maemo5NonComposited, true);
20 #endif // Q_WS_MAEMO_5
21 #ifndef Q_OS_SYMBIAN
22     toolBar->hide();
23 #endif
24     QFrame *frame = new QFrame(this);
25     QVBoxLayout *layout = new QVBoxLayout(frame);
26     layout->setMargin(0);
27     frame->setLayout(layout);
28     setCentralWidget(frame);
29     restoreButton = new TranslucentButton("view-normal", this);
30     QRect screen = QApplication::desktop()->screenGeometry();
31     restoreButton->setGeometry(
32         screen.width() - TranslucentButton::pixels - MARGIN,
33         screen.height() - TranslucentButton::pixels - MARGIN,
34         TranslucentButton::pixels,
35         TranslucentButton::pixels);
36     connect(restoreButton, SIGNAL(triggered()), this, SIGNAL(restore()));
37 }
38
39 void FullScreenWindow::showFullScreen()
40 {
41     TRACE;
42     AdopterWindow::showFullScreen();
43     restoreButton->flash(3000);
44 }
45
46 void FullScreenWindow::resizeEvent(QResizeEvent *e)
47 {
48     TRACE;
49
50     QRect screen = QApplication::desktop()->screenGeometry();
51     int w = screen.width();
52     int h = screen.height();
53
54 #ifdef Q_WS_MAEMO_5
55     // Hack: FullScreenWindow can lose orientation on Maemo...
56     QString orientation = Settings::instance()->value("orientation",
57         Platform::instance()->defaultOrientation()).toString();
58     if (((orientation == "portrait") && (w > h)) ||
59         ((orientation == "landscape") && (w < h))) {
60         int tmp = w;
61         w = h;
62         h = tmp;
63     }
64 #endif // Q_WS_MAEMO_5
65
66     restoreButton->setGeometry(
67         w - TranslucentButton::pixels - MARGIN,
68         h - TranslucentButton::pixels - MARGIN,
69         TranslucentButton::pixels,
70         TranslucentButton::pixels);
71
72     if (hasChild(progress)) {
73         progress->setGeometry(0, h - progress->thickness(),
74                               w, progress->thickness());
75     }
76     if (hasChild(previousButton)) {
77         previousButton->setGeometry(
78                 MARGIN,
79                 h - TranslucentButton::pixels - MARGIN,
80                 TranslucentButton::pixels,
81                 TranslucentButton::pixels);
82     }
83     if (hasChild(nextButton)) {
84         nextButton->setGeometry(
85         w - TranslucentButton::pixels - MARGIN,
86         MARGIN,
87         TranslucentButton::pixels,
88         TranslucentButton::pixels);
89     }
90
91     restoreButton->flash(3000);
92     AdopterWindow::resizeEvent(e);
93 }
94
95 void FullScreenWindow::takeChildren(BookView *view,
96                                     Progress *prog,
97                                     TranslucentButton *previous,
98                                     TranslucentButton *next)
99 {
100     TRACE;
101     progress = prog;
102     previousButton = previous;
103     nextButton = next;
104     QList<QWidget *> otherChildren;
105     otherChildren << progress << previousButton << nextButton;
106     AdopterWindow::takeChildren(view, otherChildren);
107 }