X-Git-Url: http://git.maemo.org/git/?p=colorflood;a=blobdiff_plain;f=colorflood%2Fsrc%2Ffield.cpp;h=7304540a28dd0f2ec63d54a2595fdabc88cdea5f;hp=b6a9db419b1c495330d501c9576e08f64902e704;hb=c67d5554ce76c3337e7b1b6d55297b0109abd0c7;hpb=79829f32441be520b96f26c5a689ab3f83e68890 diff --git a/colorflood/src/field.cpp b/colorflood/src/field.cpp index b6a9db4..7304540 100644 --- a/colorflood/src/field.cpp +++ b/colorflood/src/field.cpp @@ -114,6 +114,17 @@ Field::FieldSize Field::getSize () const return size; } +void Field::setSize (int size) +{ + Q_ASSERT(size >= 0 && size < NUM_SIZES); + + if (this->size == size) + return; + + this->size = (FieldSize)size; + randomize(); +} + void Field::randomize () { FieldRect rect; @@ -189,12 +200,6 @@ void Field::floodNeighbours (quint8 brush, int x, int y) tryFloodRecurse(brush, x, y + 1); } -void Field::mousePressEvent (QMouseEvent *event) -{ - if (event->button() == Qt::LeftButton) - randomize(); -} - void Field::paintEvent (QPaintEvent *event) { QPainter painter; @@ -243,7 +248,7 @@ void Field::flood (int colorIndex) } } - update(); + repaint(); bool allFlooded = true; @@ -259,22 +264,27 @@ void Field::flood (int colorIndex) } } + QString msg; + if (allFlooded) { finished = true; - - QMessageBox box; /*: win message */ - box.setText(tr("You won!")); - box.exec(); + msg = tr("You won!"); } else if (getNumTurnsOfSize(size) == turns) { finished = true; + /*: fail message */ + msg = tr("You lost!"); + } + if (finished) + { QMessageBox box; - /*: fail message */ - box.setText(tr("You lost!")); + box.setWindowTitle("Color Flood"); + box.setText(msg); box.exec(); + randomize(); } }