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.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 BASETOOL_H
19#define BASETOOL_H
20
21#include <QObject>
22#include <QString>
23#include <QCursor>
24#include <QPainter>
25#include <QHash>
26#include <QEvent>
27#include "pencildef.h"
28
29class QPixmap;
30class Editor;
31class ScribbleArea;
32class QEnterEvent;
33class QKeyEvent;
34class QMouseEvent;
35class QTabletEvent;
36class PointerEvent;
37
38class Properties
39{
40public:
41 qreal width = 1.0;
42 qreal feather = 1.0;
43 bool pressure = true;
44 int invisibility = 0;
45 int preserveAlpha = 0;
46 bool vectorMergeEnabled = false;
47 bool bezier_state = false;
48 bool closedPolylinePath = false;
49 bool useFeather = true;
50 int useAA = 0;
51 int fillMode = 0;
52 int stabilizerLevel = 0;
53 qreal tolerance = 0;
54 bool toleranceEnabled = false;
55 int bucketFillExpand = 0;
56 bool bucketFillExpandEnabled = 0;
57 int bucketFillReferenceMode = 0;
58 bool useFillContour = false;
59 bool showSelectionInfo = true;
60 bool cameraShowPath = true;
61 DotColorType cameraPathDotColorType = DotColorType::RED;
62};
63
64const int ON = 1;
65const int OFF = 0;
66const int DISABLED = -1;
67
68
69class BaseTool : public QObject
70{
71 Q_OBJECT
72protected:
73 explicit BaseTool(QObject* parent);
74public:
75 static QString TypeName(ToolType);
76 QString typeName() { return TypeName(type()); }
77
78 void initialize(Editor* editor);
79
80 virtual ToolType type() = 0;
81 virtual void loadSettings() = 0;
82 virtual void saveSettings() = 0;
83 virtual QCursor cursor();
84
85 virtual void pointerPressEvent(PointerEvent*) = 0;
86 virtual void pointerMoveEvent(PointerEvent*) = 0;
87 virtual void pointerReleaseEvent(PointerEvent*) = 0;
88 virtual void pointerDoubleClickEvent(PointerEvent*);
89
90 // return true if handled
91 virtual bool keyPressEvent(QKeyEvent*) { return false; }
92 virtual bool keyReleaseEvent(QKeyEvent*) { return false; }
93
94 virtual bool enterEvent(QEnterEvent*) { return false; }
95 virtual bool leaveEvent(QEvent*) { return false; }
96
97 virtual void clearToolData() {}
98 virtual void resetToDefault() {}
99
107 virtual bool isActive() const;
108
109 virtual void setWidth(const qreal width);
110 virtual void setFeather(const qreal feather);
111
112 virtual void setInvisibility(const bool invisibility);
113 virtual void setBezier(const bool bezier_state);
114 virtual void setClosedPath(const bool closed);
115 virtual void setPressure(const bool pressure);
116 virtual void setUseFeather(const bool usingFeather);
117 virtual void setPreserveAlpha(const bool preserveAlpha);
118 virtual void setVectorMergeEnabled(const bool vectorMergeEnabled);
119 virtual void setAA(const int useAA);
120 virtual void setFillMode(const int mode);
121 virtual void setStabilizerLevel(const int level);
122 virtual void setTolerance(const int tolerance);
123 virtual void setToleranceEnabled(const bool enabled);
124 virtual void setFillExpand(const int fillExpandValue);
125 virtual void setFillExpandEnabled(const bool enabled);
126 virtual void setFillReferenceMode(int referenceMode);
127 virtual void setUseFillContour(const bool useFillContour);
128 virtual void setShowSelectionInfo(const bool b);
129 virtual void setShowCameraPath(const bool showCameraPath);
130 virtual void setPathDotColorType(const DotColorType dotColorType);
131 virtual void resetCameraPath();
132
133 virtual void paint(QPainter& painter, const QRect& blitRect) { Q_UNUSED(painter) Q_UNUSED(blitRect) }
134
136 virtual bool leavingThisTool();
137
140 virtual bool enteringThisTool() { return true; }
141
142 Properties properties;
143
144 bool isPropertyEnabled(ToolPropertyType t) { return mPropertyEnabled[t]; }
145 bool isDrawingTool();
146
147signals:
148 bool isActiveChanged(ToolType, bool);
149
150protected:
151 Editor* editor() { return mEditor; }
152
153 QHash<ToolPropertyType, bool> mPropertyEnabled;
154
155 Editor* mEditor = nullptr;
156 ScribbleArea* mScribbleArea = nullptr;
157 QList<QMetaObject::Connection> mActiveConnections;
158};
159
160#endif // BASETOOL_H
BaseTool
Definition: basetool.h:70
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::enteringThisTool
virtual bool enteringThisTool()
Setup active connections here that should only emit while tool is active leavingThisTool will handle ...
Definition: basetool.h:140
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
Properties
Definition: basetool.h:39
ScribbleArea
Definition: scribblearea.h:51
QCursor
QEnterEvent
QEvent
QHash
QKeyEvent
QList
QMouseEvent
QObject
QObject::Q_OBJECT
Q_OBJECTQ_OBJECT
QObject::parent
QObject * parent() const const
QPainter
QPixmap
QRect
QString
QTabletEvent
Generated on Thu May 8 2025 04:47:53 for Pencil2D by doxygen 1.9.6 based on revision 4513250b1d5b1a3676ec0e67b06b7a885ceaae39