update version
[colorflood] / colorflood / src / window.cpp
index 63b485b..2825369 100644 (file)
 #include <QHBoxLayout>
 #include <QLabel>
 #include <QSettings>
+#include <QMenuBar>
+#include <QMessageBox>
 #include "window.hpp"
 #include "colorbuttons.hpp"
 #include "field.hpp"
-//#include "fullscreenexitbutton.hpp"
+#include "fullscreenexitbutton.hpp"
+#include "colorscheme.hpp"
 
 Window::Window ()
     : QWidget()
@@ -27,8 +30,6 @@ Window::Window ()
     setWindowTitle("Color Flood");
     setWindowIcon(QIcon(":/images/icon_48x48.png"));
 
-    //new FullScreenExitButton(this);
-
     int turns;
     field = new Field(this, &turns);
     colorButtons = new ColorButtons(this);
@@ -48,22 +49,23 @@ Window::Window ()
 
     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);
+    QPushButton *help = new QPushButton(tr("Help"), this);
+    QObject::connect(help, SIGNAL(pressed()), this, SLOT(help()));
+
+    QHBoxLayout *lowerLayout = new QHBoxLayout;
+    lowerLayout->addWidget(help);
+    lowerLayout->addWidget(newGame);
 
     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);
+    vl->setAlignment(turnsLabel, Qt::AlignRight | Qt::AlignBottom);
+    vl->addLayout(lowerLayout);
+    vl->setAlignment(lowerLayout, Qt::AlignRight | Qt::AlignTop);
 
     QHBoxLayout *hl = new QHBoxLayout;
     hl->addWidget(field);
@@ -72,29 +74,96 @@ Window::Window ()
 
     setLayout(hl);
 
-    QSettings settings;
+    /* menu bar */
+    QMenuBar *bar = new QMenuBar(this);
+
+    QObject::connect(bar->addAction(tr("Fullscreen mode")),
+                     SIGNAL(triggered()),
+                     this,
+                     SLOT(fullScreenMode()));
+
+    QObject::connect(bar->addAction(
+                         ColorScheme::getSchemeName(
+                             ColorScheme::getNextColorScheme())),
+                     SIGNAL(triggered()),
+                     this,
+                     SLOT(colorScheme()));
+
+    less = bar->addAction(tr("Less cells"));
 
-    if (settings.value("fullscreen", true).toBool())
-        showFullScreen();
+    QObject::connect(less,
+                     SIGNAL(triggered()),
+                     this,
+                     SLOT(lessCells()));
+
+    more = bar->addAction(tr("More cells"));
+
+    QObject::connect(more,
+                     SIGNAL(triggered()),
+                     this,
+                     SLOT(moreCells()));
+
+    if (!field->getSize())
+        less->setEnabled(false);
+    else if (field->getSize() == Field::NUM_SIZES - 1)
+        more->setEnabled(false);
+
+    new FullScreenExitButton(this);
+    showFullScreen();
 }
 
 void Window::updateTurns (int turns)
 {
     /*: number of turns */
-    turnsLabel->setText(tr("<font size=\"24\">Turns: %1/%2</font>")
+    turnsLabel->setText(tr("Turns: %1/%2")
                         .arg(turns)
                         .arg(field->getNumTurnsOfSize(field->getSize())));
 }
 
-void Window::toggleFullscreen ()
+void Window::fullScreenMode ()
+{
+    showFullScreen();
+}
+
+void Window::lessCells ()
+{
+    int s = field->getSize() - 1;
+
+    field->setSize(s);
+    more->setEnabled(true);
+
+    if (!s)
+        less->setEnabled(false);
+}
+
+void Window::moreCells ()
 {
-    bool isFullscreen = windowState() & Qt::WindowFullScreen;
+    int s = field->getSize() + 1;
 
-    QSettings settings;
-    settings.setValue("fullscreen", !isFullscreen);
+    field->setSize(s);
+    less->setEnabled(true);
+
+    if (s == Field::NUM_SIZES - 1)
+        more->setEnabled(false);
+}
 
-    if (isFullscreen)
-        showNormal();
-    else
-        showFullScreen();
+void Window::colorScheme ()
+{
+    QAction *action = static_cast<typeof(action)>(QObject::sender());
+
+    ColorScheme::setScheme(ColorScheme::getNextColorScheme());
+
+    field->update();
+    colorButtons->update();
+
+    action->setText(ColorScheme::getSchemeName(
+                        ColorScheme::getNextColorScheme()));
+}
+
+void Window::help ()
+{
+        QMessageBox box;
+        box.setWindowTitle("Color Flood");
+        box.setText(tr("The object of the game is to turn a board into one single color. Number of moves is limited. You start from top-left corner with one cell already flooded.\nGood luck!"));
+        box.exec();
 }