1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
/*
* kis_tool_curve.h -- part of Chalk
*
* Copyright (c) 2006 Emanuele Tamponi <emanuele@valinor.it>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KIS_TOOL_CURVE_H_
#define KIS_TOOL_CURVE_H_
#include <tqpen.h>
#include <tqcursor.h>
#include "kis_selection.h"
#include "kis_tool_paint.h"
#include "kis_canvas_subject.h"
#include "kis_point.h"
#include "kis_curve_framework.h"
class TQRect;
class KisPainter;
class KisSelectionOptions;
typedef TQPair<KisCurve::iterator,bool> PointPair;
const double MAXDISTANCE = 2.5;
double pointToSegmentDistance(const KisPoint& p, const KisPoint& l0, const KisPoint& l1);
class KisToolCurve : public KisToolPaint {
typedef KisToolPaint super;
Q_OBJECT
TQ_OBJECT
public:
KisToolCurve(const TQString& UIName);
virtual ~KisToolCurve();
virtual void update (KisCanvasSubject *subject);
virtual TQWidget* createOptionWidget(TQWidget* parent);
virtual void buttonPress(KisButtonPressEvent *event);
virtual void move(KisMoveEvent *event);
virtual void buttonRelease(KisButtonReleaseEvent *event);
virtual void doubleClick(KisDoubleClickEvent *event);
virtual void keyPress(TQKeyEvent *event);
virtual void keyRelease(TQKeyEvent *event);
public slots:
virtual void deactivate();
protected:
virtual void paint(KisCanvasPainter&);
virtual void paint(KisCanvasPainter&, const TQRect&);
/* ********************** *
* KisToolCurve interface *
* ********************** */
/*
* This keep in sync the options of the tool with the options of the curve
*/
virtual int updateOptions(int);
virtual PointPair pointUnderMouse(const TQPoint& pos);
virtual KisCurve::iterator handleUnderMouse(const TQPoint& pos);
/*
* Select the needed points; called after pointUnderMouse
*/
virtual KisCurve::iterator selectByMouse(KisCurve::iterator it);
/*
* draw() initializes the KisCanvasPainter and then loop on the points of the curve for drawing them.
*/
virtual void draw(bool = true, bool = false);
virtual void draw(KisCurve::iterator inf, bool = false, bool = true);
/*
* Used by draw() to draw the current point of the curve. Can draw more than one point and then returns the last one
*/
virtual KisCurve::iterator drawPoint(KisCanvasPainter& gc, KisCurve::iterator point);
/*
* Used by draw(), if a point is a pivot, this draw the handle around it (if m_drawPivots is set to true)
*/
virtual void drawPivotHandle(KisCanvasPainter& gc, KisCurve::iterator point);
/*
* Methods for commiting the curve
*/
/*
* Called by selectCurve(), this convert m_curve to a vector of KisPoint in order to be used by paintPolygon()
*/
virtual TQValueVector<KisPoint> convertCurve();
/*
* Called by paintCurve(), it behaves essentially like drawPoint(), but this uses a KisPainter
*/
virtual KisCurve::iterator paintPoint(KisPainter&, KisCurve::iterator);
/*
* Finish the curve: if the tool is a TOOL_SHAPE or TOOL_FREEHAND, calls paintCurve(), if it's a TOOL_SELECT, then selectCurve()
*/
virtual void commitCurve();
/*
* Used by commitCurve() if the tool is a painting tool
*/
virtual void paintCurve();
/*
* Used by commitCurve() if the tool is a selection tool
*/
virtual void selectCurve();
/*
* Return the rect around a given point, assuming that that point is an unselected pivot
*/
TQRect pivotRect (const TQPoint&);
/*
* Same as above for selected pivots
*/
TQRect selectedPivotRect (const TQPoint&);
protected:
KisImageSP m_currentImage;
KisCurve *m_curve;
KisCurve::iterator m_current;
KisCurve::iterator m_previous;
KisPoint m_currentPoint;
bool m_dragging;
bool m_drawPivots;
TQPen m_drawingPen;
TQPen m_pivotPen;
TQPen m_selectedPivotPen;
int m_pivotRounding;
int m_selectedPivotRounding;
int m_actionOptions;
bool m_supportMinimalDraw;
bool m_draggingCursor;
TQString m_transactionMessage;
TQString m_cursor;
private:
TQString m_UIName;
/* ********************************** *
* Selection Tools specific functions *
* ********************************** */
public:
/*
* This initializes our Option Widget (called by createOptionWidget())
*/
virtual TQWidget* createSelectionOptionWidget(TQWidget* parent);
/*
* This return our internal KisSelectionOptions if toolType() returns TOOL_SELECT
*/
virtual TQWidget* optionWidget();
public slots:
/*
* Slot for createSelectionOptionWidget()
*/
virtual void slotSetAction(int);
private:
/*
* Members used by slotSetAction() and selectCurve()
*/
KisSelectionOptions* m_optWidget;
enumSelectionMode m_selectAction;
};
#endif //__KIS_TOOL_CURVE_H_
|