remove old stuff
[colorflood] / colorflood / src / window.cpp
index a189dcf..e0b64ea 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"));
+    setWindowTitle("Color Flood");
+    setWindowIcon(QIcon(":/images/icon_48x48.png"));
 
-    //setWindowState(windowState() | Qt::WindowFullScreen);
+    int turns;
+    field = new Field(this, &turns);
+    colorButtons = new ColorButtons(this);
 
-    QPushButton *button = new QPushButton("randomize", this);
-    field = new Field(this);
+    QObject::connect(colorButtons,
+                     SIGNAL(flood(int)),
+                     field,
+                     SLOT(flood(int)));
 
-    QObject::connect(button, SIGNAL(pressed()), this, SLOT(randomize()));
+    turnsLabel = new QLabel(this);
+    turnsLabel->setAlignment(Qt::AlignRight);
 
-    QHBoxLayout *layout = new QHBoxLayout;
-    layout->addWidget(button);
-    layout->setAlignment(button, Qt::AlignLeft);
-    layout->addWidget(field);
-    layout->setAlignment(field, Qt::AlignRight);
-    setLayout(layout);
+    QObject::connect(field,
+                     SIGNAL(turnsChanged(int)),
+                     this,
+                     SLOT(updateTurns(int)));
+
+    updateTurns(turns);
+
+    QPushButton *newGame = new QPushButton(tr("New game"), this);
+    QObject::connect(newGame, SIGNAL(pressed()), field, SLOT(randomize()));
+
+    QVBoxLayout *vl = new QVBoxLayout;
+    vl->addWidget(colorButtons);
+    vl->setAlignment(colorButtons, Qt::AlignRight | Qt::AlignTop);
+    vl->addWidget(turnsLabel);
+    vl->setAlignment(turnsLabel, Qt::AlignRight | Qt::AlignBottom);
+    vl->addWidget(newGame);
+    vl->setAlignment(newGame, Qt::AlignRight | Qt::AlignTop);
+
+    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();
+
+    new FullScreenExitButton(this);
+}
+
+Window::~Window ()
+{
+    bool isFullscreen = windowState() & Qt::WindowFullScreen;
+
+    QSettings settings;
+    settings.setValue("fullscreen", isFullscreen);
 }
 
-void Window::randomize ()
+void Window::updateTurns (int turns)
 {
-    field->randomize();
+    /*: number of turns */
+    turnsLabel->setText(tr("<font size=\"16\">Turns: %1/%2</font>")
+                        .arg(turns)
+                        .arg(field->getNumTurnsOfSize(field->getSize())));
 }