crazyFlyZone.cpp 2.11 KB
Newer Older
1
#include "crazyFlyZone.h"
2
#include "globalDefinitions.h"
3
4
5
6

crazyFlyZone::crazyFlyZone(const QRectF & rect, int index,  QGraphicsItem * parent)
    : myGraphicsRectItem(rect, parent)
{
7
    createCenterMarker();
8
9
    this->setPen(QPen(Qt::black, 0));
    setIndex(index);
10
11
12
13
14
    m_linked = false;
}

crazyFlyZone::~crazyFlyZone()
{
15
16
17
18
19
20
21
22
}

void crazyFlyZone::updateLabel(QString string)
{
    label->setText(string);
    setLabelPosition();
}

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
void crazyFlyZone::createCenterMarker()
{
    qreal diameter = 0.1 * FROM_METERS_TO_UNITS;
    m_center_marker = new QGraphicsEllipseItem(QRectF(-diameter/2, -diameter/2, diameter, diameter), this);
    updateCenterMarker();
    m_center_marker->setZValue(10); //max z value, always on top of things
}

void crazyFlyZone::updateCenterMarker()
{
    qreal x_offset = this->rect().width()/2;
    qreal y_offset = this->rect().height()/2;
    m_center_marker->setPos(this->rect().topLeft().x() + x_offset,this->rect().topLeft().y() + y_offset);
}

38
39
40
41
void crazyFlyZone::setLabel(QString string)
{
    label = new QGraphicsSimpleTextItem(string, this);
    label->setFlag(QGraphicsItem::ItemIgnoresTransformations);
42
    label->setFont(QFont("Arial", 16, QFont::Bold, true));
43
44
45
46
47
    setLabelPosition();
}

void crazyFlyZone::setLabelPosition()
{
48
49
    qreal x_offset = 0.1 * FROM_METERS_TO_UNITS;
    qreal y_offset = 0.05 * FROM_METERS_TO_UNITS;
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
    label->setPos(this->rect().topLeft().x() + x_offset,this->rect().topLeft().y() + y_offset);
}

int crazyFlyZone::getIndex()
{
    return _index;
}

void crazyFlyZone::setIndex(int index)
{
    // TODO: how to make sure that we never have two rectangles with the same index?
    // Maybe only when we reduce the size of the rectangles vector?
    _index = index;
}

void crazyFlyZone::rectSizeChanged() // pure virtual coming from parent
{
    setLabelPosition();
68
    updateCenterMarker();
69
}
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

void crazyFlyZone::linkCF(std::string cf_name)
{
    m_crazyfly_linked_name = cf_name;
    m_linked = true;
}

bool crazyFlyZone::isLinked()
{
    return m_linked;
}

void crazyFlyZone::removeLink()
{
    if(m_linked)
    {
        m_crazyfly_linked_name = "";
        m_linked = false;
    }
}