• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kig

  • sources
  • kde-4.12
  • kdeedu
  • kig
  • objects
text_imp.cc
Go to the documentation of this file.
1 // Copyright (C) 2003 Dominique Devriese <devriese@kde.org>
2 
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.
7 
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.
12 
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., 51 Franklin Street, Fifth Floor, Boston, MA
16 // 02110-1301, USA.
17 
18 #include "text_imp.h"
19 
20 #include "bogus_imp.h"
21 #include "../misc/kigpainter.h"
22 
23 TextImp::TextImp( const QString& text, const Coordinate& loc, bool frame )
24  : mtext( text), mloc( loc ), mframe( frame ), mboundrect( Rect::invalidRect() )
25 {
26 }
27 
28 TextImp* TextImp::copy() const
29 {
30  return new TextImp( mtext, mloc );
31 }
32 
33 TextImp::~TextImp()
34 {
35 }
36 
37 Coordinate TextImp::attachPoint() const
38 {
39  return Coordinate::invalidCoord();
40 }
41 
42 ObjectImp* TextImp::transform( const Transformation& t ) const
43 {
44  Coordinate nloc = t.apply( mloc );
45  return new TextImp( mtext, nloc, mframe );
46 }
47 
48 void TextImp::draw( KigPainter& p ) const
49 {
50  mboundrect = p.simpleBoundingRect( mloc, mtext );
51  p.drawTextFrame( mboundrect, mtext, mframe );
52 }
53 
54 bool TextImp::contains( const Coordinate& p, int, const KigWidget& ) const
55 {
56  return mboundrect.contains( p );
57 }
58 
59 bool TextImp::inRect( const Rect& r, int, const KigWidget& ) const
60 {
61  return mboundrect.intersects( r );
62 }
63 
64 bool TextImp::valid() const
65 {
66  return true;
67 }
68 
69 int TextImp::numberOfProperties() const
70 {
71  return Parent::numberOfProperties() + 1;
72 }
73 
74 const QByteArrayList TextImp::propertiesInternalNames() const
75 {
76  QByteArrayList ret = Parent::propertiesInternalNames();
77  ret << "kig_text";
78  return ret;
79 }
80 
81 const QByteArrayList TextImp::properties() const
82 {
83  QByteArrayList ret = Parent::properties();
84  ret << I18N_NOOP( "Text" );
85  return ret;
86 }
87 
88 const ObjectImpType* TextImp::impRequirementForProperty( int which ) const
89 {
90  if ( which < Parent::numberOfProperties() )
91  return Parent::impRequirementForProperty( which );
92  return TextImp::stype();
93 }
94 
95 const char* TextImp::iconForProperty( int which ) const
96 {
97  if ( which < Parent::numberOfProperties() )
98  return Parent::iconForProperty( which );
99  else if ( which == Parent::numberOfProperties() )
100  return "draw-text"; // text
101  else assert( false );
102  return "";
103 }
104 
105 ObjectImp* TextImp::property( int which, const KigDocument& w ) const
106 {
107  if ( which < Parent::numberOfProperties() )
108  return Parent::property( which, w );
109  else if ( which == Parent::numberOfProperties() )
110  return new StringImp( text() );
111  else assert( false );
112  return new InvalidImp;
113 }
114 
115 QString TextImp::text() const
116 {
117  return mtext;
118 }
119 
120 void TextImp::visit( ObjectImpVisitor* vtor ) const
121 {
122  vtor->visit( this );
123 }
124 
125 const Coordinate TextImp::coordinate() const
126 {
127  return mloc;
128 }
129 
130 bool TextImp::equals( const ObjectImp& rhs ) const
131 {
132  return rhs.inherits( TextImp::stype() ) &&
133  static_cast<const TextImp&>( rhs ).coordinate() == coordinate() &&
134  static_cast<const TextImp&>( rhs ).text() == text() &&
135  static_cast<const TextImp&>( rhs ).hasFrame() == hasFrame();
136 }
137 
138 bool TextImp::hasFrame() const
139 {
140  return mframe;
141 }
142 
143 const ObjectImpType* TextImp::stype()
144 {
145  static const ObjectImpType t(
146  Parent::stype(), "label",
147  I18N_NOOP( "label" ),
148  I18N_NOOP( "Select this label" ),
149  I18N_NOOP( "Select label %1" ),
150  I18N_NOOP( "Remove a Label" ),
151  I18N_NOOP( "Add a Label" ),
152  I18N_NOOP( "Move a Label" ),
153  I18N_NOOP( "Attach to this label" ),
154  I18N_NOOP( "Show a Label" ),
155  I18N_NOOP( "Hide a Label" )
156  );
157  return &t;
158 }
159 
160 const ObjectImpType* TextImp::type() const
161 {
162  return TextImp::stype();
163 }
164 
165 bool TextImp::isPropertyDefinedOnOrThroughThisImp( int which ) const
166 {
167  return Parent::isPropertyDefinedOnOrThroughThisImp( which );
168 }
169 
170 Rect TextImp::surroundingRect() const
171 {
172  return mboundrect;
173 }
174 
175 /*
176  * NumericTextImp
177  */
178 
179 NumericTextImp::NumericTextImp( const QString& text, const Coordinate& loc, bool frame, double value )
180  : TextImp( text, loc, frame ), mvalue( value )
181 {
182 }
183 
184 NumericTextImp* NumericTextImp::copy() const
185 {
186  return new NumericTextImp( text(), coordinate(), hasFrame(), mvalue );
187 }
188 
189 const ObjectImpType* NumericTextImp::stype()
190 {
191  static const ObjectImpType t(
192  Parent::stype(), "numeric-label",
193  I18N_NOOP( "numeric label" ),
194  I18N_NOOP( "Select this numeric label" ),
195  I18N_NOOP( "Select numeric label %1" ),
196  I18N_NOOP( "Remove a Numeric Label" ),
197  I18N_NOOP( "Add a Numeric Label" ),
198  I18N_NOOP( "Move a Numeric Label" ),
199  I18N_NOOP( "Attach to this numeric label" ),
200  I18N_NOOP( "Show a Numeric Label" ),
201  I18N_NOOP( "Hide a Numeric Label" )
202  );
203  return &t;
204 }
205 
206 const ObjectImpType* NumericTextImp::type() const
207 {
208  return NumericTextImp::stype();
209 }
210 
211 double NumericTextImp::getValue( void ) const
212 {
213  return mvalue;
214 }
215 
216 int NumericTextImp::numberOfProperties() const
217 {
218  return Parent::numberOfProperties() + 1;
219 }
220 
221 const QByteArrayList NumericTextImp::propertiesInternalNames() const
222 {
223  QByteArrayList ret = Parent::propertiesInternalNames();
224  ret << "kig_value";
225  return ret;
226 }
227 
228 const QByteArrayList NumericTextImp::properties() const
229 {
230  QByteArrayList ret = Parent::properties();
231  ret << I18N_NOOP( "Numeric value" );
232  return ret;
233 }
234 
235 const ObjectImpType* NumericTextImp::impRequirementForProperty( int which ) const
236 {
237  if ( which < Parent::numberOfProperties() )
238  return Parent::impRequirementForProperty( which );
239  return NumericTextImp::stype();
240 }
241 
242 const char* NumericTextImp::iconForProperty( int which ) const
243 {
244  if ( which < Parent::numberOfProperties() )
245  return Parent::iconForProperty( which );
246  else if ( which == Parent::numberOfProperties() )
247  return "value"; // text
248  else assert( false );
249  return "";
250 }
251 
252 ObjectImp* NumericTextImp::property( int which, const KigDocument& w ) const
253 {
254  if ( which < Parent::numberOfProperties() )
255  return Parent::property( which, w );
256  else if ( which == Parent::numberOfProperties() )
257  return new DoubleImp( getValue() );
258  else assert( false );
259  return new InvalidImp;
260 }
261 
262 bool NumericTextImp::isPropertyDefinedOnOrThroughThisImp( int which ) const
263 {
264  return Parent::isPropertyDefinedOnOrThroughThisImp( which );
265 }
266 
267 /*
268  * BoolTextImp
269  */
270 
271 BoolTextImp::BoolTextImp( const QString& text, const Coordinate& loc, bool frame, bool value )
272  : TextImp( text, loc, frame ), mvalue( value )
273 {
274 }
275 
276 BoolTextImp* BoolTextImp::copy() const
277 {
278  return new BoolTextImp( text(), coordinate(), hasFrame(), mvalue );
279 }
280 
281 const ObjectImpType* BoolTextImp::stype()
282 {
283  static const ObjectImpType t(
284  Parent::stype(), "boolean-label",
285  I18N_NOOP( "boolean label" ),
286  I18N_NOOP( "Select this boolean label" ),
287  I18N_NOOP( "Select boolean label %1" ),
288  I18N_NOOP( "Remove a Boolean Label" ),
289  I18N_NOOP( "Add a Boolean Label" ),
290  I18N_NOOP( "Move a Boolean Label" ),
291  I18N_NOOP( "Attach to this boolean label" ),
292  I18N_NOOP( "Show a Boolean Label" ),
293  I18N_NOOP( "Hide a Boolean Label" )
294  );
295  return &t;
296 }
297 
298 const ObjectImpType* BoolTextImp::type() const
299 {
300  return BoolTextImp::stype();
301 }
302 
303 bool BoolTextImp::getValue( void ) const
304 {
305  return mvalue;
306 }
307 
308 int BoolTextImp::numberOfProperties() const
309 {
310  return Parent::numberOfProperties() + 1;
311 }
312 
313 const QByteArrayList BoolTextImp::propertiesInternalNames() const
314 {
315  QByteArrayList ret = Parent::propertiesInternalNames();
316  ret << "kig_value";
317  return ret;
318 }
319 
320 const QByteArrayList BoolTextImp::properties() const
321 {
322  QByteArrayList ret = Parent::properties();
323  ret << I18N_NOOP( "Numeric value" );
324  return ret;
325 }
326 
327 const ObjectImpType* BoolTextImp::impRequirementForProperty( int which ) const
328 {
329  if ( which < Parent::numberOfProperties() )
330  return Parent::impRequirementForProperty( which );
331  return NumericTextImp::stype();
332 }
333 
334 const char* BoolTextImp::iconForProperty( int which ) const
335 {
336  if ( which < Parent::numberOfProperties() )
337  return Parent::iconForProperty( which );
338  else if ( which == Parent::numberOfProperties() )
339  return "value"; // text
340  else assert( false );
341  return "";
342 }
343 
344 ObjectImp* BoolTextImp::property( int which, const KigDocument& w ) const
345 {
346  if ( which < Parent::numberOfProperties() )
347  return Parent::property( which, w );
348  else if ( which == Parent::numberOfProperties() )
349  return new DoubleImp( getValue() );
350  else assert( false );
351  return new InvalidImp;
352 }
353 
354 bool BoolTextImp::isPropertyDefinedOnOrThroughThisImp( int which ) const
355 {
356  return Parent::isPropertyDefinedOnOrThroughThisImp( which );
357 }
TextImp::surroundingRect
Rect surroundingRect() const
Definition: text_imp.cc:170
ObjectImpType
Instances of this class represent a certain ObjectImp type.
Definition: object_imp.h:95
BoolTextImp::iconForProperty
const char * iconForProperty(int which) const
Definition: text_imp.cc:334
ObjectImp::inherits
bool inherits(const ObjectImpType *t) const
Returns true if this ObjectImp inherits the ObjectImp type represented by t.
Definition: object_imp.cc:279
NumericTextImp::isPropertyDefinedOnOrThroughThisImp
bool isPropertyDefinedOnOrThroughThisImp(int which) const
Definition: text_imp.cc:262
TextImp::contains
bool contains(const Coordinate &p, int width, const KigWidget &) const
Definition: text_imp.cc:54
NumericTextImp::getValue
double getValue() const
Definition: text_imp.cc:211
TextImp::impRequirementForProperty
const ObjectImpType * impRequirementForProperty(int which) const
Definition: text_imp.cc:88
TextImp::iconForProperty
const char * iconForProperty(int which) const
Definition: text_imp.cc:95
TextImp::coordinate
const Coordinate coordinate() const
Definition: text_imp.cc:125
StringImp
This ObjectImp is a BogusImp containing only a string value.
Definition: bogus_imp.h:167
NumericTextImp::impRequirementForProperty
const ObjectImpType * impRequirementForProperty(int which) const
Definition: text_imp.cc:235
text_imp.h
ObjectImpVisitor::visit
void visit(const ObjectImp *imp)
Definition: object_imp.cc:81
ObjectImp::impRequirementForProperty
virtual const ObjectImpType * impRequirementForProperty(int which) const
Definition: object_imp.cc:76
TextImp
Definition: text_imp.h:26
ObjectImp::property
virtual ObjectImp * property(int which, const KigDocument &d) const
Definition: object_imp.cc:70
Rect
This file is part of Kig, a KDE program for Interactive Geometry...
Definition: rect.h:34
TextImp::attachPoint
Coordinate attachPoint() const
Returns a reference point where to attach labels; when this returns an invalidCoord then the attachme...
Definition: text_imp.cc:37
TextImp::transform
ObjectImp * transform(const Transformation &) const
Return this ObjectImp, transformed by the transformation t.
Definition: text_imp.cc:42
NumericTextImp
Definition: text_imp.h:70
TextImp::numberOfProperties
int numberOfProperties() const
Definition: text_imp.cc:69
ObjectImp::propertiesInternalNames
virtual const QByteArrayList propertiesInternalNames() const
Definition: object_imp.cc:63
ObjectImp::stype
static const ObjectImpType * stype()
The ObjectImpType representing the base ObjectImp class.
Definition: object_imp.cc:284
Rect::intersects
bool intersects(const Rect &p) const
Definition: rect.cc:230
Coordinate
The Coordinate class is the basic class representing a 2D location by its x and y components...
Definition: coordinate.h:33
TextImp::equals
bool equals(const ObjectImp &rhs) const
Returns true if this ObjectImp is equal to rhs.
Definition: text_imp.cc:130
TextImp::copy
TextImp * copy() const
Returns a copy of this ObjectImp.
Definition: text_imp.cc:28
BoolTextImp::numberOfProperties
int numberOfProperties() const
Definition: text_imp.cc:308
BoolTextImp::propertiesInternalNames
const QByteArrayList propertiesInternalNames() const
Definition: text_imp.cc:313
TextImp::draw
void draw(KigPainter &p) const
Definition: text_imp.cc:48
ObjectImp::iconForProperty
virtual const char * iconForProperty(int which) const
Definition: object_imp.cc:187
Rect::contains
bool contains(const Coordinate &p) const
Definition: rect.cc:222
NumericTextImp::numberOfProperties
int numberOfProperties() const
Definition: text_imp.cc:216
BoolTextImp::properties
const QByteArrayList properties() const
Definition: text_imp.cc:320
TextImp::text
QString text() const
Definition: text_imp.cc:115
KigPainter
KigPainter is an extended QPainter.
Definition: kigpainter.h:51
NumericTextImp::properties
const QByteArrayList properties() const
Definition: text_imp.cc:228
bogus_imp.h
BoolTextImp
Definition: text_imp.h:91
Transformation
Class representing a transformation.
Definition: kigtransform.h:37
NumericTextImp::iconForProperty
const char * iconForProperty(int which) const
Definition: text_imp.cc:242
TextImp::visit
void visit(ObjectImpVisitor *vtor) const
Definition: text_imp.cc:120
KigPainter::drawTextFrame
void drawTextFrame(const Rect &frame, const QString &s, bool needframe)
Definition: kigpainter.cpp:933
KigWidget
This class is the real widget showing the document.
Definition: kig_view.h:50
BoolTextImp::impRequirementForProperty
const ObjectImpType * impRequirementForProperty(int which) const
Definition: text_imp.cc:327
NumericTextImp::NumericTextImp
NumericTextImp(const QString &text, const Coordinate &loc, bool frame, double value)
Definition: text_imp.cc:179
ObjectImp::isPropertyDefinedOnOrThroughThisImp
virtual bool isPropertyDefinedOnOrThroughThisImp(int which) const
Definition: object_imp.cc:326
TextImp::TextImp
TextImp(const QString &text, const Coordinate &loc, bool frame=false)
Definition: text_imp.cc:23
NumericTextImp::type
const ObjectImpType * type() const
Returns the lowermost ObjectImpType that this object is an instantiation of.
Definition: text_imp.cc:206
BoolTextImp::property
ObjectImp * property(int which, const KigDocument &w) const
Definition: text_imp.cc:344
BoolTextImp::BoolTextImp
BoolTextImp(const QString &text, const Coordinate &loc, bool frame, bool value)
Definition: text_imp.cc:271
KigPainter::simpleBoundingRect
const Rect simpleBoundingRect(const Coordinate &c, const QString &s)
Definition: kigpainter.cpp:573
NumericTextImp::property
ObjectImp * property(int which, const KigDocument &w) const
Definition: text_imp.cc:252
TextImp::propertiesInternalNames
const QByteArrayList propertiesInternalNames() const
Definition: text_imp.cc:74
Transformation::apply
const Coordinate apply(const double x0, const double x1, const double x2) const
Apply this Tranformation.
Definition: kigtransform.cpp:611
Coordinate::invalidCoord
static Coordinate invalidCoord()
Create an invalid Coordinate.
Definition: coordinate.cpp:171
TextImp::~TextImp
~TextImp()
Definition: text_imp.cc:33
TextImp::type
const ObjectImpType * type() const
Returns the lowermost ObjectImpType that this object is an instantiation of.
Definition: text_imp.cc:160
BoolTextImp::getValue
bool getValue() const
Definition: text_imp.cc:303
DoubleImp
This ObjectImp is a BogusImp containing only a double value.
Definition: bogus_imp.h:89
KigDocument
KigDocument is the class holding the real data in a Kig document.
Definition: kig_document.h:36
NumericTextImp::stype
static const ObjectImpType * stype()
Definition: text_imp.cc:189
QByteArrayList
QList< QByteArray > QByteArrayList
Definition: objects/common.h:50
BoolTextImp::isPropertyDefinedOnOrThroughThisImp
bool isPropertyDefinedOnOrThroughThisImp(int which) const
Definition: text_imp.cc:354
ObjectImp
The ObjectImp class represents the behaviour of an object after it is calculated. ...
Definition: object_imp.h:226
TextImp::valid
bool valid() const
Definition: text_imp.cc:64
TextImp::inRect
bool inRect(const Rect &r, int width, const KigWidget &) const
Definition: text_imp.cc:59
TextImp::properties
const QByteArrayList properties() const
Definition: text_imp.cc:81
TextImp::stype
static const ObjectImpType * stype()
Definition: text_imp.cc:143
NumericTextImp::copy
NumericTextImp * copy() const
Returns a copy of this ObjectImp.
Definition: text_imp.cc:184
TextImp::hasFrame
bool hasFrame() const
Definition: text_imp.cc:138
TextImp::isPropertyDefinedOnOrThroughThisImp
bool isPropertyDefinedOnOrThroughThisImp(int which) const
Definition: text_imp.cc:165
NumericTextImp::propertiesInternalNames
const QByteArrayList propertiesInternalNames() const
Definition: text_imp.cc:221
TextImp::property
ObjectImp * property(int which, const KigDocument &w) const
Definition: text_imp.cc:105
ObjectImp::numberOfProperties
virtual int numberOfProperties() const
Definition: object_imp.cc:58
BoolTextImp::stype
static const ObjectImpType * stype()
Definition: text_imp.cc:281
ObjectImpVisitor
Definition: object_imp.h:56
BoolTextImp::type
const ObjectImpType * type() const
Returns the lowermost ObjectImpType that this object is an instantiation of.
Definition: text_imp.cc:298
ObjectImp::properties
virtual const QByteArrayList properties() const
Definition: object_imp.cc:51
InvalidImp
This ObjectImp represents an invalid object.
Definition: bogus_imp.h:61
BoolTextImp::copy
BoolTextImp * copy() const
Returns a copy of this ObjectImp.
Definition: text_imp.cc:276
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kig

Skip menu "kig"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal