Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_tool_dyna.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2009-2011 Lukáš Tvrdý <lukast.dev@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#ifndef KIS_TOOL_DYNA_H_
8#define KIS_TOOL_DYNA_H_
9
10#include "kis_tool_freehand.h"
11
13#include "KoPointerEvent.h"
14
16#include <kis_icon.h>
17#include <kconfig.h>
18#include <kconfiggroup.h>
19
20
22class QCheckBox;
23class QGridLayout;
25
26class KoCanvasBase;
27
29{
30public:
32
33 void init(qreal x, qreal y) {
34 curx = x;
35 cury = y;
36 lastx = x;
37 lasty = y;
38 velx = 0.0;
39 vely = 0.0;
40 accx = 0.0;
41 accy = 0.0;
42 }
43
45
46public:
47 qreal curx {0.0}, cury {0.0};
48 qreal velx {0.0}, vely {0.0}, vel {0.0};
49 qreal accx {0.0}, accy {0.0}, acc {0.0};
50 qreal angx {0.0}, angy {0.0};
51 qreal mass {0.0}, drag {0.0};
52 qreal lastx {0.0}, lasty {0.0};
53 bool fixedangle {false};
54};
55
56
58{
59 Q_OBJECT
60
61public:
63 ~KisToolDyna() override;
64
65 QWidget * createOptionWidget() override;
66 void activate(const QSet<KoShape*> &shapes) override;
67 void beginPrimaryAction(KoPointerEvent *event) override;
68 void continuePrimaryAction(KoPointerEvent *event) override;
69
70protected:
71 void initStroke(KoPointerEvent *event) override;
72
73protected Q_SLOTS:
74 void resetCursorStyle() override;
75
76private Q_SLOTS:
77
78 void slotSetDynaWidth(double width);
79 void slotSetMass(qreal mass);
80 void slotSetDrag(qreal drag);
81 void slotSetAngle(qreal angle);
82 void slotSetWidthRange(double widthRange);
83 void slotSetFixedAngle(bool fixedAngle);
84
85private:
86 QGridLayout* m_optionLayout {nullptr};
87
88 // dyna gui
89 QCheckBox * m_chkFixedAngle {nullptr};
93
94 // dyna algorithm
96 qreal m_odelx {0.0};
97 qreal m_odely {0.0};
98
99 // mouse info
100 QPointF m_mousePos;
101
102 qreal m_surfaceWidth {0.0};
103 qreal m_surfaceHeight {0.0};
104
105 // settings variables
106 KConfigGroup m_configGroup;
107 qreal m_width {0.0};
108 qreal m_curmass {0.0};
109 qreal m_curdrag {0.0};
111 qreal m_xangle {0.0};
112 qreal m_yangle {0.0};
113 qreal m_widthRange {0.0};
114
115
116 // methods
117 qreal flerp(qreal f0, qreal f1, qreal p) {
118 return ((f0 *(1.0 - p)) + (f1 * p));
119 }
120 void setMousePosition(const QPointF &point) {
121 m_mousePos.setX(point.x() / m_surfaceWidth );
122 m_mousePos.setY(point.y() / m_surfaceHeight);
123 }
124
125 void initDyna();
126 int applyFilter(qreal mx, qreal my);
128
129};
130
131
133{
134
135public:
137 : KisToolPaintFactoryBase("KritaShape/KisToolDyna") {
138
139 setToolTip(i18n("Dynamic Brush Tool"));
141 setIconName(koIconNameCStr("krita_tool_dyna"));
142 //setShortcut(QKeySequence(Qt::Key_F));
143 setPriority(10);
145 }
146
148
150 return new KisToolDyna(canvas);
151 }
152
153};
154
155
156#endif // KIS_TOOL_DYNA_H_
157
const Params2D p
void init(qreal x, qreal y)
A widget with several options to select an angle.
This class is a spinbox in which you can click and drag to set the value. A slider like bar is displa...
KoToolBase * createTool(KoCanvasBase *canvas) override
~KisToolDynaFactory() override
void setMousePosition(const QPointF &point)
QCheckBox * m_chkFixedAngle
int applyFilter(qreal mx, qreal my)
void beginPrimaryAction(KoPointerEvent *event) override
void initStroke(KoPointerEvent *event) override
KisToolDyna(KoCanvasBase *canvas)
void continuePrimaryAction(KoPointerEvent *event) override
void slotSetFixedAngle(bool fixedAngle)
DynaFilter m_mouse
QPointF m_mousePos
qreal m_surfaceHeight
~KisToolDyna() override
QGridLayout * m_optionLayout
void activate(const QSet< KoShape * > &shapes) override
KoPointerEvent filterEvent(KoPointerEvent *event)
qreal m_surfaceWidth
KisDoubleSliderSpinBox * m_massSPBox
void slotSetMass(qreal mass)
KisAngleSelector * m_angleSelector
void slotSetDynaWidth(double width)
qreal flerp(qreal f0, qreal f1, qreal p)
void slotSetDrag(qreal drag)
void resetCursorStyle() override
QWidget * createOptionWidget() override
void slotSetAngle(qreal angle)
void slotSetWidthRange(double widthRange)
QVector< QPointF > m_prevPosition
KConfigGroup m_configGroup
KisDoubleSliderSpinBox * m_dragSPBox
void setSection(const QString &section)
void setActivationShapeId(const QString &activationShapeId)
void setIconName(const char *iconName)
void setToolTip(const QString &tooltip)
void setPriority(int newPriority)
#define koIconNameCStr(name)
Definition kis_icon.h:28
static const QString KRITA_TOOL_ACTIVATION_ID
Definition kis_tool.h:37
static const QString Shape
Freehand and shapes like ellipses and lines.
KisCanvas2 * canvas