Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_tool_lazy_brush.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <klocalizedstring.h>
10#include <QAction>
11#include <kactioncollection.h>
12
13#include <KoCanvasBase.h>
14#include <KoCanvasController.h>
15
16#include <KisViewManager.h>
17#include "kis_canvas2.h"
18#include "kis_cursor.h"
19#include "kis_config.h"
20#include "kundo2magicstring.h"
21
22#include "KoProperties.h"
23#include "kis_node_manager.h"
25
28
31
32
43
44
46 : KisToolFreehand(canvas,
47 KisCursor::load("tool_freehand_cursor.xpm", 2, 2),
48 kundo2_i18n("Colorize Mask Key Stroke")),
49 m_d(new Private)
50{
51 setObjectName("tool_lazybrush");
52}
53
57
59{
60 // upgrade to strong pointer
61 KisNodeSP manuallyActivatedNode = m_d->manuallyActivatedNode;
62
63 if (manuallyActivatedNode) {
65 manuallyActivatedNode = 0;
66 }
67
68 m_d->manuallyActivatedNode = 0;
69}
70
71
72void KisToolLazyBrush::activate(const QSet<KoShape*> &shapes)
73{
74 KisCanvas2 * kiscanvas = dynamic_cast<KisCanvas2*>(canvas());
75 KIS_ASSERT(kiscanvas);
76 m_d->toolConnections.addUniqueConnection(
77 kiscanvas->viewManager()->canvasResourceProvider(), SIGNAL(sigNodeChanged(KisNodeSP)),
79
80
81 KisColorizeMask *mask = qobject_cast<KisColorizeMask*>(currentNode().data());
82 if (mask) {
84 }
85
87}
88
90{
93 m_d->toolConnections.clear();
94}
95
97{
98 // upgrade to strong pointer
99 KisNodeSP manuallyActivatedNode = m_d->manuallyActivatedNode;
100
101 if (node != manuallyActivatedNode) {
103
104 KisColorizeMask *mask = qobject_cast<KisColorizeMask*>(node.data());
105 if (mask) {
107 }
108 }
109}
110
112{
113 // If there's no mask yet, we show the hand cursor
116 m_d->activateMaskMode = true;
117 setOutlineVisible(false);
118 }
119 else {
121 }
122}
123
125{
126 KisNodeSP node = currentNode();
127 return node && node->inherits("KisColorizeMask");
128}
129
131{
132 KisNodeSP node = currentNode();
133 return node && node->inherits("KisLayer");
134}
135
137{
138 KisNodeSP node = currentNode();
139
140 return node && node->inherits("KisColorizeMask") &&
143 true).toBool();
144}
145
147{
148 KisNodeSP node = currentNode();
149 if (!node) return;
150
151 KoProperties properties;
152 properties.setProperty("visible", true);
153 properties.setProperty("locked", false);
154
155 QList<KisNodeSP> masks = node->childNodes(QStringList("KisColorizeMask"), properties);
156
157 if (!masks.isEmpty()) {
158 KisCanvas2 * kiscanvas = static_cast<KisCanvas2*>(canvas());
159 KisViewManager* viewManager = kiscanvas->viewManager();
160 viewManager->nodeManager()->slotNonUiActivatedNode(masks.first());
161 } else {
162 KisCanvas2 * kiscanvas = static_cast<KisCanvas2*>(canvas());
163 KisViewManager* viewManager = kiscanvas->viewManager();
164 viewManager->nodeManager()->createNode("KisColorizeMask");
165 }
166}
167
177
179{
180 if (m_d->activateMaskMode) {
181 m_d->activateMaskMode = false;
182 setOutlineVisible(true);
184 }
185
187}
188
190{
191 if (m_d->activateMaskMode) {
194 } else if (shouldActivateKeyStrokes()) {
195 // upgrade to strong pointer
196 KisNodeSP manuallyActivatedNode = m_d->manuallyActivatedNode;
197 KisNodeSP node = currentNode();
198
199 KIS_SAFE_ASSERT_RECOVER_NOOP(!manuallyActivatedNode ||
200 manuallyActivatedNode == node);
201
204 true, image());
205 m_d->manuallyActivatedNode = node;
206 }
207 } else {
209 }
210}
211
213{
214 if (m_d->activateMaskMode) return;
216}
217
219{
220 if (m_d->activateMaskMode) return;
222}
223
225{
226 if (action == KisTool::Secondary && !m_d->activateMaskMode && !m_d->activatedActionLock) {
227 KisNodeSP node = currentNode();
228 if (!node) return;
229
230 m_d->activatedActionLock = true;
231 m_d->oldShowKeyStrokesValue =
234 true).toBool();
235
238 !m_d->oldShowKeyStrokesValue, image());
239
241
242 } else if (action == KisTool::Third && !m_d->activateMaskMode && !m_d->activatedActionLock) {
243 KisNodeSP node = currentNode();
244 if (!node) return;
245
246 m_d->activatedActionLock = true;
247 m_d->oldShowColoringValue =
250 true).toBool();
251
254 !m_d->oldShowColoringValue, image());
255
257
258 } else {
260 }
261}
262
264{
265 if (action == KisTool::Secondary && !m_d->activateMaskMode) {
266 KisNodeSP node = currentNode();
267 if (!node) return;
268
269 bool showKeyStrokes =
271
274 m_d->oldShowKeyStrokesValue, image());
275
276 // if the values are same, means the property update hasn't finished. So, we should hold on to the lock
277 if (m_d->oldShowKeyStrokesValue != showKeyStrokes) {
278 m_d->activatedActionLock = false;
279 }
280
282
283 } else if (action == KisTool::Third && !m_d->activateMaskMode) {
284 KisNodeSP node = currentNode();
285 if (!node) return;
286
287 bool colorizeShowColoring =
289
292 m_d->oldShowColoringValue, image());
293
294 // if the values are same, means the property update hasn't finished. So, we should hold on to the lock
295 if (m_d->oldShowColoringValue != colorizeShowColoring) {
296 m_d->activatedActionLock = false;
297 }
298
300
301 } else {
303 }
304}
305
307{
308 if (!m_d->activateMaskMode && (action == KisTool::Secondary || action == KisTool::Third)) {
309 beginPrimaryAction(event);
310 } else {
312 }
313}
314
323
325{
326 if (!m_d->activateMaskMode && (action == KisTool::Secondary || action == KisTool::Third)) {
327 endPrimaryAction(event);
328 } else {
330 }
331}
332
334{
335 if (m_d->activateMaskMode) {
337 } else if (colorizeMaskActive()) {
338 KisNodeSP node = currentNode();
339 if (!node) return;
340
342 }
343}
344
346{
347 KisCanvas2 * kiscanvas = dynamic_cast<KisCanvas2*>(canvas());
348 KIS_ASSERT(kiscanvas);
349
350 QWidget *optionsWidget = new KisToolLazyBrushOptionsWidget(kiscanvas->viewManager()->canvasResourceProvider(), 0);
351 optionsWidget->setObjectName(toolId() + "option widget");
352
353 // // See https://bugs.kde.org/show_bug.cgi?id=316896
354 // QWidget *specialSpacer = new QWidget(optionsWidget);
355 // specialSpacer->setObjectName("SpecialSpacer");
356 // specialSpacer->setFixedSize(0, 0);
357 // optionsWidget->layout()->addWidget(specialSpacer);
358
359
360 return optionsWidget;
361}
362
363
QList< QString > QStringList
KisViewManager * viewManager() const
void regeneratePrefilteredDeviceIfNeeded()
static QCursor handCursor()
static QVariant nodeProperty(KisNodeSP node, const KoID &id, const QVariant &defaultValue)
static void setNodePropertyAutoUndo(KisNodeSP node, const KoID &id, const QVariant &value, KisImageSP image)
KisNodeSP createNode(const QString &nodeType, bool quiet=false, KisPaintDeviceSP copyFrom=0)
void slotNonUiActivatedNode(KisNodeSP node)
void deactivate() override
void continuePrimaryAction(KoPointerEvent *event) override
void activateAlternateAction(AlternateAction action) override
void activate(const QSet< KoShape * > &shapes) override
void deactivateAlternateAction(AlternateAction action) override
void beginPrimaryAction(KoPointerEvent *event) override
void beginAlternateAction(KoPointerEvent *event, AlternateAction action) override
void endAlternateAction(KoPointerEvent *event, AlternateAction action) override
void continueAlternateAction(KoPointerEvent *event, AlternateAction action) override
void resetCursorStyle() override
void endPrimaryAction(KoPointerEvent *event) override
The KisToolLazyBrushOptionsWidget class.
void deactivateAlternateAction(AlternateAction action) override
void activate(const QSet< KoShape * > &shapes) override
void continueAlternateAction(KoPointerEvent *event, AlternateAction action) override
bool colorizeMaskActive() const
void slotCurrentNodeChanged(KisNodeSP node)
void activateAlternateAction(AlternateAction action) override
KisToolLazyBrush(KoCanvasBase *canvas)
void endPrimaryAction(KoPointerEvent *event) override
QWidget * createOptionWidget() override
void deactivatePrimaryAction() override
void beginPrimaryAction(KoPointerEvent *event) override
void explicitUserStrokeEndRequest() override
explicitUserStrokeEndRequest is called by the input manager when the user presses Enter key or any eq...
void deactivate() override
void activatePrimaryAction() override
void endAlternateAction(KoPointerEvent *event, AlternateAction action) override
void beginAlternateAction(KoPointerEvent *event, AlternateAction action) override
void continuePrimaryAction(KoPointerEvent *event) override
bool shouldActivateKeyStrokes() const
void resetCursorStyle() override
const QScopedPointer< Private > m_d
bool canCreateColorizeMask() const
void setOutlineVisible(bool visible)
KisNodeManager * nodeManager() const
The node manager handles everything about nodes.
KisCanvasResourceProvider * canvasResourceProvider()
void setProperty(const QString &name, const QVariant &value)
Q_INVOKABLE QString toolId() const
void useCursor(const QCursor &cursor)
QAction * action(const QString &name) const
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130
#define KIS_ASSERT(cond)
Definition kis_assert.h:33
KUndo2MagicString kundo2_i18n(const char *text)
QList< KisNodeSP > childNodes(const QStringList &nodeTypes, const KoProperties &properties) const
Definition kis_node.cpp:439
KisSignalAutoConnectionsStore toolConnections
virtual void activatePrimaryAction()
Definition kis_tool.cc:421
KisNodeSP currentNode() const
Definition kis_tool.cc:370
KisImageWSP image() const
Definition kis_tool.cc:332
virtual void deactivatePrimaryAction()
Definition kis_tool.cc:426
AlternateAction
Definition kis_tool.h:134
@ Secondary
Definition kis_tool.h:141
KisCanvas2 * canvas