summaryrefslogtreecommitdiffstats
path: root/kig/objects/object_type.h
blob: f0ac49af39f45409980ae2d827588ecfc4352e7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright (C)  2002  Dominique Devriese <devriese@kde.org>

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
// 02110-1301, USA.

#ifndef KIG_OBJECTS_OBJECT_TYPE_H
#define KIG_OBJECTS_OBJECT_TYPE_H

#include "common.h"
#include "../misc/argsparser.h"

class ObjectTypeCalcer;

/**
 * The ObjectType class is a thing that represents the "behaviour" for
 * a certain type..  This basically means that it decides what
 * \ref ObjectImp the object gets in the calc() function, how the
 * object move()'s etc.
 */
class ObjectType
{
  const char* mfulltypename;
protected:
  ObjectType( const char fulltypename[] );
public:
  virtual ~ObjectType();

  enum {
    ID_ConstrainedPointType,
    ID_LocusType,
    ID_FixedPointType
  };

  virtual bool inherits( int type ) const;

  virtual ObjectImp* calc( const Args& parents, const KigDocument& d ) const = 0;

  virtual bool canMove( const ObjectTypeCalcer& ourobj ) const;
  virtual bool isFreelyTranslatable( const ObjectTypeCalcer& ourobj ) const;
  virtual std::vector<ObjectCalcer*> movableParents( const ObjectTypeCalcer& ourobj ) const;
  virtual const Coordinate moveReferencePoint( const ObjectTypeCalcer& ourobj ) const;
  virtual void move( ObjectTypeCalcer& ourobj, const Coordinate& to,
                     const KigDocument& d ) const;

  const char* fullName() const;

  /**
   * Supposing that \p parents would be given as parents to
   * this type's calc function, this function returns the ObjectImp id
   * that \p o should at least have..  ( \p o should be part of \p parents )
   */
  virtual const ObjectImpType* impRequirement( const ObjectImp* o, const Args& parents ) const = 0;

  /**
   * Supposing that \p parents would be given as parents to this type's
   * calc function, this function returns whether the returned
   * ObjectImp will be, by construction, on \p o ( if \p o is a curve ), or
   * through \p o ( if \p o is a point ).
   */
  virtual bool isDefinedOnOrThrough( const ObjectImp* o, const Args& parents ) const = 0;

  /**
   * returns the ObjectImp id of the ObjectImp's produced by this
   * ObjectType..  if the ObjectType can return different sorts of
   * ObjectImp's, it should return the biggest common id, or
   * ID_AnyImp..
   */
  virtual const ObjectImpType* resultId() const = 0;

  virtual std::vector<ObjectCalcer*> sortArgs( const std::vector<ObjectCalcer*>& args ) const = 0;

  virtual Args sortArgs( const Args& args ) const = 0;

  /**
   * is this object type a transformation type.  We want to know this
   * cause transform types are shown separately in an object's RMB
   * menu..
   */
  virtual bool isTransform() const;

  // ObjectType's can define some special actions, that are strictly
  // specific to the type at hand.  E.g. a text label allows to toggle
  // the display of a frame around the text.  Constrained and fixed
  // points can be redefined etc.

  /**
   * return i18n'd names for the special actions..
   */
  virtual QStringList specialActions() const;
  /**
   * execute the \p i 'th action from the specialActions above..
   */
  virtual void executeAction( int i, ObjectHolder& o, ObjectTypeCalcer& t,
                              KigPart& d, KigWidget& w, NormalMode& m ) const;
};

/**
 * This is a convenience subclass of ObjectType that a type should
 * inherit from if its parents can be specified in an ArgsParser..
 */
class ArgsParserObjectType
  : public ObjectType
{
protected:
  const ArgsParser margsparser;
  ArgsParserObjectType( const char fulltypename[],
                        const struct ArgsParser::spec argsspec[],
                        int n );
public:
  const ObjectImpType* impRequirement( const ObjectImp* o, const Args& parents ) const;
  bool isDefinedOnOrThrough( const ObjectImp* o, const Args& parents ) const;
  const ArgsParser& argsParser() const;

  std::vector<ObjectCalcer*> sortArgs( const std::vector<ObjectCalcer*>& args ) const;
  Args sortArgs( const Args& args ) const;
};

#endif