game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
qt_image_service.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// qt/qt_image_service.h
4// ==============================================================================
5// Qt implementation of IImageService
6// Uses QPixmap for image loading and caching
7// ==============================================================================
8
9#pragma once
10
12
13#include <QPixmap>
14#include <QString>
15#include <map>
16#include <mutex>
17
19{
20 public:
21 QtImageService() = default;
22 ~QtImageService() override = default;
23
24 // IImageService implementation
25 bool loadImage(const std::string& path, int* width = nullptr, int* height = nullptr) override;
26 bool isImageLoaded(const std::string& path) const override;
27 void unloadImage(const std::string& path) override;
28 void clearCache() override;
29 bool getImageDimensions(const std::string& path, int* width, int* height) const override;
30
31 // Qt-specific: Get cached pixmap for a path
32 QPixmap getPixmap(const std::string& path);
33
34 // Qt-specific: Get scaled pixmap for a path
35 QPixmap getScaledPixmap(const std::string& path, int maxWidth, int maxHeight);
36
37 private:
38 struct CachedImage
39 {
40 QPixmap pixmap;
41 int width = 0;
42 int height = 0;
43 };
44
45 mutable std::mutex cacheMutex_;
46 std::map<std::string, CachedImage> cache_;
47};
void unloadImage(const std::string &path) override
Unload a specific image and free resources.
bool loadImage(const std::string &path, int *width=nullptr, int *height=nullptr) override
Load an image from disk.
QPixmap getPixmap(const std::string &path)
void clearCache() override
Clear all cached images and free resources.
QtImageService()=default
~QtImageService() override=default
bool getImageDimensions(const std::string &path, int *width, int *height) const override
Get dimensions of a loaded image.
QPixmap getScaledPixmap(const std::string &path, int maxWidth, int maxHeight)
bool isImageLoaded(const std::string &path) const override
Check if an image is already loaded/cached.
Abstract interface for image loading operations.