-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjunction.cpp
More file actions
51 lines (41 loc) · 1.46 KB
/
junction.cpp
File metadata and controls
51 lines (41 loc) · 1.46 KB
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
#include "junction.h"
Junction::Junction(QGraphicsObject *parent) :
QGraphicsObject(parent){
}
void Junction::setStations(QList<Station*> station){
m_station = station;
for (int i = 0; i < station.size(); i++){
m_station[i]->setPos(this->pos().x(), this->pos().y() + 20 * i);
m_station[i]->updateLineItems();
}
}
QRectF Junction::boundingRect() const{
return QRectF (-10,-10,20, m_station.size() * 20);
}
void Junction::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
painter->save();
painter->setPen(QPen(Qt::black, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
painter->drawRoundRect(-10,-10, 20, m_station.size() * 20, 50, 50);
Q_UNUSED(option);
Q_UNUSED(widget);
painter->restore();
}
void Junction::mouseMoveEvent(QGraphicsSceneMouseEvent *event){
this->setPos(mapToScene(event->pos()));
for (int i = 0; i < m_station.size(); i++){
QGraphicsSceneMouseEvent *tempEvent = event;
QPointF pointEvent;
pointEvent.setX(event->pos().x());
pointEvent.setY(event->pos().y());
tempEvent->setPos(pointEvent);
m_station[i]->mouseMoveEvent(tempEvent);
}
}
void Junction::mousePressEvent(QGraphicsSceneMouseEvent *event){
this->setCursor(QCursor(Qt::ClosedHandCursor));
Q_UNUSED(event);
}
void Junction::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){
this->setCursor(QCursor(Qt::ArrowCursor));
Q_UNUSED(event);
}