hildon fullscreen button is back
[colorflood] / colorflood / src / window.cpp
index affafdc..ef4f63d 100644 (file)
 #include <QVBoxLayout>
 #include <QHBoxLayout>
 #include <QLabel>
+#include <QSettings>
 #include "window.hpp"
 #include "colorbuttons.hpp"
 #include "field.hpp"
-//#include "fullscreenexitbutton.hpp"
+#include "fullscreenexitbutton.hpp"
 
 Window::Window ()
     : QWidget()
@@ -26,13 +27,7 @@ Window::Window ()
     setWindowTitle("Color Flood");
     setWindowIcon(QIcon(":/images/icon_48x48.png"));
 
-#if defined(Q_WS_HILDON) || defined(Q_WS_MAEMO_5)
-    setWindowState(windowState() | Qt::WindowFullScreen);
-#else
-    setFixedSize(800, 480);
-#endif
-
-    //new FullScreenExitButton(this);
+    new FullScreenExitButton(this);
 
     int turns;
     field = new Field(this, &turns);
@@ -44,6 +39,7 @@ Window::Window ()
                      SLOT(flood(int)));
 
     turnsLabel = new QLabel(this);
+    turnsLabel->setAlignment(Qt::AlignRight);
 
     QObject::connect(field,
                      SIGNAL(turnsChanged(int)),
@@ -52,11 +48,22 @@ Window::Window ()
 
     updateTurns(turns);
 
+    QHBoxLayout *secondary = new QHBoxLayout;
+    QPushButton *toggleFS = new QPushButton(QPixmap("/usr/share/icons/hicolor/64x64/hildon/general_fullsize"), tr("Toggle fullscreen"), this);
+    QObject::connect(toggleFS, SIGNAL(pressed()), this, SLOT(toggleFullscreen()));
+    QPushButton *newGame = new QPushButton(tr("New game"), this);
+    QObject::connect(newGame, SIGNAL(pressed()), field, SLOT(randomize()));
+
+    secondary->addWidget(newGame);
+    secondary->addWidget(toggleFS);
+
     QVBoxLayout *vl = new QVBoxLayout;
     vl->addWidget(colorButtons);
     vl->setAlignment(colorButtons, Qt::AlignRight | Qt::AlignTop);
     vl->addWidget(turnsLabel);
     vl->setAlignment(turnsLabel, Qt::AlignRight | Qt::AlignTop);
+    vl->addLayout(secondary);
+    vl->setAlignment(secondary, Qt::AlignRight | Qt::AlignBottom);
 
     QHBoxLayout *hl = new QHBoxLayout;
     hl->addWidget(field);
@@ -64,12 +71,30 @@ Window::Window ()
     hl->addLayout(vl);
 
     setLayout(hl);
+
+    QSettings settings;
+
+    if (settings.value("fullscreen", true).toBool())
+        showFullScreen();
 }
 
 void Window::updateTurns (int turns)
 {
     /*: number of turns */
-    turnsLabel->setText(tr("Turns: %1/%2")
+    turnsLabel->setText(tr("<font size=\"16\">Turns: %1/%2</font>")
                         .arg(turns)
                         .arg(field->getNumTurnsOfSize(field->getSize())));
 }
+
+void Window::toggleFullscreen ()
+{
+    bool isFullscreen = windowState() & Qt::WindowFullScreen;
+
+    QSettings settings;
+    settings.setValue("fullscreen", !isFullscreen);
+
+    if (isFullscreen)
+        showNormal();
+    else
+        showFullScreen();
+}