-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtriangleitem3d.cpp
88 lines (80 loc) · 2.74 KB
/
triangleitem3d.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
// QGraphicsPolygonItem pour item Triangle de la vue 3D
//---------------------------------------------------------
#include "triangleitem3d.h"
//---------------------------------------------------------
TriangleItem3d::TriangleItem3d () {
pieceCouleur = QColor();
id = -1;
col = -1;
sceneD = nullptr;
}
TriangleItem3d::TriangleItem3d (DepliageScene *scene, QColor pieceCouleur, QPolygonF poly, int id, int col = 0) {
this->pieceCouleur = pieceCouleur;
this->sceneD = scene;
this->id = id;
setData(0, QVariant(id));
this->col = col;
this->hoverOn = false;
setPolygon(poly);
setFlag(ItemIsSelectable);
setCursor(Qt::PointingHandCursor);
setAcceptHoverEvents(true);
scene->addItem(this);
}
void TriangleItem3d::paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
QStyleOptionGraphicsItem opt = *option;
if (isSelected())
opt.state = QStyle::State_None;
QPen p = QPen();
p.setWidth(1);
setPen(p);
setBrush(QBrush(this->hoverOn ? this->pieceCouleur.darker() : this->pieceCouleur, Qt::SolidPattern));
QGraphicsPolygonItem::paint(painter, &opt, widget);
}
void TriangleItem3d::editeTriangle () {
bool ok = false;
if (sceneD->itemColorId >= 0) {
if (col != sceneD->itemColorId) {
emit sceneD->peutColorierFace(this->id);
} else {
emit sceneD->pieceEnleveFace(this->id);
}
sceneD->update(boundingRect());
}
}
void TriangleItem3d::mousePressEvent (QGraphicsSceneMouseEvent *event) {
if (event->button() == Qt::LeftButton) {
editeTriangle();
} else if (event->button() == Qt::RightButton) {
emit sceneD->changeCouleur(col);
}
//QGraphicsPolygonItem::mousePressEvent(event);
}
void TriangleItem3d::hoverEnterEvent(QGraphicsSceneHoverEvent *event) {
if (sceneD->gereHover) {
this->hoverOn = true;
if (sceneD->faceCourante != this->id) {
sceneD->dernFace = sceneD->faceCourante;
sceneD->faceCourante = this->id;
}
if (sceneD->triangleHover) {
TriangleItem3d *t = qgraphicsitem_cast<TriangleItem3d*>(sceneD->triangleHover);
if (t) {
t->hoverOn = false;
t->update();
}
}
sceneD->triangleHover = this;
if (this->col > 0)
emit sceneD->facetteHoverOn(this->id);
update();
}
}
void TriangleItem3d::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) {
if (sceneD->gereHover) {
this->hoverOn = false;
update();
sceneD->triangleHover = nullptr;
emit sceneD->facetteHoverOff(this->id);
}
}