floatimageobj.cpp
author insilmaril
Tue, 15 Aug 2006 11:42:10 +0000
branchqt4-port
changeset 13 9aadd0f58300
parent 11 b8c547f0fc58
permissions -rw-r--r--
1.8.52 Toolbar layout is saved now.
     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 QString &format)
   108 {	
   109 	icon->save (fn,qPrintable (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 	url="images/"+prefix+"image-" + QString().number(saveCounter,10) + "." +filetype;
   186 
   187 	// And really save the image
   188 	icon->save (tmpdir + "/" + url, "PNG");
   189  
   190 	QString nameAttr=attribut ("orgName",originalFilename);
   191 
   192     return singleElement ("floatimage",  
   193 		getOrnAttr() 
   194 		+useOrientAttr 
   195 		+saveInMapAttr 
   196 		+exportAttr  
   197 		+zAttr  
   198 		+attribut ("href",QString ("file:")+url)
   199 		+nameAttr
   200 	);	
   201 }
   202 
   203 void FloatImageObj::resetSaveCounter()
   204 {
   205 	saveCounter=0;
   206 }
   207 
   208 
   209 QRect FloatImageObj::getTotalBBox()
   210 {
   211 	return bbox;
   212 }
   213 
   214 QRect FloatImageObj::getBBoxSizeWithChilds()
   215 {
   216 	//FIXME  abstract in linkablemapobj.h, not calculated
   217 	return bboxTotal;
   218 }
   219 
   220 void FloatImageObj::calcBBoxSizeWithChilds()
   221 {
   222 	//FIXME  abstract in linkablemapobj.h
   223 }
   224 
   225 QString FloatImageObj::getSelectString()
   226 {
   227 	QString s;
   228 	if (parObj)
   229 	{
   230 		if (parObj->getDepth()==0)
   231 			s= "fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));
   232 		else	
   233 			s= ((BranchObj*)(parObj))->getSelectString() + ",fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));
   234 	} else
   235 		s="mc:";
   236 	
   237 	return s;
   238 
   239 }
   240