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

List:       kde-commits
Subject:    KDE/kdegames/kpat/libkcardgame
From:       Parker Coates <parker.coates () kdemail ! net>
Date:       2010-09-03 21:39:16
Message-ID: 20100903213916.3E79CAC899 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1171457 by coates:

Store both front and back pixmaps inside KCard.

By having both cached inside the card itself, it eliminates a fair bit
of communication between the KCard and KAbstractCardDeck. It also avoids
potential "hiccups" during card flip animations.

 M  +6 -11     kabstractcarddeck.cpp  
 M  +0 -2      kabstractcarddeck.h  
 M  +27 -5     kcard.cpp  
 M  +5 -0      kcard.h  
 M  +3 -0      kcard_p.h  


--- trunk/KDE/kdegames/kpat/libkcardgame/kabstractcarddeck.cpp #1171456:1171457
@@ -259,8 +259,7 @@
         {
             it.value().cardPixmap = pix;
             foreach ( KCard * c, it.value().cardUsers )
-                if ( c->isFaceUp() )
-                    c->setPixmap( pix );
+                c->setFrontPixmap( pix );
         }
 
         it = backIndex.find( elementId );
@@ -268,8 +267,7 @@
         {
             it.value().cardPixmap = pix;
             foreach ( KCard * c, it.value().cardUsers )
-                if ( !c->isFaceUp() )
-                    c->setPixmap( pix );
+                c->setBackPixmap( pix );
         }
     }
 }
@@ -419,7 +417,10 @@
         d->cache->insert( lastUsedSizeKey, buffer );
 
         foreach ( KCard * c, d->cards )
-            c->setPixmap( cardPixmap( c ) );
+        {
+            c->setFrontPixmap( d->requestPixmap( c->id(), true ) );
+            c->setBackPixmap( d->requestPixmap( c->id(), false ) );
+        }
 
         d->deleteThread();
 
@@ -522,11 +523,5 @@
 }
 
 
-QPixmap KAbstractCardDeck::cardPixmap( KCard * card )
-{
-    return d->requestPixmap( card->id(), card->isFaceUp() );
-}
-
-
 #include "kabstractcarddeck.moc"
 #include "kabstractcarddeck_p.moc"
--- trunk/KDE/kdegames/kpat/libkcardgame/kabstractcarddeck.h #1171456:1171457
@@ -55,8 +55,6 @@
 
     bool hasAnimatedCards() const;
 
-    QPixmap cardPixmap( KCard * card );
-
 Q_SIGNALS:
     void cardAnimationDone();
 
--- trunk/KDE/kdegames/kpat/libkcardgame/kcard.cpp #1171456:1171457
@@ -90,11 +90,10 @@
     if ( flippedness == flipValue )
         return;
 
-    if ( (flipValue < 0.5 && flippedness >= 0.5)
-         || (flipValue >= 0.5 && flippedness < 0.5) )
-    {
-        q->setPixmap( deck->cardPixmap( q ) );
-    }
+    if ( flipValue < 0.5 && flippedness >= 0.5 )
+        q->setPixmap( frontPixmap );
+    else if ( flipValue >= 0.5 && flippedness < 0.5 )
+        q->setPixmap( backPixmap );
 
     flipValue = flippedness;
 
@@ -332,5 +331,28 @@
 }
 
 
+void KCard::setFrontPixmap( const QPixmap & pix )
+{
+    d->frontPixmap = pix;
+    if ( d->flipValue >= 0.5 )
+        setPixmap( d->frontPixmap );
+}
+
+
+void KCard::setBackPixmap( const QPixmap & pix )
+{
+    d->backPixmap = pix;
+    if ( d->flipValue < 0.5 )
+        setPixmap( d->backPixmap );
+}
+
+
+void KCard::setPixmap( const QPixmap & pix )
+{
+    QGraphicsPixmapItem::setPixmap( pix );
+}
+
+
+
 #include "kcard_p.moc"
 #include "kcard.moc"
--- trunk/KDE/kdegames/kpat/libkcardgame/kcard.h #1171456:1171457
@@ -60,6 +60,9 @@
     void setHighlighted( bool highlighted );
     bool isHighlighted() const;
 
+    void setFrontPixmap( const QPixmap & pix );
+    void setBackPixmap( const QPixmap & pix );
+
 Q_SIGNALS:
     void animationStarted( KCard * card );
     void animationStopped( KCard * card );
@@ -69,6 +72,8 @@
     void stopAnimation();
 
 private:
+    void setPixmap( const QPixmap & pix );
+
     class KCardPrivate * const d;
 
     friend class KCardPrivate;
--- trunk/KDE/kdegames/kpat/libkcardgame/kcard_p.h #1171456:1171457
@@ -81,6 +81,9 @@
     KAbstractCardDeck * deck;
     KCardPile * pile;
 
+    QPixmap frontPixmap;
+    QPixmap backPixmap;
+
     KCardAnimation * animation;
     QPropertyAnimation * fadeAnimation;
 };
[prev in list] [next in list] [prev in thread] [next in thread] 

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