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 int PuzzleItem::moveCount_ = 0;
27 PuzzleItem::PuzzleItem(QGraphicsItem *parent) :
28 QGraphicsPixmapItem(parent)
31 moveAnimation_ = new QPropertyAnimation(this, "pos", this);
34 QPointF PuzzleItem::correctPlace() const
39 QPointF PuzzleItem::currentPlace() const
44 void PuzzleItem::setCorrectPlace(const QPointF &place)
46 correctPlace_ = place;
49 void PuzzleItem::setCurrentPlace(const QPointF &place)
51 currentPlace_ = place;
54 bool PuzzleItem::movable() const
59 void PuzzleItem::setMovable(bool canMove)
64 void PuzzleItem::moveMeTo(const QPointF &location)
66 moveAnimation_->setStartValue(currentPlace());
67 moveAnimation_->setEndValue(location);
68 moveAnimation_->start();
71 void PuzzleItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
74 moveMeTo(GameView::instance()->emptyPlace());
75 QPointF tmp = currentPlace();
76 setCurrentPlace(GameView::instance()->emptyPlace());
77 GameView::instance()->setEmptyPlace(tmp);
82 // If piece is in its place check if we won the game
84 if(currentPlace() == correctPlace()) {
85 won = GameView::instance()->areAllPiecesOk();
88 // if we didn't win set pieces that can be moved
90 GameView::instance()->setMovingPieces();
98 void PuzzleItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
103 int PuzzleItem::moveCount()
108 void PuzzleItem::resetMoveCount()