[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:07
Message-ID: 20100903213907.6AB37AC88F () svn ! kde ! org
[Download RAW message or body]

SVN commit 1171453 by coates:

Switch KCard back to a QGraphicsPixmapItem subclass.

This seems to sort out some (but not all) of the graphical glitches
that we've been seeing lately. More changes are likely to come here.

 M  +32 -49    kabstractcarddeck.cpp  
 M  +2 -3      kabstractcarddeck.h  
 M  +19 -10    kcard.cpp  
 M  +4 -3      kcard.h  


--- trunk/KDE/kdegames/kpat/libkcardgame/kabstractcarddeck.cpp #1171452:1171453
@@ -229,41 +229,6 @@
 }
 
 
-void KAbstractCardDeckPrivate::updateCardSize( const QSize & size )
-{
-    currentCardSize = size;
-
-    if ( !theme.isValid() )
-        return;
-
-    QByteArray buffer;
-    QDataStream stream( &buffer, QIODevice::WriteOnly );
-    stream << currentCardSize;
-    cache->insert( lastUsedSizeKey, buffer );
-
-    foreach ( KCard * c, cards )
-        c->update();
-
-    deleteThread();
-
-    // We have to compile the list of elements to load here, because we can't
-    // check the contents of the KPixmapCache from outside the GUI thread.
-    QPixmap pix;
-    QStringList unrenderedElements;
-    QHash<QString,CardElementData>::const_iterator it = \
                elementIdMapping.constBegin();
-    QHash<QString,CardElementData>::const_iterator end = \
                elementIdMapping.constEnd();
-    for ( ; it != end; ++it )
-    {
-        QString key = keyForPixmap( it.key(), currentCardSize );
-        if ( !cache->findPixmap( key, &pix ) )
-            unrenderedElements << it.key();
-    }
-
-    thread = new RenderingThread( this, currentCardSize, unrenderedElements );
-    thread->start();
-}
-
-
 void KAbstractCardDeckPrivate::deleteThread()
 {
     if ( thread && thread->isRunning() )
@@ -279,7 +244,8 @@
     cache->findPixmap( keyForPixmap( elementId, currentCardSize ), \
&(usage.cardPixmap) );  
     foreach ( KCard * c, usage.cardUsers )
-        c->update();
+        if ( elementId == q->elementName( c->id(), c->isFaceUp() ) )
+            c->setPixmap( usage.cardPixmap );
 }
 
 
@@ -405,12 +371,38 @@
 
     if ( newSize != d->currentCardSize )
     {
+        d->currentCardSize = newSize;
+
+        if ( !d->theme.isValid() )
+            return;
+
+        QByteArray buffer;
+        QDataStream stream( &buffer, QIODevice::WriteOnly );
+        stream << d->currentCardSize;
+        d->cache->insert( lastUsedSizeKey, buffer );
+
         foreach ( KCard * c, d->cards )
-            c->prepareGeometryChange();
+            c->setPixmap( cardPixmap( c ) );
 
-        d->updateCardSize( newSize );
+        d->deleteThread();
+
+        // We have to compile the list of elements to load here, because we can't
+        // check the contents of the KPixmapCache from outside the GUI thread.
+        QPixmap pix;
+        QStringList unrenderedElements;
+        QHash<QString,CardElementData>::const_iterator it = \
d->elementIdMapping.constBegin(); +        \
QHash<QString,CardElementData>::const_iterator end = d->elementIdMapping.constEnd(); \
+        for ( ; it != end; ++it ) +        {
+            QString key = keyForPixmap( it.key(), d->currentCardSize );
+            if ( !d->cache->findPixmap( key, &pix ) )
+                unrenderedElements << it.key();
     }
+
+        d->thread = new RenderingThread( d, d->currentCardSize, unrenderedElements \
); +        d->thread->start();
 }
+}
 
 
 int KAbstractCardDeck::cardWidth() const
@@ -504,20 +496,11 @@
 }
 
 
-void KAbstractCardDeck::paintCard( QPainter * painter, quint32 id, bool faceUp, \
qreal highlightedness ) +QPixmap KAbstractCardDeck::cardPixmap( KCard * card )
 {
-    QPixmap pix = d->requestPixmap( elementName( id, faceUp ) );
-
-    if ( highlightedness > 0 )
-    {
-        QPainter p( &pix );
-        p.setCompositionMode( QPainter::CompositionMode_SourceAtop );
-        p.fillRect( 0, 0, pix.width(), pix.height(), QColor::fromRgbF( 0, 0, 0, 0.5 \
* highlightedness ) ); +    return d->requestPixmap( elementName( card->id(), \
card->isFaceUp() ) );  }
 
-    painter->drawPixmap( 0, 0, pix );
-}
 
-
 #include "kabstractcarddeck.moc"
 #include "kabstractcarddeck_p.moc"
--- trunk/KDE/kdegames/kpat/libkcardgame/kabstractcarddeck.h #1171452:1171453
@@ -55,6 +55,8 @@
 
     bool hasAnimatedCards() const;
 
+    QPixmap cardPixmap( KCard * card );
+
 Q_SIGNALS:
     void cardAnimationDone();
 
@@ -62,9 +64,6 @@
     virtual QString elementName( quint32 id, bool faceUp = true ) const = 0;
 
 private:
-    virtual void paintCard( QPainter * painter, quint32 id, bool faceUp, qreal \
                highlightedness );
-
-private:
     class KAbstractCardDeckPrivate * const d;
 
     friend class KCard;
--- trunk/KDE/kdegames/kpat/libkcardgame/kcard.cpp #1171452:1171453
@@ -90,6 +90,12 @@
     if ( flippedness == flipValue )
         return;
 
+    if ( (flipValue < 0.5 && flippedness >= 0.5)
+         || (flipValue >= 0.5 && flippedness < 0.5) )
+    {
+        q->setPixmap( deck->cardPixmap( q ) );
+    }
+
     flipValue = flippedness;
 
     qreal xOffset = deck->cardWidth() * ( 0.5 - qAbs( flippedness - 0.5 ) );
@@ -119,7 +125,8 @@
 
 
 KCard::KCard( quint32 id, KAbstractCardDeck * deck )
-  : QGraphicsObject(),
+  : QObject(),
+    QGraphicsPixmapItem(),
     d( new KCardPrivate( this ) )
 {
     d->id = id;
@@ -157,12 +164,6 @@
 }
 
 
-QRectF KCard::boundingRect() const
-{
-    return QRectF( QPointF( 0, 0 ), d->deck->cardSize() );
-}
-
-
 quint32 KCard::id() const
 {
     return d->id;
@@ -205,8 +206,7 @@
     if ( d->faceUp != faceUp || d->flipValue != flippedness )
     {
         d->faceUp = faceUp;
-        d->flipValue = flippedness;
-        update();
+        d->setFlippedness( flippedness );
     }
 }
 
@@ -319,9 +319,18 @@
     // don't really need it otherwise and it slows down our flip animations.
     painter->setRenderHint( QPainter::SmoothPixmapTransform, int(rotation()) % 90 );
 
-    d->deck->paintCard( painter, d->id, d->flipValue > 0.5, d->highlightValue );
+    QPixmap pix = pixmap();
+
+    if ( d->highlightValue > 0 )
+    {
+        QPainter p( &pix );
+        p.setCompositionMode( QPainter::CompositionMode_SourceAtop );
+        p.fillRect( 0, 0, pix.width(), pix.height(), QColor::fromRgbF( 0, 0, 0, 0.5 \
* d->highlightValue ) );  }
 
+    painter->drawPixmap( 0, 0, pix );
+}
 
+
 #include "kcard_p.moc"
 #include "kcard.moc"
--- trunk/KDE/kdegames/kpat/libkcardgame/kcard.h #1171452:1171453
@@ -23,9 +23,11 @@
 class KCardPile;
 #include "libkcardgame_export.h"
 
-#include <QtGui/QGraphicsObject>
+#include <QtCore/QObject>
+#include <QtGui/QGraphicsPixmapItem>
 
-class LIBKCARDGAME_EXPORT KCard : public QGraphicsObject
+
+class LIBKCARDGAME_EXPORT KCard : public QObject, public QGraphicsPixmapItem
 {
     Q_OBJECT
 
@@ -37,7 +39,6 @@
     enum { Type = QGraphicsItem::UserType + 1 };
     virtual int type() const;
 
-    virtual QRectF boundingRect() const;
     virtual void paint( QPainter * painter, const QStyleOptionGraphicsItem * option, \
QWidget * widget = 0 );  
     quint32 id() const;


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

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