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";
21 FloatImageObj::FloatImageObj (QGraphicsScene* s):FloatObj(s)
23 // cout << "Const FloatImageObj (s) called from MapCenterObj (s)\n";
28 FloatImageObj::FloatImageObj (QGraphicsScene *s, OrnamentedObj* p):FloatObj(s,p)
30 // cout << "Const FloatImageObj (c,p)\n";
34 FloatImageObj::~FloatImageObj ()
36 // cout << "Destr FloatImageObj "<<this<<"\n";
40 void FloatImageObj::init ()
42 icon=new ImageObj (scene);
43 icon->setPos (absPos.x(), absPos.y() );
44 icon->setVisibility (true);
45 setZValue (Z_FLOATIMG);
46 bbox.setSize (QSizeF(icon->boundingRect().width(), icon->boundingRect().height()));
47 clickBox.setSize (QSizeF(icon->boundingRect().width(), icon->boundingRect().height()));filename="";
48 originalFilename="no original name available";
54 systemFlags->setShowFlags(false);
57 void FloatImageObj::copy (FloatImageObj* other)
59 FloatObj::copy (other);
60 icon->copy (other->icon);
61 filetype=other->filetype;
62 filename=other->filename;
63 originalFilename=other->originalFilename;
64 saveInMap=other->saveInMap;
68 void FloatImageObj::setZValue (const int &i)
74 int FloatImageObj::z ()
76 return qRound (icon->zValue());
79 void FloatImageObj::load (const QPixmap &pixmap)
82 bbox.setSize (QSizeF(icon->boundingRect().width()+8, icon->boundingRect().height()+8));
83 clickBox.setSize (QSizeF(icon->boundingRect().width()+8, icon->boundingRect().height()+8));
86 filename="No filename given";
89 bool FloatImageObj::load (const QString &fn)
91 QImageReader reader (fn);
94 if( reader.read (&img))
96 icon->setPixmap(QPixmap::fromImage(img));
97 bbox.setSize (QSizeF(icon->boundingRect().width()+8, icon->boundingRect().height()+8));
100 filetype=reader.format();
101 setOriginalFilename (fn);
108 void FloatImageObj::save (const QString &fn, const QString &format)
110 icon->save (fn,qPrintable (format));
113 void FloatImageObj::setOriginalFilename(const QString & fn)
117 // Set short name, too. Search from behind:
118 int i=originalFilename.findRev("/");
119 if (i>=0) originalFilename=originalFilename.remove (0,i+1);
122 QString FloatImageObj::getOriginalFilename()
124 return originalFilename;
127 void FloatImageObj::setVisibility(bool v)
129 OrnamentedObj::setVisibility(v);
131 icon->setVisibility(true);
133 icon->setVisibility(false);
136 void FloatImageObj::move (double x, double y)
139 icon->setPos (x+4,y+4);
143 void FloatImageObj::move (QPointF p)
145 OrnamentedObj::move (p.x(),p.y());
148 void FloatImageObj::positionBBox()
153 void FloatImageObj::calcBBoxSize()
158 QString FloatImageObj::saveToDir (const QString &tmpdir,const QString &prefix)
160 //FIXME-2 if (hidden) return "";
164 QString useOrientAttr;
166 useOrientAttr=attribut ("useOrientation","true");
168 useOrientAttr=attribut ("useOrientation","false");
170 QString saveInMapAttr;
172 saveInMapAttr=attribut ("saveInMap","true");
175 saveInMapAttr=attribut ("saveInMap","false");
179 exportAttr=attribut ("floatExport","true");
181 exportAttr=attribut ("floatExport","false");
183 QString zAttr=attribut ("zPlane",QString().setNum(zPlane));
186 url="images/"+prefix+"image-" + QString().number(saveCounter,10) + ".png" ;
188 // And really save the image
189 icon->save (tmpdir +"/"+ url, "PNG");
191 QString nameAttr=attribut ("orgName",originalFilename);
193 return singleElement ("floatimage",
199 +attribut ("href",QString ("file:")+url)
204 void FloatImageObj::resetSaveCounter()
210 QRectF FloatImageObj::getTotalBBox()
215 QRectF FloatImageObj::getBBoxSizeWithChildren()
217 //TODO abstract in linkablemapobj.h, not calculated
221 void FloatImageObj::calcBBoxSizeWithChildren()
223 //TODO abstract in linkablemapobj.h