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
stroketool.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 STROKETOOL_H
19#define STROKETOOL_H
20
21#include "basetool.h"
22#include "pointerevent.h"
23#include "preferencesdef.h"
24#include "strokeinterpolator.h"
25#include "undoredomanager.h"
26
27#include "canvascursorpainter.h"
28
29#include <QList>
30#include <QPointF>
31
32
33class StrokeTool : public BaseTool
34{
35 Q_OBJECT
36
37public:
38 explicit StrokeTool(QObject* parent);
39
40 void startStroke(PointerEvent::InputType inputType);
41 void drawStroke();
42 void endStroke();
43
44 bool leavingThisTool() override;
45 bool enteringThisTool() override;
46
47 void updateCanvasCursor();
48
49 static const qreal FEATHER_MIN;
50 static const qreal FEATHER_MAX;
51 static const qreal WIDTH_MIN;
52 static const qreal WIDTH_MAX;
53
54 void loadSettings() override;
55 bool isActive() const override { return mInterpolator.isActive(); };
56
57 bool keyPressEvent(QKeyEvent* event) override;
58 void pointerPressEvent(PointerEvent* event) override;
59 void pointerMoveEvent(PointerEvent* event) override;
60 void pointerReleaseEvent(PointerEvent* event) override;
61 bool enterEvent(QEnterEvent*) override;
62 bool leaveEvent(QEvent*) override;
63
64 bool handleQuickSizing(PointerEvent* event);
65
66 void paint(QPainter& painter, const QRect& blitRect) override;
67
68public slots:
69 void onPreferenceChanged(SETTING setting);
70 void onViewUpdated();
71
72protected:
73 QPointF getCurrentPressPixel() const;
74 QPointF getCurrentPressPoint() const;
75 QPointF getCurrentPixel() const;
76 QPointF getCurrentPoint() const;
77 QPointF getLastPixel() const;
78 QPointF getLastPoint() const;
79
80 // dynamic cursor adjustment
81 virtual bool startAdjusting(Qt::KeyboardModifiers modifiers);
82 virtual void stopAdjusting();
83 virtual void adjustCursor(Qt::KeyboardModifiers modifiers);
84
85 static bool mQuickSizingEnabled;
86 static bool msIsAdjusting;
87
88 QHash<Qt::KeyboardModifiers, ToolPropertyType> mQuickSizingProperties;
89 bool mFirstDraw = false;
90
91 QList<QPointF> mStrokePoints;
92 QList<qreal> mStrokePressures;
93
94 qreal mCurrentWidth = 0.0;
95 qreal mCurrentPressure = 0.5;
96
97 PointerEvent::InputType mCurrentInputType = PointerEvent::Unknown;
98
104 virtual bool emptyFrameActionEnabled();
105
106 bool mCanvasCursorEnabled = false;
107 QPointF mLastPixel { 0, 0 };
108
109 QPointF mAdjustPosition;
110
111 CanvasCursorPainter mCanvasCursorPainter;
112
113 StrokeInterpolator mInterpolator;
114
115 const UndoSaveState* mUndoSaveState = nullptr;
116};
117
118#endif // STROKETOOL_H
BaseTool
Definition: basetool.h:70
CanvasCursorPainter
Definition: canvascursorpainter.h:34
PointerEvent
Definition: pointerevent.h:8
StrokeInterpolator
Definition: strokeinterpolator.h:30
StrokeTool
Definition: stroketool.h:34
StrokeTool::leavingThisTool
bool leavingThisTool() override
Will clean up active connections.
Definition: stroketool.cpp:74
StrokeTool::enteringThisTool
bool enteringThisTool() override
Setup active connections here that should only emit while tool is active leavingThisTool will handle ...
Definition: stroketool.cpp:68
StrokeTool::isActive
bool isActive() const override
Check if the tool is active.
Definition: stroketool.h:55
StrokeTool::loadSettings
void loadSettings() override
Definition: stroketool.cpp:58
StrokeTool::emptyFrameActionEnabled
virtual bool emptyFrameActionEnabled()
Whether to enable the "drawing on empty frame" preference.
Definition: stroketool.cpp:167
QEnterEvent
QEvent
QHash
QKeyEvent
QList
QObject
QObject::Q_OBJECT
Q_OBJECTQ_OBJECT
QObject::event
virtual bool event(QEvent *e)
QObject::parent
QObject * parent() const const
QPainter
QPointF
QRect
Qt::KeyboardModifiers
typedef KeyboardModifiers
UndoSaveState
This is the main undo/redo state structure which is meant to populate whatever states that needs to b...
Definition: undoredomanager.h:80
Generated on Thu May 8 2025 04:47:53 for Pencil2D by doxygen 1.9.6 based on revision 4513250b1d5b1a3676ec0e67b06b7a885ceaae39