Line data Source code
1 : #include "object.h"
2 :
3 8 : Object::Object(QWidget *parent): QWidget(parent)
4 : {
5 8 : QString path = QCoreApplication::applicationDirPath();
6 8 : speed50_path = QDir(path).filePath("../fonts_icon/speed50.png");
7 8 : speed50_path = QDir::cleanPath(speed50_path);
8 8 : speed80_path = QDir(path).filePath("../fonts_icon/speed80.png");
9 8 : speed80_path = QDir::cleanPath(speed80_path);
10 8 : object = 0;
11 8 : set_object(1, "jetracer/speed_50");
12 8 : }
13 :
14 4 : void Object::paintEvent(QPaintEvent *event)
15 : {
16 4 : QPainter painter(this);
17 4 : painter.setRenderHint(QPainter::Antialiasing);
18 4 : QPixmap pixmap;
19 4 : if (object == 11) {
20 4 : pixmap.load(speed50_path);
21 0 : } else if (object == 1) {
22 0 : pixmap.load(speed80_path);
23 : }
24 4 : if (!pixmap.isNull()) {
25 4 : QPixmap scaled = pixmap.scaled(60, 60, Qt::KeepAspectRatio, Qt::SmoothTransformation);
26 4 : painter.drawPixmap(0, 0, scaled); // margin
27 4 : }
28 : else {
29 0 : std::cout << "Object: no image found" << std::endl;
30 : }
31 4 : }
32 :
33 : //parsing
34 13 : void Object::set_object(int i, const QString &topicName)
35 : {
36 13 : if (i != 1)
37 1 : return;
38 12 : if (topicName == "jetracer/speed_50") {
39 10 : object = i + 10;
40 : } else {
41 2 : object = i;
42 : }
43 12 : update();
44 : }
45 :
46 5 : int Object::get_object()
47 : {
48 5 : return object;
49 : }
50 :
51 16 : Object::~Object()
52 : {
53 8 : std::cout << "Remove Object" << std::endl;
54 16 : }
|