1 #include <QImageReader>
4 #include "floatimageobj.h"
7 /////////////////////////////////////////////////////////////////
9 /////////////////////////////////////////////////////////////////
11 uint FloatImageObj::saveCounter=0; // make instance
14 FloatImageObj::FloatImageObj ():FloatObj()
16 // cout << "Const FloatImageObj ()\n";
22 FloatImageObj::FloatImageObj (QGraphicsScene* s):FloatObj(s)
24 // cout << "Const FloatImageObj (s) called from MapCenterObj (s)\n";
30 FloatImageObj::FloatImageObj (QGraphicsScene *s, OrnamentedObj* p):FloatObj(s,p)
32 // cout << "Const FloatImageObj (c,p)\n";
36 FloatImageObj::~FloatImageObj ()
38 // cout << "Destr FloatImageObj "<<this<<"\n";
42 void FloatImageObj::init ()
44 icon=new ImageObj (scene);
45 icon->setPos (absPos.x(), absPos.y() );
46 icon->setVisibility (true);
47 setZValue (Z_FLOATIMG);
48 bbox.setSize (QSizeF(icon->boundingRect().width(), icon->boundingRect().height()));
49 clickBox.setSize (QSizeF(icon->boundingRect().width(), icon->boundingRect().height()));filename="";
50 originalFilename="no original name available";
56 systemFlags->setShowFlags(false);
59 void FloatImageObj::copy (FloatImageObj* other)
61 FloatObj::copy (other);
62 icon->copy (other->icon);
63 filetype=other->filetype;
64 filename=other->filename;
65 originalFilename=other->originalFilename;
66 saveInMap=other->saveInMap;
70 void FloatImageObj::setZValue (const int &i)
76 int FloatImageObj::z ()
78 return qRound (icon->zValue());
81 void FloatImageObj::load (const QPixmap &pixmap)
84 bbox.setSize (QSizeF(icon->boundingRect().width()+8, icon->boundingRect().height()+8));
85 clickBox.setSize (QSizeF(icon->boundingRect().width()+8, icon->boundingRect().height()+8));
88 filename="No filename given";
91 bool FloatImageObj::load (const QString &fn)
93 QImageReader reader (fn);
96 if( reader.read (&img))
98 icon->setPixmap(QPixmap::fromImage(img));
99 bbox.setSize (QSizeF(icon->boundingRect().width()+8, icon->boundingRect().height()+8));
102 filetype=reader.format();
103 setOriginalFilename (fn);
110 void FloatImageObj::save (const QString &fn, const QString &format)
112 icon->save (fn,qPrintable (format));
115 void FloatImageObj::setOriginalFilename(const QString & fn)
119 // Set short name, too. Search from behind:
120 int i=originalFilename.findRev("/");
121 if (i>=0) originalFilename=originalFilename.remove (0,i+1);
124 QString FloatImageObj::getOriginalFilename()
126 return originalFilename;
129 void FloatImageObj::setVisibility(bool v)
131 OrnamentedObj::setVisibility(v);
133 icon->setVisibility(true);
135 icon->setVisibility(false);
138 void FloatImageObj::move (double x, double y)
141 icon->setPos (x+4,y+4);
145 void FloatImageObj::move (QPointF p)
147 OrnamentedObj::move (p.x(),p.y());
150 void FloatImageObj::positionBBox()
155 void FloatImageObj::calcBBoxSize()
160 QString FloatImageObj::saveToDir (const QString &tmpdir,const QString &prefix)
162 if (hidden) return "";
166 QString useOrientAttr;
168 useOrientAttr=attribut ("useOrientation","true");
170 useOrientAttr=attribut ("useOrientation","false");
172 QString saveInMapAttr;
174 saveInMapAttr=attribut ("saveInMap","true");
177 saveInMapAttr=attribut ("saveInMap","false");
181 exportAttr=attribut ("floatExport","true");
183 exportAttr=attribut ("floatExport","false");
185 QString zAttr=attribut ("zPlane",QString().setNum(zPlane));
188 url="images/"+prefix+"image-" + QString().number(saveCounter,10) + "." +filetype;
190 // And really save the image
191 icon->save (tmpdir + "/" + url, "PNG");
193 QString nameAttr=attribut ("orgName",originalFilename);
195 return singleElement ("floatimage",
201 +attribut ("href",QString ("file:")+url)
206 void FloatImageObj::resetSaveCounter()
212 QRectF FloatImageObj::getTotalBBox()
217 QRectF FloatImageObj::getBBoxSizeWithChilds()
219 //TODO abstract in linkablemapobj.h, not calculated
223 void FloatImageObj::calcBBoxSizeWithChilds()
225 //TODO abstract in linkablemapobj.h
228 QString FloatImageObj::getSelectString()
233 if (parObj->getDepth()==0)
234 s= "fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));
236 s= ((BranchObj*)(parObj))->getSelectString() + ",fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));