-
Notifications
You must be signed in to change notification settings - Fork 5
/
boundingrectitem.cpp
81 lines (71 loc) · 2.12 KB
/
boundingrectitem.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
#include "boundingrectitem.h"
BoundingRectItem::BoundingRectItem()
{
setFlag(QGraphicsItem::ItemIsMovable);
_transformMode = false;
_width = 0;
_height = 0;
setAcceptHoverEvents(true);
}
void BoundingRectItem::setPoints(QPointF min, QPointF max)
{
_boundingRect.setTopLeft(min);
_boundingRect.setBottomRight(max);
_width = max.x() - min.x();
_height = max.y() - min.y();
}
void BoundingRectItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
painter->setPen(QPen(Qt::gray, 1, Qt::DashLine));
if(_transformMode){
painter->setPen(QPen(Qt::black, 1, Qt::SolidLine));
}
painter->drawRect(_boundingRect);
QPointF topleft = _boundingRect.topLeft();
topleft -= QPointF(2,2);
QPointF bottomRight = _boundingRect.topLeft();
bottomRight += QPointF(2,2);
QRectF r(topleft,bottomRight);
painter->setPen(QPen(Qt::gray, 1, Qt::SolidLine));
if(_transformMode){
painter->setPen(QPen(Qt::black, 1, Qt::SolidLine));
}
painter->drawRect(r);
r.translate(_width/2,0);
painter->drawRect(r);
r.translate(_width/2 + 0.75,0);
painter->drawRect(r);
r.translate(0,_height/2);
painter->drawRect(r);
r.translate(0,_height/2 + 0.75);
painter->drawRect(r);
r.translate(-1 * _width/2,0);
painter->drawRect(r);
r.translate(-1 * _width/2 - 0.75,0);
painter->drawRect(r);
r.translate(0,-1 * _height/2 - 0.75);
painter->drawRect(r);
}
QRectF BoundingRectItem::boundingRect() const
{
return QRectF(_boundingRect.topLeft() - QPointF(5,5),
_boundingRect.bottomRight() + QPointF(5,5));
}
void BoundingRectItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
qDebug() << "hover entered";
}
void BoundingRectItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
qDebug() << "hover leaved";
}
void BoundingRectItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
qDebug() << "hover moved";
}
void BoundingRectItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
qDebug() << "pressed";
}