5 #include "branchitem.h"
7 #include "mainwindow.h"
9 #include "warningdialog.h"
10 #include "xlinkitem.h"
13 extern int statusbarTime;
14 extern Main *mainWindow;
15 extern QString tmpVymDir;
16 extern QString clipboardDir;
17 extern QString clipboardFile;
18 extern bool clipboardEmpty;
21 extern QMenu* branchContextMenu;
22 extern QMenu* floatimageContextMenu;
23 extern QMenu* canvasContextMenu;
25 extern Settings settings;
26 extern QString iconPath;
28 ///////////////////////////////////////////////////////////////////////
29 ///////////////////////////////////////////////////////////////////////
30 MapEditor::MapEditor( VymModel *vm)
32 //qDebug() << "Constructor ME "<<this;
33 mapScene= new QGraphicsScene(NULL);
34 mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern));
36 zoomFactor=zoomFactorTarget=1;
39 model->setScene (mapScene);
40 model->registerEditor(this);
41 model->makeDefault(); // No changes in model so far
47 // Create bitmap cursors, platform dependant
48 HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);
49 PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
50 CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 );
51 XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 );
53 //setFocusPolicy (Qt::StrongFocus); //FIXME-3
66 setAcceptDrops (true);
68 //model->reposition(); //FIXME-3 really still needed?
71 // Shortcuts and actions
73 a = new QAction("Select upper branch", this);
74 a->setShortcut (Qt::Key_Up );
75 a->setShortcutContext (Qt::WidgetShortcut);
77 connect( a, SIGNAL( triggered() ), this, SLOT( cursorUp() ) );
79 a = new QAction( "Select lower branch",this);
80 a->setShortcut ( Qt::Key_Down );
81 a->setShortcutContext (Qt::WidgetShortcut);
83 connect( a, SIGNAL( triggered() ), this, SLOT( cursorDown() ) );
85 a = new QAction( "Select left branch", this);
86 a->setShortcut (Qt::Key_Left );
87 // a->setShortcutContext (Qt::WindowShortcut);
88 // a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
90 connect( a, SIGNAL( triggered() ), this, SLOT( cursorLeft() ) );
92 a = new QAction( "Select child branch", this);
93 a->setShortcut (Qt::Key_Right);
94 // a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
96 connect( a, SIGNAL( triggered() ), this, SLOT( cursorRight() ) );
98 a = new QAction( "Select first branch", this);
99 a->setShortcut (Qt::Key_Home );
100 a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
102 connect( a, SIGNAL( triggered() ), this, SLOT( cursorFirst() ) );
104 a = new QAction( "Select last branch",this);
105 a->setShortcut ( Qt::Key_End );
106 a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
108 connect( a, SIGNAL( triggered() ), this, SLOT( cursorLast() ) );
110 // Action to embed LineEdit for heading in Scene
111 editingHeading=false;
114 a = new QAction( tr( "Edit heading","MapEditor" ), this);
115 a->setShortcut ( Qt::Key_Return ); //Edit heading
116 a->setShortcutContext (Qt::WidgetShortcut);
118 connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
119 a = new QAction( tr( "Edit heading","MapEditor" ), this);
120 a->setShortcut ( Qt::Key_Enter); //Edit heading
122 connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
125 selectionColor =QColor (255,255,0);
128 // Attributes //FIXME-2 testing only...
131 attrTable= new AttributeTable();
133 ad=attrTable->addKey (k,StringList);
137 sl <<"val 1"<<"val 2"<< "val 3";
138 ad->setValue (QVariant (sl));
140 //attrTable->addValue ("Key A","P 1");
141 //attrTable->addValue ("Key A","P 2");
142 //attrTable->addValue ("Key A","P 3");
143 //attrTable->addValue ("Key A","P 4");
145 ad=attrTable->addKey (k,FreeString);
148 //attrTable->addValue ("Key B","w1");
149 //attrTable->addValue ("Key B","w2");
151 k="C - UniqueString";
152 ad=attrTable->addKey (k,UniqueString);
155 //attrTable->addKey ("Key Prio");
156 //attrTable->addValue ("Key Prio","Prio 1");
157 //attrTable->addValue ("Key Prio","Prio 2");
161 MapEditor::~MapEditor()
163 //qDebug() <<"Destructor MapEditor for "<<model->getMapName();
164 model->unregisterEditor(this);
167 VymModel* MapEditor::getModel()
172 QGraphicsScene * MapEditor::getScene()
177 void MapEditor::scrollTo (const QModelIndex &index)
181 LinkableMapObj* lmo=NULL;
182 TreeItem *ti= static_cast<TreeItem*>(index.internalPointer());
183 if (ti->getType()==TreeItem::Image ||ti->isBranchLikeType() )
184 lmo=((MapItem*)ti)->getLMO();
187 QRectF r=lmo->getBBox();
188 setScrollBarPosTarget (r);
193 void MapEditor::setScrollBarPosTarget (const QRectF &rect)
195 // Code copied from Qt sources
199 qreal width = viewport()->width();
200 qreal height = viewport()->height();
201 QRectF viewRect = matrix().mapRect(rect);
203 qreal left = horizontalScrollBar()->value();
204 qreal right = left + width;
205 qreal top = verticalScrollBar()->value();
206 qreal bottom = top + height;
208 scrollBarPosTarget=getScrollBarPos();
210 if (viewRect.left() <= left + xmargin) {
211 // need to scroll from the left
212 // if (!d->leftIndent)
213 scrollBarPosTarget.setX(int(viewRect.left() - xmargin - 0.5));
215 if (viewRect.right() >= right - xmargin) {
216 // need to scroll from the right
217 // if (!d->leftIndent)
218 scrollBarPosTarget.setX(int(viewRect.right() - width + xmargin + 0.5));
220 if (viewRect.top() <= top + ymargin) {
221 // need to scroll from the top
222 // if (!d->topIndent)
223 scrollBarPosTarget.setY(int(viewRect.top() - ymargin - 0.5));
225 if (viewRect.bottom() >= bottom - ymargin) {
226 // need to scroll from the bottom
227 // if (!d->topIndent)
228 scrollBarPosTarget.setY(int(viewRect.bottom() - height + ymargin + 0.5));
231 if (scrollBarPosTarget==getScrollBarPos()) return;
233 if (scrollBarPosAnimation.state()==QtAbstractAnimation::Running)
234 scrollBarPosAnimation.stop();
236 if (settings.value ("/animation/use/",true).toBool() )
238 scrollBarPosAnimation.setTargetObject (this);
239 scrollBarPosAnimation.setPropertyName ("scrollBarPos");
240 scrollBarPosAnimation.setDuration(1000);
241 scrollBarPosAnimation.setEasingCurve ( QtEasingCurve::OutQuint);
242 scrollBarPosAnimation.setStartValue(
243 QPointF (horizontalScrollBar()->value() ,
244 verticalScrollBar()->value() ) );
245 scrollBarPosAnimation.setEndValue(scrollBarPosTarget);
246 scrollBarPosAnimation.start();
248 setScrollBarPos (scrollBarPosTarget);
251 QPointF MapEditor::getScrollBarPosTarget()
253 return scrollBarPosTarget;
257 void MapEditor::setScrollBarPos(const QPointF &p)
260 horizontalScrollBar()->setValue(int(p.x()));
261 verticalScrollBar()->setValue(int(p.y()));
264 QPointF MapEditor::getScrollBarPos()
266 return QPointF (horizontalScrollBar()->value(),verticalScrollBar()->value());
267 //return scrollBarPos;
270 void MapEditor::setZoomFactorTarget (const qreal &zft)
272 zoomFactorTarget=zft;
273 if (zoomAnimation.state()==QtAbstractAnimation::Running)
274 zoomAnimation.stop();
275 if (settings.value ("/animation/use/",true).toBool() )
277 //zoomAnimation=QPropertyAnimation(this, "zoomFactor");
278 zoomAnimation.setTargetObject (this);
279 zoomAnimation.setPropertyName ("zoomFactor");
280 zoomAnimation.setDuration(1000);
281 zoomAnimation.setEasingCurve ( QtEasingCurve::OutQuint);
282 zoomAnimation.setStartValue(zoomFactor);
283 zoomAnimation.setEndValue(zft);
284 zoomAnimation.start();
289 qreal MapEditor::getZoomFactorTarget()
291 return zoomFactorTarget;
295 void MapEditor::setZoomFactor(const qreal &zf)
298 setMatrix (QMatrix(zf, 0, 0, zf, 0, 0),false );
301 qreal MapEditor::getZoomFactor()
306 void MapEditor::print()
310 printer = new QPrinter;
311 printer->setColorMode (QPrinter::Color);
312 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
313 printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
314 printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
317 QRectF totalBBox=getTotalBBox();
319 // Try to set orientation automagically
320 // Note: Interpretation of generated postscript is amibiguous, if
321 // there are problems with landscape mode, see
322 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
324 if (totalBBox.width()>totalBBox.height())
325 // recommend landscape
326 printer->setOrientation (QPrinter::Landscape);
328 // recommend portrait
329 printer->setOrientation (QPrinter::Portrait);
331 if ( printer->setup(this) )
332 // returns false, if printing is canceled
334 QPainter pp(printer);
336 pp.setRenderHint(QPainter::Antialiasing,true);
338 // Don't print the visualisation of selection
341 QRectF mapRect=totalBBox;
342 QGraphicsRectItem *frame=NULL;
346 // Print frame around map
347 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
348 totalBBox.width()+20, totalBBox.height()+20);
349 frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
355 double paperAspect = (double)printer->width() / (double)printer->height();
356 double mapAspect = (double)mapRect.width() / (double)mapRect.height();
358 if (mapAspect>=paperAspect)
360 // Fit horizontally to paper width
361 //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
362 viewBottom=(int)(printer->width()/mapAspect);
365 // Fit vertically to paper height
366 //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
367 viewBottom=printer->height();
372 // Print footer below map
374 font.setPointSize(10);
376 QRectF footerBox(0,viewBottom,printer->width(),15);
377 // FIXME-3 fileName not any longer available here: pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
378 pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
382 QRectF (0,0,printer->width(),printer->height()-15),
383 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
386 // Viewport has paper dimension
387 if (frame) delete (frame);
392 // Save settings in vymrc
393 settings.writeEntry("/mainwindow/printerName",printer->printerName());
394 settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
395 settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
399 QRectF MapEditor::getTotalBBox()
403 pen.setCapStyle ( Qt::RoundCap );
407 BranchItem *cur=NULL;
408 BranchItem *prev=NULL;
409 model->nextBranch(cur,prev);
412 if (!cur->hasHiddenExportParent())
414 bo=(BranchObj*)(cur->getLMO());
415 if (bo && bo->isVisibleObj())
417 bo->calcBBoxSizeWithChildren();
419 //QRectF r1=bo->getBBoxSizeWithChildren();
420 QRectF r1=bo->getBBox();
421 //pen.setColor ( QColor(qrand()%32*8,qrand()%32*8,qrand()%32*8));
422 //mapScene->addRect (r1,pen);
424 if (rt.isNull()) rt=r1;
426 //qDebug() <<"ME: r1="<<r1<<" "<<cur->getHeadingStd();
427 //qDebug() <<" rt="<<rt;
430 model->nextBranch(cur,prev);
436 QImage MapEditor::getImage()
438 QRectF mapRect=getTotalBBox();
439 int w=mapRect.width()+2;
440 int h=mapRect.height()+2;
442 QImage pix (w,h,QImage::Format_RGB32);
446 pp.setRenderHints(renderHints());
447 mapScene->render ( &pp,
449 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
454 void MapEditor::setAntiAlias (bool b)
456 setRenderHint(QPainter::Antialiasing,b);
459 void MapEditor::setSmoothPixmap(bool b)
461 setRenderHint(QPainter::SmoothPixmapTransform,b);
464 void MapEditor::setHideTmp (bool b) // FIXME-4 better use signals
469 setHideTmpMode (HideExport);
470 mapCenter->calcBBoxSizeWithChilds();
471 QRectF totalBBox=mapCenter->getTotalBBox();
472 //QRectF mapRect=totalBBox;
473 qDebug() << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
475 mapRect.setRect (totalBBox.x(), totalBBox.y(),
476 totalBBox.width(), totalBBox.height());
478 QCanvasRectangle *frame=new QCanvasRectangle (mapRect,mapScene);
479 frame->setBrush (QColor(white));
480 frame->setPen (QColor(black));
487 setHideTmpMode (HideNone);
489 qDebug() <<" hidemode="<<hidemode;
493 if (hidemode==HideExport)
494 setHideTmpMode (HideNone);
496 setHideTmpMode (HideExport);
501 void MapEditor::autoLayout()
503 // Create list with all bounding polygons
504 QList <LinkableMapObj*> mapobjects;
505 QList <ConvexPolygon> polys;
507 QList <Vector> vectors;
508 QList <Vector> orgpos;
509 QStringList headings; //FIXME-3 testing only
515 // Outer loop: Iterate until we no more changes in orientation
516 bool orientationChanged=true;
517 while (orientationChanged)
519 BranchItem *ri=model->getRootItem();
520 for (int i=0;i<ri->branchCount();++i)
522 bi=ri->getBranchNum (i);
523 bo=(BranchObj*)bi->getLMO();
526 mapobjects.append (bo);
527 p=bo->getBoundingPolygon();
530 vectors.append (QPointF(0,0));
531 orgpos.append (p.at(0));
532 headings.append (bi->getHeading());
534 for (int j=0;j<bi->branchCount();++j)
536 bi2=bi->getBranchNum (j);
537 bo=(BranchObj*)bi2->getLMO();
540 mapobjects.append (bo);
541 p=bo->getBoundingPolygon();
544 vectors.append (QPointF(0,0));
545 orgpos.append (p.at(0));
546 headings.append (bi2->getHeading());
551 // Iterate moving bounding polygons until we have no more collisions
556 for (int i=0; i<polys.size()-1; ++i)
558 for (int j=i+1; j<polys.size();++j)
560 if (polygonCollision (polys.at(i),polys.at(j), QPointF(0,0)).intersect )
563 if (debug) qDebug() << "Collision: "<<headings[i]<<" - "<<headings[j];
564 v=polys.at(j).centroid()-polys.at(i).centroid();
565 // Move also away if centroids are identical
568 //qDebug() << "v==0="<<polys[i].centroid()<<polys[j].centroid()<<" "<<v;
569 v.setX (rand()%200 -100);
570 v.setY (rand()%200 -100);
574 //qDebug() << " v="<<v;
575 vectors[j]=v*10000/polys.at(j).weight();
576 vectors[i]=v*10000/polys.at(i).weight();
578 //FIXME-3 outer loop, "i" get's changed several times...
579 // Better not move away from centroid of 2 colliding polys, but from centroid of _all_
583 for (int i=0;i<vectors.size();i++)
585 //qDebug() << " v="<<vectors[i]<<" "<<headings[i];
586 if (!vectors[i].isNull() )
587 polys[i].translate (vectors[i]);
589 if (debug) qDebug()<< "Collisions total: "<<collisions;
593 // Finally move the real objects and update
594 QList <LinkableMapObj::Orientation> orients;
595 for (int i=0;i<polys.size();i++)
597 Vector v=polys[i].at(0)-orgpos[i];
598 orients.append (mapobjects[i]->getOrientation());
601 if (debug) cout<<" Moving "<<polys.at(i).weight()<<" "<<mapobjects[i]->getAbsPos()<<" -> "<<mapobjects[i]->getAbsPos() + v<<" "<<headings[i].toStdString()<<endl;
602 //mapobjects[i]->moveBy(v.x(),v.y() );
603 //mapobjects[i]->setRelPos();
604 model->startAnimation ((BranchObj*)mapobjects[i], v);
605 if (debug) cout<<i<< " Weight: "<<polys.at(i).weight()<<" "<<v<<" "<<headings.at(i).toStdString()<<endl;
610 orientationChanged=false;
611 for (int i=0;i<polys.size();i++)
612 if (orients[i]!=mapobjects[i]->getOrientation())
614 orientationChanged=true;
621 //orientationChanged=false;
622 } // loop if orientation has changed
624 model->emitSelectionChanged();
627 TreeItem* MapEditor::findMapItem (QPointF p,TreeItem *exclude)
629 // Start with mapcenter, no images allowed at rootItem
631 BranchItem *bi=model->getRootItem()->getFirstBranch();
632 TreeItem *found=NULL;
635 found=bi->findMapItem (p, exclude);
636 if (found) return found;
638 bi=model->getRootItem()->getBranchNum(i);
643 AttributeTable* MapEditor::attributeTable()
648 void MapEditor::testFunction1()
650 qDebug()<< "ME::test1 selected TI="<<model->getSelectedItem();
651 model->setExportMode (true);
654 // Code copied from Qt sources
655 QRectF rect=model->getSelectedBranchObj()->getBBox();
659 qreal width = viewport()->width();
660 qreal height = viewport()->height();
661 QRectF viewRect = matrix().mapRect(rect);
663 qreal left = horizontalScrollBar()->value();
664 qreal right = left + width;
665 qreal top = verticalScrollBar()->value();
666 qreal bottom = top + height;
668 if (viewRect.left() <= left + xmargin) {
669 // need to scroll from the left
670 // if (!d->leftIndent)
671 horizontalScrollBar()->setValue(int(viewRect.left() - xmargin - 0.5));
673 if (viewRect.right() >= right - xmargin) {
674 // need to scroll from the right
675 // if (!d->leftIndent)
676 horizontalScrollBar()->setValue(int(viewRect.right() - width + xmargin + 0.5));
678 if (viewRect.top() <= top + ymargin) {
679 // need to scroll from the top
680 // if (!d->topIndent)
681 verticalScrollBar()->setValue(int(viewRect.top() - ymargin - 0.5));
683 if (viewRect.bottom() >= bottom - ymargin) {
684 // need to scroll from the bottom
685 // if (!d->topIndent)
686 verticalScrollBar()->setValue(int(viewRect.bottom() - height + ymargin + 0.5));
688 qDebug() << "test1: hor="<<horizontalScrollBar()->value();
689 qDebug() << "test1: ver="<<verticalScrollBar()->value();
694 QtPropertyAnimation *animation=new QtPropertyAnimation(this, "sceneRect");
695 animation->setDuration(5000);
696 //animation->setEasingCurve ( QtEasingCurve::OutElastic);
697 animation->setEasingCurve ( QtEasingCurve::OutQuint);
698 animation->setStartValue(sceneRect() );
699 animation->setEndValue(QRectF(50, 50, 1000, 1000));
704 QDialog *dia= new QDialog (this);
705 dia->setGeometry (50,50,10,10);
710 QtPropertyAnimation *animation=new QtPropertyAnimation(dia, "geometry");
711 animation->setDuration(1000);
712 //animation->setEasingCurve ( QtEasingCurve::OutElastic);
713 animation->setEasingCurve ( QtEasingCurve::OutQuint);
714 animation->setStartValue(QRect(50, 50, 10, 10));
715 animation->setEndValue(QRect(250, 250, 100, 100));
722 void MapEditor::testFunction2()
727 BranchItem* MapEditor::getBranchDirectAbove (BranchItem *bi)
732 if (i>0) return bi->parent()->getBranchNum(i-1);
737 BranchItem* MapEditor::getBranchAbove (BranchItem *selbi)
741 int dz=selbi->depth(); // original depth
743 if (selbi->getLMO()->getOrientation()==LinkableMapObj::LeftOfCenter)
748 // Look for branch with same parent but directly above
750 bi=getBranchDirectBelow(selbi);
752 bi=getBranchDirectAbove (selbi);
755 // direct predecessor
758 // Go towards center and look for predecessor
759 while (selbi->depth()>0)
761 selbi=(BranchItem*)(selbi->parent());
762 if (selbi->depth()==1 && invert)
763 bi=getBranchDirectBelow (selbi);
765 bi=getBranchDirectAbove (selbi);
770 while (selbi->depth()<dz)
772 // try to get back to original depth dz
773 bi=selbi->getLastBranch();
787 BranchItem* MapEditor::getBranchDirectBelow(BranchItem *bi)
792 if (i+1<bi->parent()->branchCount()) return bi->parent()->getBranchNum(i+1);
797 BranchItem* MapEditor::getBranchBelow (BranchItem *selbi)
802 int dz=selbi->depth(); // original depth
804 if (selbi->getLMO()->getOrientation()==LinkableMapObj::LeftOfCenter)
808 // Look for branch with same parent but directly below
810 bi=getBranchDirectAbove (selbi);
812 bi=getBranchDirectBelow (selbi);
818 // Go towards center and look for neighbour
819 while (selbi->depth()>0)
821 selbi=(BranchItem*)(selbi->parent());
822 if (selbi->depth()==1 && invert)
823 bi=getBranchDirectAbove (selbi);
825 bi=getBranchDirectBelow (selbi);
830 while (selbi->depth()<dz)
832 // try to get back to original depth dz
833 bi=selbi->getFirstBranch();
847 BranchItem* MapEditor::getLeftBranch (BranchItem *bi)
852 // Special case: use alternative selection index
853 return bi->getLastSelectedBranchAlt();
854 if (bi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter)
856 return (BranchItem*)(bi->parent());
859 if (bi->getType()== TreeItem::Branch )
860 return bi->getLastSelectedBranch();
865 BranchItem* MapEditor::getRightBranch(BranchItem *bi)
869 if (bi->depth()==0) return bi->getLastSelectedBranch();
870 if (bi->getBranchObj()->getOrientation()==LinkableMapObj::LeftOfCenter)
872 return (BranchItem*)(bi->parent());
875 if (bi->getType()== TreeItem::Branch )
876 return (BranchItem*)bi->getLastSelectedBranch();
883 void MapEditor::cursorUp()
885 BranchItem *bi=model->getSelectedBranch();
886 if (bi) model->select (getBranchAbove(bi));
889 void MapEditor::cursorDown()
892 BranchItem *bi=model->getSelectedBranch();
893 if (bi) model->select (getBranchBelow(bi));
896 void MapEditor::cursorLeft()
898 BranchItem *bi=getLeftBranch (model->getSelectedBranch());
899 if (bi) model->select (bi);
902 void MapEditor::cursorRight()
904 BranchItem *bi=getRightBranch (model->getSelectedBranch());
905 if (bi) model->select (bi);
908 void MapEditor::cursorFirst()
910 model->selectFirstBranch();
913 void MapEditor::cursorLast()
915 model->selectLastBranch();
919 void MapEditor::editHeading()
923 editHeadingFinished();
926 BranchObj *bo=model->getSelectedBranchObj();
927 BranchItem *bi=model->getSelectedBranch();
930 model->setSelectionBlocked(true);
932 lineEdit=new QLineEdit;
933 QGraphicsProxyWidget *pw=scene()->addWidget (lineEdit);
934 pw->setZValue (Z_LINEEDIT);
936 lineEdit->setText (bi->getHeading());
937 QPoint p = mapTo (this,bo->getAbsPos().toPoint() );
938 lineEdit->setGeometry(p.x(),p.y(),230,25);
939 //lineEdit->selectAll();
940 //lineEdit->setCursorPosition (1);
942 lineEdit->setFocus();
943 lineEdit->grabKeyboard();
948 void MapEditor::editHeadingFinished()
950 editingHeading=false;
951 lineEdit->releaseKeyboard();
952 lineEdit->clearFocus();
953 QString s=lineEdit->text();
954 s.replace (QRegExp ("\\n")," "); // Don't paste newline chars
955 model->setHeading (s);
956 model->setSelectionBlocked(false);
959 // Maybe reselect previous branch
960 mainWindow->editHeadingFinished (model);
964 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
966 // Lineedits are already closed by preceding
967 // mouseEvent, we don't need to close here.
969 QPointF p = mapToScene(e->pos());
970 TreeItem *ti=findMapItem (p, NULL);
971 LinkableMapObj* lmo=NULL;
972 if (ti) lmo=((MapItem*)ti)->getLMO();
975 { // MapObj was found
976 if (model->getSelectedLMO() != lmo)
982 if (model->getSelectedBranchObj() )
984 // Context Menu on branch or mapcenter
985 branchContextMenu->popup(e->globalPos() );
988 if (model->getSelectedImage() )
990 // Context Menu on floatimage
991 floatimageContextMenu->popup(e->globalPos() );
995 { // No MapObj found, we are on the Canvas itself
996 // Context Menu on scene
998 // Open context menu synchronously to position new mapcenter
999 model->setContextPos (p);
1000 canvasContextMenu->exec(e->globalPos() );
1001 model->unsetContextPos ();
1006 void MapEditor::keyPressEvent(QKeyEvent* e)
1008 if (e->modifiers() & Qt::ControlModifier)
1010 switch (mainWindow->getModMode())
1012 case Main::ModModeColor:
1013 setCursor (PickColorCursor);
1015 case Main::ModModeCopy:
1016 setCursor (CopyCursor);
1018 case Main::ModModeXLink:
1019 setCursor (XLinkCursor);
1022 setCursor (Qt::ArrowCursor);
1028 void MapEditor::keyReleaseEvent(QKeyEvent* e)
1030 if (!(e->modifiers() & Qt::ControlModifier))
1031 setCursor (Qt::ArrowCursor);
1034 void MapEditor::mousePressEvent(QMouseEvent* e)
1036 //qDebug() << "ME::mousePressed\n"; //FIXME-3
1037 // Ignore right clicks, these will go to context menus
1038 if (e->button() == Qt::RightButton )
1040 //qDebug() << " ME::ignoring right mouse event...\n";
1045 //Ignore clicks while editing heading
1046 if (model->isSelectionBlocked() )
1048 //qDebug() << " ME::ignoring other mouse event...\n";
1053 QPointF p = mapToScene(e->pos());
1054 TreeItem *ti=findMapItem (p, NULL);
1055 LinkableMapObj* lmo=NULL;
1056 if (ti) lmo=((MapItem*)ti)->getLMO();
1061 //Take care of system flags _or_ modifier modes
1063 if (lmo && ti->isBranchLikeType() )
1065 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
1066 if (!foname.isEmpty())
1068 // systemFlag clicked
1069 model->select (lmo);
1070 if (foname.contains("system-url"))
1072 if (e->state() & Qt::ControlModifier)
1073 mainWindow->editOpenURLTab();
1075 mainWindow->editOpenURL();
1077 else if (foname=="system-vymLink")
1079 mainWindow->editOpenVymLink();
1080 // tabWidget may change, better return now
1081 // before segfaulting...
1082 } else if (foname=="system-note")
1083 mainWindow->windowToggleNoteEditor();
1084 else if (foname=="hideInExport")
1085 model->toggleHideExport();
1086 // FIXME-3 needed? xelection.update();
1090 // Take care of xLink
1091 if (ti->xlinkCount()>0 && lmo->getBBox().width()>30)
1093 if ((lmo->getOrientation()!=LinkableMapObj::RightOfCenter && p.x() < lmo->getBBox().left()+20) ||
1094 (lmo->getOrientation()!=LinkableMapObj::LeftOfCenter && p.x() > lmo->getBBox().right()-20) )
1096 // FIXME-4 if (ti->xlinkCount()>1)
1100 QList <QAction*> alist;
1101 for (int i=0;i<ti->xlinkCount();i++)
1102 alist.append (new QAction(ti->getXLinkNum(i)->getOtherBranch(ti)->getHeading(),&menu));
1103 menu.addActions (alist);
1104 QAction *ra=menu.exec (e->globalPos() );
1106 model->select (ti->getXLinkNum(alist.indexOf(ra))->getOtherBranch (ti));
1107 while (!alist.isEmpty())
1109 QAction *a=alist.takeFirst();
1115 model->select (ti->getXLinkNum(0)->getOtherBranch (ti));
1123 // No system flag clicked, take care of modmodes (CTRL-Click)
1124 if (e->state() & Qt::ControlModifier)
1126 if (mainWindow->getModMode()==Main::ModModeColor)
1129 setCursor (PickColorCursor);
1132 if (mainWindow->getModMode()==Main::ModModeXLink)
1134 BranchItem *bi_begin=model->getSelectedBranch();
1138 tmpXLink=model->createXLink(bi_begin,true);
1139 tmpXLink->setColor(model->getMapDefXLinkColor());
1140 tmpXLink->setWidth(model->getMapDefXLinkWidth());
1141 tmpXLink->setEnd (p);
1142 tmpXLink->updateXLink();
1146 } // End of modmodes
1151 qDebug() << "ME::mouse pressed\n";
1152 qDebug() << " lmo="<<lmo;
1153 qDebug() << " ti="<<ti->getHeadingStd();
1155 // Select the clicked object
1160 // Left Button Move Branches
1161 if (e->button() == Qt::LeftButton )
1163 movingObj_start.setX( p.x() - lmo->x() );
1164 movingObj_start.setY( p.y() - lmo->y() );
1165 movingObj_orgPos.setX (lmo->x() );
1166 movingObj_orgPos.setY (lmo->y() );
1168 movingObj_orgRelPos=lmo->getRelPos();
1170 // If modMode==copy, then we want to "move" the _new_ object around
1171 // then we need the offset from p to the _old_ selection, because of tmp
1172 if (mainWindow->getModMode()==Main::ModModeCopy &&
1173 e->state() & Qt::ControlModifier)
1175 BranchItem *bi=model->getSelectedBranch();
1179 //FIXME-2 TreeItem::addBranch (BranchItem still missing)
1180 //bi->addBranch (model->getSelectedBranch());
1182 model->select(bi->getLastBranch());
1183 model->reposition();
1187 movingObj=model->getSelectedLMO();
1189 // Middle Button Toggle Scroll
1190 // (On Mac OS X this won't work, but we still have
1191 // a button in the toolbar)
1192 if (e->button() == Qt::MidButton )
1193 model->toggleScroll();
1194 // model->updateActions(); FIXME-3 needed?
1195 // FIXME-3 needed? xelection.update();
1197 { // No MapObj found, we are on the scene itself
1198 // Left Button move Pos of sceneView
1199 if (e->button() == Qt::LeftButton )
1201 movingObj=NULL; // move Content not Obj
1202 movingObj_start=e->globalPos();
1203 movingCont_start=QPointF (
1204 horizontalScrollBar()->value(),
1205 verticalScrollBar()->value());
1206 movingVec=QPointF(0,0);
1207 setCursor(HandOpenCursor);
1212 void MapEditor::mouseMoveEvent(QMouseEvent* e)
1214 QPointF p = mapToScene(e->pos());
1215 TreeItem *seli=model->getSelectedItem();
1216 LinkableMapObj* lmosel=NULL;
1217 if (seli && (seli->isBranchLikeType() ||seli->getType()==TreeItem::Image))
1218 lmosel=((MapItem*)seli)->getLMO();
1220 // Move the selected MapObj
1221 if ( lmosel && movingObj)
1224 // reset cursor if we are moving and don't copy
1225 if (mainWindow->getModMode()!=Main::ModModeCopy)
1226 setCursor (Qt::ArrowCursor);
1228 // To avoid jumping of the sceneView, only
1229 // show selection, if not tmp linked
1230 /* FIXME-2 if (!lmosel->hasParObjTmp())
1231 model->emitShowSelection();
1234 // Now move the selection, but add relative position
1235 // (movingObj_start) where selection was chosen with
1236 // mousepointer. (This avoids flickering resp. jumping
1237 // of selection back to absPos)
1239 // Check if we could link
1240 TreeItem *ti=findMapItem (p, seli);
1241 BranchItem *dsti=NULL;
1242 LinkableMapObj* dst=NULL;
1243 if (ti && ti!=seli && ti->isBranchLikeType())
1245 dsti=(BranchItem*)ti;
1251 if (lmosel && seli->getType()==TreeItem::Image)
1253 FloatObj *fio=(FloatImageObj*)lmosel;
1254 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
1256 fio->updateLinkGeometry(); //no need for reposition, if we update link here
1257 model->emitSelectionChanged(); // position has changed
1259 // Relink float to new mapcenter or branch, if shift is pressed
1260 // Only relink, if selection really has a new parent
1261 if ( e->modifiers()==Qt::ShiftModifier && dsti && dsti != seli->parent() )
1263 // Also save the move which was done so far
1264 QString pold=qpointFToString(movingObj_orgRelPos);
1265 QString pnow=qpointFToString(fio->getRelPos());
1271 QString("Move %1 to relative position %2").arg(model->getObjectName(fio)).arg(pnow));
1272 fio->getParObj()->requestReposition();
1273 model->reposition();
1275 model->relinkImage ((ImageItem*) seli,dsti);
1276 model->select (seli);
1277 //movingObj=lmosel; //FIXME-3
1278 //movingObj_orgRelPos=lmosel->getRelPos();
1280 model->reposition();
1283 { // selection != a FloatObj
1284 if (seli->depth()==0)
1287 lmosel->move (p-movingObj_start);
1288 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
1290 // Move only mapcenter, leave its children where they are
1292 v=lmosel->getAbsPos();
1293 for (int i=0; i<seli->branchCount(); ++i)
1295 seli->getBranchObjNum(i)->setRelPos();
1296 seli->getBranchObjNum(i)->setOrientation();
1301 if (seli->depth()==1)
1304 if (!lmosel->hasParObjTmp())
1305 lmosel->move(p-movingObj_start);
1306 lmosel->setRelPos();
1309 // Move ordinary branch
1310 if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
1311 // Add width of bbox here, otherwise alignRelTo will cause jumping around
1312 lmosel->move(p.x() -movingObj_start.x() , //lmosel->getBBox().width(),
1313 p.y()-movingObj_start.y() +lmosel->getTopPad() );
1315 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
1316 lmosel->setRelPos();
1320 // Maybe we can relink temporary?
1323 if (e->modifiers()==Qt::ControlModifier)
1325 // Special case: CTRL to link below dst
1326 lmosel->setParObjTmp (dst,p,+1);
1327 } else if (e->modifiers()==Qt::ShiftModifier)
1328 lmosel->setParObjTmp (dst,p,-1);
1330 lmosel->setParObjTmp (dst,p,0);
1333 lmosel->unsetParObjTmp();
1335 // reposition subbranch
1336 lmosel->reposition();
1338 QItemSelection sel=model->getSelectionModel()->selection();
1339 updateSelection(sel,sel); // position has changed
1341 } // no FloatImageObj
1345 } // selection && moving_obj
1347 // Draw a link from one branch to another
1350 tmpXLink->setEnd (p);
1351 tmpXLink->updateXLink();
1355 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
1357 QPointF p=e->globalPos();
1358 movingVec.setX(-p.x() + movingObj_start.x() );
1359 movingVec.setY(-p.y() + movingObj_start.y() );
1360 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
1361 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
1366 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
1368 QPointF p = mapToScene(e->pos());
1369 TreeItem *seli=model->getSelectedItem();
1371 TreeItem *dsti=NULL;
1372 if (seli) dsti=findMapItem(p, seli);
1373 LinkableMapObj* dst=NULL;
1374 if (dsti && dsti->isBranchLikeType ())
1375 dst=((MapItem*)dsti)->getLMO();
1380 // Have we been picking color?
1384 setCursor (Qt::ArrowCursor);
1385 // Check if we are over another branch
1388 if (e->state() & Qt::ShiftModifier)
1389 model->colorBranch (((BranchObj*)dst)->getColor());
1391 model->colorSubtree (((BranchObj*)dst)->getColor());
1396 // Have we been drawing a link?
1400 // Check if we are over another branch
1403 tmpXLink->setEnd ( ((BranchItem*)dsti) );
1404 tmpXLink->updateXLink();
1405 tmpXLink->activate();
1407 tmpXLink,QString("delete ()"),
1408 dsti,QString("addXLink (\"%1\",\"%2\")").arg(model->getSelectString(tmpXLink->getBegin())).arg(model->getSelectString(dsti)),
1409 QString("Add xLink from %1 to %2").arg(model->getObjectName(tmpXLink->getBegin())).arg(model->getObjectName(dsti))
1413 model->deleteItem(tmpXLink);
1419 // Have we been moving something?
1420 if ( seli && movingObj )
1422 if (seli->getType()==TreeItem::Image)
1424 FloatImageObj *fio=(FloatImageObj*)( ((MapItem*)seli)->getLMO());
1427 // Moved FloatObj. Maybe we need to reposition
1428 QString pold=qpointFToString(movingObj_orgRelPos);
1429 QString pnow=qpointFToString(fio->getRelPos());
1435 QString("Move %1 to relative position %2").arg(model->getObjectName(seli)).arg(pnow));
1437 fio->getParObj()->requestReposition();
1438 model->reposition();
1442 BranchItem *bi=model->getSelectedBranch();
1443 if (bi && bi->depth()==0)
1445 if (movingObj_orgPos != bi->getBranchObj()->getAbsPos()) // FIXME-3 check getBO here...
1447 QString pold=qpointFToString(movingObj_orgPos);
1448 QString pnow=qpointFToString(bi->getBranchObj()->getAbsPos()); // FIXME-3 check getBO here...
1455 QString("Move mapcenter %1 to position %2").arg(model->getObjectName(bi)).arg(pnow));
1459 if (seli->isBranchLikeType() ) //(seli->getType() == TreeItem::Branch )
1460 { // A branch was moved
1461 LinkableMapObj* lmosel=NULL;
1462 lmosel=((MapItem*)seli)->getLMO();
1464 // save the position in case we link to mapcenter
1465 QPointF savePos=QPointF (lmosel->getAbsPos() );
1467 // Reset the temporary drawn link to the original one
1468 lmosel->unsetParObjTmp();
1470 // For Redo we may need to save original selection
1471 QString preSelStr=model->getSelectString(seli);
1474 if (dsti && objectMoved)
1476 // We have a destination, relink to that
1478 BranchObj* bsel=model->getSelectedBranchObj();
1480 QString preParStr=model->getSelectString (bsel->getParObj());
1481 QString preNum=QString::number (seli->num(),10);
1482 QString preDstParStr;
1485 if (e->state() & Qt::ShiftModifier && dst->getParObj())
1487 preDstParStr=model->getSelectString (dst->getParObj());
1488 relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num());
1490 if (e->state() & Qt::ControlModifier && dst->getParObj())
1493 preDstParStr=model->getSelectString (dst->getParObj());
1494 relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num()+1);
1497 preDstParStr=model->getSelectString(dst);
1498 relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti);
1499 if (dsti->depth()==0) bsel->move (savePos);
1503 QString postSelStr=model->getSelectString(lmosel);
1504 QString postNum=QString::number (seli->num(),10);
1506 QString undoCom="relinkTo (\""+
1507 preParStr+ "\"," + preNum +"," +
1508 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
1510 QString redoCom="relinkTo (\""+
1511 preDstParStr + "\"," + postNum + "," +
1512 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
1517 QString("Relink %1 to %2").arg(model->getObjectName(bsel)).arg(model->getObjectName(dst)) );
1522 // No destination, undo temporary move
1524 if (seli->depth()==1)
1526 // The select string might be different _after_ moving around.
1527 // Therefor reposition and then use string of old selection, too
1528 model->reposition();
1530 QPointF rp(lmosel->getRelPos());
1531 if (rp != movingObj_orgRelPos)
1533 QString ps=qpointFToString(rp);
1535 model->getSelectString(lmosel), "moveRel "+qpointFToString(movingObj_orgRelPos),
1536 preSelStr, "moveRel "+ps,
1537 QString("Move %1 to relative position %2").arg(model->getObjectName(lmosel)).arg(ps));
1541 // Draw the original link, before selection was moved around
1542 if (settings.value("/animation/use",true).toBool()
1544 // && distance (lmosel->getRelPos(),movingObj_orgRelPos)<3
1547 lmosel->setRelPos(); // calc relPos first for starting point
1549 model->startAnimation(
1551 lmosel->getRelPos(),
1555 model->reposition();
1558 model->emitSelectionChanged(); //FIXME-3 needed? at least not after pos of selection has changed...
1559 // Finally resize scene, if needed
1565 // maybe we moved View: set old cursor
1566 setCursor (Qt::ArrowCursor);
1570 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
1574 qDebug()<< "ME p="<<mapToScene (e->pos())<<" scrollBarPos="<<getScrollBarPos() <<
1575 " min="<<QPointF(horizontalScrollBar()->minimum(),verticalScrollBar()->minimum());
1579 if (model->isSelectionBlocked() )
1585 if (e->button() == Qt::LeftButton )
1587 QPointF p = mapToScene(e->pos());
1588 TreeItem *ti=findMapItem (p, NULL);
1589 if (ti) { // MapObj was found
1590 // First select the MapObj than edit heading
1597 void MapEditor::resizeEvent (QResizeEvent* e)
1599 QGraphicsView::resizeEvent( e );
1602 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
1604 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
1605 // cerr << event->format(i) << endl;
1607 if (event->mimeData()->hasImage())
1608 event->acceptProposedAction();
1610 if (event->mimeData()->hasUrls())
1611 event->acceptProposedAction();
1614 void MapEditor::dragMoveEvent(QDragMoveEvent *)
1618 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
1623 void MapEditor::dropEvent(QDropEvent *event)
1625 BranchItem *selbi=model->getSelectedBranch();
1630 foreach (QString format,event->mimeData()->formats())
1631 qDebug()<< "MapEditor: Dropped format: "<<qPrintable (format);
1632 foreach (QString url,event->mimeData()->urls())
1633 qDebug()<< " URL:"<<url;
1634 //foreach (QString plain,event->mimeData()->text())
1635 // qDebug()<< " PLAIN:"<<plain;
1636 QByteArray ba=event->mimeData()->data("STRING");
1640 qDebug() << " STRING:" <<s;
1642 ba=event->mimeData()->data("TEXT");
1644 qDebug() << " TEXT:" <<s;
1646 ba=event->mimeData()->data("COMPOUND_TEXT");
1648 qDebug() << " CTEXT:" <<s;
1650 ba=event->mimeData()->data("text/x-moz-url");
1652 qDebug() << " x-moz-url:" <<s;
1654 if (b!=0) qDebug() << "b="<<b;
1657 if (event->mimeData()->hasImage())
1659 QVariant imageData = event->mimeData()->imageData();
1660 model->addFloatImage (qvariant_cast<QPixmap>(imageData));
1662 if (event->mimeData()->hasUrls())
1664 //model->selectLastBranch();
1665 QList <QUrl> uris=event->mimeData()->urls();
1670 for (int i=0; i<uris.count();i++)
1672 // Workaround to avoid adding empty branches
1673 if (!uris.at(i).toString().isEmpty())
1675 bi=model->addNewBranch();
1679 QString u=uris.at(i).toString();
1680 s=uris.at(i).toLocalFile();
1683 QString file = QDir::fromNativeSeparators(s);
1684 heading = QFileInfo(file).baseName();
1686 if (file.endsWith(".vym", false))
1687 model->setVymLink(file);
1695 // Automatically try to fetch data from Bugzilla
1696 if (settings.value( "/mainwindow/showTestMenu",false).toBool()
1697 && u.contains ("https://bugzilla.novell.com"))
1698 model->getBugzillaData();
1702 if (!heading.isEmpty())
1703 model->setHeading(heading);
1705 model->setHeading(u);
1707 model->select (bi->parent());
1711 //model->reposition();
1714 event->acceptProposedAction();
1717 void MapEditor::updateSelection(QItemSelection newsel,QItemSelection oldsel)
1719 // Note: Here we are prepared for multiple selections, though this
1720 // is not yet implemented elsewhere
1722 // Here in MapEditor we can only select Branches and Images
1723 QList <TreeItem*> treeItemsNew;
1724 QList <TreeItem*> treeItemsOld;
1726 QModelIndex newIndex;
1728 bool do_reposition=false;
1731 foreach (ix,newsel.indexes() )
1733 TreeItem *ti= static_cast<TreeItem*>(ix.internalPointer());
1734 if (ti->isBranchLikeType() || ti->getType()==TreeItem::Image )
1735 if (!treeItemsNew.contains(ti)) treeItemsNew.append (ti);
1737 foreach (ix,oldsel.indexes() )
1739 TreeItem *ti= static_cast<TreeItem*>(ix.internalPointer());
1740 if (ti->isBranchLikeType() || ti->getType()==TreeItem::Image )
1741 if (!treeItemsOld.contains(ti)) treeItemsOld.append (ti);
1744 // Trim list of selection rectangles
1745 while (treeItemsNew.count() < selboxList.count() )
1746 delete selboxList.takeFirst();
1748 // Take care to tmp scroll/unscroll
1749 if (!oldsel.isEmpty())
1751 QModelIndex ix=oldsel.indexes().first();
1754 TreeItem *ti= static_cast<TreeItem*>(ix.internalPointer());
1757 if (ti->isBranchLikeType() )
1759 // reset tmp scrolled branches
1760 BranchItem *bi=(BranchItem*)ti;
1761 if (bi->resetTmpUnscroll() )
1764 if (ti->isBranchLikeType() || ti->getType()==TreeItem::Image)
1765 // Hide link if not needed
1766 ((MapItem*)ti)->getLMO()->updateVisibility();
1771 if (!treeItemsNew.isEmpty())
1773 QModelIndex ix=newsel.indexes().first();
1778 // Temporary unscroll if necessary
1779 TreeItem *ti= static_cast<TreeItem*>(ix.internalPointer());
1780 if (ti->isBranchLikeType() )
1782 BranchItem *bi=(BranchItem*)ti;
1783 if (bi->hasScrolledParent(bi) )
1785 if (bi->parentBranch()->tmpUnscroll() )
1789 if (ti->isBranchLikeType() || ti->getType()==TreeItem::Image)
1790 // Show link if needed
1791 ((MapItem*)ti)->getLMO()->updateVisibility();
1794 if (do_reposition) model->reposition();
1796 // Reduce rectangles
1797 while (treeItemsNew.count() < selboxList.count() )
1798 delete selboxList.takeFirst();
1800 // Add additonal rectangles
1801 QGraphicsRectItem *sb;
1802 while (treeItemsNew.count() > selboxList.count() )
1804 sb = mapScene->addRect(
1806 QPen(selectionColor),
1808 sb->setZValue(Z_SELBOX);
1810 selboxList.append (sb);
1813 // Reposition rectangles
1817 LinkableMapObj *lmo;
1818 for (int i=0; i<treeItemsNew.count();++i)
1820 lmo=((MapItem*)treeItemsNew.at(i) )->getLMO();
1821 bbox=lmo->getBBox();
1822 sb=selboxList.at(i);
1825 bbox.width(), bbox.height());
1826 sb->setPen (selectionColor);
1827 sb->setBrush (selectionColor);
1834 void MapEditor::updateData (const QModelIndex &sel)
1836 TreeItem *ti= static_cast<TreeItem*>(sel.internalPointer());
1839 qDebug() << "ME::updateData\n";
1841 qDebug() << " ti="<<ti;
1842 qDebug() << " h="<<ti->getHeading();
1845 if (ti->isBranchLikeType())
1847 // qDebug() << " ->updating...\n";
1848 BranchObj *bo=(BranchObj*) ( ((MapItem*)ti)->getLMO());
1853 void MapEditor::setSelectionColor (QColor col)
1856 QItemSelection sel=model->getSelectionModel()->selection();
1857 updateSelection(sel,sel);
1861 QColor MapEditor::getSelectionColor ()
1863 return selectionColor;