Commit 01521265 authored by Thomas Zander's avatar Thomas Zander

API review for KoShapeShadow

* make 'insets' const.
* make 'insets' not pass in a KoShape; there is no way the insets
  can change based on the shape passed in.
* rename setVisibility -> setVisible so its a match with isVisible
* fix bug in insets() when the shape is invisible the insets are
  set to zero, not left untouched.

svn path=/trunk/koffice/; revision=1072431
parent 5d74215f
......@@ -379,7 +379,7 @@ QRectF KoPathShape::boundingRect() const
}
if (shadow()) {
KoInsets insets;
shadow()->insets(this, insets);
shadow()->insets(insets);
bb.adjust(-insets.left, -insets.top, insets.right, insets.bottom);
}
if (filterEffectStack()) {
......
......@@ -327,14 +327,14 @@ QRectF KoShape::boundingRect() const
bb = transform.mapRect(bb);
if (d->shadow) {
KoInsets insets;
d->shadow->insets(this, insets);
d->shadow->insets(insets);
bb.adjust(-insets.left, -insets.top, insets.right, insets.bottom);
}
if (d->filterEffectStack) {
QRectF clipRect = d->filterEffectStack->clipRectForBoundingRect(QRectF(QPointF(), mySize));
bb |= transform.mapRect(clipRect);
}
return bb;
}
......@@ -1156,7 +1156,7 @@ KoShapeShadow * KoShape::loadOdfShadow(const KoXmlElement & element, KoShapeLoad
if (! opacity.isEmpty() && opacity.right(1) == "%")
shadowColor.setAlphaF(opacity.left(opacity.length() - 1).toFloat() / 100.0);
shadow->setColor(shadowColor);
shadow->setVisibility(shadowStyle == "visible");
shadow->setVisible(shadowStyle == "visible");
return shadow;
}
......
/* This file is part of the KDE project
* Copyright (C) 2008-2009 Jan Hambrecht <jaham@gmx.net>
* Copyright (C) 2010 Thomas Zander <zander@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -128,7 +129,7 @@ QColor KoShapeShadow::color() const
return d->color;
}
void KoShapeShadow::setVisibility(bool visible)
void KoShapeShadow::setVisible(bool visible)
{
d->visible = visible;
}
......@@ -138,12 +139,15 @@ bool KoShapeShadow::isVisible() const
return d->visible;
}
void KoShapeShadow::insets(const KoShape *shape, KoInsets &insets)
void KoShapeShadow::insets(KoInsets &insets) const
{
if (! d->visible)
if (!d->visible) {
insets.top = 0;
insets.bottom = 0;
insets.left = 0;
insets.right = 0;
return;
Q_UNUSED(shape);
}
insets.left = (d->offset.x() < 0.0) ? qAbs(d->offset.x()) : 0.0;
insets.top = (d->offset.y() < 0.0) ? qAbs(d->offset.y()) : 0.0;
......
/* This file is part of the KDE project
* Copyright (C) 2008 Jan Hambrecht <jaham@gmx.net>
* Copyright (C) 2010 Thomas Zander <zander@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -72,13 +73,13 @@ public:
QColor color() const;
/// Sets the shadow visibility
void setVisibility(bool visible);
void setVisible(bool visible);
/// Returns if shadow is visible
bool isVisible() const;
/// Returns the insets of the shadow
void insets(const KoShape *shape, KoInsets &insets);
/// Fills the insets oject with the space the shadow takes around a shape
void insets(KoInsets &insets) const;
/**
* Increments the use-value.
......
......@@ -107,7 +107,7 @@ void TestShapeAt::testShadow()
shadow->setOffset(QPointF(5, 9));
shape.setShadow(shadow);
KoInsets shadowInsets;
shadow->insets(&shape, shadowInsets);
shadow->insets(shadowInsets);
bbox.adjust(-shadowInsets.left, -shadowInsets.top, shadowInsets.right, shadowInsets.bottom);
QCOMPARE(shape.boundingRect(), bbox);
}
......
......@@ -261,7 +261,7 @@ void TestShapeGroupCommand::testGroupStrokeShapes()
}
if (strokeGroup->shadow()) {
KoInsets insets;
strokeGroup->shadow()->insets(strokeGroup, insets);
strokeGroup->shadow()->insets(insets);
bound.adjust(-insets.left, -insets.top, insets.right, insets.bottom);
}
......
......@@ -56,7 +56,7 @@ void TestShapeShadowCommand::refCounting()
// if shadow1 is deleted when deleting cmd1 this will crash
KoInsets insets;
shadow1->insets(shape1,insets);
shadow1->insets(insets);
delete cmd2;
delete shape1;
......
......@@ -121,7 +121,7 @@ void ShadowDocker::shadowChanged()
return;
KoShapeShadow * newShadow = new KoShapeShadow();
newShadow->setVisibility( d->widget->shadowVisible() );
newShadow->setVisible(d->widget->shadowVisible());
newShadow->setColor( d->widget->shadowColor() );
newShadow->setOffset( d->widget->shadowOffset() );
d->canvas->addCommand( new KoShapeShadowCommand( selection->selectedShapes(), newShadow ) );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment