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