2 Copyright 2010 Serge Ziryukin <ftrvxmtrx@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
14 #include <QPushButton>
15 #include <QVBoxLayout>
16 #include <QHBoxLayout>
20 #include <QMessageBox>
22 #include "colorbuttons.hpp"
24 #include "fullscreenexitbutton.hpp"
25 #include "colorscheme.hpp"
30 setWindowTitle("Color Flood");
31 setWindowIcon(QIcon(":/images/icon_48x48.png"));
34 field = new Field(this, &turns);
35 colorButtons = new ColorButtons(this);
37 QObject::connect(colorButtons,
42 turnsLabel = new QLabel(this);
43 turnsLabel->setAlignment(Qt::AlignRight);
45 QObject::connect(field,
46 SIGNAL(turnsChanged(int)),
48 SLOT(updateTurns(int)));
52 QPushButton *newGame = new QPushButton(tr("New game"), this);
53 QObject::connect(newGame, SIGNAL(pressed()), field, SLOT(randomize()));
55 QPushButton *help = new QPushButton(tr("Help"), this);
56 QObject::connect(help, SIGNAL(pressed()), this, SLOT(help()));
58 QHBoxLayout *lowerLayout = new QHBoxLayout;
59 lowerLayout->addWidget(help);
60 lowerLayout->addWidget(newGame);
62 QVBoxLayout *vl = new QVBoxLayout;
63 vl->addWidget(colorButtons);
64 vl->setAlignment(colorButtons, Qt::AlignRight | Qt::AlignTop);
65 vl->addWidget(turnsLabel);
66 vl->setAlignment(turnsLabel, Qt::AlignRight | Qt::AlignBottom);
67 vl->addLayout(lowerLayout);
68 vl->setAlignment(lowerLayout, Qt::AlignRight | Qt::AlignTop);
70 QHBoxLayout *hl = new QHBoxLayout;
72 hl->setAlignment(field, Qt::AlignLeft);
78 QMenuBar *bar = new QMenuBar(this);
80 QObject::connect(bar->addAction(tr("Fullscreen mode")),
83 SLOT(fullScreenMode()));
85 QObject::connect(bar->addAction(
86 ColorScheme::getSchemeName(
87 ColorScheme::getNextColorScheme())),
92 less = bar->addAction(tr("Less cells"));
94 QObject::connect(less,
99 more = bar->addAction(tr("More cells"));
101 QObject::connect(more,
106 if (!field->getSize())
107 less->setEnabled(false);
108 else if (field->getSize() == Field::NUM_SIZES - 1)
109 more->setEnabled(false);
111 new FullScreenExitButton(this);
115 void Window::updateTurns (int turns)
117 /*: number of turns */
118 turnsLabel->setText(tr("Turns: %1/%2")
120 .arg(field->getNumTurnsOfSize(field->getSize())));
123 void Window::fullScreenMode ()
128 void Window::lessCells ()
130 int s = field->getSize() - 1;
133 more->setEnabled(true);
136 less->setEnabled(false);
139 void Window::moreCells ()
141 int s = field->getSize() + 1;
144 less->setEnabled(true);
146 if (s == Field::NUM_SIZES - 1)
147 more->setEnabled(false);
150 void Window::colorScheme ()
152 QAction *action = static_cast<typeof(action)>(QObject::sender());
154 ColorScheme::setScheme(ColorScheme::getNextColorScheme());
157 colorButtons->update();
159 action->setText(ColorScheme::getSchemeName(
160 ColorScheme::getNextColorScheme()));
166 box.setWindowTitle("Color Flood");
167 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!"));