20#include "shadoweffectplugin.h"
22#include <karbon_view.h>
23#include <karbon_part.h>
24#include <kgenericfactory.h>
26#include <tqgroupbox.h>
30#include <core/vgroup.h>
31#include <core/vpath.h>
32#include <core/vsegment.h>
33#include <core/vselection.h>
34#include <core/vdocument.h>
35#include "vshadowdecorator.h"
37typedef KGenericFactory<ShadowEffectPlugin, KarbonView> ShadowEffectPluginFactory;
38K_EXPORT_COMPONENT_FACTORY( karbon_shadoweffectplugin, ShadowEffectPluginFactory(
"karbonshadoweffectplugin" ) )
40ShadowEffectPlugin::ShadowEffectPlugin( KarbonView *parent, const
char* name, const TQStringList & )
41: Plugin( parent, name )
44 i18n(
"&Shadow Effect..." ),
"shadowRB", 0,
this,
45 TQ_SLOT( slotShadowEffect() ), actionCollection(),
"object_shadow" );
47 m_shadowEffectDlg =
new VShadowEffectDlg();
48 m_shadowEffectDlg->setDistance( 2 );
49 m_shadowEffectDlg->setAngle( 0 );
53ShadowEffectPlugin::slotShadowEffect()
55 KarbonPart *part = ((KarbonView *)parent())->part();
56 if( part && m_shadowEffectDlg->exec() )
57 part->
addCommand(
new VCreateShadowCmd( &part->document(), m_shadowEffectDlg->distance(), m_shadowEffectDlg->angle(),
double( m_shadowEffectDlg->opacity() ) / 255.0 ),
true );
60VShadowEffectDlg::VShadowEffectDlg( TQWidget* parent,
const char* name )
61 : KDialogBase( parent, name, true, i18n(
"Create Shadow Effect" ), Ok | Cancel )
64 TQGroupBox* group =
new TQGroupBox( 2, TQt::Horizontal, i18n(
"Properties" ),
this );
65 new TQLabel( i18n(
"Distance:" ), group );
66 m_distance =
new KIntNumInput( group );
67 m_distance->setRange( -1000, 1000, 1,
true );
68 m_distance->setValue( 2 );
69 new TQLabel( i18n(
"Angle:" ), group );
70 m_angle =
new KIntNumInput( group );
71 m_angle->setRange( 0, 360, 10,
true );
72 m_angle->setValue( 0 );
73 new TQLabel( i18n(
"Opacity:" ), group );
74 m_opacity =
new KIntNumInput( group );
75 m_opacity->setRange( 0, 100, 1,
true );
76 m_opacity->setValue( 100 );
77 group->setMinimumWidth( 300 );
78 m_opacity->setSuffix(i18n(
"%"));
81 connect(
this, TQ_SIGNAL( okClicked() ),
this, TQ_SLOT( accept() ) );
82 connect(
this, TQ_SIGNAL( cancelClicked() ),
this, TQ_SLOT( reject() ) );
84 setMainWidget( group );
88VShadowEffectDlg::setDistance(
int d )
90 m_distance->setValue( d );
94VShadowEffectDlg::setAngle(
int a )
96 m_angle->setValue( a );
100VShadowEffectDlg::setOpacity(
int o )
102 m_angle->setValue( o );
106VShadowEffectDlg::distance()
const
108 return m_distance->value();
112VShadowEffectDlg::angle()
const
114 return m_angle->value();
118VShadowEffectDlg::opacity()
const
120 return m_opacity->value();
123VCreateShadowCmd::VCreateShadowCmd(
VDocument* doc,
int distance,
int angle,
float opacity )
124 :
VCommand( doc, i18n(
"Create Shadow" ) ), m_distance( distance ), m_angle( angle ), m_opacity( opacity )
127 m_oldObjects = document()->selection()->clone();
131VCreateShadowCmd::~VCreateShadowCmd()
133 delete( m_oldObjects );
134 delete( m_newObjects );
142 bool successful =
false;
148 m_newObjects =
new VSelection();
153 VObjectListIterator itr( m_oldObjects->objects() );
155 for( ; itr.current(); ++itr )
158 VShadowDecorator *shadow =
dynamic_cast<VShadowDecorator *
>( itr.current() );
162 shadow->setShadow( m_distance, m_angle, m_opacity );
166 newObject =
new VShadowDecorator( itr.current()->clone(), 0L, m_distance, m_angle, m_opacity );
173 itr.current()->parent()->insertInfrontOf(
174 newObject, itr.current() );
177 m_newObjects->append( newObject );
183 if( m_newObjects->objects().count() == 0 )
186 VObjectListIterator itr( m_oldObjects->objects() );
189 for( ; itr.current(); ++itr )
196 for( itr = m_newObjects->objects(); itr.current(); ++itr )
212 if( m_newObjects->objects().count() == 0 )
216 VObjectListIterator itr( m_oldObjects->objects() );
219 for( ; itr.current(); ++itr )
226 for( itr = m_newObjects->objects(); itr.current(); ++itr )
236#include "shadoweffectplugin.moc"
void addCommand(VCommand *cmd, bool repaint=false)
insert a command into the undo/redo-history:
The base class for all karbon commands.
virtual void unexecute()
Unexecutes the command.
VDocument * document() const
Returns the document the command works on.
virtual void execute()=0
Executes the command.
All non-visual, static doc info is in here.
VSelection * selection() const
Returns a pointer to the selection.
@ deleted
deleted, nearly dead
@ normal
visible, not active
void append()
Adds all objects to the selection.
void take(VObject &object)
Removes the reference to the object, not the object itself.
void setSuccess(bool success=true)
Set the success property.