a80eed7bb2a33256e6ca0d7a277ad8c494bc6db9
[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): AdopterWindow(parent)
13 {
14     TRACE;
15     Q_ASSERT(parent);
16 #ifdef Q_WS_MAEMO_5
17     setAttribute(Qt::WA_Maemo5StackedWindow, true);
18     setAttribute(Qt::WA_Maemo5NonComposited, true);
19 #endif // Q_WS_MAEMO_5
20     QFrame *frame = new QFrame(this);
21     QVBoxLayout *layout = new QVBoxLayout(frame);
22     layout->setMargin(0);
23     frame->setLayout(layout);
24     setCentralWidget(frame);
25     restoreButton = new TranslucentButton("view-normal", this);
26     QRect screen = QApplication::desktop()->screenGeometry();
27     restoreButton->setGeometry(
28         screen.width() - TranslucentButton::pixels - MARGIN,
29         screen.height() - TranslucentButton::pixels - MARGIN,
30         TranslucentButton::pixels,
31         TranslucentButton::pixels);
32     connect(restoreButton, SIGNAL(triggered()), this, SIGNAL(restore()));
33 }
34
35 void FullScreenWindow::showEvent(QShowEvent *e)
36 {
37     Trace t("FullScreenWindow::showEvent");
38     AdopterWindow::showEvent(e);
39     placeChildren();
40 }
41
42 void FullScreenWindow::resizeEvent(QResizeEvent *e)
43 {
44     Trace t("FullScreenWindow::resizeEvent");
45     AdopterWindow::resizeEvent(e);
46     placeChildren();
47 }
48
49 void FullScreenWindow::placeChildren()
50 {
51     Trace t("FullScreenWindow::placeChildren");
52
53     QRect screen = QApplication::desktop()->screenGeometry();
54     int w = screen.width();
55     int h = screen.height();
56
57 #ifdef Q_WS_MAEMO_5
58     // Hack: FullScreenWindow can lose orientation on Maemo...
59     QString orientation = Settings::instance()->value("orientation",
60         Platform::instance()->defaultOrientation()).toString();
61     if (((orientation == "portrait") && (w > h)) ||
62         ((orientation == "landscape") && (w < h))) {
63         int tmp = w;
64         w = h;
65         h = tmp;
66     }
67 #endif // Q_WS_MAEMO_5
68
69     restoreButton->setGeometry(
70         w - TranslucentButton::pixels - MARGIN,
71         h - TranslucentButton::pixels - MARGIN,
72         TranslucentButton::pixels,
73         TranslucentButton::pixels);
74     restoreButton->flash(3000);
75 }