moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kig / objects / object_type.h
blob7ae74fe7987ea53a31e2cde028f9568bc07dafaa
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 #ifndef KIG_OBJECTS_OBJECT_TYPE_H
19 #define KIG_OBJECTS_OBJECT_TYPE_H
21 #include "common.h"
22 #include "../misc/argsparser.h"
24 class ObjectTypeCalcer;
26 /**
27 * The ObjectType class is a thing that represents the "behaviour" for
28 * a certain type.. This basically means that it decides what
29 * @ref ObjectImp the object gets in the calc() function, how the
30 * object move()'s etc.
32 class ObjectType
34 const char* mfulltypename;
35 protected:
36 ObjectType( const char fulltypename[] );
37 public:
38 virtual ~ObjectType();
40 enum {
41 ID_ConstrainedPointType,
42 ID_LocusType,
43 ID_FixedPointType
46 virtual bool inherits( int type ) const;
48 virtual ObjectImp* calc( const Args& parents, const KigDocument& d ) const = 0;
50 virtual bool canMove( const ObjectTypeCalcer& ourobj ) const;
51 virtual bool isFreelyTranslatable( const ObjectTypeCalcer& ourobj ) const;
52 virtual std::vector<ObjectCalcer*> movableParents( const ObjectTypeCalcer& ourobj ) const;
53 virtual const Coordinate moveReferencePoint( const ObjectTypeCalcer& ourobj ) const;
54 virtual void move( ObjectTypeCalcer& ourobj, const Coordinate& to,
55 const KigDocument& d ) const;
57 const char* fullName() const;
59 // Supposing that parents would be given as parents to
60 // this type's calc function, this function returns the ObjectImp id
61 // that o should at least have.. ( o should be part of parents )
62 virtual const ObjectImpType* impRequirement( const ObjectImp* o, const Args& parents ) const = 0;
64 // Supposing that parents would be given as parents to this type's
65 // calc function, this function returns whether the returned
66 // ObjectImp will be, by construction, on o ( if o is a curve ), or
67 // through o ( if o is a point ).
68 virtual bool isDefinedOnOrThrough( const ObjectImp* o, const Args& parents ) const = 0;
70 // returns the ObjectImp id of the ObjectImp's produced by this
71 // ObjectType.. if the ObjectType can return different sorts of
72 // ObjectImp's, it should return the biggest common id, or
73 // ID_AnyImp..
74 virtual const ObjectImpType* resultId() const = 0;
76 virtual std::vector<ObjectCalcer*> sortArgs( const std::vector<ObjectCalcer*>& args ) const = 0;
78 virtual Args sortArgs( const Args& args ) const = 0;
80 // is this object type a transformation type. We want to know this
81 // cause transform types are shown separately in an object's RMB
82 // menu..
83 virtual bool isTransform() const;
85 // ObjectType's can define some special actions, that are strictly
86 // specific to the type at hand. E.g. a text label allows to toggle
87 // the display of a frame around the text. Constrained and fixed
88 // points can be redefined etc.
90 // return i18n'd names for the special actions..
91 virtual QStringList specialActions() const;
92 // execute the i'th action from the specialActions above..
93 virtual void executeAction( int i, ObjectHolder& o, ObjectTypeCalcer& t,
94 KigPart& d, KigWidget& w, NormalMode& m ) const;
97 /**
98 * This is a convenience subclass of ObjectType that a type should
99 * inherit from if its parents can be specified in an argparser..
101 class ArgsParserObjectType
102 : public ObjectType
104 protected:
105 const ArgsParser margsparser;
106 ArgsParserObjectType( const char fulltypename[],
107 const struct ArgsParser::spec argsspec[],
108 int n );
109 public:
110 const ObjectImpType* impRequirement( const ObjectImp* o, const Args& parents ) const;
111 bool isDefinedOnOrThrough( const ObjectImp* o, const Args& parents ) const;
112 const ArgsParser& argsParser() const;
114 std::vector<ObjectCalcer*> sortArgs( const std::vector<ObjectCalcer*>& args ) const;
115 Args sortArgs( const Args& args ) const;
118 #endif