-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathm.cpp
78 lines (63 loc) · 1.78 KB
/
m.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
#include "m.h"
#include <QtWidgets>
m::m(const QColor &color, int x, int y)
{
this->x = x;
this->y = y;
this->color = color;
setZValue((x + y) % 2);
setFlags(ItemIsSelectable | ItemIsMovable);
setAcceptHoverEvents(true);
}
QRectF m::boundingRect() const
{
//QRectF represents a rectangle
return QRectF(0, 0, 110, 70); //x,y,width,height
}
QPainterPath m::shape() const
{
QPainterPath path;
path.addRect(14, 14, 82, 42);
return path;
}
void m::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(widget);
QColor fillColor = (option->state & QStyle::State_Selected) ? color.dark(150) : color;
if (option->state & QStyle::State_MouseOver)
fillColor = fillColor.light(125);
QPen oldPen = painter->pen();
QPen pen = oldPen;
int width = 0;
if (option->state & QStyle::State_Selected)
width += 2;
pen.setWidth(width);
QBrush b = painter->brush();
painter->setBrush(QBrush(fillColor.dark(option->state & QStyle::State_Sunken ? 120 : 100)));
//painter->drawRect(QRect(14, 14, 79, 39));
painter->setBrush(b);
painter->setPen(QPen(Qt::black, 3));
painter->drawLine(0, 0, 0, 50);
painter->drawLine(0, 50, 50, 0);
painter->drawLine(50, 50, 50, 0);
painter->setPen(QPen(Qt::black, 0));
}
void m::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem::mousePressEvent(event);
update();
}
void m::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (event->modifiers() & Qt::ShiftModifier) {
stuff << event->pos();
update();
return;
}
QGraphicsItem::mouseMoveEvent(event);
}
void m::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem::mouseReleaseEvent(event);
update();
}