floatimageobj.cpp
author insilmaril
Mon, 15 May 2006 07:32:11 +0000
changeset 329 8f04006214dc
parent 312 d1d464798f08
child 334 df4fdaa07527
permissions -rw-r--r--
1.7.17
     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, OrnamentedObj* 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 	setZ (Z_FLOATIMG);
    46 	bbox.setSize (QSize(icon->size().width(), icon->size().height()));
    47 	clickBox.setSize (QSize(icon->size().width(), icon->size().height()));
    48 	filename="";
    49 	originalFilename="no original name available";
    50 	filetype="";
    51 	saveInMap=true;
    52 	useRelPos=true;
    53 
    54 	//Hide flags
    55 	systemFlags->setShowFlags(false);
    56 }
    57 
    58 void FloatImageObj::copy (FloatImageObj* other)
    59 {					
    60 	FloatObj::copy (other);
    61 	icon->copy (other->icon);
    62 	filetype=other->filetype;
    63 	filename=other->filename;
    64 	originalFilename=other->originalFilename;
    65 	saveInMap=other->saveInMap;
    66     positionBBox();
    67 }
    68 
    69 void FloatImageObj::setZ (const int &i)
    70 {
    71 	icon->setZ (i);
    72 	zPlane=i;
    73 }
    74 
    75 int FloatImageObj::z ()
    76 {
    77 	return qRound (icon->z());
    78 }
    79 
    80 void FloatImageObj::load (const QPixmap &pixmap)
    81 {
    82   icon->load(pixmap);
    83   bbox.setSize (QSize(icon->size().width()+8, icon->size().height()+8));
    84   clickBox.setSize (QSize(icon->size().width()+8, icon->size().height()+8));
    85   positionBBox();
    86   filetype="PNG";
    87   filename="noname.png";
    88 }
    89 
    90 bool FloatImageObj::load (const QString &fn)
    91 {	
    92 	if( icon->load (fn))
    93 	{
    94 		bbox.setSize (QSize(icon->size().width()+8, icon->size().height()+8));
    95 		positionBBox();
    96 		filename=fn;
    97 		filetype=QPixmap::imageFormat (fn);
    98 		return true;
    99 	} else
   100 		return false;
   101 	
   102 }
   103 
   104 void FloatImageObj::save (const QString &fn, const char *format)
   105 {	
   106 	icon->save (fn,format);
   107 }
   108 
   109 void FloatImageObj::setOriginalFilename(const QString & fn)
   110 {
   111 	originalFilename=fn;
   112 }
   113 
   114 QString FloatImageObj::getOriginalFilename()
   115 {
   116 	return originalFilename;
   117 }
   118 
   119 void FloatImageObj::setVisibility(bool v)
   120 {
   121     OrnamentedObj::setVisibility(v);
   122 	if (v)
   123 	    icon->setVisibility(true);
   124 	else
   125 	    icon->setVisibility(false);
   126 }
   127 
   128 void FloatImageObj::move (double x, double y)
   129 {
   130 	FloatObj::move(x,y);
   131 	icon->move (x+4,y+4);
   132     positionBBox();
   133 }
   134 
   135 void FloatImageObj::move (QPoint p)
   136 {
   137 	move (p.x(), p.y());
   138 }
   139 
   140 void FloatImageObj::positionBBox()
   141 {
   142 	clickBox=bbox;
   143 }
   144 
   145 void FloatImageObj::calcBBoxSize()
   146 {
   147 	// TODO
   148 }
   149 
   150 QString FloatImageObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPoint &p)
   151 {
   152 	if (hidden) return "";
   153 
   154 	saveCounter++;
   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 		getOrnAttr() 
   189 		+useOrientAttr 
   190 		+saveInMapAttr 
   191 		+exportAttr  
   192 		+zAttr  
   193 		+attribut ("href",QString ("file:")+url)
   194 	);	
   195 }
   196 
   197 void FloatImageObj::resetSaveCounter()
   198 {
   199 	saveCounter=0;
   200 }
   201 
   202 
   203 QRect FloatImageObj::getTotalBBox()
   204 {
   205 	return bbox;
   206 }
   207 
   208 QRect FloatImageObj::getBBoxSizeWithChilds()
   209 {
   210 	//FIXME  abstract in linkablemapobj.h, not calculated
   211 	return bboxTotal;
   212 }
   213 
   214 void FloatImageObj::calcBBoxSizeWithChilds()
   215 {
   216 	//FIXME  abstract in linkablemapobj.h
   217 }
   218 
   219 QString FloatImageObj::getSelectString()
   220 {
   221 	QString s;
   222 	if (parObj)
   223 	{
   224 		if (parObj->getDepth()==0)
   225 			s= "fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));
   226 		else	
   227 			s= ((BranchObj*)(parObj))->getSelectString() + ",fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));
   228 	} else
   229 		s="mc:";
   230 	
   231 	return s;
   232 
   233 }
   234