floatimageobj.cpp
author insilmaril
Fri, 08 Jul 2005 07:24:43 +0000
changeset 123 09edde7ae30e
parent 113 3b0b9352cf49
child 124 e0f6a21cc6d6
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 <<<<<<< floatimageobj.cpp
    70 	return qRound (icon->z());
    71 }
    72 
    73 void FloatImageObj::load (const QPixmap &pixmap)
    74 {
    75   icon->load(pixmap);
    76   bbox.setSize (QSize(icon->size().width()+8, icon->size().height()+8));
    77   positionBBox();
    78   filetype="PNG";
    79   filename="noname.png";
    80 =======
    81 	return qRound (icon->z());
    82 >>>>>>> 1.2
    83 }
    84 
    85 bool FloatImageObj::load (const QString &fn)
    86 {	
    87 	if( icon->load (fn))
    88 	{
    89 		bbox.setSize (QSize(icon->size().width()+8, icon->size().height()+8));
    90 		positionBBox();
    91 		filename=fn;
    92 		filetype=QPixmap::imageFormat (fn);
    93 		return true;
    94 	} else
    95 		return false;
    96 	
    97 }
    98 
    99 void FloatImageObj::save (const QString &fn, const char *format)
   100 {	
   101 	icon->save (fn,format);
   102 }
   103 
   104 void FloatImageObj::setOriginalFilename(const QString & fn)
   105 {
   106 	originalFilename=fn;
   107 }
   108 
   109 QString FloatImageObj::getOriginalFilename()
   110 {
   111 	return originalFilename;
   112 }
   113 
   114 void FloatImageObj::setVisibility(bool v)
   115 {
   116     LinkableMapObj::setVisibility(v);
   117 	if (v)
   118 	    icon->setVisibility(true);
   119 	else
   120 	    icon->setVisibility(false);
   121 }
   122 
   123 void FloatImageObj::move (double x, double y)
   124 {
   125 	FloatObj::move(x,y);
   126 	icon->move (x+4,y+4);
   127     positionBBox();
   128 }
   129 
   130 void FloatImageObj::move (QPoint p)
   131 {
   132 	move (p.x(), p.y());
   133 }
   134 
   135 void FloatImageObj::positionBBox()
   136 {
   137 	// TODO
   138 }
   139 
   140 void FloatImageObj::calcBBoxSize()
   141 {
   142 	// TODO
   143 }
   144 
   145 QString FloatImageObj::saveToDir (const QString &tmpdir,const QString &prefix)
   146 {
   147 	counter++;
   148 
   149 	QString posAttr=
   150 		attribut("relPosX",QString().setNum(relPos.x(),10)) +
   151 		attribut("relPosY",QString().setNum(relPos.y(),10)); 
   152 
   153 	QString useOrientAttr;
   154 	if (useOrientation)
   155 		useOrientAttr=attribut ("useOrientation","true");
   156 	else	
   157 		useOrientAttr=attribut ("useOrientation","false");
   158 		
   159 	QString saveInMapAttr;
   160 	if (saveInMap)
   161 		saveInMapAttr=attribut ("saveInMap","true");
   162 	else	
   163 		
   164 		saveInMapAttr=attribut ("saveInMap","false");
   165 
   166 	QString exportAttr;
   167 	if (floatExport)
   168 		exportAttr=attribut ("floatExport","true");
   169 	else	
   170 		exportAttr=attribut ("floatExport","false");
   171 
   172 	QString zAttr=attribut ("zPlane",QString().setNum(zPlane));
   173 	QString url;
   174 
   175 	// prevent saving as GIF
   176 	if (filetype=="GIF")
   177 		filetype="PNG";
   178 		
   179 	url="images/"+prefix+"image-" + QString().number(counter,10) + "." +filetype;
   180 
   181 	// And really save the image
   182 	icon->save (tmpdir + "/" + url, filetype);
   183 
   184     return singleElement ("floatimage",  
   185 		posAttr + 
   186 		useOrientAttr + 
   187 		saveInMapAttr + 
   188 		exportAttr + 
   189 		zAttr + 
   190 		attribut ("href",QString ("file:")+url)
   191 	);	
   192 }
   193 
   194 void FloatImageObj::resetSaveCounter()
   195 {
   196 	counter=0;
   197 }
   198 
   199 
   200 QRect FloatImageObj::getTotalBBox()
   201 {
   202 	return bbox;
   203 }
   204 
   205 QRect FloatImageObj::getBBoxSizeWithChilds()
   206 {
   207 	//FIXME  abstract in linkablemapobj.h, not calculated
   208 	return bboxTotal;
   209 }
   210 
   211 void FloatImageObj::calcBBoxSizeWithChilds()
   212 {
   213 	//FIXME  abstract in linkablemapobj.h
   214 }
   215 
   216 QString FloatImageObj::getSelectString()
   217 {
   218 	QString s;
   219 	if (parObj)
   220 	{
   221 		if (parObj->getDepth()==0)
   222 			s= "fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));
   223 		else	
   224 			s= ((BranchObj*)(parObj))->getSelectString() + ",fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));
   225 	} else
   226 		s="mc:";
   227 	
   228 	return s;
   229 
   230 }
   231