moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kig / misc / guiaction.cc
blob9178586326b50b4e235fca135413adf87d5593e5
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
16 // 02111-1307, USA.
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>
34 #include <klocale.h>
36 #include <qregexp.h>
38 int GUIAction::shortcut() const
40 return 0;
43 GUIAction::~GUIAction()
47 ConstructibleAction::~ConstructibleAction()
51 ConstructibleAction::ConstructibleAction(
52 ObjectConstructor* ctor,
53 const QCString& actionname,
54 int shortcut )
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 );
77 d.runMode( m );
78 delete m;
81 KigGUIAction::KigGUIAction( GUIAction* act,
82 KigPart& doc,
83 QObject* parent )
84 : KAction( act->descriptiveName(),
85 doc.instance()->iconLoader()->loadIcon(
86 act->iconFileName(), KIcon::User ),
87 act->shortcut(),
88 0, 0, // no slot connection
89 parent, act->actionName() ),
90 mact( act ),
91 mdoc( doc )
93 setWhatsThis( act->description() );
94 QString tooltip = act->descriptiveName();
95 tooltip.replace( QRegExp( "&&" ), "&" );
96 setToolTip( tooltip );
99 void KigGUIAction::slotActivated()
101 mact->act( mdoc );
104 const char* ConstructibleAction::actionName() const
106 return mactionname;
109 ConstructPointAction::~ConstructPointAction()
113 QString ConstructPointAction::description() const
115 return i18n(
116 "A normal point, i.e. one that is either independent or attached "
117 "to a line, circle, segment."
121 QCString ConstructPointAction::iconFileName() const
123 return "point";
126 QString ConstructPointAction::descriptiveName() const
128 return i18n("Point");
131 const char* ConstructPointAction::actionName() const
133 return mactionname;
136 int ConstructPointAction::shortcut() const
138 return Qt::Key_P;
141 void ConstructPointAction::act( KigPart& d )
143 PointConstructMode m( d );
144 d.runMode( &m );
147 ConstructPointAction::ConstructPointAction( const char* actionname )
148 : mactionname( actionname )
152 GUIAction* KigGUIAction::guiAction()
154 return mact;
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
174 return "text";
177 QString ConstructTextLabelAction::descriptiveName() const
179 return i18n( "Text Label" );
182 const char* ConstructTextLabelAction::actionName() const
184 return mactionname;
187 void ConstructTextLabelAction::act( KigPart& d )
189 TextLabelConstructionMode m( d );
190 d.runMode( &m );
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
205 return "pointxy";
208 QString AddFixedPointAction::descriptiveName() const
210 return i18n( "Point by Coordinates" );
213 const char* AddFixedPointAction::actionName() const
215 return mactionname;
218 void AddFixedPointAction::act( KigPart& doc )
220 bool ok;
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 );
227 if ( ! ok ) return;
228 ObjectHolder* p = ObjectFactory::instance()->fixedPoint( c );
229 p->calc( doc.document() );
230 doc.addObject( p );
233 AddFixedPointAction::AddFixedPointAction( const char* actionname )
234 : mactionname( actionname )
238 AddFixedPointAction::~AddFixedPointAction()
242 void GUIAction::plug( KigPart*, KigGUIAction* )
246 int ConstructibleAction::shortcut() const
248 return mshortcut;
251 int ConstructTextLabelAction::shortcut() const
253 return Qt::Key_B;
256 int AddFixedPointAction::shortcut() const
258 return Qt::Key_F;
261 #if 0
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
278 return "new";
281 QString TestAction::descriptiveName() const
283 return QString::fromLatin1( "Test stuff !!!" );
286 const char* TestAction::actionName() const
288 return mactionname;
291 void TestAction::act( KigPart& doc )
293 const char* script =
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,
319 const char* icon )
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
340 return micon;
343 QString NewScriptAction::descriptiveName() const
345 return i18n( mdescname );
348 const char* NewScriptAction::actionName() const
350 return mactionname;
353 void NewScriptAction::act( KigPart& doc )
355 ScriptMode m( doc );
356 m.setScriptType( mtype );
357 doc.runMode( &m );
360 int NewScriptAction::shortcut() const
362 return 0;
365 #endif // if KIG_ENABLE_PYTHON_SCRIPTING ( NewScriptAction )