Fix forward navigation control on Linux.
[dorian] / fullscreenwindow.cpp
index e5dc3c0..145b425 100644 (file)
@@ -2,44 +2,82 @@
 
 #include "fullscreenwindow.h"
 #include "translucentbutton.h"
+#include "progress.h"
+#include "trace.h"
+#include "settings.h"
+#include "platform.h"
 
-FullScreenWindow::FullScreenWindow(QWidget *child, QWidget *parent):
-        QMainWindow(parent)
+static const int MARGIN = 9;
+
+FullScreenWindow::FullScreenWindow(QWidget *parent): AdopterWindow(parent)
 {
-    Q_ASSERT(parent);
-#ifdef Q_WS_MAEMO_5
+    TRACE;
+
+#if defined(Q_WS_MAEMO_5)
     setAttribute(Qt::WA_Maemo5StackedWindow, true);
-    setAttribute(Qt::WA_Maemo5PortraitOrientation,
-                 parent->testAttribute(Qt::WA_Maemo5PortraitOrientation));
-    setAttribute(Qt::WA_Maemo5LandscapeOrientation,
-                 parent->testAttribute(Qt::WA_Maemo5LandscapeOrientation));
-#endif // Q_WS_MAEMO_5
-    child->setParent(this);
-    setCentralWidget(child);
-    restoreButton = new TranslucentButton("view-fullscreen", this);
+    setAttribute(Qt::WA_Maemo5NonComposited, true);
+#endif
+    QFrame *frame = new QFrame(this);
+    QVBoxLayout *layout = new QVBoxLayout(frame);
+    layout->setMargin(0);
+    frame->setLayout(layout);
+    setCentralWidget(frame);
+    restoreButton = new TranslucentButton("view-normal", this);
+    QRect screen = QApplication::desktop()->screenGeometry();
+    restoreButton->setGeometry(
+        screen.width() - TranslucentButton::pixels - MARGIN,
+        screen.height() - TranslucentButton::pixels - MARGIN,
+        TranslucentButton::pixels,
+        TranslucentButton::pixels);
+    connect(restoreButton, SIGNAL(triggered()), this, SIGNAL(restore()));
 }
 
-void FullScreenWindow::showFullScreen()
+void FullScreenWindow::showEvent(QShowEvent *e)
 {
-    QWidget::showFullScreen();
-    restoreButton->flash();
+    Trace t("FullScreenWindow::showEvent");
+    qDebug() << "Softkeys visible?"
+             << (windowFlags() & Qt::WindowSoftkeysVisibleHint);
+    placeChildren();
+    AdopterWindow::showEvent(e);
 }
 
-void FullScreenWindow::MOUSE_ACTIVATE_EVENT(QMouseEvent *event)
+void FullScreenWindow::resizeEvent(QResizeEvent *e)
 {
-    if (fullScreenZone().contains(event->x(), event->y())) {
-        emit restore();
-    }
-    QMainWindow::MOUSE_ACTIVATE_EVENT(event);
+    Trace t("FullScreenWindow::resizeEvent");
+    placeChildren();
+    AdopterWindow::resizeEvent(e);
 }
 
-QRect FullScreenWindow::fullScreenZone() const
+void FullScreenWindow::closeEvent(QCloseEvent *e)
 {
-    return QRect(width() / 2 - 45, height() - 104, 95, 95);
+    Trace t("FullscreenWindow::closeEvent");
+    AdopterWindow::closeEvent(e);
 }
 
-void FullScreenWindow::resizeEvent(QResizeEvent *e)
+void FullScreenWindow::placeChildren()
 {
-    restoreButton->setGeometry(fullScreenZone());
-    QMainWindow::resizeEvent(e);
+    Trace t("FullScreenWindow::placeChildren");
+
+    QRect screen = QApplication::desktop()->screenGeometry();
+    int w = screen.width();
+    int h = screen.height();
+
+#ifdef Q_WS_MAEMO_5
+    // Hack: FullScreenWindow can lose orientation on Maemo...
+    QString orientation = Settings::instance()->value("orientation",
+        Platform::instance()->defaultOrientation()).toString();
+    if (((orientation == "portrait") && (w > h)) ||
+        ((orientation == "landscape") && (w < h))) {
+        int tmp = w;
+        w = h;
+        h = tmp;
+    }
+#endif // Q_WS_MAEMO_5
+
+    restoreButton->setGeometry(
+        w - TranslucentButton::pixels - MARGIN,
+        h - TranslucentButton::pixels - MARGIN,
+        TranslucentButton::pixels,
+        TranslucentButton::pixels);
+    restoreButton->flash(3000);
 }