-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexocontrolpoint.cpp
More file actions
133 lines (109 loc) · 3.31 KB
/
exocontrolpoint.cpp
File metadata and controls
133 lines (109 loc) · 3.31 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "exocontrolpoint.h"
EXO_ControlPoint::EXO_ControlPoint(QGraphicsItem *parent) : QGraphicsRectItem(parent),
mouseDownX(0),
mouseDownY(0),
_outterborderColor(Qt::black),
_outterborderPen(),
_width(6),
_height(6),
_mouseButtonState(kMouseReleased)
{
setParentItem(parent);
_outterborderPen.setWidth(2);
_outterborderPen.setColor(_outterborderColor);
this->setAcceptHoverEvents(true);
}
EXO_ControlPoint::EXO_ControlPoint(const EXO_ControlPoint &P)
{
mouseDownX= P.mouseDownX;
mouseDownY = P.mouseDownY;
_outterborderColor = P._outterborderColor;
_outterborderPen = P._outterborderPen;
_width = P._width;
_height = P._height;
setMouseState(P.getMouseState());
_outterborderPen.setWidth(2);
_outterborderPen.setColor(_outterborderColor);
setAcceptHoverEvents(true);
}
EXO_ControlPoint &EXO_ControlPoint :: operator=(const EXO_ControlPoint& P)
{
if (this != &P)
{
this->mouseDownX= P.mouseDownX;
this->mouseDownY = P.mouseDownY;
this->_outterborderColor = P._outterborderColor;
this->_outterborderPen = P._outterborderPen;
this->_width = P._width;
this->_height = P._height;
this->setMouseState(P.getMouseState());
this->_outterborderPen.setWidth(2);
this->_outterborderPen.setColor(_outterborderColor);
this->setAcceptHoverEvents(true);
}
return *this;
}
int EXO_ControlPoint::getCorner()
{
return 0;
}
void EXO_ControlPoint::setMouseState(int state)
{
_mouseButtonState = state;
}
int EXO_ControlPoint::getMouseState() const
{
return _mouseButtonState;
}
// we have to implement the mouse events to keep the linker happy,
// but just set accepted to false since are not actually handling them
void EXO_ControlPoint::mouseMoveEvent(QGraphicsSceneDragDropEvent *event)
{
event->setAccepted(false);
}
void EXO_ControlPoint::mousePressEvent(QGraphicsSceneDragDropEvent *event)
{
event->setAccepted(false);
}
void EXO_ControlPoint::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
{
event->setAccepted(true);
}
void EXO_ControlPoint::mousePressEvent ( QGraphicsSceneMouseEvent * event )
{
event->setAccepted(false);
}
void EXO_ControlPoint::mouseMoveEvent ( QGraphicsSceneMouseEvent * event )
{
event->setAccepted(false);
}
// change the color on hover events to indicate to the use the object has
// been captured by the mouse
void EXO_ControlPoint::hoverLeaveEvent ( QGraphicsSceneHoverEvent * )
{
_outterborderColor = Qt::black;
this->update(0,0,_width,_height);
}
void EXO_ControlPoint::hoverEnterEvent ( QGraphicsSceneHoverEvent * )
{
_outterborderColor = Qt::red;
this->update(0,0,_width,_height);
qDebug()<<"Rojooo";
}
QRectF EXO_ControlPoint::boundingRect() const
{
return QRectF(0,0,_width,_height);
}
void EXO_ControlPoint::paint (QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
// fill the box with solid color, use sharp corners
_outterborderPen.setCapStyle(Qt::SquareCap);
_outterborderPen.setStyle(Qt::SolidLine);
painter->setPen(_outterborderPen);
QPointF topLeft (0, 0);
QPointF bottomRight ( _width, _height);
QRectF rect (topLeft, bottomRight);
QBrush brush (Qt::SolidPattern);
brush.setColor (_outterborderColor);
painter->fillRect(rect,brush);
}