Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_tool.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006 Boudewijn Rempt <boud@valdyas.org>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#ifndef KIS_TOOL_H_
8#define KIS_TOOL_H_
9
10#include <QCursor>
11
12#include <KoColor.h>
13#include <KoToolBase.h>
14#include <KoID.h>
16#include <KoPattern.h>
17#include <KoAbstractGradient.h>
18
19#include <kis_types.h>
20
21#ifdef __GNUC__
22#define WARN_WRONG_MODE(_mode) warnKrita << "Unexpected tool event has come to" << __func__ << "while being mode" << _mode << "!"
23#else
24#define WARN_WRONG_MODE(_mode) warnKrita << "Unexpected tool event has come while being mode" << _mode << "!"
25#endif
26
27#define CHECK_MODE_SANITY_OR_RETURN(_mode) if (mode() != _mode) { WARN_WRONG_MODE(mode()); return; }
28
29class KoCanvasBase;
31class QPainter;
32class QPainterPath;
33class QPolygonF;
35
36//activation id for Krita tools, Krita tools are always active and handle locked and invisible layers by themselves
37static const QString KRITA_TOOL_ACTIVATION_ID = "flake/always";
38
39#include <kritaui_export.h>
40class KRITAUI_EXPORT KisTool : public KoToolBase
41{
42 Q_OBJECT
43
44 Q_PROPERTY(bool isActive READ isActive NOTIFY isActiveChanged)
45
46public:
47 enum { FLAG_USES_CUSTOM_PRESET=0x01, FLAG_USES_CUSTOM_COMPOSITEOP=0x02, FLAG_USES_CUSTOM_SIZE=0x04 };
48
49 KisTool(KoCanvasBase * canvas, const QCursor & cursor);
50 ~KisTool() override;
51
52 virtual int flags() const { return 0; }
53
54 void deleteSelection() override;
55// KoToolBase Implementation.
56
57public:
58
67 virtual void activatePrimaryAction();
68
75 virtual void deactivatePrimaryAction();
76
86 virtual void beginPrimaryAction(KoPointerEvent *event);
87
93 virtual void continuePrimaryAction(KoPointerEvent *event);
94
101 virtual void endPrimaryAction(KoPointerEvent *event);
102
109 virtual void beginPrimaryDoubleClickAction(KoPointerEvent *event);
110
115 virtual bool primaryActionSupportsHiResEvents() const;
116
133
134 // Technically users are allowed to configure this, but nobody ever would do that.
135 // So these can basically be thought of as aliases to ctrl+click, etc.
137 ChangeSize = AlternateChangeSize, // Default: Shift+Left click
138 ChangeSizeSnap = AlternateChangeSizeSnap, // Default: Shift+Z+Left click
139 SampleFgNode = AlternateSampleFgNode, // Default: Ctrl+Alt+Left click
140 SampleBgNode = AlternateSampleBgNode, // Default: Ctrl+Alt+Right click
141 SampleFgGroup = AlternateSampleFgGroup,
142 SampleBgGroup = AlternateSampleBgGroup,
143 SampleFgImage = AlternateSampleFgImage, // Default: Ctrl+Left click
144 SampleBgImage = AlternateSampleBgImage, // Default: Ctrl+Right click
145 Secondary = AlternateSecondary,
146 Third = AlternateThird,
147 Fourth = AlternateFourth,
148 Fifth = AlternateFifth,
149 NONE = 10000
150 };
151
157 MYPAINTBRUSH_UNPAINTABLE
158 };
159 Q_ENUMS(NodePaintAbility)
160
161 static AlternateAction actionToAlternateAction(ToolAction action);
162
163 virtual void activateAlternateAction(AlternateAction action);
164 virtual void deactivateAlternateAction(AlternateAction action);
165
166 virtual void beginAlternateAction(KoPointerEvent *event, AlternateAction action);
167 virtual void continueAlternateAction(KoPointerEvent *event, AlternateAction action);
168 virtual void endAlternateAction(KoPointerEvent *event, AlternateAction action);
169 virtual void beginAlternateDoubleClickAction(KoPointerEvent *event, AlternateAction action);
170 virtual bool alternateActionSupportsHiResEvents(AlternateAction action) const;
171 virtual bool supportsPaintingAssistants() const;
172
173 void mousePressEvent(KoPointerEvent *event) override;
174 void mouseDoubleClickEvent(KoPointerEvent *event) override;
175 void mouseTripleClickEvent(KoPointerEvent *event) override;
176 void mouseReleaseEvent(KoPointerEvent *event) override;
177 void mouseMoveEvent(KoPointerEvent *event) override;
178
179 bool isActive() const;
180
181 KisTool::NodePaintAbility nodePaintAbility();
182
191 virtual void newActivationWithExternalSource(KisPaintDeviceSP externalSource);
192
193public Q_SLOTS:
194 void activate(const QSet<KoShape*> &shapes) override;
195 void deactivate() override;
196 void canvasResourceChanged(int key, const QVariant & res) override;
197 // Implement this slot in case there are any widgets or properties which need
198 // to be updated after certain operations, to reflect the inner state correctly.
199 // At the moment this is used for smoothing options in the freehand brush, but
200 // this will likely be expanded.
201 virtual void updateSettingsViews();
202
203Q_SIGNALS:
204 void isActiveChanged(bool isActivated);
205
206protected:
207 // conversion methods are also needed by the paint information builder
208 friend class KisToolPaintingInformationBuilder;
209
212 QPointF convertToPixelCoord(KoPointerEvent *e);
213 QPointF convertToPixelCoord(const QPointF& pt);
214
215 QPointF convertToPixelCoordAndAlignOnWidget(const QPointF& pt);
216
217 QPointF convertToPixelCoordAndSnap(KoPointerEvent *e, const QPointF &offset = QPointF(), bool useModifiers = true);
218 QPointF convertToPixelCoordAndSnap(const QPointF& pt, const QPointF &offset = QPointF());
219
220protected:
221 QPointF widgetCenterInWidgetPixels();
222 QPointF convertDocumentToWidget(const QPointF& pt);
223
228 QPoint convertToImagePixelCoordFloored(KoPointerEvent *e);
229
230 QRectF convertToPt(const QRectF &rect);
231 qreal convertToPt(qreal value);
232
233 QPointF viewToPixel(const QPointF &viewCoord) const;
236 QPointF pixelToView(const QPoint &pixelCoord) const;
237
239 QPointF pixelToView(const QPointF &pixelCoord) const;
240
242 QRectF pixelToView(const QRectF &pixelRect) const;
243
245 QPainterPath pixelToView(const QPainterPath &pixelPath) const;
246
247 KisOptimizedBrushOutline pixelToView(const KisOptimizedBrushOutline &path) const;
248
250 QPolygonF pixelToView(const QPolygonF &pixelPolygon) const;
251
253 void updateCanvasPixelRect(const QRectF &pixelRect);
254
256 void updateCanvasViewRect(const QRectF &viewRect);
257
258 QWidget* createOptionWidget() override;
259
264 virtual bool listeningToModifiers();
269 virtual void listenToModifiers(bool listen);
270
271protected:
272 KisImageWSP image() const;
273 QCursor cursor() const;
274
275 KisImageWSP currentImage();
278 KisNodeSP currentNode() const;
279 KisNodeList selectedNodes() const;
282 KisPaintOpPresetSP currentPaintOpPreset();
284
287 void paintToolOutline(QPainter * painter, const KisOptimizedBrushOutline &path);
288
290 bool nodeEditable();
291
293 bool selectionEditable();
294
296 bool overrideCursorIfNotEditable();
297
298 bool blockUntilOperationsFinished();
299 void blockUntilOperationsFinishedForced();
300
301protected:
302 enum ToolMode: int {
309 OTHER, // tool-specific modes, like multibrush's symmetry axis setup
310 OTHER_1
311 };
312
313 virtual void setMode(ToolMode mode);
314 virtual ToolMode mode() const;
315 void setCursor(const QCursor &cursor);
316
317protected Q_SLOTS:
321 virtual void resetCursorStyle();
322
323private:
324 struct Private;
325 Private* const d;
326};
327
328
329
330#endif // KIS_TOOL_H_
float value(const T *src, size_t ch)
@ NONE
virtual void deleteSelection()
virtual void mouseTripleClickEvent(KoPointerEvent *event)
virtual QWidget * createOptionWidget()
virtual void mousePressEvent(KoPointerEvent *event)=0
virtual void mouseMoveEvent(KoPointerEvent *event)=0
virtual void activate(const QSet< KoShape * > &shapes)
virtual void canvasResourceChanged(int key, const QVariant &res)
virtual void mouseReleaseEvent(KoPointerEvent *event)=0
virtual void deactivate()
virtual void mouseDoubleClickEvent(KoPointerEvent *event)
static const QString KRITA_TOOL_ACTIVATION_ID
Definition kis_tool.h:37
KoColor currentBgColor()
KisFilterConfigurationSP currentGenerator()
void isActiveChanged(bool isActivated)
KoAbstractGradientSP currentGradient()
@ AlternateFourth
Definition kis_tool.h:129
@ AlternateSampleFgImage
Definition kis_tool.h:125
@ Primary
Definition kis_tool.h:118
@ AlternateChangeSize
Definition kis_tool.h:119
@ AlternateSecondary
Definition kis_tool.h:127
@ AlternateSampleBgNode
Definition kis_tool.h:122
@ AlternateSampleBgImage
Definition kis_tool.h:126
@ AlternateThird
Definition kis_tool.h:128
@ AlternateSampleFgGroup
Definition kis_tool.h:123
@ AlternateSampleBgGroup
Definition kis_tool.h:124
@ AlternateSampleFgNode
Definition kis_tool.h:121
@ AlternateChangeSizeSnap
Definition kis_tool.h:120
@ AlternateFifth
Definition kis_tool.h:130
Private *const d
Definition kis_tool.h:325
virtual int flags() const
Definition kis_tool.h:52
@ SECONDARY_PAINT_MODE
Definition kis_tool.h:305
@ GESTURE_MODE
Definition kis_tool.h:307
@ MIRROR_AXIS_SETUP_MODE
Definition kis_tool.h:306
@ PAINT_MODE
Definition kis_tool.h:304
@ PAN_MODE
Definition kis_tool.h:308
@ HOVER_MODE
Definition kis_tool.h:303
KoPatternSP currentPattern()
KoColor currentFgColor()
QCursor cursor() const
AlternateAction
Definition kis_tool.h:136
NodePaintAbility
Definition kis_tool.h:152
@ UNPAINTABLE
Definition kis_tool.h:156