marker.cpp 1.82 KB
Newer Older
1
2
3
4
5
6
7
#include "marker.h"

#include <QPen>
#include <QBrush>


Marker::Marker(qreal x, qreal y, QGraphicsItem * parent)
8
    : QGraphicsEllipseItem(-MARKER_DIAMETER/2, - MARKER_DIAMETER/2, MARKER_DIAMETER, MARKER_DIAMETER, parent)
9
10
11
{
    _highlighted = false;
    _highlight_diameter = HIGHLIGHT_DIAMETER;
12
13
14
15

    // save original x and y
    _center_x = x;
    _center_y = y;
16
17

    _diameter = MARKER_DIAMETER; // x and y are top left coordinates
18
19
20
21
    this->setPos(_center_x, _center_y);          //where it is now, it is the center

    _x_highlight = _center_x - _highlight_diameter/2; // update top-left corner coordinates of highlighing circle
    _y_highlight = _center_y - _highlight_diameter/2;
22
23
24
25
26
    this->setPen(Qt::NoPen);
    this->setBrush(QColor(255, 0, 0));
    this->setZValue(10);        // max z value, should always be seen
}

27
28
29
void Marker::setPosMarker(QPointF new_p)
{
    prepareGeometryChange();
30
    this->setPos(_center_x, _center_y);
31
32
33
34
35

    _center_x = new_p.x();              // update center coordinates
    _center_y = new_p.y();
}

36
37
void Marker::setHighlighted(void)
{
38
39
40
    if(!_highlighted)
    {
        prepareGeometryChange();
41
42
        _highlight_circle = new QGraphicsEllipseItem(QRectF(-_highlight_diameter/2, -_highlight_diameter/2, _highlight_diameter, _highlight_diameter), this);
        _highlight_circle->setPos(0, 0);
43
        _highlight_circle->setPen(QPen(QBrush(Qt::black), HIGHLIGHT_WIDTH));
44
        _highlight_circle->setFlag(QGraphicsItem::ItemIgnoresTransformations);
45
46
        _highlighted = true;
    }
47
48
49
50
}

void Marker::clearHighlighted(void)
{
51
52
53
54
55
56
57
    if(_highlighted)
    {
        prepareGeometryChange();
        _highlight_circle->setParentItem(NULL);
        delete _highlight_circle;
        _highlighted = false;
    }
58
59
60
61
62
63
64
65
}


bool Marker::getHighlighted(void)
{
    return _highlighted;
}

66
67
68
69
Marker::~Marker()
{
    clearHighlighted();
}