insilmaril@408: #include insilmaril@408: #include insilmaril@408: insilmaril@0: #include "floatimageobj.h" insilmaril@0: #include "branchobj.h" insilmaril@0: insilmaril@0: ///////////////////////////////////////////////////////////////// insilmaril@0: // FloatImageObj insilmaril@0: ///////////////////////////////////////////////////////////////// insilmaril@0: insilmaril@173: uint FloatImageObj::saveCounter=0; // make instance insilmaril@0: insilmaril@0: insilmaril@0: FloatImageObj::FloatImageObj ():FloatObj() insilmaril@0: { insilmaril@0: // cout << "Const FloatImageObj ()\n"; insilmaril@0: setParObj (this); insilmaril@0: init(); insilmaril@0: } insilmaril@0: insilmaril@408: FloatImageObj::FloatImageObj (QGraphicsScene* s):FloatObj(s) insilmaril@0: { insilmaril@408: // cout << "Const FloatImageObj (s) called from MapCenterObj (s)\n"; insilmaril@0: setParObj (this); insilmaril@0: init(); insilmaril@0: } insilmaril@0: insilmaril@408: FloatImageObj::FloatImageObj (QGraphicsScene *s, OrnamentedObj* p):FloatObj(s,p) insilmaril@0: { insilmaril@0: // cout << "Const FloatImageObj (c,p)\n"; insilmaril@0: init(); insilmaril@0: } insilmaril@0: insilmaril@0: FloatImageObj::~FloatImageObj () insilmaril@0: { insilmaril@417: // cout << "Destr FloatImageObj "<setPos (absPos.x(), absPos.y() ); insilmaril@0: icon->setVisibility (true); insilmaril@408: setZValue (Z_FLOATIMG); insilmaril@408: bbox.setSize (QSizeF(icon->boundingRect().width(), icon->boundingRect().height())); insilmaril@408: clickBox.setSize (QSizeF(icon->boundingRect().width(), icon->boundingRect().height()));filename=""; insilmaril@0: originalFilename="no original name available"; insilmaril@0: filetype=""; insilmaril@0: saveInMap=true; insilmaril@218: useRelPos=true; insilmaril@258: insilmaril@258: //Hide flags insilmaril@258: systemFlags->setShowFlags(false); insilmaril@0: } insilmaril@0: insilmaril@0: void FloatImageObj::copy (FloatImageObj* other) insilmaril@0: { insilmaril@0: FloatObj::copy (other); insilmaril@0: icon->copy (other->icon); insilmaril@173: filetype=other->filetype; insilmaril@0: filename=other->filename; insilmaril@173: originalFilename=other->originalFilename; insilmaril@0: saveInMap=other->saveInMap; insilmaril@0: positionBBox(); insilmaril@0: } insilmaril@0: insilmaril@408: void FloatImageObj::setZValue (const int &i) insilmaril@0: { insilmaril@408: icon->setZValue (i); insilmaril@0: zPlane=i; insilmaril@0: } insilmaril@0: insilmaril@0: int FloatImageObj::z () insilmaril@0: { insilmaril@408: return qRound (icon->zValue()); insilmaril@0: } insilmaril@0: insilmaril@113: void FloatImageObj::load (const QPixmap &pixmap) insilmaril@113: { insilmaril@408: icon->load(pixmap); insilmaril@408: bbox.setSize (QSizeF(icon->boundingRect().width()+8, icon->boundingRect().height()+8)); insilmaril@408: clickBox.setSize (QSizeF(icon->boundingRect().width()+8, icon->boundingRect().height()+8)); insilmaril@408: positionBBox(); insilmaril@408: filetype="PNG"; insilmaril@408: filename="No filename given"; insilmaril@113: } insilmaril@113: insilmaril@0: bool FloatImageObj::load (const QString &fn) insilmaril@0: { insilmaril@408: QImageReader reader (fn); insilmaril@408: QImage img; insilmaril@408: insilmaril@408: if( reader.read (&img)) insilmaril@0: { insilmaril@408: icon->setPixmap(QPixmap::fromImage(img)); insilmaril@408: bbox.setSize (QSizeF(icon->boundingRect().width()+8, icon->boundingRect().height()+8)); insilmaril@0: positionBBox(); insilmaril@0: filename=fn; insilmaril@408: filetype=reader.format(); insilmaril@334: setOriginalFilename (fn); insilmaril@0: return true; insilmaril@0: } else insilmaril@0: return false; insilmaril@0: insilmaril@0: } insilmaril@0: insilmaril@366: void FloatImageObj::save (const QString &fn, const QString &format) insilmaril@0: { insilmaril@366: icon->save (fn,qPrintable (format)); insilmaril@0: } insilmaril@0: insilmaril@0: void FloatImageObj::setOriginalFilename(const QString & fn) insilmaril@0: { insilmaril@0: originalFilename=fn; insilmaril@334: insilmaril@334: // Set short name, too. Search from behind: insilmaril@334: int i=originalFilename.findRev("/"); insilmaril@334: if (i>=0) originalFilename=originalFilename.remove (0,i+1); insilmaril@0: } insilmaril@0: insilmaril@0: QString FloatImageObj::getOriginalFilename() insilmaril@0: { insilmaril@0: return originalFilename; insilmaril@0: } insilmaril@0: insilmaril@0: void FloatImageObj::setVisibility(bool v) insilmaril@0: { insilmaril@258: OrnamentedObj::setVisibility(v); insilmaril@0: if (v) insilmaril@0: icon->setVisibility(true); insilmaril@0: else insilmaril@0: icon->setVisibility(false); insilmaril@0: } insilmaril@0: insilmaril@0: void FloatImageObj::move (double x, double y) insilmaril@0: { insilmaril@0: FloatObj::move(x,y); insilmaril@408: icon->setPos (x+4,y+4); insilmaril@0: positionBBox(); insilmaril@0: } insilmaril@0: insilmaril@408: void FloatImageObj::move (QPointF p) insilmaril@0: { insilmaril@408: OrnamentedObj::move (p.x(),p.y()); insilmaril@0: } insilmaril@0: insilmaril@0: void FloatImageObj::positionBBox() insilmaril@0: { insilmaril@173: clickBox=bbox; insilmaril@0: } insilmaril@0: insilmaril@0: void FloatImageObj::calcBBoxSize() insilmaril@0: { insilmaril@0: // TODO insilmaril@0: } insilmaril@0: insilmaril@377: QString FloatImageObj::saveToDir (const QString &tmpdir,const QString &prefix) insilmaril@0: { insilmaril@753: //FIXME-2 if (hidden) return ""; insilmaril@258: insilmaril@173: saveCounter++; insilmaril@173: insilmaril@0: QString useOrientAttr; insilmaril@0: if (useOrientation) insilmaril@0: useOrientAttr=attribut ("useOrientation","true"); insilmaril@0: else insilmaril@0: useOrientAttr=attribut ("useOrientation","false"); insilmaril@0: insilmaril@0: QString saveInMapAttr; insilmaril@0: if (saveInMap) insilmaril@0: saveInMapAttr=attribut ("saveInMap","true"); insilmaril@0: else insilmaril@0: insilmaril@0: saveInMapAttr=attribut ("saveInMap","false"); insilmaril@0: insilmaril@0: QString exportAttr; insilmaril@0: if (floatExport) insilmaril@0: exportAttr=attribut ("floatExport","true"); insilmaril@0: else insilmaril@0: exportAttr=attribut ("floatExport","false"); insilmaril@0: insilmaril@0: QString zAttr=attribut ("zPlane",QString().setNum(zPlane)); insilmaril@0: QString url; insilmaril@0: insilmaril@680: url="images/"+prefix+"image-" + QString().number(saveCounter,10) + ".png" ; insilmaril@0: insilmaril@0: // And really save the image insilmaril@680: icon->save (tmpdir +"/"+ url, "PNG"); insilmaril@334: insilmaril@334: QString nameAttr=attribut ("orgName",originalFilename); insilmaril@0: insilmaril@0: return singleElement ("floatimage", insilmaril@628: getOrnXMLAttr() insilmaril@241: +useOrientAttr insilmaril@241: +saveInMapAttr insilmaril@241: +exportAttr insilmaril@241: +zAttr insilmaril@241: +attribut ("href",QString ("file:")+url) insilmaril@334: +nameAttr insilmaril@0: ); insilmaril@0: } insilmaril@0: insilmaril@0: void FloatImageObj::resetSaveCounter() insilmaril@0: { insilmaril@173: saveCounter=0; insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@408: QRectF FloatImageObj::getTotalBBox() insilmaril@0: { insilmaril@0: return bbox; insilmaril@0: } insilmaril@0: insilmaril@721: QRectF FloatImageObj::getBBoxSizeWithChildren() insilmaril@0: { insilmaril@411: //TODO abstract in linkablemapobj.h, not calculated insilmaril@0: return bboxTotal; insilmaril@0: } insilmaril@0: insilmaril@721: void FloatImageObj::calcBBoxSizeWithChildren() insilmaril@0: { insilmaril@411: //TODO abstract in linkablemapobj.h insilmaril@0: } insilmaril@0: