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
|
#include "imageprovider.h"
#include <QDebug>
#include <QFileInfo>
#include <QCoreApplication>
ImageProvider::ImageProvider(const QString &type) :
QQuickImageProvider(QQuickImageProvider::Image),
m_type(type)
{
}
QImage ImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
{
if (id.split('/').count() < 2) {
return QImage();
}
QString levelpack = id.split('/').first();
QString filebasename = id.split('/').at(1);
QImage image;
QString subdir = m_type;
QString fileName = filebasename;
if (m_type == "boards") {
qDebug() << "filebakse" << filebasename;
subdir = filebasename;
fileName = "board.png";
if (filebasename.endsWith("-preview")) {
subdir.remove(QRegExp("-preview$"));
fileName += "_preview.png";
}
} else if (m_type == "packdata") {
subdir = "";
}
qDebug() << "loading image:" << QCoreApplication::applicationDirPath() + "/data/levelpacks/" + levelpack + '/' + subdir + "/" + fileName;
image.load(QCoreApplication::applicationDirPath() + "/data/levelpacks/" + levelpack + '/' + subdir + "/" + fileName);
if (requestedSize.isValid()) {
image.scaled(requestedSize);
}
if (size) {
size->setWidth(image.width());
size->setHeight(image.height());
}
return image;
}
|