20#include "roundcornersplugin.h"
21#include <karbon_view.h>
22#include <karbon_part.h>
23#include <core/vpath.h>
24#include <core/vsegment.h>
25#include <kgenericfactory.h>
27#include <tqgroupbox.h>
32typedef KGenericFactory<VRoundCornersPlugin, KarbonView> VRoundCornersPluginFactory;
33K_EXPORT_COMPONENT_FACTORY( karbon_roundcornersplugin, VRoundCornersPluginFactory(
"karbonroundcornersplugin" ) )
35VRoundCornersPlugin::VRoundCornersPlugin( KarbonView *parent, const
char* name, const TQStringList & ) : Plugin( parent, name )
38 i18n(
"&Round Corners..." ),
"14_roundcorners", 0,
this,
39 TQ_SLOT( slotRoundCorners() ), actionCollection(),
"path_round_corners" );
41 m_roundCornersDlg =
new VRoundCornersDlg();
42 m_roundCornersDlg->setRadius( 10.0 );
45VRoundCornersPlugin::~VRoundCornersPlugin()
50VRoundCornersPlugin::slotRoundCorners()
52 KarbonPart *part = ((KarbonView *)parent())->part();
53 if( part && m_roundCornersDlg->exec() )
54 part->
addCommand(
new VRoundCornersCmd( &part->document(), m_roundCornersDlg->radius() ),
true );
58VRoundCornersDlg::VRoundCornersDlg( TQWidget* parent,
const char* name )
59 : KDialogBase( parent, name, true, i18n(
"Polygonize" ), Ok | Cancel )
62 TQGroupBox* group =
new TQGroupBox( 2, TQt::Horizontal, i18n(
"Properties" ),
this );
64 new TQLabel( i18n(
"Round corners:" ), group );
65 m_radius =
new KDoubleNumInput( group );
66 group->setMinimumWidth( 300 );
69 connect(
this, TQ_SIGNAL( okClicked() ),
this, TQ_SLOT( accept() ) );
70 connect(
this, TQ_SIGNAL( cancelClicked() ),
this, TQ_SLOT( reject() ) );
72 setMainWidget( group );
73 setFixedSize( baseSize() );
77VRoundCornersDlg::radius()
const
79 return m_radius->value();
83VRoundCornersDlg::setRadius(
double value )
85 m_radius->setValue(value);
90VRoundCornersCmd::VRoundCornersCmd(
VDocument* doc,
double radius )
94 m_radius = radius > 0.0 ? radius : 1.0;
98VRoundCornersCmd::visitVSubpath(
VSubpath& path )
107 VSubpath newPath( 0L );
232 if( path.current()->
isFlat() )
235 if( path.getLast()->
isFlat() )
241 !path.getLast()->
isSmooth( *path.current() ) )
243 length = path.current()->
length();
245 param = length > 2 * m_radius
251 path.current()->
splitAt( param ) );
254 path.current()->
knot() );
274 path.current()->
next() )
277 if( path.current()->
isFlat() )
287 newPath.append( path.current()->
clone() );
295 length = path.current()->
length();
299 if( length > m_radius )
301 param = path.current()->
lengthParam( length - m_radius );
304 path.current()->
splitAt( param ) );
306 path.current()->
clone() );
317 length = path.current()->
length();
319 param = length > 2 * m_radius
324 path.current()->
splitAt( param ) );
330 path.current()->
pointAt( 0.5 ),
331 path.current()->
knot() );
344 if( path.isClosed() )
347 if( path.current()->
isFlat() )
354 if( !path.current()->
isSmooth( *path.getFirst()->
next() ) )
356 length = path.current()->
length();
360 if( length > m_radius )
362 param = path.current()->
lengthParam( length - m_radius );
365 path.current()->
splitAt( param ) );
367 path.current()->
clone() );
378 path.getLast()->
pointAt( 0.5 ),
379 path.current()->
pointAt( 0.5 ),
380 path.current()->
knot() );
387 newPath.append( path.current()->
clone() );
392 newPath.append( path.current()->
clone() );
401#include "roundcornersplugin.moc"
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.
VReplacingCmd is a generic command.
double length(double t=1.0) const
Calculates the arclength from p0 to the point parametrized by 0 <= t <= 1.
double lengthParam(double len) const
Calculates the parameter of a point located at arclength len.
VSegment * next() const
Returns a pointer to the next not deleted segment, if stored in a VSubpath.
bool isFlat(double flatness=VGlobal::flatnessTolerance) const
Returns true if the segment is flat.
VSegment * clone() const
Returns a pointer to a copy of this segment.
void setDegree(unsigned short deg)
Sets the segment's degree and thus resizes the array of node data.
bool isSmooth(const VSegment &next) const
Calculates wether the tangent at the knot is exactly parallel to the tangent at p0 of the next segmen...
VSegment * splitAt(double t)
Splits the segment at parameter 0 <= t <= 1.
VSegment * prev() const
Returns a pointer to the previous not deleted segment, if stored in a VSubpath.
KoPoint pointAt(double t) const
Calculates the point on this segment at parameter 0 <= t <= 1.
const KoPoint & knot() const
Returns the knot.
VSubpath provides a sophisticated list of VSegment.
bool isEmpty() const
Returns true if the current path is "emtpy".
bool success() const
Return if the operation was a success or not.
void setSuccess(bool success=true)
Set the success property.