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