20#include "vshadowdecorator.h"
21#include <core/vfill.h>
22#include <core/vstroke.h>
23#include <render/vpainter.h>
24#include <core/vvisitor.h>
25#include <core/vdocument.h>
26#include <core/vselection.h>
27#include <commands/vtransformcmd.h>
29VShadowDecorator::VShadowDecorator(
VObject *
object,
VObject* parent,
int distance,
int angle,
float opacity )
30 :
VObject( parent ), m_object( object ), m_distance( distance ), m_angle( angle ), m_opacity( opacity )
34VShadowDecorator::VShadowDecorator(
const VShadowDecorator& other ) :
VObject( other )
36 m_object = other.m_object->
clone();
37 m_opacity = other.m_opacity;
38 m_distance = other.m_distance;
39 m_angle = other.m_angle;
42VShadowDecorator::~VShadowDecorator()
48VShadowDecorator::draw( VPainter* painter,
const KoRect* rect )
const
58 m_object->setState(
state() );
62 int shadowDx = int( m_distance * cos( m_angle / 360. * 6.2832 ) );
63 int shadowDy = int( m_distance * sin( m_angle / 360. * 6.2832 ) );
65 VFill *fill =
new VFill( *m_object->fill() );
66 VStroke *stroke =
new VStroke( *m_object->stroke() );
67 VColor black( TQt::black );
68 black.setOpacity( m_opacity );
69 if( m_object->fill()->type() != VFill::none )
70 m_object->fill()->setColor( black );
71 m_object->stroke()->setColor( black );
72 TQWMatrix mat = painter->worldMatrix();
73 painter->setWorldMatrix( mat.translate( shadowDx * painter->zoomFactor(), -shadowDy * painter->zoomFactor()) );
74 m_object->draw( painter, rect );
75 m_object->setFill( *fill );
76 m_object->setStroke( *stroke );
77 painter->setWorldMatrix( mat.translate( -shadowDx* painter->zoomFactor() , shadowDy * painter->zoomFactor() ) );
79 m_object->draw( painter, rect );
85 return new VShadowDecorator( *
this );
89VShadowDecorator::accept(
VVisitor& visitor )
91 m_object->accept( visitor );
98VShadowDecorator::setShadow(
int distance,
int angle,
float opacity )
100 m_distance = distance;
106VShadowDecorator::setStroke(
const VStroke& stroke )
108 m_object->setStroke( stroke );
112VShadowDecorator::setFill(
const VFill& fill )
114 m_object->setFill( fill );
118VShadowDecorator::setState(
const VState state )
121 m_object->setState( state );
125VShadowDecorator::save( TQDomElement& element )
const
130 int shadowDx = int( m_distance * cos( m_angle / 360. * 6.2832 ) );
131 int shadowDy = int( m_distance * sin( m_angle / 360. * 6.2832 ) );
133 VObject *shadow = m_object->clone();
135 VColor black( TQt::black );
136 black.setOpacity( m_opacity );
137 if( shadow->
fill()->type() != VFill::none )
138 shadow->
fill()->setColor( black );
139 shadow->
stroke()->setColor( black );
141 mat.translate( shadowDx, -shadowDy );
142 VTransformCmd trafo( 0L, mat );
143 trafo.visit( *shadow );
144 shadow->
save( element );
148 m_object->
save( element );
VSelection * selection() const
Returns a pointer to the selection.
Manages the fill of shapes.
The base class for all karbon objects.
VObject(VObject *parent, VState state=edit)
Constructs a new object that is child of parent and has the given state.
virtual VObject * clone() const =0
Create an exact copy of this object.
@ hidden_locked
hidden and locked (r/o)
@ deleted
deleted, nearly dead
@ edit
visible, active and is currently manipulated by a tool
VState m_state
the object's state
virtual VFill * fill() const
Gets the object's actual fill.
virtual VStroke * stroke() const
Gets the object's actual stroke.
virtual void save(TQDomElement &element) const
Save this object's state to xml.
VDocument * document() const
Return document the object belongs to.
VState state() const
Get the state the object is in.
void take(VObject &object)
Removes the reference to the object, not the object itself.
Manages stroke properties.
The abstract visitor class.
virtual void visitVObject(VObject &object)
Visit method for a VObject.