Repository navigation
Expand file tree
/
Copy pathcontrolpoint.cpp
More file actions
90 lines (64 loc) · 1.6 KB
/
Copy pathcontrolpoint.cpp
File metadata and controls
90 lines (64 loc) · 1.6 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "controlpoint.h"
#include <QPainter>
#include <QCursor>
#include <QGraphicsSceneMouseEvent>
#include <QDebug>
#include <cmath>
ControlPoint::ControlPoint(int id,float x , float y):id(id),m_x(x),m_y(y)
{
this->color = QColor("red");
setToolTip(QString("Point %0").arg(this->id));
setCursor(Qt::OpenHandCursor);
setAcceptedMouseButtons(Qt::LeftButton);
}
ControlPoint::ControlPoint(int id, QPointF &p):ControlPoint(id,p.x(),p.y())
{
}
ControlPoint::ControlPoint():ControlPoint(0,0,0)
{
}
QRectF ControlPoint::boundingRect() const
{
return QRectF(-5.5,-5.5, 11, 11);
}
void ControlPoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
painter->setPen(QPen(Qt::black, 1));
painter->setBrush(QBrush(color));
painter->drawEllipse(-5, -5, 10, 10);
}
void ControlPoint::setPos(const QPointF &pos)
{
// qDebug() << QString("Custom setpos");
QGraphicsItem::setPos(pos);
this->m_x = pos.x();
this->m_y = pos.y();
emit posChanged(id);
}
float ControlPoint::get_mx()
{
return m_x;
}
float ControlPoint::get_my()
{
return m_y;
}
void ControlPoint::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
setCursor(Qt::ClosedHandCursor);
moveable = true;
}
void ControlPoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *)
{
setCursor(Qt::OpenHandCursor);
}
void ControlPoint::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
this->setPos(event->scenePos());
}
QPointF operator *(float f, ControlPoint &v)
{
return QPointF( v.get_mx() * f, v.get_my() * f);
}