insilmaril@0: #include "branchobj.h" insilmaril@616: insilmaril@616: // #include "texteditor.h" insilmaril@749: #include "branchitem.h" insilmaril@643: #include "geometry.h" insilmaril@0: #include "mapeditor.h" insilmaril@0: #include "mainwindow.h" insilmaril@616: #include "misc.h" insilmaril@616: insilmaril@616: class TextEditor; insilmaril@0: insilmaril@0: extern TextEditor *textEditor; insilmaril@0: extern Main *mainWindow; insilmaril@0: extern FlagRowObj *standardFlagsDefault; insilmaril@0: insilmaril@0: insilmaril@0: ///////////////////////////////////////////////////////////////// insilmaril@0: // BranchObj insilmaril@0: ///////////////////////////////////////////////////////////////// insilmaril@0: insilmaril@746: BranchObj::BranchObj () :OrnamentedObj() // FIXME-3 needed at all? insilmaril@0: { insilmaril@0: // cout << "Const BranchObj ()\n"; insilmaril@0: setParObj (this); insilmaril@0: init(); insilmaril@0: depth=-1; insilmaril@0: } insilmaril@0: insilmaril@408: BranchObj::BranchObj (QGraphicsScene* s):OrnamentedObj (s) insilmaril@0: { insilmaril@408: // cout << "Const BranchObj (s) called from MapCenterObj (s)\n"; insilmaril@83: parObj=NULL; insilmaril@408: scene=s; insilmaril@0: } insilmaril@0: insilmaril@408: BranchObj::BranchObj (QGraphicsScene* s, LinkableMapObj* p):OrnamentedObj (s) insilmaril@0: { insilmaril@408: // cout << "Const BranchObj (s,p)\n"; insilmaril@408: scene=s; insilmaril@0: setParObj (p); insilmaril@0: depth=p->getDepth()+1; insilmaril@0: if (depth==1) insilmaril@0: // Calc angle to mapCenter if I am a mainbranch insilmaril@0: // needed for reordering the mainbranches clockwise insilmaril@0: // around mapcenter insilmaril@408: angle=getAngle (QPointF (x() - parObj->getChildPos().x() , insilmaril@408: (y() - parObj->getChildPos().y() ) ) ); insilmaril@0: init(); insilmaril@0: } insilmaril@0: insilmaril@0: BranchObj::~BranchObj () insilmaril@0: { insilmaril@722: // If I'm animated, I need to un-animate myself first insilmaril@722: if (anim.isAnimated() ) insilmaril@722: { insilmaril@722: anim.setAnimated (false); insilmaril@722: model->stopAnimation (this); insilmaril@722: } insilmaril@722: insilmaril@748: cout << "Destr BranchObj of "<getLastBranch(); insilmaril@425: if (bo) po->unScroll(); insilmaril@0: } insilmaril@749: */ insilmaril@83: clear(); insilmaril@0: } insilmaril@0: insilmaril@0: bool BranchObj::operator< ( const BranchObj & other ) insilmaril@0: { insilmaril@0: return angle < other.angle; insilmaril@0: } insilmaril@0: insilmaril@0: bool BranchObj::operator== ( const BranchObj & other ) insilmaril@0: { insilmaril@0: return angle == other.angle; insilmaril@0: } insilmaril@0: insilmaril@0: void BranchObj::init () insilmaril@0: { insilmaril@83: if (parObj) insilmaril@83: { insilmaril@83: absPos=getRandPos(); insilmaril@83: absPos+=parObj->getChildPos(); insilmaril@83: } insilmaril@0: insilmaril@0: setChildObj(this); insilmaril@0: insilmaril@169: includeImagesVer=false; insilmaril@169: includeImagesHor=false; insilmaril@0: } insilmaril@0: insilmaril@0: void BranchObj::copy (BranchObj* other) insilmaril@0: { insilmaril@0: OrnamentedObj::copy(other); insilmaril@0: insilmaril@0: branch.clear(); insilmaril@750: for (int i=0; itreeItem->branchCount(); ++i) insilmaril@0: // Make deep copy of b insilmaril@721: // Because addBranch again calls copy for the children, insilmaril@0: // Those will get a deep copy, too insilmaril@406: addBranch(other->branch.at(i) ); insilmaril@0: insilmaril@404: for (int i=0; ifloatimage.size(); ++i) insilmaril@404: addFloatImage (other->floatimage.at(i)); insilmaril@749: insilmaril@0: setVisibility (other->visible); insilmaril@0: insilmaril@0: angle=other->angle; insilmaril@0: insilmaril@0: positionBBox(); insilmaril@0: } insilmaril@0: insilmaril@0: void BranchObj::clear() insilmaril@0: { insilmaril@425: setVisibility (true); insilmaril@425: insilmaril@404: while (!floatimage.isEmpty()) insilmaril@404: delete floatimage.takeFirst(); insilmaril@404: insilmaril@95: while (!xlink.isEmpty()) insilmaril@406: delete xlink.takeFirst(); insilmaril@83: insilmaril@83: while (!branch.isEmpty()) insilmaril@406: delete branch.takeFirst(); insilmaril@0: } insilmaril@0: insilmaril@411: bool isAbove (BranchObj* a, BranchObj *b) insilmaril@411: { insilmaril@411: if (a->angle < b->angle) insilmaril@411: return true; insilmaril@411: else insilmaril@411: return false; insilmaril@411: } insilmaril@411: insilmaril@408: void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off) insilmaril@0: { insilmaril@0: // Temporary link to lmo insilmaril@0: // m is position of mouse pointer insilmaril@0: // offset 0: default 1: below lmo -1 above lmo (if possible) insilmaril@0: insilmaril@0: insilmaril@0: BranchObj* o=(BranchObj*)(lmo); insilmaril@0: if (!parObjTmpBuf) insilmaril@0: parObjTmpBuf=parObj; insilmaril@0: insilmaril@0: // ignore mapcenter and mainbranch insilmaril@0: if (lmo->getDepth()<2) off=0; insilmaril@0: if (off==0) insilmaril@0: link2ParPos=false; insilmaril@0: else insilmaril@0: link2ParPos=true; insilmaril@93: parObj=o; insilmaril@0: insilmaril@0: depth=parObj->getDepth()+1; insilmaril@0: insilmaril@0: // setLinkStyle calls updateLink, only set it once insilmaril@0: if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle()); insilmaril@0: insilmaril@0: // Move temporary to new position at destination insilmaril@0: // Usually the positioning would be done by reposition(), insilmaril@0: // but then also the destination branch would "Jump" around... insilmaril@0: // Better just do it approximately insilmaril@0: if (depth==1) insilmaril@0: { // new parent is the mapcenter itself insilmaril@0: insilmaril@408: QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(), insilmaril@0: m.y() - o->getChildPos().y() )); insilmaril@0: if (p.x()<0) p.setX( p.x()-bbox.width() ); insilmaril@0: move2RelPos (p); insilmaril@0: } else insilmaril@0: { insilmaril@408: qreal y; insilmaril@0: if (off==0) insilmaril@0: { insilmaril@0: // new parent is just a branch, link to it insilmaril@721: QRectF t=o->getBBoxSizeWithChildren(); insilmaril@750: if (o->getTreeItem()->getLastBranch()) insilmaril@0: y=t.y() + t.height() ; insilmaril@0: else insilmaril@0: y=t.y(); insilmaril@0: insilmaril@0: } else insilmaril@0: { insilmaril@0: if (off<0) insilmaril@0: // we want to link above lmo insilmaril@0: y=o->y() - height() + 5; insilmaril@0: else insilmaril@0: // we want to link below lmo insilmaril@0: // Bottom of sel should be 5 pixels above insilmaril@0: // the bottom of the branch _below_ the target: insilmaril@0: // Don't try to find that branch, guess 12 pixels insilmaril@0: y=o->getChildPos().y() -height() + 12; insilmaril@0: } insilmaril@462: if (o->getOrientation()==LinkableMapObj::LeftOfCenter) insilmaril@0: move ( o->getChildPos().x() - linkwidth, y ); insilmaril@0: else insilmaril@0: move (o->getChildPos().x() + linkwidth, y ); insilmaril@0: } insilmaril@0: insilmaril@0: // updateLink is called implicitly in move insilmaril@417: requestReposition(); insilmaril@0: } insilmaril@0: insilmaril@0: void BranchObj::unsetParObjTmp() insilmaril@0: { insilmaril@0: if (parObjTmpBuf) insilmaril@0: { insilmaril@0: link2ParPos=false; insilmaril@0: parObj=parObjTmpBuf; insilmaril@0: parObjTmpBuf=NULL; insilmaril@0: depth=parObj->getDepth()+1; insilmaril@0: setLinkStyle (getDefLinkStyle() ); insilmaril@93: updateLink(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void BranchObj::setVisibility(bool v, int toDepth) insilmaril@0: { insilmaril@749: BranchItem *bi=(BranchItem*)treeItem; insilmaril@0: if (depth <= toDepth) insilmaril@0: { insilmaril@0: frame->setVisibility(v); insilmaril@0: heading->setVisibility(v); insilmaril@0: systemFlags->setVisibility(v); insilmaril@0: standardFlags->setVisibility(v); insilmaril@0: LinkableMapObj::setVisibility (v); insilmaril@730: int i; insilmaril@730: for (i=0; isetVisibility (v); insilmaril@730: for (i=0; isetVisibility (); insilmaril@730: insilmaril@721: // Only change children, if I am not scrolled insilmaril@749: if (! bi->isScrolled() && (bi->depth() < toDepth)) insilmaril@0: { insilmaril@721: // Now go recursivly through all children insilmaril@750: for (i=0; ibranchCount(); ++i) insilmaril@406: branch.at(i)->setVisibility (v,toDepth); insilmaril@0: } insilmaril@0: } // depth <= toDepth insilmaril@0: requestReposition(); insilmaril@0: } insilmaril@0: insilmaril@0: void BranchObj::setVisibility(bool v) insilmaril@0: { insilmaril@0: setVisibility (v,MAX_DEPTH); insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: void BranchObj::setLinkColor () insilmaril@0: { insilmaril@0: // Overloaded from LinkableMapObj insilmaril@0: // BranchObj can use color of heading insilmaril@0: insilmaril@721: if (model) insilmaril@611: { insilmaril@721: if (model->getMapLinkColorHint()==HeadingColor) insilmaril@164: LinkableMapObj::setLinkColor (heading->getColor() ); insilmaril@164: else insilmaril@164: LinkableMapObj::setLinkColor (); insilmaril@611: } insilmaril@0: } insilmaril@0: insilmaril@417: void BranchObj::setColorSubtree(QColor col) insilmaril@0: { insilmaril@638: setColor (col); insilmaril@750: for (int i=0; ibranchCount(); ++i) insilmaril@417: branch.at(i)->setColorSubtree(col); insilmaril@100: } insilmaril@0: insilmaril@333: void BranchObj::positionContents() insilmaril@333: { insilmaril@404: for (int i=0; ireposition(); insilmaril@333: OrnamentedObj::positionContents(); insilmaril@333: } insilmaril@0: insilmaril@0: void BranchObj::move (double x, double y) insilmaril@0: { insilmaril@0: OrnamentedObj::move (x,y); insilmaril@404: for (int i=0; ireposition(); insilmaril@0: positionBBox(); insilmaril@0: } insilmaril@0: insilmaril@408: void BranchObj::move (QPointF p) insilmaril@0: { insilmaril@0: move (p.x(), p.y()); insilmaril@0: } insilmaril@0: insilmaril@0: void BranchObj::moveBy (double x, double y) insilmaril@0: { insilmaril@0: OrnamentedObj::moveBy (x,y); insilmaril@750: for (int i=0; ibranchCount(); ++i) insilmaril@406: branch.at(i)->moveBy (x,y); insilmaril@333: positionBBox(); insilmaril@0: } insilmaril@83: insilmaril@408: void BranchObj::moveBy (QPointF p) insilmaril@0: { insilmaril@0: moveBy (p.x(), p.y()); insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: void BranchObj::positionBBox() insilmaril@0: { insilmaril@408: QPointF ap=getAbsPos(); insilmaril@223: bbox.moveTopLeft (ap); insilmaril@169: positionContents(); insilmaril@0: insilmaril@0: // set the frame insilmaril@408: frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) ); insilmaril@83: insilmaril@83: // Update links to other branches insilmaril@406: for (int i=0; iupdateXLink(); insilmaril@0: } insilmaril@0: insilmaril@0: void BranchObj::calcBBoxSize() insilmaril@0: { insilmaril@408: QSizeF heading_r=heading->getSize(); insilmaril@408: qreal heading_w=(qreal) heading_r.width() ; insilmaril@408: qreal heading_h=(qreal) heading_r.height() ; insilmaril@408: QSizeF sysflags_r=systemFlags->getSize(); insilmaril@408: qreal sysflags_h=sysflags_r.height(); insilmaril@408: qreal sysflags_w=sysflags_r.width(); insilmaril@408: QSizeF stanflags_r=standardFlags->getSize(); insilmaril@408: qreal stanflags_h=stanflags_r.height(); insilmaril@408: qreal stanflags_w=stanflags_r.width(); insilmaril@408: qreal w; insilmaril@408: qreal h; insilmaril@0: insilmaril@0: // set width to sum of all widths insilmaril@0: w=heading_w + sysflags_w + stanflags_w; insilmaril@0: // set height to maximum needed height insilmaril@0: h=max (sysflags_h,stanflags_h); insilmaril@0: h=max (h,heading_h); insilmaril@0: insilmaril@223: // Save the dimension of flags and heading insilmaril@408: ornamentsBBox.setSize ( QSizeF(w,h)); insilmaril@223: insilmaril@223: // clickBox includes Flags and Heading insilmaril@223: clickBox.setSize (ornamentsBBox.size() ); insilmaril@169: insilmaril@169: // Floatimages insilmaril@408: QPointF rp; insilmaril@169: insilmaril@169: topPad=botPad=leftPad=rightPad=0; insilmaril@169: if (includeImagesVer || includeImagesHor) insilmaril@169: { insilmaril@749: if (treeItem->imageCount()>0) insilmaril@169: { insilmaril@404: for (int i=0; igetRelPos(); insilmaril@169: if (includeImagesVer) insilmaril@169: { insilmaril@169: if (rp.y() < 0) insilmaril@223: topPad=max (topPad,-rp.y()-h); insilmaril@404: if (rp.y()+floatimage.at(i)->height() > 0) insilmaril@404: botPad=max (botPad,rp.y()+floatimage.at(i)->height()); insilmaril@169: } insilmaril@213: if (includeImagesHor) insilmaril@213: { insilmaril@462: if (orientation==LinkableMapObj::RightOfCenter) insilmaril@223: { insilmaril@223: if (-rp.x()-w > 0) insilmaril@223: leftPad=max (leftPad,-rp.x()-w); insilmaril@404: if (rp.x()+floatimage.at(i)->width() > 0) insilmaril@404: rightPad=max (rightPad,rp.x()+floatimage.at(i)->width()); insilmaril@223: } else insilmaril@223: { insilmaril@223: if (rp.x()< 0) insilmaril@223: leftPad=max (leftPad,-rp.x()); insilmaril@404: if (rp.x()+floatimage.at(i)->width() > w) insilmaril@404: rightPad=max (rightPad,rp.x()+floatimage.at(i)->width()-w); insilmaril@223: } insilmaril@213: } insilmaril@169: } insilmaril@169: } insilmaril@169: h+=topPad+botPad; insilmaril@213: w+=leftPad+rightPad; insilmaril@169: } insilmaril@169: insilmaril@169: // Frame thickness insilmaril@462: w+=frame->getPadding(); insilmaril@462: h+=frame->getPadding(); insilmaril@169: insilmaril@169: // Finally set size insilmaril@408: bbox.setSize (QSizeF (w,h)); insilmaril@0: } insilmaril@0: insilmaril@223: void BranchObj::setDockPos() insilmaril@223: { insilmaril@382: // Sets childpos and parpos depending on orientation insilmaril@462: if (getOrientation()==LinkableMapObj::LeftOfCenter ) insilmaril@223: { insilmaril@440: childPos=QPointF ( insilmaril@440: ornamentsBBox.bottomLeft().x(), insilmaril@440: bottomlineY); insilmaril@440: parPos=QPointF ( insilmaril@440: ornamentsBBox.bottomRight().x(), insilmaril@440: bottomlineY); insilmaril@223: } else insilmaril@223: { insilmaril@440: childPos=QPointF ( insilmaril@440: ornamentsBBox.bottomRight().x(), insilmaril@440: bottomlineY); insilmaril@440: parPos=QPointF ( insilmaril@440: ornamentsBBox.bottomLeft().x(), insilmaril@440: bottomlineY); insilmaril@223: } insilmaril@223: } insilmaril@382: insilmaril@408: LinkableMapObj* BranchObj::findMapObj(QPointF p, LinkableMapObj* excludeLMO) insilmaril@0: { insilmaril@0: // Search branches insilmaril@0: LinkableMapObj *lmo; insilmaril@750: for (int i=0; ibranchCount(); ++i) insilmaril@0: { insilmaril@406: lmo=branch.at(i)->findMapObj(p, excludeLMO); insilmaril@0: if (lmo != NULL) return lmo; insilmaril@0: } insilmaril@0: insilmaril@593: insilmaril@0: // Search myself insilmaril@643: if (inBox (p,clickBox) && (this != excludeLMO) && isVisibleObj() ) insilmaril@0: return this; insilmaril@0: insilmaril@0: // Search float images insilmaril@404: for (int i=0; igetClickBox()) && insilmaril@404: (floatimage.at(i) != excludeLMO) && insilmaril@404: floatimage.at(i)->getParObj()!= excludeLMO && insilmaril@404: floatimage.at(i)->isVisibleObj() insilmaril@404: ) return floatimage.at(i); insilmaril@0: insilmaril@0: return NULL; insilmaril@0: } insilmaril@0: insilmaril@529: LinkableMapObj* BranchObj::findID (QString sid) insilmaril@529: { insilmaril@529: // Search branches insilmaril@529: LinkableMapObj *lmo; insilmaril@750: for (int i=0; ibranchCount(); ++i) insilmaril@529: { insilmaril@529: lmo=branch.at(i)->findID (sid); insilmaril@529: if (lmo != NULL) return lmo; insilmaril@529: } insilmaril@529: insilmaril@529: // Search myself insilmaril@593: if (sid==objID) return this; insilmaril@593: insilmaril@529: insilmaril@529: /* insilmaril@529: // Search float images insilmaril@529: for (int i=0; iinBox(p) && insilmaril@529: (floatimage.at(i) != excludeLMO) && insilmaril@529: floatimage.at(i)->getParObj()!= excludeLMO && insilmaril@529: floatimage.at(i)->isVisibleObj() insilmaril@529: ) return floatimage.at(i); insilmaril@529: */ insilmaril@529: return NULL; insilmaril@529: } insilmaril@529: insilmaril@0: void BranchObj::setHeading(QString s) insilmaril@0: { insilmaril@0: heading->setText(s); // set new heading insilmaril@0: calcBBoxSize(); // recalculate bbox insilmaril@0: positionBBox(); // rearrange contents insilmaril@0: requestReposition(); insilmaril@0: } insilmaril@0: insilmaril@254: void BranchObj::setHideTmp (HideTmpMode mode) insilmaril@254: { insilmaril@628: if (mode==HideExport && (hideExport|| hasHiddenExportParent() ) ) insilmaril@254: { insilmaril@628: // Hide stuff according to hideExport flag and parents insilmaril@254: setVisibility (false); insilmaril@254: hidden=true; insilmaril@254: }else insilmaril@254: { insilmaril@628: // Do not hide, but still take care of scrolled status insilmaril@749: if ( ((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem)) insilmaril@301: setVisibility (false); insilmaril@301: else insilmaril@301: setVisibility (true); insilmaril@254: hidden=false; insilmaril@254: } insilmaril@254: insilmaril@721: // And take care of my children insilmaril@750: for (int i=0; ibranchCount(); ++i) insilmaril@406: branch.at(i)->setHideTmp (mode); insilmaril@254: } insilmaril@254: insilmaril@598: bool BranchObj::hasHiddenExportParent() insilmaril@254: { insilmaril@254: // Calls parents recursivly to insilmaril@628: // find out, if we or parents are temp. hidden insilmaril@254: insilmaril@628: if (hidden || hideExport) return true; insilmaril@254: insilmaril@598: BranchObj* bo=(BranchObj*)parObj; insilmaril@254: if (bo) insilmaril@598: return bo->hasHiddenExportParent(); insilmaril@254: else insilmaril@254: return false; insilmaril@254: } insilmaril@254: insilmaril@408: QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset) insilmaril@0: { insilmaril@417: // Cloudy stuff can be hidden during exports insilmaril@254: if (hidden) return ""; insilmaril@254: insilmaril@417: // Update of note is usually done while unselecting a branch insilmaril@746: // if (isNoteInEditor) getNoteFromTextEditor(); //FIXME-2 moved to TreeItem insilmaril@417: insilmaril@0: QString s,a; insilmaril@0: QString scrolledAttr; insilmaril@749: if ( ((BranchItem*)treeItem)->isScrolled() ) insilmaril@0: scrolledAttr=attribut ("scrolled","yes"); insilmaril@0: else insilmaril@0: scrolledAttr=""; insilmaril@0: insilmaril@0: // save area, if not scrolled insilmaril@0: QString areaAttr; insilmaril@749: if (!((BranchItem*) (treeItem->parent()) )->isScrolled() ) insilmaril@0: { insilmaril@0: areaAttr= insilmaril@408: attribut("x1",QString().setNum(absPos.x()-offset.x())) + insilmaril@408: attribut("y1",QString().setNum(absPos.y()-offset.y())) + insilmaril@408: attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) + insilmaril@408: attribut("y2",QString().setNum(absPos.y()+height()-offset.y())); insilmaril@0: insilmaril@0: } else insilmaril@0: areaAttr=""; insilmaril@0: insilmaril@169: // Providing an ID for a branch makes export to XHTML easier insilmaril@169: QString idAttr; insilmaril@749: if (treeItem->xlinkCount()>0) insilmaril@723: idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model insilmaril@169: else insilmaril@169: idAttr=""; insilmaril@169: insilmaril@239: s=beginElement ("branch" insilmaril@628: +getOrnXMLAttr() insilmaril@239: +scrolledAttr insilmaril@239: +areaAttr insilmaril@239: +idAttr insilmaril@239: +getIncludeImageAttr() ); insilmaril@0: incIndent(); insilmaril@0: insilmaril@0: // save heading insilmaril@160: s+=valueElement("heading", getHeading(), insilmaril@0: attribut ("textColor",QColor(heading->getColor()).name())); insilmaril@0: insilmaril@421: // Save frame insilmaril@462: if (frame->getFrameType()!=FrameObj::NoFrame) insilmaril@421: s+=frame->saveToDir (); insilmaril@421: insilmaril@0: // save names of flags set insilmaril@0: s+=standardFlags->saveToDir(tmpdir,prefix,0); insilmaril@0: insilmaril@364: // Save FloatImages insilmaril@404: for (int i=0; isaveToDir (tmpdir,prefix); insilmaril@364: insilmaril@0: // save note insilmaril@746: if (!treeItem->getNoteObj().isEmpty() ) insilmaril@746: s+=treeItem->getNoteObj().saveToDir(); insilmaril@0: insilmaril@0: // Save branches insilmaril@750: for (int i=0; ibranchCount(); ++i) insilmaril@406: s+=branch.at(i)->saveToDir(tmpdir,prefix,offset); insilmaril@0: insilmaril@95: // Save XLinks insilmaril@345: QString ol; // old link insilmaril@345: QString cl; // current link insilmaril@406: for (int i=0; isaveToDir(); insilmaril@345: if (cl!=ol) insilmaril@345: { insilmaril@345: s+=cl; insilmaril@345: ol=cl; insilmaril@345: } else insilmaril@345: { insilmaril@345: qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading())); insilmaril@345: } insilmaril@345: } insilmaril@95: insilmaril@95: decIndent(); insilmaril@0: s+=endElement ("branch"); insilmaril@0: return s; insilmaril@0: } insilmaril@0: insilmaril@95: void BranchObj::addXLink (XLinkObj *xlo) insilmaril@83: { insilmaril@95: xlink.append (xlo); insilmaril@83: insilmaril@83: } insilmaril@83: insilmaril@95: void BranchObj::removeXLinkRef (XLinkObj *xlo) insilmaril@83: { insilmaril@406: xlink.removeAt (xlink.indexOf(xlo)); insilmaril@83: } insilmaril@83: insilmaril@95: void BranchObj::deleteXLink(XLinkObj *xlo) insilmaril@83: { insilmaril@95: xlo->deactivate(); insilmaril@95: if (!xlo->isUsed()) delete (xlo); insilmaril@83: } insilmaril@83: insilmaril@95: void BranchObj::deleteXLinkAt (int i) insilmaril@94: { insilmaril@95: XLinkObj *xlo=xlink.at(i); insilmaril@95: xlo->deactivate(); insilmaril@95: if (!xlo->isUsed()) delete(xlo); insilmaril@94: } insilmaril@94: insilmaril@97: XLinkObj* BranchObj::XLinkAt (int i) insilmaril@97: { insilmaril@97: return xlink.at(i); insilmaril@97: } insilmaril@97: insilmaril@95: BranchObj* BranchObj::XLinkTargetAt (int i) insilmaril@89: { insilmaril@406: if (i>=0 && iotherBranch (this); insilmaril@406: } insilmaril@406: return NULL; insilmaril@89: } insilmaril@89: insilmaril@169: void BranchObj::setIncludeImagesVer(bool b) insilmaril@169: { insilmaril@169: includeImagesVer=b; insilmaril@169: calcBBoxSize(); insilmaril@169: positionBBox(); insilmaril@169: requestReposition(); insilmaril@169: } insilmaril@169: insilmaril@169: bool BranchObj::getIncludeImagesVer() insilmaril@169: { insilmaril@169: return includeImagesVer; insilmaril@169: } insilmaril@169: insilmaril@169: void BranchObj::setIncludeImagesHor(bool b) insilmaril@169: { insilmaril@169: includeImagesHor=b; insilmaril@169: calcBBoxSize(); insilmaril@169: positionBBox(); insilmaril@169: requestReposition(); insilmaril@169: } insilmaril@169: insilmaril@169: bool BranchObj::getIncludeImagesHor() insilmaril@169: { insilmaril@169: return includeImagesHor; insilmaril@169: } insilmaril@169: insilmaril@169: QString BranchObj::getIncludeImageAttr() insilmaril@169: { insilmaril@169: QString a; insilmaril@169: if (includeImagesVer) insilmaril@169: a=attribut ("incImgV","true"); insilmaril@169: else insilmaril@169: a=attribut ("incImgV","false"); insilmaril@169: if (includeImagesHor) insilmaril@213: a+=attribut ("incImgH","true"); insilmaril@169: else insilmaril@213: a+=attribut ("incImgH","false"); insilmaril@169: return a; insilmaril@169: } insilmaril@169: insilmaril@395: FloatImageObj* BranchObj::addFloatImage () insilmaril@0: { insilmaril@408: FloatImageObj *newfi=new FloatImageObj (scene,this); insilmaril@0: floatimage.append (newfi); insilmaril@749: if ( ((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) ) insilmaril@0: newfi->setVisibility (false); insilmaril@0: else insilmaril@0: newfi->setVisibility(visible); insilmaril@395: /* insilmaril@169: calcBBoxSize(); insilmaril@169: positionBBox(); insilmaril@395: */ insilmaril@0: requestReposition(); insilmaril@0: return newfi; insilmaril@0: } insilmaril@0: insilmaril@395: FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio) insilmaril@0: { insilmaril@408: FloatImageObj *newfi=new FloatImageObj (scene,this); insilmaril@0: floatimage.append (newfi); insilmaril@0: newfi->copy (fio); insilmaril@749: if (((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) ) insilmaril@0: newfi->setVisibility (false); insilmaril@0: else insilmaril@0: newfi->setVisibility(visible); insilmaril@395: /* insilmaril@169: calcBBoxSize(); insilmaril@169: positionBBox(); insilmaril@395: */ insilmaril@0: requestReposition(); insilmaril@0: return newfi; insilmaril@0: } insilmaril@0: insilmaril@0: FloatImageObj* BranchObj::getFirstFloatImage () insilmaril@0: { insilmaril@0: return floatimage.first(); insilmaril@0: } insilmaril@0: insilmaril@0: FloatImageObj* BranchObj::getLastFloatImage () insilmaril@0: { insilmaril@0: return floatimage.last(); insilmaril@0: } insilmaril@0: insilmaril@0: FloatImageObj* BranchObj::getFloatImageNum (const uint &i) insilmaril@0: { insilmaril@0: return floatimage.at(i); insilmaril@0: } insilmaril@0: insilmaril@0: void BranchObj::removeFloatImage (FloatImageObj *fio) insilmaril@0: { insilmaril@404: int i=floatimage.indexOf (fio); insilmaril@411: if (i>-1) delete (floatimage.takeAt (i)); insilmaril@169: calcBBoxSize(); insilmaril@169: positionBBox(); insilmaril@0: requestReposition(); insilmaril@0: } insilmaril@0: insilmaril@0: void BranchObj::savePosInAngle () insilmaril@0: { insilmaril@0: // Save position in angle insilmaril@750: for (int i=0; ibranchCount(); ++i) insilmaril@406: branch.at(i)->angle=i; insilmaril@0: } insilmaril@0: insilmaril@146: void BranchObj::setDefAttr (BranchModification mod) insilmaril@146: { insilmaril@146: int fontsize; insilmaril@146: switch (depth) insilmaril@146: { insilmaril@146: case 0: fontsize=16; break; insilmaril@146: case 1: fontsize=12; break; insilmaril@146: default: fontsize=10; break; insilmaril@146: } insilmaril@146: insilmaril@146: setLinkColor (); insilmaril@146: setLinkStyle(getDefLinkStyle()); insilmaril@146: QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0"); insilmaril@146: font.setPointSize(fontsize); insilmaril@146: heading->setFont(font ); insilmaril@146: insilmaril@146: if (mod==NewBranch) insilmaril@239: setColor (((BranchObj*)(parObj))->getColor()); insilmaril@146: insilmaril@146: calcBBoxSize(); insilmaril@146: } insilmaril@146: insilmaril@0: BranchObj* BranchObj::addBranch() insilmaril@0: { insilmaril@408: BranchObj* newbo=new BranchObj(scene,this); insilmaril@0: branch.append (newbo); insilmaril@0: newbo->setParObj(this); insilmaril@146: newbo->setDefAttr(NewBranch); insilmaril@0: newbo->setHeading ("new"); insilmaril@749: /* FIXME-2 treeItem not set yet!!! insilmaril@749: if ( ((BranchItem*)treeItem)->isScrolled() ) insilmaril@0: newbo->setVisibility (false); insilmaril@0: else insilmaril@0: newbo->setVisibility(visible); insilmaril@749: */ insilmaril@93: newbo->updateLink(); insilmaril@0: requestReposition(); insilmaril@0: return newbo; insilmaril@0: } insilmaril@0: insilmaril@0: BranchObj* BranchObj::addBranch(BranchObj* bo) insilmaril@0: { insilmaril@408: BranchObj* newbo=new BranchObj(scene,this); insilmaril@0: branch.append (newbo); insilmaril@0: newbo->copy(bo); insilmaril@0: newbo->setParObj(this); insilmaril@162: newbo->setDefAttr(MovedBranch); insilmaril@749: if ( ((BranchItem*)treeItem)->isScrolled() ) insilmaril@0: newbo->setVisibility (false); insilmaril@0: else insilmaril@0: newbo->setVisibility(bo->visible); insilmaril@93: newbo->updateLink(); insilmaril@0: requestReposition(); insilmaril@0: return newbo; insilmaril@0: } insilmaril@0: insilmaril@83: BranchObj* BranchObj::addBranchPtr(BranchObj* bo) insilmaril@83: { insilmaril@83: branch.append (bo); insilmaril@83: bo->setParObj (this); insilmaril@83: bo->depth=depth+1; insilmaril@146: bo->setDefAttr(MovedBranch); insilmaril@749: BranchItem *bi=(BranchItem*)treeItem; insilmaril@749: if ( bi->isScrolled() ) bi->tmpUnscroll(); insilmaril@746: //setLastSelectedBranch (bo); //FIXME-3 needed? insilmaril@83: return bo; insilmaril@83: } insilmaril@83: insilmaril@0: BranchObj* BranchObj::insertBranch(int pos) insilmaril@0: { insilmaril@0: savePosInAngle(); insilmaril@0: // Add new bo and resort branches insilmaril@0: BranchObj *newbo=addBranch (); insilmaril@0: newbo->angle=pos-0.5; insilmaril@411: qSort (branch.begin(),branch.end(), isAbove); insilmaril@0: return newbo; insilmaril@0: } insilmaril@0: insilmaril@0: BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos) insilmaril@0: { insilmaril@0: savePosInAngle(); insilmaril@0: // Add new bo and resort branches insilmaril@0: bo->angle=pos-0.5; insilmaril@0: BranchObj *newbo=addBranch (bo); insilmaril@411: qSort (branch.begin(),branch.end(), isAbove); insilmaril@0: return newbo; insilmaril@0: } insilmaril@0: insilmaril@83: BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos) insilmaril@83: { insilmaril@83: savePosInAngle(); insilmaril@83: // Add new bo and resort branches insilmaril@83: bo->angle=pos-0.5; insilmaril@83: branch.append (bo); insilmaril@83: bo->setParObj (this); insilmaril@83: bo->depth=depth+1; insilmaril@146: bo->setDefAttr (MovedBranch); insilmaril@749: BranchItem *bi=(BranchItem*)treeItem; insilmaril@749: if ( bi->isScrolled() ) bi->tmpUnscroll(); insilmaril@746: //setLastSelectedBranch (bo); //FIXME-3 needed? insilmaril@411: qSort (branch.begin(),branch.end(), isAbove); insilmaril@83: return bo; insilmaril@83: } insilmaril@83: insilmaril@749: void BranchObj::removeBranchHere(BranchObj* borem) // FIXME-1 getNum no longer available insilmaril@98: { insilmaril@749: /* insilmaril@98: // This removes the branch bo from list, but insilmaril@721: // inserts its children at the place of bo insilmaril@98: BranchObj *bo; insilmaril@98: bo=borem->getLastBranch(); insilmaril@139: int pos=borem->getNum(); insilmaril@98: while (bo) insilmaril@98: { insilmaril@421: bo->linkTo (this,pos+1); insilmaril@98: bo=borem->getLastBranch(); insilmaril@98: } insilmaril@98: removeBranch (borem); insilmaril@749: */ insilmaril@98: } insilmaril@98: insilmaril@721: void BranchObj::removeChildren() insilmaril@98: { insilmaril@98: clear(); insilmaril@98: } insilmaril@98: insilmaril@0: void BranchObj::removeBranch(BranchObj* bo) insilmaril@0: { insilmaril@0: // if bo is not in branch remove returns false, we insilmaril@0: // don't care... insilmaril@83: insilmaril@406: int i=branch.indexOf(bo); insilmaril@406: if (i>=0) insilmaril@406: { insilmaril@83: delete (bo); insilmaril@406: branch.removeAt (i); insilmaril@406: } else insilmaril@83: qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n"); insilmaril@83: requestReposition(); insilmaril@83: } insilmaril@83: insilmaril@83: void BranchObj::removeBranchPtr(BranchObj* bo) insilmaril@83: { insilmaril@406: int i=branch.indexOf(bo); insilmaril@406: insilmaril@406: if (i>=0) insilmaril@406: branch.removeAt (i); insilmaril@406: else insilmaril@406: qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n"); insilmaril@0: requestReposition(); insilmaril@0: } insilmaril@0: insilmaril@310: bool BranchObj::canMoveBranchUp() insilmaril@310: { insilmaril@750: /* FIXME-1 move to BranchItem insilmaril@364: if (!parObj || depth==1) return false; insilmaril@310: BranchObj* par=(BranchObj*)parObj; insilmaril@750: if (this==par->getTreeItem()->getFirstBranch()) insilmaril@310: return false; insilmaril@310: else insilmaril@310: return true; insilmaril@750: */ insilmaril@750: return false; insilmaril@310: } insilmaril@0: insilmaril@364: BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // modify my childlist insilmaril@0: { insilmaril@0: savePosInAngle(); insilmaril@406: int i=branch.indexOf(bo1); insilmaril@0: if (i>0) insilmaril@0: { // -1 if bo1 not found insilmaril@0: branch.at(i)->angle--; insilmaril@0: branch.at(i-1)->angle++; insilmaril@411: qSort (branch.begin(),branch.end(), isAbove); insilmaril@364: return branch.at(i); insilmaril@0: } else insilmaril@364: return NULL; insilmaril@0: } insilmaril@0: insilmaril@310: bool BranchObj::canMoveBranchDown() insilmaril@310: { insilmaril@750: /* FIXME-1 move to BranchItem insilmaril@364: if (!parObj|| depth==1) return false; insilmaril@310: BranchObj* par=(BranchObj*)parObj; insilmaril@750: if (this==par->getTreeItem()->getLastBranch()) insilmaril@310: return false; insilmaril@310: else insilmaril@310: return true; insilmaril@750: */ insilmaril@750: return false; insilmaril@310: } insilmaril@310: insilmaril@364: BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// modify my childlist insilmaril@0: { insilmaril@0: savePosInAngle(); insilmaril@406: int i=branch.indexOf(bo1); insilmaril@0: int j; insilmaril@750: if (i branchCount()) insilmaril@0: { insilmaril@406: j = i+1; insilmaril@0: branch.at(i)->angle++; insilmaril@0: branch.at(j)->angle--; insilmaril@411: qSort (branch.begin(),branch.end(), isAbove); insilmaril@364: return branch.at(i); insilmaril@0: } else insilmaril@364: return NULL; insilmaril@0: } insilmaril@0: insilmaril@749: void BranchObj::sortChildren() //FIXME-1 insilmaril@604: { insilmaril@749: /* insilmaril@749: int childCount=branch.count(); insilmaril@604: int curChildIndex; insilmaril@604: bool madeChanges=false; insilmaril@604: do insilmaril@604: { insilmaril@604: madeChanges=false; insilmaril@604: for(curChildIndex=1;curChildIndexheading->text().compare(curChild->heading->text())>0) insilmaril@604: { insilmaril@604: this->moveBranchUp(curChild); insilmaril@604: madeChanges=true; insilmaril@604: } insilmaril@604: } insilmaril@604: }while(madeChanges); insilmaril@749: */ insilmaril@604: } insilmaril@604: insilmaril@604: insilmaril@421: BranchObj* BranchObj::linkTo (BranchObj* dst, int pos) insilmaril@83: { insilmaril@83: // Find current parent and insilmaril@83: // remove pointer to myself there insilmaril@94: if (!dst) return NULL; insilmaril@364: BranchObj *par=(BranchObj*)parObj; insilmaril@83: if (par) insilmaril@83: par->removeBranchPtr (this); insilmaril@83: else insilmaril@83: return NULL; insilmaril@83: insilmaril@129: // Create new pointer to myself at dst insilmaril@98: if (pos<0||dst->getDepth()==0) insilmaril@83: { insilmaril@98: // links myself as last branch at dst insilmaril@83: dst->addBranchPtr (this); insilmaril@151: updateLink(); insilmaril@83: return this; insilmaril@83: } else insilmaril@83: { insilmaril@83: // inserts me at pos in parent of dst insilmaril@83: if (par) insilmaril@139: { insilmaril@139: BranchObj *bo=dst->insertBranchPtr (this,pos); insilmaril@146: bo->setDefAttr(MovedBranch); insilmaril@151: updateLink(); insilmaril@139: return bo; insilmaril@139: insilmaril@139: } else insilmaril@83: return NULL; insilmaril@83: } insilmaril@83: } insilmaril@83: insilmaril@721: void BranchObj::alignRelativeTo (QPointF ref,bool alignSelf) insilmaril@0: { insilmaril@408: qreal th = bboxTotal.height(); insilmaril@223: // TODO testing insilmaril@223: /* insilmaril@688: QPointF pp; if (parObj) pp=parObj->getChildPos(); insilmaril@688: cout << "BO::alignRelTo "<