floatimageobj.cpp
author insilmaril
Wed, 25 Jan 2006 09:04:00 +0000
changeset 194 de97201180ea
parent 173 309609406650
child 218 160459d924a1
permissions -rw-r--r--
smaller URL-icons for XHTML export
     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 }
    52 
    53 void FloatImageObj::copy (FloatImageObj* other)
    54 {					
    55 	FloatObj::copy (other);
    56 	icon->copy (other->icon);
    57 	filetype=other->filetype;
    58 	filename=other->filename;
    59 	originalFilename=other->originalFilename;
    60 	saveInMap=other->saveInMap;
    61     positionBBox();
    62 }
    63 
    64 void FloatImageObj::setZ (const int &i)
    65 {
    66 	icon->setZ (i);
    67 	zPlane=i;
    68 }
    69 
    70 int FloatImageObj::z ()
    71 {
    72 	return qRound (icon->z());
    73 }
    74 
    75 void FloatImageObj::load (const QPixmap &pixmap)
    76 {
    77   icon->load(pixmap);
    78   bbox.setSize (QSize(icon->size().width()+8, icon->size().height()+8));
    79   clickBox.setSize (QSize(icon->size().width()+8, icon->size().height()+8));
    80   positionBBox();
    81   filetype="PNG";
    82   filename="noname.png";
    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 	clickBox=bbox;
   138 }
   139 
   140 void FloatImageObj::calcBBoxSize()
   141 {
   142 	// TODO
   143 }
   144 
   145 QString FloatImageObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPoint &p)
   146 {
   147 	saveCounter++;
   148 
   149 	QString posAttr=
   150 		attribut("relPosX",QString().setNum(relPos.x(),10)) +
   151 		attribut("relPosY",QString().setNum(relPos.y(),10)); 
   152 
   153 	QString linkAttr=getLinkAttr();
   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 		posAttr + 
   188 		linkAttr +
   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