-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphicssectoritem.cpp
120 lines (105 loc) · 3.93 KB
/
graphicssectoritem.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
110
111
112
113
114
115
116
117
118
119
120
#include "graphicssectoritem.h"
#include <QCursor>
GraphicsSectorItem::GraphicsSectorItem(QObject *parent) : QObject(parent) {
this->setAcceptHoverEvents(true);
//this->setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
//this->setFlag(QGraphicsPathItem::ItemIsSelectable, true);
this->setCursor(QCursor(Qt::PointingHandCursor));
this->Status = GraphicsSectorItem::SS_Undefined;
this->Track = 0;
this->Sector = 0xFF;
this->setPen(GraphicsSectorItem::statusToPen());
this->setBrush(GraphicsSectorItem::statusToBrush());
}
QPainterPath GraphicsSectorItem::path() const {
return QGraphicsPathItem::path();
}
void GraphicsSectorItem::setPath(QPainterPath &path) {
QGraphicsPathItem::setPath(path);
}
void GraphicsSectorItem::setStatus(GraphicsSectorItem::SectorStatus status) {
this->Status = status;
this->setPen(GraphicsSectorItem::statusToPen(status));
this->setBrush(GraphicsSectorItem::statusToBrush(status));
}
GraphicsSectorItem::SectorStatus GraphicsSectorItem::status() {
return this->Status;
}
void GraphicsSectorItem::setId(QString id) {
this->Id = id;
}
QString GraphicsSectorItem::id() const {
return this->Id;
}
void GraphicsSectorItem::setTrack(int id) {
this->Track = id;
}
int GraphicsSectorItem::track() {
return this->Track;
}
void GraphicsSectorItem::setSector(int id) {
this->Sector = id;
}
int GraphicsSectorItem::sector() {
return this->Sector;
}
QPen GraphicsSectorItem::statusToPen(SectorStatus status, bool selected) {
Q_UNUSED(status);
Q_UNUSED(selected);
qreal width = 0.25;
//if (selected) width = 0.5;
return QPen(Qt::black, width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
}
QBrush GraphicsSectorItem::statusToBrush(SectorStatus status, bool selected) {
Q_UNUSED(status);
switch (status) {
case GraphicsSectorItem::SS_Free:
if (selected) return QBrush(QColor(0, 153, 145));
return QBrush(QColor(37, 180, 177));
case GraphicsSectorItem::SS_Used:
if (selected) return QBrush(QColor(229, 0, 81));
return QBrush(QColor(236, 103, 122));
case GraphicsSectorItem::SS_ReservedUsed:
if (selected) return QBrush(QColor(234, 91, 12));
return QBrush(QColor(242, 141, 79));
case GraphicsSectorItem::SS_ReservedFree:
if (selected) return QBrush(QColor(0, 105, 180));
return QBrush(QColor(72, 140, 203));
case GraphicsSectorItem::SS_Undefined:
default:
return QBrush();
}
return QBrush();
}
bool GraphicsSectorItem::sceneEvent(QEvent *ev) {
if (ev->type() == QEvent::GraphicsSceneHoverEnter) {
//qDebug() << ev->type() << this->id();
this->setPen(GraphicsSectorItem::statusToPen(this->status(), true));
this->setBrush(GraphicsSectorItem::statusToBrush(this->status(), true));
emit onMouseEnterSector(this->id(), this->status(), this->track(), this->sector());
return true;
} else if (ev->type() == QEvent::GraphicsSceneHoverLeave) {
//qDebug() << ev->type() << this->id();
this->setPen(GraphicsSectorItem::statusToPen(this->status(), false));
this->setBrush(GraphicsSectorItem::statusToBrush(this->status(), false));
emit onMouseLeaveSector(this->id(), this->status(), this->track(), this->sector());
return true;
}
return QGraphicsPathItem::sceneEvent(ev);
}
QString GraphicsSectorItem::sectorStatusToString(GraphicsSectorItem::SectorStatus status) {
switch (status) {
case GraphicsSectorItem::SS_Free:
return "free";
case GraphicsSectorItem::SS_Used:
return "used";
case GraphicsSectorItem::SS_ReservedFree:
return "reserved free";
case GraphicsSectorItem::SS_ReservedUsed:
return "reserved used";
default:
case GraphicsSectorItem::SS_Undefined:
return "Undefined";
}
return "Undefined";
}