Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_assistant_tool.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2008 Cyrille Berger <cberger@cberger.net>
3 * SPDX-FileCopyrightText: 2017 Scott Petrovic <scottpetrovic@gmail.com>
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7
8#ifndef _KIS_ASSISTANT_TOOL_H_
9#define _KIS_ASSISTANT_TOOL_H_
10
11#include <QPointer>
12
13#include <KoToolFactoryBase.h>
14#include <KoIcon.h>
15
16#include <kis_tool.h>
18#include <kis_icon.h>
19#include <kis_canvas2.h>
20
21#include "ui_AssistantsToolOptions.h"
22
23/* The assistant tool allows artists to create special guides on the canvas
24 * to help them with things like perspective and parallel lines
25 * This tool has its own canvas decoration on it that only appears when the tool
26 * is active. This decoration allows people to edit assistant points as well as delete assistants
27 * Many of the operations here are forwarded on to another class (kis_painting_assistant_decoration)
28 * that stores the assistant information as well as the decoration information with lines
29 *
30 * Drawing in two separate classes creates an issue where the editor controls in this class
31 * are covered by the kis_painting_assistant_decoration class. In the future, we probably need to
32 * do all the drawing in one class so we have better control of what is in front
33 */
35{
36 Q_OBJECT
38 MODE_CREATION, // This is the mode when there is not yet a perspective grid
39 MODE_EDITING, // This is the mode when the grid has been created, and we are waiting for the user to click on a control box
40 MODE_DRAGGING_NODE, // In this mode one node is translated
41 MODE_DRAGGING_TRANSLATING_TWONODES, // This mode is used when creating a new sub perspective grid
42 MODE_DRAGGING_EDITOR_WIDGET // This mode is used when dragging/moving the little editor widget
43 };
44public:
46 ~KisAssistantTool() override;
47
48 virtual quint32 priority() {
49 return 3;
50 }
51
52
53 /* this is a very big function that has to figure out if we are adding a new assistant,
54 * or editing an existing one when we click on the canvas. There is also a lot of logic
55 * in here that is specific to certain assistants and how they should be handled.
56 * The editor widget is not a UI file, so the move, delete, preview areas have manual
57 * hitbox regions specified to know if a click is doing any of those actions.
58 */
59 void beginPrimaryAction(KoPointerEvent *event) override;
60
61 // We will need this to allow Shift-modifier to align to axes when making new assistants
63
64 void continuePrimaryAction(KoPointerEvent *event) override;
65 void endPrimaryAction(KoPointerEvent *event) override;
68 void mouseMoveEvent(KoPointerEvent *event) override;
69 void keyPressEvent(QKeyEvent *event) override;
70
71
72 QWidget *createOptionWidget() override;
73
74private:
75 // adds and removes assistant.
76 // this is event is forwarded to the kis_painting_decoration class
77 // perspective grids seem to be managed in two places with these calls
78 void addAssistant();
80
82
83 // Handles both shift+mouse-drag or shift+mouse-move snapping
84 // Returns true if snapping is successful
85 // This uses m_handleDrag or m_newAssistant to figure out what handle to snap and where
86 bool snap(KoPointerEvent *event);
87
88 //Recorded state for toggle panel for docker tool options visibility
92 void endActionImpl(KoPointerEvent *event);
93 //function to calculate new button positions for editor widget
95public Q_SLOTS:
96 void activate(const QSet<KoShape*> &shapes) override;
97 void deactivate() override;
98
99
101 void slotChangeTwoPointDensity(double value);
105 void slotEnableFixedLength(int enabled);
106 void slotChangeFixedLength(double value);
107
108private Q_SLOTS:
109 void removeAllAssistants();
110 void saveAssistants();
111 void loadAssistants();
112 void updateToolOptionsUI();
113
116 void slotGlobalAssistantsColorChanged(const QColor&);
118
122
124 void slotChangeFixedLengthUnit(int index);
125
127
128 //When the user checks an editor widget button checkbox, update the AssistantEditorData
129 //struct within the current document's KisPaintingAssistantsDecoration instance
130 void slotToggleMoveButton(int index);
131 void slotToggleSnapButton(int index);
132 void slotToggleLockButton(int index);
133 void slotToggleDuplicateButton(int index);
134 void slotToggleDeleteButton(int index);
135
136protected:
141 void paint(QPainter& gc, const KoViewConverter &converter) override;
142
143protected:
147
156
160
164 Ui::AssistantsToolOptions m_options;
165 QWidget* m_optionsWidget {0};
166 QPointF m_dragStart;
167 QLineF m_radius;
168 bool m_snapIsRadial {false};
169 QPointF m_dragEnd;
170 int m_handleSize {17}; // how large the editor handles will appear
171 int m_handleMaxDist {81}; // how far away the user can click and still select a handle
172 bool assistantDuplicatingFlag {false}; // this flag is set during an assistant duplication
173
174private:
175 void drawEditorWidget(KisPaintingAssistantSP assistant, QPainter& _gc);
178 int m_assistantHelperYOffset {10}; // used by the assistant editor icons for placement on the canvas.
181};
182
183
185{
186public:
188 : KoToolFactoryBase("KisAssistantTool") {
189 setToolTip(i18n("Assistant Tool"));
191 setIconName(koIconNameCStr("krita_tool_assistant"));
192 setPriority(0);
194 }
195
196
198
200 return new KisAssistantTool(canvas);
201 }
202
203};
204
205
206#endif
207
float value(const T *src, size_t ch)
KoToolBase * createTool(KoCanvasBase *canvas) override
KisPaintingAssistantHandleSP m_selectedNode2
void endPrimaryAction(KoPointerEvent *event) override
void slotChangeFixedLength(double value)
Ui::AssistantsToolOptions m_options
KisPaintingAssistantHandleSP m_handleHover
KisPaintingAssistantHandleSP m_handleDrag
void slotChangeTwoPointUseVertical(int value)
bool snap(KoPointerEvent *event)
void assistantSelected(KisPaintingAssistantSP assistant)
void slotToggleMoveButton(int index)
KisPaintingAssistantSP m_assistantDrag
void activate(const QSet< KoShape * > &shapes) override
void slotToggleDuplicateButton(int index)
void continueAlternateAction(KoPointerEvent *event, AlternateAction action) override
void endAlternateAction(KoPointerEvent *event, AlternateAction action) override
void drawEditorWidget(KisPaintingAssistantSP assistant, QPainter &_gc)
QList< KisPaintingAssistantHandleSP > m_handles
void beginPrimaryAction(KoPointerEvent *event) override
void slotChangeFixedLengthUnit(int index)
void mouseMoveEvent(KoPointerEvent *event) override
void slotChangeTwoPointDensity(double value)
KisPaintingAssistantSP m_newAssistant
QList< KisPaintingAssistantHandleSP > m_sideHandles
void removeAssistant(KisPaintingAssistantSP assistant)
void paint(QPainter &gc, const KoViewConverter &converter) override
void slotChangeMinorSubdivisions(int value)
void slotToggleLockButton(int index)
void slotChangeVanishingPointAngle(double value)
void slotGlobalAssistantsColorChanged(const QColor &)
KisPaintingAssistantHandleSP m_highlightedNode
void keyPressEvent(QKeyEvent *event) override
void beginAlternateAction(KoPointerEvent *event, KisTool::AlternateAction action) override
KisPaintingAssistantHandleSP m_handleCombine
KisAssistantTool(KoCanvasBase *canvas)
KisSpinBoxUnitManager * m_unitManager
void endActionImpl(KoPointerEvent *event)
void slotToggleSnapButton(int index)
void continuePrimaryAction(KoPointerEvent *event) override
void beginActionImpl(KoPointerEvent *event)
void slotChangeSubdivisions(int value)
PerspectiveAssistantEditionMode m_internalMode
QList< KisPaintingAssistantSP > m_origAssistantList
QWidget * createOptionWidget() override
void deactivate() override
void slotToggleDeleteButton(int index)
virtual quint32 priority()
void slotEnableFixedLength(int enabled)
QPointer< KisCanvas2 > m_canvas
void continueActionImpl(KoPointerEvent *event)
KisPaintingAssistantHandleSP m_selectedNode1
The KisSpinBoxUnitManager class is an abstract interface for the unitspinboxes classes to manage diff...
QAction * action(const QString &name) const
void setSection(const QString &section)
void setActivationShapeId(const QString &activationShapeId)
void setIconName(const char *iconName)
void setToolTip(const QString &tooltip)
void setPriority(int newPriority)
#define koIconNameCStr(name)
Definition kis_icon.h:28
static const QString KRITA_TOOL_ACTIVATION_ID
Definition kis_tool.h:37
static const QString View
Assistance tools: guides, reference, etc.
AlternateAction
Definition kis_tool.h:134
KisCanvas2 * canvas