floatimageobj.cpp
author insilmaril
Tue, 06 Jun 2006 14:58:11 +0000
branchqt4-port
changeset 2 608f976aa7bb
parent 0 7a96bd401351
child 11 b8c547f0fc58
permissions -rw-r--r--
First compilation on QT4
     1 #include "floatimageobj.h"
     2 #include "branchobj.h"
     3 //Added by qt3to4:
     4 #include <QPixmap>
     5 
     6 
     7 /////////////////////////////////////////////////////////////////
     8 // FloatImageObj
     9 /////////////////////////////////////////////////////////////////
    10 
    11 uint FloatImageObj::saveCounter=0;		// make instance 
    12 
    13 
    14 FloatImageObj::FloatImageObj ():FloatObj()
    15 {
    16 //    cout << "Const FloatImageObj ()\n";
    17     setParObj (this);	
    18     init();
    19     depth=-1;
    20 }
    21 
    22 FloatImageObj::FloatImageObj (Q3Canvas* c):FloatObj(c)
    23 {
    24  //   cout << "Const FloatImageObj (c)  called from MapCenterObj (c)\n";
    25     setParObj (this);	
    26     init();
    27     depth=-1;
    28 }
    29 
    30 FloatImageObj::FloatImageObj (Q3Canvas* c, OrnamentedObj* p):FloatObj(c,p)
    31 {
    32  //   cout << "Const FloatImageObj (c,p)\n";
    33     init();
    34 }
    35 
    36 FloatImageObj::~FloatImageObj ()
    37 {
    38 //	cout << "Destr FloatImageObj "<<this<<"\n";
    39 	delete(icon);
    40 }
    41 
    42 void FloatImageObj::init () 
    43 {
    44 	icon=new ImageObj (canvas);
    45 	icon->move (absPos.x(), absPos.y() );
    46 	icon->setVisibility (true);
    47 	setZ (Z_FLOATIMG);
    48 	bbox.setSize (QSize(icon->size().width(), icon->size().height()));
    49 	clickBox.setSize (QSize(icon->size().width(), icon->size().height()));
    50 	filename="";
    51 	originalFilename="no original name available";
    52 	filetype="";
    53 	saveInMap=true;
    54 	useRelPos=true;
    55 
    56 	//Hide flags
    57 	systemFlags->setShowFlags(false);
    58 }
    59 
    60 void FloatImageObj::copy (FloatImageObj* other)
    61 {					
    62 	FloatObj::copy (other);
    63 	icon->copy (other->icon);
    64 	filetype=other->filetype;
    65 	filename=other->filename;
    66 	originalFilename=other->originalFilename;
    67 	saveInMap=other->saveInMap;
    68     positionBBox();
    69 }
    70 
    71 void FloatImageObj::setZ (const int &i)
    72 {
    73 	icon->setZ (i);
    74 	zPlane=i;
    75 }
    76 
    77 int FloatImageObj::z ()
    78 {
    79 	return qRound (icon->z());
    80 }
    81 
    82 void FloatImageObj::load (const QPixmap &pixmap)
    83 {
    84   icon->load(pixmap);
    85   bbox.setSize (QSize(icon->size().width()+8, icon->size().height()+8));
    86   clickBox.setSize (QSize(icon->size().width()+8, icon->size().height()+8));
    87   positionBBox();
    88   filetype="PNG";
    89   filename="noname.png";
    90 }
    91 
    92 bool FloatImageObj::load (const QString &fn)
    93 {	
    94 	if( icon->load (fn))
    95 	{
    96 		bbox.setSize (QSize(icon->size().width()+8, icon->size().height()+8));
    97 		positionBBox();
    98 		filename=fn;
    99 //FIXME QT3 was		filetype=QPixmap::imageFormat (fn);
   100 		setOriginalFilename (fn);
   101 		return true;
   102 	} else
   103 		return false;
   104 	
   105 }
   106 
   107 void FloatImageObj::save (const QString &fn, const char *format)
   108 {	
   109 	icon->save (fn,format);
   110 }
   111 
   112 void FloatImageObj::setOriginalFilename(const QString & fn)
   113 {
   114 	originalFilename=fn;
   115 
   116 	// Set short name, too. Search from behind:
   117 	int i=originalFilename.findRev("/");
   118 	if (i>=0) originalFilename=originalFilename.remove (0,i+1);
   119 }
   120 
   121 QString FloatImageObj::getOriginalFilename()
   122 {
   123 	return originalFilename;
   124 }
   125 
   126 void FloatImageObj::setVisibility(bool v)
   127 {
   128     OrnamentedObj::setVisibility(v);
   129 	if (v)
   130 	    icon->setVisibility(true);
   131 	else
   132 	    icon->setVisibility(false);
   133 }
   134 
   135 void FloatImageObj::move (double x, double y)
   136 {
   137 	FloatObj::move(x,y);
   138 	icon->move (x+4,y+4);
   139     positionBBox();
   140 }
   141 
   142 void FloatImageObj::move (QPoint p)
   143 {
   144 	move (p.x(), p.y());
   145 }
   146 
   147 void FloatImageObj::positionBBox()
   148 {
   149 	clickBox=bbox;
   150 }
   151 
   152 void FloatImageObj::calcBBoxSize()
   153 {
   154 	// TODO
   155 }
   156 
   157 QString FloatImageObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPoint &p)
   158 {
   159 	if (hidden) return "";
   160 
   161 	saveCounter++;
   162 	
   163 	QString useOrientAttr;
   164 	if (useOrientation)
   165 		useOrientAttr=attribut ("useOrientation","true");
   166 	else	
   167 		useOrientAttr=attribut ("useOrientation","false");
   168 		
   169 	QString saveInMapAttr;
   170 	if (saveInMap)
   171 		saveInMapAttr=attribut ("saveInMap","true");
   172 	else	
   173 		
   174 		saveInMapAttr=attribut ("saveInMap","false");
   175 
   176 	QString exportAttr;
   177 	if (floatExport)
   178 		exportAttr=attribut ("floatExport","true");
   179 	else	
   180 		exportAttr=attribut ("floatExport","false");
   181 
   182 	QString zAttr=attribut ("zPlane",QString().setNum(zPlane));
   183 	QString url;
   184 
   185 	// prevent saving as GIF
   186 	if (filetype=="GIF")
   187 		filetype="PNG";
   188 		
   189 	url="images/"+prefix+"image-" + QString().number(saveCounter,10) + "." +filetype;
   190 
   191 	// And really save the image
   192 	icon->save (tmpdir + "/" + url, filetype);
   193  
   194 	QString nameAttr=attribut ("orgName",originalFilename);
   195 
   196     return singleElement ("floatimage",  
   197 		getOrnAttr() 
   198 		+useOrientAttr 
   199 		+saveInMapAttr 
   200 		+exportAttr  
   201 		+zAttr  
   202 		+attribut ("href",QString ("file:")+url)
   203 		+nameAttr
   204 	);	
   205 }
   206 
   207 void FloatImageObj::resetSaveCounter()
   208 {
   209 	saveCounter=0;
   210 }
   211 
   212 
   213 QRect FloatImageObj::getTotalBBox()
   214 {
   215 	return bbox;
   216 }
   217 
   218 QRect FloatImageObj::getBBoxSizeWithChilds()
   219 {
   220 	//FIXME  abstract in linkablemapobj.h, not calculated
   221 	return bboxTotal;
   222 }
   223 
   224 void FloatImageObj::calcBBoxSizeWithChilds()
   225 {
   226 	//FIXME  abstract in linkablemapobj.h
   227 }
   228 
   229 QString FloatImageObj::getSelectString()
   230 {
   231 	QString s;
   232 	if (parObj)
   233 	{
   234 		if (parObj->getDepth()==0)
   235 			s= "fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));
   236 		else	
   237 			s= ((BranchObj*)(parObj))->getSelectString() + ",fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));
   238 	} else
   239 		s="mc:";
   240 	
   241 	return s;
   242 
   243 }
   244