insilmaril@0: #include "branchobj.h" insilmaril@616: insilmaril@616: // #include "texteditor.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@0: BranchObj* BranchObj::itLast=NULL; insilmaril@364: BranchObj* BranchObj::itFirst=NULL; insilmaril@0: insilmaril@0: insilmaril@0: BranchObj::BranchObj () :OrnamentedObj() 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@425: //cout << "Destr BranchObj of "<getLastBranch(); insilmaril@425: if (bo) po->unScroll(); insilmaril@0: } 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@408: lastSelectedBranch=0; insilmaril@0: insilmaril@0: setChildObj(this); insilmaril@0: insilmaril@0: scrolled=false; insilmaril@0: tmpUnscrolled=false; 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@406: for (int i=0; ibranch.size(); ++i) insilmaril@0: // Make deep copy of b insilmaril@0: // Because addBranch again calls copy for the childs, 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@0: scrolled=other->scrolled; insilmaril@0: tmpUnscrolled=other->tmpUnscrolled; 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@0: int BranchObj::getNum() insilmaril@0: { insilmaril@0: if (parObj) insilmaril@364: return ((BranchObj*)parObj)->getNum (this); insilmaril@0: else insilmaril@0: return 0; insilmaril@0: } insilmaril@0: insilmaril@0: int BranchObj::getNum(BranchObj *bo) insilmaril@0: { insilmaril@406: return branch.indexOf (bo); insilmaril@0: } insilmaril@0: insilmaril@0: int BranchObj::getFloatImageNum(FloatImageObj *fio) insilmaril@0: { insilmaril@404: return floatimage.indexOf(fio); insilmaril@0: } insilmaril@0: insilmaril@0: int BranchObj::countBranches() insilmaril@0: { insilmaril@0: return branch.count(); insilmaril@0: } insilmaril@0: insilmaril@0: int BranchObj::countFloatImages() insilmaril@0: { insilmaril@0: return floatimage.count(); insilmaril@0: } insilmaril@0: insilmaril@95: int BranchObj::countXLinks() insilmaril@89: { insilmaril@95: return xlink.count(); insilmaril@89: } insilmaril@89: 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@408: QRectF t=o->getBBoxSizeWithChilds(); insilmaril@0: if (o->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::unScroll() insilmaril@0: { insilmaril@0: if (tmpUnscrolled) resetTmpUnscroll(); insilmaril@0: if (scrolled) toggleScroll(); insilmaril@0: } insilmaril@0: insilmaril@0: void BranchObj::toggleScroll() insilmaril@0: { insilmaril@0: if (scrolled) insilmaril@0: { insilmaril@0: scrolled=false; insilmaril@0: systemFlags->deactivate("scrolledright"); insilmaril@406: for (int i=0; isetVisibility(true); insilmaril@0: } else insilmaril@0: { insilmaril@0: scrolled=true; insilmaril@0: systemFlags->activate("scrolledright"); insilmaril@406: for (int i=0; isetVisibility(false); insilmaril@0: } insilmaril@0: calcBBoxSize(); insilmaril@0: positionBBox(); insilmaril@0: move (absPos.x(), absPos.y() ); insilmaril@0: forceReposition(); insilmaril@0: } insilmaril@0: insilmaril@0: bool BranchObj::isScrolled() insilmaril@0: { insilmaril@0: return scrolled; insilmaril@0: } insilmaril@0: insilmaril@0: bool BranchObj::hasScrolledParent(BranchObj *start) insilmaril@0: { insilmaril@0: // Calls parents recursivly to insilmaril@0: // find out, if we are scrolled at all. insilmaril@0: // But ignore myself, just look at parents. insilmaril@0: insilmaril@0: if (this !=start && scrolled) return true; insilmaril@0: insilmaril@0: BranchObj* bo=(BranchObj*)(parObj); insilmaril@0: if (bo) insilmaril@0: return bo->hasScrolledParent(start); insilmaril@0: else insilmaril@0: return false; insilmaril@0: } insilmaril@0: insilmaril@0: void BranchObj::tmpUnscroll() insilmaril@0: { insilmaril@0: // Unscroll parent (recursivly) insilmaril@0: BranchObj* bo=(BranchObj*)(parObj); insilmaril@0: if (bo) bo->tmpUnscroll(); insilmaril@0: insilmaril@0: // Unscroll myself insilmaril@0: if (scrolled) insilmaril@0: { insilmaril@0: tmpUnscrolled=true; insilmaril@0: systemFlags->activate("tmpUnscrolledright"); insilmaril@0: toggleScroll(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void BranchObj::resetTmpUnscroll() insilmaril@0: { insilmaril@0: // Unscroll parent (recursivly) insilmaril@0: BranchObj* bo=(BranchObj*)(parObj); insilmaril@0: if (bo) insilmaril@0: bo->resetTmpUnscroll(); insilmaril@0: insilmaril@0: // Unscroll myself insilmaril@0: if (tmpUnscrolled) insilmaril@0: { insilmaril@0: tmpUnscrolled=false; insilmaril@0: systemFlags->deactivate("tmpUnscrolledright"); insilmaril@0: toggleScroll(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void BranchObj::setVisibility(bool v, int toDepth) insilmaril@0: { 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@0: insilmaril@254: // Only change childs, if I am not scrolled insilmaril@0: if (!scrolled && (depth < toDepth)) insilmaril@0: { insilmaril@0: // Now go recursivly through all childs insilmaril@406: int i; insilmaril@406: for (i=0; isetVisibility (v,toDepth); insilmaril@406: for (i=0; isetVisibility (v); insilmaril@406: for (i=0; isetVisibility (); 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@164: if (mapEditor) insilmaril@611: { insilmaril@398: if (mapEditor->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@406: for (int i=0; isetColorSubtree(col); insilmaril@100: } insilmaril@0: insilmaril@0: BranchObj* BranchObj::first() insilmaril@0: { insilmaril@0: itLast=NULL; insilmaril@364: itFirst=this; insilmaril@0: return this; insilmaril@0: } insilmaril@0: insilmaril@0: BranchObj* BranchObj::next() insilmaril@0: { insilmaril@406: BranchObj *bo; insilmaril@0: BranchObj *lmo; insilmaril@406: BranchObj *po=(BranchObj*)parObj; insilmaril@406: insilmaril@406: if (branch.isEmpty()) insilmaril@406: bo=NULL; insilmaril@406: else insilmaril@406: bo=branch.first(); insilmaril@0: insilmaril@0: if (!itLast) insilmaril@364: { insilmaril@406: // no itLast, we are just beginning insilmaril@0: if (bo) insilmaril@406: { insilmaril@406: // we have childs, return first one insilmaril@0: itLast=this; insilmaril@0: return bo; insilmaril@0: } insilmaril@0: else insilmaril@0: { insilmaril@406: // No childs, so there is no next insilmaril@364: itLast=this; insilmaril@0: return NULL; insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@406: // We have an itLast insilmaril@406: if (itLast==po) insilmaril@406: { // We come from parent insilmaril@0: if (bo) insilmaril@0: { insilmaril@0: // there are childs, go there insilmaril@0: itLast=this; insilmaril@0: return bo; insilmaril@0: } insilmaril@0: else insilmaril@0: { // no childs, try to go up again insilmaril@0: if (po) insilmaril@0: { insilmaril@406: // go back to parent and try to find next there insilmaril@0: itLast=this; insilmaril@0: lmo=po->next(); insilmaril@0: itLast=this; insilmaril@0: return lmo; insilmaril@0: insilmaril@0: } insilmaril@0: else insilmaril@0: { insilmaril@406: // can't go up, I am mapCenter, no next insilmaril@0: itLast=NULL; insilmaril@0: return NULL; insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@406: // We don't come from parent, but from brother or childs insilmaril@406: insilmaril@364: // Try to find last child, where we came from, in my own childs insilmaril@0: bool searching=true; insilmaril@406: int i=0; insilmaril@406: while (inext(); insilmaril@0: itLast=this; insilmaril@0: return lmo; insilmaril@0: } insilmaril@0: else insilmaril@0: { insilmaril@0: // can't go up, I am mapCenter insilmaril@0: itLast=NULL; insilmaril@0: return NULL; insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: // couldn't find last child, it must be a nephew of mine insilmaril@406: if (branch.size()>0) insilmaril@0: { insilmaril@0: // proceed with my first child insilmaril@0: itLast=this; insilmaril@406: return branch.first(); insilmaril@0: } insilmaril@0: else insilmaril@0: { insilmaril@0: // or go back to my parents insilmaril@0: if (po) insilmaril@0: { insilmaril@0: // go up insilmaril@0: itLast=this; insilmaril@0: lmo=po->next(); insilmaril@0: itLast=this; insilmaril@0: return lmo; insilmaril@0: } insilmaril@0: else insilmaril@0: { insilmaril@0: // can't go up, I am mapCenter insilmaril@0: itLast=NULL; insilmaril@0: return NULL; insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: BranchObj* BranchObj::getLastIterator() insilmaril@0: { insilmaril@0: return itLast; insilmaril@0: } insilmaril@0: insilmaril@0: void BranchObj::setLastIterator(BranchObj* it) insilmaril@0: { insilmaril@0: itLast=it; insilmaril@0: } 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@406: for (int i=0; imoveBy (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@169: if (countFloatImages()>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@406: for (int i=0; ifindMapObj(p, excludeLMO); insilmaril@0: if (lmo != NULL) return lmo; insilmaril@0: } insilmaril@0: insilmaril@593: insilmaril@0: // Search myself insilmaril@169: if (inBox (p) && (this != excludeLMO) && isVisibleObj() ) insilmaril@0: return this; insilmaril@0: insilmaril@0: // Search float images insilmaril@404: for (int i=0; iinBox(p) && 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@529: for (int i=0; ifindID (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@301: if (hasScrolledParent(this)) insilmaril@301: setVisibility (false); insilmaril@301: else insilmaril@301: setVisibility (true); insilmaril@254: hidden=false; insilmaril@254: } insilmaril@254: insilmaril@628: // And take care of my childs insilmaril@406: for (int i=0; isetHideTmp (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@417: if (isNoteInEditor) getNoteFromTextEditor(); insilmaril@417: insilmaril@0: QString s,a; insilmaril@0: QString scrolledAttr; insilmaril@0: if (scrolled) 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@0: if (!((BranchObj*)(parObj))->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@169: if (countXLinks()>0) insilmaril@169: idAttr=attribut ("id",getSelectString()); 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@0: if (!note.isEmpty() ) insilmaril@0: s+=note.saveToDir(); insilmaril@0: insilmaril@0: // Save branches insilmaril@406: for (int i=0; isaveToDir(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: int BranchObj::countXLink() insilmaril@83: { insilmaril@95: return xlink.count(); insilmaril@83: } insilmaril@83: insilmaril@223: 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@0: if (hasScrolledParent(this) ) 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@0: if (hasScrolledParent(this) ) 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@406: for (int i=0; iangle=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@0: if (scrolled) insilmaril@0: newbo->setVisibility (false); insilmaril@0: else insilmaril@0: newbo->setVisibility(visible); 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@0: if (scrolled) 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@83: if (scrolled) tmpUnscroll(); insilmaril@83: setLastSelectedBranch (bo); 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@83: if (scrolled) tmpUnscroll(); insilmaril@83: setLastSelectedBranch (bo); insilmaril@411: qSort (branch.begin(),branch.end(), isAbove); insilmaril@83: return bo; insilmaril@83: } insilmaril@83: insilmaril@98: void BranchObj::removeBranchHere(BranchObj* borem) insilmaril@98: { insilmaril@98: // This removes the branch bo from list, but insilmaril@98: // inserts its childs 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@98: } insilmaril@98: insilmaril@98: void BranchObj::removeChilds() 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@0: void BranchObj::setLastSelectedBranch (BranchObj* bo) insilmaril@0: { insilmaril@406: lastSelectedBranch=branch.indexOf(bo); insilmaril@0: } insilmaril@0: insilmaril@0: BranchObj* BranchObj::getLastSelectedBranch () insilmaril@0: { insilmaril@417: if (lastSelectedBranch>=0) insilmaril@417: { insilmaril@417: if ( branch.size()>lastSelectedBranch) insilmaril@417: return branch.at(lastSelectedBranch); insilmaril@417: if (branch.size()>0) insilmaril@417: return branch.last(); insilmaril@417: } insilmaril@408: return NULL; insilmaril@0: } insilmaril@0: insilmaril@0: BranchObj* BranchObj::getFirstBranch () insilmaril@0: { insilmaril@408: if (branch.size()>0) insilmaril@408: return branch.first(); insilmaril@408: else insilmaril@408: return NULL; insilmaril@0: } insilmaril@0: insilmaril@0: BranchObj* BranchObj::getLastBranch () insilmaril@0: { insilmaril@408: if (branch.size()>0) insilmaril@408: return branch.last(); insilmaril@408: else insilmaril@408: return NULL; insilmaril@0: } insilmaril@0: insilmaril@406: BranchObj* BranchObj::getBranchNum (int i) insilmaril@0: { insilmaril@406: if (i>=0 && igetFirstBranch()) insilmaril@310: return false; insilmaril@310: else insilmaril@310: return true; 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@364: if (!parObj|| depth==1) return false; insilmaril@310: BranchObj* par=(BranchObj*)parObj; insilmaril@310: if (this==par->getLastBranch()) insilmaril@310: return false; insilmaril@310: else insilmaril@310: return true; 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@406: if (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@604: void BranchObj::sortChildren() insilmaril@604: { insilmaril@604: 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@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@408: void BranchObj::alignRelativeTo (QPointF ref) insilmaril@0: { insilmaril@408: qreal th = bboxTotal.height(); insilmaril@223: // TODO testing insilmaril@223: /* insilmaril@382: cout << "BO::alignRelTo "<