48
48
#include <QtGui/QHBoxLayout>
51
typedef KGenericFactory<FlattenPathPlugin,QWidget> FlattenPathPluginFactory;
52
K_EXPORT_COMPONENT_FACTORY( karbon_flattenpathplugin, FlattenPathPluginFactory( "karbonflattenpathplugin" ) )
51
typedef KGenericFactory<FlattenPathPlugin, QWidget> FlattenPathPluginFactory;
52
K_EXPORT_COMPONENT_FACTORY(karbon_flattenpathplugin, FlattenPathPluginFactory("karbonflattenpathplugin"))
54
FlattenPathPlugin::FlattenPathPlugin( QWidget *parent, const QStringList & )
55
: Plugin( parent/*, name*/ )
54
FlattenPathPlugin::FlattenPathPlugin(QWidget *parent, const QStringList &)
55
: Plugin(parent/*, name*/)
57
57
KAction *actionFlattenPath = new KAction(KIcon("14_flatten"), i18n("&Flatten Path..."), this);
58
actionCollection()->addAction("path_flatten", actionFlattenPath );
58
actionCollection()->addAction("path_flatten", actionFlattenPath);
59
59
connect(actionFlattenPath, SIGNAL(triggered()), this, SLOT(slotFlattenPath()));
61
m_flattenPathDlg = new FlattenDlg( parent );
62
m_flattenPathDlg->setFlatness( 10.0 );
61
m_flattenPathDlg = new FlattenDlg(parent);
62
m_flattenPathDlg->setFlatness(10.0);
65
65
void FlattenPathPlugin::slotFlattenPath()
67
67
KoCanvasController* canvasController = KoToolManager::instance()->activeCanvasController();
68
68
KoSelection *selection = canvasController->canvas()->shapeManager()->selection();
69
69
KoShape * shape = selection->firstSelectedShape();
73
73
// check if we have a path based shape
74
KoPathShape * path = dynamic_cast<KoPathShape*>( shape );
74
KoPathShape * path = dynamic_cast<KoPathShape*>(shape);
78
78
// check if it is no parametric shape
79
KoParameterShape * ps = dynamic_cast<KoParameterShape*>( shape );
80
if( ps && ps->isParametricShape() )
83
if( QDialog::Rejected == m_flattenPathDlg->exec() )
86
canvasController->canvas()->addCommand(
87
new KarbonPathFlattenCommand( path, m_flattenPathDlg->flatness() ) );
79
KoParameterShape * ps = dynamic_cast<KoParameterShape*>(shape);
80
if (ps && ps->isParametricShape())
83
if (QDialog::Rejected == m_flattenPathDlg->exec())
86
canvasController->canvas()->addCommand(
87
new KarbonPathFlattenCommand(path, m_flattenPathDlg->flatness()));
90
FlattenDlg::FlattenDlg( QWidget* parent, const char* name )
90
FlattenDlg::FlattenDlg(QWidget* parent, const char* name)
93
93
setObjectName(name);
95
setCaption( i18n( "Flatten Path" ) );
96
setButtons( Ok | Cancel );
95
setCaption(i18n("Flatten Path"));
96
setButtons(Ok | Cancel);
98
98
// add input fields on the left:
99
QGroupBox* group = new QGroupBox( i18n( "Properties" ), this );
99
QGroupBox* group = new QGroupBox(i18n("Properties"), this);
101
101
QHBoxLayout* layout = new QHBoxLayout;
103
layout->addWidget(new QLabel( i18n( "Flatness:" )));
103
layout->addWidget(new QLabel(i18n("Flatness:")));
104
104
m_flatness = new KDoubleNumInput(group);
105
105
layout->addWidget(m_flatness);
107
107
group->setLayout(layout);
108
group->setMinimumWidth( 300 );
108
group->setMinimumWidth(300);
110
110
// signals and slots:
111
connect( this, SIGNAL( okClicked() ), this, SLOT( accept() ) );
112
connect( this, SIGNAL( cancelClicked() ), this, SLOT( reject() ) );
111
connect(this, SIGNAL(okClicked()), this, SLOT(accept()));
112
connect(this, SIGNAL(cancelClicked()), this, SLOT(reject()));
114
setMainWidget( group );
114
setMainWidget(group);
117
117
qreal FlattenDlg::flatness() const