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
 
KisPopupWidgetInterface * popupWidget () 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
 
KoCanvasBase * canvas () 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.
 
KoToolFactoryBase * factory () 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 KoToolSelection * selection ()
 
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 (int)
 
void slotSetDitherSteps (int)
 
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_ckReverse {nullptr}
 
KComboBox * m_cmbDither {nullptr}
 
KComboBox * m_cmbRepeat {nullptr}
 
KComboBox * m_cmbShape {nullptr}
 
KConfigGroup m_configGroup
 
KisGradientPainter::enumDither m_dither {KisGradientPainter::DitherNone}
 
int m_ditherSteps {KisGradientPainter::defaultDitherSteps}
 
QPointF m_endPos
 
QLabel * m_lbAntiAliasThreshold {nullptr}
 
QLabel * m_lbDither {nullptr}
 
QLabel * m_lbDitherSteps {nullptr}
 
QLabel * m_lbRepeat {nullptr}
 
QLabel * m_lbShape {nullptr}
 
KisGradientPainter::enumGradientRepeat m_repeat
 
bool m_reverse {false}
 
KisIntParseSpinBox * m_sbDitherSteps {nullptr}
 
KisGradientPainter::enumGradientShape m_shape
 
KisDoubleSliderSpinBox * m_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
KisCanvas2 * canvas
 
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)
 
KoPointerEvent * lastDeliveredPointerEvent () const
 
void setAbstractResource (KoAbstractCanvasResourceInterfaceSP abstractResource)
 
void setConverter (KoDerivedResourceConverterSP converter)
 
void setIsOpacityPresetMode (bool value)
 
void setMaskSyntheticEvents (bool value)
 
void setTextMode (bool value)
 
QHash< int, KoAbstractCanvasResourceInterfaceSP > toolAbstractResources ()
 
QHash< int, KoDerivedResourceConverterSP > toolConverters ()
 
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
KoToolBasePrivate * d_ptr
 
- Properties inherited from KisTool
bool isActive
 

Detailed Description

Definition at line 38 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::loadWithSize("tool_gradient_cursor.svg", 32, 32, 6, 6))
55{
56 setObjectName("tool_gradient");
57
58 m_startPos = QPointF(0, 0);
59 m_endPos = QPointF(0, 0);
60
63 m_reverse = false;
67
68 KisCanvas2 *kritaCanvas = dynamic_cast<KisCanvas2*>(canvas);
69
70 connect(kritaCanvas->viewManager()->canvasResourceProvider(), SIGNAL(sigEffectiveCompositeOpChanged()), SLOT(resetCursorStyle()));
71}
KisViewManager * viewManager() const
static QCursor loadWithSize(const QString &cursorName, int width, int height, int hotspotX=-1, int hotspotY=-1)
void resetCursorStyle() override
KisGradientPainter::enumDither m_dither
KisGradientPainter::enumGradientShape m_shape
KisGradientPainter::enumGradientRepeat m_repeat
KisToolPaint(KoCanvasBase *canvas, const QCursor &cursor)
KisCanvasResourceProvider * canvasResourceProvider()
static constexpr int defaultDitherSteps
KisCanvas2 * canvas

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

◆ ~KisToolGradient()

KisToolGradient::~KisToolGradient ( )
override

Definition at line 73 of file kis_tool_gradient.cc.

74{
75}

Member Function Documentation

◆ activate

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

Definition at line 88 of file kis_tool_gradient.cc.

89{
91 m_configGroup = KSharedConfig::openConfig()->group(toolId());
92}
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 69 of file kis_tool_gradient.h.

69 {
70 currentNode()->setDirty(rc); // Starts computing the projection for the area we've done.
71
72 }
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 102 of file kis_tool_gradient.cc.

103{
104 if (!nodeEditable()) {
105 event->ignore();
106 return;
107 }
108
110
111 m_startPos = convertToPixelCoordAndSnap(event, QPointF(), false);
113}
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 115 of file kis_tool_gradient.cc.

116{
123 //CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
124
125 // First ensure the old guideline is deleted
127
128 QPointF pos = convertToPixelCoordAndSnap(event, QPointF(), false);
129
130 if (event->modifiers() == Qt::ShiftModifier) {
131 m_endPos = straightLine(pos);
132 } else {
133 m_endPos = pos;
134 }
135
137}
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 234 of file kis_tool_gradient.cc.

235{
236 QWidget *widget = KisToolPaint::createOptionWidget();
237 Q_CHECK_PTR(widget);
238 widget->setObjectName(toolId() + " option widget");
239
240
241 // Make sure to create the connections last after everything is set up. The initialized values
242 // won't be loaded from the configuration file if you add the widget before the connection
243 m_lbShape = new QLabel(i18n("Shape:"), widget);
244 m_cmbShape = new KComboBox(widget);
245 m_cmbShape->setObjectName("shape_combo");
246 m_cmbShape->addItem(i18nc("the gradient will be drawn linearly", "Linear"));
247 m_cmbShape->addItem(i18nc("the gradient will be drawn bilinearly", "Bi-Linear"));
248 m_cmbShape->addItem(i18nc("the gradient will be drawn radially", "Radial"));
249 m_cmbShape->addItem(i18nc("the gradient will be drawn in a square around a centre", "Square"));
250 m_cmbShape->addItem(i18nc("the gradient will be drawn as an asymmetric cone", "Conical"));
251 m_cmbShape->addItem(i18nc("the gradient will be drawn as a symmetric cone", "Conical Symmetric"));
252 m_cmbShape->addItem(i18nc("the gradient will be drawn as a spiral", "Spiral"));
253 m_cmbShape->addItem(i18nc("the gradient will be drawn as a reverse spiral", "Reverse Spiral"));
254 m_cmbShape->addItem(i18nc("the gradient will be drawn in a selection outline", "Shaped"));
256 connect(m_cmbShape, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSetShape(int)));
257
258 m_lbRepeat = new QLabel(i18n("Repeat:"), widget);
259 m_cmbRepeat = new KComboBox(widget);
260 m_cmbRepeat->setObjectName("repeat_combo");
261 m_cmbRepeat->addItem(i18nc("The gradient will not repeat", "None"));
262 m_cmbRepeat->addItem(i18nc("The gradient will repeat forwards", "Forwards"));
263 m_cmbRepeat->addItem(i18nc("The gradient will repeat alternatingly", "Alternating"));
265 connect(m_cmbRepeat, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSetRepeat(int)));
266
267 m_lbDither = new QLabel(i18n("Dither:"), widget);
268 m_cmbDither = new KComboBox(widget);
269 m_cmbDither->setObjectName("dither");
270 m_cmbDither->addItem(i18nc("The gradient will not be dithered", "None"));
271 m_cmbDither->addItem(i18nc("The gradient will be dithered with Blue Noise", "Blue Noise"));
272 m_cmbDither->addItem(i18nc("The gradient will be dithered with Bayer Matrix 2x2", "Bayer Matrix 2x2"));
273 m_cmbDither->addItem(i18nc("The gradient will be dithered with Bayer Matrix 4x4", "Bayer Matrix 4x4"));
274 m_cmbDither->addItem(i18nc("The gradient will be dithered with Bayer Matrix 8x8", "Bayer Matrix 8x8"));
276 connect(m_cmbDither, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSetDither(int)));
277
278 m_lbDitherSteps = new QLabel(i18n("Dither steps:"), widget);
280 m_sbDitherSteps->setObjectName("dither_steps");
281 m_sbDitherSteps->setRange(2, 10000);
283 connect(m_sbDitherSteps, SIGNAL(valueChanged(int)), this, SLOT(slotSetDitherSteps(int)));
284
285 m_lbAntiAliasThreshold = new QLabel(i18n("Anti-alias threshold:"), widget);
287 m_slAntiAliasThreshold->setObjectName("threshold_slider");
289 m_slAntiAliasThreshold->setSingleStep(0.001);
291 connect(m_slAntiAliasThreshold, SIGNAL(valueChanged(qreal)), this, SLOT(slotSetAntiAliasThreshold(qreal)));
292
293 m_ckReverse = new QCheckBox(i18nc("the gradient will be drawn with the color order reversed", "Reverse"), widget);
294 m_ckReverse->setObjectName("reverse_check");
295 connect(m_ckReverse, SIGNAL(toggled(bool)), this, SLOT(slotSetReverse(bool)));
297
298
299 // load configuration settings into widget (updating UI will update internal variables from signals/slots)
300 slotSetDither((int)m_configGroup.readEntry("dither", 0));
302 m_ckReverse->setChecked((bool)m_configGroup.readEntry("reverse", false));
303 m_cmbShape->setCurrentIndex((int)m_configGroup.readEntry("shape", 0));
304 m_cmbRepeat->setCurrentIndex((int)m_configGroup.readEntry("repeat", 0));
305 m_slAntiAliasThreshold->setValue((qreal)m_configGroup.readEntry("antialiasThreshold", 0.0));
306
307 return widget;
308}
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.
The KisIntParseSpinBox class is a cleverer SpinBox, able to parse arithmetic expressions.
void setValue(int value, bool overwriteExpression=false)
Set the value of the spinbox.
QLabel * m_lbAntiAliasThreshold
KComboBox * m_cmbRepeat
KComboBox * m_cmbDither
KisDoubleSliderSpinBox * m_slAntiAliasThreshold
QCheckBox * m_ckReverse
void slotSetAntiAliasThreshold(qreal)
KComboBox * m_cmbShape
KisIntParseSpinBox * m_sbDitherSteps
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(), KisToolPaint::createOptionWidget(), KisGradientPainter::defaultDitherSteps, m_ckReverse, m_cmbDither, m_cmbRepeat, m_cmbShape, m_configGroup, m_lbAntiAliasThreshold, m_lbDither, m_lbDitherSteps, m_lbRepeat, m_lbShape, m_sbDitherSteps, m_slAntiAliasThreshold, KisDoubleSliderSpinBox::setRange(), KisIntParseSpinBox::setValue(), KisDoubleSliderSpinBox::setValue(), slotSetAntiAliasThreshold(), slotSetDither(), slotSetDitherSteps(), 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 139 of file kis_tool_gradient.cc.

140{
141 Q_UNUSED(event);
144
145 if (!currentNode())
146 return;
147
148 if (m_startPos == m_endPos) {
149 return;
150 }
151
152 KisImageSP image = this->image();
153
154 KisResourcesSnapshotSP resources =
155 new KisResourcesSnapshot(image, currentNode(), this->canvas()->resourceManager());
156
157 if (image && resources->currentNode()->paintDevice()) {
158 KUndo2MagicString actionName = kundo2_i18n("Gradient");
159 KisProcessingApplicator applicator(image, resources->currentNode(),
162 actionName);
163
164 applicator.applyCommand(
166 [resources, startPos = m_startPos, endPos = m_endPos,
167 shape = m_shape, repeat = m_repeat, reverse = m_reverse,
168 antiAliasThreshold = m_antiAliasThreshold, dither = m_dither,
169 ditherSteps = m_ditherSteps] () mutable {
170
171 KisNodeSP node = resources->currentNode();
172 KisPaintDeviceSP device = node->paintDevice();
174 const QRect bounds = device->defaultBounds()->bounds();
175
176 KisGradientPainter painter(device, resources->activeSelection());
177 resources->setupPainter(&painter);
178 painter.setProgress(helper.updater());
179
180 painter.beginTransaction();
181
182 painter.setGradientShape(shape);
183 painter.paintGradient(startPos, endPos,
184 repeat, antiAliasThreshold,
185 reverse, 0, 0,
186 bounds.width(), bounds.height(),
187 dither, ditherSteps);
188
189 return painter.endAndTakeTransaction();
190 }));
191 applicator.end();
192 }
193
195}
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_ditherSteps, 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 94 of file kis_tool_gradient.cc.

95{
97 paintLine(painter);
98 }
99 KisToolPaint::paint(painter, converter);
100}
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 213 of file kis_tool_gradient.cc.

214{
215 QPointF viewStartPos = pixelToView(m_startPos);
216 QPointF viewStartEnd = pixelToView(m_endPos);
217
218 if (canvas()) {
219 QPainterPath path;
220 path.moveTo(viewStartPos);
221 path.lineTo(viewStartEnd);
222 paintToolOutline(&gc, path);
223 }
224}
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 77 of file kis_tool_gradient.cc.

78{
79 if (isEraser()) {
80 useCursor(KisCursor::loadWithSize("tool_gradient_eraser_cursor.svg", 32, 32, 6, 6));
81 } else {
83 }
84
86}
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::loadWithSize(), KisTool::overrideCursorIfNotEditable(), KisTool::resetCursorStyle(), and KoToolBase::useCursor().

◆ slotSetAntiAliasThreshold

void KisToolGradient::slotSetAntiAliasThreshold ( qreal value)
privateslot

Definition at line 346 of file kis_tool_gradient.cc.

347{
349 m_configGroup.writeEntry("antialiasThreshold", value);
350}
float value(const T *src, size_t ch)

References m_antiAliasThreshold, m_configGroup, and value().

◆ slotSetDither

void KisToolGradient::slotSetDither ( int dither)
privateslot

Definition at line 328 of file kis_tool_gradient.cc.

329{
330 if (m_cmbDither->currentIndex() != dither) {
331 m_cmbDither->setCurrentIndex(dither);
332 }
333
334 m_dither = static_cast<KisGradientPainter::enumDither>(dither);
335 m_configGroup.writeEntry("dither", dither);
336
338}
void showControl(QWidget *control, bool value)
static bool isBayerDither(enumDither dither)

References KisGradientPainter::isBayerDither(), m_cmbDither, m_configGroup, m_dither, m_sbDitherSteps, and KisToolPaint::showControl().

◆ slotSetDitherSteps

void KisToolGradient::slotSetDitherSteps ( int value)
privateslot

Definition at line 340 of file kis_tool_gradient.cc.

341{
343 m_configGroup.writeEntry("ditherSteps", value);
344}

References m_configGroup, m_ditherSteps, and value().

◆ slotSetRepeat

void KisToolGradient::slotSetRepeat ( int repeat)
privateslot

Definition at line 316 of file kis_tool_gradient.cc.

317{
319 m_configGroup.writeEntry("repeat", repeat);
320}

References m_configGroup, and m_repeat.

◆ slotSetReverse

void KisToolGradient::slotSetReverse ( bool state)
privateslot

Definition at line 322 of file kis_tool_gradient.cc.

323{
324 m_reverse = state;
325 m_configGroup.writeEntry("reverse", state);
326}

References m_configGroup, and m_reverse.

◆ slotSetShape

void KisToolGradient::slotSetShape ( int shape)
privateslot

Definition at line 310 of file kis_tool_gradient.cc.

311{
313 m_configGroup.writeEntry("shape", shape);
314}

References m_configGroup, and m_shape.

◆ straightLine()

QPointF KisToolGradient::straightLine ( QPointF point)
private

Definition at line 197 of file kis_tool_gradient.cc.

198{
199 QPointF comparison = point - m_startPos;
200 QPointF result;
201
202 if (fabs(comparison.x()) > fabs(comparison.y())) {
203 result.setX(point.x());
204 result.setY(m_startPos.y());
205 } else {
206 result.setX(m_startPos.x());
207 result.setY(point.y());
208 }
209
210 return result;
211}

References m_startPos.

◆ updateGuideline()

void KisToolGradient::updateGuideline ( )
private

Definition at line 226 of file kis_tool_gradient.cc.

227{
228 if (canvas()) {
229 QRectF bound(m_startPos, m_endPos);
230 canvas()->updateCanvas(convertToPt(bound.normalized().adjusted(-3, -3, 3, 3)));
231 }
232}
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 90 of file kis_tool_gradient.h.

90{0.0};

◆ m_ckReverse

QCheckBox* KisToolGradient::m_ckReverse {nullptr}
private

Definition at line 98 of file kis_tool_gradient.h.

98{nullptr};

◆ m_cmbDither

KComboBox* KisToolGradient::m_cmbDither {nullptr}
private

Definition at line 95 of file kis_tool_gradient.h.

95{nullptr};

◆ m_cmbRepeat

KComboBox* KisToolGradient::m_cmbRepeat {nullptr}
private

Definition at line 100 of file kis_tool_gradient.h.

100{nullptr};

◆ m_cmbShape

KComboBox* KisToolGradient::m_cmbShape {nullptr}
private

Definition at line 99 of file kis_tool_gradient.h.

99{nullptr};

◆ m_configGroup

KConfigGroup KisToolGradient::m_configGroup
private

Definition at line 103 of file kis_tool_gradient.h.

◆ m_dither

Definition at line 87 of file kis_tool_gradient.h.

◆ m_ditherSteps

int KisToolGradient::m_ditherSteps {KisGradientPainter::defaultDitherSteps}
private

◆ m_endPos

QPointF KisToolGradient::m_endPos
private

Definition at line 82 of file kis_tool_gradient.h.

◆ m_lbAntiAliasThreshold

QLabel* KisToolGradient::m_lbAntiAliasThreshold {nullptr}
private

Definition at line 101 of file kis_tool_gradient.h.

101{nullptr};

◆ m_lbDither

QLabel* KisToolGradient::m_lbDither {nullptr}
private

Definition at line 94 of file kis_tool_gradient.h.

94{nullptr};

◆ m_lbDitherSteps

QLabel* KisToolGradient::m_lbDitherSteps {nullptr}
private

Definition at line 96 of file kis_tool_gradient.h.

96{nullptr};

◆ m_lbRepeat

QLabel* KisToolGradient::m_lbRepeat {nullptr}
private

Definition at line 93 of file kis_tool_gradient.h.

93{nullptr};

◆ m_lbShape

QLabel* KisToolGradient::m_lbShape {nullptr}
private

Definition at line 92 of file kis_tool_gradient.h.

92{nullptr};

◆ m_repeat

KisGradientPainter::enumGradientRepeat KisToolGradient::m_repeat
private

Definition at line 85 of file kis_tool_gradient.h.

◆ m_reverse

bool KisToolGradient::m_reverse {false}
private

Definition at line 89 of file kis_tool_gradient.h.

89{false};

◆ m_sbDitherSteps

KisIntParseSpinBox* KisToolGradient::m_sbDitherSteps {nullptr}
private

Definition at line 97 of file kis_tool_gradient.h.

97{nullptr};

◆ m_shape

KisGradientPainter::enumGradientShape KisToolGradient::m_shape
private

Definition at line 84 of file kis_tool_gradient.h.

◆ m_slAntiAliasThreshold

KisDoubleSliderSpinBox* KisToolGradient::m_slAntiAliasThreshold {nullptr}
private

Definition at line 102 of file kis_tool_gradient.h.

102{nullptr};

◆ m_startPos

QPointF KisToolGradient::m_startPos
private

Definition at line 81 of file kis_tool_gradient.h.


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