1 /*
2    Drawpile - a collaborative drawing program.
3 
4    Copyright (C) 2006-2019 Calle Laakkonen
5 
6    Drawpile is free software: you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation, either version 3 of the License, or
9    (at your option) any later version.
10 
11    Drawpile 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    You should have received a copy of the GNU General Public License
17    along with Drawpile.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 #ifndef TOOLS_TOOL_H
20 #define TOOLS_TOOL_H
21 
22 #include "core/point.h"
23 
24 #include <QCursor>
25 
26 /**
27  * @brief Tools
28  *
29  * Tools translate commands from the local user into messages that
30  * can be sent over the network.
31  * Read-only tools can access the canvas directly.
32  */
33 namespace tools {
34 
35 class ToolController;
36 
37 /**
38  * @brief Base class for all tools
39  * Tool classes interpret mouse/pen commands into editing actions.
40  */
41 class Tool
42 {
43 public:
44 	enum Type {
45 		FREEHAND, ERASER, LINE, RECTANGLE, ELLIPSE, BEZIER,
46 		FLOODFILL, ANNOTATION,
47 		PICKER, LASERPOINTER,
48 		SELECTION, POLYGONSELECTION,
49 		ZOOM, INSPECTOR,
50 		_LASTTOOL};
51 
Tool(ToolController & owner,Type type,const QCursor & cursor)52 	Tool(ToolController &owner, Type type, const QCursor &cursor)
53 		: owner(owner), m_type(type), m_cursor(cursor)
54 		{}
~Tool()55 	virtual ~Tool() {}
56 
type()57 	Type type() const { return m_type; }
cursor()58 	const QCursor &cursor() const { return m_cursor; }
59 
60 	/**
61 	 * @brief Start a new stroke
62 	 * @param point starting point
63 	 * @param right is the right mouse/pen button pressed instead of the left one
64 	 * @param zoom the current view zoom factor
65 	 */
66 	virtual void begin(const paintcore::Point& point, bool right, float zoom) = 0;
67 
68 	/**
69 	 * @brief Continue a stroke
70 	 * @param point new point
71 	 * @param constrain is the "constrain motion" button pressed
72 	 * @param cener is the "center on start point" button pressed
73 	 */
74 	virtual void motion(const paintcore::Point& point, bool constrain, bool center) = 0;
75 
76 	/**
77 	 * @brief Tool hovering over the canvas
78 	 * @param point tool position
79 	 */
hover(const QPointF & point)80 	virtual void hover(const QPointF &point) { Q_UNUSED(point); }
81 
82 	//! End stroke
83 	virtual void end() = 0;
84 
85 	//! Finish and commit a multipart stroke
finishMultipart()86 	virtual void finishMultipart() { }
87 
88 	//! Cancel the current multipart stroke (if any)
cancelMultipart()89 	virtual void cancelMultipart() { }
90 
91 	//! Undo the latest step of a multipart stroke. Undoing the first part should cancel the stroke
undoMultipart()92 	virtual void undoMultipart() { }
93 
94 	//! Is there a multipart stroke in progress at the moment?
isMultipart()95 	virtual bool isMultipart() const { return false; }
96 
97 	//! Add an offset to this tool's current position (if active)
offsetActiveTool(int x,int y)98 	virtual void offsetActiveTool(int x, int y) { Q_UNUSED(x) Q_UNUSED(y) /* most tools don't need to do anything here */ }
99 
100 	//! Does this tool allow stroke smoothing to be used?
allowSmoothing()101 	virtual bool allowSmoothing() const { return false; }
102 
103 protected:
104 	ToolController &owner;
105 
106 private:
107 	const Type m_type;
108 	const QCursor m_cursor;
109 };
110 
111 }
112 
113 #endif
114 
115