All Classes Namespaces Functions Variables Enumerations Properties Pages
basetool.h
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2020 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU 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 <QPointF>
25 #include <QHash>
26 #include "movemode.h"
27 #include "pencildef.h"
28 
29 class QPixmap;
30 class Editor;
31 class ScribbleArea;
32 class QKeyEvent;
33 class QMouseEvent;
34 class QTabletEvent;
35 class StrokeManager;
36 class PointerEvent;
37 
39 {
40 public:
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 useFeather = true;
49  int useAA = 0;
50  int fillMode = 0;
51  int stabilizerLevel = 0;
52  qreal tolerance = 0;
53  bool toleranceEnabled = false;
54  int bucketFillExpand = 0;
55  bool bucketFillExpandEnabled = 0;
56  int bucketFillToLayerMode = 0;
57  int bucketFillReferenceMode = 0;
58  bool useFillContour = false;
59  bool showSelectionInfo = true;
60 };
61 
62 const int ON = 1;
63 const int OFF = 0;
64 const int DISABLED = -1;
65 
66 
67 class BaseTool : public QObject
68 {
69  Q_OBJECT
70 protected:
71  explicit BaseTool(QObject* parent);
72 
73 public:
74  static QString TypeName(ToolType);
75  QString typeName() { return TypeName(type()); }
76 
77  void initialize(Editor* editor);
78 
79  virtual ToolType type() = 0;
80  virtual void loadSettings() = 0;
81  virtual QCursor cursor();
82 
83  virtual void pointerPressEvent(PointerEvent*) = 0;
84  virtual void pointerMoveEvent(PointerEvent*) = 0;
85  virtual void pointerReleaseEvent(PointerEvent*) = 0;
86  virtual void pointerDoubleClickEvent(PointerEvent*);
87 
88  // return true if handled
89  virtual bool keyPressEvent(QKeyEvent*) { return false; }
90  virtual bool keyReleaseEvent(QKeyEvent*) { return false; }
91 
92  // dynamic cursor adjustment
93  virtual bool startAdjusting(Qt::KeyboardModifiers modifiers, qreal argStep);
94  virtual void stopAdjusting();
95  virtual void adjustCursor(Qt::KeyboardModifiers modifiers);
96 
97  virtual void clearToolData() {}
98  virtual void resetToDefault() {}
99 
100  static QPixmap canvasCursor(float brushWidth, float brushFeather, bool useFeather, float scalingFac, int windowWidth);
101  QPixmap quickSizeCursor(qreal scalingFac);
102  static QCursor selectMoveCursor(MoveMode mode, ToolType type);
103  static bool isAdjusting() { return msIsAdjusting; }
104 
112  virtual bool isActive();
113 
114  virtual void setWidth(const qreal width);
115  virtual void setFeather(const qreal feather);
116  virtual void setInvisibility(const bool invisibility);
117  virtual void setBezier(const bool bezier_state);
118  virtual void setPressure(const bool pressure);
119  virtual void setUseFeather(const bool usingFeather);
120  virtual void setPreserveAlpha(const bool preserveAlpha);
121  virtual void setVectorMergeEnabled(const bool vectorMergeEnabled);
122  virtual void setAA(const int useAA);
123  virtual void setFillMode(const int mode);
124  virtual void setStabilizerLevel(const int level);
125  virtual void setTolerance(const int tolerance);
126  virtual void setToleranceEnabled(const bool enabled);
127  virtual void setFillExpand(const int fillExpandValue);
128  virtual void setFillExpandEnabled(const bool enabled);
129  virtual void setFillToLayer(int layerMode);
130  virtual void setFillReferenceMode(int referenceMode);
131  virtual void setUseFillContour(const bool useFillContour);
132  virtual void setShowSelectionInfo(const bool b);
133 
134  virtual bool leavingThisTool() { return true; }
135  virtual bool switchingLayer() { return true; } // default state should be true
136 
137  Properties properties;
138 
139  QPointF getCurrentPressPixel();
140  QPointF getCurrentPressPoint();
141  QPointF getCurrentPixel();
142  QPointF getCurrentPoint();
143  QPointF getLastPixel();
144  QPointF getLastPoint();
145  QPointF getLastPressPixel();
146  QPointF getLastPressPoint();
147 
148  bool isPropertyEnabled(ToolPropertyType t) { return mPropertyEnabled[t]; }
149  bool isDrawingTool();
150 
151 signals:
152  bool isActiveChanged(ToolType, bool);
153 
154 protected:
155  StrokeManager* strokeManager() { return mStrokeManager; }
156  Editor* editor() { return mEditor; }
157 
158  QHash<ToolPropertyType, bool> mPropertyEnabled;
159 
160  Editor* mEditor = nullptr;
161  ScribbleArea* mScribbleArea = nullptr;
162 
163  QHash<Qt::KeyboardModifiers, ToolPropertyType> mQuickSizingProperties;
164 
165 private:
166  StrokeManager* mStrokeManager = nullptr;
167  qreal mAdjustmentStep = 0.0f;
168 
169  static bool msIsAdjusting;
170  static qreal msOriginalPropertyValue; // start from previous value (width, or feather ...)
171 };
172 
173 #endif // BASETOOL_H
static QPixmap canvasCursor(float brushWidth, float brushFeather, bool useFeather, float scalingFac, int windowWidth)
precision circular cursor: used for drawing a cursor within scribble area.
Definition: basetool.cpp:124
typedef KeyboardModifiers
QPixmap quickSizeCursor(qreal scalingFac)
precision circular cursor: used for drawing stroke size while adjusting
Definition: basetool.cpp:262
bool isDrawingTool()
BaseTool::isDrawingTool - A drawing tool is anything that applies something to the canvas...
Definition: basetool.cpp:111
Q_OBJECTQ_OBJECT
Definition: editor.h:55
QObject * parent() const const
virtual bool isActive()
Check if the tool is active.
Definition: basetool.cpp:253