-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpharmimage.cpp
More file actions
80 lines (70 loc) · 2.78 KB
/
pharmimage.cpp
File metadata and controls
80 lines (70 loc) · 2.78 KB
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
71
72
73
74
75
76
77
78
#include "pharmimage.h"
#include <QDebug>
#include <QPainter>
PharmImage::PharmImage():
QQuickImageProvider(QQuickImageProvider::Image)
{
}
QImage PharmImage::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
{
/*
* thumbnail/file.png
*/
qDebug() << "id: " << id << "\n";
qDebug() << "size: (" << size->width() << ", " << size->height() << ")";
qDebug() << "requestedSize: (" << requestedSize.width() << ", " << requestedSize.height() << ")";
(void) size; // to avoid unused variable warnings
//bool requestedThumb = false;
if(id.contains('/')) {
int indexOfSlash = id.indexOf('/');
qDebug() << "index of /:" << indexOfSlash;
QString command = id.left(indexOfSlash);
QString fileUrlString = id.right(id.length() - command.length() - 1);
QString filename = QUrl(fileUrlString).path();
qDebug() << "command: " << command;
qDebug() << "filename: " << filename;
if(command=="thumbnail"){
//requestedThumb = true;
return loadThumbnail(filename, requestedSize.width(), requestedSize.height());
} else if (command.startsWith("rec")) {
QString cod_str = command.remove(QRegExp("[rec)(]"));
qDebug() << "rectangle center: " << cod_str;
QStringList cod_str_lst = cod_str.split(",");
QList<int> cod_int_lst;
for(int i =0; i < cod_str_lst.length(); i++) cod_int_lst.push_back(cod_str_lst[i].trimmed().toInt()); // push the trimmed elements of
// cod_str_lst to cod_int_lst
qDebug() << "cod_int_lst[0]: " << cod_int_lst[0];
qDebug() << "cod_int_lst[1]: " << cod_int_lst[1];
return loadRecImage(filename, cod_int_lst[0], cod_int_lst[1]);
}
} else {
return loadImage(id);
}
}
QImage PharmImage::loadImage(const QString &filename)
{
//qDebug() << "filename: " << filename << "\n";
QImage img(filename);
return img;
}
QImage PharmImage::loadThumbnail(const QString &filename, int width, int height)
{
QImage img(filename);
//qDebug() << "filename: " << filename << "\n";
qDebug() << "widht: " << width;
qDebug() << "height: " << height;
// return a scaled image only if sourceWidth and sourceHeight are defined in the qml image element
if(width > 0 && height > 0)
img = img.scaled(width, height);
return img;
}
QImage PharmImage::loadRecImage(const QString &filename, int cntX, int cntY)
{
QImage img(filename);
QPainter p(&img);
p.setBrush(Qt::NoBrush);
p.setPen(Qt::cyan);
p.drawRect(cntX-15, cntY-15, 30, 30);
p.end();
return img;
}