-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobotgraphicsitem.cpp
55 lines (40 loc) · 1.68 KB
/
robotgraphicsitem.cpp
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
#include "robotgraphicsitem.h"
#include <QDebug>
#include "robotpropswidget.h"
RobotGraphicsItem::RobotGraphicsItem(RobotPropsWidget *widget)
: QGraphicsSvgItem(":/svg/cortex.svg")
, m_props(widget)
{
setFlag(QGraphicsItem::ItemIsMovable);
setFlag(QGraphicsItem::ItemIsSelectable);
setFlag(QGraphicsItem::ItemSendsGeometryChanges);
// as opacity is changed in paint(), we filter the related event
// setFlag(QGraphicsItem::ItemOpacityChange, false);
// setFlag(QGraphicsItem::ItemOpacityHasChanged, false);
setTransformOriginPoint(boundingRect().width() / 2, boundingRect().height() / 2);
}
RobotGraphicsItem::~RobotGraphicsItem()
{
}
void RobotGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QGraphicsSvgItem::paint(painter, option, widget);
// setOpacity(isSelected() ? 1.0 : 0.3);
}
void RobotGraphicsItem::setPos(const QPointF &pos)
{
QPointF itemAbsPos = QPointF(pos.x() - round(boundingRect().width() / 2),
pos.y() - round(boundingRect().height() / 2));
itemAbsPos.setY(2000 + itemAbsPos.y());
QGraphicsItem::setPos(itemAbsPos);
}
QVariant RobotGraphicsItem::itemChange(GraphicsItemChange change, const QVariant &value)
{
if (change == ItemPositionHasChanged || change == ItemRotationHasChanged) {
QPointF itemAbsPos = QPointF(pos().x() + round(boundingRect().width() / 2),
pos().y() + round(boundingRect().height() / 2));
itemAbsPos.setY(2000 - itemAbsPos.y());
m_props->robotMoved(itemAbsPos.x(), itemAbsPos.y(), -rotation() + 90);
}
return QGraphicsItem::itemChange(change, value);
}