filters

objects.cpp

00001 /* libppt - library to read PowerPoint presentation
00002    Copyright (C) 2005 Yolla Indria <yolla.indria@gmail.com>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008    
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA
00018 */
00019 
00020 #include "objects.h"
00021 #include "ustring.h"
00022 
00023 #include <string>
00024 #include <map>
00025 #include <vector>
00026 #include <iostream>
00027 
00028 using namespace Libppt;
00029 
00030 class PropertyValue
00031 {
00032 public:
00033   enum { InvalidType,  IntType, DoubleType, StringType, BoolType, ColorType } type;
00034   bool b;
00035   int i;
00036   double d; 
00037   std::string s;
00038   Color c;
00039 
00040   PropertyValue()
00041   {
00042     type = InvalidType;
00043     b = false;
00044     i = 0;
00045     d = 0.0;
00046      
00047     
00048   }
00049 };
00050 
00051 class Object::Private
00052 {
00053 public:
00054   int id;
00055   double top;
00056   double left;
00057   double width;
00058   double height;
00059   bool background;
00060   std::map<std::string,PropertyValue> properties;
00061 };
00062 
00063 Object::Object()
00064 {
00065   d = new Private;
00066   d->id = -1;
00067   d->top = 0.0;
00068   d->left = 0.0;
00069   d->width = 10.0;
00070   d->height = 3.0;
00071   d->background = false;
00072 }
00073 
00074 Object::~Object()
00075 {
00076   delete d;
00077 }
00078 
00079 int Object::id() const
00080 {
00081   return d->id;
00082 }
00083 
00084 void Object::setId( int id )
00085 {
00086   d->id = id;
00087 }
00088 
00089 double Object::top() const
00090 {
00091   return d->top;
00092 }
00093 
00094 double Object::left() const
00095 {
00096   return d->left;
00097 }
00098 
00099 double Object::width() const
00100 {
00101   return d->width;
00102 }
00103 
00104 double Object::height() const
00105 {
00106   return d->height;
00107 }
00108 
00109 void Object::setTop( double top )
00110 {
00111   d->top = top;
00112 }
00113 
00114 void Object::setLeft( double left )
00115 {
00116   d->left = left;
00117 }
00118 
00119 void Object::setWidth( double width )
00120 {
00121   d->width = width;
00122 }
00123 
00124 void Object::setHeight( double height)
00125 {
00126   d->height = height;
00127 }
00128 
00129 bool Object::isBackground() const
00130 {
00131   return d->background;
00132 }
00133 
00134 void Object::setBackground( bool bg )
00135 {
00136   d->background = bg;
00137 }
00138 
00139 bool Object::hasProperty( std::string name )
00140 {
00141   std::map<std::string,PropertyValue>::const_iterator i;
00142   i = d->properties.find( name );
00143   if( i ==  d->properties.end() )
00144     return false;
00145   else
00146     return true;
00147 }
00148 
00149 void Object::setProperty( std::string name, std::string value )
00150 {
00151   PropertyValue pv;
00152   pv.type = PropertyValue::StringType;
00153   pv.s = value;
00154   d->properties[ name ] = pv;
00155 }
00156 
00157 void Object::setProperty( std::string name, int value )
00158  {
00159   PropertyValue pv;
00160   pv.type = PropertyValue::IntType;
00161   pv.i = value;
00162   d->properties[ name ] = pv;
00163 }
00164 
00165 void Object::setProperty( std::string name, double value )
00166 {
00167   PropertyValue pv;
00168   pv.type = PropertyValue::DoubleType;
00169   pv.d = value;
00170   d->properties[ name ] = pv;
00171 }
00172 
00173 void Object::setProperty( std::string name, bool value )
00174 {
00175   PropertyValue pv;
00176   pv.type = PropertyValue::BoolType;
00177   pv.b = value;
00178   d->properties[ name ] = pv;
00179 }
00180 
00181 void Object::setProperty( std::string name, Color value )
00182 {
00183   PropertyValue pv;
00184   pv.type = PropertyValue::ColorType;
00185   pv.c = value;
00186   d->properties[ name ] = pv;
00187 }
00188 
00189 int Object::getIntProperty( std::string name )
00190 {
00191   PropertyValue pv;
00192   pv = d->properties[ name ];
00193   if( pv.type == PropertyValue::IntType )
00194     return pv.i;
00195   else
00196     return 0;
00197 }
00198 
00199 double Object::getDoubleProperty( std::string name )
00200 {
00201   PropertyValue pv;
00202   pv = d->properties[ name ];
00203   if( pv.type == PropertyValue::DoubleType )
00204     return pv.d;
00205   else
00206     return 0;
00207 }
00208 
00209 bool Object::getBoolProperty( std::string name )
00210 {
00211   PropertyValue pv;
00212   pv = d->properties[ name ];
00213   if( pv.type == PropertyValue::BoolType )
00214     return pv.b;
00215   else
00216     return false;
00217 
00218 }
00219 
00220 std::string Object::getStrProperty( std::string name )
00221 {
00222   PropertyValue pv;
00223   pv = d->properties[ name ];
00224   if( pv.type == PropertyValue::StringType )
00225     return pv.s;
00226   else
00227     return "NoString";  
00228 }
00229 
00230 Color Object::getColorProperty(std::string name)
00231 {
00232   PropertyValue pv;
00233   pv = d->properties[ name ];
00234   if( pv.type == PropertyValue::ColorType )
00235     return pv.c;
00236   else 
00237     return Color(153,204,255); // #99ccff
00238  
00239 } 
00240 
00241 class TextObject::Private
00242 {
00243 public:
00244   unsigned type;
00245   std::vector<UString> text;  
00246   unsigned listSize; 
00247   std::vector<bool> bulletFlag; 
00248 };
00249 
00250 TextObject::TextObject(): Object()
00251 {
00252   d = new Private;
00253 }
00254 
00255 TextObject::~TextObject()
00256 {
00257   delete d;
00258 }
00259 
00260 unsigned TextObject::type() const
00261 {
00262   return d->type;
00263 }
00264 
00265 unsigned TextObject::listSize() const
00266 {
00267   return d->text.size();
00268 }
00269 
00270 const char* TextObject::typeAsString() const
00271 {
00272   switch( d->type )
00273   {
00274     case  Title       : return "Title";
00275     case  Body        : return "Body";
00276     case  Notes       : return "Notes";
00277     case  NotUsed     : return "NotUsed";
00278     case  Other       : return "Other";
00279     case  CenterBody  : return "CenterBody";
00280     case  CenterTitle : return "CenterTitle";
00281     case  HalfBody    : return "HalfBody";
00282     case  QuarterBody : return "QuarterBody";
00283     default: break;
00284   }
00285 
00286   return "Unknown";
00287 }
00288 
00289 bool TextObject::bulletFlag( unsigned index ) const
00290 {
00291   return d->bulletFlag[index];
00292 }
00293 
00294 void TextObject::setBulletFlag( bool flag )
00295 {
00296   d->bulletFlag.push_back( flag );
00297 }
00298 
00299 
00300 void TextObject::setType( unsigned type )
00301 {
00302   d->type = type;
00303 }
00304 
00305 UString TextObject::text( unsigned index) const
00306 {
00307   return d->text[index];
00308 }
00309 
00310 void TextObject::setText( const UString& text )
00311 {
00312   d->text.push_back( text );
00313 }
00314 
00315 void TextObject::convertFrom( Object* object )
00316 {
00317   setId( object->id() );
00318   setLeft( object->left() );
00319   setTop( object->top() );
00320   setWidth( object->width() );
00321   setHeight( object->height() );
00322 
00323   if( object->isText() )
00324   {
00325     TextObject* textObj = static_cast<TextObject*>( object );
00326     setType( textObj->type() );
00327   // jgn lupa diganti :  setText( textObj->text() );
00328   }
00329 }
00330 
00331 class GroupObject::Private
00332 {
00333 public:
00334   std::vector<Object*> objects;
00335 };
00336 
00337 GroupObject::GroupObject()
00338 {
00339   d = new Private;
00340 }
00341 
00342 GroupObject::~GroupObject()
00343 {
00344   for( unsigned i=0; i<d->objects.size(); i++ )
00345     delete d->objects[i];
00346   delete d;
00347 }
00348 
00349 unsigned GroupObject::objectCount() const
00350 {
00351   return d->objects.size();
00352 }
00353 
00354 Object* GroupObject::object( unsigned i )
00355 {
00356   return d->objects[i];
00357 }
00358 
00359 void GroupObject::addObject( Object* object )
00360 {
00361   d->objects.push_back( object );
00362 }
00363 
00364 void GroupObject::takeObject( Object* object )
00365 {
00366   std::vector<Object*> result;
00367   for( unsigned i=0; i<d->objects.size(); i++ )
00368   {
00369     Object* obj = d->objects[i];
00370     if( obj != object ) 
00371       result.push_back( obj );
00372   }
00373 
00374   d->objects.clear();
00375   for( unsigned j=0; j<result.size(); j++ )
00376     d->objects.push_back( result[j] );
00377 }
00378 
00379 class DrawObject::Private
00380 {
00381 public:
00382   unsigned shape;
00383   bool isVerFlip; 
00384   bool isHorFlip;
00385 };
00386 
00387 DrawObject::DrawObject()
00388 {
00389   d = new Private;
00390   d->shape = None;
00391 }
00392 
00393 DrawObject::~DrawObject()
00394 {
00395   delete d;
00396 }
00397 
00398 unsigned DrawObject::shape() const
00399 {
00400   return d->shape;
00401 }
00402 
00403 void DrawObject::setShape( unsigned s )
00404 {
00405   d->shape = s;
00406 }
00407 
00408 bool DrawObject::isVerFlip() const
00409 {
00410   return d->isVerFlip;
00411 }
00412 
00413 void DrawObject::setVerFlip( bool isVerFlip )
00414 {
00415   d->isVerFlip = isVerFlip;
00416 }
00417 
00418 bool DrawObject::isHorFlip() const
00419 {
00420   return d->isHorFlip;
00421 }
00422 
00423 void DrawObject::setHorFlip( bool isHorFlip )
00424 {
00425   d->isHorFlip = isHorFlip;
00426 }
KDE Home | KDE Accessibility Home | Description of Access Keys