floatimageobj.cpp
author insilmaril
Wed Mar 15 13:53:54 2006 +0000 (2006-03-15)
changeset 252 f9ed11f2ab60
parent 218 160459d924a1
child 258 42c8cf6dd1c3
permissions -rw-r--r--
hide export for floatimages.
     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 useOrientAttr;
   151 	if (useOrientation)
   152 		useOrientAttr=attribut ("useOrientation","true");
   153 	else	
   154 		useOrientAttr=attribut ("useOrientation","false");
   155 		
   156 	QString saveInMapAttr;
   157 	if (saveInMap)
   158 		saveInMapAttr=attribut ("saveInMap","true");
   159 	else	
   160 		
   161 		saveInMapAttr=attribut ("saveInMap","false");
   162 
   163 	QString exportAttr;
   164 	if (floatExport)
   165 		exportAttr=attribut ("floatExport","true");
   166 	else	
   167 		exportAttr=attribut ("floatExport","false");
   168 
   169 	QString zAttr=attribut ("zPlane",QString().setNum(zPlane));
   170 	QString url;
   171 
   172 	// prevent saving as GIF
   173 	if (filetype=="GIF")
   174 		filetype="PNG";
   175 		
   176 	url="images/"+prefix+"image-" + QString().number(saveCounter,10) + "." +filetype;
   177 
   178 	// And really save the image
   179 	icon->save (tmpdir + "/" + url, filetype);
   180 
   181     return singleElement ("floatimage",  
   182 		getOrnAttr() 
   183 		+useOrientAttr 
   184 		+saveInMapAttr 
   185 		+exportAttr  
   186 		+zAttr  
   187 		+attribut ("href",QString ("file:")+url)
   188 	);	
   189 }
   190 
   191 void FloatImageObj::resetSaveCounter()
   192 {
   193 	saveCounter=0;
   194 }
   195 
   196 
   197 QRect FloatImageObj::getTotalBBox()
   198 {
   199 	return bbox;
   200 }
   201 
   202 QRect FloatImageObj::getBBoxSizeWithChilds()
   203 {
   204 	//FIXME  abstract in linkablemapobj.h, not calculated
   205 	return bboxTotal;
   206 }
   207 
   208 void FloatImageObj::calcBBoxSizeWithChilds()
   209 {
   210 	//FIXME  abstract in linkablemapobj.h
   211 }
   212 
   213 QString FloatImageObj::getSelectString()
   214 {
   215 	QString s;
   216 	if (parObj)
   217 	{
   218 		if (parObj->getDepth()==0)
   219 			s= "fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));
   220 		else	
   221 			s= ((BranchObj*)(parObj))->getSelectString() + ",fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));
   222 	} else
   223 		s="mc:";
   224 	
   225 	return s;
   226 
   227 }
   228