floatimageobj.cpp
author insilmaril
Mon Oct 06 12:28:25 2008 +0000 (2008-10-06)
branchrelease-1-12-maintained
changeset 51 b2224ebf331f
child 2 608f976aa7bb
child 104 270593ab83b2
permissions -rw-r--r--
added moligaloo to translators list
     1 #include "floatimageobj.h"
     2 #include "branchobj.h"
     3 #include <math.h>
     4 
     5 
     6 /////////////////////////////////////////////////////////////////
     7 // FloatImageObj
     8 /////////////////////////////////////////////////////////////////
     9 
    10 int FloatImageObj::counter=0;		// make instance 
    11 
    12 
    13 FloatImageObj::FloatImageObj ():FloatObj()
    14 {
    15 //    cout << "Const FloatImageObj ()\n";
    16     setParObj (this);	
    17     init();
    18     depth=-1;
    19 }
    20 
    21 FloatImageObj::FloatImageObj (QCanvas* c):FloatObj(c)
    22 {
    23  //   cout << "Const FloatImageObj (c)  called from MapCenterObj (c)\n";
    24     setParObj (this);	
    25     init();
    26     depth=-1;
    27 }
    28 
    29 FloatImageObj::FloatImageObj (QCanvas* c, LinkableMapObj* p):FloatObj(c,p)
    30 {
    31  //   cout << "Const FloatImageObj (c,p)\n";
    32     init();
    33 }
    34 
    35 FloatImageObj::~FloatImageObj ()
    36 {
    37 //	cout << "Destr FloatImageObj "<<this<<"\n";
    38 	delete(icon);
    39 }
    40 
    41 void FloatImageObj::init () 
    42 {
    43 	icon=new ImageObj (canvas);
    44 	icon->move (absPos.x(), absPos.y() );
    45 	icon->setVisibility (true);
    46 	bbox.setSize (QSize(icon->size().width(), icon->size().height()));
    47 	filename="";
    48 	originalFilename="no original name available";
    49 	filetype="";
    50 	saveInMap=true;
    51 }
    52 
    53 void FloatImageObj::copy (FloatImageObj* other)
    54 {					
    55 	FloatObj::copy (other);
    56 	icon->copy (other->icon);
    57 	filename=other->filename;
    58 	saveInMap=other->saveInMap;
    59     positionBBox();
    60 }
    61 
    62 void FloatImageObj::setZ (const int &i)
    63 {
    64 	icon->setZ (i);
    65 	zPlane=i;
    66 }
    67 
    68 int FloatImageObj::z ()
    69 {
    70 	return lrint (icon->z());
    71 }
    72 
    73 bool FloatImageObj::load (const QString &fn)
    74 {	
    75 	if( icon->load (fn))
    76 	{
    77 		bbox.setSize (QSize(icon->size().width()+8, icon->size().height()+8));
    78 		positionBBox();
    79 		filename=fn;
    80 		filetype=QPixmap::imageFormat (fn);
    81 		return true;
    82 	} else
    83 		return false;
    84 	
    85 }
    86 
    87 void FloatImageObj::save (const QString &fn, const char *format)
    88 {	
    89 	icon->save (fn,format);
    90 }
    91 
    92 void FloatImageObj::setOriginalFilename(const QString & fn)
    93 {
    94 	originalFilename=fn;
    95 }
    96 
    97 QString FloatImageObj::getOriginalFilename()
    98 {
    99 	return originalFilename;
   100 }
   101 
   102 void FloatImageObj::setVisibility(bool v)
   103 {
   104     LinkableMapObj::setVisibility(v);
   105 	if (v)
   106 	    icon->setVisibility(true);
   107 	else
   108 	    icon->setVisibility(false);
   109 }
   110 
   111 void FloatImageObj::move (double x, double y)
   112 {
   113 	FloatObj::move(x,y);
   114 	icon->move (x+4,y+4);
   115     positionBBox();
   116 }
   117 
   118 void FloatImageObj::move (QPoint p)
   119 {
   120 	move (p.x(), p.y());
   121 }
   122 
   123 void FloatImageObj::positionBBox()
   124 {
   125 	// TODO
   126 }
   127 
   128 void FloatImageObj::calcBBoxSize()
   129 {
   130 	// TODO
   131 }
   132 
   133 QString FloatImageObj::saveToDir (const QString &tmpdir,const QString &prefix)
   134 {
   135 	counter++;
   136 
   137 	QString posAttr=
   138 		attribut("relPosX",QString().setNum(relPos.x(),10)) +
   139 		attribut("relPosY",QString().setNum(relPos.y(),10)); 
   140 
   141 	QString useOrientAttr;
   142 	if (useOrientation)
   143 		useOrientAttr=attribut ("useOrientation","true");
   144 	else	
   145 		useOrientAttr=attribut ("useOrientation","false");
   146 		
   147 	QString saveInMapAttr;
   148 	if (saveInMap)
   149 		saveInMapAttr=attribut ("saveInMap","true");
   150 	else	
   151 		
   152 		saveInMapAttr=attribut ("saveInMap","false");
   153 
   154 	QString exportAttr;
   155 	if (floatExport)
   156 		exportAttr=attribut ("floatExport","true");
   157 	else	
   158 		exportAttr=attribut ("floatExport","false");
   159 
   160 	QString zAttr=attribut ("zPlane",QString().setNum(zPlane));
   161 	QString url;
   162 
   163 	// prevent saving as GIF
   164 	if (filetype=="GIF")
   165 		filetype="PNG";
   166 		
   167 	url="images/"+prefix+"image-" + QString().number(counter,10) + "." +filetype;
   168 
   169 	// And really save the image
   170 	icon->save (tmpdir + "/" + url, filetype);
   171 
   172     return singleElement ("floatimage",  
   173 		posAttr + 
   174 		useOrientAttr + 
   175 		saveInMapAttr + 
   176 		exportAttr + 
   177 		zAttr + 
   178 		attribut ("href",QString ("file:")+url)
   179 	);	
   180 }
   181 
   182 void FloatImageObj::resetSaveCounter()
   183 {
   184 	counter=0;
   185 }
   186 
   187 
   188 QRect FloatImageObj::getTotalBBox()
   189 {
   190 	return bbox;
   191 }
   192 
   193 QRect FloatImageObj::getBBoxSizeWithChilds()
   194 {
   195 	//FIXME  abstract in linkablemapobj.h, not calculated
   196 	return bboxTotal;
   197 }
   198 
   199 void FloatImageObj::calcBBoxSizeWithChilds()
   200 {
   201 	//FIXME  abstract in linkablemapobj.h
   202 }
   203 
   204 QString FloatImageObj::getSelectString()
   205 {
   206 	QString s;
   207 	if (parObj)
   208 	{
   209 		if (parObj->getDepth()==0)
   210 			s= "fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));
   211 		else	
   212 			s= ((BranchObj*)(parObj))->getSelectString() + ",fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));
   213 	} else
   214 		s="mc:";
   215 	
   216 	return s;
   217 
   218 }
   219