-
Notifications
You must be signed in to change notification settings - Fork 0
/
pathelement.h
148 lines (113 loc) · 5.11 KB
/
pathelement.h
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/***************************************************************************
* Copyright (c) 2014 Martin Llavallol <m5lmodelling@gmail.com> *
* *
* This file is part of Network Editor for SUMO. *
* *
* Network Editor for SUMO is free software: you can redistribute it *
* and/or modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version. *
* *
* Network Editor for SUMO is distributed in the hope that it will be *
* useful but WITHOUT ANY WARRANTY; without even the implied warranty *
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with Network Editor for SUMO. If not, see *
* <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef PATHELEMENT_H
#define PATHELEMENT_H
#include "model.h"
#include <QObject>
#include <QGraphicsPathItem>
#include <QItemSelectionModel>
#include <QModelIndex>
#include <QBasicTimer>
class PathElement : public QGraphicsPathItem, public QObject
{
public:
// Element type to adjust colour and pens accordingly
enum ElementType { Edge, EdgeNoShape, NormalLane, IntLane, PlainJunction, IntJunction, Connection };
// Constructor
PathElement(ElementType type, QString shape, Model *model, Item *item, QItemSelectionModel *selectionModel);
// Reimplementation of the shape method for more accurate selection
QPainterPath shape() const;
QPainterPath centerLine() const;
QRectF boundingRect() const;
// Index of the Item in the model (tree view)
QModelIndex modelIndex;
// Selection and deselection methods
void select();
void deselect();
bool isSelected() const;
// Changes an element property
void switchState(Model::ElementProperty prop, bool state);
// Highlights the whole element or point
void highlight();
void highlightPoint(int node);
// deletes the selected element
void deleteElement();
// MW: just for testing purposes
ElementType type;
// getter function for item
Item* getItem();
// Pointer to the model
Model *model;
protected:
// Calls a selection change in the Selection Model (to update the tree and properties view)
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
// Reimplemented paint method
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
// Timer event used when highlighting the element
void timerEvent(QTimerEvent *event);
// Context menu call
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
private:
// General properties
int r, g, b;
Qt::PenStyle style;
bool selected, fill, isWired, editable, showArrow;
int selectedNode;
qreal normalW, wireW, z;
qreal gripRadius;
// Element type
//ElementType type;
// Path nodes
QList <QPointF> nodes;
// Pointer to the model item this graphic item belongs to
Item* item;
// Pointer to the Selection Model, to call it when the item is clicked
QItemSelectionModel *selectionModel;
// Center path and border path
QPainterPath centerPath, borderPath, arrow;
// Calculates the paths from the current node positions
void calcPaths();
// Returns unit vector for two given points, used in the path calculations
QPointF unitVector(QPointF pA, QPointF pB, bool perpendicular) const;
// Parses a string with coordinates and fills in the list of nodes
void parseShape(QString shape);
// Point used in mouse movement events
QPointF lastPos;
// Updates the shape and length properties in XML domDocument after the nodes have been modified
void updateXML();
// Returns a string with the nodes' coordinates; used by updateXML()
QString shapePoints() const;
// Returns a string with the shape length; used by updateXML()
QString length() const;
// Context menu actions
void insertNode(QPointF I);
void deleteNode();
void copyID();
void copyFirstNode();
void copyLastNode();
void pasteFirstNode();
void pasteLastNode();
// Timer and properties used for highlighting
QBasicTimer timer;
int blink, blinkingNode;
};
#endif // PATHELEMENT_H