karbon

flattenpathplugin.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002, 2003 The Karbon Developers
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "flattenpathplugin.h"
21#include "tdelocale.h"
22#include <karbon_view.h>
23#include <karbon_part.h>
24#include <kgenericfactory.h>
25#include <kdebug.h>
26#include <tqgroupbox.h>
27#include <tqlabel.h>
28
29#include <knuminput.h>
30#include <commands/vflattencmd.h>
31
32
33typedef KGenericFactory<FlattenPathPlugin, KarbonView> FlattenPathPluginFactory;
34K_EXPORT_COMPONENT_FACTORY( karbon_flattenpathplugin, FlattenPathPluginFactory( "karbonflattenpathplugin" ) )
35
36FlattenPathPlugin::FlattenPathPlugin( KarbonView *parent, const char* name, const TQStringList & )
37: Plugin( parent, name )
38{
39 new TDEAction(
40 i18n( "&Flatten Path..." ), "14_flatten", 0, this,
41 TQ_SLOT( slotFlattenPath() ), actionCollection(), "path_flatten" );
42
43 m_flattenPathDlg = new VFlattenDlg();
44 m_flattenPathDlg->setFlatness( 0.2 );
45}
46
47void
48FlattenPathPlugin::slotFlattenPath()
49{
50 KarbonPart *part = ((KarbonView *)parent())->part();
51 if( part && m_flattenPathDlg->exec() )
52 part->addCommand( new VFlattenCmd( &part->document(), m_flattenPathDlg->flatness() ), true );
53}
54
55VFlattenDlg::VFlattenDlg( TQWidget* parent, const char* name )
56 : KDialogBase( parent, name, true, i18n( "Flatten Path" ), Ok | Cancel )
57{
58 // add input fields on the left:
59 TQGroupBox* group = new TQGroupBox( 2, TQt::Horizontal, i18n( "Properties" ), this );
60 new TQLabel( i18n( "Flatness:" ), group );
61 m_flatness = new KDoubleNumInput( group );
62 group->setMinimumWidth( 300 );
63
64 // signals and slots:
65 connect( this, TQ_SIGNAL( okClicked() ), this, TQ_SLOT( accept() ) );
66 connect( this, TQ_SIGNAL( cancelClicked() ), this, TQ_SLOT( reject() ) );
67
68 setMainWidget( group );
69 setFixedSize( baseSize() );
70}
71
72double
73VFlattenDlg::flatness() const
74{
75 return m_flatness->value();
76}
77
78void
79VFlattenDlg::setFlatness( double value )
80{
81 m_flatness->setValue( value);
82}
83
84#include "flattenpathplugin.moc"
85
void addCommand(VCommand *cmd, bool repaint=false)
insert a command into the undo/redo-history: