1 #include "branchitem.h"
3 #include "attributeitem.h"
11 extern TaskModel *taskModel;
15 BranchItem::BranchItem(TreeItem *parent)
18 //qDebug()<< "Constr. BranchItem this=" << this << "parent:" << parent;
20 // Set type if parent is known yet
21 // if not, type is set in insertBranch or TreeItem::appendChild
22 if (parent == rootItem)
28 tmpUnscrolled = false;
30 includeImagesVer = false;
31 includeImagesHor = false;
32 includeChildren = false;
33 childrenLayout = BranchItem::AutoPositioning;
35 lastSelectedBranchNum = 0;
36 lastSelectedBranchNumAlt = 0;
41 BranchItem::~BranchItem()
43 // qDebug()<< "Destr. BranchItem this="<<this<<" "<<getHeading();
51 void BranchItem::clear()
54 taskModel->deleteTask(task);
57 void BranchItem::copy(BranchItem *other) // TODO lacks most of data...
59 scrolled = other->scrolled;
60 tmpUnscrolled = other->tmpUnscrolled;
63 BranchItem *BranchItem::parentBranch() { return (BranchItem *)parentItem; }
65 void BranchItem::insertBranch(int pos, BranchItem *branch)
69 if (pos > branchCounter)
71 childItems.insert(pos + branchOffset, branch);
72 branch->parentItem = this;
73 branch->rootItem = rootItem;
74 branch->setModel(model);
75 if (parentItem == rootItem)
80 if (branchCounter == 0)
81 branchOffset = childItems.count() - 1;
85 QString BranchItem::saveToDir(const QString &tmpdir, const QString &prefix,
86 const QPointF &offset, QList<Link *> &tmpLinks)
88 // Cloudy stuff can be hidden during exports
93 QString idAttr = attribut("uuid", uuid.toString());
97 // Update of note is usually done while unselecting a branch
101 scrolledAttr = attribut("scrolled", "yes");
105 // save area, if not scrolled // not needed if HTML is rewritten...
106 // also we could check if _any_ of parents is scrolled
108 if (mo && parentItem->isBranchLikeType() &&
109 !((BranchItem *)parentItem)->isScrolled()) {
110 qreal x = mo->getAbsPos().x();
111 qreal y = mo->getAbsPos().y();
113 attribut("x1", QString().setNum(x - offset.x())) +
114 attribut("y1", QString().setNum(y - offset.y())) +
115 attribut("x2", QString().setNum(x + mo->width() - offset.x())) +
116 attribut("y2", QString().setNum(y + mo->height() - offset.y()));
122 if (parentItem == rootItem)
123 elementName = "mapcenter";
125 elementName = "branch";
127 // Free positioning of children
129 if (childrenLayout == BranchItem::FreePositioning)
130 layoutAttr += attribut("childrenFreePos", "true");
134 if (mo && mo->getRotation() != 0)
135 rotAttr = attribut("rotation", QString().setNum(mo->getRotation()));
137 s = beginElement(elementName + getMapAttr() + getGeneralAttr() +
138 scrolledAttr + getIncludeImageAttr() + rotAttr +
139 layoutAttr + idAttr);
143 s += heading.saveToDir();
147 s += note.saveToDir();
149 // Save frame // not saved if there is no MO
151 // Avoid saving NoFrame for objects other than MapCenter
152 if (depth() == 0 || ((OrnamentedObj *)mo)->getFrame()->getFrameType() !=
154 s += ((OrnamentedObj *)mo)->getFrame()->saveToDir();
157 // save names of flags set
158 s += standardFlags.saveState();
159 s += userFlags.saveState();
162 for (int i = 0; i < imageCount(); ++i)
163 s += getImageNum(i)->saveToDir(tmpdir, prefix);
166 for (int i = 0; i < attributeCount(); ++i)
167 s += getAttributeNum(i)->getDataXML();
171 s += task->saveToDir();
175 TreeItem *ti = getBranchNum(i);
177 s += getBranchNum(i)->saveToDir(tmpdir, prefix, offset, tmpLinks);
179 ti = getBranchNum(i);
182 // Mark Links for save
183 for (int i = 0; i < xlinkCount(); ++i) {
184 Link *l = getXLinkItemNum(i)->getLink();
185 if (l && !tmpLinks.contains(l))
189 s += endElement(elementName);
193 void BranchItem::updateVisibility()
195 // Needed to hide relinked branch, if parent is scrolled
197 if (hasScrolledParent(this) || hidden)
198 mo->setVisibility(false);
200 mo->setVisibility(true);
204 void BranchItem::setHeadingColor(QColor color)
206 TreeItem::setHeadingColor(color);
208 ((BranchObj *)mo)->setColor(color);
211 void BranchItem::updateTaskFlag()
213 systemFlags.deactivateGroup("system-tasks");
215 QString s = "system-" + task->getIconString();
216 systemFlags.activate(s);
217 model->emitDataChanged(this);
219 // else: During initialization the task is not yet attached to branch,
220 // so ignore it for now
223 void BranchItem::setTask(Task *t)
229 Task *BranchItem::getTask() { return task; }
231 void BranchItem::scroll()
238 void BranchItem::unScroll()
246 bool BranchItem::toggleScroll()
248 // MapCenters are not scrollable
255 systemFlags.deactivate(QString("system-scrolledright"));
256 if (branchCounter > 0)
257 for (int i = 0; i < branchCounter; ++i) {
258 bo = (BranchObj *)(getBranchNum(i)->getMO());
260 bo->setVisibility(true); // Recursively!
265 systemFlags.activate(QString("system-scrolledright"));
266 if (branchCounter > 0)
267 for (int i = 0; i < branchCounter; ++i) {
268 bo = (BranchObj *)(getBranchNum(i)->getMO());
270 bo->setVisibility(false); // Recursively!
276 bool BranchItem::isScrolled() { return scrolled; }
278 bool BranchItem::hasScrolledParent(BranchItem *start)
280 // Calls parents recursivly to
281 // find out, if we are scrolled at all.
282 // But ignore myself, just look at parents.
287 if (this != start && scrolled)
290 BranchItem *bi = (BranchItem *)parentItem;
291 if (bi && bi != rootItem)
292 return bi->hasScrolledParent(start);
297 bool BranchItem::tmpUnscroll(BranchItem *start)
304 // Unscroll parent (recursivly)
305 BranchItem *pi = (BranchItem *)parentItem;
306 if (pi && pi->isBranchLikeType())
307 result = pi->tmpUnscroll(start);
310 if (start != this && scrolled) {
311 tmpUnscrolled = true;
312 systemFlags.activate(QString("system-tmpUnscrolledRight"));
314 model->emitDataChanged(this);
320 bool BranchItem::resetTmpUnscroll()
324 // Unscroll parent (recursivly)
325 BranchItem *pi = (BranchItem *)parentItem;
326 if (pi && pi->isBranchLikeType())
327 result = pi->resetTmpUnscroll();
331 tmpUnscrolled = false;
332 systemFlags.deactivate(QString("system-tmpUnscrolledRight"));
334 model->emitDataChanged(this);
340 void BranchItem::sortChildren(
341 bool inverse) // FIXME-4 optimize by not using moveUp/Down
343 int childCount = branchCounter;
345 bool madeChanges = false;
348 for (curChildIndex = 1; curChildIndex < childCount; curChildIndex++) {
349 BranchItem *curChild = getBranchNum(curChildIndex);
350 BranchItem *prevChild = getBranchNum(curChildIndex - 1);
352 if (prevChild->getHeadingPlain().compare(
353 curChild->getHeadingPlain(), Qt::CaseInsensitive) < 0) {
354 model->moveUp(curChild);
358 else if (prevChild->getHeadingPlain().compare(
359 curChild->getHeadingPlain(), Qt::CaseInsensitive) >
361 model->moveUp(curChild);
365 } while (madeChanges);
368 void BranchItem::setChildrenLayout(BranchItem::LayoutHint layoutHint)
370 childrenLayout = layoutHint;
373 BranchItem::LayoutHint BranchItem::getChildrenLayout()
375 return childrenLayout;
378 void BranchItem::setIncludeImagesVer(bool b) { includeImagesVer = b; }
380 bool BranchItem::getIncludeImagesVer() { return includeImagesVer; }
382 void BranchItem::setIncludeImagesHor(bool b) { includeImagesHor = b; }
384 bool BranchItem::getIncludeImagesHor() { return includeImagesHor; }
386 QString BranchItem::getIncludeImageAttr()
389 if (includeImagesVer)
390 a = attribut("incImgV", "true");
391 if (includeImagesHor)
392 a += attribut("incImgH", "true");
396 BranchItem *BranchItem::getFramedParentBranch(BranchItem *start)
398 BranchObj *bo = getBranchObj();
399 if (bo && bo->getFrameType() != FrameObj::NoFrame) {
400 if (bo->getFrame()->getFrameIncludeChildren())
405 BranchItem *bi = (BranchItem *)parentItem;
406 if (bi && bi != rootItem)
407 return bi->getFramedParentBranch(start);
412 void BranchItem::setFrameIncludeChildren(bool b)
414 includeChildren = b; // FIXME-4 ugly: same information stored in FrameObj
415 BranchObj *bo = getBranchObj();
417 bo->getFrame()->setFrameIncludeChildren(b);
420 bool BranchItem::getFrameIncludeChildren()
422 BranchObj *bo = getBranchObj();
424 return bo->getFrame()->getFrameIncludeChildren();
426 return includeChildren;
429 QColor BranchItem::getBackgroundColor(BranchItem *start, bool checkInnerFrame)
432 // Determine background color in taskEditor, first try inner frame
433 if (checkInnerFrame && branchContainer->frameType(true) != FrameContainer::NoFrame)
434 return branchContainer->frameBrushColor(true);
437 if (branchContainer->frameType(false) != FrameContainer::NoFrame)
438 return branchContainer->frameBrushColor(false);
440 BranchItem *pb = parentBranch();
441 if (pb && pb != rootItem)
442 // Recursively try parents and check for frames there
443 return pb->getBackgroundColor(start, false);
446 BranchItem *bi = getFramedParentBranch(start);
448 return bi->getBranchObj()->getFrameBrushColor();
451 return model->getMapBackgroundColor();
454 void BranchItem::setLastSelectedBranch()
459 // Hack to save an additional lastSelected for mapcenters in
460 // MapEditor depending on orientation this allows to go both left
461 // and right from there
462 if (mo && ((BranchObj *)mo)->getOrientation() ==
463 LinkableMapObj::LeftOfCenter) {
464 ((BranchItem *)parentItem)->lastSelectedBranchNumAlt =
465 parentItem->num(this);
468 ((BranchItem *)parentItem)->lastSelectedBranchNum =
469 parentItem->num(this);
473 void BranchItem::setLastSelectedBranch(int i) { lastSelectedBranchNum = i; }
475 BranchItem *BranchItem::getLastSelectedBranch()
477 if (lastSelectedBranchNum >= branchCounter)
478 return getBranchNum(branchCounter - 1);
480 return getBranchNum(lastSelectedBranchNum);
483 BranchItem *BranchItem::getLastSelectedBranchAlt()
485 return getBranchNum(lastSelectedBranchNumAlt);
488 TreeItem *BranchItem::findMapItem(QPointF p, TreeItem *excludeTI)
492 for (int i = 0; i < branchCount(); ++i) {
493 ti = getBranchNum(i)->findMapItem(p, excludeTI);
500 for (int i = 0; i < imageCount(); ++i) {
502 MapObj *mo = ii->getMO();
503 if (mo && mo->isInClickBox(p) && (ii != excludeTI) &&
504 this != excludeTI && mo->isVisibleObj())
509 if (getBranchObj()->isInClickBox(p) && (this != excludeTI) &&
510 getBranchObj()->isVisibleObj())
515 for (int i = 0; i < attributeCount(); ++i) {
516 ai = getAttributeNum(i);
517 MapObj *mo = ai->getMO();
518 if (mo && mo->isInClickBox(p) && (ai != excludeTI) &&
519 this != excludeTI && mo->isVisibleObj())
525 void BranchItem::updateStyles(const bool &keepFrame)
527 // Update styles when relinking branches
529 BranchObj *bo = getBranchObj();
530 if (parentItem != rootItem)
531 bo->setParObj((LinkableMapObj *)(((MapItem *)parentItem)->getMO()));
534 bo->setDefAttr(BranchObj::MovedBranch, keepFrame);
538 BranchObj *BranchItem::getBranchObj() { return (BranchObj *)mo; }
540 BranchObj *BranchItem::createMapObj(QGraphicsScene *scene)
544 if (parentItem == rootItem) {
545 newbo = new BranchObj(NULL, this);
547 scene->addItem(newbo);
550 newbo = new BranchObj(((MapItem *)parentItem)->getMO(), this);
552 // Set visibility depending on parents
553 if (parentItem != rootItem &&
554 (((BranchItem *)parentItem)->scrolled ||
555 !((MapItem *)parentItem)->getLMO()->isVisibleObj()))
556 newbo->setVisibility(false);
560 -M_PI_4 + M_PI_2 * (num()) + (M_PI_4 / 2) * (num() / 4 % 4);
561 QPointF p(r * cos(a), r * sin(a));
565 newbo->setDefAttr(BranchObj::NewBranch);
568 if (!getHeading().isEmpty()) {
569 newbo->updateVisuals();
570 newbo->setColor(heading.getColor());