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