mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-09 03:23:24 -08:00
* [VisualDatabase] Draw the card grid with a model/view instead of a widget per card The visual card database built one CardInfoPictureWithTextOverlayWidget per card, 100 per page, and tore them down on every search, resize and scroll page. It also looked each card up again by name from the model row, kept a shadow QList<ExactCard>, and carried paging state plus a 5 s timer that only existed to defer the first page. Replace that with a real view on a flattened model: - CardDatabaseDisplayModel gains CardInfoRole and cardInfoAt(), so a view can get the CardInfoPtr behind a proxy row without a name round trip. - New CardDatabaseVisualDisplayModel (libcockatrice_models) flattens the filtered and sorted proxy into one entry per displayed card picture: the preferred printing normally, every printing of the selected sets while set filters are active. Proxy changes rebuild it on a 30 ms coalescing timer. - New CardDatabaseVisualView (QListView IconMode) paints only visible rows through the new CardPictureDelegate, keeps the old interaction contract (left/right/middle press -> cardClicked, hover -> cardHovered, Ctrl+wheel resize, no selection, no focus stealing, scroll to top on a new result) and repaints when CardPictureLoader reports an async image. - CardSizeWidget::enableCtrlScrollResize() also watches scroll-area viewports, which is what makes Ctrl+wheel work over a QListView. - VisualDatabaseDisplayWidget drops the paging, the shadow list, the dead members and the 5 s timer. Behaviour-preserving: no gameplay change, no new user-facing strings. * [VisualDatabase] Fix the card grid wheel step QListView hands the delegate's item height to the scroll bar as its single step under ScrollPerPixel, so QAbstractSlider moved wheelScrollLines() whole card rows per notch. Handle the wheel in the view instead: one line is an eighth of the grid cell, so a notch moves about a third of a card row at any card size and still follows the OS line count. --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
177 lines
6.1 KiB
C++
177 lines
6.1 KiB
C++
#ifndef CARD_PICTURE_LOADER_H
|
|
#define CARD_PICTURE_LOADER_H
|
|
|
|
#include <QHash>
|
|
#include <QLoggingCategory>
|
|
#include <QObject>
|
|
#include <qtmetamacros.h>
|
|
|
|
class CardPictureLoaderStatusBar;
|
|
class CardPictureLoaderWorker;
|
|
class ExactCard;
|
|
class QDateTime;
|
|
class QImage;
|
|
class QPixmap;
|
|
class QSize;
|
|
class QString;
|
|
template <typename T> class QList;
|
|
|
|
inline Q_LOGGING_CATEGORY(CardPictureLoaderLog, "card_picture_loader");
|
|
inline Q_LOGGING_CATEGORY(CardPictureLoaderCardBackCacheFailLog, "card_picture_loader.card_back_cache_fail");
|
|
|
|
/**
|
|
* @class CardPictureLoader
|
|
* @ingroup PictureLoader
|
|
* @brief 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:
|
|
* - Card images by ExactCard.
|
|
* - Card back images (normal, in-progress, failed).
|
|
* - Cache management (clearPixmapCache(), clearNetworkCache(), cacheCardPixmaps(const QList<ExactCard> &cards)).
|
|
*
|
|
* Uses a worker thread for asynchronous image loading and a status bar widget
|
|
* to track load progress.
|
|
*/
|
|
class CardPictureLoader : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
/**
|
|
* @brief Access the singleton instance of CardPictureLoader.
|
|
* @return Reference to the singleton.
|
|
*/
|
|
static CardPictureLoader &getInstance()
|
|
{
|
|
static CardPictureLoader instance;
|
|
return instance;
|
|
}
|
|
|
|
private:
|
|
explicit CardPictureLoader();
|
|
~CardPictureLoader() override;
|
|
|
|
// Disable copy and assignment for singleton
|
|
CardPictureLoader(CardPictureLoader const &) = delete;
|
|
void operator=(CardPictureLoader const &) = delete;
|
|
|
|
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
|
|
|
|
public:
|
|
/**
|
|
* @brief Retrieve a card pixmap, either from cache or enqueued for loading.
|
|
* @param pixmap Reference to QPixmap where result will be stored.
|
|
* @param card ExactCard to load.
|
|
* @param size Desired size of pixmap.
|
|
*/
|
|
static void getPixmap(QPixmap &pixmap, const ExactCard &card, QSize size);
|
|
|
|
/**
|
|
* @brief Retrieve a generic card back pixmap.
|
|
* @param pixmap Reference to QPixmap where result will be stored.
|
|
* @param size Desired size of pixmap.
|
|
*/
|
|
static void getCardBackPixmap(QPixmap &pixmap, QSize size);
|
|
|
|
/**
|
|
* @brief Retrieve a card back pixmap for the loading-in-progress state.
|
|
* @param pixmap Reference to QPixmap where result will be stored.
|
|
* @param size Desired size of pixmap.
|
|
*/
|
|
static void getCardBackLoadingInProgressPixmap(QPixmap &pixmap, QSize size);
|
|
|
|
/**
|
|
* @brief Retrieve a card back pixmap for the loading-failed state.
|
|
* @param pixmap Reference to QPixmap where result will be stored.
|
|
* @param size Desired size of pixmap.
|
|
*/
|
|
static void getCardBackLoadingFailedPixmap(QPixmap &pixmap, QSize size);
|
|
|
|
/**
|
|
* @brief Preload a list of cards into the pixmap cache (limited to CACHED_CARD_PER_DECK_MAX).
|
|
* @param cards List of ExactCard objects to preload.
|
|
*/
|
|
static void cacheCardPixmaps(const QList<ExactCard> &cards);
|
|
|
|
/**
|
|
* @brief Check if a local override image already exists for the card.
|
|
* @param card The card to check.
|
|
* @return True if the card has at least one locally stored override image.
|
|
*/
|
|
static bool hasLocalOverrides(const ExactCard &card);
|
|
|
|
/**
|
|
* @brief Removes all locally stored override images for the card.
|
|
* @param card The card to remove the override images of.
|
|
*/
|
|
static void deleteAllLocalOverrides(const ExactCard &card);
|
|
|
|
/**
|
|
* @brief Clears the in-memory QPixmap cache for all cards.
|
|
*/
|
|
static void clearPixmapCache();
|
|
|
|
public slots:
|
|
/**
|
|
* @brief 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.
|
|
*/
|
|
static void clearNetworkCache();
|
|
|
|
/**
|
|
* @brief Slot called by the worker when an image is loaded.
|
|
* Inserts the pixmap into the cache and emits pixmap updated signals.
|
|
* @param card ExactCard that was loaded.
|
|
* @param image Loaded QImage.
|
|
*/
|
|
void imageLoaded(const ExactCard &card, const QImage &image);
|
|
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:
|
|
/** @brief Emitted after the worker has finished clearing the network and redirect caches. */
|
|
void networkCacheCleared();
|
|
|
|
/**
|
|
* @brief Emitted once an image has been loaded and put into the pixmap cache.
|
|
*
|
|
* Views that paint cards from the loader without owning a widget per card can
|
|
* listen to this to repaint the rows whose picture just became available.
|
|
*/
|
|
void pixmapLoaded(const ExactCard &card);
|
|
|
|
private slots:
|
|
/**
|
|
* @brief Triggered when the user changes the picture download settings.
|
|
* Clears the QPixmap cache to reload images.
|
|
*/
|
|
void picDownloadChanged();
|
|
|
|
/**
|
|
* @brief Triggered when the pictures path changes.
|
|
* Clears the QPixmap cache to reload images.
|
|
*/
|
|
void picsPathChanged();
|
|
|
|
/**
|
|
* @brief Triggered when the card language setting changes.
|
|
* Clears the in-memory picture caches so images reload in the new language.
|
|
*/
|
|
void cardLangChanged();
|
|
};
|
|
|
|
#endif
|