Cockatrice 2026-10-19-Development-3.1.2-beta.2
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
CardPictureLoader Class Reference

Singleton class to manage card image loading and caching. Provides functionality to asynchronously load, cache, and manage card images for the client. More...

#include <card_picture_loader.h>

Inheritance diagram for CardPictureLoader:
[legend]
Collaboration diagram for CardPictureLoader:
[legend]

Public Slots

static void clearNetworkCache ()
 Clears the network disk cache of the worker.
void imageLoaded (const ExactCard &card, const QImage &image)
 Slot called by the worker when an image is loaded. Inserts the pixmap into the cache and emits pixmap updated signals.
void saveCardImageToLocalStorage (const ExactCard &card, const QPixmap &pixmap, bool allowOverwrite=false)
void installPrintingOverride (const ExactCard &originalCard, const ExactCard &overrideCard)
void installPrintingOverrideOnLoad (const ExactCard &originalCard, const ExactCard &overrideCard)

Signals

void networkCacheCleared ()
 Emitted after the worker has finished clearing the network and redirect caches.

Static Public Member Functions

static CardPictureLoader & getInstance ()
 Access the singleton instance of CardPictureLoader.
static void getPixmap (QPixmap &pixmap, const ExactCard &card, QSize size)
 Retrieve a card pixmap, either from cache or enqueued for loading.
static void getCardBackPixmap (QPixmap &pixmap, QSize size)
 Retrieve a generic card back pixmap.
static void getCardBackLoadingInProgressPixmap (QPixmap &pixmap, QSize size)
 Retrieve a card back pixmap for the loading-in-progress state.
static void getCardBackLoadingFailedPixmap (QPixmap &pixmap, QSize size)
 Retrieve a card back pixmap for the loading-failed state.
static void cacheCardPixmaps (const QList< ExactCard > &cards)
 Preload a list of cards into the pixmap cache (limited to CACHED_CARD_PER_DECK_MAX).
static bool hasLocalOverrides (const ExactCard &card)
 Check if a local override image already exists for the card.
static void deleteAllLocalOverrides (const ExactCard &card)
 Removes all locally stored override images for the card.
static void clearPixmapCache ()
 Clears the in-memory QPixmap cache for all cards.
static void clearPixmapCache (CardInfoPtr card)

Private Slots

void picDownloadChanged ()
 Triggered when the user changes the picture download settings. Clears the QPixmap cache to reload images.
void picsPathChanged ()
 Triggered when the pictures path changes. Clears the QPixmap cache to reload images.
void cardLangChanged ()
 Triggered when the card language setting changes. Clears the in-memory picture caches so images reload in the new language.

Private Member Functions

 CardPictureLoader ()
 ~CardPictureLoader () override
 CardPictureLoader (CardPictureLoader const &)=delete
void operator= (CardPictureLoader const &)=delete

Private Attributes

CardPictureLoaderWorker * worker
 Worker thread for async image loading.
CardPictureLoaderStatusBar * statusBar
 Status bar widget showing load progress.
QHash< QString, QDateTime > failedAt
 Timestamp of the last failed load attempt per pixmap cache key.

Detailed Description

Singleton class to manage card image loading and caching. Provides functionality to asynchronously load, cache, and manage card images for the client.

This class is a singleton and handles:

  • Loading card images from disk or network.
  • Caching images in QPixmapCache for fast reuse.
  • Providing themed card backs, including fallback and in-progress/failed states.
  • Emitting updates when pixmaps are loaded.

It interacts with CardPictureLoaderWorker for background loading and CardPictureLoaderStatusBar to display loading progress in the main window.

Provides static accessors for:

Uses a worker thread for asynchronous image loading and a status bar widget to track load progress.

Constructor & Destructor Documentation

◆ CardPictureLoader() [1/2]

CardPictureLoader::CardPictureLoader ( )
explicitprivate
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~CardPictureLoader()

CardPictureLoader::~CardPictureLoader ( )
overrideprivate
Here is the call graph for this function:

◆ CardPictureLoader() [2/2]

CardPictureLoader::CardPictureLoader ( CardPictureLoader const & )
privatedelete
Here is the call graph for this function:

Member Function Documentation

◆ cacheCardPixmaps()

void CardPictureLoader::cacheCardPixmaps ( const QList< ExactCard > & cards)
static

Preload a list of cards into the pixmap cache (limited to CACHED_CARD_PER_DECK_MAX).

Parameters
cardsList of ExactCard objects to preload.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cardLangChanged

void CardPictureLoader::cardLangChanged ( )
privateslot

Triggered when the card language setting changes. Clears the in-memory picture caches so images reload in the new language.

Here is the caller graph for this function:

◆ clearNetworkCache

void CardPictureLoader::clearNetworkCache ( )
staticslot

Clears the network disk cache of the worker.

The clear runs on the worker thread, so this returns before it has completed; connect to networkCacheCleared() to act once it is done.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clearPixmapCache() [1/2]

void CardPictureLoader::clearPixmapCache ( )
static

Clears the in-memory QPixmap cache for all cards.

Here is the caller graph for this function:

◆ clearPixmapCache() [2/2]

void CardPictureLoader::clearPixmapCache ( CardInfoPtr card)
static

◆ deleteAllLocalOverrides()

void CardPictureLoader::deleteAllLocalOverrides ( const ExactCard & card)
static

Removes all locally stored override images for the card.

Parameters
cardThe card to remove the override images of.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCardBackLoadingFailedPixmap()

void CardPictureLoader::getCardBackLoadingFailedPixmap ( QPixmap & pixmap,
QSize size )
static

Retrieve a card back pixmap for the loading-failed state.

Parameters
pixmapReference to QPixmap where result will be stored.
sizeDesired size of pixmap.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCardBackLoadingInProgressPixmap()

void CardPictureLoader::getCardBackLoadingInProgressPixmap ( QPixmap & pixmap,
QSize size )
static

Retrieve a card back pixmap for the loading-in-progress state.

Parameters
pixmapReference to QPixmap where result will be stored.
sizeDesired size of pixmap.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCardBackPixmap()

void CardPictureLoader::getCardBackPixmap ( QPixmap & pixmap,
QSize size )
static

Retrieve a generic card back pixmap.

Parameters
pixmapReference to QPixmap where result will be stored.
sizeDesired size of pixmap.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getInstance()

CardPictureLoader & CardPictureLoader::getInstance ( )
inlinestatic

Access the singleton instance of CardPictureLoader.

Returns
Reference to the singleton.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPixmap()

void CardPictureLoader::getPixmap ( QPixmap & pixmap,
const ExactCard & card,
QSize size )
static

Retrieve a card pixmap, either from cache or enqueued for loading.

Parameters
pixmapReference to QPixmap where result will be stored.
cardExactCard to load.
sizeDesired size of pixmap.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasLocalOverrides()

bool CardPictureLoader::hasLocalOverrides ( const ExactCard & card)
static

Check if a local override image already exists for the card.

Parameters
cardThe card to check.
Returns
True if the card has at least one locally stored override image.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ imageLoaded

void CardPictureLoader::imageLoaded ( const ExactCard & card,
const QImage & image )
slot

Slot called by the worker when an image is loaded. Inserts the pixmap into the cache and emits pixmap updated signals.

Parameters
cardExactCard that was loaded.
imageLoaded QImage.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ installPrintingOverride

void CardPictureLoader::installPrintingOverride ( const ExactCard & originalCard,
const ExactCard & overrideCard )
slot
Here is the call graph for this function:
Here is the caller graph for this function:

◆ installPrintingOverrideOnLoad

void CardPictureLoader::installPrintingOverrideOnLoad ( const ExactCard & originalCard,
const ExactCard & overrideCard )
slot
Here is the call graph for this function:
Here is the caller graph for this function:

◆ networkCacheCleared

void CardPictureLoader::networkCacheCleared ( )
signal

Emitted after the worker has finished clearing the network and redirect caches.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

void CardPictureLoader::operator= ( CardPictureLoader const & )
privatedelete
Here is the call graph for this function:

◆ picDownloadChanged

void CardPictureLoader::picDownloadChanged ( )
privateslot

Triggered when the user changes the picture download settings. Clears the QPixmap cache to reload images.

Here is the caller graph for this function:

◆ picsPathChanged

void CardPictureLoader::picsPathChanged ( )
privateslot

Triggered when the pictures path changes. Clears the QPixmap cache to reload images.

Here is the caller graph for this function:

◆ saveCardImageToLocalStorage

void CardPictureLoader::saveCardImageToLocalStorage ( const ExactCard & card,
const QPixmap & pixmap,
bool allowOverwrite = false )
slot
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ failedAt

QHash<QString, QDateTime> CardPictureLoader::failedAt
private

Timestamp of the last failed load attempt per pixmap cache key.

◆ statusBar

CardPictureLoaderStatusBar* CardPictureLoader::statusBar
private

Status bar widget showing load progress.

◆ worker

CardPictureLoaderWorker* CardPictureLoader::worker
private

Worker thread for async image loading.


The documentation for this class was generated from the following files: