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 <QSet>
27#include <QEvent>
28#include "pencildef.h"
29#include "toolproperties.h"
30#include "layer.h"
31
32class QPixmap;
33class Editor;
34class ScribbleArea;
35class QEnterEvent;
36class QKeyEvent;
37class QMouseEvent;
38class QTabletEvent;
39class PointerEvent;
40
41const int ON = 1;
42const int OFF = 0;
43const int DISABLED = -1;
44
45
46class BaseTool : public QObject
47{
48 Q_OBJECT
49protected:
50 explicit BaseTool(QObject* parent);
51 virtual ~BaseTool();
52public:
53 static QString TypeName(ToolType);
54 QString typeName() { return TypeName(type()); }
55
56 void initialize(Editor* editor);
57
58 virtual ToolType type() const = 0;
59
60 virtual ToolProperties& toolProperties() = 0;
61 virtual void loadSettings() = 0;
62 void saveSettings();
63 void resetSettings();
64
65 virtual QCursor cursor();
66
67 virtual void pointerPressEvent(PointerEvent*) = 0;
68 virtual void pointerMoveEvent(PointerEvent*) = 0;
69 virtual void pointerReleaseEvent(PointerEvent*) = 0;
70 virtual void pointerDoubleClickEvent(PointerEvent*);
71
72 // return true if handled
73 virtual bool keyPressEvent(QKeyEvent*) { return false; }
74 virtual bool keyReleaseEvent(QKeyEvent*) { return false; }
75
76 virtual bool enterEvent(QEnterEvent*) { return false; }
77 virtual bool leaveEvent(QEvent*) { return false; }
78
79 virtual void clearToolData() {}
80
88 virtual bool isActive() const;
89
90 virtual void paint(QPainter& painter, const QRect& blitRect) { Q_UNUSED(painter) Q_UNUSED(blitRect) }
91
93 virtual bool leavingThisTool();
94
97 virtual bool enteringThisTool() { return true; }
98
99 bool isPropertyEnabled(int rawType);
100 bool isDrawingTool();
101
102signals:
103 bool isActiveChanged(ToolType, bool);
104
105protected:
106 Editor* editor() { return mEditor; }
107 QHash<int, QSet<Layer::LAYER_TYPE>> mPropertyUsed;
108
109 Editor* mEditor = nullptr;
110 ScribbleArea* mScribbleArea = nullptr;
111 QList<QMetaObject::Connection> mActiveConnections;
112
113};
114
115#endif // BASETOOL_H
BaseTool
Definition: basetool.h:47
BaseTool::isActive
virtual bool isActive() const
Check if the tool is active.
Definition: basetool.cpp:137
BaseTool::leavingThisTool
virtual bool leavingThisTool()
Will clean up active connections.
Definition: basetool.cpp:91
BaseTool::enteringThisTool
virtual bool enteringThisTool()
Setup active connections here that should only emit while tool is active leavingThisTool will handle ...
Definition: basetool.h:97
BaseTool::isDrawingTool
bool isDrawingTool()
BaseTool::isDrawingTool - A drawing tool is anything that applies something to the canvas.
Definition: basetool.cpp:128
Editor
Definition: editor.h:71
PointerEvent
Definition: pointerevent.h:8
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
ToolProperties
Definition: toolproperties.h:204
Generated on Wed Dec 24 2025 23:46:02 for Pencil2D by doxygen 1.9.6 based on revision 1be63043db1f7fc0545528fc3b6d5098a552755b