57#include <klocalizedstring.h>
59#include <QPainterPath>
68 qreal dx =
p1.x()-
p2.x();
69 qreal dy =
p1.y()-
p2.y();
90 , m_pointSelection(this)
113 m_selectCursor = QCursor(QIcon(
":/cursor-needle.svg").pixmap(32), 0, 0);
114 m_moveCursor = QCursor(QIcon(
":/cursor-needle-move.svg").pixmap(32), 0, 0);
128 connect(
this, SIGNAL(
typeChanged(
int)), toolOptions, SLOT(setSelectionType(
int)));
130 connect(toolOptions, SIGNAL(sigRequestUpdateActions()),
this, SLOT(
updateActions()));
132 toolOptions->setWindowTitle(i18n(
"Edit Shape"));
133 list.append(toolOptions);
158 if (initialConversionCommand) {
159 initialConversionCommand->
redo();
165 if (initialConversionCommand) {
168 parent->setText(command->
text());
170 parent->addCommand(command);
174 d->canvas->addCommand(command);
182 if (segments.size() == 1) {
183 qreal positionInSegment = 0.5;
189 d->canvas->addCommand(cmd);
210 d->canvas->addCommand(cmd);
222 for (; it != selectedPoints.constEnd(); ++it) {
223 KoPathPoint *point = it->pathShape->pointByIndex(it->pointIndex);
225 pointToChange.append(*it);
228 if (! pointToChange.isEmpty()) {
243 d->canvas->addCommand(command);
254 for (; it != points.constEnd(); ++it) {
255 KoPathPoint *point = it->pathShape->pointByIndex(it->pointIndex);
257 pointToChange.append(*it);
260 if (!pointToChange.isEmpty()) {
272 if (segments.size() > 0) {
283 if (segments.size() > 0) {
300 parameterShapes.append(parametric);
304 if (!parameterShapes.isEmpty()) {
311 textShapes.append(text);
315 if (!textShapes.isEmpty()) {
317 const QList<KoShape*> oldSelectedShapes = implicitCastList<KoShape*>(textShapes);
330 newSelectedShapes << outlineShape;
358 if (index1.second != 0 && index1.second != path1->
subpathPointCount(index1.first)-1)
362 if (index2.second != 0 && index2.second != path2->
subpathPointCount(index2.first)-1)
377 if (pointData.size() != 2)
return;
382 if (!checkCanJoinToPoints(pd1, pd2)) {
391 cmd =
new KoMultiPathPointJoinCommand(pd1, pd2, d->canvas->shapeController()->documentBase(), d->canvas->shapeManager()->selection());
395 d->canvas->addCommand(cmd);
422 if (segments.size() == 1) {
436 if (segments.size() == 1) {
463 if (!shape->
stroke() || !shape->
stroke()->isVisible()) {
513 d->canvas->snapGuide()->paint(painter, converter,
canvas()->displayRendererInterface());
522 QRectF newDecorationsRect;
548 return newDecorationsRect;
575 if (event->
button() & Qt::LeftButton) {
577 bool shift_pressed = (
event->modifiers() & Qt::ShiftModifier);
604 if (shape && !
selection->isSelected(shape)) {
606 if (!shift_pressed) {
622 if (event->
button() & Qt::RightButton)
643 int handleId = parameterShape->
handleIdAt(roi);
644 if (handleId != -1) {
654 if (! points.empty()) {
658 qreal minDistance = HUGE_VAL;
666 if (
p->activeControlPoint1() && roi.contains(
p->controlPoint1())) {
668 if (dist < minDistance) {
675 if (
p->activeControlPoint2() && roi.contains(
p->controlPoint2())) {
677 if (dist < minDistance) {
686 if (dist < minDistance) {
700 Q_EMIT
statusTextChanged(i18n(
"Drag to move point. Shift click to change point type."));
725 Q_EMIT
statusTextChanged(i18n(
"Drag to change curve directly. Double click to insert new path point."));
730 if (selectedPointCount == 0)
734 if (selectedPointCount == 1)
753 d->canvas->addCommand(command);
767 switch (event->key()) {
768 case Qt::Key_Control:
772 if (! event->isAutoRepeat()) {
785 switch (event->key()) {
806 switch (event->key()) {
807 case Qt::Key_Control:
811 if (! event->isAutoRepeat()) {
835 d->canvas->addCommand(cmd);
854 std::unique_ptr<PathSegment> segment(
new PathSegment);
863 segment->path = shape;
864 segment->segmentStart = s.
first();
869 if (!segment->isValid()) {
873 return segment.release();
882 d->canvas->snapGuide()->reset();
915 d->canvas->selectedShapesProxy()->selection()->selectedEditableShapesAndDelegates();
941 Q_FOREACH (
KoShape *shape, shapes) {
945 selectedShapes.append(pathShape);
961 PathToolOptionWidget::Types type;
977 bool canBreakAtPoint =
false;
979 bool hasNonSmoothPoints =
false;
980 bool hasNonSymmetricPoints =
false;
981 bool hasNonSplitPoints =
false;
983 bool hasNonLinePoints =
false;
984 bool hasNonCurvePoints =
false;
986 bool canJoinSubpaths =
false;
988 if (!pointData.isEmpty()) {
1000 hasNonSplitPoints |=
1008 if (pointData.size() == 2) {
1012 canJoinSubpaths = checkCanJoinToPoints(pd1, pd2);
1033 bool canSplitAtSegment =
false;
1034 bool canConvertSegmentToLine =
false;
1035 bool canConvertSegmentToCurve=
false;
1037 if (!segments.isEmpty()) {
1039 canSplitAtSegment = segments.size() == 1;
1041 bool hasLines =
false;
1042 bool hasCurves =
false;
1046 hasLines |= segment.
degree() == 1;
1047 hasCurves |= segment.
degree() > 1;
1050 canConvertSegmentToLine = !segments.isEmpty() && hasCurves;
1051 canConvertSegmentToCurve= !segments.isEmpty() && hasLines;
1063 bool haveConvertibleShapes =
false;
1070 haveConvertibleShapes =
true;
1088 d->canvas->snapGuide()->reset();
1126void addActionsGroupIfEnabled(QMenu *menu, QAction *a1, QAction *a2)
1128 if (a1->isEnabled() || a2->isEnabled()) {
1129 menu->addAction(a1);
1130 menu->addAction(a2);
1131 menu->addSeparator();
1135void addActionsGroupIfEnabled(QMenu *menu, QAction *a1, QAction *a2, QAction *a3)
1137 if (a1->isEnabled() || a2->isEnabled()) {
1138 menu->addAction(a1);
1139 menu->addAction(a2);
1140 menu->addAction(a3);
1141 menu->addSeparator();
QPair< int, int > KoPathPointIndex
KUndo2MagicString text() const
The KisHandlePainterHelper class is a special helper for painting handles around objects....
void drawPath(const QPainterPath &path)
void setHandleStyle(const KisHandleStyle &style)
static KisHandleStyle & secondarySelection(KisHandlePalette palette=KisHandlePalette())
static KisHandleStyle & primarySelection(KisHandlePalette palette=KisHandlePalette())
void addConnection(Sender sender, Signal signal, Receiver receiver, Method method, Qt::ConnectionType type=Qt::AutoConnection)
QPointer< KoShapeController > shapeController
virtual KoShapeManager * shapeManager() const =0
virtual KoColorDisplayRendererInterface * displayRendererInterface() const
displayRendererInterface The display renderer interface has a number of color conversion functions wh...
virtual void addCommand(KUndo2Command *command)=0
KoCanvasController * canvasController() const
virtual KoSelectedShapesProxy * selectedShapesProxy() const =0
selectedShapesProxy() is a special interface for keeping a persistent connections to selectionChanged...
QPointer< KoToolManager > toolManager
virtual KisHandlePalette handlePaletteForDisplayColorSpace() const =0
handlePaletteForDisplayColorSpace
void paintHandles(KisHandlePainterHelper &handlesHelper)
Paint the handles.
bool isParametricShape() const
Check if object is a parametric shape.
int handleIdAt(const QRectF &rect) const
Get the id of the handle within the given rect.
The undo / redo command for changing a KoParameterShape into a KoPathShape.
Command to break a subpath at points.
Describe a KoPathPoint by a KoPathShape and its indices.
KoPathPointIndex pointIndex
position of the point in the path shape
KoPathShape * pathShape
path shape the path point belongs too
The undo / redo command for inserting path points.
QList< KoPathPoint * > insertedPoints() const
Returns list of inserted points.
static KUndo2Command * createCommand(const QList< KoPathPointData > &pointDataList, KoShapeController *shapeController, KUndo2Command *parent=0)
Create command for removing points from path shapes.
Strategy to rubber select points of a path shape.
The undo / redo command for changing the path point type.
PointType
The type of the point.
A KoPathPoint represents a point in a path.
PointProperties properties
QRectF boundingRect(bool active=true) const
Get the bounding rect of the point.
@ IsSmooth
it is smooth, both control points on a line through the point
@ IsSymmetric
it is symmetric, like smooth but control points have same distance to point
PointType
the type for identifying part of a KoPathPoint
@ ControlPoint2
the second control point
@ ControlPoint1
the first control point
The undo / redo command for breaking a subpath by removing the segment.
Strategy for deforming a segment of a path shape.
The undo / redo command for changing segments to curves/lines.
A KoPathSegment consist of two neighboring KoPathPoints.
int degree() const
Returns the degree of the segment: 1 = line, 2 = quadratic, 3 = cubic, -1 = invalid.
qreal nearestPoint(const QPointF &point) const
bool isValid() const
Returns if segment is valid, e.g. has two valid points.
QRectF boundingRect() const
Returns the axis aligned tight bounding rect.
KoPathSegment toCubic() const
Returns cubic bezier curve segment of this segment.
The position of a path point within a path shape.
int subpathPointCount(int subpathIndex) const
Returns the number of points in a subpath.
bool isClosedSubpath(int subpathIndex) const
Checks if a subpath is closed.
KoPathSegment segmentAtPoint(const QPointF &point, const QRectF &grabRoi) const
QList< KoPathPoint * > pointsAt(const QRectF &rect, const bool useControlPoints=false) const
Returns the path points within the given rectangle.
QPainterPath outline() const override
reimplemented
KoPathSegment segmentByIndex(const KoPathPointIndex &pointIndex) const
Returns the segment specified by a path point index.
virtual void paintPoints(KisHandlePainterHelper &handlesHelper)
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.
Qt::MouseButton button() const
return button pressed (see QMouseEvent::button());
bool isTouchEvent() const
Qt::KeyboardModifiers modifiers() const
QPointF point
The point in document coordinates.
virtual KoSelection * selection()=0
void connectToCanvas(KoCanvasBase *canvas)
KoShape * shapeAt(const QPointF &position, KoFlake::ShapeSelection selection=KoFlake::ShapeOnTop, bool omitHiddenShapes=true)
virtual bool isShapeEditable(bool recursive=true) const
checks recursively if the shape or one of its parents is not visible or locked
virtual KoShapeStrokeModelSP stroke() const
QPointF documentToShape(const QPointF &point) const
Transforms point from document coordinates to shape coordinates.
virtual QRectF boundingRect() const
Get the bounding box of the shape.
KoShapeContainer * parent() const
static KisHandlePainterHelper createHandlePainterHelperView(QPainter *painter, KoShape *shape, const KoViewConverter &converter, qreal handleRadius=0.0, int decorationThickness=1)
The KoSvgTextShapeOutlineHelper class helper class that draws the text outlines and contour mode butt...
KoShape * textOutline() const
textOutline This turns the text object into non-text KoShape(s) to the best of its abilities.
virtual QPointF documentToView(const QPointF &documentPoint) const
KoPathPoint * activePoint() const
KoPathPoint::PointType activePointType() const
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
#define KIS_ASSERT_RECOVER_RETURN(cond)
T kisGrowRect(const T &rect, U offset)
KUndo2MagicString kundo2_i18n(const char *text)
@ DecorationThickness
Integer, the thickness of single px decorations, will be adjusted by HiDPI settings....
@ HandleRadius
The handle radius used for drawing handles of any kind.
@ ShapeOnTop
return the shape highest z-ordering, regardless of selection.