1 // Copyright (C) 2002 Dominique Devriese <devriese@kde.org>
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18 #include "guiaction.h"
19 #include "guiaction.moc"
21 #include "coordinate_system.h"
22 #include "coordinate.h"
23 #include "object_constructor.h"
25 #include "../kig/kig_part.h"
26 #include "../kig/kig_document.h"
27 #include "../modes/construct_mode.h"
28 #include "../modes/label.h"
29 #include "../objects/object_holder.h"
30 #include "../objects/object_factory.h"
31 #include "../objects/bogus_imp.h"
33 #include <kiconloader.h>
38 int GUIAction::shortcut() const
43 GUIAction::~GUIAction()
47 ConstructibleAction::~ConstructibleAction()
51 ConstructibleAction::ConstructibleAction(
52 ObjectConstructor
* ctor
,
53 const QCString
& actionname
,
55 : GUIAction(), mctor( ctor
), mactionname( actionname
), mshortcut( shortcut
)
59 QString
ConstructibleAction::description() const
61 return mctor
->description();
64 QCString
ConstructibleAction::iconFileName() const
66 return mctor
->iconFileName();
69 QString
ConstructibleAction::descriptiveName() const
71 return mctor
->descriptiveName();
74 void ConstructibleAction::act( KigPart
& d
)
76 BaseConstructMode
* m
= mctor
->constructMode( d
);
81 KigGUIAction::KigGUIAction( GUIAction
* act
,
84 : KAction( act
->descriptiveName(),
85 doc
.instance()->iconLoader()->loadIcon(
86 act
->iconFileName(), KIcon::User
),
88 0, 0, // no slot connection
89 parent
, act
->actionName() ),
93 setWhatsThis( act
->description() );
94 QString tooltip
= act
->descriptiveName();
95 tooltip
.replace( QRegExp( "&&" ), "&" );
96 setToolTip( tooltip
);
99 void KigGUIAction::slotActivated()
104 const char* ConstructibleAction::actionName() const
109 ConstructPointAction::~ConstructPointAction()
113 QString
ConstructPointAction::description() const
116 "A normal point, i.e. one that is either independent or attached "
117 "to a line, circle, segment."
121 QCString
ConstructPointAction::iconFileName() const
126 QString
ConstructPointAction::descriptiveName() const
128 return i18n("Point");
131 const char* ConstructPointAction::actionName() const
136 int ConstructPointAction::shortcut() const
141 void ConstructPointAction::act( KigPart
& d
)
143 PointConstructMode
m( d
);
147 ConstructPointAction::ConstructPointAction( const char* actionname
)
148 : mactionname( actionname
)
152 GUIAction
* KigGUIAction::guiAction()
157 void KigGUIAction::plug( KigPart
* doc
)
159 mact
->plug( doc
, this );
162 void ConstructibleAction::plug( KigPart
* doc
, KigGUIAction
* kact
)
164 mctor
->plug( doc
, kact
);
167 QString
ConstructTextLabelAction::description() const
169 return i18n( "Construct a text label." );
172 QCString
ConstructTextLabelAction::iconFileName() const
177 QString
ConstructTextLabelAction::descriptiveName() const
179 return i18n( "Text Label" );
182 const char* ConstructTextLabelAction::actionName() const
187 void ConstructTextLabelAction::act( KigPart
& d
)
189 TextLabelConstructionMode
m( d
);
193 ConstructTextLabelAction::ConstructTextLabelAction( const char* actionname
)
194 : mactionname( actionname
)
198 QString
AddFixedPointAction::description() const
200 return i18n( "Construct a Point by its Coordinates" );
203 QCString
AddFixedPointAction::iconFileName() const
208 QString
AddFixedPointAction::descriptiveName() const
210 return i18n( "Point by Coordinates" );
213 const char* AddFixedPointAction::actionName() const
218 void AddFixedPointAction::act( KigPart
& doc
)
221 Coordinate c
= doc
.document().coordinateSystem().getCoordFromUser(
222 i18n( "Fixed Point" ),
223 i18n( "Enter the coordinates for the new point." ) +
224 QString::fromLatin1("\n") +
225 doc
.document().coordinateSystem().coordinateFormatNotice(),
226 doc
.document(), doc
.widget(), &ok
);
228 ObjectHolder
* p
= ObjectFactory::instance()->fixedPoint( c
);
229 p
->calc( doc
.document() );
233 AddFixedPointAction::AddFixedPointAction( const char* actionname
)
234 : mactionname( actionname
)
238 AddFixedPointAction::~AddFixedPointAction()
242 void GUIAction::plug( KigPart
*, KigGUIAction
* )
246 int ConstructibleAction::shortcut() const
251 int ConstructTextLabelAction::shortcut() const
256 int AddFixedPointAction::shortcut() const
262 TestAction::TestAction( const char* actionname
)
263 : mactionname( actionname
)
267 TestAction::~TestAction()
271 QString
TestAction::description() const
273 return QString::fromLatin1( "Test stuff !!!" );
276 QCString
TestAction::iconFileName() const
281 QString
TestAction::descriptiveName() const
283 return QString::fromLatin1( "Test stuff !!!" );
286 const char* TestAction::actionName() const
291 void TestAction::act( KigPart
& doc
)
294 "def calc( a ):\n\treturn Point( a.coordinate() + Coordinate( 2, 0 ) )\n";
295 Object
* constantpoint
= ObjectFactory::instance()->fixedPoint( Coordinate( -1, -1 ) );
296 constantpoint
->calc( doc
);
298 Object
* codeobject
= new DataObject( new StringImp( QString::fromLatin1( script
) ) );
299 Object
* compiledcode
= new RealObject( PythonCompileType::instance(), Objects( codeobject
) );
300 compiledcode
->calc( doc
);
302 Objects
args( compiledcode
);
303 args
.push_back( constantpoint
);
304 Object
* scriptobject
= new RealObject( PythonExecuteType::instance(), args
);
305 scriptobject
->calc( doc
);
307 doc
.addObject( constantpoint
);
308 doc
.addObject( scriptobject
);
311 #endif // if 0 ( TestAction )
313 #ifdef KIG_ENABLE_PYTHON_SCRIPTING
314 #include "../scripting/python_type.h"
315 #include "../scripting/script_mode.h"
317 NewScriptAction::NewScriptAction( const char* descname
, const char* description
,
318 const char* actionname
, const ScriptType::Type type
,
320 : GUIAction(), mactionname( actionname
), mdescname( descname
),
321 mdescription( description
), micon( icon
), mtype( type
)
323 if ( QString( micon
).isEmpty() )
325 micon
= ScriptType::icon( type
);
329 NewScriptAction::~NewScriptAction()
333 QString
NewScriptAction::description() const
335 return i18n( mdescription
);
338 QCString
NewScriptAction::iconFileName() const
343 QString
NewScriptAction::descriptiveName() const
345 return i18n( mdescname
);
348 const char* NewScriptAction::actionName() const
353 void NewScriptAction::act( KigPart
& doc
)
356 m
.setScriptType( mtype
);
360 int NewScriptAction::shortcut() const
365 #endif // if KIG_ENABLE_PYTHON_SCRIPTING ( NewScriptAction )