forked from ppikula/quadtri
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPolyDot.cpp
82 lines (69 loc) · 1.83 KB
/
PolyDot.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
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
#include <QtGui>
#include "PolyDot.h"
PolyDot::PolyDot():QGraphicsItem(),dispRect(false),dispLabel(true)
{
setAcceptedMouseButtons(Qt::LeftButton);
setAcceptHoverEvents(true);
acceptHoverEvents();
}
QPointF PolyDot::center(){
return QPointF(pos().x() - boundingRect().width()/2,pos().y() -boundingRect().height()/2);
}
QRectF PolyDot::boundingRect() const
{
return QRectF(-20, -20, 20, 20);
}
QRectF PolyDot::markerRect() const
{
return QRectF(-20, -20, 20, 20);
}
void PolyDot::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
painter->setPen(Qt::white);
painter->drawEllipse(-12,-12,5,5);
if(dispRect){
painter->setPen(Qt::white);
painter->setBrush(Qt::NoBrush);
painter->drawRect(markerRect());
}
if(dispLabel){
QString label;
QString y;
label.setNum(center().x());
label += ",";
y.setNum(center().y());
label += y;
painter->drawText(QPointF(0,0),label);
}
}
void PolyDot::mousePressEvent(QGraphicsSceneMouseEvent *)
{
setCursor(Qt::ClosedHandCursor);
}
void PolyDot::mouseMoveEvent(QGraphicsSceneMouseEvent *event){
setPos(this->pos() +event->pos());
scene()->update();
emit dotMoved();
}
void PolyDot::mouseReleaseEvent(QGraphicsSceneMouseEvent *){
setCursor(Qt::OpenHandCursor);
scene()->update();
emit dotMoved();
}
void PolyDot::hoverEnterEvent(QGraphicsSceneHoverEvent *event){
Q_UNUSED(event)
setCursor(Qt::OpenHandCursor);
dispRect=true;
scene()->update();
}
void PolyDot::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){
Q_UNUSED(event)
dispRect=false;
scene()->update();
}
void PolyDot::hoverMoveEvent(QGraphicsSceneHoverEvent *event){
Q_UNUSED(event)
scene()->update();
}