karbon
insertknotsplugin.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "insertknotsplugin.h"
00022 #include <karbon_view.h>
00023 #include <karbon_part.h>
00024 #include <core/vpath.h>
00025 #include <core/vsegment.h>
00026 #include <kgenericfactory.h>
00027 #include <kdebug.h>
00028 #include <qgroupbox.h>
00029 #include <qlabel.h>
00030
00031 #include <knuminput.h>
00032
00033 typedef KGenericFactory<InsertKnotsPlugin, KarbonView> InsertKnotsPluginFactory;
00034 K_EXPORT_COMPONENT_FACTORY( karbon_insertknotsplugin, InsertKnotsPluginFactory( "karboninsertknotsplugin" ) )
00035
00036 InsertKnotsPlugin::InsertKnotsPlugin( KarbonView *parent, const char* name, const QStringList & ) : Plugin( parent, name )
00037 {
00038 new KAction(
00039 i18n( "&Insert Knots..." ), "14_insertknots", 0, this,
00040 SLOT( slotInsertKnots() ), actionCollection(), "path_insert_knots" );
00041
00042 m_insertKnotsDlg = new VInsertKnotsDlg();
00043 }
00044
00045 void
00046 InsertKnotsPlugin::slotInsertKnots()
00047 {
00048 KarbonPart *part = ((KarbonView *)parent())->part();
00049 if( part && m_insertKnotsDlg->exec() )
00050 part->addCommand( new VInsertKnotsCmd( &part->document(), m_insertKnotsDlg->knots() ), true );
00051 }
00052
00053 VInsertKnotsDlg::VInsertKnotsDlg( QWidget* parent, const char* name )
00054 : KDialogBase( parent, name, true, i18n( "Insert Knots" ), Ok | Cancel )
00055 {
00056
00057 QGroupBox* group = new QGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), this );
00058
00059 new QLabel( i18n( "Knots:" ), group );
00060 m_knots = new KIntSpinBox( group );
00061 m_knots->setMinValue( 1 );
00062 group->setMinimumWidth( 300 );
00063
00064
00065 connect( this, SIGNAL( okClicked() ), this, SLOT( accept() ) );
00066 connect( this, SIGNAL( cancelClicked() ), this, SLOT( reject() ) );
00067
00068 setMainWidget( group );
00069 setFixedSize( baseSize() );
00070 }
00071
00072 uint
00073 VInsertKnotsDlg::knots() const
00074 {
00075 return m_knots->value();
00076 }
00077
00078 void
00079 VInsertKnotsDlg::setKnots( uint value )
00080 {
00081 m_knots->setValue( value );
00082 }
00083
00084
00085 VInsertKnotsCmd::VInsertKnotsCmd( VDocument* doc, uint knots )
00086 : VReplacingCmd( doc, i18n( "Insert Knots" ) )
00087 {
00088 m_knots = knots > 0 ? knots : 1;
00089 }
00090
00091 void
00092 VInsertKnotsCmd::visitVSubpath( VSubpath& path )
00093 {
00094 path.first();
00095
00096 double length;
00097
00098
00099 while( path.next() )
00100 {
00101 length = path.current()->length();
00102
00103 for( uint i = m_knots; i > 0; --i )
00104 {
00105 path.insert(
00106 path.current()->splitAt(
00107 path.current()->lengthParam( length / ( m_knots + 1.0 ) ) ) );
00108
00109 path.next();
00110 }
00111
00112 if( !success() )
00113 setSuccess();
00114 }
00115 }
00116
00117 #include "insertknotsplugin.moc"
00118
|