1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/floatimageobj.cpp Sun Jan 30 12:59:03 2005 +0000
1.3 @@ -0,0 +1,219 @@
1.4 +#include "floatimageobj.h"
1.5 +#include "branchobj.h"
1.6 +#include <math.h>
1.7 +
1.8 +
1.9 +/////////////////////////////////////////////////////////////////
1.10 +// FloatImageObj
1.11 +/////////////////////////////////////////////////////////////////
1.12 +
1.13 +int FloatImageObj::counter=0; // make instance
1.14 +
1.15 +
1.16 +FloatImageObj::FloatImageObj ():FloatObj()
1.17 +{
1.18 +// cout << "Const FloatImageObj ()\n";
1.19 + setParObj (this);
1.20 + init();
1.21 + depth=-1;
1.22 +}
1.23 +
1.24 +FloatImageObj::FloatImageObj (QCanvas* c):FloatObj(c)
1.25 +{
1.26 + // cout << "Const FloatImageObj (c) called from MapCenterObj (c)\n";
1.27 + setParObj (this);
1.28 + init();
1.29 + depth=-1;
1.30 +}
1.31 +
1.32 +FloatImageObj::FloatImageObj (QCanvas* c, LinkableMapObj* p):FloatObj(c,p)
1.33 +{
1.34 + // cout << "Const FloatImageObj (c,p)\n";
1.35 + init();
1.36 +}
1.37 +
1.38 +FloatImageObj::~FloatImageObj ()
1.39 +{
1.40 +// cout << "Destr FloatImageObj "<<this<<"\n";
1.41 + delete(icon);
1.42 +}
1.43 +
1.44 +void FloatImageObj::init ()
1.45 +{
1.46 + icon=new ImageObj (canvas);
1.47 + icon->move (absPos.x(), absPos.y() );
1.48 + icon->setVisibility (true);
1.49 + bbox.setSize (QSize(icon->size().width(), icon->size().height()));
1.50 + filename="";
1.51 + originalFilename="no original name available";
1.52 + filetype="";
1.53 + saveInMap=true;
1.54 +}
1.55 +
1.56 +void FloatImageObj::copy (FloatImageObj* other)
1.57 +{
1.58 + FloatObj::copy (other);
1.59 + icon->copy (other->icon);
1.60 + filename=other->filename;
1.61 + saveInMap=other->saveInMap;
1.62 + positionBBox();
1.63 +}
1.64 +
1.65 +void FloatImageObj::setZ (const int &i)
1.66 +{
1.67 + icon->setZ (i);
1.68 + zPlane=i;
1.69 +}
1.70 +
1.71 +int FloatImageObj::z ()
1.72 +{
1.73 + return lrint (icon->z());
1.74 +}
1.75 +
1.76 +bool FloatImageObj::load (const QString &fn)
1.77 +{
1.78 + if( icon->load (fn))
1.79 + {
1.80 + bbox.setSize (QSize(icon->size().width()+8, icon->size().height()+8));
1.81 + positionBBox();
1.82 + filename=fn;
1.83 + filetype=QPixmap::imageFormat (fn);
1.84 + return true;
1.85 + } else
1.86 + return false;
1.87 +
1.88 +}
1.89 +
1.90 +void FloatImageObj::save (const QString &fn, const char *format)
1.91 +{
1.92 + icon->save (fn,format);
1.93 +}
1.94 +
1.95 +void FloatImageObj::setOriginalFilename(const QString & fn)
1.96 +{
1.97 + originalFilename=fn;
1.98 +}
1.99 +
1.100 +QString FloatImageObj::getOriginalFilename()
1.101 +{
1.102 + return originalFilename;
1.103 +}
1.104 +
1.105 +void FloatImageObj::setVisibility(bool v)
1.106 +{
1.107 + LinkableMapObj::setVisibility(v);
1.108 + if (v)
1.109 + icon->setVisibility(true);
1.110 + else
1.111 + icon->setVisibility(false);
1.112 +}
1.113 +
1.114 +void FloatImageObj::move (double x, double y)
1.115 +{
1.116 + FloatObj::move(x,y);
1.117 + icon->move (x+4,y+4);
1.118 + positionBBox();
1.119 +}
1.120 +
1.121 +void FloatImageObj::move (QPoint p)
1.122 +{
1.123 + move (p.x(), p.y());
1.124 +}
1.125 +
1.126 +void FloatImageObj::positionBBox()
1.127 +{
1.128 + // TODO
1.129 +}
1.130 +
1.131 +void FloatImageObj::calcBBoxSize()
1.132 +{
1.133 + // TODO
1.134 +}
1.135 +
1.136 +QString FloatImageObj::saveToDir (const QString &tmpdir,const QString &prefix)
1.137 +{
1.138 + counter++;
1.139 +
1.140 + QString posAttr=
1.141 + attribut("relPosX",QString().setNum(relPos.x(),10)) +
1.142 + attribut("relPosY",QString().setNum(relPos.y(),10));
1.143 +
1.144 + QString useOrientAttr;
1.145 + if (useOrientation)
1.146 + useOrientAttr=attribut ("useOrientation","true");
1.147 + else
1.148 + useOrientAttr=attribut ("useOrientation","false");
1.149 +
1.150 + QString saveInMapAttr;
1.151 + if (saveInMap)
1.152 + saveInMapAttr=attribut ("saveInMap","true");
1.153 + else
1.154 +
1.155 + saveInMapAttr=attribut ("saveInMap","false");
1.156 +
1.157 + QString exportAttr;
1.158 + if (floatExport)
1.159 + exportAttr=attribut ("floatExport","true");
1.160 + else
1.161 + exportAttr=attribut ("floatExport","false");
1.162 +
1.163 + QString zAttr=attribut ("zPlane",QString().setNum(zPlane));
1.164 + QString url;
1.165 +
1.166 + // prevent saving as GIF
1.167 + if (filetype=="GIF")
1.168 + filetype="PNG";
1.169 +
1.170 + url="images/"+prefix+"image-" + QString().number(counter,10) + "." +filetype;
1.171 +
1.172 + // And really save the image
1.173 + icon->save (tmpdir + "/" + url, filetype);
1.174 +
1.175 + return singleElement ("floatimage",
1.176 + posAttr +
1.177 + useOrientAttr +
1.178 + saveInMapAttr +
1.179 + exportAttr +
1.180 + zAttr +
1.181 + attribut ("href",QString ("file:")+url)
1.182 + );
1.183 +}
1.184 +
1.185 +void FloatImageObj::resetSaveCounter()
1.186 +{
1.187 + counter=0;
1.188 +}
1.189 +
1.190 +
1.191 +QRect FloatImageObj::getTotalBBox()
1.192 +{
1.193 + return bbox;
1.194 +}
1.195 +
1.196 +QRect FloatImageObj::getBBoxSizeWithChilds()
1.197 +{
1.198 + //FIXME abstract in linkablemapobj.h, not calculated
1.199 + return bboxTotal;
1.200 +}
1.201 +
1.202 +void FloatImageObj::calcBBoxSizeWithChilds()
1.203 +{
1.204 + //FIXME abstract in linkablemapobj.h
1.205 +}
1.206 +
1.207 +QString FloatImageObj::getSelectString()
1.208 +{
1.209 + QString s;
1.210 + if (parObj)
1.211 + {
1.212 + if (parObj->getDepth()==0)
1.213 + s= "fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));
1.214 + else
1.215 + s= ((BranchObj*)(parObj))->getSelectString() + ",fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));
1.216 + } else
1.217 + s="mc:";
1.218 +
1.219 + return s;
1.220 +
1.221 +}
1.222 +