50 setBackgroundBrush(m_eraser); |
50 setBackgroundBrush(m_eraser); |
51 m_isErasing = false; |
51 m_isErasing = false; |
52 |
52 |
53 m_pathType = Polyline; |
53 m_pathType = Polyline; |
54 |
54 |
55 m_pen.setWidth(76); |
55 m_pen.setWidth(DRAWN_MAP_BRUSH_SIZE_START); |
56 m_pen.setJoinStyle(Qt::RoundJoin); |
56 m_pen.setJoinStyle(Qt::RoundJoin); |
57 m_pen.setCapStyle(Qt::RoundCap); |
57 m_pen.setCapStyle(Qt::RoundCap); |
58 m_currPath = 0; |
58 m_currPath = 0; |
59 |
59 |
60 m_isCursorShown = false; |
60 m_isCursorShown = false; |
61 QPen cursorPen = QPen(DRAWN_MAP_COLOR_CURSOR_PEN); |
61 QPen cursorPen = QPen(DRAWN_MAP_COLOR_CURSOR_PEN); |
62 cursorPen.setJoinStyle(Qt::RoundJoin); |
62 cursorPen.setJoinStyle(Qt::RoundJoin); |
63 cursorPen.setCapStyle(Qt::RoundCap); |
63 cursorPen.setCapStyle(Qt::RoundCap); |
64 cursorPen.setWidth(m_pen.width()); |
64 cursorPen.setWidth(brushSize()); |
65 m_cursor->setPen(cursorPen); |
65 m_cursor->setPen(cursorPen); |
66 m_cursor->setZValue(1); |
66 m_cursor->setZValue(1); |
67 } |
67 } |
68 |
68 |
69 void DrawMapScene::mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent) |
69 void DrawMapScene::mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent) |
129 p += QPointF(0.01, 0.01); |
129 p += QPointF(0.01, 0.01); |
130 path.moveTo(p); |
130 path.moveTo(p); |
131 path.lineTo(mouseEvent->scenePos()); |
131 path.lineTo(mouseEvent->scenePos()); |
132 |
132 |
133 PathParams params; |
133 PathParams params; |
134 params.width = serializePenWidth(m_pen.width()); |
134 params.width = serializePenWidth(brushSize()); |
135 params.erasing = m_isErasing; |
135 params.erasing = m_isErasing; |
136 params.initialPoint = mouseEvent->scenePos().toPoint(); |
136 params.initialPoint = mouseEvent->scenePos().toPoint(); |
137 params.points = QList<QPoint>() << params.initialPoint; |
137 params.points = QList<QPoint>() << params.initialPoint; |
138 paths.prepend(params); |
138 paths.prepend(params); |
139 m_currPath->setPath(path); |
139 m_currPath->setPath(path); |
183 |
183 |
184 emit pathChanged(); |
184 emit pathChanged(); |
185 } |
185 } |
186 } |
186 } |
187 |
187 |
188 void DrawMapScene::wheelEvent(QGraphicsSceneWheelEvent * wheelEvent) |
188 void DrawMapScene::setBrushSize(int newBrushSize) |
189 { |
189 { |
190 if(wheelEvent->delta() > 0 && m_pen.width() < 516) |
190 if(newBrushSize > DRAWN_MAP_BRUSH_SIZE_MAX) |
191 m_pen.setWidth(m_pen.width() + 10); |
191 newBrushSize = DRAWN_MAP_BRUSH_SIZE_MAX; |
192 else if(wheelEvent->delta() < 0 && m_pen.width() >= 16) |
192 if(newBrushSize < DRAWN_MAP_BRUSH_SIZE_MIN) |
193 m_pen.setWidth(m_pen.width() - 10); |
193 newBrushSize = DRAWN_MAP_BRUSH_SIZE_MIN; |
194 |
194 |
|
195 m_pen.setWidth(newBrushSize); |
195 QPen cursorPen = m_cursor->pen(); |
196 QPen cursorPen = m_cursor->pen(); |
196 cursorPen.setWidth(m_pen.width()); |
197 cursorPen.setWidth(m_pen.width()); |
197 m_cursor->setPen(cursorPen); |
198 m_cursor->setPen(cursorPen); |
198 |
|
199 if(m_currPath) |
199 if(m_currPath) |
200 { |
200 { |
201 m_currPath->setPen(m_pen); |
201 m_currPath->setPen(m_pen); |
202 paths.first().width = serializePenWidth(m_pen.width()); |
202 paths.first().width = serializePenWidth(m_pen.width()); |
203 } |
203 } |
|
204 |
|
205 emit brushSizeChanged(newBrushSize); |
|
206 } |
|
207 |
|
208 int DrawMapScene::brushSize() |
|
209 { |
|
210 return m_pen.width(); |
|
211 } |
|
212 |
|
213 void DrawMapScene::wheelEvent(QGraphicsSceneWheelEvent * wheelEvent) |
|
214 { |
|
215 int b = brushSize(); |
|
216 if(wheelEvent->delta() > 0) |
|
217 setBrushSize(b + DRAWN_MAP_BRUSH_SIZE_STEP); |
|
218 else if(wheelEvent->delta() < 0 && b >= DRAWN_MAP_BRUSH_SIZE_MIN) |
|
219 setBrushSize(b - DRAWN_MAP_BRUSH_SIZE_STEP); |
204 } |
220 } |
205 |
221 |
206 void DrawMapScene::showCursor() |
222 void DrawMapScene::showCursor() |
207 { |
223 { |
208 if(!m_isCursorShown) |
224 if(!m_isCursorShown) |