Changeset View
Changeset View
Standalone View
Standalone View
libs/basicflakes/tools/KoPencilTool.cpp
Show All 28 Lines | |||||
29 | #include <KoShapeManager.h> | 29 | #include <KoShapeManager.h> | ||
30 | #include <KoSelection.h> | 30 | #include <KoSelection.h> | ||
31 | #include <KoCanvasResourceManager.h> | 31 | #include <KoCanvasResourceManager.h> | ||
32 | #include <KoColor.h> | 32 | #include <KoColor.h> | ||
33 | #include <KoPathPoint.h> | 33 | #include <KoPathPoint.h> | ||
34 | #include <KoPathPointData.h> | 34 | #include <KoPathPointData.h> | ||
35 | #include <KoPathPointMergeCommand.h> | 35 | #include <KoPathPointMergeCommand.h> | ||
36 | #include <KoShapePaintingContext.h> | 36 | #include <KoShapePaintingContext.h> | ||
37 | #include <KoStrokeConfigWidget.h> | 37 | #include <widgets/KoStrokeConfigWidget.h> | ||
38 | #include <KisHandlePainterHelper.h> | ||||
38 | 39 | | |||
39 | #include <klocalizedstring.h> | 40 | #include <klocalizedstring.h> | ||
40 | 41 | | |||
41 | #include <QDoubleSpinBox> | 42 | #include <QDoubleSpinBox> | ||
42 | #include <QComboBox> | 43 | #include <QComboBox> | ||
43 | #include <QStackedWidget> | 44 | #include <QStackedWidget> | ||
44 | #include <QGroupBox> | 45 | #include <QGroupBox> | ||
45 | #include <QCheckBox> | 46 | #include <QCheckBox> | ||
Show All 13 Lines | 56 | KoPencilTool::KoPencilTool(KoCanvasBase *canvas) | |||
59 | , m_optimizeCurve(false) | 60 | , m_optimizeCurve(false) | ||
60 | , m_combineAngle(15.0) | 61 | , m_combineAngle(15.0) | ||
61 | , m_fittingError(5.0) | 62 | , m_fittingError(5.0) | ||
62 | , m_close(false) | 63 | , m_close(false) | ||
63 | , m_shape(0) | 64 | , m_shape(0) | ||
64 | , m_existingStartPoint(0) | 65 | , m_existingStartPoint(0) | ||
65 | , m_existingEndPoint(0) | 66 | , m_existingEndPoint(0) | ||
66 | , m_hoveredPoint(0) | 67 | , m_hoveredPoint(0) | ||
68 | , m_strokeWidget(0) | ||||
67 | { | 69 | { | ||
68 | } | 70 | } | ||
69 | 71 | | |||
70 | KoPencilTool::~KoPencilTool() | 72 | KoPencilTool::~KoPencilTool() | ||
71 | { | 73 | { | ||
72 | } | 74 | } | ||
73 | 75 | | |||
74 | void KoPencilTool::paint(QPainter &painter, const KoViewConverter &converter) | 76 | void KoPencilTool::paint(QPainter &painter, const KoViewConverter &converter) | ||
Show All 13 Lines | 88 | if (m_shape->stroke()) { | |||
88 | m_shape->stroke()->paint(m_shape, painter, converter); | 90 | m_shape->stroke()->paint(m_shape, painter, converter); | ||
89 | painter.restore(); | 91 | painter.restore(); | ||
90 | } | 92 | } | ||
91 | 93 | | |||
92 | painter.restore(); | 94 | painter.restore(); | ||
93 | } | 95 | } | ||
94 | 96 | | |||
95 | if (m_hoveredPoint) { | 97 | if (m_hoveredPoint) { | ||
96 | painter.save(); | 98 | KisHandlePainterHelper helper = | ||
97 | painter.setTransform(m_hoveredPoint->parent()->absoluteTransformation(&converter), true); | 99 | KoShape::createHandlePainterHelper(&painter, m_hoveredPoint->parent(), converter, handleRadius()); | ||
98 | KoShape::applyConversion(painter, converter); | | |||
99 | | ||||
100 | painter.setPen(QPen(Qt::blue, 0)); //TODO make configurable | | |||
101 | painter.setBrush(Qt::white); //TODO make configurable | | |||
102 | m_hoveredPoint->paint(painter, handleRadius(), KoPathPoint::Node); | | |||
103 | 100 | | |||
104 | painter.restore(); | 101 | helper.setHandleStyle(KisHandleStyle::primarySelection()); | ||
102 | m_hoveredPoint->paint(helper, KoPathPoint::Node); | ||||
105 | } | 103 | } | ||
106 | } | 104 | } | ||
107 | 105 | | |||
108 | void KoPencilTool::repaintDecorations() | 106 | void KoPencilTool::repaintDecorations() | ||
109 | { | 107 | { | ||
110 | } | 108 | } | ||
111 | 109 | | |||
112 | void KoPencilTool::mousePressEvent(KoPointerEvent *event) | 110 | void KoPencilTool::mousePressEvent(KoPointerEvent *event) | ||
113 | { | 111 | { | ||
114 | if (! m_shape) { | 112 | KoShapeStrokeSP stroke = createStroke(); | ||
113 | | ||||
114 | if (!m_shape && stroke && stroke->isVisible()) { | ||||
115 | m_shape = new KoPathShape(); | 115 | m_shape = new KoPathShape(); | ||
116 | m_shape->setShapeId(KoPathShapeId); | 116 | m_shape->setShapeId(KoPathShapeId); | ||
117 | m_shape->setStroke(createStroke()); | 117 | m_shape->setStroke(createStroke()); | ||
118 | m_points.clear(); | 118 | m_points.clear(); | ||
119 | 119 | | |||
120 | QPointF point = event->point; | 120 | QPointF point = event->point; | ||
121 | m_existingStartPoint = endPointAtPosition(point); | 121 | m_existingStartPoint = endPointAtPosition(point); | ||
122 | if (m_existingStartPoint) | 122 | if (m_existingStartPoint) | ||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | |||||
173 | { | 173 | { | ||
174 | if (m_shape) { | 174 | if (m_shape) { | ||
175 | event->accept(); | 175 | event->accept(); | ||
176 | } else { | 176 | } else { | ||
177 | event->ignore(); | 177 | event->ignore(); | ||
178 | } | 178 | } | ||
179 | } | 179 | } | ||
180 | 180 | | |||
181 | void KoPencilTool::activate(ToolActivation, const QSet<KoShape*> &) | 181 | void KoPencilTool::activate(ToolActivation activation, const QSet<KoShape*> &shapes) | ||
182 | { | 182 | { | ||
183 | KoToolBase::activate(activation, shapes); | ||||
184 | | ||||
183 | m_points.clear(); | 185 | m_points.clear(); | ||
184 | m_close = false; | 186 | m_close = false; | ||
185 | useCursor(Qt::ArrowCursor); | 187 | slotUpdatePencilCursor(); | ||
188 | | ||||
189 | if (m_strokeWidget) { | ||||
190 | m_strokeWidget->activate(); | ||||
191 | } | ||||
186 | } | 192 | } | ||
187 | 193 | | |||
188 | void KoPencilTool::deactivate() | 194 | void KoPencilTool::deactivate() | ||
189 | { | 195 | { | ||
190 | m_points.clear(); | 196 | m_points.clear(); | ||
191 | delete m_shape; | 197 | delete m_shape; | ||
192 | m_shape = 0; | 198 | m_shape = 0; | ||
193 | m_existingStartPoint = 0; | 199 | m_existingStartPoint = 0; | ||
194 | m_existingEndPoint = 0; | 200 | m_existingEndPoint = 0; | ||
195 | m_hoveredPoint = 0; | 201 | m_hoveredPoint = 0; | ||
202 | | ||||
203 | if (m_strokeWidget) { | ||||
204 | m_strokeWidget->deactivate(); | ||||
205 | } | ||||
206 | | ||||
207 | KoToolBase::deactivate(); | ||||
208 | } | ||||
209 | | ||||
210 | void KoPencilTool::slotUpdatePencilCursor() | ||||
211 | { | ||||
212 | KoShapeStrokeSP stroke = createStroke(); | ||||
213 | useCursor((stroke && stroke->isVisible()) ? Qt::ArrowCursor : Qt::ForbiddenCursor); | ||||
196 | } | 214 | } | ||
197 | 215 | | |||
198 | void KoPencilTool::addPoint(const QPointF & point) | 216 | void KoPencilTool::addPoint(const QPointF & point) | ||
199 | { | 217 | { | ||
200 | if (! m_shape) | 218 | if (! m_shape) | ||
201 | return; | 219 | return; | ||
202 | 220 | | |||
203 | // do a moveTo for the first point added | 221 | // do a moveTo for the first point added | ||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Line(s) | 305 | { | |||
348 | connect(combineAngle, SIGNAL(valueChanged(double)), this, SLOT(setDelta(double))); | 366 | connect(combineAngle, SIGNAL(valueChanged(double)), this, SLOT(setDelta(double))); | ||
349 | 367 | | |||
350 | modeBox->setCurrentIndex(m_mode); | 368 | modeBox->setCurrentIndex(m_mode); | ||
351 | stackedWidget->setCurrentIndex(m_mode); | 369 | stackedWidget->setCurrentIndex(m_mode); | ||
352 | optionWidget->setObjectName(i18n("Pencil")); | 370 | optionWidget->setObjectName(i18n("Pencil")); | ||
353 | optionWidget->setWindowTitle(i18n("Pencil")); | 371 | optionWidget->setWindowTitle(i18n("Pencil")); | ||
354 | widgets.append(optionWidget); | 372 | widgets.append(optionWidget); | ||
355 | 373 | | |||
356 | m_strokeWidget = new KoStrokeConfigWidget(0); | 374 | m_strokeWidget = new KoStrokeConfigWidget(canvas(), 0); | ||
375 | m_strokeWidget->setNoSelectionTrackingMode(true); | ||||
357 | m_strokeWidget->setWindowTitle(i18n("Line")); | 376 | m_strokeWidget->setWindowTitle(i18n("Line")); | ||
358 | m_strokeWidget->setCanvas(canvas()); | 377 | connect(m_strokeWidget, SIGNAL(sigStrokeChanged()), SLOT(slotUpdatePencilCursor())); | ||
378 | if (isActivated()) { | ||||
379 | m_strokeWidget->activate(); | ||||
380 | } | ||||
359 | widgets.append(m_strokeWidget); | 381 | widgets.append(m_strokeWidget); | ||
360 | return widgets; | 382 | return widgets; | ||
361 | } | 383 | } | ||
362 | 384 | | |||
363 | void KoPencilTool::addPathShape(KoPathShape* path, bool closePath) | 385 | void KoPencilTool::addPathShape(KoPathShape* path, bool closePath) | ||
364 | { | 386 | { | ||
365 | KoShape * startShape = 0; | 387 | KoShape * startShape = 0; | ||
366 | KoShape * endShape = 0; | 388 | KoShape * endShape = 0; | ||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | |||||
412 | void KoPencilTool::setDelta(double delta) | 434 | void KoPencilTool::setDelta(double delta) | ||
413 | { | 435 | { | ||
414 | if (m_mode == ModeCurve) | 436 | if (m_mode == ModeCurve) | ||
415 | m_fittingError = delta; | 437 | m_fittingError = delta; | ||
416 | else if (m_mode == ModeStraight) | 438 | else if (m_mode == ModeStraight) | ||
417 | m_combineAngle = delta; | 439 | m_combineAngle = delta; | ||
418 | } | 440 | } | ||
419 | 441 | | |||
420 | KoShapeStroke* KoPencilTool::createStroke() | 442 | KoShapeStrokeSP KoPencilTool::createStroke() | ||
421 | { | 443 | { | ||
422 | KoShapeStroke *stroke = 0; | 444 | KoShapeStrokeSP stroke; | ||
423 | if (m_strokeWidget) { | 445 | if (m_strokeWidget) { | ||
424 | stroke = m_strokeWidget->createShapeStroke(); | 446 | stroke = m_strokeWidget->createShapeStroke(); | ||
425 | } | 447 | } | ||
426 | return stroke; | 448 | return stroke; | ||
427 | } | 449 | } | ||
428 | 450 | | |||
429 | KoPathPoint* KoPencilTool::endPointAtPosition(const QPointF &position) | 451 | KoPathPoint* KoPencilTool::endPointAtPosition(const QPointF &position) | ||
430 | { | 452 | { | ||
▲ Show 20 Lines • Show All 129 Lines • Show Last 20 Lines |