floatimageobj.cpp
author insilmaril
Thu, 01 Jun 2006 11:19:58 +0000
changeset 344 7bafe3db684c
parent 334 df4fdaa07527
child 366 e95081c21da2
permissions -rw-r--r--
added warningdialog.ui
     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 		setOriginalFilename (fn);
    99 		return true;
   100 	} else
   101 		return false;
   102 	
   103 }
   104 
   105 void FloatImageObj::save (const QString &fn, const char *format)
   106 {	
   107 	icon->save (fn,format);
   108 }
   109 
   110 void FloatImageObj::setOriginalFilename(const QString & fn)
   111 {
   112 	originalFilename=fn;
   113 
   114 	// Set short name, too. Search from behind:
   115 	int i=originalFilename.findRev("/");
   116 	if (i>=0) originalFilename=originalFilename.remove (0,i+1);
   117 }
   118 
   119 QString FloatImageObj::getOriginalFilename()
   120 {
   121 	return originalFilename;
   122 }
   123 
   124 void FloatImageObj::setVisibility(bool v)
   125 {
   126     OrnamentedObj::setVisibility(v);
   127 	if (v)
   128 	    icon->setVisibility(true);
   129 	else
   130 	    icon->setVisibility(false);
   131 }
   132 
   133 void FloatImageObj::move (double x, double y)
   134 {
   135 	FloatObj::move(x,y);
   136 	icon->move (x+4,y+4);
   137     positionBBox();
   138 }
   139 
   140 void FloatImageObj::move (QPoint p)
   141 {
   142 	move (p.x(), p.y());
   143 }
   144 
   145 void FloatImageObj::positionBBox()
   146 {
   147 	clickBox=bbox;
   148 }
   149 
   150 void FloatImageObj::calcBBoxSize()
   151 {
   152 	// TODO
   153 }
   154 
   155 QString FloatImageObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPoint &p)
   156 {
   157 	if (hidden) return "";
   158 
   159 	saveCounter++;
   160 	
   161 	QString useOrientAttr;
   162 	if (useOrientation)
   163 		useOrientAttr=attribut ("useOrientation","true");
   164 	else	
   165 		useOrientAttr=attribut ("useOrientation","false");
   166 		
   167 	QString saveInMapAttr;
   168 	if (saveInMap)
   169 		saveInMapAttr=attribut ("saveInMap","true");
   170 	else	
   171 		
   172 		saveInMapAttr=attribut ("saveInMap","false");
   173 
   174 	QString exportAttr;
   175 	if (floatExport)
   176 		exportAttr=attribut ("floatExport","true");
   177 	else	
   178 		exportAttr=attribut ("floatExport","false");
   179 
   180 	QString zAttr=attribut ("zPlane",QString().setNum(zPlane));
   181 	QString url;
   182 
   183 	// prevent saving as GIF
   184 	if (filetype=="GIF")
   185 		filetype="PNG";
   186 		
   187 	url="images/"+prefix+"image-" + QString().number(saveCounter,10) + "." +filetype;
   188 
   189 	// And really save the image
   190 	icon->save (tmpdir + "/" + url, filetype);
   191  
   192 	QString nameAttr=attribut ("orgName",originalFilename);
   193 
   194     return singleElement ("floatimage",  
   195 		getOrnAttr() 
   196 		+useOrientAttr 
   197 		+saveInMapAttr 
   198 		+exportAttr  
   199 		+zAttr  
   200 		+attribut ("href",QString ("file:")+url)
   201 		+nameAttr
   202 	);	
   203 }
   204 
   205 void FloatImageObj::resetSaveCounter()
   206 {
   207 	saveCounter=0;
   208 }
   209 
   210 
   211 QRect FloatImageObj::getTotalBBox()
   212 {
   213 	return bbox;
   214 }
   215 
   216 QRect FloatImageObj::getBBoxSizeWithChilds()
   217 {
   218 	//FIXME  abstract in linkablemapobj.h, not calculated
   219 	return bboxTotal;
   220 }
   221 
   222 void FloatImageObj::calcBBoxSizeWithChilds()
   223 {
   224 	//FIXME  abstract in linkablemapobj.h
   225 }
   226 
   227 QString FloatImageObj::getSelectString()
   228 {
   229 	QString s;
   230 	if (parObj)
   231 	{
   232 		if (parObj->getDepth()==0)
   233 			s= "fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));
   234 		else	
   235 			s= ((BranchObj*)(parObj))->getSelectString() + ",fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));
   236 	} else
   237 		s="mc:";
   238 	
   239 	return s;
   240 
   241 }
   242