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
basetool.cpp
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#include "basetool.h"
19
20#include <array>
21#include "editor.h"
22#include "viewmanager.h"
23#include "scribblearea.h"
24#include "strokeinterpolator.h"
25#include "pointerevent.h"
26
27QString BaseTool::TypeName(ToolType type)
28{
29 static std::array<QString, TOOL_TYPE_COUNT> map;
30
31 if (map[0].isEmpty())
32 {
33 map[PENCIL] = tr("Pencil");
34 map[ERASER] = tr("Eraser");
35 map[SELECT] = tr("Select");
36 map[MOVE] = tr("Move");
37 map[HAND] = tr("Hand");
38 map[SMUDGE] = tr("Smudge");
39 map[PEN] = tr("Pen");
40 map[POLYLINE] = tr("Polyline");
41 map[BUCKET] = tr("Bucket");
42 map[EYEDROPPER] = tr("Eyedropper");
43 map[BRUSH] = tr("Brush");
44 }
45 return map.at(type);
46}
47
48BaseTool::BaseTool(QObject* parent) : QObject(parent)
49{
50 mPropertyEnabled.insert(WIDTH, false);
51 mPropertyEnabled.insert(FEATHER, false);
52 mPropertyEnabled.insert(USEFEATHER, false);
53 mPropertyEnabled.insert(PRESSURE, false);
54 mPropertyEnabled.insert(INVISIBILITY, false);
55 mPropertyEnabled.insert(PRESERVEALPHA, false);
56 mPropertyEnabled.insert(BEZIER, false);
57 mPropertyEnabled.insert(CLOSEDPATH, false);
58 mPropertyEnabled.insert(ANTI_ALIASING, false);
59 mPropertyEnabled.insert(FILL_MODE, false);
60 mPropertyEnabled.insert(STABILIZATION, false);
61 mPropertyEnabled.insert(CAMERAPATH, false);
62}
63
64QCursor BaseTool::cursor()
65{
66 return Qt::ArrowCursor;
67}
68
69bool BaseTool::leavingThisTool()
70{
71 for (auto& connection : mActiveConnections) {
72 disconnect(connection);
73 mActiveConnections.removeOne(connection);
74 }
75
76 saveSettings();
77
78 return true;
79}
80
81void BaseTool::initialize(Editor* editor)
82{
83 Q_ASSERT(editor);
84 mEditor = editor;
85 mScribbleArea = editor->getScribbleArea();
86 Q_ASSERT(mScribbleArea);
87
88 loadSettings();
89}
90
91void BaseTool::pointerPressEvent(PointerEvent* event)
92{
93 event->accept();
94}
95
96void BaseTool::pointerMoveEvent(PointerEvent* event)
97{
98 event->accept();
99}
100
101void BaseTool::pointerReleaseEvent(PointerEvent* event)
102{
103 event->accept();
104}
105
106void BaseTool::pointerDoubleClickEvent(PointerEvent* event)
107{
108 pointerPressEvent(event);
109}
110
116bool BaseTool::isDrawingTool()
117{
118 if (type() == ToolType::HAND || type() == ToolType::MOVE || type() == ToolType::CAMERA || type() == ToolType::SELECT )
119 {
120 return false;
121 }
122 return true;
123}
124
125bool BaseTool::isActive() const
126{
127 return false;
128}
129
130void BaseTool::setWidth(const qreal width)
131{
132 properties.width = width;
133}
134
135void BaseTool::setFeather(const qreal feather)
136{
137 properties.feather = feather;
138}
139
140void BaseTool::setUseFeather(const bool usingFeather)
141{
142 properties.useFeather = usingFeather;
143}
144
145void BaseTool::setInvisibility(const bool invisibility)
146{
147 properties.invisibility = invisibility;
148}
149
150void BaseTool::setBezier(const bool _bezier_state)
151{
152 properties.bezier_state = _bezier_state;
153}
154
155void BaseTool::setClosedPath(const bool closed)
156{
157 properties.closedPolylinePath = closed;
158}
159
160void BaseTool::setPressure(const bool pressure)
161{
162 properties.pressure = pressure;
163}
164
165void BaseTool::setPreserveAlpha(const bool preserveAlpha)
166{
167 properties.preserveAlpha = preserveAlpha;
168}
169
170void BaseTool::setVectorMergeEnabled(const bool vectorMergeEnabled)
171{
172 properties.vectorMergeEnabled = vectorMergeEnabled;
173}
174
175void BaseTool::setAA(const int useAA)
176{
177 properties.useAA = useAA;
178}
179
180void BaseTool::setFillMode(const int mode)
181{
182 properties.fillMode = mode;
183}
184
185void BaseTool::setStabilizerLevel(const int level)
186{
187 properties.stabilizerLevel = level;
188}
189
190void BaseTool::setTolerance(const int tolerance)
191{
192 properties.tolerance = tolerance;
193}
194
195void BaseTool::setToleranceEnabled(const bool enabled)
196{
197 properties.toleranceEnabled = enabled;
198}
199
200void BaseTool::setFillExpand(const int fillExpandValue)
201{
202 properties.bucketFillExpand = fillExpandValue;
203}
204
205void BaseTool::setFillReferenceMode(int referenceMode)
206{
207 properties.bucketFillReferenceMode = referenceMode;
208}
209
210void BaseTool::setFillExpandEnabled(const bool enabled)
211{
212 properties.bucketFillExpandEnabled = enabled;
213}
214
215void BaseTool::setUseFillContour(const bool useFillContour)
216{
217 properties.useFillContour = useFillContour;
218}
219
220void BaseTool::setShowSelectionInfo(const bool b)
221{
222 properties.showSelectionInfo = b;
223}
224
225void BaseTool::setShowCameraPath(const bool showCameraPath)
226{
227 properties.cameraShowPath = showCameraPath;
228}
229
230void BaseTool::setPathDotColorType(const DotColorType dotColorType)
231{
232 properties.cameraPathDotColorType = dotColorType;
233}
234
235void BaseTool::resetCameraPath()
236{
237}
BaseTool::isActive
virtual bool isActive() const
Check if the tool is active.
Definition: basetool.cpp:125
BaseTool::leavingThisTool
virtual bool leavingThisTool()
Will clean up active connections.
Definition: basetool.cpp:69
BaseTool::isDrawingTool
bool isDrawingTool()
BaseTool::isDrawingTool - A drawing tool is anything that applies something to the canvas.
Definition: basetool.cpp:116
Editor
Definition: editor.h:71
PointerEvent
Definition: pointerevent.h:8
QCursor
QObject
QObject::disconnect
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QObject::event
virtual bool event(QEvent *e)
QObject::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
QString
Qt::ArrowCursor
ArrowCursor
Generated on Thu May 8 2025 04:47:53 for Pencil2D by doxygen 1.9.6 based on revision 4513250b1d5b1a3676ec0e67b06b7a885ceaae39