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

#include <KoShapeShadow.h>

+ Inheritance diagram for KoShapeShadow:

Public Member Functions

qreal blur () const
 Returns the shadow blur radius.
 
void blurShadow (QImage &image, int radius, const QColor &shadowColor)
 
QColor color () const
 Returns the shadow color including opacity.
 
bool deref ()
 
void insets (KoInsets &insets) const
 Fills the insets object with the space the shadow takes around a shape.
 
bool isVisible () const
 Returns if shadow is visible.
 
 KoShapeShadow ()
 
 KoShapeShadow (const KoShapeShadow &rhs)
 
QPointF offset () const
 Returns the shadow offset.
 
KoShapeShadowoperator= (const KoShapeShadow &rhs)
 
void paint (KoShape *shape, QPainter &painter)
 
void paintGroupShadow (KoShapeGroup *group, QPainter &painter)
 
void paintShadow (KoShape *shape, QPainter &painter)
 
 Private ()
 
bool ref ()
 
void setBlur (qreal blur)
 
void setColor (const QColor &color)
 
void setOffset (const QPointF &offset)
 
void setVisible (bool visible)
 Sets the shadow visibility.
 
int useCount () const
 Return the usage count.
 
 ~KoShapeShadow ()
 

Public Attributes

qreal blur
 
QColor color
 
QPointF offset
 
QAtomicInt refCount
 
bool visible
 

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

Definition at line 25 of file KoShapeShadow.cpp.

Constructor & Destructor Documentation

◆ KoShapeShadow() [1/2]

KoShapeShadow::KoShapeShadow ( )

Definition at line 177 of file KoShapeShadow.cpp.

178 : d(new Private())
179{
180}
Private *const d

◆ ~KoShapeShadow()

KoShapeShadow::~KoShapeShadow ( )

Definition at line 182 of file KoShapeShadow.cpp.

183{
184 delete d;
185}

References d.

◆ KoShapeShadow() [2/2]

KoShapeShadow::KoShapeShadow ( const KoShapeShadow & rhs)

Definition at line 187 of file KoShapeShadow.cpp.

188 : d(new Private(*rhs.d))
189{
190 d->refCount = 0;
191}

References d.

Member Function Documentation

◆ blur()

qreal KoShapeShadow::blur ( ) const

Returns the shadow blur radius.

◆ blurShadow()

void KoShapeShadow::blurShadow ( QImage & image,
int radius,
const QColor & shadowColor )

◆ color()

QColor KoShapeShadow::color ( ) const

Returns the shadow color including opacity.

◆ deref()

bool KoShapeShadow::deref ( )

Decrements the use-value. Returns true if the new value is non-zero, false otherwise.

Definition at line 321 of file KoShapeShadow.cpp.

322{
323 return d->refCount.deref();
324}

References d.

◆ insets()

void KoShapeShadow::insets ( KoInsets & insets) const

Fills the insets object with the space the shadow takes around a shape.

Definition at line 293 of file KoShapeShadow.cpp.

294{
295 if (!d->visible) {
296 insets.top = 0;
297 insets.bottom = 0;
298 insets.left = 0;
299 insets.right = 0;
300 return;
301 }
302
303 qreal expand = d->blur;
304
305 insets.left = (d->offset.x() < 0.0) ? qAbs(d->offset.x()) : 0.0;
306 insets.top = (d->offset.y() < 0.0) ? qAbs(d->offset.y()) : 0.0;
307 insets.right = (d->offset.x() > 0.0) ? d->offset.x() : 0.0;
308 insets.bottom = (d->offset.y() > 0.0) ? d->offset.y() : 0.0;
309
310 insets.left += expand;
311 insets.top += expand;
312 insets.right += expand;
313 insets.bottom += expand;
314}
void expand(ExpansionStrategy &expansionStrategy, KoUpdater *progressUpdater)
void insets(KoInsets &insets) const
Fills the insets object with the space the shadow takes around a shape.

References d, expand(), and insets().

◆ isVisible()

bool KoShapeShadow::isVisible ( ) const

Returns if shadow is visible.

Definition at line 288 of file KoShapeShadow.cpp.

289{
290 return d->visible;
291}

References d.

◆ offset()

QPointF KoShapeShadow::offset ( ) const

Returns the shadow offset.

◆ operator=()

KoShapeShadow & KoShapeShadow::operator= ( const KoShapeShadow & rhs)

Definition at line 193 of file KoShapeShadow.cpp.

194{
195 *d = *rhs.d;
196 d->refCount = 0;
197 return *this;
198}

References d.

◆ paint()

void KoShapeShadow::paint ( KoShape * shape,
QPainter & painter )

Paints the shadow of the shape.

Parameters
shapethe shape to paint around
painterthe painter to paint shadows to canvas
converterto convert between internal and view coordinates.

Definition at line 200 of file KoShapeShadow.cpp.

201{
202 if (! d->visible)
203 return;
204
205 // So the approach we are taking here is to draw into a buffer image the size of boundingRect
206 // We offset by the shadow offset at the time we draw into the buffer
207 // Then we filter the image and draw it at the position of the bounding rect on canvas
208
209 QTransform documentToView = painter.transform();
210
211 //the boundingRect of the shape or the KoSelection boundingRect of the group
212 QRectF shadowRect = shape->boundingRect();
213 QRectF zoomedClipRegion = documentToView.mapRect(shadowRect);
214
215 // Init the buffer image
216 QImage sourceGraphic(zoomedClipRegion.size().toSize(), QImage::Format_ARGB32_Premultiplied);
217 sourceGraphic.fill(qRgba(0,0,0,0));
218 // Init the buffer painter
219 QPainter imagePainter(&sourceGraphic);
220 imagePainter.setPen(Qt::NoPen);
221 imagePainter.setBrush(Qt::NoBrush);
222 imagePainter.setRenderHint(QPainter::Antialiasing, painter.testRenderHint(QPainter::Antialiasing));
223 // Since our image buffer and the canvas don't align we need to offset our drawings
224 imagePainter.translate(-1.0f*documentToView.map(shadowRect.topLeft()));
225
226 // Handle the shadow offset
227 imagePainter.translate(documentToView.map(offset()));
228
229 KoShapeGroup *group = dynamic_cast<KoShapeGroup*>(shape);
230 if (group) {
231 d->paintGroupShadow(group, imagePainter);
232 } else {
233 //apply shape's transformation
234 imagePainter.setTransform(shape->absoluteTransformation(), true);
235
236 d->paintShadow(shape, imagePainter);
237 }
238 imagePainter.end();
239
240 // Blur the shadow (well the entire buffer)
241 d->blurShadow(sourceGraphic, qRound(documentToView.m11() * d->blur), d->color);
242
243 // Paint the result
244 painter.save();
245 // The painter is initialized for us with canvas transform 'plus' shape transform
246 // we are only interested in the canvas transform so 'subtract' the shape transform part
247 painter.setTransform(shape->absoluteTransformation().inverted() * painter.transform());
248 painter.drawImage(zoomedClipRegion.topLeft(), sourceGraphic);
249 painter.restore();
250}
virtual QRectF boundingRect() const
Get the bounding box of the shape.
Definition KoShape.cpp:335
QTransform absoluteTransformation() const
Definition KoShape.cpp:382

References KoShape::absoluteTransformation(), KoShape::boundingRect(), d, and offset.

◆ paintGroupShadow()

void KoShapeShadow::paintGroupShadow ( KoShapeGroup * group,
QPainter & painter )

Paints the shadow of the shape group to the buffer image.

Parameters
groupthe shape group to paint around
painterthe painter to paint on the image
converterto convert between internal and view coordinates.

◆ paintShadow()

void KoShapeShadow::paintShadow ( KoShape * shape,
QPainter & painter )

Paints the shadow of the shape to the buffer image.

Parameters
shapethe shape to paint around
painterthe painter to paint on the image

◆ Private()

KoShapeShadow::Private ( )
inline

Definition at line 28 of file KoShapeShadow.cpp.

29 : offset(2, 2), color(Qt::black), blur(8), visible(true), refCount(0) {
30 }
QAtomicInt refCount

◆ ref()

bool KoShapeShadow::ref ( )

Increments the use-value. Returns true if the new value is non-zero, false otherwise.

Definition at line 316 of file KoShapeShadow.cpp.

317{
318 return d->refCount.ref();
319}

References d.

◆ setBlur()

void KoShapeShadow::setBlur ( qreal blur)

Sets the shadow blur radius of the shape

Parameters
blurthe shadow blur radius

Definition at line 272 of file KoShapeShadow.cpp.

273{
274 // force positive blur radius
275 d->blur = qAbs(blur);
276}

References blur, and d.

◆ setColor()

void KoShapeShadow::setColor ( const QColor & color)

Sets the shadow color, including the shadow opacity.

Parameters
colorthe shadow color and opacity

Definition at line 262 of file KoShapeShadow.cpp.

263{
264 d->color = color;
265}

References color, and d.

◆ setOffset()

void KoShapeShadow::setOffset ( const QPointF & offset)

Sets the shadow offset from the topleft corner of the shape

Parameters
offsetthe shadow offset

Definition at line 252 of file KoShapeShadow.cpp.

253{
254 d->offset = offset;
255}

References d, and offset.

◆ setVisible()

void KoShapeShadow::setVisible ( bool visible)

Sets the shadow visibility.

Definition at line 283 of file KoShapeShadow.cpp.

284{
285 d->visible = visible;
286}

References d, and visible.

◆ useCount()

int KoShapeShadow::useCount ( ) const

Return the usage count.

Definition at line 326 of file KoShapeShadow.cpp.

327{
328 return d->refCount;
329}

References d.

Member Data Documentation

◆ blur

qreal KoShapeShadow::blur

Definition at line 33 of file KoShapeShadow.cpp.

◆ color

QColor KoShapeShadow::color

Definition at line 32 of file KoShapeShadow.cpp.

◆ d

Private* const KoShapeShadow::d
private

Definition at line 90 of file KoShapeShadow.h.

◆ offset

QPointF KoShapeShadow::offset

Definition at line 31 of file KoShapeShadow.cpp.

◆ refCount

QAtomicInt KoShapeShadow::refCount

Definition at line 35 of file KoShapeShadow.cpp.

◆ visible

bool KoShapeShadow::visible

Definition at line 34 of file KoShapeShadow.cpp.


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