X-Git-Url: http://git.maemo.org/git/?p=colorflood;a=blobdiff_plain;f=colorflood%2Fsrc%2Fwindow.cpp;h=2825369ea21cb358e89b6c031ab7e5afee7e57da;hp=0ee555493592b7e2748afe93f1ef1bb3f8223e61;hb=2d27bd2bcce5e9fa03349f7096d3aa4055628f9a;hpb=83a85755d88a8e1abd737629cb9f59c3c9f1d55e diff --git a/colorflood/src/window.cpp b/colorflood/src/window.cpp index 0ee5554..2825369 100644 --- a/colorflood/src/window.cpp +++ b/colorflood/src/window.cpp @@ -11,41 +11,159 @@ GNU General Public License for more details. */ -#include +#include +#include +#include +#include +#include +#include +#include #include "window.hpp" +#include "colorbuttons.hpp" #include "field.hpp" +#include "fullscreenexitbutton.hpp" +#include "colorscheme.hpp" Window::Window () : QWidget() { - setWindowTitle(tr("Color flood")); - - setWindowState(windowState() | Qt::WindowFullScreen); - - QVector 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())); + + 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::AlignBottom); + vl->addLayout(lowerLayout); + vl->setAlignment(lowerLayout, Qt::AlignRight | Qt::AlignTop); + + QHBoxLayout *hl = new QHBoxLayout; + hl->addWidget(field); + hl->setAlignment(field, Qt::AlignLeft); + hl->addLayout(vl); + + setLayout(hl); + + /* 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")); + + 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("Turns: %1/%2") + .arg(turns) + .arg(field->getNumTurnsOfSize(field->getSize()))); +} + +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 () +{ + int s = field->getSize() + 1; + + field->setSize(s); + less->setEnabled(true); + + if (s == Field::NUM_SIZES - 1) + more->setEnabled(false); +} + +void Window::colorScheme () +{ + QAction *action = static_cast(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(); }