-
Notifications
You must be signed in to change notification settings - Fork 1
/
cornergrabber.cpp
67 lines (54 loc) · 1.38 KB
/
cornergrabber.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
#include "cornergrabber.h"
CornerGrabber::CornerGrabber(QGraphicsItem *parent) :
QGraphicsItem(parent),
_outterborderColor(Qt::green),
_outterborderPen(),
_width(10),
_height(10),
_is_active(false)
{
setParentItem(parent);
_outterborderPen.setWidth(2);
_outterborderPen.setColor(_outterborderColor);
setAcceptHoverEvents(true);
}
qreal CornerGrabber::getHeight()
{
return _height;
}
qreal CornerGrabber::getWidth()
{
return _width;
}
bool CornerGrabber::isActive()
{
return _is_active;
}
void CornerGrabber::hoverLeaveEvent ( QGraphicsSceneHoverEvent * )
{
_outterborderColor = Qt::green;
_is_active = false;
update(0,0,_width,_height);
}
void CornerGrabber::hoverEnterEvent ( QGraphicsSceneHoverEvent * )
{
_outterborderColor = Qt::red;
_is_active = true;
update(0,0,_width,_height);
}
QRectF CornerGrabber::boundingRect() const
{
return QRectF(0,0,_width,_height);
}
void CornerGrabber::paint (QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
_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);
}