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
|
/*
* kis_tool_crop.h - part of Krita
*
* Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org>
*
* 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_CROP_H_
#define KIS_TOOL_CROP_H_
#include <qpoint.h>
#include <qregion.h>
#include <kis_tool_non_paint.h>
#include <kis_tool_factory.h>
class QRect;
class QCursor;
class WdgToolCrop;
/**
* Crop tool
*
* TODO: - crop from selection -- i.e, set crop outline to the exact bounds of the selection.
* - (when moving to Qt 4: replace rectangle with darker, dimmer overlay layer
* like we have for selections right now)
*/
class KisToolCrop : public KisToolNonPaint {
typedef KisToolNonPaint super;
Q_OBJECT
public:
KisToolCrop();
virtual ~KisToolCrop();
virtual void update(KisCanvasSubject *subject);
virtual QWidget* createOptionWidget(QWidget* parent);
virtual QWidget* optionWidget();
virtual void setup(KActionCollection *collection);
virtual enumToolType toolType() { return TOOL_TRANSFORM; }
virtual Q_UINT32 priority() { return 1; }
virtual void paint(KisCanvasPainter& gc);
virtual void paint(KisCanvasPainter& gc, const QRect& rc);
virtual void buttonPress(KisButtonPressEvent *e);
virtual void move(KisMoveEvent *e);
virtual void buttonRelease(KisButtonReleaseEvent *e);
virtual void doubleClick(KisDoubleClickEvent *);
public slots:
virtual void activate();
virtual void deactivate();
private:
void clearRect();
QRegion handles(QRect rect);
void paintOutlineWithHandles();
void paintOutlineWithHandles(KisCanvasPainter& gc, const QRect& rc);
Q_INT32 mouseOnHandle (const QPoint currentViewPoint);
void setMoveResizeCursor (Q_INT32 handle);
void validateSelection(bool updateratio = true);
void setOptionWidgetX(Q_INT32 x);
void setOptionWidgetY(Q_INT32 y);
void setOptionWidgetWidth(Q_INT32 x);
void setOptionWidgetHeight(Q_INT32 y);
void setOptionWidgetRatio(double ratio);
private slots:
void crop();
void setCropX(int x);
void setCropY(int y);
void setCropWidth(int x);
void setCropHeight(int y);
void setRatio(double ratio);
inline QRect realRectCrop() { QRect r = m_rectCrop; r.setSize(r.size() - QSize(1,1)); return r; }
private:
void updateWidgetValues(bool updateratio = true);
KisCanvasSubject *m_subject;
QRect m_rectCrop; // Is the coordinate of the outline rect and not of the region to crop (to get the region to crop you need to remove 1 to width and height
// QPoint m_startPos;
// QPoint m_endPos;
bool m_selecting;
QPoint m_dragStart;
QPoint m_dragStop;
WdgToolCrop* m_optWidget;
Q_INT32 m_handleSize;
QRegion m_handlesRegion;
bool m_haveCropSelection;
Q_INT32 m_dx, m_dy;
Q_INT32 m_mouseOnHandleType;
QCursor m_cropCursor;
enum handleType
{
None = 0,
UpperLeft = 1,
UpperRight = 2,
LowerLeft = 3,
LowerRight = 4,
Upper = 5,
Lower = 6,
Left = 7,
Right = 8,
Inside = 9
};
};
class KisToolCropFactory : public KisToolFactory {
typedef KisToolFactory super;
public:
KisToolCropFactory() : super() {};
virtual ~KisToolCropFactory(){};
virtual KisTool * createTool(KActionCollection * ac) {
KisTool * t = new KisToolCrop();
Q_CHECK_PTR(t);
t->setup(ac);
return t;
}
virtual KisID id() { return KisID("crop", i18n("Crop Tool")); }
};
#endif // KIS_TOOL_CROP_H_
|