moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kig / objects / object_holder.h
blob9716db888db63f98ccc5b7d7a5b9523b0e74c879
1 // Copyright (C) 2003 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_HOLDER_H
19 #define KIG_OBJECTS_OBJECT_HOLDER_H
21 #include "object_calcer.h"
23 #include <qstring.h>
25 /**
26 * An ObjectHolder represents an object as it is known to the
27 * document. It keeps a pointer to an ObjectCalcer, where it gets its
28 * data ( the ObjectImp that the ObjectCalcer holds ) from. It also
29 * holds information about how to draw this ObjectImp on the window,
30 * by keeping a pointer to an ObjectDrawer ( see below ). In its draw
31 * method, it gets the ObjectImp from the ObjectCalcer, and passes it
32 * to the ObjectDrawer, asking it to draw the ObjectImp on the window.
34 * The document ( check the KigDocument class ) holds a list of these
35 * ObjectHolder's. This is its only link with the ObjectCalcer
36 * dependency graph.
38 * An ObjectHolder keeps a reference to its * ObjectCalcer.
40 class ObjectHolder
42 ObjectCalcer::shared_ptr mcalcer;
43 ObjectDrawer* mdrawer;
44 ObjectConstCalcer::shared_ptr mnamecalcer;
46 public:
47 /**
48 * Construct a new ObjectHolder with a given ObjectCalcer and
49 * ObjectDrawer, with a given name calcer.
51 ObjectHolder( ObjectCalcer* calcer, ObjectDrawer* drawer, ObjectConstCalcer* namecalcer );
52 /**
53 * Construct a new ObjectHolder with a given ObjectCalcer and
54 * ObjectDrawer.
56 ObjectHolder( ObjectCalcer* calcer, ObjectDrawer* drawer );
57 /**
58 * equivalent to the previous constructor, but with a default
59 * ObjectDrawer and no name.
61 ObjectHolder( ObjectCalcer* calcer );
62 ~ObjectHolder();
64 const ObjectImp* imp() const;
65 const ObjectCalcer* calcer() const;
66 ObjectCalcer* calcer();
67 const ObjectDrawer* drawer() const;
68 ObjectDrawer* drawer();
69 // the following two return zero if no name is set.
70 const ObjectConstCalcer* nameCalcer() const;
71 ObjectConstCalcer* nameCalcer();
72 // Setting the namecalcer is only allowed if previously none was
73 // set. This way, we avoid keeping a useless namecalcer around if
74 // no name is set.
75 void setNameCalcer( ObjectConstCalcer* namecalcer );
77 // returns QString::null if no name is set.
78 const QString name() const;
79 /**
80 * Set the ObjectDrawer of this ObjectHolder to d, the old
81 * ObjectDrawer is deleted.
83 void setDrawer( ObjectDrawer* d );
84 /**
85 * Set the ObjectDrawer of this ObjectHolder to d, the old
86 * ObjectDrawer is not deleted, but returned.
88 ObjectDrawer* switchDrawer( ObjectDrawer* d );
90 /**
91 * Make our ObjectCalcer recalculate its ObjectImp.
93 void calc( const KigDocument& );
94 /**
95 * Draw this object on the given KigPainter. If selected is true,
96 * then it will be drawn in red, instead of its normal color.
98 void draw( KigPainter& p, bool selected ) const;
99 /**
100 * Returns whether this object contains the point p.
102 bool contains( const Coordinate& p, const KigWidget& w, bool nv = false ) const;
104 * Returns whether this object is in the rectangle r.
106 bool inRect( const Rect& r, const KigWidget& w ) const;
108 * Returns whether this object is shown.
110 bool shown( ) const;
113 * This call is simply forwarded to the ObjectCalcer. Check the
114 * documentation of ObjectCalcer::moveReferencePoint() for more info.
116 const Coordinate moveReferencePoint() const;
118 * This call is simply forwarded to the ObjectCalcer. Check the
119 * documentation of ObjectCalcer::move() for more info.
121 void move( const Coordinate& to, const KigDocument& );
123 * This call is simply forwarded to the ObjectCalcer. Check the
124 * documentation of ObjectCalcer::canMove() for more info.
126 bool canMove() const;
128 * This call is simply forwarded to the ObjectCalcer. Check the
129 * documentation of ObjectCalcer::isFreelyTranslatable() for more info.
131 bool isFreelyTranslatable() const;
134 * Return a statement saying something like "select this segment" or
135 * "select segment ab" depending on whether this ObjectHolder has a
136 * name.
138 QString selectStatement() const;
141 #endif