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));
86 selbox->setRect(0,0,clickBox.width(),clickBox.height());
89 filename="No filename given";
92 bool FloatImageObj::load (const QString &fn)
94 QImageReader reader (fn);
97 if( reader.read (&img))
99 icon->setPixmap(QPixmap::fromImage(img));
100 bbox.setSize (QSizeF(icon->boundingRect().width()+8, icon->boundingRect().height()+8));
101 selbox->setRect(0,0,clickBox.width(),clickBox.height());
104 filetype=reader.format();
105 setOriginalFilename (fn);
112 void FloatImageObj::save (const QString &fn, const QString &format)
114 icon->save (fn,qPrintable (format));
117 void FloatImageObj::setOriginalFilename(const QString & fn)
121 // Set short name, too. Search from behind:
122 int i=originalFilename.findRev("/");
123 if (i>=0) originalFilename=originalFilename.remove (0,i+1);
126 QString FloatImageObj::getOriginalFilename()
128 return originalFilename;
131 void FloatImageObj::setVisibility(bool v)
133 OrnamentedObj::setVisibility(v);
135 icon->setVisibility(true);
137 icon->setVisibility(false);
140 void FloatImageObj::move (double x, double y)
143 icon->setPos (x+4,y+4);
147 void FloatImageObj::move (QPointF p)
149 OrnamentedObj::move (p.x(),p.y());
152 void FloatImageObj::positionBBox()
158 void FloatImageObj::calcBBoxSize()
163 QString FloatImageObj::saveToDir (const QString &tmpdir,const QString &prefix)
165 if (hidden) return "";
169 QString useOrientAttr;
171 useOrientAttr=attribut ("useOrientation","true");
173 useOrientAttr=attribut ("useOrientation","false");
175 QString saveInMapAttr;
177 saveInMapAttr=attribut ("saveInMap","true");
180 saveInMapAttr=attribut ("saveInMap","false");
184 exportAttr=attribut ("floatExport","true");
186 exportAttr=attribut ("floatExport","false");
188 QString zAttr=attribut ("zPlane",QString().setNum(zPlane));
191 url="images/"+prefix+"image-" + QString().number(saveCounter,10) + "." +filetype;
193 // And really save the image
194 icon->save (tmpdir + "/" + url, "PNG");
196 QString nameAttr=attribut ("orgName",originalFilename);
198 return singleElement ("floatimage",
204 +attribut ("href",QString ("file:")+url)
209 void FloatImageObj::resetSaveCounter()
215 QRectF FloatImageObj::getTotalBBox()
220 QRectF FloatImageObj::getBBoxSizeWithChilds()
222 //TODO abstract in linkablemapobj.h, not calculated
226 void FloatImageObj::calcBBoxSizeWithChilds()
228 //TODO abstract in linkablemapobj.h
231 QString FloatImageObj::getSelectString()
236 if (parObj->getDepth()==0)
237 s= "fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));
239 s= ((BranchObj*)(parObj))->getSelectString() + ",fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));