Skip to content
Snippets Groups Projects
Commit ec64ec5c authored by roangel's avatar roangel
Browse files

fixed problem with position of highlighting circle for markers

parent ae577cba
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.0.2, 2017-04-27T17:56:07. -->
<!-- Written by QtCreator 4.0.2, 2017-05-02T17:57:24. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
......
......@@ -10,6 +10,7 @@
#define HIGHLIGHT_DIAMETER 20
#define HIGHLIGHT_WIDTH 5
class Marker : public QGraphicsEllipseItem
{
public:
......
......@@ -68,7 +68,7 @@ void MainGUIWindow::_init()
marker = new Marker(1 * FROM_METERS_TO_UNITS, 1 * FROM_METERS_TO_UNITS);
// marker->setPos(0,0);
setPosMarker(0, 0);
setPosMarker(1, 1);
// scene->addItem(marker);
ui->graphicsView->setScene(scene);
......
......@@ -5,7 +5,7 @@
Marker::Marker(qreal x, qreal y, QGraphicsItem * parent)
: QGraphicsEllipseItem(parent)
: QGraphicsEllipseItem(-MARKER_DIAMETER/2, - MARKER_DIAMETER/2, MARKER_DIAMETER, MARKER_DIAMETER, parent)
{
_highlighted = false;
_highlight_diameter = HIGHLIGHT_DIAMETER;
......@@ -15,9 +15,10 @@ Marker::Marker(qreal x, qreal y, QGraphicsItem * parent)
_center_y = y;
_diameter = MARKER_DIAMETER; // x and y are top left coordinates
_x = _center_x - _diameter/2;
_y = _center_y - _diameter/2;
this->setRect(QRectF(_x, _y, _diameter, _diameter));
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;
this->setPen(Qt::NoPen);
this->setBrush(QColor(255, 0, 0));
this->setZValue(10); // max z value, should always be seen
......@@ -26,37 +27,21 @@ Marker::Marker(qreal x, qreal y, QGraphicsItem * parent)
void Marker::setPosMarker(QPointF new_p)
{
prepareGeometryChange();
this->setPos(_center_x, _center_y);
_center_x = new_p.x(); // update center coordinates
_center_y = new_p.y();
_x = _center_x - _diameter/2;
_y = _center_y - _diameter/2;
// this->setPos(_x, _y); //update top-left corner coordinates
this->setRect(QRectF(_x, _y, _diameter, _diameter));
if(_highlighted)
{
_x_highlight = _center_x - _highlight_diameter/2; // update top-left corner coordinates of highlighing circle
_y_highlight = _center_y -_highlight_diameter/2;
// _highlight_circle->setPos(_x_highlight, _y_highlight);
_highlight_circle->setRect(QRectF(_x_highlight, _y_highlight, _highlight_diameter, _highlight_diameter));
}
}
void Marker::setHighlighted(void)
{
if(!_highlighted)
{
_x_highlight = _center_x - _highlight_diameter/2;
_y_highlight = _center_y -_highlight_diameter/2;
prepareGeometryChange();
_highlight_circle = new QGraphicsEllipseItem();
_highlight_circle->setRect(QRectF(_x_highlight, _y_highlight, _highlight_diameter, _highlight_diameter));
_highlight_circle = new QGraphicsEllipseItem(QRectF(-_highlight_diameter/2, -_highlight_diameter/2, _highlight_diameter, _highlight_diameter), this);
_highlight_circle->setPos(0, 0);
_highlight_circle->setPen(QPen(QBrush(Qt::black), HIGHLIGHT_WIDTH));
_highlight_circle->setParentItem(this);
// _highlight_circle->setFlag(QGraphicsItem::ItemIgnoresTransformations);
_highlight_circle->setFlag(QGraphicsItem::ItemIgnoresTransformations);
_highlighted = true;
}
}
......@@ -82,6 +67,3 @@ Marker::~Marker()
{
clearHighlighted();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment