1.1 --- a/branchobj.cpp Sun Jan 30 12:58:47 2005 +0000
1.2 +++ b/branchobj.cpp Tue Jun 13 13:54:53 2006 +0000
1.3 @@ -24,13 +24,14 @@
1.4 depth=-1;
1.5 }
1.6
1.7 -BranchObj::BranchObj (QCanvas* c):OrnamentedObj (c)
1.8 +BranchObj::BranchObj (Q3Canvas* c):OrnamentedObj (c)
1.9 {
1.10 // cout << "Const BranchObj (c) called from MapCenterObj (c)\n";
1.11 + parObj=NULL;
1.12 canvas=c;
1.13 }
1.14
1.15 -BranchObj::BranchObj (QCanvas* c, LinkableMapObj* p):OrnamentedObj (c)
1.16 +BranchObj::BranchObj (Q3Canvas* c, LinkableMapObj* p):OrnamentedObj (c)
1.17 {
1.18 // cout << "Const BranchObj (c,p)\n";
1.19 canvas=c;
1.20 @@ -47,16 +48,18 @@
1.21
1.22 BranchObj::~BranchObj ()
1.23 {
1.24 - //cout << "Destr BranchObj\n";
1.25 +// cout << "Destr BranchObj of "<<this<<endl;
1.26 // Check, if this branch was the last child to be deleted
1.27 // If so, unset the scrolled flags
1.28
1.29 BranchObj *po=(BranchObj*)(parObj);
1.30 + BranchObj *bo;
1.31 if (po)
1.32 {
1.33 - BranchObj *bo=((BranchObj*)(parObj))->getLastBranch();
1.34 + bo=((BranchObj*)(parObj))->getLastBranch();
1.35 if (!bo) po->unScroll();
1.36 }
1.37 + clear();
1.38 }
1.39
1.40 bool BranchObj::operator< ( const BranchObj & other )
1.41 @@ -69,7 +72,7 @@
1.42 return angle == other.angle;
1.43 }
1.44
1.45 -int BranchObjPtrList::compareItems ( QPtrCollection::Item i, QPtrCollection::Item j)
1.46 +int BranchObjPtrList::compareItems ( Q3PtrCollection::Item i, Q3PtrCollection::Item j)
1.47 {
1.48 // Make sure PtrList::find works
1.49 if (i==j) return 0;
1.50 @@ -82,17 +85,15 @@
1.51
1.52 void BranchObj::init ()
1.53 {
1.54 - branch.setAutoDelete (true);
1.55 + branch.setAutoDelete (false);
1.56 floatimage.setAutoDelete (true);
1.57 + xlink.setAutoDelete (false);
1.58
1.59 - absPos=getRandPos();
1.60 - absPos+=parObj->getChildPos();
1.61 -
1.62 - // TODO This should be done in TextObj later
1.63 - QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
1.64 -// font.setPointSize(12);
1.65 - heading->setFont(font );
1.66 -// heading->setText(QObject::tr("new branch"));
1.67 + if (parObj)
1.68 + {
1.69 + absPos=getRandPos();
1.70 + absPos+=parObj->getChildPos();
1.71 + }
1.72
1.73 lastSelectedBranch=-1;
1.74
1.75 @@ -101,8 +102,8 @@
1.76 scrolled=false;
1.77 tmpUnscrolled=false;
1.78
1.79 - url="";
1.80 - vymLink="";
1.81 + includeImagesVer=false;
1.82 + includeImagesHor=false;
1.83 }
1.84
1.85 void BranchObj::copy (BranchObj* other)
1.86 @@ -125,9 +126,6 @@
1.87 tmpUnscrolled=other->tmpUnscrolled;
1.88 setVisibility (other->visible);
1.89
1.90 - url=other->url;
1.91 - vymLink=other->vymLink;
1.92 -
1.93 angle=other->angle;
1.94
1.95 positionBBox();
1.96 @@ -135,8 +133,17 @@
1.97
1.98 void BranchObj::clear()
1.99 {
1.100 - branch.clear();
1.101 floatimage.clear();
1.102 + while (!xlink.isEmpty())
1.103 + deleteXLink (xlink.first() );
1.104 +
1.105 + BranchObj *bo;
1.106 + while (!branch.isEmpty())
1.107 + {
1.108 + bo=branch.first();
1.109 + branch.removeFirst();
1.110 + delete (bo);
1.111 + }
1.112 }
1.113
1.114 int BranchObj::getNum()
1.115 @@ -149,7 +156,12 @@
1.116
1.117 int BranchObj::getNum(BranchObj *bo)
1.118 {
1.119 - return branch.findRef (bo);
1.120 + // keep current pointer in branch,
1.121 + // otherwise save might fail
1.122 + int cur=branch.at();
1.123 + int ind=branch.findRef (bo);
1.124 + branch.at(cur);
1.125 + return ind;
1.126 }
1.127
1.128 int BranchObj::getFloatImageNum(FloatImageObj *fio)
1.129 @@ -167,6 +179,11 @@
1.130 return floatimage.count();
1.131 }
1.132
1.133 +int BranchObj::countXLinks()
1.134 +{
1.135 + return xlink.count();
1.136 +}
1.137 +
1.138 void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPoint m, int off)
1.139 {
1.140 // Temporary link to lmo
1.141 @@ -181,19 +198,10 @@
1.142 // ignore mapcenter and mainbranch
1.143 if (lmo->getDepth()<2) off=0;
1.144 if (off==0)
1.145 - {
1.146 link2ParPos=false;
1.147 - parObj=o;
1.148 - }
1.149 else
1.150 - {
1.151 link2ParPos=true;
1.152 - if (off>0)
1.153 - parObj=o->getParObj();
1.154 - else
1.155 - parObj=o->getParObj();
1.156 - parObj=o;
1.157 - }
1.158 + parObj=o;
1.159
1.160 depth=parObj->getDepth()+1;
1.161
1.162 @@ -254,6 +262,7 @@
1.163 parObjTmpBuf=NULL;
1.164 depth=parObj->getDepth()+1;
1.165 setLinkStyle (getDefLinkStyle() );
1.166 + updateLink();
1.167 }
1.168 }
1.169
1.170 @@ -350,6 +359,7 @@
1.171 standardFlags->setVisibility(v);
1.172 LinkableMapObj::setVisibility (v);
1.173
1.174 + // Only change childs, if I am not scrolled
1.175 if (!scrolled && (depth < toDepth))
1.176 {
1.177 // Now go recursivly through all childs
1.178 @@ -359,9 +369,11 @@
1.179 FloatImageObj *fio;
1.180 for (fio=floatimage.first(); fio; fio=floatimage.next())
1.181 fio->setVisibility (v);
1.182 + XLinkObj* xlo;
1.183 + for (xlo=xlink.first(); xlo;xlo=xlink.next() )
1.184 + xlo->setVisibility ();
1.185 }
1.186 } // depth <= toDepth
1.187 - move (absPos.x(), absPos.y() );
1.188 requestReposition();
1.189 }
1.190
1.191 @@ -376,25 +388,21 @@
1.192 // Overloaded from LinkableMapObj
1.193 // BranchObj can use color of heading
1.194
1.195 - if (mapEditor->getLinkColorHint()==HeadingColor)
1.196 - LinkableMapObj::setLinkColor (heading->getColor() );
1.197 - else
1.198 - LinkableMapObj::setLinkColor ();
1.199 + if (mapEditor)
1.200 + if (mapEditor->getLinkColorHint()==HeadingColor)
1.201 + LinkableMapObj::setLinkColor (heading->getColor() );
1.202 + else
1.203 + LinkableMapObj::setLinkColor ();
1.204 }
1.205
1.206 -void BranchObj::setColor (QColor col, bool colorChilds)
1.207 +void BranchObj::setColorChilds (QColor col)
1.208 {
1.209 - heading->setColor(col);
1.210 - setLinkColor();
1.211 - if (colorChilds)
1.212 - {
1.213 - BranchObj *bo;
1.214 - for (bo=branch.first(); bo; bo=branch.next() )
1.215 - bo->setColor(col,colorChilds);
1.216 - }
1.217 + OrnamentedObj::setColor (col);
1.218 + BranchObj *bo;
1.219 + for (bo=branch.first(); bo; bo=branch.next() )
1.220 + bo->setColorChilds(col);
1.221 }
1.222
1.223 -
1.224 BranchObj* BranchObj::first()
1.225 {
1.226 itLast=NULL;
1.227 @@ -521,10 +529,20 @@
1.228 itLast=it;
1.229 }
1.230
1.231 +void BranchObj::positionContents()
1.232 +{
1.233 + FloatImageObj *fio;
1.234 + for (fio=floatimage.first(); fio; fio=floatimage.next() )
1.235 + fio->reposition();
1.236 + OrnamentedObj::positionContents();
1.237 +}
1.238
1.239 void BranchObj::move (double x, double y)
1.240 {
1.241 OrnamentedObj::move (x,y);
1.242 + FloatImageObj *fio;
1.243 + for (fio=floatimage.first(); fio; fio=floatimage.next() )
1.244 + fio->reposition();
1.245 positionBBox();
1.246 }
1.247
1.248 @@ -536,12 +554,12 @@
1.249 void BranchObj::moveBy (double x, double y)
1.250 {
1.251 OrnamentedObj::moveBy (x,y);
1.252 - positionBBox();
1.253 BranchObj* b;
1.254 for (b=branch.first(); b;b=branch.next() )
1.255 b->moveBy (x,y);
1.256 + positionBBox();
1.257 }
1.258 -
1.259 +
1.260 void BranchObj::moveBy (QPoint p)
1.261 {
1.262 moveBy (p.x(), p.y());
1.263 @@ -550,30 +568,25 @@
1.264
1.265 void BranchObj::positionBBox()
1.266 {
1.267 -
1.268 - heading->positionBBox();
1.269 - systemFlags->positionBBox();
1.270 - standardFlags->positionBBox();
1.271 - // It seems that setting x,y also affects width,height
1.272 - int w_old=bbox.width();
1.273 - int h_old=bbox.height();
1.274 - bbox.setX (absPos.x() );
1.275 - bbox.setY (absPos.y() );
1.276 - bbox.setWidth(w_old);
1.277 - bbox.setHeight(h_old);
1.278 -
1.279 -
1.280 + QPoint ap=getAbsPos();
1.281 + bbox.moveTopLeft (ap);
1.282 + positionContents();
1.283 setSelBox();
1.284
1.285 // set the frame
1.286 frame->setRect(QRect(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
1.287 +
1.288 + // Update links to other branches
1.289 + XLinkObj *xlo;
1.290 + for (xlo=xlink.first(); xlo; xlo=xlink.next() )
1.291 + xlo->updateXLink();
1.292 }
1.293
1.294 void BranchObj::calcBBoxSize()
1.295 {
1.296 QSize heading_r=heading->getSize();
1.297 - int heading_w=static_cast <int> (heading_r.width() );
1.298 - int heading_h=static_cast <int> (heading_r.height() );
1.299 + int heading_w=(int) heading_r.width() ;
1.300 + int heading_h=(int) heading_r.height() ;
1.301 QSize sysflags_r=systemFlags->getSize();
1.302 int sysflags_h=sysflags_r.height();
1.303 int sysflags_w=sysflags_r.width();
1.304 @@ -589,11 +602,73 @@
1.305 h=max (sysflags_h,stanflags_h);
1.306 h=max (h,heading_h);
1.307
1.308 + // Save the dimension of flags and heading
1.309 + ornamentsBBox.setSize ( QSize(w,h));
1.310 +
1.311 + // clickBox includes Flags and Heading
1.312 + clickBox.setSize (ornamentsBBox.size() );
1.313 +
1.314 + // Floatimages
1.315 + QPoint rp;
1.316 + FloatImageObj *foi;
1.317 +
1.318 + topPad=botPad=leftPad=rightPad=0;
1.319 + if (includeImagesVer || includeImagesHor)
1.320 + {
1.321 + if (countFloatImages()>0)
1.322 + {
1.323 + for (foi=floatimage.first(); foi; foi=floatimage.next() )
1.324 + {
1.325 + rp=foi->getRelPos();
1.326 + if (includeImagesVer)
1.327 + {
1.328 + if (rp.y() < 0)
1.329 + topPad=max (topPad,-rp.y()-h);
1.330 + if (rp.y()+foi->height() > 0)
1.331 + botPad=max (botPad,rp.y()+foi->height());
1.332 + }
1.333 + if (includeImagesHor)
1.334 + {
1.335 + if (orientation==OrientRightOfCenter)
1.336 + {
1.337 + if (-rp.x()-w > 0)
1.338 + leftPad=max (leftPad,-rp.x()-w);
1.339 + if (rp.x()+foi->width() > 0)
1.340 + rightPad=max (rightPad,rp.x()+foi->width());
1.341 + } else
1.342 + {
1.343 + if (rp.x()< 0)
1.344 + leftPad=max (leftPad,-rp.x());
1.345 + if (rp.x()+foi->width() > w)
1.346 + rightPad=max (rightPad,rp.x()+foi->width()-w);
1.347 + }
1.348 + }
1.349 + }
1.350 + }
1.351 + h+=topPad+botPad;
1.352 + w+=leftPad+rightPad;
1.353 + }
1.354 +
1.355 + // Frame thickness
1.356 w+=frame->getBorder();
1.357 h+=frame->getBorder();
1.358 +
1.359 + // Finally set size
1.360 bbox.setSize (QSize (w,h));
1.361 }
1.362
1.363 +void BranchObj::setDockPos()
1.364 +{
1.365 + if (getOrientation()==OrientLeftOfCenter )
1.366 + {
1.367 + childPos=QPoint (ornamentsBBox.bottomLeft().x(), ornamentsBBox.bottomLeft().y() );
1.368 + parPos=QPoint (ornamentsBBox.bottomRight().x(),ornamentsBBox.bottomRight().y() );
1.369 + } else
1.370 + {
1.371 + childPos=QPoint (ornamentsBBox.bottomRight().x(), ornamentsBBox.bottomRight().y() );
1.372 + parPos=QPoint (ornamentsBBox.bottomLeft().x(),ornamentsBBox.bottomLeft().y() );
1.373 + }
1.374 +}
1.375 LinkableMapObj* BranchObj::findMapObj(QPoint p, LinkableMapObj* excludeLMO)
1.376 {
1.377 // Search branches
1.378 @@ -606,89 +681,67 @@
1.379 }
1.380
1.381 // Search myself
1.382 - if (inBBox (p) && (this != excludeLMO) && isVisibleObj() )
1.383 + if (inBox (p) && (this != excludeLMO) && isVisibleObj() )
1.384 return this;
1.385
1.386 // Search float images
1.387 FloatImageObj *foi;
1.388 for (foi=floatimage.first(); foi; foi=floatimage.next() )
1.389 - if (foi->inBBox(p) && (foi != excludeLMO) && foi->getParObj()!= excludeLMO) return foi;
1.390 + if (foi->inBox(p) &&
1.391 + (foi != excludeLMO) &&
1.392 + foi->getParObj()!= excludeLMO &&
1.393 + foi->isVisibleObj()
1.394 + ) return foi;
1.395
1.396 return NULL;
1.397 }
1.398
1.399 void BranchObj::setHeading(QString s)
1.400 {
1.401 - // Adjusting font size
1.402 - QFont font=heading->getFont();
1.403 - if (depth==0)
1.404 - font.setPointSize(16);
1.405 - else
1.406 - if (depth>1)
1.407 - font.setPointSize(10);
1.408 - else
1.409 - font.setPointSize(12);
1.410 - heading->setFont(font);
1.411 heading->setText(s); // set new heading
1.412 calcBBoxSize(); // recalculate bbox
1.413 positionBBox(); // rearrange contents
1.414 requestReposition();
1.415 }
1.416
1.417 -void BranchObj::setURL(QString s)
1.418 +void BranchObj::setHideTmp (HideTmpMode mode)
1.419 {
1.420 - url=s;
1.421 - if (!url.isEmpty())
1.422 - systemFlags->activate("url");
1.423 - else
1.424 - systemFlags->deactivate("url");
1.425 - calcBBoxSize(); // recalculate bbox
1.426 - positionBBox(); // rearrange contents
1.427 - forceReposition();
1.428 + if (mode==HideExport && hasHiddenExportParent(this))
1.429 + {
1.430 + setVisibility (false);
1.431 + hidden=true;
1.432 + }else
1.433 + {
1.434 + if (hasScrolledParent(this))
1.435 + setVisibility (false);
1.436 + else
1.437 + setVisibility (true);
1.438 + hidden=false;
1.439 + }
1.440 +
1.441 + BranchObj *bo;
1.442 + for (bo=branch.first(); bo; bo=branch.next() )
1.443 + bo->setHideTmp (mode);
1.444 }
1.445
1.446 -QString BranchObj::getURL()
1.447 +bool BranchObj::hasHiddenExportParent(BranchObj *start)
1.448 {
1.449 - return url;
1.450 -}
1.451 + // Calls parents recursivly to
1.452 + // find out, if we are temp. hidden
1.453
1.454 -void BranchObj::setVymLink(QString s)
1.455 -{
1.456 - if (!s.isEmpty())
1.457 - {
1.458 - // We need the relative (from loading)
1.459 - // or absolute path (from User event)
1.460 - // and build the absolute path.
1.461 - // Note: If we have relative, use path of
1.462 - // current map to build absolute path
1.463 - QDir d(s);
1.464 - if (!d.path().startsWith ("/"))
1.465 - {
1.466 - QString p=mapEditor->getDestPath();
1.467 - int i=p.findRev("/",-1);
1.468 - d.setPath(p.left(i)+"/"+s);
1.469 - d.convertToAbs();
1.470 - }
1.471 - vymLink=d.path();
1.472 - systemFlags->activate("vymLink");
1.473 - }
1.474 - else
1.475 - {
1.476 - systemFlags->deactivate("vymLink");
1.477 - vymLink="";
1.478 - }
1.479 - calcBBoxSize(); // recalculate bbox
1.480 - positionBBox(); // rearrange contents
1.481 - forceReposition();
1.482 -}
1.483 + if (hideExport) return true;
1.484
1.485 -QString BranchObj::getVymLink()
1.486 -{
1.487 - return vymLink;
1.488 + BranchObj* bo=(BranchObj*)(parObj);
1.489 + if (bo)
1.490 + return bo->hasHiddenExportParent(start);
1.491 + else
1.492 + return false;
1.493 }
1.494
1.495 QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPoint& offset)
1.496 {
1.497 + if (hidden) return "";
1.498 +
1.499 QString s,a;
1.500 QString scrolledAttr;
1.501 if (scrolled)
1.502 @@ -696,21 +749,6 @@
1.503 else
1.504 scrolledAttr="";
1.505
1.506 - QString posAttr;
1.507 - if (depth<2) posAttr=
1.508 - attribut("absPosX",QString().setNum(absPos.x(),10)) +
1.509 - attribut("absPosY",QString().setNum(absPos.y(),10));
1.510 - else
1.511 - posAttr="";
1.512 -
1.513 - QString urlAttr;
1.514 - if (!url.isEmpty())
1.515 - urlAttr=attribut ("url",url);
1.516 -
1.517 - QString vymLinkAttr;
1.518 - if (!vymLink.isEmpty())
1.519 - vymLinkAttr=attribut ("vymLink",convertToRel(mapEditor->getDestPath(),vymLink) );
1.520 -
1.521 QString frameAttr;
1.522 if (frame->getFrameType()!=NoFrame)
1.523 frameAttr=attribut ("frameType",frame->getFrameTypeName());
1.524 @@ -730,11 +768,24 @@
1.525 } else
1.526 areaAttr="";
1.527
1.528 - s=beginElement ("branch" +scrolledAttr +posAttr +urlAttr +vymLinkAttr +frameAttr +areaAttr);
1.529 + // Providing an ID for a branch makes export to XHTML easier
1.530 + QString idAttr;
1.531 + if (countXLinks()>0)
1.532 + idAttr=attribut ("id",getSelectString());
1.533 + else
1.534 + idAttr="";
1.535 +
1.536 + s=beginElement ("branch"
1.537 + +getOrnAttr()
1.538 + +scrolledAttr
1.539 + +frameAttr
1.540 + +areaAttr
1.541 + +idAttr
1.542 + +getIncludeImageAttr() );
1.543 incIndent();
1.544
1.545 // save heading
1.546 - s=s+valueElement("heading", getHeading(),
1.547 + s+=valueElement("heading", getHeading(),
1.548 attribut ("textColor",QColor(heading->getColor()).name()));
1.549
1.550 // save names of flags set
1.551 @@ -748,17 +799,120 @@
1.552 BranchObj *bo;
1.553 for (bo=branch.first(); bo; bo=branch.next() )
1.554 s+=bo->saveToDir(tmpdir,prefix,offset);
1.555 - decIndent();
1.556
1.557 // Save FloatImages
1.558 FloatImageObj *fio;
1.559 for (fio=floatimage.first(); fio; fio=floatimage.next() )
1.560 - s+=fio->saveToDir (tmpdir,prefix);
1.561 + s+=fio->saveToDir (tmpdir,prefix,offset);
1.562
1.563 + // Save XLinks
1.564 + XLinkObj *xlo;
1.565 + //FIXME exponential increase in xlinks...
1.566 + QString ol; // old link
1.567 + QString cl; // current link
1.568 + for (xlo=xlink.first(); xlo; xlo=xlink.next() )
1.569 + {
1.570 + cl=xlo->saveToDir();
1.571 + if (cl!=ol)
1.572 + {
1.573 + s+=cl;
1.574 + ol=cl;
1.575 + } else
1.576 + {
1.577 + qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
1.578 + }
1.579 + }
1.580 +
1.581 + decIndent();
1.582 s+=endElement ("branch");
1.583 return s;
1.584 }
1.585
1.586 +void BranchObj::addXLink (XLinkObj *xlo)
1.587 +{
1.588 + xlink.append (xlo);
1.589 +
1.590 +}
1.591 +
1.592 +void BranchObj::removeXLinkRef (XLinkObj *xlo)
1.593 +{
1.594 + xlink.remove (xlo);
1.595 +}
1.596 +
1.597 +void BranchObj::deleteXLink(XLinkObj *xlo)
1.598 +{
1.599 + xlo->deactivate();
1.600 + if (!xlo->isUsed()) delete (xlo);
1.601 +}
1.602 +
1.603 +void BranchObj::deleteXLinkAt (int i)
1.604 +{
1.605 + XLinkObj *xlo=xlink.at(i);
1.606 + xlo->deactivate();
1.607 + if (!xlo->isUsed()) delete(xlo);
1.608 +}
1.609 +
1.610 +XLinkObj* BranchObj::XLinkAt (int i)
1.611 +{
1.612 + return xlink.at(i);
1.613 +}
1.614 +
1.615 +int BranchObj::countXLink()
1.616 +{
1.617 + return xlink.count();
1.618 +}
1.619 +
1.620 +
1.621 +BranchObj* BranchObj::XLinkTargetAt (int i)
1.622 +{
1.623 + if (xlink.at(i))
1.624 + return xlink.at(i)->otherBranch (this);
1.625 + else
1.626 + return NULL;
1.627 +}
1.628 +
1.629 +void BranchObj::setIncludeImagesVer(bool b)
1.630 +{
1.631 + includeImagesVer=b;
1.632 + calcBBoxSize();
1.633 + positionBBox();
1.634 + requestReposition();
1.635 + //FIXME undo needed
1.636 +}
1.637 +
1.638 +bool BranchObj::getIncludeImagesVer()
1.639 +{
1.640 + return includeImagesVer;
1.641 +}
1.642 +
1.643 +void BranchObj::setIncludeImagesHor(bool b)
1.644 +{
1.645 + includeImagesHor=b;
1.646 + calcBBoxSize();
1.647 + positionBBox();
1.648 + requestReposition();
1.649 + //FIXME undo needed
1.650 +}
1.651 +
1.652 +bool BranchObj::getIncludeImagesHor()
1.653 +{
1.654 + return includeImagesHor;
1.655 +}
1.656 +
1.657 +QString BranchObj::getIncludeImageAttr()
1.658 +{
1.659 + QString a;
1.660 + if (includeImagesVer)
1.661 + a=attribut ("incImgV","true");
1.662 + else
1.663 + a=attribut ("incImgV","false");
1.664 + if (includeImagesHor)
1.665 + a+=attribut ("incImgH","true");
1.666 + else
1.667 + a+=attribut ("incImgH","false");
1.668 + return a;
1.669 +}
1.670 +
1.671 LinkableMapObj* BranchObj::addFloatImage ()
1.672 {
1.673 FloatImageObj *newfi=new FloatImageObj (canvas,this);
1.674 @@ -767,8 +921,11 @@
1.675 newfi->setVisibility (false);
1.676 else
1.677 newfi->setVisibility(visible);
1.678 + calcBBoxSize();
1.679 + positionBBox();
1.680 requestReposition();
1.681 return newfi;
1.682 + //FIXME undo needed
1.683 }
1.684
1.685 LinkableMapObj* BranchObj::addFloatImage (FloatImageObj *fio)
1.686 @@ -780,8 +937,11 @@
1.687 newfi->setVisibility (false);
1.688 else
1.689 newfi->setVisibility(visible);
1.690 + calcBBoxSize();
1.691 + positionBBox();
1.692 requestReposition();
1.693 return newfi;
1.694 + // FIMXE undo needed
1.695 }
1.696
1.697 FloatImageObj* BranchObj::getFirstFloatImage ()
1.698 @@ -802,7 +962,10 @@
1.699 void BranchObj::removeFloatImage (FloatImageObj *fio)
1.700 {
1.701 floatimage.remove (fio);
1.702 + calcBBoxSize();
1.703 + positionBBox();
1.704 requestReposition();
1.705 + // FIMXE undo needed
1.706 }
1.707
1.708 void BranchObj::savePosInAngle ()
1.709 @@ -817,19 +980,40 @@
1.710 }
1.711 }
1.712
1.713 +void BranchObj::setDefAttr (BranchModification mod)
1.714 +{
1.715 + int fontsize;
1.716 + switch (depth)
1.717 + {
1.718 + case 0: fontsize=16; break;
1.719 + case 1: fontsize=12; break;
1.720 + default: fontsize=10; break;
1.721 + }
1.722 +
1.723 + setLinkColor ();
1.724 + setLinkStyle(getDefLinkStyle());
1.725 + QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
1.726 + font.setPointSize(fontsize);
1.727 + heading->setFont(font );
1.728 +
1.729 + if (mod==NewBranch)
1.730 + setColor (((BranchObj*)(parObj))->getColor());
1.731 +
1.732 + calcBBoxSize();
1.733 +}
1.734 +
1.735 BranchObj* BranchObj::addBranch()
1.736 {
1.737 BranchObj* newbo=new BranchObj(canvas,this);
1.738 branch.append (newbo);
1.739 newbo->setParObj(this);
1.740 - newbo->setColor(getColor(),false);
1.741 - newbo->setLinkColor();
1.742 + newbo->setDefAttr(NewBranch);
1.743 newbo->setHeading ("new");
1.744 - newbo->setLinkStyle (newbo->getDefLinkStyle());
1.745 if (scrolled)
1.746 newbo->setVisibility (false);
1.747 else
1.748 newbo->setVisibility(visible);
1.749 + newbo->updateLink();
1.750 requestReposition();
1.751 return newbo;
1.752 }
1.753 @@ -840,16 +1024,27 @@
1.754 branch.append (newbo);
1.755 newbo->copy(bo);
1.756 newbo->setParObj(this);
1.757 - newbo->setHeading (newbo->getHeading()); // adjust fontsize to depth
1.758 - newbo->setLinkStyle (newbo->getDefLinkStyle());
1.759 + newbo->setDefAttr(MovedBranch);
1.760 if (scrolled)
1.761 newbo->setVisibility (false);
1.762 else
1.763 newbo->setVisibility(bo->visible);
1.764 + newbo->updateLink();
1.765 requestReposition();
1.766 return newbo;
1.767 }
1.768
1.769 +BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
1.770 +{
1.771 + branch.append (bo);
1.772 + bo->setParObj (this);
1.773 + bo->depth=depth+1;
1.774 + bo->setDefAttr(MovedBranch);
1.775 + if (scrolled) tmpUnscroll();
1.776 + setLastSelectedBranch (bo);
1.777 + return bo;
1.778 +}
1.779 +
1.780 BranchObj* BranchObj::insertBranch(int pos)
1.781 {
1.782 savePosInAngle();
1.783 @@ -870,11 +1065,56 @@
1.784 return newbo;
1.785 }
1.786
1.787 +BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
1.788 +{
1.789 + savePosInAngle();
1.790 + // Add new bo and resort branches
1.791 + bo->angle=pos-0.5;
1.792 + branch.append (bo);
1.793 + bo->setParObj (this);
1.794 + bo->depth=depth+1;
1.795 + bo->setDefAttr (MovedBranch);
1.796 + if (scrolled) tmpUnscroll();
1.797 + setLastSelectedBranch (bo);
1.798 + branch.sort();
1.799 + return bo;
1.800 +}
1.801 +
1.802 +void BranchObj::removeBranchHere(BranchObj* borem)
1.803 +{
1.804 + // This removes the branch bo from list, but
1.805 + // inserts its childs at the place of bo
1.806 + BranchObj *bo;
1.807 + bo=borem->getLastBranch();
1.808 + int pos=borem->getNum();
1.809 + while (bo)
1.810 + {
1.811 + bo->moveBranchTo (this,pos+1);
1.812 + bo=borem->getLastBranch();
1.813 + }
1.814 + removeBranch (borem);
1.815 +}
1.816 +
1.817 +void BranchObj::removeChilds()
1.818 +{
1.819 + clear();
1.820 +}
1.821 +
1.822 void BranchObj::removeBranch(BranchObj* bo)
1.823 {
1.824 // if bo is not in branch remove returns false, we
1.825 // don't care...
1.826 - branch.remove (bo);
1.827 +
1.828 + if (branch.remove (bo))
1.829 + delete (bo);
1.830 + else
1.831 + qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
1.832 + requestReposition();
1.833 +}
1.834 +
1.835 +void BranchObj::removeBranchPtr(BranchObj* bo)
1.836 +{
1.837 + branch.remove (bo);
1.838 requestReposition();
1.839 }
1.840
1.841 @@ -908,6 +1148,15 @@
1.842 return branch.at(i);
1.843 }
1.844
1.845 +bool BranchObj::canMoveBranchUp()
1.846 +{
1.847 + if (!parObj) return false;
1.848 + BranchObj* par=(BranchObj*)parObj;
1.849 + if (this==par->getFirstBranch())
1.850 + return false;
1.851 + else
1.852 + return true;
1.853 +}
1.854
1.855 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // move a branch up (modify myself)
1.856 {
1.857 @@ -923,6 +1172,16 @@
1.858 return branch.at(i);
1.859 }
1.860
1.861 +bool BranchObj::canMoveBranchDown()
1.862 +{
1.863 + if (!parObj) return false;
1.864 + BranchObj* par=(BranchObj*)parObj;
1.865 + if (this==par->getLastBranch())
1.866 + return false;
1.867 + else
1.868 + return true;
1.869 +}
1.870 +
1.871 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)
1.872 {
1.873 savePosInAngle();
1.874 @@ -939,29 +1198,63 @@
1.875 return branch.at(i);
1.876 }
1.877
1.878 +BranchObj* BranchObj::moveBranchTo (BranchObj* dst, int pos)
1.879 +{
1.880 + // Find current parent and
1.881 + // remove pointer to myself there
1.882 + if (!dst) return NULL;
1.883 + BranchObj *par=(BranchObj*)(parObj);
1.884 + if (par)
1.885 + par->removeBranchPtr (this);
1.886 + else
1.887 + return NULL;
1.888 +
1.889 + // Create new pointer to myself at dst
1.890 + if (pos<0||dst->getDepth()==0)
1.891 + {
1.892 + // links myself as last branch at dst
1.893 + dst->addBranchPtr (this);
1.894 + updateLink();
1.895 + return this;
1.896 + } else
1.897 + {
1.898 + // inserts me at pos in parent of dst
1.899 + if (par)
1.900 + {
1.901 + BranchObj *bo=dst->insertBranchPtr (this,pos);
1.902 + bo->setDefAttr(MovedBranch);
1.903 + updateLink();
1.904 + return bo;
1.905 +
1.906 + } else
1.907 + return NULL;
1.908 + }
1.909 +}
1.910 +
1.911 void BranchObj::alignRelativeTo (QPoint ref)
1.912 {
1.913 -/* FIXME testing
1.914 - if (!getHeading().isEmpty())
1.915 - cout << "BO::alignRelTo "<<getHeading()<<endl;
1.916 - else
1.917 - cout << "BO::alignRelTo ???"<<endl;
1.918 - cout << " d="<<depth<<endl;
1.919 -*/
1.920 int th = bboxTotal.height();
1.921 +// TODO testing
1.922 +/*
1.923 + cout << "BO::alignRelTo "<<getHeading()<<endl;
1.924 + cout << " d="<<depth<<
1.925 + " ref="<<ref<<
1.926 +// " bbox.topLeft="<<bboxTotal.topLeft()<<
1.927 + " absPos="<<absPos<<
1.928 +// " pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
1.929 + " hidden="<<hidden<<
1.930 + " th="<<th<<endl;
1.931 +*/
1.932
1.933 // If I am the mapcenter or a mainbranch, reposition heading
1.934 if (depth<2)
1.935 - {
1.936 - move (absPos.x(),absPos.y());
1.937 + { //FIXME ugly! optimize this move for MCO needed to initially position text in box...
1.938 if (depth==1)
1.939 - {
1.940 // Calc angle to mapCenter if I am a mainbranch
1.941 // needed for reordering the mainbranches clockwise
1.942 // around mapcenter
1.943 angle=getAngle (QPoint ((int)(x() - parObj->getChildPos().x() ),
1.944 (int)(y() - parObj->getChildPos().y() ) ) );
1.945 - }
1.946 }
1.947 else
1.948 {
1.949 @@ -970,29 +1263,25 @@
1.950 switch (orientation)
1.951 {
1.952 case OrientLeftOfCenter:
1.953 - move (ref.x()-bbox.width(), ref.y() + (th-bbox.height())/2 );
1.954 + move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
1.955 break;
1.956 case OrientRightOfCenter:
1.957 - move (ref.x(), ref.y() + (th-bbox.height())/2 );
1.958 + move (ref.x() , ref.y() + (th-bbox.height())/2 );
1.959 break;
1.960 default:
1.961 - cout <<"LMO::alignRelativeTo: oops, no orientation given...\n";
1.962 + qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
1.963 break;
1.964 }
1.965 }
1.966
1.967 - FloatImageObj *fio;
1.968 - for (fio=floatimage.first(); fio; fio=floatimage.next() )
1.969 - fio->reposition();
1.970 -
1.971 if (scrolled) return;
1.972
1.973 // Set reference point for alignment of childs
1.974 QPoint ref2;
1.975 if (orientation==OrientLeftOfCenter)
1.976 - ref2.setX(childPos.x() - linkwidth);
1.977 + ref2.setX(bbox.topLeft().x() - linkwidth);
1.978 else
1.979 - ref2.setX(childPos.x() + linkwidth);
1.980 + ref2.setX(bbox.topRight().x() + linkwidth);
1.981
1.982 if (depth==1)
1.983 ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
1.984 @@ -1003,15 +1292,18 @@
1.985 BranchObj *b;
1.986 for (b=branch.first(); b; b=branch.next() )
1.987 {
1.988 - b->alignRelativeTo (ref2);
1.989 - ref2.setY(ref2.y() + b->getBBoxSizeWithChilds().height() );
1.990 + if (!b->isHidden())
1.991 + {
1.992 + b->alignRelativeTo (ref2);
1.993 + ref2.setY(ref2.y() + b->getBBoxSizeWithChilds().height() );
1.994 + }
1.995 }
1.996 }
1.997
1.998
1.999 void BranchObj::reposition()
1.1000 {
1.1001 -/* FIXME testing
1.1002 +/* TODO testing only
1.1003 if (!getHeading().isEmpty())
1.1004 cout << "BO::reposition "<<getHeading()<<endl;
1.1005 else
1.1006 @@ -1023,9 +1315,13 @@
1.1007 // changes its height,
1.1008 // all upper LMOs have to change, too.
1.1009 calcBBoxSizeWithChilds();
1.1010 + updateLink(); // This update is needed if the canvas is resized
1.1011 + // due to excessive moving of a FIO
1.1012 +
1.1013 alignRelativeTo ( QPoint (absPos.x(),
1.1014 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1.1015 branch.sort();
1.1016 + positionBBox(); // Reposition bbox and contents
1.1017 } else
1.1018 {
1.1019 // This is only important for moving branches:
1.1020 @@ -1044,11 +1340,13 @@
1.1021
1.1022 BranchObj* b;
1.1023 for (b=branch.first();b ;b=branch.next() )
1.1024 - r=addBBox(b->getTotalBBox(),r);
1.1025 + if (!b->isHidden())
1.1026 + r=addBBox(b->getTotalBBox(),r);
1.1027
1.1028 FloatImageObj* fio;
1.1029 for (fio=floatimage.first();fio ;fio=floatimage.next() )
1.1030 - r=addBBox(fio->getTotalBBox(),r);
1.1031 + if (!fio->isHidden())
1.1032 + r=addBBox(fio->getTotalBBox(),r);
1.1033
1.1034 return r;
1.1035 }
1.1036 @@ -1059,14 +1357,14 @@
1.1037 }
1.1038
1.1039 void BranchObj::calcBBoxSizeWithChilds()
1.1040 -{
1.1041 - // This is called only from reposition and
1.1042 +{
1.1043 + // This is initially called only from reposition and
1.1044 // and only for mapcenter. So it won't be
1.1045 // called more than once for a single user
1.1046 // action
1.1047
1.1048 +
1.1049 // Calculate size of LMO including all childs (to align them later)
1.1050 -
1.1051 bboxTotal.setX(bbox.x() );
1.1052 bboxTotal.setY(bbox.y() );
1.1053
1.1054 @@ -1078,6 +1376,22 @@
1.1055 return;
1.1056 }
1.1057
1.1058 + if (hidden)
1.1059 + {
1.1060 + bboxTotal.setWidth (0);
1.1061 + bboxTotal.setHeight(0);
1.1062 + if (parObj)
1.1063 + {
1.1064 + bboxTotal.setX (parObj->x());
1.1065 + bboxTotal.setY (parObj->y());
1.1066 + } else
1.1067 + {
1.1068 + bboxTotal.setX (bbox.x());
1.1069 + bboxTotal.setY (bbox.y());
1.1070 + }
1.1071 + return;
1.1072 + }
1.1073 +
1.1074 QRect r(0,0,0,0);
1.1075 QRect br;
1.1076 // Now calculate recursivly
1.1077 @@ -1087,11 +1401,14 @@
1.1078 BranchObj* b;
1.1079 for (b=branch.first();b ;b=branch.next() )
1.1080 {
1.1081 - b->calcBBoxSizeWithChilds();
1.1082 - br=b->getBBoxSizeWithChilds();
1.1083 - r.setWidth( max (br.width(), r.width() ));
1.1084 - r.setHeight(br.height() + r.height() );
1.1085 - if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
1.1086 + if (!b->isHidden())
1.1087 + {
1.1088 + b->calcBBoxSizeWithChilds();
1.1089 + br=b->getBBoxSizeWithChilds();
1.1090 + r.setWidth( max (br.width(), r.width() ));
1.1091 + r.setHeight(br.height() + r.height() );
1.1092 + if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
1.1093 + }
1.1094 }
1.1095 // Add myself and also
1.1096 // add width of link to sum if necessary
1.1097 @@ -1099,12 +1416,21 @@
1.1098 bboxTotal.setWidth (bbox.width() + r.width() );
1.1099 else
1.1100 bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
1.1101 - bboxTotal.setHeight(max (r.height(), bbox.height() ) );
1.1102 -// frame->setRect(QRect(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
1.1103 +
1.1104 + bboxTotal.setHeight(max (r.height(), bbox.height()));
1.1105 }
1.1106
1.1107 void BranchObj::select()
1.1108 {
1.1109 + // set Text in Editor
1.1110 + textEditor->setText(note.getNote() );
1.1111 + QString fnh=note.getFilenameHint();
1.1112 + if (fnh!="")
1.1113 + textEditor->setFilenameHint(note.getFilenameHint() );
1.1114 + else
1.1115 + textEditor->setFilenameHint(getHeading() );
1.1116 + textEditor->setFontHint (note.getFontHint() );
1.1117 +
1.1118 LinkableMapObj::select();
1.1119 // Tell parent that I am selected now:
1.1120 BranchObj* po=(BranchObj*)(parObj);
1.1121 @@ -1114,13 +1440,6 @@
1.1122 // temporary unscroll, if we have scrolled parents somewhere
1.1123 if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
1.1124
1.1125 - // set Text in Editor
1.1126 - textEditor->setText(note.getNote() );
1.1127 - textEditor->setFilename(note.getFilenameHint() );
1.1128 - textEditor->setFontHint (note.getFontHint() );
1.1129 - connect (textEditor, SIGNAL (textHasChanged() ), this, SLOT (updateNoteFlag() ) );
1.1130 - connect (textEditor, SIGNAL (fontSizeHasChanged() ), this, SLOT (updateNoteFlag() ) );
1.1131 -
1.1132 // Show URL and link in statusbar
1.1133 QString status;
1.1134 if (!url.isEmpty()) status+="URL: "+url+" ";
1.1135 @@ -1128,13 +1447,7 @@
1.1136 if (!status.isEmpty()) mainWindow->statusMessage (status);
1.1137
1.1138 // Update Toolbar
1.1139 - standardFlags->updateToolBar();
1.1140 -
1.1141 - // Update Browserbutton
1.1142 - if (!url.isEmpty())
1.1143 - actionEditOpenURL->setEnabled (true);
1.1144 - else
1.1145 - actionEditOpenURL->setEnabled (false);
1.1146 + standardFlags->updateToolbar();
1.1147
1.1148 // Update actions in mapeditor
1.1149 mapEditor->updateActions();
1.1150 @@ -1154,15 +1467,11 @@
1.1151 // reset temporary unscroll, if we have scrolled parents somewhere
1.1152 if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
1.1153
1.1154 - // Disconnect textEditor from this LMO
1.1155 - disconnect( textEditor, SIGNAL(textHasChanged()), 0, 0 );
1.1156 - disconnect( textEditor, SIGNAL (fontSizeHasChanged()),0,0 );
1.1157 -
1.1158 // Erase content of editor
1.1159 textEditor->setInactive();
1.1160
1.1161 // unselect all buttons in toolbar
1.1162 - standardFlagsDefault->updateToolBar();
1.1163 + standardFlagsDefault->updateToolbar();
1.1164 }
1.1165
1.1166 QString BranchObj::getSelectString()
1.1167 @@ -1170,15 +1479,12 @@
1.1168 QString s;
1.1169 if (parObj)
1.1170 {
1.1171 - if (parObj->getDepth()==0)
1.1172 + if (depth==1)
1.1173 s= "bo:" + QString("%1").arg(getNum());
1.1174 else
1.1175 s= ((BranchObj*)(parObj))->getSelectString() + ",bo:" + QString("%1").arg(getNum());
1.1176 } else
1.1177 - {
1.1178 s="mc:";
1.1179 - }
1.1180 -
1.1181 return s;
1.1182 }
1.1183