2 Image Puzzle - A set your pieces straight game
3 Copyright (C) 2009 Timo Härkönen
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "puzzleitem.h"
22 #include <QGraphicsSceneMouseEvent>
23 #include <QPropertyAnimation>
25 PuzzleItem::PuzzleItem(QGraphicsItem *parent) :
26 QGraphicsPixmapItem(parent)
29 moveAnimation_ = new QPropertyAnimation(this, "pos", this);
32 QPointF PuzzleItem::correctPlace() const
37 QPointF PuzzleItem::currentPlace() const
42 void PuzzleItem::setCorrectPlace(const QPointF &place)
44 correctPlace_ = place;
47 void PuzzleItem::setCurrentPlace(const QPointF &place)
49 currentPlace_ = place;
52 bool PuzzleItem::movable() const
57 void PuzzleItem::setMovable(bool canMove)
62 void PuzzleItem::moveMeTo(const QPointF &location)
64 moveAnimation_->setStartValue(currentPlace());
65 moveAnimation_->setEndValue(location);
66 moveAnimation_->start();
69 void PuzzleItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
72 moveMeTo(GameView::instance()->emptyPlace());
73 QPointF tmp = currentPlace();
74 setCurrentPlace(GameView::instance()->emptyPlace());
75 GameView::instance()->setEmptyPlace(tmp);
78 // If piece is in its place check if we won the game
79 if(currentPlace() == correctPlace()) {
80 GameView::instance()->areAllPiecesOk();
88 void PuzzleItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)