Krita Source Code Documentation
Loading...
Searching...
No Matches
KisToolGradient Class Reference

#include <kis_tool_gradient.h>

+ Inheritance diagram for KisToolGradient:

Public Slots

void activate (const QSet< KoShape * > &shapes) override
 
- Public Slots inherited from KisToolPaint
void activate (const QSet< KoShape * > &shapes) override
 
void deactivate () override
 
- Public Slots inherited from KisTool
void activate (const QSet< KoShape * > &shapes) override
 
void canvasResourceChanged (int key, const QVariant &res) override
 
void deactivate () override
 
virtual void updateSettingsViews ()
 
- Public Slots inherited from KoToolBase
virtual void activate (const QSet< KoShape * > &shapes)
 
virtual void deactivate ()
 
virtual void documentResourceChanged (int key, const QVariant &res)
 
virtual void repaintDecorations ()
 
virtual void requestRedoDuringStroke ()
 
virtual void requestStrokeCancellation ()
 
virtual void requestStrokeEnd ()
 
virtual void requestUndoDuringStroke ()
 
void setStatusText (const QString &statusText)
 
void updateOptionsWidgetIcons ()
 

Public Member Functions

void beginPrimaryAction (KoPointerEvent *event) override
 
void continuePrimaryAction (KoPointerEvent *event) override
 
QWidget * createOptionWidget () override
 
void endPrimaryAction (KoPointerEvent *event) override
 
 KisToolGradient (KoCanvasBase *canvas)
 
void paint (QPainter &painter, const KoViewConverter &converter) override
 
 ~KisToolGradient () override
 
- Public Member Functions inherited from KisToolPaint
int flags () const override
 
 KisToolPaint (KoCanvasBase *canvas, const QCursor &cursor)
 
void mouseMoveEvent (KoPointerEvent *event) override
 
void mousePressEvent (KoPointerEvent *event) override
 
void mouseReleaseEvent (KoPointerEvent *event) override
 
KisPopupWidgetInterfacepopupWidget () override
 
 ~KisToolPaint () override
 
- Public Member Functions inherited from KisTool
virtual bool alternateActionSupportsHiResEvents (AlternateAction action) const
 
virtual void beginAlternateDoubleClickAction (KoPointerEvent *event, AlternateAction action)
 
virtual void beginPrimaryDoubleClickAction (KoPointerEvent *event)
 
void deleteSelection () override
 
bool isActive () const
 
 KisTool (KoCanvasBase *canvas, const QCursor &cursor)
 
void mouseDoubleClickEvent (KoPointerEvent *event) override
 
void mouseTripleClickEvent (KoPointerEvent *event) override
 
virtual void newActivationWithExternalSource (KisPaintDeviceSP externalSource)
 newActivationWithExternalSource Makes sure that the tool is active and starts a new stroke, which will be able to access the pixels from the specified external source.
 
KisTool::NodePaintAbility nodePaintAbility ()
 
virtual bool primaryActionSupportsHiResEvents () const
 
virtual bool supportsPaintingAssistants () const
 
 ~KisTool () override
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 
- Public Member Functions inherited from KoToolBase
QAction * action (const QString &name) const
 
KoCanvasBasecanvas () const
 Returns the canvas the tool is working on.
 
virtual void copy () const
 
QCursor cursor () const
 return the last emitted cursor
 
virtual void customMoveEvent (KoPointerEvent *event)
 
virtual void customPressEvent (KoPointerEvent *event)
 
virtual void customReleaseEvent (KoPointerEvent *event)
 
virtual void cut ()
 
virtual QRectF decorationsRect () const
 
int decorationThickness () const
 decorationThickness The minimum thickness for tool decoration lines, this is derived from the screen magnification, thus the HiDPI settings. Note: to use this effectively, also set the pen to isCosmetic(true);
 
virtual void deselect ()
 deselect the tool should clear the selection if it has one.
 
virtual void dragLeaveEvent (QDragLeaveEvent *event)
 
virtual void dragMoveEvent (QDragMoveEvent *event, const QPointF &point)
 
virtual void dropEvent (QDropEvent *event, const QPointF &point)
 
virtual void explicitUserStrokeEndRequest ()
 explicitUserStrokeEndRequest is called by the input manager when the user presses Enter key or any equivalent. This callback comes before requestStrokeEnd(), which comes from a different source.
 
KoToolFactoryBasefactory () const
 
virtual void focusInEvent (QFocusEvent *event)
 
virtual void focusOutEvent (QFocusEvent *event)
 
virtual bool hasSelection ()
 
virtual void inputMethodEvent (QInputMethodEvent *event)
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery query) const
 
bool isInTextMode () const
 
bool isOpacityPresetMode () const
 
virtual void keyPressEvent (QKeyEvent *event)
 
virtual void keyReleaseEvent (QKeyEvent *event)
 
 KoToolBase (KoCanvasBase *canvas)
 
bool maskSyntheticEvents () const
 
QList< QPointer< QWidget > > optionWidgets ()
 
virtual bool paste ()
 
virtual QMenu * popupActionsMenu ()
 
virtual bool selectAll ()
 selectAll select all data the tool can select.
 
virtual KoToolSelectionselection ()
 
Q_INVOKABLE QString toolId () const
 
virtual bool wantsAutoScroll () const
 
 ~KoToolBase () override
 

Protected Slots

void resetCursorStyle () override
 
- Protected Slots inherited from KisTool
virtual void resetCursorStyle ()
 

Private Slots

void areaDone (const QRect &rc)
 
void slotSetAntiAliasThreshold (qreal)
 
void slotSetDither (bool)
 
void slotSetRepeat (int)
 
void slotSetReverse (bool)
 
void slotSetShape (int)
 

Private Member Functions

void paintLine (QPainter &gc)
 
QPointF straightLine (QPointF point)
 
void updateGuideline ()
 

Private Attributes

double m_antiAliasThreshold {0.0}
 
QCheckBox * m_ckDither {nullptr}
 
QCheckBox * m_ckReverse {nullptr}
 
KComboBox * m_cmbRepeat {nullptr}
 
KComboBox * m_cmbShape {nullptr}
 
KConfigGroup m_configGroup
 
bool m_dither {false}
 
QPointF m_endPos
 
QLabel * m_lbAntiAliasThreshold {nullptr}
 
QLabel * m_lbRepeat {nullptr}
 
QLabel * m_lbShape {nullptr}
 
KisGradientPainter::enumGradientRepeat m_repeat
 
bool m_reverse {false}
 
KisGradientPainter::enumGradientShape m_shape
 
KisDoubleSliderSpinBoxm_slAntiAliasThreshold {nullptr}
 
QPointF m_startPos
 

Additional Inherited Members

- Public Types inherited from KisTool
enum  { FLAG_USES_CUSTOM_PRESET =0x01 , FLAG_USES_CUSTOM_COMPOSITEOP =0x02 , FLAG_USES_CUSTOM_SIZE =0x04 }
 
enum  AlternateAction {
  ChangeSize = AlternateChangeSize , ChangeSizeSnap = AlternateChangeSizeSnap , SampleFgNode = AlternateSampleFgNode , SampleBgNode = AlternateSampleBgNode ,
  SampleFgImage = AlternateSampleFgImage , SampleBgImage = AlternateSampleBgImage , Secondary = AlternateSecondary , Third = AlternateThird ,
  Fourth = AlternateFourth , Fifth = AlternateFifth , NONE = 10000
}
 
enum  NodePaintAbility {
  VECTOR , CLONE , PAINT , UNPAINTABLE ,
  MYPAINTBRUSH_UNPAINTABLE
}
 
enum  ToolAction {
  Primary , AlternateChangeSize , AlternateChangeSizeSnap , AlternateSampleFgNode ,
  AlternateSampleBgNode , AlternateSampleFgImage , AlternateSampleBgImage , AlternateSecondary ,
  AlternateThird , AlternateFourth , AlternateFifth , Alternate_NONE = 10000
}
 
- Signals inherited from KisToolPaint
void sigPaintingFinished ()
 
- Signals inherited from KisTool
void isActiveChanged (bool isActivated)
 
- Signals inherited from KoToolBase
void activateTool (const QString &id)
 
void cursorChanged (const QCursor &cursor)
 
void selectionChanged (bool hasSelection)
 
void statusTextChanged (const QString &statusText)
 
void textModeChanged (bool inTextMode)
 
- Static Public Member Functions inherited from KisTool
static AlternateAction actionToAlternateAction (ToolAction action)
 
- Public Attributes inherited from KisTool
KoColor currentBgColor
 
float currentExposure {1.0}
 
KoColor currentFgColor
 
KisFilterConfigurationSP currentGenerator
 
KoAbstractGradientSP currentGradient
 
KoPatternSP currentPattern
 
QCursor cursor
 
bool m_isActive {false}
 
ToolMode m_mode {HOVER_MODE}
 
QWidget * optionWidget {0}
 
- Public Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 
- Protected Types inherited from KisTool
enum  ToolMode : int {
  HOVER_MODE , PAINT_MODE , SECONDARY_PAINT_MODE , MIRROR_AXIS_SETUP_MODE ,
  GESTURE_MODE , PAN_MODE , OTHER , OTHER_1
}
 
- Protected Member Functions inherited from KisToolPaint
void activateAlternateAction (AlternateAction action) override
 
void activatePrimaryAction () override
 
void addOptionWidgetLayout (QLayout *layout)
 Add the tool-specific layout to the default option widget layout.
 
virtual void addOptionWidgetOption (QWidget *control, QWidget *label=nullptr)
 Add a widget and a label to the current option widget layout.
 
void beginAlternateAction (KoPointerEvent *event, AlternateAction action) override
 
void canvasResourceChanged (int key, const QVariant &v) override
 
void continueAlternateAction (KoPointerEvent *event, AlternateAction action) override
 
QWidget * createOptionWidget () override
 
void deactivateAlternateAction (AlternateAction action) override
 
void deactivatePrimaryAction () override
 
void enableControl (QWidget *control, bool value)
 
void endAlternateAction (KoPointerEvent *event, AlternateAction action) override
 
virtual KisOptimizedBrushOutline getOutlinePath (const QPointF &documentPos, const KoPointerEvent *event, KisPaintOpSettings::OutlineMode outlineMode)
 
bool isEraser () const
 
bool isOutlineEnabled () const
 
bool isOutlineVisible () const
 
void paint (QPainter &gc, const KoViewConverter &converter) override
 
virtual QString quickHelp () const
 
virtual void requestUpdateOutline (const QPointF &outlineDocPoint, const KoPointerEvent *event)
 
void setMode (ToolMode mode) override
 
void setOutlineEnabled (bool enabled)
 
void setOutlineVisible (bool visible)
 
void setSupportOutline (bool supportOutline)
 
void showControl (QWidget *control, bool value)
 
- Protected Member Functions inherited from KisTool
bool blockUntilOperationsFinished ()
 
void blockUntilOperationsFinishedForced ()
 
QPointF convertDocumentToWidget (const QPointF &pt)
 
QPoint convertToImagePixelCoordFloored (KoPointerEvent *e)
 
QPointF convertToPixelCoord (const QPointF &pt)
 
QPointF convertToPixelCoord (KoPointerEvent *e)
 
QPointF convertToPixelCoordAndAlignOnWidget (const QPointF &pt)
 
QPointF convertToPixelCoordAndSnap (const QPointF &pt, const QPointF &offset=QPointF())
 
QPointF convertToPixelCoordAndSnap (KoPointerEvent *e, const QPointF &offset=QPointF(), bool useModifiers=true)
 
QRectF convertToPt (const QRectF &rect)
 
qreal convertToPt (qreal value)
 
KoColor currentBgColor ()
 
KoColor currentFgColor ()
 
KisFilterConfigurationSP currentGenerator ()
 
KoAbstractGradientSP currentGradient ()
 
KisImageWSP currentImage ()
 
KisNodeSP currentNode () const
 
KisPaintOpPresetSP currentPaintOpPreset ()
 
KoPatternSP currentPattern ()
 
QCursor cursor () const
 
KisImageWSP image () const
 
virtual bool listeningToModifiers ()
 
virtual void listenToModifiers (bool listen)
 
virtual ToolMode mode () const
 
bool nodeEditable ()
 Checks checks if the current node is editable.
 
bool overrideCursorIfNotEditable ()
 Override the cursor appropriately if current node is not editable.
 
void paintToolOutline (QPainter *painter, const KisOptimizedBrushOutline &path)
 
KisOptimizedBrushOutline pixelToView (const KisOptimizedBrushOutline &path) const
 
QPainterPath pixelToView (const QPainterPath &pixelPath) const
 Convert a pixel path into a view path.
 
QPointF pixelToView (const QPoint &pixelCoord) const
 
QPointF pixelToView (const QPointF &pixelCoord) const
 Convert a floating point pixel coordinate into a view coordinate.
 
QPolygonF pixelToView (const QPolygonF &pixelPolygon) const
 Convert a pixel polygon into a view path.
 
QRectF pixelToView (const QRectF &pixelRect) const
 Convert a pixel rectangle into a view rectangle.
 
KisNodeList selectedNodes () const
 
bool selectionEditable ()
 Checks checks if the selection is editable, only applies to local selection as global selection is always editable.
 
void setCursor (const QCursor &cursor)
 
void updateCanvasPixelRect (const QRectF &pixelRect)
 Update the canvas for the given rectangle in image pixel coordinates.
 
void updateCanvasViewRect (const QRectF &viewRect)
 Update the canvas for the given rectangle in view coordinates.
 
QPointF viewToPixel (const QPointF &viewCoord) const
 
QPointF widgetCenterInWidgetPixels ()
 
- Protected Member Functions inherited from KoToolBase
virtual QList< QPointer< QWidget > > createOptionWidgets ()
 
int grabSensitivity () const
 Convenience function to get the current grab sensitivity.
 
qreal handleDocRadius () const
 
QRectF handleGrabRect (const QPointF &position) const
 
QRectF handlePaintRect (const QPointF &position) const
 
int handleRadius () const
 Convenience function to get the current handle radius.
 
bool isActivated () const
 
 KoToolBase (KoToolBasePrivate &dd)
 
KoPointerEventlastDeliveredPointerEvent () const
 
void setAbstractResource (KoAbstractCanvasResourceInterfaceSP abstractResource)
 
void setConverter (KoDerivedResourceConverterSP converter)
 
void setIsOpacityPresetMode (bool value)
 
void setMaskSyntheticEvents (bool value)
 
void setTextMode (bool value)
 
QHash< int, KoAbstractCanvasResourceInterfaceSPtoolAbstractResources ()
 
QHash< int, KoDerivedResourceConverterSPtoolConverters ()
 
void useCursor (const QCursor &cursor)
 
- Protected Attributes inherited from KisToolPaint
KisOptimizedBrushOutline m_currentOutline
 
QRectF m_oldColorPreviewUpdateRect
 
QRectF m_oldOutlineRect
 
QPointF m_outlineDocPoint
 
bool m_paintOutline {false}
 
- Protected Attributes inherited from KoToolBase
KoToolBasePrivated_ptr
 
- Properties inherited from KisTool
bool isActive
 

Detailed Description

Definition at line 37 of file kis_tool_gradient.h.

Constructor & Destructor Documentation

◆ KisToolGradient()

KisToolGradient::KisToolGradient ( KoCanvasBase * canvas)

Definition at line 53 of file kis_tool_gradient.cc.

54 : KisToolPaint(canvas, KisCursor::load("tool_gradient_cursor.png", 6, 6))
55{
56 setObjectName("tool_gradient");
57
58 m_startPos = QPointF(0, 0);
59 m_endPos = QPointF(0, 0);
60
61 m_dither = false;
62 m_reverse = false;
66
67 KisCanvas2 *kritaCanvas = dynamic_cast<KisCanvas2*>(canvas);
68
69 connect(kritaCanvas->viewManager()->canvasResourceProvider(), SIGNAL(sigEffectiveCompositeOpChanged()), SLOT(resetCursorStyle()));
70}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
KisViewManager * viewManager() const
static QCursor load(const QString &cursorName, int hotspotX=-1, int hotspotY=-1)
void resetCursorStyle() override
KisGradientPainter::enumGradientShape m_shape
KisGradientPainter::enumGradientRepeat m_repeat
KisToolPaint(KoCanvasBase *canvas, const QCursor &cursor)
KisCanvasResourceProvider * canvasResourceProvider()
KisCanvas2 * canvas

References Private::canvas, KisViewManager::canvasResourceProvider(), connect(), KisGradientPainter::GradientRepeatNone, KisGradientPainter::GradientShapeLinear, m_antiAliasThreshold, m_dither, m_endPos, m_repeat, m_reverse, m_shape, m_startPos, resetCursorStyle(), and KisCanvas2::viewManager().

◆ ~KisToolGradient()

KisToolGradient::~KisToolGradient ( )
override

Definition at line 72 of file kis_tool_gradient.cc.

73{
74}

Member Function Documentation

◆ activate

void KisToolGradient::activate ( const QSet< KoShape * > & shapes)
overrideslot

Definition at line 87 of file kis_tool_gradient.cc.

88{
90 m_configGroup = KSharedConfig::openConfig()->group(toolId());
91}
KConfigGroup m_configGroup
void activate(const QSet< KoShape * > &shapes) override
Q_INVOKABLE QString toolId() const

References KisToolPaint::activate(), m_configGroup, and KoToolBase::toolId().

◆ areaDone

void KisToolGradient::areaDone ( const QRect & rc)
inlineprivateslot

Definition at line 67 of file kis_tool_gradient.h.

67 {
68 currentNode()->setDirty(rc); // Starts computing the projection for the area we've done.
69
70 }
virtual void setDirty()
Definition kis_node.cpp:577
KisNodeSP currentNode() const
Definition kis_tool.cc:370

References KisTool::currentNode(), and KisNode::setDirty().

◆ beginPrimaryAction()

void KisToolGradient::beginPrimaryAction ( KoPointerEvent * event)
overridevirtual

Called by KisToolProxy when a primary action for the tool is started. The event stores the original event that started the stroke. The event is accepted by default. If the tool decides to ignore this particular action (e.g. when the node is not editable), it should call event->ignore(). Then no further continuePrimaryAction() or endPrimaryAction() will be called until the next user action.

Reimplemented from KisTool.

Definition at line 101 of file kis_tool_gradient.cc.

102{
103 if (!nodeEditable()) {
104 event->ignore();
105 return;
106 }
107
109
110 m_startPos = convertToPixelCoordAndSnap(event, QPointF(), false);
112}
void setMode(ToolMode mode) override
bool nodeEditable()
Checks checks if the current node is editable.
Definition kis_tool.cc:651
@ PAINT_MODE
Definition kis_tool.h:300
QPointF convertToPixelCoordAndSnap(KoPointerEvent *e, const QPointF &offset=QPointF(), bool useModifiers=true)
Definition kis_tool.cc:214

References KisTool::convertToPixelCoordAndSnap(), m_endPos, m_startPos, KisTool::nodeEditable(), KisTool::PAINT_MODE, and KisToolPaint::setMode().

◆ continuePrimaryAction()

void KisToolGradient::continuePrimaryAction ( KoPointerEvent * event)
overridevirtual

Called by KisToolProxy when the primary action is in progress of pointer movement. If the tool has ignored the event in beginPrimaryAction(), this method will not be called.

TODO: The gradient tool is still not in strokes, so the end of its action can call processEvent(), which would result in nested event handler calls. Please uncomment this line when the tool is ported to strokes.

Reimplemented from KisTool.

Definition at line 114 of file kis_tool_gradient.cc.

115{
122 //CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
123
124 // First ensure the old guideline is deleted
126
127 QPointF pos = convertToPixelCoordAndSnap(event, QPointF(), false);
128
129 if (event->modifiers() == Qt::ShiftModifier) {
130 m_endPos = straightLine(pos);
131 } else {
132 m_endPos = pos;
133 }
134
136}
QPointF straightLine(QPointF point)
Qt::KeyboardModifiers modifiers() const

References KisTool::convertToPixelCoordAndSnap(), m_endPos, KoPointerEvent::modifiers(), straightLine(), and updateGuideline().

◆ createOptionWidget()

QWidget * KisToolGradient::createOptionWidget ( )
overridevirtual

Reimplement this if your tool actually has an option widget. Sets the option widget to 0 by default.

Reimplemented from KisTool.

Definition at line 240 of file kis_tool_gradient.cc.

241{
242 QWidget *widget = KisToolPaint::createOptionWidget();
243 Q_CHECK_PTR(widget);
244 widget->setObjectName(toolId() + " option widget");
245
246
247 // Make sure to create the connections last after everything is set up. The initialized values
248 // won't be loaded from the configuration file if you add the widget before the connection
249 m_lbShape = new QLabel(i18n("Shape:"), widget);
250 m_cmbShape = new KComboBox(widget);
251 m_cmbShape->setObjectName("shape_combo");
252 m_cmbShape->addItem(i18nc("the gradient will be drawn linearly", "Linear"));
253 m_cmbShape->addItem(i18nc("the gradient will be drawn bilinearly", "Bi-Linear"));
254 m_cmbShape->addItem(i18nc("the gradient will be drawn radially", "Radial"));
255 m_cmbShape->addItem(i18nc("the gradient will be drawn in a square around a centre", "Square"));
256 m_cmbShape->addItem(i18nc("the gradient will be drawn as an asymmetric cone", "Conical"));
257 m_cmbShape->addItem(i18nc("the gradient will be drawn as a symmetric cone", "Conical Symmetric"));
258 m_cmbShape->addItem(i18nc("the gradient will be drawn as a spiral", "Spiral"));
259 m_cmbShape->addItem(i18nc("the gradient will be drawn as a reverse spiral", "Reverse Spiral"));
260 m_cmbShape->addItem(i18nc("the gradient will be drawn in a selection outline", "Shaped"));
262 connect(m_cmbShape, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSetShape(int)));
263
264 m_lbRepeat = new QLabel(i18n("Repeat:"), widget);
265 m_cmbRepeat = new KComboBox(widget);
266 m_cmbRepeat->setObjectName("repeat_combo");
267 m_cmbRepeat->addItem(i18nc("The gradient will not repeat", "None"));
268 m_cmbRepeat->addItem(i18nc("The gradient will repeat forwards", "Forwards"));
269 m_cmbRepeat->addItem(i18nc("The gradient will repeat alternatingly", "Alternating"));
271 connect(m_cmbRepeat, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSetRepeat(int)));
272
273
274 m_lbAntiAliasThreshold = new QLabel(i18n("Anti-alias threshold:"), widget);
276 m_slAntiAliasThreshold->setObjectName("threshold_slider");
278 m_slAntiAliasThreshold->setSingleStep(0.001);
280 connect(m_slAntiAliasThreshold, SIGNAL(valueChanged(qreal)), this, SLOT(slotSetAntiAliasThreshold(qreal)));
281
282 m_ckReverse = new QCheckBox(i18nc("the gradient will be drawn with the color order reversed", "Reverse"), widget);
283 m_ckReverse->setObjectName("reverse_check");
284 connect(m_ckReverse, SIGNAL(toggled(bool)), this, SLOT(slotSetReverse(bool)));
286
287 m_ckDither = new QCheckBox(i18nc("the gradient will be dithered", "Dither"), widget);
288 m_ckDither->setObjectName("dither_check");
289 connect(m_ckDither, SIGNAL(toggled(bool)), this, SLOT(slotSetDither(bool)));
291
292 widget->setFixedHeight(widget->sizeHint().height());
293
294
295 // load configuration settings into widget (updating UI will update internal variables from signals/slots)
296 m_ckDither->setChecked(m_configGroup.readEntry<bool>("dither", false));
297 m_ckReverse->setChecked((bool)m_configGroup.readEntry("reverse", false));
298 m_cmbShape->setCurrentIndex((int)m_configGroup.readEntry("shape", 0));
299 m_cmbRepeat->setCurrentIndex((int)m_configGroup.readEntry("repeat", 0));
300 m_slAntiAliasThreshold->setValue((qreal)m_configGroup.readEntry("antialiasThreshold", 0.0));
301
302 return widget;
303}
This class is a spinbox in which you can click and drag to set the value. A slider like bar is displa...
void setValue(qreal newValue)
void setRange(qreal newMinimum, qreal newMaximum, int newNumberOfDecimals=0, bool computeNewFastSliderStep=true)
Set the minimum and the maximum values of the range.
QLabel * m_lbAntiAliasThreshold
KComboBox * m_cmbRepeat
KisDoubleSliderSpinBox * m_slAntiAliasThreshold
QCheckBox * m_ckDither
QCheckBox * m_ckReverse
void slotSetAntiAliasThreshold(qreal)
KComboBox * m_cmbShape
QWidget * createOptionWidget() override
virtual void addOptionWidgetOption(QWidget *control, QWidget *label=nullptr)
Add a widget and a label to the current option widget layout.

References KisToolPaint::addOptionWidgetOption(), connect(), KisToolPaint::createOptionWidget(), m_ckDither, m_ckReverse, m_cmbRepeat, m_cmbShape, m_configGroup, m_lbAntiAliasThreshold, m_lbRepeat, m_lbShape, m_slAntiAliasThreshold, KisDoubleSliderSpinBox::setRange(), KisDoubleSliderSpinBox::setValue(), slotSetAntiAliasThreshold(), slotSetDither(), slotSetRepeat(), slotSetReverse(), slotSetShape(), and KoToolBase::toolId().

◆ endPrimaryAction()

void KisToolGradient::endPrimaryAction ( KoPointerEvent * event)
overridevirtual

Called by KisToolProxy when the primary action is being finished, that is while mouseRelease or tabletRelease event. If the tool has ignored the event in beginPrimaryAction(), this method will not be called.

Reimplemented from KisTool.

Definition at line 138 of file kis_tool_gradient.cc.

139{
140 Q_UNUSED(event);
143
144 if (!currentNode())
145 return;
146
147 if (m_startPos == m_endPos) {
148 return;
149 }
150
151 KisImageSP image = this->image();
152
153 KisResourcesSnapshotSP resources =
154 new KisResourcesSnapshot(image, currentNode(), this->canvas()->resourceManager());
155
156 if (image && resources->currentNode()->paintDevice()) {
157 // TODO: refactor out local variables when we switch to C++14
158 QPointF startPos = m_startPos;
159 QPointF endPos = m_endPos;
162 bool reverse = m_reverse;
163 double antiAliasThreshold = m_antiAliasThreshold;
164 bool dither = m_dither;
165
166 KUndo2MagicString actionName = kundo2_i18n("Gradient");
167 KisProcessingApplicator applicator(image, resources->currentNode(),
170 actionName);
171
172 applicator.applyCommand(
174 [resources, startPos, endPos,
175 shape, repeat, reverse, antiAliasThreshold, dither] () mutable {
176
177 KisNodeSP node = resources->currentNode();
178 KisPaintDeviceSP device = node->paintDevice();
180 const QRect bounds = device->defaultBounds()->bounds();
181
182 KisGradientPainter painter(device, resources->activeSelection());
183 resources->setupPainter(&painter);
184 painter.setProgress(helper.updater());
185
186 painter.beginTransaction();
187
188 painter.setGradientShape(shape);
189 painter.paintGradient(startPos, endPos,
190 repeat, antiAliasThreshold,
191 reverse, 0, 0,
192 bounds.width(), bounds.height(),
193 dither);
194
195 return painter.endAndTakeTransaction();
196 }));
197 applicator.end();
198 }
199
201}
virtual QRect bounds() const =0
KisDefaultBoundsBaseSP defaultBounds() const
The KisResourcesSnapshot class takes a snapshot of the various resources like colors and settings use...
void setupPainter(KisPainter *painter)
KisSelectionSP activeSelection() const
#define bounds(x, a, b)
#define CHECK_MODE_SANITY_OR_RETURN(_mode)
Definition kis_tool.h:27
KUndo2MagicString kundo2_i18n(const char *text)
virtual KisPaintDeviceSP paintDevice() const =0
The LambdaCommand struct is a shorthand for creation of AggregateCommand commands using C++ lambda fe...
KisImageWSP image() const
Definition kis_tool.cc:332
@ HOVER_MODE
Definition kis_tool.h:299

References KisResourcesSnapshot::activeSelection(), KisProcessingApplicator::applyCommand(), KisPainter::beginTransaction(), KisDefaultBoundsBase::bounds(), bounds, Private::canvas, CHECK_MODE_SANITY_OR_RETURN, KisResourcesSnapshot::currentNode(), KisTool::currentNode(), KisPaintDevice::defaultBounds(), KisProcessingApplicator::end(), KisPainter::endAndTakeTransaction(), KisTool::HOVER_MODE, KisTool::image(), kundo2_i18n(), m_antiAliasThreshold, m_dither, m_endPos, m_repeat, m_reverse, m_shape, m_startPos, KisProcessingApplicator::NONE, KisTool::PAINT_MODE, KisBaseNode::paintDevice(), KisGradientPainter::paintGradient(), KisGradientPainter::setGradientShape(), KisToolPaint::setMode(), KisPainter::setProgress(), KisResourcesSnapshot::setupPainter(), updateGuideline(), and KisProcessingVisitor::ProgressHelper::updater().

◆ paint()

void KisToolGradient::paint ( QPainter & painter,
const KoViewConverter & converter )
overridevirtual

Called by the canvas to paint any decorations that the tool deems needed. The painter has the top left of the canvas as its origin.

Parameters
painterused for painting the shape
converterto convert between internal and view coordinates.

Implements KoToolBase.

Definition at line 93 of file kis_tool_gradient.cc.

94{
96 paintLine(painter);
97 }
98 KisToolPaint::paint(painter, converter);
99}
void paintLine(QPainter &gc)
void paint(QPainter &gc, const KoViewConverter &converter) override
virtual ToolMode mode() const
Definition kis_tool.cc:407

References m_endPos, m_startPos, KisTool::mode(), KisToolPaint::paint(), KisTool::PAINT_MODE, and paintLine().

◆ paintLine()

void KisToolGradient::paintLine ( QPainter & gc)
private

Definition at line 219 of file kis_tool_gradient.cc.

220{
221 QPointF viewStartPos = pixelToView(m_startPos);
222 QPointF viewStartEnd = pixelToView(m_endPos);
223
224 if (canvas()) {
225 QPainterPath path;
226 path.moveTo(viewStartPos);
227 path.lineTo(viewStartEnd);
228 paintToolOutline(&gc, path);
229 }
230}
QPointF pixelToView(const QPoint &pixelCoord) const
Definition kis_tool.cc:269
void paintToolOutline(QPainter *painter, const KisOptimizedBrushOutline &path)
Definition kis_tool.cc:589

References Private::canvas, m_endPos, m_startPos, KisTool::paintToolOutline(), and KisTool::pixelToView().

◆ resetCursorStyle

void KisToolGradient::resetCursorStyle ( )
overrideprotectedslot

Definition at line 76 of file kis_tool_gradient.cc.

77{
78 if (isEraser()) {
79 useCursor(KisCursor::load("tool_gradient_eraser_cursor.png", 6, 6));
80 } else {
82 }
83
85}
bool isEraser() const
void useCursor(const QCursor &cursor)
virtual void resetCursorStyle()
Definition kis_tool.cc:613
bool overrideCursorIfNotEditable()
Override the cursor appropriately if current node is not editable.
Definition kis_tool.cc:618

References KisToolPaint::isEraser(), KisCursor::load(), KisTool::overrideCursorIfNotEditable(), KisTool::resetCursorStyle(), and KoToolBase::useCursor().

◆ slotSetAntiAliasThreshold

void KisToolGradient::slotSetAntiAliasThreshold ( qreal value)
privateslot

Definition at line 329 of file kis_tool_gradient.cc.

330{
332 m_configGroup.writeEntry("antialiasThreshold", value);
333}
float value(const T *src, size_t ch)

References m_antiAliasThreshold, m_configGroup, and value().

◆ slotSetDither

void KisToolGradient::slotSetDither ( bool state)
privateslot

Definition at line 323 of file kis_tool_gradient.cc.

324{
325 m_dither = state;
326 m_configGroup.writeEntry("dither", state);
327}

References m_configGroup, and m_dither.

◆ slotSetRepeat

void KisToolGradient::slotSetRepeat ( int repeat)
privateslot

Definition at line 311 of file kis_tool_gradient.cc.

312{
314 m_configGroup.writeEntry("repeat", repeat);
315}

References m_configGroup, and m_repeat.

◆ slotSetReverse

void KisToolGradient::slotSetReverse ( bool state)
privateslot

Definition at line 317 of file kis_tool_gradient.cc.

318{
319 m_reverse = state;
320 m_configGroup.writeEntry("reverse", state);
321}

References m_configGroup, and m_reverse.

◆ slotSetShape

void KisToolGradient::slotSetShape ( int shape)
privateslot

Definition at line 305 of file kis_tool_gradient.cc.

306{
308 m_configGroup.writeEntry("shape", shape);
309}

References m_configGroup, and m_shape.

◆ straightLine()

QPointF KisToolGradient::straightLine ( QPointF point)
private

Definition at line 203 of file kis_tool_gradient.cc.

204{
205 QPointF comparison = point - m_startPos;
206 QPointF result;
207
208 if (fabs(comparison.x()) > fabs(comparison.y())) {
209 result.setX(point.x());
210 result.setY(m_startPos.y());
211 } else {
212 result.setX(m_startPos.x());
213 result.setY(point.y());
214 }
215
216 return result;
217}

References m_startPos.

◆ updateGuideline()

void KisToolGradient::updateGuideline ( )
private

Definition at line 232 of file kis_tool_gradient.cc.

233{
234 if (canvas()) {
235 QRectF bound(m_startPos, m_endPos);
236 canvas()->updateCanvas(convertToPt(bound.normalized().adjusted(-3, -3, 3, 3)));
237 }
238}
void updateCanvas(const QRectF &rc) override
QRectF convertToPt(const QRectF &rect)
Definition kis_tool.cc:252

References Private::canvas, KisTool::convertToPt(), m_endPos, m_startPos, and KisCanvas2::updateCanvas().

Member Data Documentation

◆ m_antiAliasThreshold

double KisToolGradient::m_antiAliasThreshold {0.0}
private

Definition at line 87 of file kis_tool_gradient.h.

87{0.0};

◆ m_ckDither

QCheckBox* KisToolGradient::m_ckDither {nullptr}
private

Definition at line 91 of file kis_tool_gradient.h.

91{nullptr};

◆ m_ckReverse

QCheckBox* KisToolGradient::m_ckReverse {nullptr}
private

Definition at line 92 of file kis_tool_gradient.h.

92{nullptr};

◆ m_cmbRepeat

KComboBox* KisToolGradient::m_cmbRepeat {nullptr}
private

Definition at line 94 of file kis_tool_gradient.h.

94{nullptr};

◆ m_cmbShape

KComboBox* KisToolGradient::m_cmbShape {nullptr}
private

Definition at line 93 of file kis_tool_gradient.h.

93{nullptr};

◆ m_configGroup

KConfigGroup KisToolGradient::m_configGroup
private

Definition at line 97 of file kis_tool_gradient.h.

◆ m_dither

bool KisToolGradient::m_dither {false}
private

Definition at line 85 of file kis_tool_gradient.h.

85{false};

◆ m_endPos

QPointF KisToolGradient::m_endPos
private

Definition at line 80 of file kis_tool_gradient.h.

◆ m_lbAntiAliasThreshold

QLabel* KisToolGradient::m_lbAntiAliasThreshold {nullptr}
private

Definition at line 95 of file kis_tool_gradient.h.

95{nullptr};

◆ m_lbRepeat

QLabel* KisToolGradient::m_lbRepeat {nullptr}
private

Definition at line 90 of file kis_tool_gradient.h.

90{nullptr};

◆ m_lbShape

QLabel* KisToolGradient::m_lbShape {nullptr}
private

Definition at line 89 of file kis_tool_gradient.h.

89{nullptr};

◆ m_repeat

KisGradientPainter::enumGradientRepeat KisToolGradient::m_repeat
private

Definition at line 83 of file kis_tool_gradient.h.

◆ m_reverse

bool KisToolGradient::m_reverse {false}
private

Definition at line 86 of file kis_tool_gradient.h.

86{false};

◆ m_shape

KisGradientPainter::enumGradientShape KisToolGradient::m_shape
private

Definition at line 82 of file kis_tool_gradient.h.

◆ m_slAntiAliasThreshold

KisDoubleSliderSpinBox* KisToolGradient::m_slAntiAliasThreshold {nullptr}
private

Definition at line 96 of file kis_tool_gradient.h.

96{nullptr};

◆ m_startPos

QPointF KisToolGradient::m_startPos
private

Definition at line 79 of file kis_tool_gradient.h.


The documentation for this class was generated from the following files: