New version. Update home page link in About box.
[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 t("FullScreenWindow::showFullScreen");
42     AdopterWindow::showFullScreen();
43     placeChildren();
44 }
45
46 void FullScreenWindow::resizeEvent(QResizeEvent *e)
47 {
48     Trace t("FullScreenWindow::resizeEvent");
49     QTimer::singleShot(100, this, SLOT(placeChildren()));
50     AdopterWindow::resizeEvent(e);
51 }
52
53 void FullScreenWindow::takeChildren(BookView *view,
54                                     Progress *prog,
55                                     TranslucentButton *previous,
56                                     TranslucentButton *next)
57 {
58     TRACE;
59     progress = prog;
60     previousButton = previous;
61     nextButton = next;
62     QList<QWidget *> otherChildren;
63     otherChildren << progress << previousButton << nextButton;
64     AdopterWindow::takeChildren(view, otherChildren);
65 }
66
67 void FullScreenWindow::placeChildren()
68 {
69     Trace t("FullScreenWindow::placeChildren");
70
71     QRect screen = QApplication::desktop()->screenGeometry();
72     int w = screen.width();
73     int h = screen.height();
74
75 #ifdef Q_WS_MAEMO_5
76     // Hack: FullScreenWindow can lose orientation on Maemo...
77     QString orientation = Settings::instance()->value("orientation",
78         Platform::instance()->defaultOrientation()).toString();
79     if (((orientation == "portrait") && (w > h)) ||
80         ((orientation == "landscape") && (w < h))) {
81         int tmp = w;
82         w = h;
83         h = tmp;
84     }
85 #endif // Q_WS_MAEMO_5
86
87     restoreButton->setGeometry(
88         w - TranslucentButton::pixels - MARGIN,
89         h - TranslucentButton::pixels - MARGIN,
90         TranslucentButton::pixels,
91         TranslucentButton::pixels);
92
93     if (hasChild(progress)) {
94         progress->setGeometry(0, h - progress->thickness(),
95                               w, progress->thickness());
96         qDebug() << "Screen (FullScreenWindow::resizeEvent)" << w << "x" << h;
97         qDebug() << "Progress (FullScreenWindow::resizeEvent)"
98                 << progress->geometry();
99     }
100     if (hasChild(previousButton)) {
101         previousButton->setGeometry(
102                 MARGIN,
103                 h - TranslucentButton::pixels - MARGIN,
104                 TranslucentButton::pixels,
105                 TranslucentButton::pixels);
106     }
107     if (hasChild(nextButton)) {
108         nextButton->setGeometry(
109         w - TranslucentButton::pixels - MARGIN,
110         MARGIN,
111         TranslucentButton::pixels,
112         TranslucentButton::pixels);
113     }
114
115     restoreButton->flash(3000);
116 }