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

#include <KarbonCalligraphyTool.h>

+ Inheritance diagram for KarbonCalligraphyTool:

Signals

void pathSelectedChanged (bool selection)
 
- Signals inherited from KoToolBase
void activateTool (const QString &id)
 
void cursorChanged (const QCursor &cursor)
 
void selectionChanged (bool hasSelection)
 
void statusTextChanged (const QString &statusText)
 
void textModeChanged (bool inTextMode)
 

Public Member Functions

void activate (const QSet< KoShape * > &shapes) override
 
QList< QPointer< QWidget > > createOptionWidgets () override
 
void deactivate () override
 
 KarbonCalligraphyTool (KoCanvasBase *canvas)
 
void mouseMoveEvent (KoPointerEvent *event) override
 
void mousePressEvent (KoPointerEvent *event) override
 
void mouseReleaseEvent (KoPointerEvent *event) override
 
void paint (QPainter &painter, const KoViewConverter &converter) override
 
KisPopupWidgetInterfacepopupWidget () override
 
 ~KarbonCalligraphyTool () override
 
- Public Member Functions inherited from KoToolBase
QAction * action (const QString &name) const
 
KoCanvasBasecanvas () const
 Returns the canvas the tool is working on.
 
virtual void copy () const
 
QCursor cursor () const
 return the last emitted cursor
 
virtual void customMoveEvent (KoPointerEvent *event)
 
virtual void customPressEvent (KoPointerEvent *event)
 
virtual void customReleaseEvent (KoPointerEvent *event)
 
virtual void cut ()
 
virtual QRectF decorationsRect () const
 
int decorationThickness () const
 decorationThickness The minimum thickness for tool decoration lines, this is derived from the screen magnification, thus the HiDPI settings. Note: to use this effectively, also set the pen to isCosmetic(true);
 
virtual void deleteSelection ()
 
virtual void deselect ()
 deselect the tool should clear the selection if it has one.
 
virtual void dragLeaveEvent (QDragLeaveEvent *event)
 
virtual void dragMoveEvent (QDragMoveEvent *event, const QPointF &point)
 
virtual void dropEvent (QDropEvent *event, const QPointF &point)
 
virtual void explicitUserStrokeEndRequest ()
 explicitUserStrokeEndRequest is called by the input manager when the user presses Enter key or any equivalent. This callback comes before requestStrokeEnd(), which comes from a different source.
 
KoToolFactoryBasefactory () const
 
virtual void focusInEvent (QFocusEvent *event)
 
virtual void focusOutEvent (QFocusEvent *event)
 
virtual bool hasSelection ()
 
virtual void inputMethodEvent (QInputMethodEvent *event)
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery query) const
 
bool isInTextMode () const
 
bool isOpacityPresetMode () const
 
virtual void keyPressEvent (QKeyEvent *event)
 
virtual void keyReleaseEvent (QKeyEvent *event)
 
 KoToolBase (KoCanvasBase *canvas)
 
bool maskSyntheticEvents () const
 
virtual void mouseDoubleClickEvent (KoPointerEvent *event)
 
virtual void mouseTripleClickEvent (KoPointerEvent *event)
 
QList< QPointer< QWidget > > optionWidgets ()
 
virtual bool paste ()
 
virtual QMenu * popupActionsMenu ()
 
virtual bool selectAll ()
 selectAll select all data the tool can select.
 
virtual KoToolSelectionselection ()
 
Q_INVOKABLE QString toolId () const
 
virtual bool wantsAutoScroll () const
 
 ~KoToolBase () override
 

Private Slots

void setAngle (int angle)
 
void setCaps (double caps)
 
void setDrag (double drag)
 
void setFixation (double fixation)
 
void setMass (double mass)
 
void setStrokeWidth (double width)
 
void setThinning (double thinning)
 
void setUseAngle (bool useAngle)
 
void setUsePath (bool usePath)
 
void setUsePressure (bool usePressure)
 
void updateSelectedPath ()
 

Private Member Functions

void addPoint (KoPointerEvent *event)
 
qreal calculateAngle (const QPointF &oldSpeed, const QPointF &newSpeed)
 
QPointF calculateNewPoint (const QPointF &mousePos, QPointF *speed)
 
qreal calculateWidth (qreal pressure)
 
void setAngle (KoPointerEvent *event)
 

Private Attributes

qreal m_angle
 
qreal m_caps
 
qreal m_customAngle
 
bool m_deviceSupportsTilt
 
qreal m_drag
 
bool m_endOfPath
 
qreal m_fixation
 
qreal m_followPathPosition
 
bool m_isDrawing
 
QPointF m_lastMousePos
 
QPointF m_lastPoint
 
qreal m_lastWidth
 
qreal m_mass
 
int m_pointCount
 
KoPathShapem_selectedPath
 
QPainterPath m_selectedPathOutline
 
KarbonCalligraphicShapem_shape
 
QPointF m_speed
 
qreal m_strokeWidth
 
qreal m_thinning
 
bool m_useAngle
 
bool m_usePath
 
bool m_usePressure
 
KarbonCalligraphyOptionWidgetm_widget {0}
 

Additional Inherited Members

- Public Slots inherited from KoToolBase
virtual void canvasResourceChanged (int key, const QVariant &res)
 
virtual void documentResourceChanged (int key, const QVariant &res)
 
virtual void repaintDecorations ()
 
virtual void requestRedoDuringStroke ()
 
virtual void requestStrokeCancellation ()
 
virtual void requestStrokeEnd ()
 
virtual void requestUndoDuringStroke ()
 
void setStatusText (const QString &statusText)
 
void updateOptionsWidgetIcons ()
 
- Protected Member Functions inherited from KoToolBase
virtual QWidget * createOptionWidget ()
 
int grabSensitivity () const
 Convenience function to get the current grab sensitivity.
 
qreal handleDocRadius () const
 
QRectF handleGrabRect (const QPointF &position) const
 
QRectF handlePaintRect (const QPointF &position) const
 
int handleRadius () const
 Convenience function to get the current handle radius.
 
bool isActivated () const
 
 KoToolBase (KoToolBasePrivate &dd)
 
KoPointerEventlastDeliveredPointerEvent () const
 
void setAbstractResource (KoAbstractCanvasResourceInterfaceSP abstractResource)
 
void setConverter (KoDerivedResourceConverterSP converter)
 
void setIsOpacityPresetMode (bool value)
 
void setMaskSyntheticEvents (bool value)
 
void setTextMode (bool value)
 
QHash< int, KoAbstractCanvasResourceInterfaceSPtoolAbstractResources ()
 
QHash< int, KoDerivedResourceConverterSPtoolConverters ()
 
void useCursor (const QCursor &cursor)
 
- Protected Attributes inherited from KoToolBase
KoToolBasePrivated_ptr
 

Detailed Description

Definition at line 20 of file KarbonCalligraphyTool.h.

Constructor & Destructor Documentation

◆ KarbonCalligraphyTool()

KarbonCalligraphyTool::KarbonCalligraphyTool ( KoCanvasBase * canvas)
explicit

Definition at line 39 of file KarbonCalligraphyTool.cpp.

41 , m_shape(0)
42 , m_angle(0)
44 , m_isDrawing(false)
45 , m_speed(0, 0)
46{
48
50}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
KarbonCalligraphicShape * m_shape
virtual KoSelectedShapesProxy * selectedShapesProxy() const =0
selectedShapesProxy() is a special interface for keeping a persistent connections to selectionChanged...
KoCanvasBase * canvas() const
Returns the canvas the tool is working on.
void selectionChanged(bool hasSelection)

References KoToolBase::canvas(), connect(), KoCanvasBase::selectedShapesProxy(), KoToolBase::selectionChanged(), and updateSelectedPath().

◆ ~KarbonCalligraphyTool()

KarbonCalligraphyTool::~KarbonCalligraphyTool ( )
override

Definition at line 52 of file KarbonCalligraphyTool.cpp.

53{
54}

Member Function Documentation

◆ activate()

void KarbonCalligraphyTool::activate ( const QSet< KoShape * > & shapes)
overridevirtual

This method is called when this tool instance is activated. For any main window there is only one tool active at a time, which then gets all user input. Switching between tools will call deactivate on one and activate on the new tool allowing the tool to flush items (like a selection) when it is not in use.

Parameters
shapesthe set of shapes that are selected or suggested for editing by a selected shape for the tool to work on. Not all shapes will be meant for this tool.
See also
deactivate()

Reimplemented from KoToolBase.

Definition at line 329 of file KarbonCalligraphyTool.cpp.

330{
331 KoToolBase::activate(shapes);
332
333 if (!m_widget) {
335 }
336
337 QAction *a = action("calligraphy_increase_width");
338 connect(a, SIGNAL(triggered()), m_widget, SLOT(increaseWidth()), Qt::UniqueConnection);
339
340 a = action("calligraphy_decrease_width");
341 connect(a, SIGNAL(triggered()), m_widget, SLOT(decreaseWidth()), Qt::UniqueConnection);
342
343 a = action("calligraphy_increase_angle");
344 connect(a, SIGNAL(triggered()), m_widget, SLOT(increaseAngle()), Qt::UniqueConnection);
345
346 a = action("calligraphy_decrease_angle");
347 connect(a, SIGNAL(triggered()), m_widget, SLOT(decreaseAngle()), Qt::UniqueConnection);
348
349
350 useCursor(Qt::CrossCursor);
351}
KarbonCalligraphyOptionWidget * m_widget
QList< QPointer< QWidget > > createOptionWidgets() override
void useCursor(const QCursor &cursor)
virtual void activate(const QSet< KoShape * > &shapes)
QAction * action(const QString &name) const

References KoToolBase::action(), KoToolBase::activate(), connect(), createOptionWidgets(), m_widget, and KoToolBase::useCursor().

◆ addPoint()

void KarbonCalligraphyTool::addPoint ( KoPointerEvent * event)
private

Definition at line 150 of file KarbonCalligraphyTool.cpp.

151{
152 if (m_pointCount == 0) {
153 if (m_usePath && m_selectedPath) {
155 }
156 m_pointCount = 1;
157 m_endOfPath = false;
159 m_lastMousePos = event->point;
161 m_deviceSupportsTilt = (event->xTilt() != 0 || event->yTilt() != 0);
162 return;
163 }
164
165 if (m_endOfPath) {
166 return;
167 }
168
169 ++m_pointCount;
170
171 setAngle(event);
172
173 QPointF newSpeed;
174 QPointF newPoint = calculateNewPoint(event->point, &newSpeed);
175 qreal width = calculateWidth(event->pressure());
176 qreal angle = calculateAngle(m_speed, newSpeed);
177
178 // add the previous point
179 m_shape->appendPoint(m_lastPoint, angle, width);
180
181 m_speed = newSpeed;
182 m_lastPoint = newPoint;
184
185 if (m_usePath && m_selectedPath) {
186 m_speed = QPointF(0, 0); // following path
187 }
188}
void appendPoint(const QPointF &p1, qreal angle, qreal width)
qreal calculateAngle(const QPointF &oldSpeed, const QPointF &newSpeed)
QPointF calculateNewPoint(const QPointF &mousePos, QPointF *speed)
qreal calculateWidth(qreal pressure)
virtual void updateCanvas(const QRectF &rc)=0
QPainterPath outline() const override
reimplemented
qreal pressure() const
QPointF point
The point in document coordinates.
QTransform absoluteTransformation() const
Definition KoShape.cpp:382

References KoShape::absoluteTransformation(), KarbonCalligraphicShape::appendPoint(), calculateAngle(), calculateNewPoint(), calculateWidth(), KoToolBase::canvas(), KarbonCalligraphicShape::lastPieceBoundingRect(), m_deviceSupportsTilt, m_endOfPath, m_followPathPosition, m_lastMousePos, m_lastPoint, m_pointCount, m_selectedPath, m_selectedPathOutline, m_shape, m_speed, m_usePath, KoPathShape::outline(), KoPointerEvent::point, KoPointerEvent::pressure(), setAngle(), and KoCanvasBase::updateCanvas().

◆ calculateAngle()

qreal KarbonCalligraphyTool::calculateAngle ( const QPointF & oldSpeed,
const QPointF & newSpeed )
private

Definition at line 271 of file KarbonCalligraphyTool.cpp.

272{
273 // calculate the average of the speed (sum of the normalized values)
274 qreal oldLength = QLineF(QPointF(0, 0), oldSpeed).length();
275 qreal newLength = QLineF(QPointF(0, 0), newSpeed).length();
276 QPointF oldSpeedNorm = !qFuzzyCompare(oldLength + 1, 1) ?
277 oldSpeed / oldLength : QPointF(0, 0);
278 QPointF newSpeedNorm = !qFuzzyCompare(newLength + 1, 1) ?
279 newSpeed / newLength : QPointF(0, 0);
280 QPointF speed = oldSpeedNorm + newSpeedNorm;
281
282 // angle solely based on the speed
283 qreal speedAngle = 0;
284 if (speed.x() != 0) { // avoid division by zero
285 speedAngle = std::atan(speed.y() / speed.x());
286 } else if (speed.y() > 0) {
287 // x == 0 && y != 0
288 speedAngle = M_PI / 2;
289 } else if (speed.y() < 0) {
290 // x == 0 && y != 0
291 speedAngle = -M_PI / 2;
292 }
293 if (speed.x() < 0) {
294 speedAngle += M_PI;
295 }
296
297 // move 90 degrees
298 speedAngle += M_PI / 2;
299
300 qreal fixedAngle = m_angle;
301 // check if the fixed angle needs to be flipped
302 qreal diff = fixedAngle - speedAngle;
303 while (diff >= M_PI) { // normalize diff between -180 and 180
304 diff -= 2 * M_PI;
305 }
306 while (diff < -M_PI) {
307 diff += 2 * M_PI;
308 }
309
310 if (std::abs(diff) > M_PI / 2) { // if absolute value < 90
311 fixedAngle += M_PI; // += 180
312 }
313
314 qreal dAngle = speedAngle - fixedAngle;
315
316 // normalize dAngle between -90 and +90
317 while (dAngle >= M_PI / 2) {
318 dAngle -= M_PI;
319 }
320 while (dAngle < -M_PI / 2) {
321 dAngle += M_PI;
322 }
323
324 qreal angle = fixedAngle + dAngle * (1.0 - m_fixation);
325
326 return angle;
327}
static bool qFuzzyCompare(half p1, half p2)
#define M_PI
Definition kis_global.h:111

References m_angle, m_fixation, M_PI, and qFuzzyCompare().

◆ calculateNewPoint()

QPointF KarbonCalligraphyTool::calculateNewPoint ( const QPointF & mousePos,
QPointF * speed )
private

Definition at line 218 of file KarbonCalligraphyTool.cpp.

219{
220 if (!m_usePath || !m_selectedPath) { // don't follow path
221 QPointF force = mousePos - m_lastPoint;
222 QPointF dSpeed = force / m_mass;
223 *speed = m_speed * (1.0 - m_drag) + dSpeed;
224 return m_lastPoint + *speed;
225 }
226
227 QPointF sp = mousePos - m_lastMousePos;
228 m_lastMousePos = mousePos;
229
230 // follow selected path
231 qreal step = QLineF(QPointF(0, 0), sp).length();
232 m_followPathPosition += step;
233
234 qreal t;
236 t = 1.0;
237 m_endOfPath = true;
238 } else {
239 t = m_selectedPathOutline.percentAtLength(m_followPathPosition);
240 }
241
242 QPointF res = m_selectedPathOutline.pointAtPercent(t);
243 *speed = res - m_lastPoint;
244 return res;
245}

References m_drag, m_endOfPath, m_followPathPosition, m_lastMousePos, m_lastPoint, m_mass, m_selectedPath, m_selectedPathOutline, m_speed, and m_usePath.

◆ calculateWidth()

qreal KarbonCalligraphyTool::calculateWidth ( qreal pressure)
private

Definition at line 247 of file KarbonCalligraphyTool.cpp.

248{
249 // calculate the modulo of the speed
250 qreal speed = std::sqrt(pow(m_speed.x(), 2) + pow(m_speed.y(), 2));
251 qreal thinning = m_thinning * (speed + 1) / 10.0; // can be negative
252
253 if (thinning > 1) {
254 thinning = 1;
255 }
256
257 if (!m_usePressure) {
258 pressure = 1.0;
259 }
260
261 qreal strokeWidth = m_strokeWidth * pressure * (1 - thinning);
262
263 const qreal MINIMUM_STROKE_WIDTH = 1.0;
264 if (strokeWidth < MINIMUM_STROKE_WIDTH) {
265 strokeWidth = MINIMUM_STROKE_WIDTH;
266 }
267
268 return strokeWidth;
269}

References m_speed, m_strokeWidth, m_thinning, and m_usePressure.

◆ createOptionWidgets()

QList< QPointer< QWidget > > KarbonCalligraphyTool::createOptionWidgets ( )
overridevirtual

Reimplemented from KoToolBase.

Definition at line 370 of file KarbonCalligraphyTool.cpp.

371{
372 // if the widget don't exists yet create it
373 QList<QPointer<QWidget> > widgets;
374
375 //KoFillConfigWidget *fillWidget = new KoFillConfigWidget(0);
376 //fillWidget->setWindowTitle(i18n("Fill"));
377 //widgets.append(fillWidget);
378
380 connect(m_widget, SIGNAL(usePathChanged(bool)),
381 this, SLOT(setUsePath(bool)));
382
383 connect(m_widget, SIGNAL(usePressureChanged(bool)),
384 this, SLOT(setUsePressure(bool)));
385
386 connect(m_widget, SIGNAL(useAngleChanged(bool)),
387 this, SLOT(setUseAngle(bool)));
388
389 connect(m_widget, SIGNAL(widthChanged(double)),
390 this, SLOT(setStrokeWidth(double)));
391
392 connect(m_widget, SIGNAL(thinningChanged(double)),
393 this, SLOT(setThinning(double)));
394
395 connect(m_widget, SIGNAL(angleChanged(int)),
396 this, SLOT(setAngle(int)));
397
398 connect(m_widget, SIGNAL(fixationChanged(double)),
399 this, SLOT(setFixation(double)));
400
401 connect(m_widget, SIGNAL(capsChanged(double)),
402 this, SLOT(setCaps(double)));
403
404 connect(m_widget, SIGNAL(massChanged(double)),
405 this, SLOT(setMass(double)));
406
407 connect(m_widget, SIGNAL(dragChanged(double)),
408 this, SLOT(setDrag(double)));
409
410 connect(this, SIGNAL(pathSelectedChanged(bool)),
411 m_widget, SLOT(setUsePathEnabled(bool)));
412
413 // sync all parameters with the loaded profile
414 m_widget->emitAll();
415 m_widget->setObjectName(i18nc("Object name of Calligraphy", "Calligraphy"));
416 m_widget->setWindowTitle(i18nc("Tool Option title of Calligraphy", "Calligraphy"));
417 widgets.append(m_widget);
418
419 return widgets;
420}
void setUseAngle(bool useAngle)
void setStrokeWidth(double width)
void setThinning(double thinning)
void pathSelectedChanged(bool selection)
void setUsePressure(bool usePressure)
void setFixation(double fixation)

References connect(), KarbonCalligraphyOptionWidget::emitAll(), m_widget, pathSelectedChanged(), setAngle(), setCaps(), setDrag(), setFixation(), setMass(), setStrokeWidth(), setThinning(), setUseAngle(), setUsePath(), and setUsePressure().

◆ deactivate()

void KarbonCalligraphyTool::deactivate ( )
overridevirtual

This method is called whenever this tool is no longer the active tool

See also
activate()

Reimplemented from KoToolBase.

Definition at line 353 of file KarbonCalligraphyTool.cpp.

354{
355 QAction *a = action("calligraphy_increase_width");
356 disconnect(a, 0, this, 0);
357
358 a = action("calligraphy_decrease_width");
359 disconnect(a, 0, this, 0);
360
361 a = action("calligraphy_increase_angle");
362 disconnect(a, 0, this, 0);
363
364 a = action("calligraphy_decrease_angle");
365 disconnect(a, 0, this, 0);
366
368}
virtual void deactivate()

References KoToolBase::action(), and KoToolBase::deactivate().

◆ mouseMoveEvent()

void KarbonCalligraphyTool::mouseMoveEvent ( KoPointerEvent * event)
overridevirtual

Called when the mouse or stylus moved over the canvas. Implementors should call event->ignore() if they do not actually use the event.

Parameters
eventstate and reason of this mouse or stylus move

Implements KoToolBase.

Definition at line 100 of file KarbonCalligraphyTool.cpp.

101{
102 if (!m_isDrawing) {
103 return;
104 }
105
106 addPoint(event);
107}
void addPoint(KoPointerEvent *event)

References addPoint(), and m_isDrawing.

◆ mousePressEvent()

void KarbonCalligraphyTool::mousePressEvent ( KoPointerEvent * event)
overridevirtual

Called when (one of) the mouse or stylus buttons is pressed. Implementors should call event->ignore() if they do not actually use the event.

Parameters
eventstate and reason of this mouse or stylus press

Implements KoToolBase.

Definition at line 84 of file KarbonCalligraphyTool.cpp.

85{
86 if (m_isDrawing) {
87 return;
88 }
89
90 m_lastPoint = event->point;
91 m_speed = QPointF(0, 0);
92
93 m_isDrawing = true;
94 m_pointCount = 0;
96 m_shape->setBackground(QSharedPointer<KoShapeBackground>(new KoColorBackground(canvas()->resourceManager()->foregroundColor().toQColor())));
97 //addPoint( event );
98}
A simple solid color shape background.
virtual void setBackground(QSharedPointer< KoShapeBackground > background)
Definition KoShape.cpp:918

References KoToolBase::canvas(), m_caps, m_isDrawing, m_lastPoint, m_pointCount, m_shape, m_speed, and KoShape::setBackground().

◆ mouseReleaseEvent()

void KarbonCalligraphyTool::mouseReleaseEvent ( KoPointerEvent * event)
overridevirtual

Called when (one of) the mouse or stylus buttons is released. Implementors should call event->ignore() if they do not actually use the event.

Parameters
eventstate and reason of this mouse or stylus release

Implements KoToolBase.

Definition at line 109 of file KarbonCalligraphyTool.cpp.

110{
111 if (!m_isDrawing) {
112 return;
113 }
114
115 if (m_pointCount == 0) {
116 // handle click: select shape (if any)
117 if (event->point == m_lastPoint) {
118 KoShapeManager *shapeManager = canvas()->shapeManager();
119 KoShape *selectedShape = shapeManager->shapeAt(event->point);
120 if (selectedShape != 0) {
121 shapeManager->selection()->deselectAll();
122 shapeManager->selection()->select(selectedShape);
123 }
124 }
125
126 delete m_shape;
127 m_shape = 0;
128 m_isDrawing = false;
129 return;
130 } else {
131 m_endOfPath = false; // allow last point being added
132 addPoint(event); // add last point
133 m_isDrawing = false;
134 }
135
137
138 KUndo2Command *cmd = canvas()->shapeController()->addShape(m_shape, 0);
139 if (cmd) {
140 canvas()->addCommand(cmd);
142 } else {
143 // don't leak shape when command could not be created
144 delete m_shape;
145 }
146
147 m_shape = 0;
148}
QPointer< KoShapeController > shapeController
virtual KoShapeManager * shapeManager() const =0
virtual void addCommand(KUndo2Command *command)=0
QRectF boundingRect() const override
reimplemented
void deselectAll()
clear the selections list
void select(KoShape *shape)
KoShape * shapeAt(const QPointF &position, KoFlake::ShapeSelection selection=KoFlake::ShapeOnTop, bool omitHiddenShapes=true)
KoSelection * selection

References KoCanvasBase::addCommand(), addPoint(), KoPathShape::boundingRect(), KoToolBase::canvas(), KoSelection::deselectAll(), m_endOfPath, m_isDrawing, m_lastPoint, m_pointCount, m_shape, KoPointerEvent::point, KoSelection::select(), KoShapeManager::selection, KoShapeManager::shapeAt(), KoCanvasBase::shapeController, KoCanvasBase::shapeManager(), KarbonCalligraphicShape::simplifyGuidePath(), and KoCanvasBase::updateCanvas().

◆ paint()

void KarbonCalligraphyTool::paint ( QPainter & painter,
const KoViewConverter & converter )
overridevirtual

Called by the canvas to paint any decorations that the tool deems needed. The painter has the top left of the canvas as its origin.

Parameters
painterused for painting the shape
converterto convert between internal and view coordinates.

Implements KoToolBase.

Definition at line 56 of file KarbonCalligraphyTool.cpp.

57{
58 if (m_selectedPath) {
59 painter.save();
60 painter.setRenderHints(QPainter::Antialiasing, false);
61 painter.setPen(Qt::red); // TODO make configurable
63 QPointF p1 = converter.documentToView(rect.topLeft());
64 QPointF p2 = converter.documentToView(rect.bottomRight());
65 painter.drawRect(QRectF(p1, p2));
66 painter.restore();
67 }
68
69 if (!m_shape) {
70 return;
71 }
72
73 painter.save();
74
75 painter.setTransform(m_shape->absoluteTransformation() *
76 converter.documentToView() *
77 painter.transform());
78
79 m_shape->paint(painter);
80
81 painter.restore();
82}
QPointF p2
QPointF p1
void paint(QPainter &painter) const override
reimplemented
virtual QPointF documentToView(const QPointF &documentPoint) const

References KoShape::absoluteTransformation(), KoPathShape::boundingRect(), KoViewConverter::documentToView(), m_selectedPath, m_shape, p1, p2, and KoPathShape::paint().

◆ pathSelectedChanged

void KarbonCalligraphyTool::pathSelectedChanged ( bool selection)
signal

◆ popupWidget()

KisPopupWidgetInterface * KarbonCalligraphyTool::popupWidget ( )
overridevirtual
Returns
a widget with useful controls to be popped up on top of the canvas. Will not be called if popupActionsMenu() does not return null.

Reimplemented from KoToolBase.

Definition at line 422 of file KarbonCalligraphyTool.cpp.

423{
424 return nullptr;
425}

◆ setAngle [1/2]

void KarbonCalligraphyTool::setAngle ( int angle)
privateslot

Definition at line 437 of file KarbonCalligraphyTool.cpp.

438{
439 m_customAngle = angle;
440}

References m_customAngle.

◆ setAngle() [2/2]

void KarbonCalligraphyTool::setAngle ( KoPointerEvent * event)
private

Definition at line 190 of file KarbonCalligraphyTool.cpp.

191{
192 if (!m_useAngle) {
193 m_angle = (360.0 - m_customAngle + 90.0) / 180.0 * M_PI;
194 return;
195 }
196
197 // setting m_angle to the angle of the device
198 if (event->xTilt() != 0 || event->yTilt() != 0) {
200 }
201
203 if (event->xTilt() == 0 && event->yTilt() == 0) {
204 return; // leave as is
205 }
206 if (event->x() == 0) {
207 m_angle = M_PI / 2.0;
208 return;
209 }
210
211 // y is inverted in qt painting
212 m_angle = std::atan(static_cast<double>(-event->yTilt()) / static_cast<double>(event->xTilt())) + M_PI / 2.0;
213 } else {
214 m_angle = event->rotation() + M_PI / 2.0;
215 }
216}
qreal yTilt() const
qreal xTilt() const

References m_angle, m_customAngle, m_deviceSupportsTilt, M_PI, m_useAngle, KoPointerEvent::x(), KoPointerEvent::xTilt(), and KoPointerEvent::yTilt().

◆ setCaps

void KarbonCalligraphyTool::setCaps ( double caps)
privateslot

Definition at line 472 of file KarbonCalligraphyTool.cpp.

473{
474 m_caps = caps;
475}

References m_caps.

◆ setDrag

void KarbonCalligraphyTool::setDrag ( double drag)
privateslot

Definition at line 452 of file KarbonCalligraphyTool.cpp.

453{
454 m_drag = drag;
455}

References m_drag.

◆ setFixation

void KarbonCalligraphyTool::setFixation ( double fixation)
privateslot

Definition at line 442 of file KarbonCalligraphyTool.cpp.

443{
444 m_fixation = fixation;
445}

References m_fixation.

◆ setMass

void KarbonCalligraphyTool::setMass ( double mass)
privateslot

Definition at line 447 of file KarbonCalligraphyTool.cpp.

448{
449 m_mass = mass * mass + 1;
450}

References m_mass.

◆ setStrokeWidth

void KarbonCalligraphyTool::setStrokeWidth ( double width)
privateslot

Definition at line 427 of file KarbonCalligraphyTool.cpp.

428{
429 m_strokeWidth = width;
430}

References m_strokeWidth.

◆ setThinning

void KarbonCalligraphyTool::setThinning ( double thinning)
privateslot

Definition at line 432 of file KarbonCalligraphyTool.cpp.

433{
434 m_thinning = thinning;
435}

References m_thinning.

◆ setUseAngle

void KarbonCalligraphyTool::setUseAngle ( bool useAngle)
privateslot

Definition at line 467 of file KarbonCalligraphyTool.cpp.

468{
469 m_useAngle = useAngle;
470}

References m_useAngle.

◆ setUsePath

void KarbonCalligraphyTool::setUsePath ( bool usePath)
privateslot

Definition at line 457 of file KarbonCalligraphyTool.cpp.

458{
459 m_usePath = usePath;
460}

References m_usePath.

◆ setUsePressure

void KarbonCalligraphyTool::setUsePressure ( bool usePressure)
privateslot

Definition at line 462 of file KarbonCalligraphyTool.cpp.

463{
464 m_usePressure = usePressure;
465}

References m_usePressure.

◆ updateSelectedPath

void KarbonCalligraphyTool::updateSelectedPath ( )
privateslot

Definition at line 477 of file KarbonCalligraphyTool.cpp.

478{
479 KoPathShape *oldSelectedPath = m_selectedPath; // save old value
480
482 if (selection) {
483 // null pointer if it the selection isn't a KoPathShape
484 // or if the selection is empty
486 dynamic_cast<KoPathShape *>(selection->firstSelectedShape());
487
488 // or if it's a KoPathShape but with no or more than one subpaths
490 m_selectedPath = 0;
491 }
492
493 // or if there ora none or more than 1 shapes selected
494 if (selection->count() != 1) {
495 m_selectedPath = 0;
496 }
497
498 // Q_EMIT signal it there wasn't a selected path and now there is
499 // or the other way around
500 if ((m_selectedPath != 0) != (oldSelectedPath != 0)) {
502 }
503 }
504}
The position of a path point within a path shape.
Definition KoPathShape.h:63
int subpathCount() const
Returns the number of subpaths in the path.
virtual KoToolSelection * selection()

References KoToolBase::canvas(), m_selectedPath, pathSelectedChanged(), KoShapeManager::selection, KoToolBase::selection(), KoCanvasBase::shapeManager(), and KoPathShape::subpathCount().

Member Data Documentation

◆ m_angle

qreal KarbonCalligraphyTool::m_angle
private

Definition at line 79 of file KarbonCalligraphyTool.h.

◆ m_caps

qreal KarbonCalligraphyTool::m_caps
private

Definition at line 82 of file KarbonCalligraphyTool.h.

◆ m_customAngle

qreal KarbonCalligraphyTool::m_customAngle
private

Definition at line 78 of file KarbonCalligraphyTool.h.

◆ m_deviceSupportsTilt

bool KarbonCalligraphyTool::m_deviceSupportsTilt
private

Definition at line 71 of file KarbonCalligraphyTool.h.

◆ m_drag

qreal KarbonCalligraphyTool::m_drag
private

Definition at line 84 of file KarbonCalligraphyTool.h.

◆ m_endOfPath

bool KarbonCalligraphyTool::m_endOfPath
private

Definition at line 89 of file KarbonCalligraphyTool.h.

◆ m_fixation

qreal KarbonCalligraphyTool::m_fixation
private

Definition at line 80 of file KarbonCalligraphyTool.h.

◆ m_followPathPosition

qreal KarbonCalligraphyTool::m_followPathPosition
private

Definition at line 88 of file KarbonCalligraphyTool.h.

◆ m_isDrawing

bool KarbonCalligraphyTool::m_isDrawing
private

Definition at line 92 of file KarbonCalligraphyTool.h.

◆ m_lastMousePos

QPointF KarbonCalligraphyTool::m_lastMousePos
private

Definition at line 90 of file KarbonCalligraphyTool.h.

◆ m_lastPoint

QPointF KarbonCalligraphyTool::m_lastPoint
private

Definition at line 67 of file KarbonCalligraphyTool.h.

◆ m_lastWidth

qreal KarbonCalligraphyTool::m_lastWidth
private

Definition at line 77 of file KarbonCalligraphyTool.h.

◆ m_mass

qreal KarbonCalligraphyTool::m_mass
private

Definition at line 83 of file KarbonCalligraphyTool.h.

◆ m_pointCount

int KarbonCalligraphyTool::m_pointCount
private

Definition at line 93 of file KarbonCalligraphyTool.h.

◆ m_selectedPath

KoPathShape* KarbonCalligraphyTool::m_selectedPath
private

Definition at line 86 of file KarbonCalligraphyTool.h.

◆ m_selectedPathOutline

QPainterPath KarbonCalligraphyTool::m_selectedPathOutline
private

Definition at line 87 of file KarbonCalligraphyTool.h.

◆ m_shape

KarbonCalligraphicShape* KarbonCalligraphyTool::m_shape
private

Definition at line 68 of file KarbonCalligraphyTool.h.

◆ m_speed

QPointF KarbonCalligraphyTool::m_speed
private

Definition at line 96 of file KarbonCalligraphyTool.h.

◆ m_strokeWidth

qreal KarbonCalligraphyTool::m_strokeWidth
private

Definition at line 76 of file KarbonCalligraphyTool.h.

◆ m_thinning

qreal KarbonCalligraphyTool::m_thinning
private

Definition at line 81 of file KarbonCalligraphyTool.h.

◆ m_useAngle

bool KarbonCalligraphyTool::m_useAngle
private

Definition at line 75 of file KarbonCalligraphyTool.h.

◆ m_usePath

bool KarbonCalligraphyTool::m_usePath
private

Definition at line 73 of file KarbonCalligraphyTool.h.

◆ m_usePressure

bool KarbonCalligraphyTool::m_usePressure
private

Definition at line 74 of file KarbonCalligraphyTool.h.

◆ m_widget

KarbonCalligraphyOptionWidget* KarbonCalligraphyTool::m_widget {0}
private

Definition at line 98 of file KarbonCalligraphyTool.h.

98{0};

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