[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    extragear/plasma/applets/fifteenPuzzle/src
From:       Aaron J. Seigo <aseigo () kde ! org>
Date:       2008-01-22 23:37:20
Message-ID: 1201045040.206173.31847.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 765003 by aseigo:

* replace the finish-randomly-and-potentially-never algorithm with a guaranteed \
                terminating one
* use Phase.


 M  +20 -17    fifteen.cpp  


--- trunk/extragear/plasma/applets/fifteenPuzzle/src/fifteen.cpp #765002:765003
@@ -24,9 +24,11 @@
 #include <QGraphicsScene>
 #include <QDebug>
 #include <QGraphicsSceneMouseEvent>
-#include <QGraphicsItemAnimation>
-#include <QTimeLine>
 
+#include <KDebug>
+
+#include "plasma/phase.h"
+
 #define SIZE 48
 
 Fifteen::Fifteen(QGraphicsItem *parent)
@@ -52,13 +54,25 @@
   qsrand(time(0));
   clearPieces();
   m_pieces.fill(NULL);
+  int numPiecesLeft = 16;
   for (int i = 0; i < 16; ++i) {
-    int rand = qrand() % 16;
+    int randIndex = qrand() % numPiecesLeft;
+    int rand = 0;
+    --numPiecesLeft;
 
-    while (m_pieces.at(rand) != NULL) {
-      rand = qrand() % 16;
+    // make sure we have an empty piece
+    if (randIndex == 0 && m_pieces.at(0)) {
+        ++randIndex;
     }
 
+    for (int j = 0; j < randIndex; ++j) {
+        ++rand;
+        while (m_pieces.at(rand)) {
+            ++rand;
+        }
+    }
+    kDebug() << "rand" << randIndex << rand;
+
     m_pieces[rand] = new Piece(SIZE, i, this);
     m_pieces[rand]->hide();
     QObject::connect(m_pieces[rand], SIGNAL(pressed(QGraphicsItem*)), this, \
SLOT(piecePressed(QGraphicsItem*))); @@ -177,18 +191,7 @@
 {
   if (isAdjacent(item, m_blank)) {
     QPointF pos = item->pos();
-
-    QTimeLine *timer = new QTimeLine(170);
-
-    QGraphicsItemAnimation *animation = new QGraphicsItemAnimation;
-    animation->setItem(item);
-    animation->setTimeLine(timer);
-
-    animation->setPosAt(0.0, item->pos());
-    animation->setPosAt(1.00, m_blank->pos());
-
-    timer->start();
-
+    Plasma::Phase::self()->moveItem(item, Plasma::Phase::FastSlideIn, \
m_blank->pos().toPoint());  m_blank->setPos(pos);
   }
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic