Pencil2D Animation
Download Community News Docs Contribute
  • Overview
  • Articles
  • Code
  •  
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members
  • File List
Loading...
Searching...
No Matches
  • core_lib
  • src
  • tool
stroketool.h
1/*
2
3Pencil2D - Traditional Animation Software
4Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5Copyright (C) 2012-2020 Matthew Chiawen Chang
6
7This program is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public License
9as published by the Free Software Foundation; version 2 of the License.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16*/
17
18#ifndef STROKETOOL_H
19#define STROKETOOL_H
20
21#include "basetool.h"
22#include "pointerevent.h"
23#include "preferencesdef.h"
24#include "strokeinterpolator.h"
25#include "undoredomanager.h"
26
27#include "canvascursorpainter.h"
28#include "radialoffsettool.h"
29
30#include <QList>
31#include <QPointF>
32
33
34class StrokeTool : public BaseTool
35{
36 Q_OBJECT
37
38public:
39 explicit StrokeTool(QObject* parent);
40 ~StrokeTool();
41
42 virtual const StrokeToolProperties& strokeToolProperties() const = 0;
43
44 void startStroke(PointerEvent::InputType inputType);
45 void drawStroke();
46 void endStroke();
47
48 bool leavingThisTool() override;
49 bool enteringThisTool() override;
50
51 void updateCanvasCursor();
52
53 void loadSettings() override;
54 bool isActive() const override { return mInterpolator.isActive(); }
55
56 bool keyPressEvent(QKeyEvent* event) override;
57 void pointerPressEvent(PointerEvent* event) override;
58 void pointerMoveEvent(PointerEvent* event) override;
59 void pointerReleaseEvent(PointerEvent* event) override;
60 bool enterEvent(QEnterEvent*) override;
61 bool leaveEvent(QEvent*) override;
62
63 bool handleQuickSizing(PointerEvent* event);
64
65 void paint(QPainter& painter, const QRect& blitRect) override;
66
67 virtual void setStablizationLevel(int level);
68 virtual void setWidth(qreal width);
69 virtual void setFeather(qreal feather);
70 virtual void setPressureEnabled(bool enabled);
71 virtual void setFeatherEnabled(bool enabled);
72 virtual void setAntiAliasingEnabled(bool enabled);
73 virtual void setFillContourEnabled(bool enabled);
74 virtual void setStrokeInvisibleEnabled(bool enabled);
75
76signals:
77 void widthChanged(qreal value);
78 void featherChanged(qreal value);
79 void pressureEnabledChanged(bool enabled);
80 void featherEnabledChanged(bool enabled);
81 void antiAliasingEnabledChanged(bool enabled);
82 void fillContourEnabledChanged(bool enabled);
83 void invisibleStrokeEnabledChanged(bool enabled);
84 void stabilizationLevelChanged(int level);
85
86public slots:
87 void onPreferenceChanged(SETTING setting);
88 void onViewUpdated();
89
90protected:
91 QPointF getCurrentPressPixel() const;
92 QPointF getCurrentPressPoint() const;
93 QPointF getCurrentPixel() const;
94 QPointF getCurrentPoint() const;
95 QPointF getLastPixel() const;
96 QPointF getLastPoint() const;
97
98 QRectF cursorRect(StrokeToolProperties::Type settingType, const QPointF& point);
99
100 static bool mQuickSizingEnabled;
101
102 QHash<Qt::KeyboardModifiers, int> mQuickSizingProperties;
103 bool mFirstDraw = false;
104
105 QList<QPointF> mStrokePoints;
106 QList<qreal> mStrokePressures;
107
108 qreal mCurrentWidth = 0.0;
109 qreal mCurrentPressure = 0.5;
110
111 PointerEvent::InputType mCurrentInputType = PointerEvent::Unknown;
112
118 virtual bool emptyFrameActionEnabled();
119
120 bool mCanvasCursorEnabled = false;
121 QPointF mLastPixel { 0, 0 };
122
123 StrokeInterpolator mInterpolator;
124
125 const UndoSaveState* mUndoSaveState = nullptr;
126
127 static const qreal FEATHER_MIN;
128 static const qreal FEATHER_MAX;
129 static const qreal WIDTH_MIN;
130 static const qreal WIDTH_MAX;
131
132private:
133 CanvasCursorPainter mWidthCursorPainter;
134 CanvasCursorPainter mFeatherCursorPainter;
135
136 RadialOffsetTool mWidthSizingTool;
137 RadialOffsetTool mFeatherSizingTool;
138};
139
140#endif // STROKETOOL_H
BaseTool
Definition: basetool.h:47
CanvasCursorPainter
Definition: canvascursorpainter.h:32
PointerEvent
Definition: pointerevent.h:8
RadialOffsetTool
Definition: radialoffsettool.h:40
StrokeInterpolator
Definition: strokeinterpolator.h:30
StrokeTool
Definition: stroketool.h:35
StrokeTool::leavingThisTool
bool leavingThisTool() override
Will clean up active connections.
Definition: stroketool.cpp:107
StrokeTool::enteringThisTool
bool enteringThisTool() override
Setup active connections here that should only emit while tool is active leavingThisTool will handle ...
Definition: stroketool.cpp:101
StrokeTool::isActive
bool isActive() const override
Check if the tool is active.
Definition: stroketool.h:54
StrokeTool::loadSettings
void loadSettings() override
Definition: stroketool.cpp:61
StrokeTool::emptyFrameActionEnabled
virtual bool emptyFrameActionEnabled()
Whether to enable the "drawing on empty frame" preference.
Definition: stroketool.cpp:200
QEnterEvent
QEvent
QHash
QKeyEvent
QList
QObject
QObject::Q_OBJECT
Q_OBJECTQ_OBJECT
QObject::event
virtual bool event(QEvent *e)
QObject::parent
QObject * parent() const const
QPainter
QPointF
QRect
QRectF
StrokeToolProperties
Definition: toolproperties.h:395
UndoSaveState
This is the main undo/redo state structure which is meant to populate whatever states that needs to b...
Definition: undoredomanager.h:80
Generated on Tue Jan 6 2026 11:38:51 for Pencil2D by doxygen 1.9.6 based on revision f91a96748ec6712509b9b0ff47979db9c34d556f