floatimageobj.cpp
author insilmaril
Wed, 01 Mar 2006 14:39:04 +0000
changeset 225 d5c70aaca22d
parent 218 160459d924a1
child 241 f5243654fe86
permissions -rw-r--r--
1.7.10 includeImagesHorizontally implemented
     1 #include "floatimageobj.h"
     2 #include "branchobj.h"
     3 
     4 
     5 /////////////////////////////////////////////////////////////////
     6 // FloatImageObj
     7 /////////////////////////////////////////////////////////////////
     8 
     9 uint FloatImageObj::saveCounter=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 	clickBox.setSize (QSize(icon->size().width(), icon->size().height()));
    47 	filename="";
    48 	originalFilename="no original name available";
    49 	filetype="";
    50 	saveInMap=true;
    51 	useRelPos=true;
    52 }
    53 
    54 void FloatImageObj::copy (FloatImageObj* other)
    55 {					
    56 	FloatObj::copy (other);
    57 	icon->copy (other->icon);
    58 	filetype=other->filetype;
    59 	filename=other->filename;
    60 	originalFilename=other->originalFilename;
    61 	saveInMap=other->saveInMap;
    62     positionBBox();
    63 }
    64 
    65 void FloatImageObj::setZ (const int &i)
    66 {
    67 	icon->setZ (i);
    68 	zPlane=i;
    69 }
    70 
    71 int FloatImageObj::z ()
    72 {
    73 	return qRound (icon->z());
    74 }
    75 
    76 void FloatImageObj::load (const QPixmap &pixmap)
    77 {
    78   icon->load(pixmap);
    79   bbox.setSize (QSize(icon->size().width()+8, icon->size().height()+8));
    80   clickBox.setSize (QSize(icon->size().width()+8, icon->size().height()+8));
    81   positionBBox();
    82   filetype="PNG";
    83   filename="noname.png";
    84 }
    85 
    86 bool FloatImageObj::load (const QString &fn)
    87 {	
    88 	if( icon->load (fn))
    89 	{
    90 		bbox.setSize (QSize(icon->size().width()+8, icon->size().height()+8));
    91 		positionBBox();
    92 		filename=fn;
    93 		filetype=QPixmap::imageFormat (fn);
    94 		return true;
    95 	} else
    96 		return false;
    97 	
    98 }
    99 
   100 void FloatImageObj::save (const QString &fn, const char *format)
   101 {	
   102 	icon->save (fn,format);
   103 }
   104 
   105 void FloatImageObj::setOriginalFilename(const QString & fn)
   106 {
   107 	originalFilename=fn;
   108 }
   109 
   110 QString FloatImageObj::getOriginalFilename()
   111 {
   112 	return originalFilename;
   113 }
   114 
   115 void FloatImageObj::setVisibility(bool v)
   116 {
   117     LinkableMapObj::setVisibility(v);
   118 	if (v)
   119 	    icon->setVisibility(true);
   120 	else
   121 	    icon->setVisibility(false);
   122 }
   123 
   124 void FloatImageObj::move (double x, double y)
   125 {
   126 	FloatObj::move(x,y);
   127 	icon->move (x+4,y+4);
   128     positionBBox();
   129 }
   130 
   131 void FloatImageObj::move (QPoint p)
   132 {
   133 	move (p.x(), p.y());
   134 }
   135 
   136 void FloatImageObj::positionBBox()
   137 {
   138 	clickBox=bbox;
   139 }
   140 
   141 void FloatImageObj::calcBBoxSize()
   142 {
   143 	// TODO
   144 }
   145 
   146 QString FloatImageObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPoint &p)
   147 {
   148 	saveCounter++;
   149 
   150 	QString posAttr=
   151 		attribut("relPosX",QString().setNum(relPos.x(),10)) +
   152 		attribut("relPosY",QString().setNum(relPos.y(),10)); 
   153 
   154 	QString linkAttr=getLinkAttr();
   155 	
   156 	QString useOrientAttr;
   157 	if (useOrientation)
   158 		useOrientAttr=attribut ("useOrientation","true");
   159 	else	
   160 		useOrientAttr=attribut ("useOrientation","false");
   161 		
   162 	QString saveInMapAttr;
   163 	if (saveInMap)
   164 		saveInMapAttr=attribut ("saveInMap","true");
   165 	else	
   166 		
   167 		saveInMapAttr=attribut ("saveInMap","false");
   168 
   169 	QString exportAttr;
   170 	if (floatExport)
   171 		exportAttr=attribut ("floatExport","true");
   172 	else	
   173 		exportAttr=attribut ("floatExport","false");
   174 
   175 	QString zAttr=attribut ("zPlane",QString().setNum(zPlane));
   176 	QString url;
   177 
   178 	// prevent saving as GIF
   179 	if (filetype=="GIF")
   180 		filetype="PNG";
   181 		
   182 	url="images/"+prefix+"image-" + QString().number(saveCounter,10) + "." +filetype;
   183 
   184 	// And really save the image
   185 	icon->save (tmpdir + "/" + url, filetype);
   186 
   187     return singleElement ("floatimage",  
   188 		posAttr + 
   189 		linkAttr +
   190 		useOrientAttr + 
   191 		saveInMapAttr + 
   192 		exportAttr + 
   193 		zAttr + 
   194 		attribut ("href",QString ("file:")+url)
   195 	);	
   196 }
   197 
   198 void FloatImageObj::resetSaveCounter()
   199 {
   200 	saveCounter=0;
   201 }
   202 
   203 
   204 QRect FloatImageObj::getTotalBBox()
   205 {
   206 	return bbox;
   207 }
   208 
   209 QRect FloatImageObj::getBBoxSizeWithChilds()
   210 {
   211 	//FIXME  abstract in linkablemapobj.h, not calculated
   212 	return bboxTotal;
   213 }
   214 
   215 void FloatImageObj::calcBBoxSizeWithChilds()
   216 {
   217 	//FIXME  abstract in linkablemapobj.h
   218 }
   219 
   220 QString FloatImageObj::getSelectString()
   221 {
   222 	QString s;
   223 	if (parObj)
   224 	{
   225 		if (parObj->getDepth()==0)
   226 			s= "fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));
   227 		else	
   228 			s= ((BranchObj*)(parObj))->getSelectString() + ",fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));
   229 	} else
   230 		s="mc:";
   231 	
   232 	return s;
   233 
   234 }
   235