-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoccupancygraphicsitem.cpp
37 lines (33 loc) · 1.12 KB
/
occupancygraphicsitem.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
#include "occupancygraphicsitem.h"
#include <QDebug>
#include <QGraphicsSceneHoverEvent>
#include "Graphics.h"
#include "constants.h"
OccupancyGraphicsItem::OccupancyGraphicsItem(QPoint coordinate, QRect rect, qint32 occupancy, QGraphicsItem* parent) :
QGraphicsRectItem(rect.x(), rect.y(), rect.width(), rect.height(), parent)
{
this->setAcceptedMouseButtons(Qt::LeftButton);
this->setAcceptHoverEvents(true);
this->coordinate = coordinate;
this->occupancy = occupancy;
int val = 255-occupancy*2.55;
QBrush varBrush(QColor(val, val, val));
this->setBrush(varBrush);
this->setPen(PEN_CLEAR);
}
void OccupancyGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem::mousePressEvent(event);
if (this->occupancy <= OCCUPANCY_THRESHOLD) {
emit clicked(this->coordinate);
}
}
void OccupancyGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem::mouseReleaseEvent(event);
}
void OccupancyGraphicsItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
QGraphicsItem::hoverEnterEvent(event);
emit hovered(this->coordinate);
}