Make full screen switching more robust. Add in/out traces.
[dorian] / fullscreenwindow.cpp
1 #include <QtGui>
2
3 #include "fullscreenwindow.h"
4 #include "translucentbutton.h"
5
6 FullScreenWindow::FullScreenWindow(QWidget *parent): QMainWindow(parent), child(0)
7 {
8     Q_ASSERT(parent);
9 #ifdef Q_WS_MAEMO_5
10     setAttribute(Qt::WA_Maemo5StackedWindow, true);
11     setAttribute(Qt::WA_Maemo5NonComposited, true);
12 #endif // Q_WS_MAEMO_5
13     QFrame *frame = new QFrame(this);
14     QVBoxLayout *layout = new QVBoxLayout(frame);
15     layout->setMargin(0);
16     frame->setLayout(layout);
17     setCentralWidget(frame);
18     restoreButton = new TranslucentButton("view-fullscreen", this);
19 }
20
21 void FullScreenWindow::showFullScreen()
22 {
23 #ifdef Q_WS_MAEMO_5
24     setAttribute(Qt::WA_Maemo5PortraitOrientation, parentWidget()->
25                  testAttribute(Qt::WA_Maemo5PortraitOrientation));
26     setAttribute(Qt::WA_Maemo5LandscapeOrientation, parentWidget()->
27                  testAttribute(Qt::WA_Maemo5LandscapeOrientation));
28 #endif // Q_WS_MAEMO_5
29     QWidget::showFullScreen();
30     restoreButton->flash();
31 }
32
33 void FullScreenWindow::MOUSE_ACTIVATE_EVENT(QMouseEvent *event)
34 {
35     if (fullScreenZone().contains(event->x(), event->y())) {
36         emit restore();
37     }
38     QMainWindow::MOUSE_ACTIVATE_EVENT(event);
39 }
40
41 QRect FullScreenWindow::fullScreenZone() const
42 {
43     return QRect(width() / 2 - 45, height() - 104, 95, 95);
44 }
45
46 void FullScreenWindow::resizeEvent(QResizeEvent *e)
47 {
48     restoreButton->setGeometry(fullScreenZone());
49     QMainWindow::resizeEvent(e);
50 }
51
52 void FullScreenWindow::takeChild(QWidget *c)
53 {
54     leaveChild();
55     if (c) {
56         child = c;
57         child->setParent(centralWidget());
58         centralWidget()->layout()->addWidget(child);
59     }
60 }
61
62 void FullScreenWindow::leaveChild()
63 {
64     if (child) {
65         centralWidget()->layout()->removeWidget(child);
66         child = 0;
67     }
68 }