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
41 void startStroke(PointerEvent::InputType inputType);
42 void drawStroke();
43 void endStroke();
44
45 bool leavingThisTool() override;
46 bool enteringThisTool() override;
47
48 void updateCanvasCursor();
49
50 static const qreal FEATHER_MIN;
51 static const qreal FEATHER_MAX;
52 static const qreal WIDTH_MIN;
53 static const qreal WIDTH_MAX;
54
55 void loadSettings() override;
56 bool isActive() const override { return mInterpolator.isActive(); }
57
58 bool keyPressEvent(QKeyEvent* event) override;
59 void pointerPressEvent(PointerEvent* event) override;
60 void pointerMoveEvent(PointerEvent* event) override;
61 void pointerReleaseEvent(PointerEvent* event) override;
62 bool enterEvent(QEnterEvent*) override;
63 bool leaveEvent(QEvent*) override;
64
65 bool handleQuickSizing(PointerEvent* event);
66
67 void paint(QPainter& painter, const QRect& blitRect) override;
68
69public slots:
70 void onPreferenceChanged(SETTING setting);
71 void onViewUpdated();
72
73protected:
74 QPointF getCurrentPressPixel() const;
75 QPointF getCurrentPressPoint() const;
76 QPointF getCurrentPixel() const;
77 QPointF getCurrentPoint() const;
78 QPointF getLastPixel() const;
79 QPointF getLastPoint() const;
80
81 QRectF cursorRect(ToolPropertyType settingType, const QPointF& point);
82
83 static bool mQuickSizingEnabled;
84
85 QHash<Qt::KeyboardModifiers, ToolPropertyType> mQuickSizingProperties;
86 bool mFirstDraw = false;
87
88 QList<QPointF> mStrokePoints;
89 QList<qreal> mStrokePressures;
90
91 qreal mCurrentWidth = 0.0;
92 qreal mCurrentPressure = 0.5;
93
94 PointerEvent::InputType mCurrentInputType = PointerEvent::Unknown;
95
101 virtual bool emptyFrameActionEnabled();
102
103 bool mCanvasCursorEnabled = false;
104 QPointF mLastPixel { 0, 0 };
105
106 StrokeInterpolator mInterpolator;
107
108 const UndoSaveState* mUndoSaveState = nullptr;
109
110private:
111 CanvasCursorPainter mWidthCursorPainter;
112 CanvasCursorPainter mFeatherCursorPainter;
113
114 RadialOffsetTool mWidthSizingTool;
115 RadialOffsetTool mFeatherSizingTool;
116};
117
118#endif // STROKETOOL_H
BaseTool
Definition: basetool.h:70
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:89
StrokeTool::enteringThisTool
bool enteringThisTool() override
Setup active connections here that should only emit while tool is active leavingThisTool will handle ...
Definition: stroketool.cpp:83
StrokeTool::isActive
bool isActive() const override
Check if the tool is active.
Definition: stroketool.h:56
StrokeTool::loadSettings
void loadSettings() override
Definition: stroketool.cpp:57
StrokeTool::emptyFrameActionEnabled
virtual bool emptyFrameActionEnabled()
Whether to enable the "drawing on empty frame" preference.
Definition: stroketool.cpp:182
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
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 Mon Dec 15 2025 03:41:35 for Pencil2D by doxygen 1.9.6 based on revision 9bfef078cfa681fa5250352bbcb5a69281765ae9