-
Notifications
You must be signed in to change notification settings - Fork 0
/
lineitem.cpp
109 lines (91 loc) · 2.52 KB
/
lineitem.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
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
#include "lineitem.h"
#include <QPen>
LineItem::LineItem(QGraphicsItem *parent) :
QGraphicsLineItem(parent),
m_outlineWidth(1),
m_outlineColor(Qt::red),
m_typeLigne(TL_NONE)
{
setAcceptHoverEvents(true);
}
qreal LineItem::outlineWidth() const
{
return m_outlineWidth;
}
void LineItem::setOutlineWidth(qreal outlineWidth)
{
m_outlineWidth = outlineWidth;
}
QColor LineItem::outlineColor() const
{
return m_outlineColor;
}
void LineItem::setOutlineColor(const QColor &outlineColor)
{
m_outlineColor = outlineColor;
}
TypeLigne LineItem::typeLigne() const
{
return m_typeLigne;
}
void LineItem::setTypeLigne(const TypeLigne t)
{
m_typeLigne = t;
}
void LineItem::setCustomPen() {
QPen p = QPen(m_outlineColor, m_outlineWidth);
QVector<qreal> dashes;
switch (m_typeLigne) {
case TL_LIE_V: {
dashes << 8 << 2 << 1 << 2;
p.setStyle(Qt::CustomDashLine);
p.setDashPattern(dashes);
break;
}
case TL_LIE_M: {
dashes << 8 << 8;
p.setStyle(Qt::CustomDashLine);
p.setDashPattern(dashes);
break;
}
default: p.setStyle(Qt::SolidLine);
}
setPen(p);
}
void LineItem::hoverEnterEvent(QGraphicsSceneHoverEvent *)
{
int a = data(1).toInt();
int b = data(2).toInt();
PieceItem * ti = static_cast<PieceItem*>(parentItem());
if (!ti->donnees->flash)
return;
QPointF p1, p2;
p1 = line().center() + parentItem()->pos();
for (auto&& it : scene()->items()) {
if ((it->data(1).toInt() == b) && (it->data(2).toInt() == a)) {
QGraphicsLineItem* l2 = static_cast<QGraphicsLineItem*>(it);
p2 = l2->line().center() + l2->parentItem()->pos();
ti->donnees->flash->setLine(QLineF(p1, p2));
ti->donnees->flash->setVisible(true);
break;
}
}
setPen(QPen(Qt::yellow, 2));
}
void LineItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
{
setCustomPen();
PieceItem * ti = static_cast<PieceItem*>(parentItem());
if (ti->donnees->flash)
ti->donnees->flash->setVisible(false);
}
void LineItem::mousePressEvent(QGraphicsSceneMouseEvent *)
{
//qDebug() << "Custom item clicked.";
PieceItem * ti = static_cast<PieceItem*>(parentItem());
int type = data(0).toInt();
int a = data(1).toInt();
int b = data(2).toInt();
//qInfo("LINE ACTION : %d %d %d", type, a, b);
type == -1 ? ti->donnees->splitPiece(a, b) : ti->donnees->stickPiece(a, b);
}