61 void DrawMapScene::mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent) |
62 void DrawMapScene::mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent) |
62 { |
63 { |
63 if(m_currPath && (mouseEvent->buttons() & Qt::LeftButton)) |
64 if(m_currPath && (mouseEvent->buttons() & Qt::LeftButton)) |
64 { |
65 { |
65 QPainterPath path = m_currPath->path(); |
66 QPainterPath path = m_currPath->path(); |
|
67 QPointF currentPos = mouseEvent->scenePos(); |
|
68 |
|
69 if(mouseEvent->modifiers() & Qt::ControlModifier) |
|
70 currentPos = putSomeConstraints(paths.first().initialPoint, currentPos); |
66 |
71 |
67 switch (m_pathType) |
72 switch (m_pathType) |
68 { |
73 { |
69 case Polyline: |
74 case Polyline: |
70 if(mouseEvent->modifiers() & Qt::ControlModifier) |
75 if(mouseEvent->modifiers() & Qt::ControlModifier) |
71 { |
76 { |
72 int c = path.elementCount(); |
77 int c = path.elementCount(); |
73 QPointF pos = mouseEvent->scenePos(); |
78 path.setElementPositionAt(c - 1, currentPos.x(), currentPos.y()); |
74 path.setElementPositionAt(c - 1, pos.x(), pos.y()); |
|
75 |
79 |
76 } |
80 } |
77 else |
81 else |
78 { |
82 { |
79 path.lineTo(mouseEvent->scenePos()); |
83 path.lineTo(currentPos); |
80 paths.first().points.append(mouseEvent->scenePos().toPoint()); |
84 paths.first().points.append(mouseEvent->scenePos().toPoint()); |
81 } |
85 } |
82 break; |
86 break; |
83 case Rectangle: { |
87 case Rectangle: { |
84 path = QPainterPath(); |
88 path = QPainterPath(); |
85 QPointF p1 = paths.first().initialPoint; |
89 QPointF p1 = paths.first().initialPoint; |
86 QPointF p2 = mouseEvent->scenePos(); |
90 QPointF p2 = currentPos; |
87 path.moveTo(p1); |
91 path.moveTo(p1); |
88 path.lineTo(p1.x(), p2.y()); |
92 path.lineTo(p1.x(), p2.y()); |
89 path.lineTo(p2); |
93 path.lineTo(p2); |
90 path.lineTo(p2.x(), p1.y()); |
94 path.lineTo(p2.x(), p1.y()); |
91 path.lineTo(p1); |
95 path.lineTo(p1); |
92 break; |
96 break; |
93 } |
97 } |
94 case Ellipse: { |
98 case Ellipse: { |
95 path = QPainterPath(); |
99 path = QPainterPath(); |
96 QList<QPointF> points = makeEllipse(paths.first().initialPoint, mouseEvent->scenePos()); |
100 QList<QPointF> points = makeEllipse(paths.first().initialPoint, currentPos); |
97 path.addPolygon(QPolygonF(QVector<QPointF>::fromList(points))); |
101 path.addPolygon(QPolygonF(QVector<QPointF>::fromList(points))); |
98 break; |
102 break; |
99 } |
103 } |
100 } |
104 } |
101 |
105 |
132 |
136 |
133 void DrawMapScene::mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent) |
137 void DrawMapScene::mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent) |
134 { |
138 { |
135 if (m_currPath) |
139 if (m_currPath) |
136 { |
140 { |
|
141 QPointF currentPos = mouseEvent->scenePos(); |
|
142 |
|
143 if(mouseEvent->modifiers() & Qt::ControlModifier) |
|
144 currentPos = putSomeConstraints(paths.first().initialPoint, currentPos); |
|
145 |
137 switch (m_pathType) |
146 switch (m_pathType) |
138 { |
147 { |
139 case Polyline: { |
148 case Polyline: { |
140 QPainterPath path = m_currPath->path(); |
149 QPainterPath path = m_currPath->path(); |
141 path.lineTo(mouseEvent->scenePos()); |
150 path.lineTo(mouseEvent->scenePos()); |
142 paths.first().points.append(mouseEvent->scenePos().toPoint()); |
151 paths.first().points.append(currentPos.toPoint()); |
143 m_currPath->setPath(path); |
152 m_currPath->setPath(path); |
144 simplifyLast(); |
153 simplifyLast(); |
145 break; |
154 break; |
146 } |
155 } |
147 case Rectangle: { |
156 case Rectangle: { |
148 QPoint p1 = paths.first().initialPoint; |
157 QPoint p1 = paths.first().initialPoint; |
149 QPoint p2 = mouseEvent->scenePos().toPoint(); |
158 QPoint p2 = currentPos.toPoint(); |
150 QList<QPoint> rpoints; |
159 QList<QPoint> rpoints; |
151 rpoints << p1 << QPoint(p1.x(), p2.y()) << p2 << QPoint(p2.x(), p1.y()) << p1; |
160 rpoints << p1 << QPoint(p1.x(), p2.y()) << p2 << QPoint(p2.x(), p1.y()) << p1; |
152 paths.first().points = rpoints; |
161 paths.first().points = rpoints; |
153 break; |
162 break; |
154 } |
163 } |
155 case Ellipse: |
164 case Ellipse: |
156 QPoint p1 = paths.first().initialPoint; |
165 QPoint p1 = paths.first().initialPoint; |
157 QPoint p2 = mouseEvent->scenePos().toPoint(); |
166 QPoint p2 = currentPos.toPoint(); |
158 QList<QPointF> points = makeEllipse(p1, p2); |
167 QList<QPointF> points = makeEllipse(p1, p2); |
159 QList<QPoint> epoints; |
168 QList<QPoint> epoints; |
160 foreach(const QPointF & p, points) |
169 foreach(const QPointF & p, points) |
161 epoints.append(p.toPoint()); |
170 epoints.append(p.toPoint()); |
162 paths.first().points = epoints; |
171 paths.first().points = epoints; |