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.f;
42  qreal feather = 1.f;
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 stabilizerLevel = 0;
51  qreal tolerance = 0;
52  bool useFillContour = false;
53 };
54 
55 const int ON = 1;
56 const int OFF = 0;
57 const int DISABLED = -1;
58 
59 
60 class BaseTool : public QObject
61 {
62  Q_OBJECT
63 protected:
64  explicit BaseTool(QObject* parent);
65 
66 public:
67  static QString TypeName(ToolType);
68  QString typeName() { return TypeName(type()); }
69 
70  void initialize(Editor* editor);
71 
72  virtual ToolType type() = 0;
73  virtual void loadSettings() = 0;
74  virtual QCursor cursor();
75 
76  virtual void pointerPressEvent(PointerEvent*) = 0;
77  virtual void pointerMoveEvent(PointerEvent*) = 0;
78  virtual void pointerReleaseEvent(PointerEvent*) = 0;
79  virtual void pointerDoubleClickEvent(PointerEvent*);
80 
81  // return true if handled
82  virtual bool keyPressEvent(QKeyEvent*) { return false; }
83  virtual bool keyReleaseEvent(QKeyEvent*) { return false; }
84 
85  // dynamic cursor adjustment
86  virtual bool startAdjusting(Qt::KeyboardModifiers modifiers, qreal argStep);
87  virtual void stopAdjusting();
88  virtual void adjustCursor(Qt::KeyboardModifiers modifiers);
89 
90  virtual void clearToolData() {}
91  virtual void resetToDefault() {}
92 
93  static QPixmap canvasCursor(float brushWidth, float brushFeather, bool useFeather, float scalingFac, int windowWidth);
94  QPixmap quickSizeCursor(qreal scalingFac);
95  static QCursor selectMoveCursor(MoveMode mode, ToolType type);
96  static bool isAdjusting() { return msIsAdjusting; }
97 
105  virtual bool isActive();
106 
107  virtual void setWidth(const qreal width);
108  virtual void setFeather(const qreal feather);
109  virtual void setInvisibility(const bool invisibility);
110  virtual void setBezier(const bool bezier_state);
111  virtual void setPressure(const bool pressure);
112  virtual void setUseFeather(const bool usingFeather);
113  virtual void setPreserveAlpha(const bool preserveAlpha);
114  virtual void setVectorMergeEnabled(const bool vectorMergeEnabled);
115  virtual void setAA(const int useAA);
116  virtual void setStabilizerLevel(const int level);
117  virtual void setTolerance(const int tolerance);
118  virtual void setUseFillContour(const bool useFillContour);
119 
120  virtual bool leavingThisTool() { return true; }
121  virtual bool switchingLayer() { return true; } // default state should be true
122 
123  Properties properties;
124 
125  QPointF getCurrentPressPixel();
126  QPointF getCurrentPressPoint();
127  QPointF getCurrentPixel();
128  QPointF getCurrentPoint();
129  QPointF getLastPixel();
130  QPointF getLastPoint();
131  QPointF getLastPressPixel();
132  QPointF getLastPressPoint();
133 
134  bool isPropertyEnabled(ToolPropertyType t) { return mPropertyEnabled[t]; }
135  bool isDrawingTool();
136 
137 protected:
138  StrokeManager* strokeManager() { return mStrokeManager; }
139  Editor* editor() { return mEditor; }
140 
141  QHash<ToolPropertyType, bool> mPropertyEnabled;
142 
143  Editor* mEditor = nullptr;
144  ScribbleArea* mScribbleArea = nullptr;
145 
146  QHash<Qt::KeyboardModifiers, ToolPropertyType> mQuickSizingProperties;
147 
148 private:
149  StrokeManager* mStrokeManager = nullptr;
150  qreal mAdjustmentStep = 0.0f;
151 
152  static bool msIsAdjusting;
153  static qreal msOriginalPropertyValue; // start from previous value (width, or feather ...)
154 };
155 
156 #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:123
typedef KeyboardModifiers
QPixmap quickSizeCursor(qreal scalingFac)
precision circular cursor: used for drawing stroke size while adjusting
Definition: basetool.cpp:252
bool isDrawingTool()
BaseTool::isDrawingTool - A drawing tool is anything that applies something to the canvas...
Definition: basetool.cpp:110
Q_OBJECTQ_OBJECT
Definition: editor.h:51
QObject * parent() const const
virtual bool isActive()
Check if the tool is active.
Definition: basetool.cpp:243