new game/toggle fullscreen buttons
[colorflood] / colorflood / src / window.cpp
index 0ee5554..63b485b 100644 (file)
   GNU General Public License for more details.
 */
 
-#include <QtGui>
+#include <QPushButton>
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QSettings>
 #include "window.hpp"
+#include "colorbuttons.hpp"
 #include "field.hpp"
+//#include "fullscreenexitbutton.hpp"
 
 Window::Window ()
     : QWidget()
 {
-    setWindowTitle(tr("Color flood"));
-
-    setWindowState(windowState() | Qt::WindowFullScreen);
-
-    QVector<QBrush> brushes;
-
-#if 1
-    // standart color scheme
-    brushes << QBrush(QColor(0x00, 0x00, 0xff)); // blue
-    brushes << QBrush(QColor(0xff, 0x00, 0x00)); // red
-    brushes << QBrush(QColor(0x00, 0xff, 0x00)); // green
-    brushes << QBrush(QColor(0xff, 0xff, 0x00)); // yellow
-    brushes << QBrush(QColor(0xff, 0x00, 0xff)); // magenta
-    brushes << QBrush(QColor(0x80, 0x00, 0x80)); // purple
-#else
-    // color-blind color scheme
-    brushes << QBrush(QColor(0x00, 0x00, 0x00));
-    brushes << QBrush(QColor(0x31, 0x31, 0x31), Qt::Dense1Pattern);
-    brushes << QBrush(QColor(0x62, 0x62, 0x62), Qt::Dense3Pattern);
-    brushes << QBrush(QColor(0x93, 0x93, 0x93), Qt::CrossPattern);
-    brushes << QBrush(QColor(0xc4, 0xc4, 0xc4));
-    brushes << QBrush(QColor(0xff, 0xff, 0xff));
-#endif
-
-    field = new Field(this, brushes, Field::SIZE_LARGE);
-
-    QHBoxLayout *layout = new QHBoxLayout;
-    layout->addWidget(field);
-    layout->setAlignment(field, Qt::AlignRight);
-    setLayout(layout);
+    setWindowTitle("Color Flood");
+    setWindowIcon(QIcon(":/images/icon_48x48.png"));
+
+    //new FullScreenExitButton(this);
+
+    int turns;
+    field = new Field(this, &turns);
+    colorButtons = new ColorButtons(this);
+
+    QObject::connect(colorButtons,
+                     SIGNAL(flood(int)),
+                     field,
+                     SLOT(flood(int)));
+
+    turnsLabel = new QLabel(this);
+    turnsLabel->setAlignment(Qt::AlignRight);
+
+    QObject::connect(field,
+                     SIGNAL(turnsChanged(int)),
+                     this,
+                     SLOT(updateTurns(int)));
+
+    updateTurns(turns);
+
+    QHBoxLayout *secondary = new QHBoxLayout;
+    QPushButton *toggleFS = new QPushButton(QIcon("/usr/share/icons/hicolor/64x64/hildon/general_fullsize.png"), 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);
+    hl->setAlignment(field, Qt::AlignLeft);
+    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("<font size=\"24\">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();
 }