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.cpp
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#include "basetool.h"
19
20#include <array>
21#include "editor.h"
22#include "viewmanager.h"
23#include "scribblearea.h"
24#include "strokeinterpolator.h"
25#include "pointerevent.h"
26#include "layermanager.h"
27
28QString BaseTool::TypeName(ToolType type)
29{
30 static std::array<QString, TOOL_TYPE_COUNT> map;
31
32 if (map[0].isEmpty())
33 {
34 map[PENCIL] = tr("Pencil");
35 map[ERASER] = tr("Eraser");
36 map[SELECT] = tr("Select");
37 map[MOVE] = tr("Move");
38 map[HAND] = tr("Hand");
39 map[SMUDGE] = tr("Smudge");
40 map[PEN] = tr("Pen");
41 map[POLYLINE] = tr("Polyline");
42 map[BUCKET] = tr("Bucket");
43 map[EYEDROPPER] = tr("Eyedropper");
44 map[BRUSH] = tr("Brush");
45 map[CAMERA] = tr("Camera");
46 }
47 return map.at(type);
48}
49
50BaseTool::BaseTool(QObject* parent) : QObject(parent)
51{
52}
53
54BaseTool::~BaseTool() {}
55
56void BaseTool::initialize(Editor* editor)
57{
58 Q_ASSERT(editor);
59 mEditor = editor;
60 mScribbleArea = editor->getScribbleArea();
61 Q_ASSERT(mScribbleArea);
62 loadSettings();
63}
64
65void BaseTool::saveSettings()
66{
67 QSettings storedSettings(PENCIL2D, PENCIL2D);
68 toolProperties().storeTo(storedSettings);
69}
70
71void BaseTool::resetSettings()
72{
73 toolProperties().restoreProperties();
74}
75
76bool BaseTool::isPropertyEnabled(int rawType)
77{
78 Layer* currentLayer = mEditor->layers()->currentLayer();
79 if (!currentLayer) {
80 return false;
81 }
82
83 return mPropertyUsed[rawType].contains(currentLayer->type());
84}
85
86QCursor BaseTool::cursor()
87{
88 return Qt::ArrowCursor;
89}
90
91bool BaseTool::leavingThisTool()
92{
93 for (auto& connection : mActiveConnections) {
94 disconnect(connection);
95 mActiveConnections.removeOne(connection);
96 }
97
98 saveSettings();
99
100 return true;
101}
102
103void BaseTool::pointerPressEvent(PointerEvent* event)
104{
105 event->accept();
106}
107
108void BaseTool::pointerMoveEvent(PointerEvent* event)
109{
110 event->accept();
111}
112
113void BaseTool::pointerReleaseEvent(PointerEvent* event)
114{
115 event->accept();
116}
117
118void BaseTool::pointerDoubleClickEvent(PointerEvent* event)
119{
120 pointerPressEvent(event);
121}
122
128bool BaseTool::isDrawingTool()
129{
130 if (type() == ToolType::HAND || type() == ToolType::MOVE || type() == ToolType::CAMERA || type() == ToolType::SELECT )
131 {
132 return false;
133 }
134 return true;
135}
136
137bool BaseTool::isActive() const
138{
139 return false;
140}
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::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
Layer
Definition: layer.h:33
PointerEvent
Definition: pointerevent.h:8
QCursor
QHash::contains
bool contains(const Key &key) const const
QObject
QObject::disconnect
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QObject::event
virtual bool event(QEvent *e)
QObject::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
QSettings
QString
Qt::ArrowCursor
ArrowCursor
Generated on Wed Dec 24 2025 23:46:02 for Pencil2D by doxygen 1.9.6 based on revision 1be63043db1f7fc0545528fc3b6d5098a552755b