KCardCache Class Reference

This class implements a kdegames wide cache for cards. More...

#include <cardcache.h>

Collaboration diagram for KCardCache:

Collaboration graph
[legend]

List of all members.

Public Types

enum  LoadInfo {
  LoadFrontSide = 1 << 0, LoadBackSide = 1 << 2, Load52Cards = 1 << 3, Load32Cards = 1 << 4,
  Load53Cards = 1 << 5
}
 Can be used to load only parts of a theme, in case the user chose to have front and backside from different themes. More...

Public Member Functions

 KCardCache ()
 Constructor creates and initializes a KPixmapCache for all KDE Games card games.
 ~KCardCache ()
 Cleans up the cache.
void setSize (const QSize &size)
 Set the size of rendered pixmaps.
QSize size () const
 Returns the currently used size to render cards and backsides.
void setFrontTheme (const QString &theme)
 Set the theme to be used to render the frontside of cards.
QString frontTheme () const
 Return the currently used frontside theme.
void setBackTheme (const QString &theme)
 Set the theme to be used to render the backside of cards.
QString backTheme () const
 Return the currently used backside theme.
QPixmap backside (int variant=-1) const
 Retrieve the backside of the given theme theme at the specified size size.
QSizeF defaultBackSize (int variant=-1) const
 Retrieve the default size for the backside card.
void invalidateBackside ()
 Invalidates all cached images in the current size for the current backside theme.
QPixmap frontside (const KCardInfo &info) const
 Retrieve the frontside pixmap.
QSizeF defaultFrontSize (const KCardInfo &info) const
 Retrieve the default size for the frontside card.
void invalidateFrontside ()
 Invalidates all cached images in the current size for the current frontside theme.
void loadTheme (LoadInfos infos=LoadInfos(LoadFrontSide|LoadBackSide|Load53Cards))
 Loads a whole theme in the background.


Detailed Description

This class implements a kdegames wide cache for cards.

Card games such as lskat or kpat should use this cache to load the various decks into QPixmaps instead of inventing their own. It uses KPixmapCache behind the scenes, set up to use disk and memory caching. Thus a SVG card deck that was loaded by kpat for the size 100x200 doesn't need re-rendering when requested from lskat.

Usage is quite simple. During initialization of the game the cache object should be created and it should be told to load the currently selected theme. myCache = new KCardCache(); myCache->loadTheme( myTheme );

Later when actually drawing the cards the getter methods can be used to get the pixmap of a specific card at a specific size from a given theme. myCache->getCard( myTheme, KCardCache::Club, KCardCache::Ace, calculatedSize );

Definition at line 79 of file cardcache.h.


Member Enumeration Documentation

enum KCardCache::LoadInfo

Can be used to load only parts of a theme, in case the user chose to have front and backside from different themes.

Enumerator:
LoadFrontSide 
LoadBackSide 
Load52Cards 
Load32Cards 
Load53Cards 

Definition at line 88 of file cardcache.h.


Constructor & Destructor Documentation

KCardCache::KCardCache (  ) 

Constructor creates and initializes a KPixmapCache for all KDE Games card games.

Definition at line 379 of file cardcache.cpp.

References KCardCachePrivate::backcache, KCardCachePrivate::backcacheMutex, KCardCachePrivate::backRenderer, KCardCachePrivate::backRendererMutex, KCardCachePrivate::frontcache, KCardCachePrivate::frontcacheMutex, KCardCachePrivate::frontRenderer, KCardCachePrivate::frontRendererMutex, and KCardCachePrivate::loadThread.

KCardCache::~KCardCache (  ) 

Cleans up the cache.

Definition at line 394 of file cardcache.cpp.

References KCardCachePrivate::backcache, KCardCachePrivate::backcacheMutex, KCardCachePrivate::backRenderer, KCardCachePrivate::backRendererMutex, KCardCachePrivate::frontcache, KCardCachePrivate::frontcacheMutex, KCardCachePrivate::frontRenderer, KCardCachePrivate::frontRendererMutex, LoadThread::kill(), and KCardCachePrivate::loadThread.

Here is the call graph for this function:


Member Function Documentation

void KCardCache::setSize ( const QSize &  size  ) 

Set the size of rendered pixmaps.

Make sure to set a reasonable size, before fetching pixmaps from the cache.

Parameters:
size the new size for rendering cards and backsides

Definition at line 491 of file cardcache.cpp.

References KCardCachePrivate::size.

QSize KCardCache::size (  )  const

Returns the currently used size to render cards and backsides.

Returns:
the size of pixmaps for rendering.

Definition at line 497 of file cardcache.cpp.

References KCardCachePrivate::size.

Referenced by defaultBackSize(), and defaultFrontSize().

void KCardCache::setFrontTheme ( const QString &  theme  ) 

Set the theme to be used to render the frontside of cards.

Make sure to set a proper theme before fetching frontside pixmaps from the cache.

Parameters:
theme the name of the theme to be use for rendering frontsides

Definition at line 502 of file cardcache.cpp.

References KCardCachePrivate::frontcache, KCardCachePrivate::frontcacheMutex, CardDeckInfo::frontDir(), KCardCachePrivate::frontRenderer, KCardCachePrivate::frontRendererMutex, CardDeckInfo::frontSVGFilePath(), KCardCachePrivate::frontTheme, and CardDeckInfo::isSVGFront().

Here is the call graph for this function:

QString KCardCache::frontTheme (  )  const

Return the currently used frontside theme.

Returns:
the name of the frontside theme

Definition at line 539 of file cardcache.cpp.

References KCardCachePrivate::frontTheme.

void KCardCache::setBackTheme ( const QString &  theme  ) 

Set the theme to be used to render the backside of cards.

Make sure to set a proper theme before fetching frontside pixmaps from the cache.

Parameters:
theme the name of the theme to be use for rendering backsides

Definition at line 544 of file cardcache.cpp.

References KCardCachePrivate::backcache, KCardCachePrivate::backcacheMutex, CardDeckInfo::backFilename(), KCardCachePrivate::backRenderer, KCardCachePrivate::backRendererMutex, CardDeckInfo::backSVGFilePath(), KCardCachePrivate::backTheme, and CardDeckInfo::isSVGBack().

Here is the call graph for this function:

QString KCardCache::backTheme (  )  const

Return the currently used backside theme.

Returns:
the name of the backside theme

Definition at line 574 of file cardcache.cpp.

References KCardCachePrivate::backTheme.

QPixmap KCardCache::backside ( int  variant = -1  )  const

Retrieve the backside of the given theme theme at the specified size size.

Make sure to set a reasonable size and theme, before calling this function.

Parameters:
variant which variant, like a back with another color, to use for rendering. Defaults to -1 which means no variant.
Returns:
a QPixmap with the card backside rendered
See also:
setBackTheme

setSize

Definition at line 413 of file cardcache.cpp.

References KCardCachePrivate::backcache, KCardCachePrivate::backcacheMutex, CardDeckInfo::backFilename(), KCardCachePrivate::backTheme, KCardCachePrivate::ensureNonNullPixmap(), CardDeckInfo::isSVGBack(), keyForPixmap(), KCardCachePrivate::renderBackSvg(), and KCardCachePrivate::size.

Here is the call graph for this function:

QSizeF KCardCache::defaultBackSize ( int  variant = -1  )  const

Retrieve the default size for the backside card.

Make sure to set a reasonable theme, before calling this function.

Parameters:
variant which variant, like a back with another color, to use. Defaults to -1 which means no variant.
Returns:
the default size of the selected background variant

Definition at line 613 of file cardcache.cpp.

References CardDeckInfo::backFilename(), KCardCachePrivate::backRenderer, KCardCachePrivate::backRendererMutex, KCardCachePrivate::backTheme, CardDeckInfo::isSVGBack(), and size().

Here is the call graph for this function:

void KCardCache::invalidateBackside (  ) 

Invalidates all cached images in the current size for the current backside theme.

Definition at line 646 of file cardcache.cpp.

References KCardCachePrivate::backcache, and KCardCachePrivate::backcacheMutex.

QPixmap KCardCache::frontside ( const KCardInfo info  )  const

Retrieve the frontside pixmap.

The infos paramter is used to determine which frontside to load. Make sure to set a reasonable size and theme, before calling this function.

Parameters:
infos A combination of CardInfo flags to identify what type of card to load. There are of course only certain combinations that make sense, like King | Heart, some flags are used standalone, like Joker.
Returns:
a QPixmap with the card frontside rendered
See also:
setBackTheme

setSize

CardInfo

Definition at line 453 of file cardcache.cpp.

References KCardCachePrivate::ensureNonNullPixmap(), KCardCachePrivate::frontcache, KCardCachePrivate::frontcacheMutex, CardDeckInfo::frontDir(), KCardCachePrivate::frontTheme, CardDeckInfo::isSVGFront(), keyForPixmap(), KCardInfo::pngName(), KCardCachePrivate::renderFrontSvg(), KCardCachePrivate::size, and KCardInfo::svgName().

Here is the call graph for this function:

QSizeF KCardCache::defaultFrontSize ( const KCardInfo info  )  const

Retrieve the default size for the frontside card.

Make sure to set a reasonable theme, before calling this function.

Parameters:
infos A combination of CardInfo flags to identify what type of card to load. There are of course only certain combinations that make sense, like King | Heart, some flags are used standalone, like Joker.
Returns:
the default size of the selected frontside card

Definition at line 594 of file cardcache.cpp.

References CardDeckInfo::frontDir(), KCardCachePrivate::frontRenderer, KCardCachePrivate::frontRendererMutex, KCardCachePrivate::frontTheme, CardDeckInfo::isSVGFront(), KCardInfo::pngName(), size(), and KCardInfo::svgName().

Here is the call graph for this function:

void KCardCache::invalidateFrontside (  ) 

Invalidates all cached images in the current size for the current frontside theme.

Definition at line 639 of file cardcache.cpp.

References KCardCachePrivate::frontcache, and KCardCachePrivate::frontcacheMutex.

void KCardCache::loadTheme ( LoadInfos  infos = LoadInfos( LoadFrontSide | LoadBackSide | Load53Cards )  ) 

Loads a whole theme in the background.

Depending on the value of type only parts may be rendered.

Parameters:
infos wether to load all entries in the theme or just the front or back sides. Also its possible to specify a different deck, like a 32 card deck.

Definition at line 579 of file cardcache.cpp.

References KCardCachePrivate::backTheme, KCardCachePrivate::frontTheme, LoadThread::kill(), KCardCachePrivate::loadThread, LoadThread::setBackTheme(), LoadThread::setFrontTheme(), LoadThread::setSize(), and KCardCachePrivate::size.

Here is the call graph for this function:


The documentation for this class was generated from the following files:
Generated on Sun Mar 16 08:03:05 2008 for Libkdegames by  doxygen 1.5.3