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