-
Notifications
You must be signed in to change notification settings - Fork 0
/
triangleitem.cpp
44 lines (40 loc) · 1.18 KB
/
triangleitem.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
#include "triangleitem.h"
#include "depliage.h"
#include <QTableWidget>
#include <QPainter>
TriangleItem::TriangleItem(MainWindow *window, QPolygonF poly, int id, int col = 0)
{
//w = qobject_cast<MainWindow*>(window);
w = window;
this->id = id;
setData(0, QVariant(id));
this->col = col;
setPolygon(poly);
setPen(QPen(Qt::black));
QColor c = Qt::white;
setBrush(QBrush(c, Qt::SolidPattern));
setFlag(ItemIsSelectable);
setFlag(ItemIsFocusable);
}
void TriangleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
QStyleOptionGraphicsItem opt = *option;
if (isSelected()) {
setPen(QPen(Qt::yellow));
setBrush(QBrush(Qt::red));
opt.state = QStyle::State_None;
} else {
setPen(QPen(Qt::black));
QColor c = this->col < w->dep->pool.size()
? w->dep->pool[this->col].couleur
: Qt::white;
c.setAlpha(235);
setBrush(QBrush(c, Qt::SolidPattern));
}
QGraphicsPolygonItem::paint(painter, &opt, widget);
}
int TriangleItem::type()
{
return Type;
}