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

A widget for configuring the shadow of a shape. More...

#include <KoShadowConfigWidget.h>

+ Inheritance diagram for KoShadowConfigWidget:

Public Slots

void setCanvas (KoCanvasBase *canvas)
 
void setUnit (const KoUnit &unit)
 
void setUnitManagers (KisSpinBoxUnitManager *managerBlur, KisSpinBoxUnitManager *managerOffset)
 

Public Member Functions

 KoShadowConfigWidget (QWidget *parent)
 
 Private ()
 
void setShadowBlur (const qreal &blur)
 Sets the shadow blur radius.
 
void setShadowColor (const QColor &color)
 Sets the shadow color.
 
void setShadowOffset (const QPointF &offset)
 Sets the shadow offset.
 
void setShadowVisible (bool visible)
 Sets if the shadow is visible.
 
qreal shadowBlur () const
 Returns the shadow blur radius.
 
QColor shadowColor () const
 Returns the shadow color.
 
QPointF shadowOffset () const
 Returns the shadow offset.
 
bool shadowVisible () const
 Returns if shadow is visible.
 
 ~KoShadowConfigWidget () override
 

Public Attributes

KoColorPopupActionactionShadowColor {nullptr}
 
KoCanvasBasecanvas {nullptr}
 
Ui_KoShadowConfigWidget widget
 

Private Slots

void applyChanges ()
 
void resourceChanged (int key, const QVariant &res)
 
void selectionChanged ()
 
void visibilityChanged ()
 

Private Attributes

Private *const d
 
- Private Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Additional Inherited Members

- Private Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Detailed Description

A widget for configuring the shadow of a shape.

Definition at line 27 of file KoShadowConfigWidget.cpp.

Constructor & Destructor Documentation

◆ KoShadowConfigWidget()

KoShadowConfigWidget::KoShadowConfigWidget ( QWidget * parent)
explicit

Definition at line 38 of file KoShadowConfigWidget.cpp.

39 : QWidget(parent)
40 , d(new Private())
41{
42 d->widget.setupUi(this);
43 d->widget.shadowOffset->setValue(8.0);
44 d->widget.shadowBlur->setValue(8.0);
45 d->widget.shadowBlur->setMinimum(0.0);
46 d->widget.shadowAngle->setValue(315.0);
47 d->widget.shadowAngle->setMinimum(0.0);
48 d->widget.shadowAngle->setMaximum(360.0);
49 d->widget.shadowVisible->setChecked(false);
51
52 d->actionShadowColor = new KoColorPopupAction(this);
53 d->actionShadowColor->setCurrentColor(QColor(0, 0, 0, 192)); // some reasonable default for shadow
54 d->actionShadowColor->setIcon(koIcon("format-stroke-color"));
55 d->actionShadowColor->setToolTip(i18n("Change the color of the shadow"));
56 d->widget.shadowColor->setDefaultAction(d->actionShadowColor);
57
58 connect(d->widget.shadowVisible, SIGNAL(toggled(bool)), this, SLOT(applyChanges()));
59 connect(d->widget.shadowVisible, SIGNAL(toggled(bool)), this, SLOT(visibilityChanged()));
60 connect(d->actionShadowColor, SIGNAL(colorChanged(KoColor)), this, SLOT(applyChanges()));
61 connect(d->widget.shadowAngle, SIGNAL(valueChanged(int)), this, SLOT(applyChanges()));
62 connect(d->widget.shadowOffset, SIGNAL(valueChangedPt(qreal)), this, SLOT(applyChanges()));
63 connect(d->widget.shadowBlur, SIGNAL(valueChangedPt(qreal)), this, SLOT(applyChanges()));
64}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
#define koIcon(name)
Use these macros for icons without any issues.
Definition kis_icon.h:25

References applyChanges(), connect(), d, koIcon, and visibilityChanged().

◆ ~KoShadowConfigWidget()

KoShadowConfigWidget::~KoShadowConfigWidget ( )
override

Definition at line 66 of file KoShadowConfigWidget.cpp.

67{
68 delete d;
69}

References d.

Member Function Documentation

◆ applyChanges

void KoShadowConfigWidget::applyChanges ( )
privateslot

Definition at line 145 of file KoShadowConfigWidget.cpp.

146{
147 if (d->canvas) {
149 KoShape * shape = selection->firstSelectedShape();
150 if (! shape) {
151 return;
152 }
153
154 KoShapeShadow *newShadow = new KoShapeShadow();
155 newShadow->setVisible(shadowVisible());
156 newShadow->setColor(shadowColor());
157 newShadow->setOffset(shadowOffset());
158 newShadow->setBlur(shadowBlur());
159 d->canvas->addCommand(new KoShapeShadowCommand(selection->selectedShapes(), newShadow));
160 }
161}
KisSelectedShapesProxy selectedShapesProxy
void addCommand(KUndo2Command *command) override
KoSelection * selection() override
KoShape * firstSelectedShape() const
const QList< KoShape * > selectedShapes() const
QPointF shadowOffset() const
Returns the shadow offset.
QColor shadowColor() const
Returns the shadow color.
qreal shadowBlur() const
Returns the shadow blur radius.
bool shadowVisible() const
Returns if shadow is visible.
The undo / redo command for setting the shape shadow.
void setOffset(const QPointF &offset)
void setBlur(qreal blur)
void setColor(const QColor &color)
void setVisible(bool visible)
Sets the shadow visibility.
KisCanvas2 * canvas

References KisCanvas2::addCommand(), Private::canvas, d, KoSelection::firstSelectedShape(), KoSelection::selectedShapes(), KisCanvas2::selectedShapesProxy, KisSelectedShapesProxy::selection(), KoShapeShadow::setBlur(), KoShapeShadow::setColor(), KoShapeShadow::setOffset(), KoShapeShadow::setVisible(), shadowBlur(), shadowColor(), shadowOffset(), and shadowVisible().

◆ Private()

KoShadowConfigWidget::Private ( )
inline

Definition at line 30 of file KoShadowConfigWidget.cpp.

31 {
32 }

◆ resourceChanged

void KoShadowConfigWidget::resourceChanged ( int key,
const QVariant & res )
privateslot

Definition at line 223 of file KoShadowConfigWidget.cpp.

224{
225 if( key == KoCanvasResource::Unit ) {
226 setUnit(res.value<KoUnit>());
227 }
228}
void setUnit(const KoUnit &unit)
@ Unit
The unit of this canvas.

References setUnit(), and KoCanvasResource::Unit.

◆ selectionChanged

void KoShadowConfigWidget::selectionChanged ( )
privateslot

Definition at line 163 of file KoShadowConfigWidget.cpp.

164{
165 if (! d->canvas) {
166 return;
167 }
168
170 KoShape * shape = selection->firstSelectedShape();
171
172 setEnabled(shape != 0);
173
174 if (! shape) {
175 setShadowVisible(false);
176 return;
177 }
178
179 KoShapeShadow * shadow = shape->shadow();
180 if (! shadow) {
181 setShadowVisible(false);
182 return;
183 }
184
185 setShadowVisible(shadow->isVisible());
186 setShadowOffset(shadow->offset());
187 setShadowColor(shadow->color());
188 setShadowBlur(shadow->blur());
189}
void setShadowVisible(bool visible)
Sets if the shadow is visible.
void setShadowOffset(const QPointF &offset)
Sets the shadow offset.
void setShadowBlur(const qreal &blur)
Sets the shadow blur radius.
void setShadowColor(const QColor &color)
Sets the shadow color.
bool isVisible() const
Returns if shadow is visible.
KoShapeShadow * shadow() const
Returns the currently set shadow or 0 if there is no shadow set.
Definition KoShape.cpp:1116

References KoShapeShadow::blur, Private::canvas, KoShapeShadow::color, d, KoSelection::firstSelectedShape(), KoShapeShadow::isVisible(), KoShapeShadow::offset, KisCanvas2::selectedShapesProxy, KisSelectedShapesProxy::selection(), setShadowBlur(), setShadowColor(), setShadowOffset(), setShadowVisible(), and KoShape::shadow().

◆ setCanvas

void KoShadowConfigWidget::setCanvas ( KoCanvasBase * canvas)
slot

Definition at line 191 of file KoShadowConfigWidget.cpp.

192{
193 d->canvas = canvas;
195 connect(canvas->selectedShapesProxy(), SIGNAL(selectionContentChanged()), this, SLOT(selectionChanged()));
196
197 setUnit(canvas->unit());
198
199 connect( d->canvas->resourceManager(), SIGNAL(canvasResourceChanged(int,QVariant)),
200 this, SLOT(resourceChanged(int,QVariant)) );
201}
virtual KoUnit unit() const =0
QPointer< KoCanvasResourceProvider > resourceManager
virtual KoSelectedShapesProxy * selectedShapesProxy() const =0
selectedShapesProxy() is a special interface for keeping a persistent connections to selectionChanged...
void resourceChanged(int key, const QVariant &res)

References Private::canvas, canvas, connect(), d, resourceChanged(), KoCanvasBase::resourceManager, KoCanvasBase::selectedShapesProxy(), selectionChanged(), setUnit(), and KoCanvasBase::unit().

◆ setShadowBlur()

void KoShadowConfigWidget::setShadowBlur ( const qreal & blur)

Sets the shadow blur radius.

Definition at line 112 of file KoShadowConfigWidget.cpp.

113{
114 d->widget.shadowBlur->blockSignals(true);
115 d->widget.shadowBlur->changeValue(blur);
116 d->widget.shadowBlur->blockSignals(false);
117}

References d.

◆ setShadowColor()

void KoShadowConfigWidget::setShadowColor ( const QColor & color)

Sets the shadow color.

Definition at line 71 of file KoShadowConfigWidget.cpp.

72{
73 d->widget.shadowColor->blockSignals(true);
74 d->actionShadowColor->blockSignals(true);
75
76 d->actionShadowColor->setCurrentColor( color );
77
78 d->actionShadowColor->blockSignals(false);
79 d->widget.shadowColor->blockSignals(false);
80}

References d.

◆ setShadowOffset()

void KoShadowConfigWidget::setShadowOffset ( const QPointF & offset)

Sets the shadow offset.

Definition at line 87 of file KoShadowConfigWidget.cpp.

88{
89 qreal length = sqrt(offset.x()*offset.x() + offset.y()*offset.y());
90 qreal angle = atan2(-offset.y(), offset.x());
91 if (angle < 0.0) {
92 angle += 2*M_PI;
93 }
94
95 d->widget.shadowAngle->blockSignals(true);
96 d->widget.shadowAngle->setValue(-90 - angle * 180.0 / M_PI);
97 d->widget.shadowAngle->blockSignals(false);
98
99 d->widget.shadowOffset->blockSignals(true);
100 d->widget.shadowOffset->changeValue(length);
101 d->widget.shadowOffset->blockSignals(false);
102}
qreal length(const QPointF &vec)
Definition Ellipse.cc:82
#define M_PI
Definition kis_global.h:111
KRITAIMAGE_EXPORT qreal atan2(qreal y, qreal x)
atan2 replacement

References d, length(), and M_PI.

◆ setShadowVisible()

void KoShadowConfigWidget::setShadowVisible ( bool visible)

Sets if the shadow is visible.

Definition at line 124 of file KoShadowConfigWidget.cpp.

125{
126 d->widget.shadowVisible->blockSignals(true);
127 d->widget.shadowVisible->setChecked(visible);
128 d->widget.shadowVisible->blockSignals(false);
130}

References d, and visibilityChanged().

◆ setUnit

void KoShadowConfigWidget::setUnit ( const KoUnit & unit)
slot

Definition at line 213 of file KoShadowConfigWidget.cpp.

214{
215 d->widget.shadowOffset->blockSignals(true);
216 d->widget.shadowBlur->blockSignals(true);
217 d->widget.shadowOffset->setUnit(unit);
218 d->widget.shadowBlur->setUnit(unit);
219 d->widget.shadowOffset->blockSignals(false);
220 d->widget.shadowBlur->blockSignals(false);
221}

References d.

◆ setUnitManagers

void KoShadowConfigWidget::setUnitManagers ( KisSpinBoxUnitManager * managerBlur,
KisSpinBoxUnitManager * managerOffset )
slot

Definition at line 203 of file KoShadowConfigWidget.cpp.

204{
205 d->widget.shadowOffset->blockSignals(true);
206 d->widget.shadowBlur->blockSignals(true);
207 d->widget.shadowOffset->setUnitManager(managerOffset);
208 d->widget.shadowBlur->setUnitManager(managerBlur);
209 d->widget.shadowOffset->blockSignals(false);
210 d->widget.shadowBlur->blockSignals(false);
211}

References d.

◆ shadowBlur()

qreal KoShadowConfigWidget::shadowBlur ( ) const

Returns the shadow blur radius.

Definition at line 119 of file KoShadowConfigWidget.cpp.

120{
121 return d->widget.shadowBlur->value();
122}

References d.

◆ shadowColor()

QColor KoShadowConfigWidget::shadowColor ( ) const

Returns the shadow color.

Definition at line 82 of file KoShadowConfigWidget.cpp.

83{
84 return d->actionShadowColor->currentColor();
85}

References d.

◆ shadowOffset()

QPointF KoShadowConfigWidget::shadowOffset ( ) const

Returns the shadow offset.

Definition at line 104 of file KoShadowConfigWidget.cpp.

105{
106 QPointF offset(d->widget.shadowOffset->value(), 0);
107 QTransform m;
108 m.rotate(d->widget.shadowAngle->value() + 90);
109 return m.map(offset);
110}

References d.

◆ shadowVisible()

bool KoShadowConfigWidget::shadowVisible ( ) const

Returns if shadow is visible.

Definition at line 132 of file KoShadowConfigWidget.cpp.

133{
134 return d->widget.shadowVisible->isChecked();
135}

References d.

◆ visibilityChanged

void KoShadowConfigWidget::visibilityChanged ( )
privateslot

Definition at line 137 of file KoShadowConfigWidget.cpp.

138{
139 d->widget.shadowAngle->setEnabled( d->widget.shadowVisible->isChecked() );
140 d->widget.shadowBlur->setEnabled( d->widget.shadowVisible->isChecked() );
141 d->widget.shadowColor->setEnabled( d->widget.shadowVisible->isChecked() );
142 d->widget.shadowOffset->setEnabled( d->widget.shadowVisible->isChecked() );
143}

References d.

Member Data Documentation

◆ actionShadowColor

KoColorPopupAction* KoShadowConfigWidget::actionShadowColor {nullptr}

Definition at line 34 of file KoShadowConfigWidget.cpp.

34{nullptr};

◆ canvas

KoCanvasBase* KoShadowConfigWidget::canvas {nullptr}

Definition at line 35 of file KoShadowConfigWidget.cpp.

35{nullptr};

◆ d

Private* const KoShadowConfigWidget::d
private

Definition at line 64 of file KoShadowConfigWidget.h.

◆ widget

Ui_KoShadowConfigWidget KoShadowConfigWidget::widget

Definition at line 33 of file KoShadowConfigWidget.cpp.


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