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