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

#include <kis_tool_dyna.h>

+ Inheritance diagram for KisToolDyna:

Public Member Functions

void activate (const QSet< KoShape * > &shapes) override
 
void beginPrimaryAction (KoPointerEvent *event) override
 
void continuePrimaryAction (KoPointerEvent *event) override
 
QWidget * createOptionWidget () override
 
 KisToolDyna (KoCanvasBase *canvas)
 
 ~KisToolDyna () override
 
- Public Member Functions inherited from KisToolFreehand
int flags () const override
 
 KisToolFreehand (KoCanvasBase *canvas, const QCursor &cursor, const KUndo2MagicString &transactionText, bool useSavedSmoothing=true)
 
void mouseMoveEvent (KoPointerEvent *event) override
 
 ~KisToolFreehand () override
 
- Public Member Functions inherited from KisToolPaint
int flags () const override
 
 KisToolPaint (KoCanvasBase *canvas, const QCursor &cursor)
 
void mouseMoveEvent (KoPointerEvent *event) override
 
void mousePressEvent (KoPointerEvent *event) override
 
void mouseReleaseEvent (KoPointerEvent *event) override
 
KisPopupWidgetInterfacepopupWidget () override
 
 ~KisToolPaint () override
 
- Public Member Functions inherited from KisTool
virtual bool alternateActionSupportsHiResEvents (AlternateAction action) const
 
virtual void beginAlternateDoubleClickAction (KoPointerEvent *event, AlternateAction action)
 
virtual void beginPrimaryDoubleClickAction (KoPointerEvent *event)
 
void deleteSelection () override
 
bool isActive () const
 
 KisTool (KoCanvasBase *canvas, const QCursor &cursor)
 
void mouseDoubleClickEvent (KoPointerEvent *event) override
 
void mouseTripleClickEvent (KoPointerEvent *event) override
 
virtual void newActivationWithExternalSource (KisPaintDeviceSP externalSource)
 newActivationWithExternalSource Makes sure that the tool is active and starts a new stroke, which will be able to access the pixels from the specified external source.
 
KisTool::NodePaintAbility nodePaintAbility ()
 
 ~KisTool () override
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 
- 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 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
 
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
 
 ~KoToolBase () override
 

Protected Slots

void resetCursorStyle () override
 
- Protected Slots inherited from KisToolFreehand
void explicitUpdateOutline ()
 
void resetCursorStyle () override
 
void setAssistant (bool assistant)
 
void setOnlyOneAssistantSnap (bool assistant)
 
void setSnapEraser (bool assistant)
 
void slotDoResizeBrush (qreal newSize)
 
- Protected Slots inherited from KisTool
virtual void resetCursorStyle ()
 

Protected Member Functions

void initStroke (KoPointerEvent *event) override
 
- Protected Member Functions inherited from KisToolFreehand
void activateAlternateAction (AlternateAction action) override
 
void beginAlternateAction (KoPointerEvent *event, AlternateAction action) override
 
void beginPrimaryAction (KoPointerEvent *event) override
 
void continueAlternateAction (KoPointerEvent *event, AlternateAction action) override
 
void continuePrimaryAction (KoPointerEvent *event) override
 
void deactivateAlternateAction (AlternateAction action) override
 
virtual void doStroke (KoPointerEvent *event)
 
void endAlternateAction (KoPointerEvent *event, AlternateAction action) override
 
void endPrimaryAction (KoPointerEvent *event) override
 
virtual void endStroke ()
 
KisOptimizedBrushOutline getOutlinePath (const QPointF &documentPos, const KoPointerEvent *event, KisPaintOpSettings::OutlineMode outlineMode) override
 
KisPaintingInformationBuilderpaintingInformationBuilder () const
 
bool primaryActionSupportsHiResEvents () const override
 
void resetHelper (KisToolFreehandHelper *helper)
 
KisSmoothingOptionsSP smoothingOptions () const
 
bool supportsPaintingAssistants () const override
 
bool trySampleByPaintOp (KoPointerEvent *event, AlternateAction action)
 
bool wantsAutoScroll () const override
 
- Protected Member Functions inherited from KisToolPaint
void activateAlternateAction (AlternateAction action) override
 
void activatePrimaryAction () override
 
void addOptionWidgetLayout (QLayout *layout)
 Add the tool-specific layout to the default option widget layout.
 
virtual void addOptionWidgetOption (QWidget *control, QWidget *label=nullptr)
 Add a widget and a label to the current option widget layout.
 
void beginAlternateAction (KoPointerEvent *event, AlternateAction action) override
 
void canvasResourceChanged (int key, const QVariant &v) override
 
void continueAlternateAction (KoPointerEvent *event, AlternateAction action) override
 
QWidget * createOptionWidget () override
 
void deactivateAlternateAction (AlternateAction action) override
 
void deactivatePrimaryAction () override
 
void enableControl (QWidget *control, bool value)
 
void endAlternateAction (KoPointerEvent *event, AlternateAction action) override
 
bool isEraser () const
 
bool isOutlineEnabled () const
 
bool isOutlineVisible () const
 
void paint (QPainter &gc, const KoViewConverter &converter) override
 
virtual QString quickHelp () const
 
virtual void requestUpdateOutline (const QPointF &outlineDocPoint, const KoPointerEvent *event)
 
void setMode (ToolMode mode) override
 
void setOutlineEnabled (bool enabled)
 
void setOutlineVisible (bool visible)
 
void setSupportOutline (bool supportOutline)
 
void showControl (QWidget *control, bool value)
 
- Protected Member Functions inherited from KisTool
bool blockUntilOperationsFinished ()
 
void blockUntilOperationsFinishedForced ()
 
QPointF convertDocumentToWidget (const QPointF &pt)
 
QPoint convertToImagePixelCoordFloored (KoPointerEvent *e)
 
QPointF convertToPixelCoord (const QPointF &pt)
 
QPointF convertToPixelCoord (KoPointerEvent *e)
 
QPointF convertToPixelCoordAndAlignOnWidget (const QPointF &pt)
 
QPointF convertToPixelCoordAndSnap (const QPointF &pt, const QPointF &offset=QPointF())
 
QPointF convertToPixelCoordAndSnap (KoPointerEvent *e, const QPointF &offset=QPointF(), bool useModifiers=true)
 
QRectF convertToPt (const QRectF &rect)
 
qreal convertToPt (qreal value)
 
KoColor currentBgColor ()
 
KoColor currentFgColor ()
 
KisFilterConfigurationSP currentGenerator ()
 
KoAbstractGradientSP currentGradient ()
 
KisImageWSP currentImage ()
 
KisNodeSP currentNode () const
 
KisPaintOpPresetSP currentPaintOpPreset ()
 
KoPatternSP currentPattern ()
 
QCursor cursor () const
 
KisImageWSP image () const
 
virtual bool listeningToModifiers ()
 
virtual void listenToModifiers (bool listen)
 
virtual ToolMode mode () const
 
bool nodeEditable ()
 Checks checks if the current node is editable.
 
bool overrideCursorIfNotEditable ()
 Override the cursor appropriately if current node is not editable.
 
void paintToolOutline (QPainter *painter, const KisOptimizedBrushOutline &path)
 
KisOptimizedBrushOutline pixelToView (const KisOptimizedBrushOutline &path) const
 
QPainterPath pixelToView (const QPainterPath &pixelPath) const
 Convert a pixel path into a view path.
 
QPointF pixelToView (const QPoint &pixelCoord) const
 
QPointF pixelToView (const QPointF &pixelCoord) const
 Convert a floating point pixel coordinate into a view coordinate.
 
QPolygonF pixelToView (const QPolygonF &pixelPolygon) const
 Convert a pixel polygon into a view path.
 
QRectF pixelToView (const QRectF &pixelRect) const
 Convert a pixel rectangle into a view rectangle.
 
KisNodeList selectedNodes () const
 
bool selectionEditable ()
 Checks checks if the selection is editable, only applies to local selection as global selection is always editable.
 
void setCursor (const QCursor &cursor)
 
void updateCanvasPixelRect (const QRectF &pixelRect)
 Update the canvas for the given rectangle in image pixel coordinates.
 
void updateCanvasViewRect (const QRectF &viewRect)
 Update the canvas for the given rectangle in view coordinates.
 
QPointF viewToPixel (const QPointF &viewCoord) const
 
QPointF widgetCenterInWidgetPixels ()
 
- Protected Member Functions inherited from KoToolBase
virtual QList< QPointer< QWidget > > createOptionWidgets ()
 
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)
 

Private Slots

void slotSetAngle (qreal angle)
 
void slotSetDrag (qreal drag)
 
void slotSetDynaWidth (double width)
 
void slotSetFixedAngle (bool fixedAngle)
 
void slotSetMass (qreal mass)
 
void slotSetWidthRange (double widthRange)
 

Private Member Functions

int applyFilter (qreal mx, qreal my)
 
KoPointerEvent filterEvent (KoPointerEvent *event)
 
qreal flerp (qreal f0, qreal f1, qreal p)
 
void initDyna ()
 
void setMousePosition (const QPointF &point)
 

Private Attributes

KisAngleSelectorm_angleSelector {nullptr}
 
QCheckBox * m_chkFixedAngle {nullptr}
 
KConfigGroup m_configGroup
 
qreal m_curdrag {0.0}
 
qreal m_curmass {0.0}
 
KisDoubleSliderSpinBoxm_dragSPBox {nullptr}
 
KisDoubleSliderSpinBoxm_massSPBox {nullptr}
 
DynaFilter m_mouse
 
QPointF m_mousePos
 
qreal m_odelx {0.0}
 
qreal m_odely {0.0}
 
QGridLayout * m_optionLayout {nullptr}
 
QVector< QPointF > m_prevPosition
 
qreal m_surfaceHeight {0.0}
 
qreal m_surfaceWidth {0.0}
 
qreal m_width {0.0}
 
qreal m_widthRange {0.0}
 
qreal m_xangle {0.0}
 
qreal m_yangle {0.0}
 

Additional Inherited Members

- Public Types inherited from KisTool
enum  { FLAG_USES_CUSTOM_PRESET =0x01 , FLAG_USES_CUSTOM_COMPOSITEOP =0x02 , FLAG_USES_CUSTOM_SIZE =0x04 }
 
enum  AlternateAction {
  ChangeSize = AlternateChangeSize , ChangeSizeSnap = AlternateChangeSizeSnap , SampleFgNode = AlternateSampleFgNode , SampleBgNode = AlternateSampleBgNode ,
  SampleFgImage = AlternateSampleFgImage , SampleBgImage = AlternateSampleBgImage , Secondary = AlternateSecondary , Third = AlternateThird ,
  Fourth = AlternateFourth , Fifth = AlternateFifth , NONE = 10000
}
 
enum  NodePaintAbility {
  VECTOR , CLONE , PAINT , UNPAINTABLE ,
  MYPAINTBRUSH_UNPAINTABLE
}
 
enum  ToolAction {
  Primary , AlternateChangeSize , AlternateChangeSizeSnap , AlternateSampleFgNode ,
  AlternateSampleBgNode , AlternateSampleFgImage , AlternateSampleBgImage , AlternateSecondary ,
  AlternateThird , AlternateFourth , AlternateFifth , Alternate_NONE = 10000
}
 
- Public Slots inherited from KisToolFreehand
void activate (const QSet< KoShape * > &shapes) override
 
void deactivate () override
 
- Public Slots inherited from KisToolPaint
void activate (const QSet< KoShape * > &shapes) override
 
void deactivate () override
 
- Public Slots inherited from KisTool
void activate (const QSet< KoShape * > &shapes) override
 
void canvasResourceChanged (int key, const QVariant &res) override
 
void deactivate () override
 
virtual void updateSettingsViews ()
 
- Public Slots inherited from KoToolBase
virtual void deactivate ()
 
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 ()
 
- Signals inherited from KisToolPaint
void sigPaintingFinished ()
 
- Signals inherited from KisTool
void isActiveChanged (bool isActivated)
 
- 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)
 
- Static Public Member Functions inherited from KisTool
static AlternateAction actionToAlternateAction (ToolAction action)
 
- Public Attributes inherited from KisTool
KoColor currentBgColor
 
float currentExposure {1.0}
 
KoColor currentFgColor
 
KisFilterConfigurationSP currentGenerator
 
KoAbstractGradientSP currentGradient
 
KoPatternSP currentPattern
 
QCursor cursor
 
bool m_isActive {false}
 
ToolMode m_mode {HOVER_MODE}
 
QWidget * optionWidget {0}
 
- Public Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 
- Protected Types inherited from KisTool
enum  ToolMode : int {
  HOVER_MODE , PAINT_MODE , SECONDARY_PAINT_MODE , MIRROR_AXIS_SETUP_MODE ,
  GESTURE_MODE , PAN_MODE , OTHER , OTHER_1
}
 
- Protected Attributes inherited from KisToolFreehand
bool m_assistant {false}
 
bool m_eraser_snapping {false}
 
double m_magnetism {1.0}
 
bool m_only_one_assistant {true}
 
- Protected Attributes inherited from KisToolPaint
KisOptimizedBrushOutline m_currentOutline
 
QRectF m_oldColorPreviewUpdateRect
 
QRectF m_oldOutlineRect
 
QPointF m_outlineDocPoint
 
bool m_paintOutline {false}
 
- Protected Attributes inherited from KoToolBase
KoToolBasePrivated_ptr
 
- Properties inherited from KisTool
bool isActive
 

Detailed Description

Definition at line 57 of file kis_tool_dyna.h.

Constructor & Destructor Documentation

◆ KisToolDyna()

KisToolDyna::KisToolDyna ( KoCanvasBase * canvas)

Definition at line 37 of file kis_tool_dyna.cpp.

38 : KisToolFreehand(canvas, KisCursor::load("tool_freehand_cursor.xpm", 2, 2), kundo2_i18n("Dynamic Brush Stroke"), false)
39{
40 setObjectName("tool_dyna");
42 initDyna();
43}
static QCursor load(const QString &cursorName, int hotspotX=-1, int hotspotY=-1)
KisToolFreehand(KoCanvasBase *canvas, const QCursor &cursor, const KUndo2MagicString &transactionText, bool useSavedSmoothing=true)
void setIsOpacityPresetMode(bool value)
KUndo2MagicString kundo2_i18n(const char *text)
KisCanvas2 * canvas

References initDyna(), and KoToolBase::setIsOpacityPresetMode().

◆ ~KisToolDyna()

KisToolDyna::~KisToolDyna ( )
override

Definition at line 59 of file kis_tool_dyna.cpp.

60{
61}

Member Function Documentation

◆ activate()

void KisToolDyna::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 70 of file kis_tool_dyna.cpp.

71{
73 m_configGroup = KSharedConfig::openConfig()->group(toolId());
74}
KConfigGroup m_configGroup
void activate(const QSet< KoShape * > &shapes) override
Q_INVOKABLE QString toolId() const

References KisToolPaint::activate(), m_configGroup, and KoToolBase::toolId().

◆ applyFilter()

int KisToolDyna::applyFilter ( qreal mx,
qreal my )
private

Definition at line 109 of file kis_tool_dyna.cpp.

110{
111 /* calculate mass and drag */
112 qreal mass = flerp(MIN_MASS, MAX_MASS, m_curmass);
113 qreal drag = flerp(MIN_DRAG, MAX_DRAG, m_curdrag * m_curdrag);
114
115 /* calculate force and acceleration */
116 qreal fx = mx - m_mouse.curx;
117 qreal fy = my - m_mouse.cury;
118
119 m_mouse.acc = sqrt(fx * fx + fy * fy);
120
121 if (m_mouse.acc < MIN_ACC) {
122 return 0;
123 }
124
125 m_mouse.accx = fx / mass;
126 m_mouse.accy = fy / mass;
127
128 /* calculate new velocity */
134 if (m_mouse.vel < MIN_VEL) {
135 return 0;
136 }
137
138 /* calculate angle of drawing tool */
139 if (m_mouse.fixedangle) {
142 } else {
145 }
146
147 m_mouse.velx = m_mouse.velx * (1.0 - drag);
148 m_mouse.vely = m_mouse.vely * (1.0 - drag);
149
154
155 return 1;
156}
DynaFilter m_mouse
qreal flerp(qreal f0, qreal f1, qreal p)
#define MIN_MASS
#define MAX_DRAG
#define MIN_VEL
#define MIN_ACC
#define MAX_MASS
#define MIN_DRAG

References DynaFilter::acc, DynaFilter::accx, DynaFilter::accy, DynaFilter::angx, DynaFilter::angy, DynaFilter::curx, DynaFilter::cury, DynaFilter::fixedangle, flerp(), DynaFilter::lastx, DynaFilter::lasty, m_curdrag, m_curmass, m_mouse, m_xangle, m_yangle, MAX_DRAG, MAX_MASS, MIN_ACC, MIN_DRAG, MIN_MASS, MIN_VEL, DynaFilter::vel, DynaFilter::velx, and DynaFilter::vely.

◆ beginPrimaryAction()

void KisToolDyna::beginPrimaryAction ( KoPointerEvent * event)
overridevirtual

Called by KisToolProxy when a primary action for the tool is started. The event stores the original event that started the stroke. The event is accepted by default. If the tool decides to ignore this particular action (e.g. when the node is not editable), it should call event->ignore(). Then no further continuePrimaryAction() or endPrimaryAction() will be called until the next user action.

Reimplemented from KisTool.

Definition at line 88 of file kis_tool_dyna.cpp.

89{
90 setMousePosition(event->point);
92 m_odelx = m_mousePos.x();
93 m_odely = m_mousePos.y();
94
96}
void init(qreal x, qreal y)
void setMousePosition(const QPointF &point)
QPointF m_mousePos
void beginPrimaryAction(KoPointerEvent *event) override
QPointF point
The point in document coordinates.

References KisToolFreehand::beginPrimaryAction(), DynaFilter::init(), m_mouse, m_mousePos, m_odelx, m_odely, KoPointerEvent::point, and setMousePosition().

◆ continuePrimaryAction()

void KisToolDyna::continuePrimaryAction ( KoPointerEvent * event)
overridevirtual

Called by KisToolProxy when the primary action is in progress of pointer movement. If the tool has ignored the event in beginPrimaryAction(), this method will not be called.

Reimplemented from KisTool.

Definition at line 98 of file kis_tool_dyna.cpp.

99{
100 setMousePosition(event->point);
101
102 if (applyFilter(m_mousePos.x(), m_mousePos.y())) {
103 KoPointerEvent newEvent = filterEvent(event);
105 }
106}
int applyFilter(qreal mx, qreal my)
KoPointerEvent filterEvent(KoPointerEvent *event)
void continuePrimaryAction(KoPointerEvent *event) override

References applyFilter(), KisToolFreehand::continuePrimaryAction(), filterEvent(), m_mousePos, KoPointerEvent::point, and setMousePosition().

◆ createOptionWidget()

QWidget * KisToolDyna::createOptionWidget ( )
overridevirtual

Reimplement this if your tool actually has an option widget. Sets the option widget to 0 by default.

Reimplemented from KisTool.

Definition at line 266 of file kis_tool_dyna.cpp.

267{
268
269 QWidget * optionsWidget = KisToolFreehand::createOptionWidget();
270 optionsWidget->setObjectName(toolId() + " option widget");
271
272 m_optionLayout = new QGridLayout();
273
274 m_optionLayout->setContentsMargins(0, 0, 0, 0);
275 m_optionLayout->setSpacing(2);
277
278 QLabel* massLbl = new QLabel(i18n("Mass:"), optionsWidget);
279 m_massSPBox = new KisDoubleSliderSpinBox(optionsWidget);
280 m_massSPBox->setRange(0.0,1.0,2);
281 m_massSPBox->setSingleStep(0.01);
282 connect(m_massSPBox, SIGNAL(valueChanged(qreal)), this, SLOT(slotSetMass(qreal)));
284
285 QLabel* dragLbl = new QLabel(i18n("Drag:"), optionsWidget);
286 m_dragSPBox = new KisDoubleSliderSpinBox(optionsWidget);
287 m_dragSPBox->setRange(0.0,1.0,2);
288 m_dragSPBox->setSingleStep(0.01);
289 connect(m_dragSPBox, SIGNAL(valueChanged(qreal)), this, SLOT(slotSetDrag(qreal)));
291
292 //NOTE: so far unused, waiting for the changes to propagate rotation/pressure to freehand tool
293 // fixed angle might be for 2.4, but the later one for 2.5
294 m_chkFixedAngle = new QCheckBox(i18n("Fixed angle:"), optionsWidget);
295 m_chkFixedAngle->setEnabled(false);
296 connect(m_chkFixedAngle, SIGNAL(toggled(bool)), this, SLOT(slotSetFixedAngle(bool)));
297
298 m_angleSelector = new KisAngleSelector(optionsWidget);
302 m_angleSelector->setEnabled(false);
303 connect(m_angleSelector, SIGNAL(angleChanged(qreal)), this, SLOT(slotSetAngle(qreal)));
304
306
307 // read settings in from config
308 m_massSPBox->setValue(m_configGroup.readEntry("massAmount", 0.01));
309 m_dragSPBox->setValue(m_configGroup.readEntry("dragAmount", .98));
310 m_chkFixedAngle->setChecked((bool)m_configGroup.readEntry("useFixedAngle", false));
311 m_angleSelector->setAngle(m_configGroup.readEntry("angleAmount", 20));
312
313
314#if 0
315 QLabel* initWidthLbl = new QLabel(i18n("Initial width:"), optionWidget);
316 m_initWidthSPBox = new QDoubleSpinBox(optionWidget);
317 connect(m_initWidthSPBox, SIGNAL(valueChanged(double)), this, SLOT(slotSetDynaWidth(double)));
318 KisToolFreehand::addOptionWidgetOption(m_initWidthSPBox,initWidthLbl);
319
320 QLabel* widthRangeLbl = new QLabel(i18n("Width range:"), optionWidget);
321 m_widthRangeSPBox = new QDoubleSpinBox(optionWidget);
322 connect(m_widthRangeSPBox, SIGNAL(valueChanged(double)), this, SLOT(slotSetWidthRange(double)));
323 //KisToolFreehand::addOptionWidgetOption(m_widthRangeSPBox,widthRangeLbl);
324
325 m_initWidthSPBox->setValue(m_configGroup.readEntry("initWidth", 10));
326 m_widthRangeSPBox->setValue(m_configGroup.readEntry("initWidthRange", 20));
327
328
329#endif
330
331 return optionsWidget;
332}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
@ IncreasingDirection_Clockwise
A widget with several options to select an angle.
@ FlipOptionsMode_MenuButton
The flip options are shown as a menu accessible via a options button.
void setFlipOptionsMode(FlipOptionsMode newMode)
Sets the mode in which the flip options should be shown.
void setIncreasingDirection(KisAngleGauge::IncreasingDirection newIncreasingDirection)
Sets the increasing direction in the angle gauge.
void setAngle(qreal newAngle)
Sets the current angle.
void setDecimals(int newNumberOfDecimals)
Sets the number of decimals (precision) used by the angle.
This class is a spinbox in which you can click and drag to set the value. A slider like bar is displa...
void setValue(qreal newValue)
void setRange(qreal newMinimum, qreal newMaximum, int newNumberOfDecimals=0, bool computeNewFastSliderStep=true)
Set the minimum and the maximum values of the range.
QCheckBox * m_chkFixedAngle
void slotSetFixedAngle(bool fixedAngle)
QGridLayout * m_optionLayout
KisDoubleSliderSpinBox * m_massSPBox
void slotSetMass(qreal mass)
KisAngleSelector * m_angleSelector
void slotSetDynaWidth(double width)
void slotSetDrag(qreal drag)
void slotSetAngle(qreal angle)
void slotSetWidthRange(double widthRange)
KisDoubleSliderSpinBox * m_dragSPBox
void addOptionWidgetLayout(QLayout *layout)
Add the tool-specific layout to the default option widget layout.
virtual void addOptionWidgetOption(QWidget *control, QWidget *label=nullptr)
Add a widget and a label to the current option widget layout.
virtual QWidget * createOptionWidget()
QWidget * optionWidget
Definition kis_tool.cc:73

References KisToolPaint::addOptionWidgetLayout(), KisToolPaint::addOptionWidgetOption(), connect(), KoToolBase::createOptionWidget(), KisAngleSelector::FlipOptionsMode_MenuButton, KisAngleGauge::IncreasingDirection_Clockwise, m_angleSelector, m_chkFixedAngle, m_configGroup, m_dragSPBox, m_massSPBox, m_optionLayout, KisTool::optionWidget, KisAngleSelector::setAngle(), KisAngleSelector::setDecimals(), KisAngleSelector::setFlipOptionsMode(), KisAngleSelector::setIncreasingDirection(), KisDoubleSliderSpinBox::setRange(), KisDoubleSliderSpinBox::setValue(), slotSetAngle(), slotSetDrag(), slotSetDynaWidth(), slotSetFixedAngle(), slotSetMass(), slotSetWidthRange(), and KoToolBase::toolId().

◆ filterEvent()

KoPointerEvent KisToolDyna::filterEvent ( KoPointerEvent * event)
private

Definition at line 159 of file kis_tool_dyna.cpp.

160{
161 qreal wid = m_widthRange - m_mouse.vel;
162
163 wid = wid * m_width;
164
165 if (wid < 0.00001) {
166 wid = 0.00001;
167 }
168
169 qreal delx = m_mouse.angx * wid;
170 qreal dely = m_mouse.angy * wid;
171
172 qreal px = m_mouse.lastx;
173 qreal py = m_mouse.lasty;
174 qreal nx = m_mouse.curx;
175 qreal ny = m_mouse.cury;
176
177 QPointF prev(px , py); // previous position
178 QPointF now(nx , ny); // new position
179
180 QPointF prevr(px + m_odelx , py + m_odely);
181 QPointF prevl(px - m_odelx , py - m_odely);
182
183 QPointF nowl(nx - delx , ny - dely);
184 QPointF nowr(nx + delx , ny + dely);
185
186 // transform coords from float points into image points
187 prev.rx() *= m_surfaceWidth;
188 prevr.rx() *= m_surfaceWidth;
189 prevl.rx() *= m_surfaceWidth;
190 now.rx() *= m_surfaceWidth;
191 nowl.rx() *= m_surfaceWidth;
192 nowr.rx() *= m_surfaceWidth;
193
194 prev.ry() *= m_surfaceHeight;
195 prevr.ry() *= m_surfaceHeight;
196 prevl.ry() *= m_surfaceHeight;
197 now.ry() *= m_surfaceHeight;
198 nowl.ry() *= m_surfaceHeight;
199 nowr.ry() *= m_surfaceHeight;
200
201#if 0
202
203 qreal xTilt, yTilt;
204 qreal m_rotation;
205 qreal m_tangentialPressure;
206
207 // some funny debugging
208 dbgPlugins << "m_mouse.vel: " << m_mouse.vel;
209 dbgPlugins << "m_mouse.velx: " << m_mouse.velx;
210 dbgPlugins << "m_mouse.vely: " << m_mouse.vely;
211 dbgPlugins << "m_mouse.accx: " << m_mouse.accx;
212 dbgPlugins << "m_mouse.accy: " << m_mouse.accy;
213
214
215 dbgPlugins << "fixed: " << m_mouse.fixedangle;
216 dbgPlugins << "drag: " << m_curdrag;
217 dbgPlugins << "mass: " << m_curmass;
218 dbgPlugins << "xAngle: " << m_xangle;
219 dbgPlugins << "yAngle: " << m_yangle;
220
221#endif
222
223 m_odelx = delx;
224 m_odely = dely;
225
226 // how to change pressure in the KoPointerEvent???
227 return KoPointerEvent(event,now);
228}
qreal m_surfaceHeight
qreal m_surfaceWidth
#define dbgPlugins
Definition kis_debug.h:51

References DynaFilter::accx, DynaFilter::accy, DynaFilter::angx, DynaFilter::angy, DynaFilter::curx, DynaFilter::cury, dbgPlugins, DynaFilter::fixedangle, DynaFilter::lastx, DynaFilter::lasty, m_curdrag, m_curmass, m_mouse, m_odelx, m_odely, m_surfaceHeight, m_surfaceWidth, m_width, m_widthRange, m_xangle, m_yangle, DynaFilter::vel, DynaFilter::velx, and DynaFilter::vely.

◆ flerp()

qreal KisToolDyna::flerp ( qreal f0,
qreal f1,
qreal p )
inlineprivate

Definition at line 117 of file kis_tool_dyna.h.

117 {
118 return ((f0 *(1.0 - p)) + (f1 * p));
119 }
const Params2D p

References p.

◆ initDyna()

void KisToolDyna::initDyna ( )
private

Definition at line 46 of file kis_tool_dyna.cpp.

47{
48 /* dynadraw init */
49 m_curmass = 0.5;
50 m_curdrag = 0.15;
51 m_mouse.fixedangle = false;
52 m_width = 1.5;
53 m_xangle = 0.60;
54 m_yangle = 0.20;
55 m_widthRange = 0.05;
56}

References DynaFilter::fixedangle, m_curdrag, m_curmass, m_mouse, m_width, m_widthRange, m_xangle, and m_yangle.

◆ initStroke()

void KisToolDyna::initStroke ( KoPointerEvent * event)
overrideprotectedvirtual

Reimplemented from KisToolFreehand.

Definition at line 76 of file kis_tool_dyna.cpp.

77{
78 QRectF imageSize = QRectF(QPointF(0.0,0.0),currentImage()->size());
79 QRectF documentSize = currentImage()->pixelToDocument(imageSize);
80 m_surfaceWidth = documentSize.width();
81 m_surfaceHeight = documentSize.height();
82 setMousePosition(event->point);
84
86}
QPointF pixelToDocument(const QPointF &pixelCoord) const
virtual void initStroke(KoPointerEvent *event)
int size(const Forest< T > &forest)
Definition KisForest.h:1232
KisImageWSP currentImage()
Definition kis_tool.cc:393

References KisTool::currentImage(), DynaFilter::init(), KisToolFreehand::initStroke(), m_mouse, m_mousePos, m_surfaceHeight, m_surfaceWidth, KisImage::pixelToDocument(), KoPointerEvent::point, and setMousePosition().

◆ resetCursorStyle

void KisToolDyna::resetCursorStyle ( )
overrideprotectedslot

Definition at line 63 of file kis_tool_dyna.cpp.

64{
66
68}
void resetCursorStyle() override
bool overrideCursorIfNotEditable()
Override the cursor appropriately if current node is not editable.
Definition kis_tool.cc:618

References KisTool::overrideCursorIfNotEditable(), and KisToolFreehand::resetCursorStyle().

◆ setMousePosition()

void KisToolDyna::setMousePosition ( const QPointF & point)
inlineprivate

Definition at line 120 of file kis_tool_dyna.h.

120 {
121 m_mousePos.setX(point.x() / m_surfaceWidth );
122 m_mousePos.setY(point.y() / m_surfaceHeight);
123 }

References m_mousePos, m_surfaceHeight, and m_surfaceWidth.

◆ slotSetAngle

void KisToolDyna::slotSetAngle ( qreal angle)
privateslot

Definition at line 334 of file kis_tool_dyna.cpp.

335{
336 m_xangle = cos(angle * M_PI/180.0);
337 m_yangle = sin(angle * M_PI/180.0);
338
339 m_configGroup.writeEntry("angleAmount", angle);
340}
#define M_PI
Definition kis_global.h:111

References m_configGroup, M_PI, m_xangle, and m_yangle.

◆ slotSetDrag

void KisToolDyna::slotSetDrag ( qreal drag)
privateslot

Definition at line 231 of file kis_tool_dyna.cpp.

232{
233 m_curdrag = drag;
234 m_configGroup.writeEntry("dragAmount", drag);
235}

References m_configGroup, and m_curdrag.

◆ slotSetDynaWidth

void KisToolDyna::slotSetDynaWidth ( double width)
privateslot

Definition at line 245 of file kis_tool_dyna.cpp.

246{
247 m_width = width;
248 m_configGroup.writeEntry("initWidth", width);
249}

References m_configGroup, and m_width.

◆ slotSetFixedAngle

void KisToolDyna::slotSetFixedAngle ( bool fixedAngle)
privateslot

Definition at line 259 of file kis_tool_dyna.cpp.

260{
261 m_mouse.fixedangle = fixedAngle;
262 m_angleSelector->setEnabled(fixedAngle);
263 m_configGroup.writeEntry("useFixedAngle", fixedAngle);
264}

References DynaFilter::fixedangle, m_angleSelector, m_configGroup, and m_mouse.

◆ slotSetMass

void KisToolDyna::slotSetMass ( qreal mass)
privateslot

Definition at line 238 of file kis_tool_dyna.cpp.

239{
240 m_curmass = mass;
241 m_configGroup.writeEntry("massAmount", mass);
242}

References m_configGroup, and m_curmass.

◆ slotSetWidthRange

void KisToolDyna::slotSetWidthRange ( double widthRange)
privateslot

Definition at line 252 of file kis_tool_dyna.cpp.

253{
254 m_widthRange = widthRange;
255 m_configGroup.writeEntry("initWidthRange", widthRange);
256}

References m_configGroup, and m_widthRange.

Member Data Documentation

◆ m_angleSelector

KisAngleSelector* KisToolDyna::m_angleSelector {nullptr}
private

Definition at line 92 of file kis_tool_dyna.h.

92{nullptr};

◆ m_chkFixedAngle

QCheckBox* KisToolDyna::m_chkFixedAngle {nullptr}
private

Definition at line 89 of file kis_tool_dyna.h.

89{nullptr};

◆ m_configGroup

KConfigGroup KisToolDyna::m_configGroup
private

Definition at line 106 of file kis_tool_dyna.h.

◆ m_curdrag

qreal KisToolDyna::m_curdrag {0.0}
private

Definition at line 109 of file kis_tool_dyna.h.

109{0.0};

◆ m_curmass

qreal KisToolDyna::m_curmass {0.0}
private

Definition at line 108 of file kis_tool_dyna.h.

108{0.0};

◆ m_dragSPBox

KisDoubleSliderSpinBox* KisToolDyna::m_dragSPBox {nullptr}
private

Definition at line 91 of file kis_tool_dyna.h.

91{nullptr};

◆ m_massSPBox

KisDoubleSliderSpinBox* KisToolDyna::m_massSPBox {nullptr}
private

Definition at line 90 of file kis_tool_dyna.h.

90{nullptr};

◆ m_mouse

DynaFilter KisToolDyna::m_mouse
private

Definition at line 110 of file kis_tool_dyna.h.

◆ m_mousePos

QPointF KisToolDyna::m_mousePos
private

Definition at line 100 of file kis_tool_dyna.h.

◆ m_odelx

qreal KisToolDyna::m_odelx {0.0}
private

Definition at line 96 of file kis_tool_dyna.h.

96{0.0};

◆ m_odely

qreal KisToolDyna::m_odely {0.0}
private

Definition at line 97 of file kis_tool_dyna.h.

97{0.0};

◆ m_optionLayout

QGridLayout* KisToolDyna::m_optionLayout {nullptr}
private

Definition at line 86 of file kis_tool_dyna.h.

86{nullptr};

◆ m_prevPosition

QVector<QPointF> KisToolDyna::m_prevPosition
private

Definition at line 95 of file kis_tool_dyna.h.

◆ m_surfaceHeight

qreal KisToolDyna::m_surfaceHeight {0.0}
private

Definition at line 103 of file kis_tool_dyna.h.

103{0.0};

◆ m_surfaceWidth

qreal KisToolDyna::m_surfaceWidth {0.0}
private

Definition at line 102 of file kis_tool_dyna.h.

102{0.0};

◆ m_width

qreal KisToolDyna::m_width {0.0}
private

Definition at line 107 of file kis_tool_dyna.h.

107{0.0};

◆ m_widthRange

qreal KisToolDyna::m_widthRange {0.0}
private

Definition at line 113 of file kis_tool_dyna.h.

113{0.0};

◆ m_xangle

qreal KisToolDyna::m_xangle {0.0}
private

Definition at line 111 of file kis_tool_dyna.h.

111{0.0};

◆ m_yangle

qreal KisToolDyna::m_yangle {0.0}
private

Definition at line 112 of file kis_tool_dyna.h.

112{0.0};

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