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"));
+
+ 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);
+
+ 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::updateTurns (int turns)
+{
+ /*: number of turns */
+ turnsLabel->setText(tr("<font size=\"16\">Turns: %1/%2</font>")
+ .arg(turns)
+ .arg(field->getNumTurnsOfSize(field->getSize())));
}