-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteractive_map_view.cpp
More file actions
59 lines (50 loc) · 1.63 KB
/
Copy pathinteractive_map_view.cpp
File metadata and controls
59 lines (50 loc) · 1.63 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
#include "interactive_map_view.h"
static bool recordFlag = false;
static int counter = 0;
static FILE* output = nullptr;
InteractiveMapView::InteractiveMapView():
backgroundPix(":/images/Ukraine.png")
{
setBackgroundBrush(QBrush(backgroundPix));
}
InteractiveMapView::InteractiveMapView(QGraphicsScene* scene, QWidget *parent):
QGraphicsView(scene, parent)
{
backgroundPix.load(":/images/Ukraine.png");
setBackgroundBrush(QBrush(backgroundPix));
}
void InteractiveMapView::mouseDoubleClickEvent(QMouseEvent *event)
{
QGraphicsView::mouseDoubleClickEvent(event);
}
void InteractiveMapView::mousePressEvent(QMouseEvent *event)
{
QGraphicsView::mousePressEvent(event);
recordFlag = true;
counter++;
output = fopen((std::string("roadX") + std::to_string(counter)).c_str(), "w");
fprintf(output, "{%f, %f}\n", event->position().x(), event->position().y());
}
void InteractiveMapView::mouseMoveEvent(QMouseEvent *event)
{
QGraphicsView::mouseMoveEvent(event);
if (recordFlag) {
fprintf(output, "{%f, %f}\n", event->position().x(), event->position().y());
}
}
void InteractiveMapView::mouseReleaseEvent(QMouseEvent *event)
{
QGraphicsView::mouseReleaseEvent(event);
recordFlag = false;
if (output) {
fprintf(output, "{%4.1f, %4.1f}\n", event->position().x(), event->position().y());
fclose(output);
output = nullptr;
}
}
void InteractiveMapView::drawBackground(QPainter *painter, const QRectF &rect)
{
Q_UNUSED(rect);
// Stretch the pixmap to fit the visible viewport area
painter->drawPixmap(viewport()->rect(), backgroundPix, backgroundPix.rect());
}