Preventing too early interaction with puzzle pieces
authortimoph <timop.harkonen@gmail.com>
Wed, 26 May 2010 19:06:38 +0000 (19:06 +0000)
committertimoph <timop.harkonen@gmail.com>
Wed, 26 May 2010 19:06:38 +0000 (19:06 +0000)
git-svn-id: file:///svnroot/impuzzle/trunk@23 e6bec12f-0854-4cc4-ad26-6875f1509f77

debian/changelog
debian/control
src/gameview.cpp
src/gameview.h
src/impuzzle.desktop
src/puzzleitem.cpp
src/puzzleitem.h
src/settingsdialog.cpp

index 6ca051a..8758931 100644 (file)
@@ -1,3 +1,16 @@
+impuzzle (0.6.1-1maemo0) unstable; urgency=low
+
+  * Fixes: Preventing user interaction with image pieces during game setup that would lead to segfault.
+  * Taking garage bug tracker into use instead of email address
+
+ -- Timo Härkönen <timop.harkonen@gmail.com>  Wed, 26 May 2010 21:46:00 +0200
+
+impuzzle (0.6-1maemo1) unstable; urgency=low
+
+  * Just building against the new SDK in autobuilder
+
+ -- Timo Härkönen <timop.harkonen@gmail.com>  Tue, 25 May 2010 17:18:00 +0200
+
 impuzzle (0.6-1maemo0) unstable; urgency=low
 
   * Fixes: Move counter not resetted when starting new game
index e367520..1867174 100644 (file)
@@ -4,7 +4,7 @@ Priority: optional
 Maintainer: Timo Härkönen <timop.harkonen@gmail.com>
 Build-Depends: debhelper (>= 5), libqt4-dev (>= 4.6.0)
 Standards-Version: 3.7.2
-XSBC-Bugtracker: mailto:timop.harkonen@gmail.com
+XSBC-Bugtracker: https://garage.maemo.org/tracker/?group_id=1167
 
 Package: impuzzle
 Architecture: any
@@ -12,6 +12,8 @@ Depends: libqt4-core (>= 4.6.0), libqt4-gui (>= 4.6.0), libqt4-maemo5 (>= 4.6.0)
 Description: Image puzzle game
  impuzzle is a picture puzzle game that let's you
  use your own pictures as the game board.
+ Limitations in current version:
+ For random images only images in /home/user/MyDocs/.images is used
 XB-Maemo-Icon-26:
  iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c
  6QAAAAZiS0dEALAAMQAxnfM89gAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0
index cf19475..ad51a83 100644 (file)
@@ -96,6 +96,8 @@ QList<PuzzleItem *> GameView::pieces() const
 
 void GameView::setPieces(const QList<PuzzleItem *> pieces, bool shuffle)
 {
+    PuzzleItem::setManuallyMovable(false);
+
     if(pieces.isEmpty()) {
         qDebug() << "Empty list @ GameView::setPieces";
         return;
@@ -148,6 +150,9 @@ void GameView::setPieces(const QList<PuzzleItem *> pieces, bool shuffle)
     if(shuffle) {
         QTimer::singleShot(750, this, SLOT(shufflePieces()));
     }
+    else {
+        PuzzleItem::setManuallyMovable(true);
+    }
 }
 
 //TODO: fixme!
@@ -178,20 +183,23 @@ void GameView::shufflePieces()
         case 0:
             if(pieces_.at(hiddenIndex_)->currentPlace().y() > topLeft.y()) {
                 QPointF tmp = pieces_.at(hiddenIndex_)->currentPlace();
-                item = dynamic_cast<PuzzleItem *>(scene()->itemAt(tmp + QPointF(0, -verticalStep_)));
-                if(item->movable()) {
-                    emptyPlace_ = item->currentPlace();
-                    pieces_.at(hiddenIndex_)->setCurrentPlace(item->currentPlace());
-                    pieces_.at(hiddenIndex_)->setPos(item->currentPlace());
-                    item->setCurrentPlace(tmp);
-                    item->setPos(tmp);
-                    invalidateScene();
-                    scene()->update();
-                    setMovingPieces();
-                    movesMade++;
-                }
-                else {
-                    qDebug() << "Item right of hidden piece not movable";
+                QGraphicsItem *graphicsItem = scene()->itemAt(tmp + QPointF(0, -verticalStep_));
+                if(graphicsItem) {
+                    item = dynamic_cast<PuzzleItem *>(graphicsItem);
+                    if(item->movable()) {
+                        emptyPlace_ = item->currentPlace();
+                        pieces_.at(hiddenIndex_)->setCurrentPlace(item->currentPlace());
+                        pieces_.at(hiddenIndex_)->setPos(item->currentPlace());
+                        item->setCurrentPlace(tmp);
+                        item->setPos(tmp);
+                        invalidateScene();
+                        scene()->update();
+                        setMovingPieces();
+                        movesMade++;
+                    }
+                    else {
+                        qDebug() << "Item right of hidden piece not movable";
+                    }
                 }
             }
             else {
@@ -202,18 +210,21 @@ void GameView::shufflePieces()
         case 1:
             if(pieces_.at(hiddenIndex_)->currentPlace().y() < bottomRight.y()) {
                 QPointF tmp = pieces_.at(hiddenIndex_)->currentPlace();
-                item = dynamic_cast<PuzzleItem *>(scene()->itemAt(tmp + QPointF(0, verticalStep_)));
-                if(item->movable()) {
-                emptyPlace_ = item->currentPlace();
-                    pieces_.at(hiddenIndex_)->setCurrentPlace(item->currentPlace());
-                    pieces_.at(hiddenIndex_)->setPos(item->currentPlace());
-                    item->setCurrentPlace(tmp);
-                    item->setPos(tmp);
-                    setMovingPieces();
-                    movesMade++;
-                }
-                else {
-                    qDebug() << "Item down of hidden piece not movable";
+                QGraphicsItem *graphicsItem = scene()->itemAt(tmp + QPointF(0, verticalStep_));
+                if(graphicsItem) {
+                    item = dynamic_cast<PuzzleItem *>(graphicsItem);
+                    if(item->movable()) {
+                    emptyPlace_ = item->currentPlace();
+                        pieces_.at(hiddenIndex_)->setCurrentPlace(item->currentPlace());
+                        pieces_.at(hiddenIndex_)->setPos(item->currentPlace());
+                        item->setCurrentPlace(tmp);
+                        item->setPos(tmp);
+                        setMovingPieces();
+                        movesMade++;
+                    }
+                    else {
+                        qDebug() << "Item down of hidden piece not movable";
+                    }
                 }
             }
             else {
@@ -224,18 +235,21 @@ void GameView::shufflePieces()
         case 2:
             if(pieces_.at(hiddenIndex_)->currentPlace().x() > topLeft.x()) {
                 QPointF tmp = pieces_.at(hiddenIndex_)->currentPlace();
-                item = dynamic_cast<PuzzleItem *>(scene()->itemAt(tmp + QPointF(-horizontalStep_, 0)));
-                if(item->movable()) {
-                    emptyPlace_ = item->currentPlace();
-                    pieces_.at(hiddenIndex_)->setCurrentPlace(item->currentPlace());
-                    pieces_.at(hiddenIndex_)->setPos(item->currentPlace());
-                    item->setCurrentPlace(tmp);
-                    item->setPos(tmp);
-                    setMovingPieces();
-                    movesMade++;
-                }
-                else {
-                    qDebug() << "Item left of hidden piece not movable";
+                QGraphicsItem *graphicsItem = scene()->itemAt(tmp + QPointF(-horizontalStep_, 0));
+                if(graphicsItem) {
+                    item = dynamic_cast<PuzzleItem *>(graphicsItem);
+                    if(item->movable()) {
+                        emptyPlace_ = item->currentPlace();
+                        pieces_.at(hiddenIndex_)->setCurrentPlace(item->currentPlace());
+                        pieces_.at(hiddenIndex_)->setPos(item->currentPlace());
+                        item->setCurrentPlace(tmp);
+                        item->setPos(tmp);
+                        setMovingPieces();
+                        movesMade++;
+                    }
+                    else {
+                        qDebug() << "Item left of hidden piece not movable";
+                    }
                 }
             }
             else {
@@ -246,18 +260,21 @@ void GameView::shufflePieces()
         case 3:
             if(pieces_.at(hiddenIndex_)->currentPlace().x() < bottomRight.x()) {
                 QPointF tmp = pieces_.at(hiddenIndex_)->currentPlace();
-                item = dynamic_cast<PuzzleItem *>(scene()->itemAt(tmp + QPointF(horizontalStep_, 0)));
-                if(item->movable()) {
-                    emptyPlace_ = item->currentPlace();
-                    pieces_.at(hiddenIndex_)->setCurrentPlace(item->currentPlace());
-                    pieces_.at(hiddenIndex_)->setPos(item->currentPlace());
-                    item->setCurrentPlace(tmp);
-                    item->setPos(tmp);
-                    setMovingPieces();
-                    movesMade++;
-                }
-                else {
-                    qDebug() << "Item up of hidden piece not movable";
+                QGraphicsItem *graphicsItem = scene()->itemAt(tmp + QPointF(horizontalStep_, 0));
+                if(graphicsItem) {
+                    item = dynamic_cast<PuzzleItem *>(graphicsItem);
+                    if(item->movable()) {
+                        emptyPlace_ = item->currentPlace();
+                        pieces_.at(hiddenIndex_)->setCurrentPlace(item->currentPlace());
+                        pieces_.at(hiddenIndex_)->setPos(item->currentPlace());
+                        item->setCurrentPlace(tmp);
+                        item->setPos(tmp);
+                        setMovingPieces();
+                        movesMade++;
+                    }
+                    else {
+                        qDebug() << "Item up of hidden piece not movable";
+                    }
                 }
             }
             else {
@@ -273,6 +290,7 @@ void GameView::shufflePieces()
     qDebug() << QString("Shuffle moves: %1/%2").arg(movesMade).arg(moveCount);
 
     QParallelAnimationGroup *animationGroup = new QParallelAnimationGroup(this);
+    connect(animationGroup, SIGNAL(finished()), this, SLOT(shuffleAnimationFinished()));
     for(int i = 0; i < pieces_.count(); ++i) {
         QPropertyAnimation *animation = new QPropertyAnimation(pieces_.at(i), "pos");
         animation->setStartValue(pieces_.at(i)->correctPlace());
@@ -282,11 +300,13 @@ void GameView::shufflePieces()
         animationGroup->addAnimation(animation);
     }
     animationGroup->start();
-
-    // Hide
     pieces_.at(hiddenIndex_)->hide();
+}
 
+void GameView::shuffleAnimationFinished()
+{
     setMovingPieces();
+    PuzzleItem::setManuallyMovable(true);
 }
 
 QPointF GameView::emptyPlace()
index 7e3e6f1..4e8d6d0 100644 (file)
@@ -43,6 +43,9 @@ public slots:
     bool restoreGame();
     void saveGame();
 
+private slots:
+    void shuffleAnimationFinished();
+
 signals:
     void gameWon();
     void gameRestored();
index 2058ea0..8df615a 100644 (file)
@@ -1,8 +1,9 @@
 [Desktop Entry]
 Encoding=UTF-8
-Version=0.1
+Version=0.6.1
 Type=Application
-Name=ImPuzzle
+Name=impuzzle
 Icon=impuzzle
 Exec=/opt/impuzzle/impuzzle
 X-Osso-Type=application/x-executable
+Maemo-Display-Name=impuzzle
index 93e5675..fd5ff88 100644 (file)
@@ -26,6 +26,7 @@
 #include <QFontMetrics>
 
 int PuzzleItem::moveCount_ = 0;
+bool PuzzleItem::manuallyMovable_ = false;
 
 PuzzleItem::PuzzleItem(QGraphicsItem *parent) :
         QGraphicsPixmapItem(parent)
@@ -75,7 +76,7 @@ void PuzzleItem::moveMeTo(const QPointF &location)
 
 void PuzzleItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
 {
-    if(movable_) {
+    if(movable_ && manuallyMovable_) {
         moveMeTo(GameView::instance()->emptyPlace());
         QPointF tmp = currentPlace();
         setCurrentPlace(GameView::instance()->emptyPlace());
@@ -115,6 +116,11 @@ void PuzzleItem::resetMoveCount()
     moveCount_ = 0;
 }
 
+void PuzzleItem::setManuallyMovable(const bool manuallyMovable)
+{
+    manuallyMovable_ = manuallyMovable;
+}
+
 void PuzzleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
 {
     QGraphicsPixmapItem::paint(painter, option, widget);
index b1abf8b..a6830fa 100644 (file)
@@ -41,6 +41,7 @@ public:
     static int moveCount();
     static void setMoveCount(const int count);
     static void resetMoveCount();
+    static void setManuallyMovable(const bool manuallyMovable);
     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
     void setPieceNumber(const int pieceNumber);
     int pieceNumber() const;
@@ -57,6 +58,7 @@ private:
     bool movable_;
     QPropertyAnimation *moveAnimation_;
     static int moveCount_;
+    static bool manuallyMovable_;
     int pieceNumber_;
     bool drawNumber_;
 };
index 58d4ca0..0c0b4f1 100644 (file)
@@ -97,6 +97,7 @@ void SettingsDialog::imageSelectionChanged(const QString &txt)
         qDebug() << "Random image selected";
 
         // Get random image from ~/MyDocs/.images/
+        //TODO: images from other directories
         QStringList filters;
         filters << "*.jpg" << "*.png" << "*.xpm";
 
@@ -133,7 +134,7 @@ void SettingsDialog::imageSelectionChanged(const QString &txt)
         }
     }
     else {
-        qDebug() << "Default image selected";
+        //qDebug() << "Default image selected";
 
         Settings::instance()->setImage(0);
         Settings::instance()->setImagePath("default");