1 // SPDX-FileCopyrightText: 2003 Dominique Devriese <devriese@kde.org>
2 
3 // SPDX-License-Identifier: GPL-2.0-or-later
4 
5 #include "text_imp.h"
6 
7 #include "bogus_imp.h"
8 #include "../misc/kigpainter.h"
9 
TextImp(const QString & text,const Coordinate & loc,bool frame)10 TextImp::TextImp( const QString& text, const Coordinate& loc, bool frame )
11   : mtext( text), mloc( loc ), mframe( frame ), mboundrect( Rect::invalidRect() )
12 {
13 }
14 
copy() const15 TextImp* TextImp::copy() const
16 {
17   return new TextImp( mtext, mloc );
18 }
19 
~TextImp()20 TextImp::~TextImp()
21 {
22 }
23 
attachPoint() const24 Coordinate TextImp::attachPoint() const
25 {
26   return Coordinate::invalidCoord();
27 }
28 
transform(const Transformation & t) const29 ObjectImp* TextImp::transform( const Transformation& t ) const
30 {
31   Coordinate nloc = t.apply( mloc );
32   return new TextImp( mtext, nloc, mframe );
33 }
34 
draw(KigPainter & p) const35 void TextImp::draw( KigPainter& p ) const
36 {
37   mboundrect = p.simpleBoundingRect( mloc, mtext );
38   p.drawTextFrame( mboundrect, mtext, mframe );
39 }
40 
contains(const Coordinate & p,int,const KigWidget &) const41 bool TextImp::contains( const Coordinate& p, int, const KigWidget& ) const
42 {
43   return mboundrect.contains( p );
44 }
45 
inRect(const Rect & r,int,const KigWidget &) const46 bool TextImp::inRect( const Rect& r, int, const KigWidget& ) const
47 {
48   return mboundrect.intersects( r );
49 }
50 
valid() const51 bool TextImp::valid() const
52 {
53   return true;
54 }
55 
numberOfProperties() const56 int TextImp::numberOfProperties() const
57 {
58   return Parent::numberOfProperties() + 1;
59 }
60 
propertiesInternalNames() const61 const QByteArrayList TextImp::propertiesInternalNames() const
62 {
63   QByteArrayList ret = Parent::propertiesInternalNames();
64   ret << "kig_text";
65   return ret;
66 }
67 
properties() const68 const QByteArrayList TextImp::properties() const
69 {
70   QByteArrayList ret = Parent::properties();
71   ret << I18N_NOOP( "Text" );
72   return ret;
73 }
74 
impRequirementForProperty(int which) const75 const ObjectImpType* TextImp::impRequirementForProperty( int which ) const
76 {
77   if ( which < Parent::numberOfProperties() )
78     return Parent::impRequirementForProperty( which );
79   return TextImp::stype();
80 }
81 
iconForProperty(int which) const82 const char* TextImp::iconForProperty( int which ) const
83 {
84   if ( which < Parent::numberOfProperties() )
85     return Parent::iconForProperty( which );
86   else if ( which == Parent::numberOfProperties() )
87     return "draw-text"; // text
88   else assert( false );
89   return "";
90 }
91 
property(int which,const KigDocument & w) const92 ObjectImp* TextImp::property( int which, const KigDocument& w ) const
93 {
94   if ( which < Parent::numberOfProperties() )
95     return Parent::property( which, w );
96   else if ( which == Parent::numberOfProperties() )
97     return new StringImp( text() );
98   else assert( false );
99   return new InvalidImp;
100 }
101 
text() const102 QString TextImp::text() const
103 {
104   return mtext;
105 }
106 
visit(ObjectImpVisitor * vtor) const107 void TextImp::visit( ObjectImpVisitor* vtor ) const
108 {
109   vtor->visit( this );
110 }
111 
coordinate() const112 const Coordinate TextImp::coordinate() const
113 {
114   return mloc;
115 }
116 
equals(const ObjectImp & rhs) const117 bool TextImp::equals( const ObjectImp& rhs ) const
118 {
119   return rhs.inherits( TextImp::stype() ) &&
120     static_cast<const TextImp&>( rhs ).coordinate() == coordinate() &&
121     static_cast<const TextImp&>( rhs ).text() == text() &&
122     static_cast<const TextImp&>( rhs ).hasFrame() == hasFrame();
123 }
124 
hasFrame() const125 bool TextImp::hasFrame() const
126 {
127   return mframe;
128 }
129 
stype()130 const ObjectImpType* TextImp::stype()
131 {
132   static const ObjectImpType t(
133     Parent::stype(), "label",
134     I18N_NOOP( "label" ),
135     I18N_NOOP( "Select this label" ),
136     I18N_NOOP( "Select label %1" ),
137     I18N_NOOP( "Remove a Label" ),
138     I18N_NOOP( "Add a Label" ),
139     I18N_NOOP( "Move a Label" ),
140     I18N_NOOP( "Attach to this label" ),
141     I18N_NOOP( "Show a Label" ),
142     I18N_NOOP( "Hide a Label" )
143     );
144   return &t;
145 }
146 
type() const147 const ObjectImpType* TextImp::type() const
148 {
149   return TextImp::stype();
150 }
151 
isPropertyDefinedOnOrThroughThisImp(int which) const152 bool TextImp::isPropertyDefinedOnOrThroughThisImp( int which ) const
153 {
154   return Parent::isPropertyDefinedOnOrThroughThisImp( which );
155 }
156 
surroundingRect() const157 Rect TextImp::surroundingRect() const
158 {
159   return mboundrect;
160 }
161 
162 /*
163  * NumericTextImp
164  */
165 
NumericTextImp(const QString & text,const Coordinate & loc,bool frame,double value)166 NumericTextImp::NumericTextImp( const QString& text, const Coordinate& loc, bool frame, double value )
167   : TextImp( text, loc, frame ), mvalue( value )
168 {
169 }
170 
copy() const171 NumericTextImp* NumericTextImp::copy() const
172 {
173   return new NumericTextImp( text(), coordinate(), hasFrame(), mvalue );
174 }
175 
stype()176 const ObjectImpType* NumericTextImp::stype()
177 {
178   static const ObjectImpType t(
179     Parent::stype(), "numeric-label",
180     I18N_NOOP( "numeric label" ),
181     I18N_NOOP( "Select this numeric label" ),
182     I18N_NOOP( "Select numeric label %1" ),
183     I18N_NOOP( "Remove a Numeric Label" ),
184     I18N_NOOP( "Add a Numeric Label" ),
185     I18N_NOOP( "Move a Numeric Label" ),
186     I18N_NOOP( "Attach to this numeric label" ),
187     I18N_NOOP( "Show a Numeric Label" ),
188     I18N_NOOP( "Hide a Numeric Label" )
189     );
190   return &t;
191 }
192 
type() const193 const ObjectImpType* NumericTextImp::type() const
194 {
195   return NumericTextImp::stype();
196 }
197 
getValue(void) const198 double NumericTextImp::getValue( void ) const
199 {
200   return mvalue;
201 }
202 
numberOfProperties() const203 int NumericTextImp::numberOfProperties() const
204 {
205   return Parent::numberOfProperties() + 1;
206 }
207 
propertiesInternalNames() const208 const QByteArrayList NumericTextImp::propertiesInternalNames() const
209 {
210   QByteArrayList ret = Parent::propertiesInternalNames();
211   ret << "kig_value";
212   return ret;
213 }
214 
properties() const215 const QByteArrayList NumericTextImp::properties() const
216 {
217   QByteArrayList ret = Parent::properties();
218   ret << I18N_NOOP( "Numeric value" );
219   return ret;
220 }
221 
impRequirementForProperty(int which) const222 const ObjectImpType* NumericTextImp::impRequirementForProperty( int which ) const
223 {
224   if ( which < Parent::numberOfProperties() )
225     return Parent::impRequirementForProperty( which );
226   return NumericTextImp::stype();
227 }
228 
iconForProperty(int which) const229 const char* NumericTextImp::iconForProperty( int which ) const
230 {
231   if ( which < Parent::numberOfProperties() )
232     return Parent::iconForProperty( which );
233   else if ( which == Parent::numberOfProperties() )
234     return "value"; // text
235   else assert( false );
236   return "";
237 }
238 
property(int which,const KigDocument & w) const239 ObjectImp* NumericTextImp::property( int which, const KigDocument& w ) const
240 {
241   if ( which < Parent::numberOfProperties() )
242     return Parent::property( which, w );
243   else if ( which == Parent::numberOfProperties() )
244     return new DoubleImp( getValue() );
245   else assert( false );
246   return new InvalidImp;
247 }
248 
isPropertyDefinedOnOrThroughThisImp(int which) const249 bool NumericTextImp::isPropertyDefinedOnOrThroughThisImp( int which ) const
250 {
251   return Parent::isPropertyDefinedOnOrThroughThisImp( which );
252 }
253 
254 /*
255  * BoolTextImp
256  */
257 
BoolTextImp(const QString & text,const Coordinate & loc,bool frame,bool value)258 BoolTextImp::BoolTextImp( const QString& text, const Coordinate& loc, bool frame, bool value )
259   : TextImp( text, loc, frame ), mvalue( value )
260 {
261 }
262 
copy() const263 BoolTextImp* BoolTextImp::copy() const
264 {
265   return new BoolTextImp( text(), coordinate(), hasFrame(), mvalue );
266 }
267 
stype()268 const ObjectImpType* BoolTextImp::stype()
269 {
270   static const ObjectImpType t(
271     Parent::stype(), "boolean-label",
272     I18N_NOOP( "boolean label" ),
273     I18N_NOOP( "Select this boolean label" ),
274     I18N_NOOP( "Select boolean label %1" ),
275     I18N_NOOP( "Remove a Boolean Label" ),
276     I18N_NOOP( "Add a Boolean Label" ),
277     I18N_NOOP( "Move a Boolean Label" ),
278     I18N_NOOP( "Attach to this boolean label" ),
279     I18N_NOOP( "Show a Boolean Label" ),
280     I18N_NOOP( "Hide a Boolean Label" )
281     );
282   return &t;
283 }
284 
type() const285 const ObjectImpType* BoolTextImp::type() const
286 {
287   return BoolTextImp::stype();
288 }
289 
getValue(void) const290 bool BoolTextImp::getValue( void ) const
291 {
292   return mvalue;
293 }
294 
numberOfProperties() const295 int BoolTextImp::numberOfProperties() const
296 {
297   return Parent::numberOfProperties() + 1;
298 }
299 
propertiesInternalNames() const300 const QByteArrayList BoolTextImp::propertiesInternalNames() const
301 {
302   QByteArrayList ret = Parent::propertiesInternalNames();
303   ret << "kig_value";
304   return ret;
305 }
306 
properties() const307 const QByteArrayList BoolTextImp::properties() const
308 {
309   QByteArrayList ret = Parent::properties();
310   ret << I18N_NOOP( "Numeric value" );
311   return ret;
312 }
313 
impRequirementForProperty(int which) const314 const ObjectImpType* BoolTextImp::impRequirementForProperty( int which ) const
315 {
316   if ( which < Parent::numberOfProperties() )
317     return Parent::impRequirementForProperty( which );
318   return NumericTextImp::stype();
319 }
320 
iconForProperty(int which) const321 const char* BoolTextImp::iconForProperty( int which ) const
322 {
323   if ( which < Parent::numberOfProperties() )
324     return Parent::iconForProperty( which );
325   else if ( which == Parent::numberOfProperties() )
326     return "value"; // text
327   else assert( false );
328   return "";
329 }
330 
property(int which,const KigDocument & w) const331 ObjectImp* BoolTextImp::property( int which, const KigDocument& w ) const
332 {
333   if ( which < Parent::numberOfProperties() )
334     return Parent::property( which, w );
335   else if ( which == Parent::numberOfProperties() )
336     return new DoubleImp( getValue() );
337   else assert( false );
338   return new InvalidImp;
339 }
340 
isPropertyDefinedOnOrThroughThisImp(int which) const341 bool BoolTextImp::isPropertyDefinedOnOrThroughThisImp( int which ) const
342 {
343   return Parent::isPropertyDefinedOnOrThroughThisImp( which );
344 }
345