Pencil2D  ff90c0872e88be3bf81c548cd60f01983012ec49
Pencil2D is an animation software for both bitmap and vector graphics. It is free, multi-platform, and open source.
 All Classes Functions
basetool.h
1 /*
2 
3 Pencil - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2017 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 <QMouseEvent>
25 #include <QPointF>
26 #include <QPixmap>
27 #include <QPen>
28 #include "pencildef.h"
29 
30 class Editor;
31 class ScribbleArea;
32 class QKeyEvent;
33 class StrokeManager;
34 
36 {
37 public:
38  qreal width = 1.f;
39  qreal feather = 1.f;
40  bool pressure = 1;
41  int invisibility = 0;
42  int preserveAlpha = 0;
43  bool vectorMergeEnabled = false;
44  bool bezier_state = false;
45  bool useFeather = true;
46  int useAA = 0;
47  int inpolLevel = 0;
48  qreal tolerance = 0;
49  bool useFillContour = 0;
50 };
51 
52 const int ON = 1;
53 const int OFF = 0;
54 const int DISABLED = -1;
55 
56 
57 class BaseTool : public QObject
58 {
59  Q_OBJECT
60 public:
61  static QString TypeName( ToolType );
62 
63  static ToolPropertyType assistedSettingType; // dynamic cursor adjustment
64  static qreal OriginalSettingValue; // start from previous value (width, or feather ...)
65 
66  explicit BaseTool( QObject* parent = 0 );
67  void initialize( Editor* editor );
68 
69  QString typeName() { return TypeName( type() ); }
70 
71  virtual ToolType type() = 0;
72  virtual void loadSettings() = 0;
73  virtual QCursor cursor();
74 
75  virtual void mousePressEvent( QMouseEvent* ) = 0;
76  virtual void mouseMoveEvent( QMouseEvent* ) = 0;
77  virtual void mouseReleaseEvent( QMouseEvent* ) = 0;
78  virtual void mouseDoubleClickEvent( QMouseEvent* );
79 
80  // return true if handled
81  virtual bool keyPressEvent( QKeyEvent* ) { return false; }
82  virtual bool keyReleaseEvent( QKeyEvent* ) { return false; }
83 
84  // dynamic cursor adjustment
85  virtual void startAdjusting( ToolPropertyType argSettingType, qreal argStep );
86  virtual void stopAdjusting();
87  virtual void adjustCursor( qreal argOffsetX, ToolPropertyType type );
88 
89  virtual void adjustPressureSensitiveProperties( qreal pressure, bool mouseDevice );
90 
91  virtual void clear() {}
92 
93  static bool isAdjusting;
94  QPixmap canvasCursor();
95  QPixmap quickSizeCursor();
96 
97  virtual void setWidth( const qreal width );
98  virtual void setFeather( const qreal feather );
99  virtual void setInvisibility( const bool invisibility );
100  virtual void setBezier( const bool bezier_state );
101  virtual void setPressure( const bool pressure );
102  virtual void setUseFeather( const bool usingFeather );
103  virtual void setPreserveAlpha( const bool preserveAlpha );
104  virtual void setVectorMergeEnabled( const bool vectorMergeEnabled );
105  virtual void setAA(const int useAA );
106  virtual void setInpolLevel( const int level );
107  virtual void setTolerance(const int tolerance);
108  virtual void setUseFillContour(const bool useFillContour);
109 
110  virtual void leavingThisTool(){}
111  virtual void switchingLayers(){}
112 
113  Properties properties;
114 
115  QPointF getCurrentPixel();
116  QPointF getCurrentPoint();
117  QPointF getLastPixel();
118  QPointF getLastPoint();
119  QPointF getLastPressPixel();
120  QPointF getLastPressPoint();
121 
122  bool isPropertyEnabled( ToolPropertyType t ) { return m_enabledProperties[ t ]; }
123 
124 protected:
125  QHash<ToolPropertyType, bool> m_enabledProperties;
126 
127  Editor* editor() { return mEditor; }
128  Editor* mEditor = nullptr;
129  ScribbleArea* mScribbleArea = nullptr;
130  StrokeManager* m_pStrokeManager = nullptr;
131  qreal mAdjustmentStep = 0.0f;
132 
133 private:
134  int propWidth;
135  int propFeather;
136  int width;
137  int cursorWidth;
138 
139  int radius;
140  int xyA;
141  int xyB;
142  int whA;
143  int whB;
144  QPixmap cursorPixmap;
145  QPen cursorPen;
146 };
147 
148 #endif // BASETOOL_H
QPixmap quickSizeCursor()
precision circular cursor: used for drawing stroke size while adjusting
Definition: basetool.cpp:179
QPixmap canvasCursor()
precision circular cursor: used for drawing a cursor within scribble area.
Definition: basetool.cpp:121
Definition: editor.h:45