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>
21 #include "colorbuttons.hpp"
23 #include "fullscreenexitbutton.hpp"
24 #include "colorscheme.hpp"
29 setWindowTitle("Color Flood");
30 setWindowIcon(QIcon(":/images/icon_48x48.png"));
33 field = new Field(this, &turns);
34 colorButtons = new ColorButtons(this);
36 QObject::connect(colorButtons,
41 turnsLabel = new QLabel(this);
42 turnsLabel->setAlignment(Qt::AlignRight);
44 QObject::connect(field,
45 SIGNAL(turnsChanged(int)),
47 SLOT(updateTurns(int)));
51 QPushButton *newGame = new QPushButton(tr("New game"), this);
52 QObject::connect(newGame, SIGNAL(pressed()), field, SLOT(randomize()));
54 QVBoxLayout *vl = new QVBoxLayout;
55 vl->addWidget(colorButtons);
56 vl->setAlignment(colorButtons, Qt::AlignRight | Qt::AlignTop);
57 vl->addWidget(turnsLabel);
58 vl->setAlignment(turnsLabel, Qt::AlignRight | Qt::AlignBottom);
59 vl->addWidget(newGame);
60 vl->setAlignment(newGame, Qt::AlignRight | Qt::AlignTop);
62 QHBoxLayout *hl = new QHBoxLayout;
64 hl->setAlignment(field, Qt::AlignLeft);
70 QMenuBar *bar = new QMenuBar(this);
72 QObject::connect(bar->addAction(tr("Fullscreen mode")),
75 SLOT(fullScreenMode()));
77 QObject::connect(bar->addAction(
78 ColorScheme::getSchemeName(
79 ColorScheme::getNextColorScheme())),
84 less = bar->addAction(tr("Less cells"));
86 QObject::connect(less,
91 more = bar->addAction(tr("More cells"));
93 QObject::connect(more,
98 if (!field->getSize())
99 less->setEnabled(false);
100 else if (field->getSize() == Field::NUM_SIZES - 1)
101 more->setEnabled(false);
103 new FullScreenExitButton(this);
107 void Window::updateTurns (int turns)
109 /*: number of turns */
110 turnsLabel->setText(tr("<font size=\"12\">Turns: %1/%2</font>")
112 .arg(field->getNumTurnsOfSize(field->getSize())));
115 void Window::fullScreenMode ()
120 void Window::lessCells ()
122 int s = field->getSize() - 1;
125 more->setEnabled(true);
128 less->setEnabled(false);
131 void Window::moreCells ()
133 int s = field->getSize() + 1;
136 less->setEnabled(true);
138 if (s == Field::NUM_SIZES - 1)
139 more->setEnabled(false);
142 void Window::colorScheme ()
144 QAction *action = static_cast<typeof(action)>(QObject::sender());
146 ColorScheme::setScheme(ColorScheme::getNextColorScheme());
149 colorButtons->update();
151 action->setText(ColorScheme::getSchemeName(
152 ColorScheme::getNextColorScheme()));