|
game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
|
Async image loader using QThreadPool. More...
#include <async_image_loader.h>
Classes | |
| class | ImageLoadTask |
Public Member Functions | |
| AsyncImageLoader (QObject *parent=nullptr) | |
| ~AsyncImageLoader () override | |
| void | cancelAll () |
| Cancel all pending requests (useful when changing views). | |
| void | clearCache () |
| Clear the image cache. | |
| QPixmap | getCached (const QString &cacheKey) |
| Get cached image directly (for synchronous fallback). | |
| void | getCacheStats (size_t &size, size_t &hits, size_t &misses) const |
| Get cache statistics. | |
| void | imageLoaded (const QString &cacheKey, const QPixmap &pixmap) |
| Emitted when an image has been loaded (on main thread). | |
| bool | isCached (const QString &cacheKey) const |
| Check if an image is already cached. | |
| void | requestImage (const QString &cacheKey, const QString &imagePath, const QSize &targetSize, bool useFastScaling=true, int priority=0) |
| Request an image to be loaded asynchronously. | |
| void | setMaxCacheSize (size_t maxSize) |
| Set maximum cache size. | |
Async image loader using QThreadPool.
Loads and scales images in background threads, emits signals when complete. Automatically manages a thread-safe LRU cache.
Usage: auto* loader = new AsyncImageLoader(this); connect(loader, &AsyncImageLoader::imageLoaded, this, &MyWidget::onImageLoaded); loader->requestImage("game123", "/path/to/image.png", QSize(150, 225));
The loader will:
Definition at line 103 of file async_image_loader.h.
|
explicit |
Definition at line 206 of file async_image_loader.cpp.
Referenced by AsyncImageLoader::ImageLoadTask::ImageLoadTask(), and AsyncImageLoader::ImageLoadTask::run().
|
override |
Definition at line 214 of file async_image_loader.cpp.
References cancelAll().
| void AsyncImageLoader::cancelAll | ( | ) |
Cancel all pending requests (useful when changing views).
Definition at line 255 of file async_image_loader.cpp.
Referenced by ~AsyncImageLoader().
| void AsyncImageLoader::clearCache | ( | ) |
Clear the image cache.
Definition at line 268 of file async_image_loader.cpp.
| QPixmap AsyncImageLoader::getCached | ( | const QString & | cacheKey | ) |
Get cached image directly (for synchronous fallback).
Definition at line 278 of file async_image_loader.cpp.
| void AsyncImageLoader::getCacheStats | ( | size_t & | size, |
| size_t & | hits, | ||
| size_t & | misses ) const |
Get cache statistics.
Definition at line 290 of file async_image_loader.cpp.
| void AsyncImageLoader::imageLoaded | ( | const QString & | cacheKey, |
| const QPixmap & | pixmap ) |
Emitted when an image has been loaded (on main thread).
| cacheKey | The key used in requestImage() |
| pixmap | The loaded and scaled pixmap (null if failed) |
Referenced by MainWindow::MainWindow(), and requestImage().
| bool AsyncImageLoader::isCached | ( | const QString & | cacheKey | ) | const |
Check if an image is already cached.
Definition at line 273 of file async_image_loader.cpp.
| void AsyncImageLoader::requestImage | ( | const QString & | cacheKey, |
| const QString & | imagePath, | ||
| const QSize & | targetSize, | ||
| bool | useFastScaling = true, | ||
| int | priority = 0 ) |
Request an image to be loaded asynchronously.
| cacheKey | Unique key for caching (e.g., "gameId_width_height") |
| imagePath | Path to the image file |
| targetSize | Desired scaled size |
| useFastScaling | Use Qt::FastTransformation (true) or SmoothTransformation (false) |
| priority | Higher priority tasks run first (default 0) |
If image is already cached, emits imageLoaded immediately (on next event loop). Otherwise queues a background task.
Definition at line 219 of file async_image_loader.cpp.
References ImageLoadRequest::cacheKey, imageLoaded(), ImageLoadRequest::imagePath, ImageLoadRequest::targetSize, and ImageLoadRequest::useFastScaling.
| void AsyncImageLoader::setMaxCacheSize | ( | size_t | maxSize | ) |
Set maximum cache size.
Definition at line 283 of file async_image_loader.cpp.