20#include <core/vselection.h>
21#include "whirlpinchplugin.h"
22#include <karbon_view.h>
23#include <karbon_part.h>
24#include <kgenericfactory.h>
25#include <core/vdocument.h>
26#include <core/vcomposite.h>
27#include <core/vpath.h>
28#include <core/vsegment.h>
29#include <core/vglobal.h>
33#include <tqgroupbox.h>
38typedef KGenericFactory<WhirlPinchPlugin, KarbonView> WhirlPinchPluginFactory;
39K_EXPORT_COMPONENT_FACTORY( karbon_whirlpinchplugin, WhirlPinchPluginFactory(
"karbonwhirlpinchplugin" ) )
41WhirlPinchPlugin::WhirlPinchPlugin( KarbonView *parent, const
char* name, const TQStringList & ) : Plugin( parent, name )
44 i18n(
"&Whirl/Pinch..." ),
"14_whirl", 0,
this,
45 TQ_SLOT( slotWhirlPinch() ), actionCollection(),
"path_whirlpinch" );
47 m_whirlPinchDlg =
new VWhirlPinchDlg();
48 m_whirlPinchDlg->setAngle( 20.0 );
49 m_whirlPinchDlg->setPinch( 0.0 );
50 m_whirlPinchDlg->setRadius( 100.0 );
54WhirlPinchPlugin::slotWhirlPinch()
56 KarbonPart *part = ((KarbonView *)parent())->part();
57 if( part && m_whirlPinchDlg->exec() )
58 part->
addCommand(
new VWhirlPinchCmd( &part->document(), m_whirlPinchDlg->angle(), m_whirlPinchDlg->pinch(), m_whirlPinchDlg->radius() ),
true );
61VWhirlPinchDlg::VWhirlPinchDlg( TQWidget* parent,
const char* name )
62 : KDialogBase( parent, name, true, i18n(
"Whirl Pinch" ), Ok | Cancel )
65 TQGroupBox* group =
new TQGroupBox( 2, TQt::Horizontal, i18n(
"Properties" ),
this );
67 new TQLabel( i18n(
"Angle:" ), group );
68 m_angle =
new KDoubleNumInput( group );
69 new TQLabel( i18n(
"Pinch:" ), group );
70 m_pinch =
new KDoubleNumInput( group );
71 new TQLabel( i18n(
"Radius:" ), group );
72 m_radius =
new KDoubleNumInput( group );
73 group->setMinimumWidth( 300 );
76 connect(
this, TQ_SIGNAL( okClicked() ),
this, TQ_SLOT( accept() ) );
77 connect(
this, TQ_SIGNAL( cancelClicked() ),
this, TQ_SLOT( reject() ) );
79 setMainWidget( group );
80 setFixedSize( baseSize() );
84VWhirlPinchDlg::angle()
const
86 return m_angle->value();
90VWhirlPinchDlg::pinch()
const
92 return m_pinch->value();
96VWhirlPinchDlg::radius()
const
98 return m_radius->value();
102VWhirlPinchDlg::setAngle(
double value )
104 m_angle->setValue( value);
108VWhirlPinchDlg::setPinch(
double value )
110 m_pinch->setValue(value);
114VWhirlPinchDlg::setRadius(
double value )
116 m_radius->setValue( value);
119VWhirlPinchCmd::VWhirlPinchCmd(
VDocument* doc,
120 double angle,
double pinch,
double radius )
126 m_center = document()->selection()->boundingBox().center();
129VWhirlPinchCmd::~VWhirlPinchCmd()
134VWhirlPinchCmd::visitVPath(
VPath& composite )
144VWhirlPinchCmd::visitVSubpath(
VSubpath& path )
160 for(
int i = 0; i < curr->
degree(); ++i )
163 delta = curr->
point( i ) - m_center;
164 dist = sqrt( delta.x() * delta.x() + delta.y() * delta.y() );
167 if( dist < m_radius )
174 double scale = pow( sin( VGlobal::pi_2 * dist ), -m_pinch );
176 m.translate( m_center.x(), m_center.y() );
177 m.scale( scale, scale );
180 m.rotate( m_angle * ( 1.0 - dist ) * ( 1.0 - dist ) );
181 m.translate( -m_center.x(), -m_center.y() );
183 path.current()->
setPoint( i, curr->
point( i ).transform( m ) );
198#include "whirlpinchplugin.moc"
Keeps track of visual per document properties.
void addCommand(VCommand *cmd, bool repaint=false)
insert a command into the undo/redo-history:
All non-visual, static doc info is in here.
void invalidateBoundingBox()
Invalidates the bounding box, so it has to be recalculated.
A composite path consists of one or many subpaths.
VReplacingCmd is a generic command.
A class representing lines and beziers.
void setPoint(int i, const KoPoint &p)
Sets the segment's point with index 0 <= i < degree() to "p".
unsigned short degree() const
Returns the segment's degree, which is identical to the number of nodes.
const KoPoint & point(int i) const
Returns the segment's point with index 0 <= i < degree().
VSubpath provides a sophisticated list of VSegment.
virtual void visitVPath(VPath &composite)
Visit method for a VPath.