Krita Source Code Documentation
Loading...
Searching...
No Matches
KoCreatePathToolPrivate Class Reference

#include <KoCreatePathTool_p.h>

+ Inheritance diagram for KoCreatePathToolPrivate:

Public Member Functions

void addPathShape ()
 
void angleDeltaChanged (qreal value)
 
void angleSnapChanged (int angleSnap)
 
void autoSmoothCurvesChanged (bool value)
 
void cleanUp ()
 
bool connectPaths (KoPathShape *pathShape, const PathConnectionPoint &pointAtStart, const PathConnectionPoint &pointAtEnd) const
 Connects given path with the ones we hit when starting/finishing.
 
KoPathPointendPointAtPosition (const QPointF &position) const
 returns the nearest existing path point
 
 KoCreatePathToolPrivate (KoCreatePathTool *const qq, KoCanvasBase *canvas)
 
void loadAutoSmoothValueFromConfig ()
 
void repaintActivePoint () const
 
- Public Member Functions inherited from KoToolBasePrivate
void connectSignals ()
 
 KoToolBasePrivate (KoToolBase *qq, KoCanvasBase *canvas_)
 
virtual ~KoToolBasePrivate ()
 

Public Attributes

KoPathPointactivePoint
 
int angleSnappingDelta
 
bool angleSnapStatus
 
AngleSnapStrategyangleSnapStrategy
 
bool autoSmoothCurves = false
 
int decorationThickness
 
QPointF dragStartPoint
 
bool enableClosePathShortcut
 
PathConnectionPoint existingEndPoint
 an existing path point we finished a new path at
 
PathConnectionPoint existingStartPoint
 an existing path point we started a new path at
 
bool finishAfterThisPoint
 
KoPathPointfirstPoint
 
int handleRadius
 
KoPathPointhoveredPoint
 an existing path end point the mouse is hovering on
 
bool mouseOverFirstPoint
 
bool pointIsDragged
 
bool prevPointWasDragged = false
 
KoPathShapeshape
 
- Public Attributes inherited from KoToolBasePrivate
KoCanvasBasecanvas
 the canvas interface this tool will work for.
 
QCursor currentCursor
 
KoToolFactoryBasefactory {0}
 
bool isActivated
 
bool isInTextMode
 
bool isOpacityPresetMode {false}
 Whether the opacity is preset or tool.
 
QRectF lastDecorationsRect
 
bool maskSyntheticEvents {false}
 Whether this tool masks synthetic events.
 
QList< QPointer< QWidget > > optionWidgets
 the optionwidgets associated with this tool
 
bool optionWidgetsCreated {false}
 
KoToolBaseq
 
ToolCanvasResources toolCanvasResources
 

Private Attributes

KoCreatePathTool *const q
 

Detailed Description

Definition at line 165 of file KoCreatePathTool_p.h.

Constructor & Destructor Documentation

◆ KoCreatePathToolPrivate()

KoCreatePathToolPrivate::KoCreatePathToolPrivate ( KoCreatePathTool *const qq,
KoCanvasBase * canvas )
inline

Definition at line 169 of file KoCreatePathTool_p.h.

171 q(qq),
172 shape(0),
173 activePoint(0),
174 firstPoint(0),
175 handleRadius(3),
177 mouseOverFirstPoint(false),
178 pointIsDragged(false),
180 hoveredPoint(0),
183 angleSnapStatus(false),
185 {
186 }
KoPathPoint * hoveredPoint
an existing path end point the mouse is hovering on
AngleSnapStrategy * angleSnapStrategy
KoCreatePathTool *const q
KoToolBasePrivate(KoToolBase *qq, KoCanvasBase *canvas_)
KoCanvasBase * canvas
the canvas interface this tool will work for.

Member Function Documentation

◆ addPathShape()

void KoCreatePathToolPrivate::addPathShape ( )
inline

Definition at line 373 of file KoCreatePathTool_p.h.

373 {
374 if (!shape) return;
375
376 if (shape->pointCount() < 2) {
377 cleanUp();
378 return;
379 }
380
381 // this is done so that nothing happens when the mouseReleaseEvent for the this event is received
382 KoPathShape *pathShape = shape;
383 shape = 0;
384
385 q->addPathShape(pathShape);
386
387 cleanUp();
388
389 return;
390 }
virtual void addPathShape(KoPathShape *pathShape)
The position of a path point within a path shape.
Definition KoPathShape.h:63
int pointCount() const
Returns the number of points in the path.

References KoCreatePathTool::addPathShape(), cleanUp(), KoPathShape::pointCount(), q, and shape.

◆ angleDeltaChanged()

void KoCreatePathToolPrivate::angleDeltaChanged ( qreal value)
inline

Definition at line 406 of file KoCreatePathTool_p.h.

406 {
407 angleSnappingDelta = static_cast<int>(value);
410 }
float value(const T *src, size_t ch)
void setAngleStep(qreal angleStep)

References angleSnappingDelta, angleSnapStrategy, AngleSnapStrategy::setAngleStep(), and value().

◆ angleSnapChanged()

void KoCreatePathToolPrivate::angleSnapChanged ( int angleSnap)
inline

Definition at line 426 of file KoCreatePathTool_p.h.

426 {
428 if (angleSnapStrategy) {
429 if (angleSnap == Qt::Checked)
431 else
433 }
434 }

References AngleSnapStrategy::activate(), angleSnapStatus, angleSnapStrategy, and AngleSnapStrategy::deactivate().

◆ autoSmoothCurvesChanged()

void KoCreatePathToolPrivate::autoSmoothCurvesChanged ( bool value)
inline

Definition at line 412 of file KoCreatePathTool_p.h.

412 {
414
415 KisConfig cfg(false);
416 cfg.setAutoSmoothBezierCurves(value);
417 }

References autoSmoothCurves, KisConfig::setAutoSmoothBezierCurves(), and value().

◆ cleanUp()

void KoCreatePathToolPrivate::cleanUp ( )
inline

Definition at line 392 of file KoCreatePathTool_p.h.

392 {
393 // reset snap guide
395 q->canvas()->snapGuide()->reset();
397
398 delete shape;
399 shape = 0;
402 hoveredPoint = 0;
403 activePoint = 0;
404 }
KoSnapGuide * snapGuide
virtual void updateCanvas(const QRectF &rc)=0
PathConnectionPoint existingStartPoint
an existing path point we started a new path at
PathConnectionPoint existingEndPoint
an existing path point we finished a new path at
void reset()
Resets the snap guide.
QRectF boundingRect()
returns the bounding rect of the guide
KoCanvasBase * canvas() const
Returns the canvas the tool is working on.

References activePoint, angleSnapStrategy, KoSnapGuide::boundingRect(), KoToolBase::canvas(), existingEndPoint, existingStartPoint, hoveredPoint, q, KoSnapGuide::reset(), shape, KoCanvasBase::snapGuide, and KoCanvasBase::updateCanvas().

◆ connectPaths()

bool KoCreatePathToolPrivate::connectPaths ( KoPathShape * pathShape,
const PathConnectionPoint & pointAtStart,
const PathConnectionPoint & pointAtEnd ) const
inline

Connects given path with the ones we hit when starting/finishing.

Definition at line 283 of file KoCreatePathTool_p.h.

283 {
284 KoPathShape * startShape = 0;
285 KoPathShape * endShape = 0;
286 KoPathPoint * startPoint = 0;
287 KoPathPoint * endPoint = 0;
288
289 if (pointAtStart.isValid()) {
290 startShape = pointAtStart.path;
291 startPoint = pointAtStart.point;
292 }
293 if (pointAtEnd.isValid()) {
294 endShape = pointAtEnd.path;
295 endPoint = pointAtEnd.point;
296 }
297
298 // at least one point must be valid
299 if (!startPoint && !endPoint)
300 return false;
301 // do not allow connecting to the same point twice
302 if (startPoint == endPoint)
303 endPoint = 0;
304
305 // we have hit an existing path point on start/finish
306 // what we now do is:
307 // 1. combine the new created path with the ones we hit on start/finish
308 // 2. merge the endpoints of the corresponding subpaths
309
310 uint newPointCount = pathShape->subpathPointCount(0);
311 KoPathPointIndex newStartPointIndex(0, 0);
312 KoPathPointIndex newEndPointIndex(0, newPointCount - 1);
313 KoPathPoint * newStartPoint = pathShape->pointByIndex(newStartPointIndex);
314 KoPathPoint * newEndPoint = pathShape->pointByIndex(newEndPointIndex);
315
316 // combine with the path we hit on start
317 KoPathPointIndex startIndex(-1, -1);
318 if (startShape && startPoint) {
319 startIndex = startShape->pathPointIndex(startPoint);
320 pathShape->combine(startShape);
321 pathShape->moveSubpath(0, pathShape->subpathCount() - 1);
322 }
323 // combine with the path we hit on finish
324 KoPathPointIndex endIndex(-1, -1);
325 if (endShape && endPoint) {
326 endIndex = endShape->pathPointIndex(endPoint);
327 if (endShape != startShape) {
328 endIndex.first += pathShape->subpathCount();
329 pathShape->combine(endShape);
330 }
331 }
332 // do we connect twice to a single subpath ?
333 bool connectToSingleSubpath = (startShape == endShape && startIndex.first == endIndex.first);
334
335 if (startIndex.second == 0 && !connectToSingleSubpath) {
336 pathShape->reverseSubpath(startIndex.first);
337 startIndex.second = pathShape->subpathPointCount(startIndex.first) - 1;
338 }
339 if (endIndex.second > 0 && !connectToSingleSubpath) {
340 pathShape->reverseSubpath(endIndex.first);
341 endIndex.second = 0;
342 }
343
344 // after combining we have a path where with the subpaths in the following
345 // order:
346 // 1. the subpaths of the pathshape we started the new path at
347 // 2. the subpath we just created
348 // 3. the subpaths of the pathshape we finished the new path at
349
350 // get the path points we want to merge, as these are not going to
351 // change while merging
352 KoPathPoint * existingStartPoint = pathShape->pointByIndex(startIndex);
353 KoPathPoint * existingEndPoint = pathShape->pointByIndex(endIndex);
354
355 // merge first two points
356 if (existingStartPoint) {
357 KoPathPointData pd1(pathShape, pathShape->pathPointIndex(existingStartPoint));
358 KoPathPointData pd2(pathShape, pathShape->pathPointIndex(newStartPoint));
359 KoPathPointMergeCommand cmd1(pd1, pd2);
360 cmd1.redo();
361 }
362 // merge last two points
363 if (existingEndPoint) {
364 KoPathPointData pd3(pathShape, pathShape->pathPointIndex(newEndPoint));
365 KoPathPointData pd4(pathShape, pathShape->pathPointIndex(existingEndPoint));
366 KoPathPointMergeCommand cmd2(pd3, pd4);
367 cmd2.redo();
368 }
369
370 return true;
371 }
unsigned int uint
QPair< int, int > KoPathPointIndex
Definition KoPathShape.h:28
Describe a KoPathPoint by a KoPathShape and its indices.
The undo / redo command for merging two subpath end points.
A KoPathPoint represents a point in a path.
int subpathPointCount(int subpathIndex) const
Returns the number of points in a subpath.
bool reverseSubpath(int subpathIndex)
Reverse subpath.
bool moveSubpath(int oldSubpathIndex, int newSubpathIndex)
Moves the position of a subpath within a path.
int subpathCount() const
Returns the number of subpaths in the path.
KoPathPointIndex pathPointIndex(const KoPathPoint *point) const
Returns the path point index of a given path point.
KoPathPoint * pointByIndex(const KoPathPointIndex &pointIndex) const
Returns the path point specified by a path point index.
int combine(KoPathShape *path)
Combines two path shapes by appending the data of the specified path.

References KoPathShape::combine(), existingEndPoint, existingStartPoint, PathConnectionPoint::isValid(), KoPathShape::moveSubpath(), PathConnectionPoint::path, KoPathShape::pathPointIndex(), PathConnectionPoint::point, KoPathShape::pointByIndex(), KoPathPointMergeCommand::redo(), KoPathShape::reverseSubpath(), KoPathShape::subpathCount(), and KoPathShape::subpathPointCount().

◆ endPointAtPosition()

KoPathPoint * KoCreatePathToolPrivate::endPointAtPosition ( const QPointF & position) const
inline

returns the nearest existing path point

Definition at line 240 of file KoCreatePathTool_p.h.

240 {
241 QRectF roi = q->handleGrabRect(position);
242 QList<KoShape *> shapes = q->canvas()->shapeManager()->shapesAt(roi);
243
245 qreal minDistance = HUGE_VAL;
246 uint grabSensitivity = q->grabSensitivity();
247 qreal maxDistance = q->canvas()->viewConverter()->viewToDocumentX(grabSensitivity);
248
249 Q_FOREACH(KoShape * s, shapes) {
250 KoPathShape * path = dynamic_cast<KoPathShape*>(s);
251 if (!path)
252 continue;
253 KoParameterShape *paramShape = dynamic_cast<KoParameterShape*>(s);
254 if (paramShape && paramShape->isParametricShape())
255 continue;
256
257 KoPathPoint * p = 0;
258 uint subpathCount = path->subpathCount();
259 for (uint i = 0; i < subpathCount; ++i) {
260 if (path->isClosedSubpath(i))
261 continue;
262 p = path->pointByIndex(KoPathPointIndex(i, 0));
263 // check start of subpath
264 qreal d = squareDistance(position, path->shapeToDocument(p->point()));
265 if (d < minDistance && d < maxDistance) {
266 nearestPoint = p;
267 minDistance = d;
268 }
269 // check end of subpath
270 p = path->pointByIndex(KoPathPointIndex(i, path->subpathPointCount(i) - 1));
271 d = squareDistance(position, path->shapeToDocument(p->point()));
272 if (d < minDistance && d < maxDistance) {
273 nearestPoint = p;
274 minDistance = d;
275 }
276 }
277 }
278
279 return nearestPoint;
280 }
const Params2D p
qreal squareDistance(const QPointF &p1, const QPointF &p2)
virtual KoShapeManager * shapeManager() const =0
virtual const KoViewConverter * viewConverter() const =0
bool isParametricShape() const
Check if object is a parametric shape.
QList< KoShape * > shapesAt(const QRectF &rect, bool omitHiddenShapes=true, bool containedMode=false)
int grabSensitivity() const
Convenience function to get the current grab sensitivity.
QRectF handleGrabRect(const QPointF &position) const
virtual qreal viewToDocumentX(qreal viewX) const
qreal nearestPoint(const QList< QPointF > controlPoints, const QPointF &point, qreal *resultDistance, QPointF *resultPoint)

References KoToolBase::canvas(), KoToolBase::grabSensitivity(), KoToolBase::handleGrabRect(), KoParameterShape::isParametricShape(), p, q, KoCanvasBase::shapeManager(), KoShapeManager::shapesAt(), squareDistance(), KoCanvasBase::viewConverter(), and KoViewConverter::viewToDocumentX().

◆ loadAutoSmoothValueFromConfig()

void KoCreatePathToolPrivate::loadAutoSmoothValueFromConfig ( )
inline

Definition at line 419 of file KoCreatePathTool_p.h.

419 {
420 KisConfig cfg(true);
421 autoSmoothCurves = cfg.autoSmoothBezierCurves();
422
424 }
void sigUpdateAutoSmoothCurvesGUI(bool value)

References KisConfig::autoSmoothBezierCurves(), autoSmoothCurves, q, and KoCreatePathTool::sigUpdateAutoSmoothCurvesGUI().

◆ repaintActivePoint()

void KoCreatePathToolPrivate::repaintActivePoint ( ) const
inline

Definition at line 209 of file KoCreatePathTool_p.h.

209 {
210 const bool isFirstPoint = (activePoint == firstPoint);
211
212 if (!isFirstPoint && !pointIsDragged)
213 return;
214
215 QRectF rect = activePoint->boundingRect(false);
216
217 // make sure that we have the second control point inside our
218 // update rect, as KoPathPoint::boundingRect will not include
219 // the second control point of the last path point if the path
220 // is not closed
221 const QPointF &point = activePoint->point();
222 const QPointF &controlPoint = activePoint->controlPoint2();
223 rect = rect.united(QRectF(point, controlPoint).normalized());
224
225 // when painting the first point we want the
226 // first control point to be painted as well
227 if (isFirstPoint) {
228 const QPointF &controlPoint = activePoint->controlPoint1();
229 rect = rect.united(QRectF(point, controlPoint).normalized());
230 }
231
232 QPointF border = q->canvas()->viewConverter()
234
235 rect.adjust(-border.x(), -border.y(), border.x(), border.y());
237 }
QRectF boundingRect(bool active=true) const
Get the bounding rect of the point.
QPointF point
QPointF controlPoint1
QPointF controlPoint2
virtual QPointF viewToDocument(const QPointF &viewPoint) const

References activePoint, KoPathPoint::boundingRect(), KoToolBase::canvas(), KoPathPoint::controlPoint1, KoPathPoint::controlPoint2, firstPoint, handleRadius, KoPathPoint::point, pointIsDragged, q, KoCanvasBase::updateCanvas(), KoCanvasBase::viewConverter(), and KoViewConverter::viewToDocument().

Member Data Documentation

◆ activePoint

KoPathPoint* KoCreatePathToolPrivate::activePoint

Definition at line 189 of file KoCreatePathTool_p.h.

◆ angleSnappingDelta

int KoCreatePathToolPrivate::angleSnappingDelta

Definition at line 205 of file KoCreatePathTool_p.h.

◆ angleSnapStatus

bool KoCreatePathToolPrivate::angleSnapStatus

Definition at line 206 of file KoCreatePathTool_p.h.

◆ angleSnapStrategy

AngleSnapStrategy* KoCreatePathToolPrivate::angleSnapStrategy

Definition at line 204 of file KoCreatePathTool_p.h.

◆ autoSmoothCurves

bool KoCreatePathToolPrivate::autoSmoothCurves = false

Definition at line 200 of file KoCreatePathTool_p.h.

◆ decorationThickness

int KoCreatePathToolPrivate::decorationThickness

Definition at line 192 of file KoCreatePathTool_p.h.

◆ dragStartPoint

QPointF KoCreatePathToolPrivate::dragStartPoint

Definition at line 202 of file KoCreatePathTool_p.h.

◆ enableClosePathShortcut

bool KoCreatePathToolPrivate::enableClosePathShortcut

Definition at line 207 of file KoCreatePathTool_p.h.

◆ existingEndPoint

PathConnectionPoint KoCreatePathToolPrivate::existingEndPoint

an existing path point we finished a new path at

Definition at line 197 of file KoCreatePathTool_p.h.

◆ existingStartPoint

PathConnectionPoint KoCreatePathToolPrivate::existingStartPoint

an existing path point we started a new path at

Definition at line 196 of file KoCreatePathTool_p.h.

◆ finishAfterThisPoint

bool KoCreatePathToolPrivate::finishAfterThisPoint

Definition at line 195 of file KoCreatePathTool_p.h.

◆ firstPoint

KoPathPoint* KoCreatePathToolPrivate::firstPoint

Definition at line 190 of file KoCreatePathTool_p.h.

◆ handleRadius

int KoCreatePathToolPrivate::handleRadius

Definition at line 191 of file KoCreatePathTool_p.h.

◆ hoveredPoint

KoPathPoint* KoCreatePathToolPrivate::hoveredPoint

an existing path end point the mouse is hovering on

Definition at line 198 of file KoCreatePathTool_p.h.

◆ mouseOverFirstPoint

bool KoCreatePathToolPrivate::mouseOverFirstPoint

Definition at line 193 of file KoCreatePathTool_p.h.

◆ pointIsDragged

bool KoCreatePathToolPrivate::pointIsDragged

Definition at line 194 of file KoCreatePathTool_p.h.

◆ prevPointWasDragged

bool KoCreatePathToolPrivate::prevPointWasDragged = false

Definition at line 199 of file KoCreatePathTool_p.h.

◆ q

KoCreatePathTool* const KoCreatePathToolPrivate::q
private

Definition at line 167 of file KoCreatePathTool_p.h.

◆ shape

KoPathShape* KoCreatePathToolPrivate::shape

Definition at line 188 of file KoCreatePathTool_p.h.


The documentation for this class was generated from the following file: