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