blob: 36d2418d9e959a3c65dd6f94ab44d6f1a19ca48e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#include "widget/wpixmapstore.h"
#include <QDir>
#include <QString>
#include <QtDebug>
#include "util/math.h"
#include "skin/imgloader.h"
// static
QHash<QString, WeakPaintablePointer> WPixmapStore::m_paintableCache;
QSharedPointer<ImgSource> WPixmapStore::m_loader
= QSharedPointer<ImgSource>(new ImgLoader());
// static
PaintablePointer WPixmapStore::getPaintable(PixmapSource source,
Paintable::DrawMode mode,
double scaleFactor) {
if (source.isEmpty()) {
return PaintablePointer();
}
QString key = source.getId() + QString::number(mode) + QString::number(scaleFactor);
// See if we have a cached value for the pixmap.
PaintablePointer pPaintable = m_paintableCache.value(
key,
PaintablePointer());
if (pPaintable) {
return pPaintable;
}
pPaintable = PaintablePointer(new Paintable(source, mode, scaleFactor));
m_paintableCache.insert(key, pPaintable);
return pPaintable;
}
// static
QPixmap* WPixmapStore::getPixmapNoCache(
const QString& fileName,
double scaleFactor) {
QPixmap* pPixmap = nullptr;
QImage* img = m_loader->getImage(fileName, scaleFactor);
#if QT_VERSION >= 0x040700
pPixmap = new QPixmap();
pPixmap->convertFromImage(*img);
#else
pPixmap = new QPixmap(QPixmap::fromImage(*img));
#endif
delete img;
return pPixmap;
}
// static
void WPixmapStore::correctImageColors(QImage* p) {
m_loader->correctImageColors(p);
}
bool WPixmapStore::willCorrectColors() {
return m_loader->willCorrectColors();
};
void WPixmapStore::setLoader(QSharedPointer<ImgSource> ld) {
m_loader = ld;
// We shouldn't hand out pointers to existing pixmaps anymore since our
// loader has changed. The pixmaps will get freed once all the widgets
// referring to them are destroyed.
m_paintableCache.clear();
}
|