Cockatrice 2026-09-01-Development-3.1.0-beta.10
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
card_picture_loader.h
Go to the documentation of this file.
1#ifndef CARD_PICTURE_LOADER_H
2#define CARD_PICTURE_LOADER_H
3
6
7#include <QDateTime>
8#include <QHash>
9#include <QLoggingCategory>
10
11inline Q_LOGGING_CATEGORY(CardPictureLoaderLog, "card_picture_loader");
12inline Q_LOGGING_CATEGORY(CardPictureLoaderCardBackCacheFailLog, "card_picture_loader.card_back_cache_fail");
13
37class CardPictureLoader : public QObject
38{
39 Q_OBJECT
40public:
46 {
47 static CardPictureLoader instance;
48 return instance;
49 }
50
51private:
52 explicit CardPictureLoader();
53 ~CardPictureLoader() override;
54
55 // Disable copy and assignment for singleton
57 void operator=(CardPictureLoader const &) = delete;
58
61 QHash<QString, QDateTime> failedAt;
62
63public:
70 static void getPixmap(QPixmap &pixmap, const ExactCard &card, QSize size);
71
77 static void getCardBackPixmap(QPixmap &pixmap, QSize size);
78
84 static void getCardBackLoadingInProgressPixmap(QPixmap &pixmap, QSize size);
85
91 static void getCardBackLoadingFailedPixmap(QPixmap &pixmap, QSize size);
92
97 static void cacheCardPixmaps(const QList<ExactCard> &cards);
98
103 static bool hasCustomArt();
104
108 static void clearPixmapCache();
109
110public slots:
114 static void clearNetworkCache();
115
122 void imageLoaded(const ExactCard &card, const QImage &image);
123 void saveCardImageToLocalStorage(const ExactCard &card, const QPixmap &pixmap);
124
125private slots:
130 void picDownloadChanged();
131
136 void picsPathChanged();
137};
138
139#endif
Q_LOGGING_CATEGORY(CardPictureLoaderLog, "card_picture_loader")
Displays the status of card image downloads in a horizontal progress bar with a log popup.
Definition card_picture_loader_status_bar.h:22
Handles asynchronous loading of card images, both locally and via network.
Definition card_picture_loader_worker.h:43
QHash< QString, QDateTime > failedAt
Timestamp of the last failed load attempt per pixmap cache key.
Definition card_picture_loader.h:61
static void getPixmap(QPixmap &pixmap, const ExactCard &card, QSize size)
Retrieve a card pixmap, either from cache or enqueued for loading.
Definition card_picture_loader.cpp:123
static bool hasCustomArt()
Check if the user has custom card art in the picsPath directory.
Definition card_picture_loader.cpp:328
static void getCardBackLoadingInProgressPixmap(QPixmap &pixmap, QSize size)
Retrieve a card back pixmap for the loading-in-progress state.
Definition card_picture_loader.cpp:80
~CardPictureLoader() override
Definition card_picture_loader.cpp:55
void picsPathChanged()
Triggered when the pictures path changes. Clears the QPixmap cache to reload images.
Definition card_picture_loader.cpp:323
void operator=(CardPictureLoader const &)=delete
CardPictureLoaderWorker * worker
Worker thread for async image loading.
Definition card_picture_loader.h:59
CardPictureLoaderStatusBar * statusBar
Status bar widget showing load progress.
Definition card_picture_loader.h:60
static CardPictureLoader & getInstance()
Access the singleton instance of CardPictureLoader.
Definition card_picture_loader.h:45
CardPictureLoader(CardPictureLoader const &)=delete
CardPictureLoader()
Definition card_picture_loader.cpp:32
void picDownloadChanged()
Triggered when the user changes the picture download settings. Clears the QPixmap cache to reload ima...
Definition card_picture_loader.cpp:318
static void clearPixmapCache()
Clears the in-memory QPixmap cache for all cards.
Definition card_picture_loader.cpp:289
void saveCardImageToLocalStorage(const ExactCard &card, const QPixmap &pixmap)
Definition card_picture_loader.cpp:207
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...
Definition card_picture_loader.cpp:167
static void getCardBackPixmap(QPixmap &pixmap, QSize size)
Retrieve a generic card back pixmap.
Definition card_picture_loader.cpp:60
static void cacheCardPixmaps(const QList< ExactCard > &cards)
Preload a list of cards into the pixmap cache (limited to CACHED_CARD_PER_DECK_MAX).
Definition card_picture_loader.cpp:299
static void getCardBackLoadingFailedPixmap(QPixmap &pixmap, QSize size)
Retrieve a card back pixmap for the loading-failed state.
Definition card_picture_loader.cpp:102
static void clearNetworkCache()
Clears the network disk cache of the worker.
Definition card_picture_loader.cpp:294
Represents a specific card instance, defined by its CardInfo and a particular printing.
Definition exact_card.h:19