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()==QAbstractAnimation::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 ( QEasingCurve::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()==QAbstractAnimation::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 ( QEasingCurve::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 v.setX (rand()%200 -100);
569 v.setY (rand()%200 -100);
571 // Add random direction
572 Vector w (cos (rand()%1000),sin(rand()%1000));
574 // Scale translation vector by area of polygons
576 vectors[j]=v*10000/polys.at(j).weight();
577 vectors[i]=v*10000/polys.at(i).weight();
579 //FIXME-3 outer loop, "i" get's changed several times...
580 // Better not move away from centroid of 2 colliding polys,
581 // but from centroid of _all_
585 for (int i=0;i<vectors.size();i++)
587 //qDebug() << " v="<<vectors[i]<<" "<<headings[i];
588 if (!vectors[i].isNull() )
589 polys[i].translate (vectors[i]);
591 if (debug) qDebug()<< "Collisions total: "<<collisions;
595 // Finally move the real objects and update
596 QList <LinkableMapObj::Orientation> orients;
597 for (int i=0;i<polys.size();i++)
599 Vector v=polys[i].at(0)-orgpos[i];
600 orients.append (mapobjects[i]->getOrientation());
603 if (debug) cout<<" Moving "<<polys.at(i).weight()<<" "<<mapobjects[i]->getAbsPos()<<" -> "<<mapobjects[i]->getAbsPos() + v<<" "<<headings[i].toStdString()<<endl;
604 //mapobjects[i]->moveBy(v.x(),v.y() );
605 //mapobjects[i]->setRelPos();
606 model->startAnimation ((BranchObj*)mapobjects[i], v);
607 if (debug) cout<<i<< " Weight: "<<polys.at(i).weight()<<" "<<v<<" "<<headings.at(i).toStdString()<<endl;
612 orientationChanged=false;
613 for (int i=0;i<polys.size();i++)
614 if (orients[i]!=mapobjects[i]->getOrientation())
616 orientationChanged=true;
623 //orientationChanged=false;
624 } // loop if orientation has changed
626 model->emitSelectionChanged();
629 TreeItem* MapEditor::findMapItem (QPointF p,TreeItem *exclude)
631 // Start with mapcenter, no images allowed at rootItem
633 BranchItem *bi=model->getRootItem()->getFirstBranch();
634 TreeItem *found=NULL;
637 found=bi->findMapItem (p, exclude);
638 if (found) return found;
640 bi=model->getRootItem()->getBranchNum(i);
645 AttributeTable* MapEditor::attributeTable()
650 void MapEditor::testFunction1()
652 qDebug()<< "ME::test1 selected TI="<<model->getSelectedItem();
653 model->setExportMode (true);
656 // Code copied from Qt sources
657 QRectF rect=model->getSelectedBranchObj()->getBBox();
661 qreal width = viewport()->width();
662 qreal height = viewport()->height();
663 QRectF viewRect = matrix().mapRect(rect);
665 qreal left = horizontalScrollBar()->value();
666 qreal right = left + width;
667 qreal top = verticalScrollBar()->value();
668 qreal bottom = top + height;
670 if (viewRect.left() <= left + xmargin) {
671 // need to scroll from the left
672 // if (!d->leftIndent)
673 horizontalScrollBar()->setValue(int(viewRect.left() - xmargin - 0.5));
675 if (viewRect.right() >= right - xmargin) {
676 // need to scroll from the right
677 // if (!d->leftIndent)
678 horizontalScrollBar()->setValue(int(viewRect.right() - width + xmargin + 0.5));
680 if (viewRect.top() <= top + ymargin) {
681 // need to scroll from the top
682 // if (!d->topIndent)
683 verticalScrollBar()->setValue(int(viewRect.top() - ymargin - 0.5));
685 if (viewRect.bottom() >= bottom - ymargin) {
686 // need to scroll from the bottom
687 // if (!d->topIndent)
688 verticalScrollBar()->setValue(int(viewRect.bottom() - height + ymargin + 0.5));
690 qDebug() << "test1: hor="<<horizontalScrollBar()->value();
691 qDebug() << "test1: ver="<<verticalScrollBar()->value();
696 QtPropertyAnimation *animation=new QtPropertyAnimation(this, "sceneRect");
697 animation->setDuration(5000);
698 //animation->setEasingCurve ( QtEasingCurve::OutElastic);
699 animation->setEasingCurve ( QtEasingCurve::OutQuint);
700 animation->setStartValue(sceneRect() );
701 animation->setEndValue(QRectF(50, 50, 1000, 1000));
706 QDialog *dia= new QDialog (this);
707 dia->setGeometry (50,50,10,10);
712 QtPropertyAnimation *animation=new QtPropertyAnimation(dia, "geometry");
713 animation->setDuration(1000);
714 //animation->setEasingCurve ( QtEasingCurve::OutElastic);
715 animation->setEasingCurve ( QtEasingCurve::OutQuint);
716 animation->setStartValue(QRect(50, 50, 10, 10));
717 animation->setEndValue(QRect(250, 250, 100, 100));
724 void MapEditor::testFunction2()
729 BranchItem* MapEditor::getBranchDirectAbove (BranchItem *bi)
734 if (i>0) return bi->parent()->getBranchNum(i-1);
739 BranchItem* MapEditor::getBranchAbove (BranchItem *selbi)
743 int dz=selbi->depth(); // original depth
745 if (selbi->getLMO()->getOrientation()==LinkableMapObj::LeftOfCenter)
750 // Look for branch with same parent but directly above
752 bi=getBranchDirectBelow(selbi);
754 bi=getBranchDirectAbove (selbi);
757 // direct predecessor
760 // Go towards center and look for predecessor
761 while (selbi->depth()>0)
763 selbi=(BranchItem*)(selbi->parent());
764 if (selbi->depth()==1 && invert)
765 bi=getBranchDirectBelow (selbi);
767 bi=getBranchDirectAbove (selbi);
772 while (selbi->depth()<dz)
774 // try to get back to original depth dz
775 bi=selbi->getLastBranch();
789 BranchItem* MapEditor::getBranchDirectBelow(BranchItem *bi)
794 if (i+1<bi->parent()->branchCount()) return bi->parent()->getBranchNum(i+1);
799 BranchItem* MapEditor::getBranchBelow (BranchItem *selbi)
804 int dz=selbi->depth(); // original depth
806 if (selbi->getLMO()->getOrientation()==LinkableMapObj::LeftOfCenter)
810 // Look for branch with same parent but directly below
812 bi=getBranchDirectAbove (selbi);
814 bi=getBranchDirectBelow (selbi);
820 // Go towards center and look for neighbour
821 while (selbi->depth()>0)
823 selbi=(BranchItem*)(selbi->parent());
824 if (selbi->depth()==1 && invert)
825 bi=getBranchDirectAbove (selbi);
827 bi=getBranchDirectBelow (selbi);
832 while (selbi->depth()<dz)
834 // try to get back to original depth dz
835 bi=selbi->getFirstBranch();
849 BranchItem* MapEditor::getLeftBranch (BranchItem *bi)
854 // Special case: use alternative selection index
855 return bi->getLastSelectedBranchAlt();
856 if (bi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter)
858 return (BranchItem*)(bi->parent());
861 if (bi->getType()== TreeItem::Branch )
862 return bi->getLastSelectedBranch();
867 BranchItem* MapEditor::getRightBranch(BranchItem *bi)
871 if (bi->depth()==0) return bi->getLastSelectedBranch();
872 if (bi->getBranchObj()->getOrientation()==LinkableMapObj::LeftOfCenter)
874 return (BranchItem*)(bi->parent());
877 if (bi->getType()== TreeItem::Branch )
878 return (BranchItem*)bi->getLastSelectedBranch();
885 void MapEditor::cursorUp()
887 BranchItem *bi=model->getSelectedBranch();
888 if (bi) model->select (getBranchAbove(bi));
891 void MapEditor::cursorDown()
894 BranchItem *bi=model->getSelectedBranch();
895 if (bi) model->select (getBranchBelow(bi));
898 void MapEditor::cursorLeft()
900 BranchItem *bi=getLeftBranch (model->getSelectedBranch());
901 if (bi) model->select (bi);
904 void MapEditor::cursorRight()
906 BranchItem *bi=getRightBranch (model->getSelectedBranch());
907 if (bi) model->select (bi);
910 void MapEditor::cursorFirst()
912 model->selectFirstBranch();
915 void MapEditor::cursorLast()
917 model->selectLastBranch();
921 void MapEditor::editHeading()
925 editHeadingFinished();
928 BranchObj *bo=model->getSelectedBranchObj();
929 BranchItem *bi=model->getSelectedBranch();
932 model->setSelectionBlocked(true);
934 lineEdit=new QLineEdit;
935 QGraphicsProxyWidget *pw=scene()->addWidget (lineEdit);
936 pw->setZValue (Z_LINEEDIT);
938 lineEdit->setText (bi->getHeading());
939 QPoint p = mapTo (this,bo->getAbsPos().toPoint() );
940 lineEdit->setGeometry(p.x(),p.y(),230,25);
941 //lineEdit->selectAll();
942 //lineEdit->setCursorPosition (1);
944 lineEdit->setFocus();
945 lineEdit->grabKeyboard();
950 void MapEditor::editHeadingFinished()
952 editingHeading=false;
953 lineEdit->releaseKeyboard();
954 lineEdit->clearFocus();
955 QString s=lineEdit->text();
956 s.replace (QRegExp ("\\n")," "); // Don't paste newline chars
957 model->setHeading (s);
958 model->setSelectionBlocked(false);
961 // Maybe reselect previous branch
962 mainWindow->editHeadingFinished (model);
966 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
968 // Lineedits are already closed by preceding
969 // mouseEvent, we don't need to close here.
971 QPointF p = mapToScene(e->pos());
972 TreeItem *ti=findMapItem (p, NULL);
973 LinkableMapObj* lmo=NULL;
974 if (ti) lmo=((MapItem*)ti)->getLMO();
977 { // MapObj was found
978 if (model->getSelectedLMO() != lmo)
984 if (model->getSelectedBranchObj() )
986 // Context Menu on branch or mapcenter
987 branchContextMenu->popup(e->globalPos() );
990 if (model->getSelectedImage() )
992 // Context Menu on floatimage
993 floatimageContextMenu->popup(e->globalPos() );
997 { // No MapObj found, we are on the Canvas itself
998 // Context Menu on scene
1000 // Open context menu synchronously to position new mapcenter
1001 model->setContextPos (p);
1002 canvasContextMenu->exec(e->globalPos() );
1003 model->unsetContextPos ();
1008 void MapEditor::keyPressEvent(QKeyEvent* e)
1010 if (e->modifiers() & Qt::ControlModifier)
1012 switch (mainWindow->getModMode())
1014 case Main::ModModeColor:
1015 setCursor (PickColorCursor);
1017 case Main::ModModeCopy:
1018 setCursor (CopyCursor);
1020 case Main::ModModeXLink:
1021 setCursor (XLinkCursor);
1024 setCursor (Qt::ArrowCursor);
1030 void MapEditor::keyReleaseEvent(QKeyEvent* e)
1032 if (!(e->modifiers() & Qt::ControlModifier))
1033 setCursor (Qt::ArrowCursor);
1036 void MapEditor::mousePressEvent(QMouseEvent* e)
1038 //qDebug() << "ME::mousePressed\n"; //FIXME-3
1039 // Ignore right clicks, these will go to context menus
1040 if (e->button() == Qt::RightButton )
1042 //qDebug() << " ME::ignoring right mouse event...\n";
1047 //Ignore clicks while editing heading
1048 if (model->isSelectionBlocked() )
1050 //qDebug() << " ME::ignoring other mouse event...\n";
1055 QPointF p = mapToScene(e->pos());
1056 TreeItem *ti=findMapItem (p, NULL);
1057 LinkableMapObj* lmo=NULL;
1058 if (ti) lmo=((MapItem*)ti)->getLMO();
1063 //Take care of system flags _or_ modifier modes
1065 if (lmo && ti->isBranchLikeType() )
1067 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
1068 if (!foname.isEmpty())
1070 // systemFlag clicked
1071 model->select (lmo);
1072 if (foname.contains("system-url"))
1074 if (e->state() & Qt::ControlModifier)
1075 mainWindow->editOpenURLTab();
1077 mainWindow->editOpenURL();
1079 else if (foname=="system-vymLink")
1081 mainWindow->editOpenVymLink();
1082 // tabWidget may change, better return now
1083 // before segfaulting...
1084 } else if (foname=="system-note")
1085 mainWindow->windowToggleNoteEditor();
1086 else if (foname=="hideInExport")
1087 model->toggleHideExport();
1088 // FIXME-3 needed? xelection.update();
1092 // Take care of xLink
1093 if (ti->xlinkCount()>0 && lmo->getBBox().width()>30)
1095 if ((lmo->getOrientation()!=LinkableMapObj::RightOfCenter && p.x() < lmo->getBBox().left()+20) ||
1096 (lmo->getOrientation()!=LinkableMapObj::LeftOfCenter && p.x() > lmo->getBBox().right()-20) )
1098 // FIXME-4 if (ti->xlinkCount()>1)
1102 QList <QAction*> alist;
1103 for (int i=0;i<ti->xlinkCount();i++)
1104 alist.append (new QAction(ti->getXLinkNum(i)->getOtherBranch(ti)->getHeading(),&menu));
1105 menu.addActions (alist);
1106 QAction *ra=menu.exec (e->globalPos() );
1108 model->select (ti->getXLinkNum(alist.indexOf(ra))->getOtherBranch (ti));
1109 while (!alist.isEmpty())
1111 QAction *a=alist.takeFirst();
1117 model->select (ti->getXLinkNum(0)->getOtherBranch (ti));
1125 // No system flag clicked, take care of modmodes (CTRL-Click)
1126 if (e->state() & Qt::ControlModifier)
1128 if (mainWindow->getModMode()==Main::ModModeColor)
1131 setCursor (PickColorCursor);
1134 if (mainWindow->getModMode()==Main::ModModeXLink)
1136 BranchItem *bi_begin=model->getSelectedBranch();
1140 tmpXLink=model->createXLink(bi_begin,true);
1141 tmpXLink->setColor(model->getMapDefXLinkColor());
1142 tmpXLink->setWidth(model->getMapDefXLinkWidth());
1143 tmpXLink->setEnd (p);
1144 tmpXLink->updateXLink();
1148 } // End of modmodes
1153 qDebug() << "ME::mouse pressed\n";
1154 qDebug() << " lmo="<<lmo;
1155 qDebug() << " ti="<<ti->getHeadingStd();
1157 // Select the clicked object
1162 // Left Button Move Branches
1163 if (e->button() == Qt::LeftButton )
1165 movingObj_start.setX( p.x() - lmo->x() );
1166 movingObj_start.setY( p.y() - lmo->y() );
1167 movingObj_orgPos.setX (lmo->x() );
1168 movingObj_orgPos.setY (lmo->y() );
1170 movingObj_orgRelPos=lmo->getRelPos();
1172 // If modMode==copy, then we want to "move" the _new_ object around
1173 // then we need the offset from p to the _old_ selection, because of tmp
1174 if (mainWindow->getModMode()==Main::ModModeCopy &&
1175 e->state() & Qt::ControlModifier)
1177 BranchItem *bi=model->getSelectedBranch();
1181 //FIXME-2 TreeItem::addBranch (BranchItem still missing)
1182 //bi->addBranch (model->getSelectedBranch());
1184 model->select(bi->getLastBranch());
1185 model->reposition();
1189 movingObj=model->getSelectedLMO();
1191 // Middle Button Toggle Scroll
1192 // (On Mac OS X this won't work, but we still have
1193 // a button in the toolbar)
1194 if (e->button() == Qt::MidButton )
1195 model->toggleScroll();
1196 // model->updateActions(); FIXME-3 needed?
1197 // FIXME-3 needed? xelection.update();
1199 { // No MapObj found, we are on the scene itself
1200 // Left Button move Pos of sceneView
1201 if (e->button() == Qt::LeftButton )
1203 movingObj=NULL; // move Content not Obj
1204 movingObj_start=e->globalPos();
1205 movingCont_start=QPointF (
1206 horizontalScrollBar()->value(),
1207 verticalScrollBar()->value());
1208 movingVec=QPointF(0,0);
1209 setCursor(HandOpenCursor);
1214 void MapEditor::mouseMoveEvent(QMouseEvent* e)
1216 QPointF p = mapToScene(e->pos());
1217 TreeItem *seli=model->getSelectedItem();
1218 LinkableMapObj* lmosel=NULL;
1219 if (seli && (seli->isBranchLikeType() ||seli->getType()==TreeItem::Image))
1220 lmosel=((MapItem*)seli)->getLMO();
1222 // Move the selected MapObj
1223 if ( lmosel && movingObj)
1226 // reset cursor if we are moving and don't copy
1227 if (mainWindow->getModMode()!=Main::ModModeCopy)
1228 setCursor (Qt::ArrowCursor);
1230 // To avoid jumping of the sceneView, only
1231 // show selection, if not tmp linked
1232 /* FIXME-2 if (!lmosel->hasParObjTmp())
1233 model->emitShowSelection();
1236 // Now move the selection, but add relative position
1237 // (movingObj_start) where selection was chosen with
1238 // mousepointer. (This avoids flickering resp. jumping
1239 // of selection back to absPos)
1241 // Check if we could link
1242 TreeItem *ti=findMapItem (p, seli);
1243 BranchItem *dsti=NULL;
1244 LinkableMapObj* dst=NULL;
1245 if (ti && ti!=seli && ti->isBranchLikeType())
1247 dsti=(BranchItem*)ti;
1253 if (lmosel && seli->getType()==TreeItem::Image)
1255 FloatObj *fio=(FloatImageObj*)lmosel;
1256 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
1258 fio->updateLinkGeometry(); //no need for reposition, if we update link here
1259 model->emitSelectionChanged(); // position has changed
1261 // Relink float to new mapcenter or branch, if shift is pressed
1262 // Only relink, if selection really has a new parent
1263 if ( e->modifiers()==Qt::ShiftModifier && dsti && dsti != seli->parent() )
1265 // Also save the move which was done so far
1266 QString pold=qpointFToString(movingObj_orgRelPos);
1267 QString pnow=qpointFToString(fio->getRelPos());
1273 QString("Move %1 to relative position %2").arg(model->getObjectName(fio)).arg(pnow));
1274 fio->getParObj()->requestReposition();
1275 model->reposition();
1277 model->relinkImage ((ImageItem*) seli,dsti);
1278 model->select (seli);
1279 //movingObj=lmosel; //FIXME-3
1280 //movingObj_orgRelPos=lmosel->getRelPos();
1282 model->reposition();
1285 { // selection != a FloatObj
1286 if (seli->depth()==0)
1289 lmosel->move (p-movingObj_start);
1290 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
1292 // Move only mapcenter, leave its children where they are
1294 v=lmosel->getAbsPos();
1295 for (int i=0; i<seli->branchCount(); ++i)
1297 seli->getBranchObjNum(i)->setRelPos();
1298 seli->getBranchObjNum(i)->setOrientation();
1303 if (seli->depth()==1)
1306 if (!lmosel->hasParObjTmp())
1307 lmosel->move(p-movingObj_start);
1308 lmosel->setRelPos();
1311 // Move ordinary branch
1312 if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
1313 // Add width of bbox here, otherwise alignRelTo will cause jumping around
1314 lmosel->move(p.x() -movingObj_start.x() , //lmosel->getBBox().width(),
1315 p.y()-movingObj_start.y() +lmosel->getTopPad() );
1317 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
1318 lmosel->setRelPos();
1322 // Maybe we can relink temporary?
1325 if (e->modifiers()==Qt::ControlModifier)
1327 // Special case: CTRL to link below dst
1328 lmosel->setParObjTmp (dst,p,+1);
1329 } else if (e->modifiers()==Qt::ShiftModifier)
1330 lmosel->setParObjTmp (dst,p,-1);
1332 lmosel->setParObjTmp (dst,p,0);
1335 lmosel->unsetParObjTmp();
1337 // reposition subbranch
1338 lmosel->reposition();
1340 QItemSelection sel=model->getSelectionModel()->selection();
1341 updateSelection(sel,sel); // position has changed
1343 } // no FloatImageObj
1347 } // selection && moving_obj
1349 // Draw a link from one branch to another
1352 tmpXLink->setEnd (p);
1353 tmpXLink->updateXLink();
1357 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
1359 QPointF p=e->globalPos();
1360 movingVec.setX(-p.x() + movingObj_start.x() );
1361 movingVec.setY(-p.y() + movingObj_start.y() );
1362 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
1363 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
1368 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
1370 QPointF p = mapToScene(e->pos());
1371 TreeItem *seli=model->getSelectedItem();
1373 TreeItem *dsti=NULL;
1374 if (seli) dsti=findMapItem(p, seli);
1375 LinkableMapObj* dst=NULL;
1376 if (dsti && dsti->isBranchLikeType ())
1377 dst=((MapItem*)dsti)->getLMO();
1382 // Have we been picking color?
1386 setCursor (Qt::ArrowCursor);
1387 // Check if we are over another branch
1390 if (e->state() & Qt::ShiftModifier)
1391 model->colorBranch (((BranchObj*)dst)->getColor());
1393 model->colorSubtree (((BranchObj*)dst)->getColor());
1398 // Have we been drawing a link?
1402 // Check if we are over another branch
1405 tmpXLink->setEnd ( ((BranchItem*)dsti) );
1406 tmpXLink->updateXLink();
1407 tmpXLink->activate();
1409 tmpXLink,QString("delete ()"),
1410 dsti,QString("addXLink (\"%1\",\"%2\")").arg(model->getSelectString(tmpXLink->getBegin())).arg(model->getSelectString(dsti)),
1411 QString("Add xLink from %1 to %2").arg(model->getObjectName(tmpXLink->getBegin())).arg(model->getObjectName(dsti))
1415 model->deleteItem(tmpXLink);
1421 // Have we been moving something?
1422 if ( seli && movingObj )
1424 if (seli->getType()==TreeItem::Image)
1426 FloatImageObj *fio=(FloatImageObj*)( ((MapItem*)seli)->getLMO());
1429 // Moved FloatObj. Maybe we need to reposition
1430 QString pold=qpointFToString(movingObj_orgRelPos);
1431 QString pnow=qpointFToString(fio->getRelPos());
1437 QString("Move %1 to relative position %2").arg(model->getObjectName(seli)).arg(pnow));
1439 fio->getParObj()->requestReposition();
1440 model->reposition();
1444 BranchItem *bi=model->getSelectedBranch();
1445 if (bi && bi->depth()==0)
1447 if (movingObj_orgPos != bi->getBranchObj()->getAbsPos()) // FIXME-3 check getBO here...
1449 QString pold=qpointFToString(movingObj_orgPos);
1450 QString pnow=qpointFToString(bi->getBranchObj()->getAbsPos()); // FIXME-3 check getBO here...
1457 QString("Move mapcenter %1 to position %2").arg(model->getObjectName(bi)).arg(pnow));
1461 if (seli->isBranchLikeType() ) //(seli->getType() == TreeItem::Branch )
1462 { // A branch was moved
1463 LinkableMapObj* lmosel=NULL;
1464 lmosel=((MapItem*)seli)->getLMO();
1466 // save the position in case we link to mapcenter
1467 QPointF savePos=QPointF (lmosel->getAbsPos() );
1469 // Reset the temporary drawn link to the original one
1470 lmosel->unsetParObjTmp();
1472 // For Redo we may need to save original selection
1473 QString preSelStr=model->getSelectString(seli);
1476 if (dsti && objectMoved)
1478 // We have a destination, relink to that
1480 BranchObj* bsel=model->getSelectedBranchObj();
1482 QString preParStr=model->getSelectString (bsel->getParObj());
1483 QString preNum=QString::number (seli->num(),10);
1484 QString preDstParStr;
1487 if (e->state() & Qt::ShiftModifier && dst->getParObj())
1489 preDstParStr=model->getSelectString (dst->getParObj());
1490 relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num());
1492 if (e->state() & Qt::ControlModifier && dst->getParObj())
1495 preDstParStr=model->getSelectString (dst->getParObj());
1496 relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num()+1);
1499 preDstParStr=model->getSelectString(dst);
1500 relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti);
1501 if (dsti->depth()==0) bsel->move (savePos);
1505 QString postSelStr=model->getSelectString(lmosel);
1506 QString postNum=QString::number (seli->num(),10);
1508 QString undoCom="relinkTo (\""+
1509 preParStr+ "\"," + preNum +"," +
1510 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
1512 QString redoCom="relinkTo (\""+
1513 preDstParStr + "\"," + postNum + "," +
1514 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
1519 QString("Relink %1 to %2").arg(model->getObjectName(bsel)).arg(model->getObjectName(dst)) );
1524 // No destination, undo temporary move
1526 if (seli->depth()==1)
1528 // The select string might be different _after_ moving around.
1529 // Therefor reposition and then use string of old selection, too
1530 model->reposition();
1532 QPointF rp(lmosel->getRelPos());
1533 if (rp != movingObj_orgRelPos)
1535 QString ps=qpointFToString(rp);
1537 model->getSelectString(lmosel), "moveRel "+qpointFToString(movingObj_orgRelPos),
1538 preSelStr, "moveRel "+ps,
1539 QString("Move %1 to relative position %2").arg(model->getObjectName(lmosel)).arg(ps));
1543 // Draw the original link, before selection was moved around
1544 if (settings.value("/animation/use",true).toBool()
1546 // && distance (lmosel->getRelPos(),movingObj_orgRelPos)<3
1549 lmosel->setRelPos(); // calc relPos first for starting point
1551 model->startAnimation(
1553 lmosel->getRelPos(),
1557 model->reposition();
1560 model->emitSelectionChanged(); //FIXME-3 needed? at least not after pos of selection has changed...
1561 // Finally resize scene, if needed
1567 // maybe we moved View: set old cursor
1568 setCursor (Qt::ArrowCursor);
1572 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
1576 qDebug()<< "ME p="<<mapToScene (e->pos())<<" scrollBarPos="<<getScrollBarPos() <<
1577 " min="<<QPointF(horizontalScrollBar()->minimum(),verticalScrollBar()->minimum());
1581 if (model->isSelectionBlocked() )
1587 if (e->button() == Qt::LeftButton )
1589 QPointF p = mapToScene(e->pos());
1590 TreeItem *ti=findMapItem (p, NULL);
1591 if (ti) { // MapObj was found
1592 // First select the MapObj than edit heading
1599 void MapEditor::resizeEvent (QResizeEvent* e)
1601 QGraphicsView::resizeEvent( e );
1604 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
1606 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
1607 // cerr << event->format(i) << endl;
1609 if (event->mimeData()->hasImage())
1610 event->acceptProposedAction();
1612 if (event->mimeData()->hasUrls())
1613 event->acceptProposedAction();
1616 void MapEditor::dragMoveEvent(QDragMoveEvent *)
1620 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
1625 void MapEditor::dropEvent(QDropEvent *event)
1627 BranchItem *selbi=model->getSelectedBranch();
1632 foreach (QString format,event->mimeData()->formats())
1633 qDebug()<< "MapEditor: Dropped format: "<<qPrintable (format);
1634 foreach (QString url,event->mimeData()->urls())
1635 qDebug()<< " URL:"<<url;
1636 //foreach (QString plain,event->mimeData()->text())
1637 // qDebug()<< " PLAIN:"<<plain;
1638 QByteArray ba=event->mimeData()->data("STRING");
1642 qDebug() << " STRING:" <<s;
1644 ba=event->mimeData()->data("TEXT");
1646 qDebug() << " TEXT:" <<s;
1648 ba=event->mimeData()->data("COMPOUND_TEXT");
1650 qDebug() << " CTEXT:" <<s;
1652 ba=event->mimeData()->data("text/x-moz-url");
1654 qDebug() << " x-moz-url:" <<s;
1656 if (b!=0) qDebug() << "b="<<b;
1659 if (event->mimeData()->hasImage())
1661 QVariant imageData = event->mimeData()->imageData();
1662 model->addFloatImage (qvariant_cast<QPixmap>(imageData));
1664 if (event->mimeData()->hasUrls())
1666 //model->selectLastBranch();
1667 QList <QUrl> uris=event->mimeData()->urls();
1672 for (int i=0; i<uris.count();i++)
1674 // Workaround to avoid adding empty branches
1675 if (!uris.at(i).toString().isEmpty())
1677 bi=model->addNewBranch();
1681 QString u=uris.at(i).toString();
1682 s=uris.at(i).toLocalFile();
1685 QString file = QDir::fromNativeSeparators(s);
1686 heading = QFileInfo(file).baseName();
1688 if (file.endsWith(".vym", false))
1689 model->setVymLink(file);
1697 // Automatically try to fetch data from Bugzilla
1698 if (settings.value( "/mainwindow/showTestMenu",false).toBool()
1699 && u.contains ("https://bugzilla.novell.com"))
1700 model->getBugzillaData();
1704 if (!heading.isEmpty())
1705 model->setHeading(heading);
1707 model->setHeading(u);
1709 model->select (bi->parent());
1713 //model->reposition();
1716 event->acceptProposedAction();
1719 void MapEditor::updateSelection(QItemSelection newsel,QItemSelection oldsel)
1721 // Note: Here we are prepared for multiple selections, though this
1722 // is not yet implemented elsewhere
1724 // Here in MapEditor we can only select Branches and Images
1725 QList <TreeItem*> treeItemsNew;
1726 QList <TreeItem*> treeItemsOld;
1728 QModelIndex newIndex;
1730 bool do_reposition=false;
1733 foreach (ix,newsel.indexes() )
1735 TreeItem *ti= static_cast<TreeItem*>(ix.internalPointer());
1736 if (ti->isBranchLikeType() || ti->getType()==TreeItem::Image )
1737 if (!treeItemsNew.contains(ti)) treeItemsNew.append (ti);
1739 foreach (ix,oldsel.indexes() )
1741 TreeItem *ti= static_cast<TreeItem*>(ix.internalPointer());
1742 if (ti->isBranchLikeType() || ti->getType()==TreeItem::Image )
1743 if (!treeItemsOld.contains(ti)) treeItemsOld.append (ti);
1746 // Trim list of selection rectangles
1747 while (treeItemsNew.count() < selboxList.count() )
1748 delete selboxList.takeFirst();
1750 // Take care to tmp scroll/unscroll
1751 if (!oldsel.isEmpty())
1753 QModelIndex ix=oldsel.indexes().first();
1756 TreeItem *ti= static_cast<TreeItem*>(ix.internalPointer());
1759 if (ti->isBranchLikeType() )
1761 // reset tmp scrolled branches
1762 BranchItem *bi=(BranchItem*)ti;
1763 if (bi->resetTmpUnscroll() )
1766 if (ti->isBranchLikeType() || ti->getType()==TreeItem::Image)
1767 // Hide link if not needed
1768 ((MapItem*)ti)->getLMO()->updateVisibility();
1773 if (!treeItemsNew.isEmpty())
1775 QModelIndex ix=newsel.indexes().first();
1780 // Temporary unscroll if necessary
1781 TreeItem *ti= static_cast<TreeItem*>(ix.internalPointer());
1782 if (ti->isBranchLikeType() )
1784 BranchItem *bi=(BranchItem*)ti;
1785 if (bi->hasScrolledParent(bi) )
1787 if (bi->parentBranch()->tmpUnscroll() )
1791 if (ti->isBranchLikeType() || ti->getType()==TreeItem::Image)
1792 // Show link if needed
1793 ((MapItem*)ti)->getLMO()->updateVisibility();
1796 if (do_reposition) model->reposition();
1798 // Reduce rectangles
1799 while (treeItemsNew.count() < selboxList.count() )
1800 delete selboxList.takeFirst();
1802 // Add additonal rectangles
1803 QGraphicsRectItem *sb;
1804 while (treeItemsNew.count() > selboxList.count() )
1806 sb = mapScene->addRect(
1808 QPen(selectionColor),
1810 sb->setZValue(Z_SELBOX);
1812 selboxList.append (sb);
1815 // Reposition rectangles
1819 LinkableMapObj *lmo;
1820 for (int i=0; i<treeItemsNew.count();++i)
1822 lmo=((MapItem*)treeItemsNew.at(i) )->getLMO();
1823 bbox=lmo->getBBox();
1824 sb=selboxList.at(i);
1827 bbox.width(), bbox.height());
1828 sb->setPen (selectionColor);
1829 sb->setBrush (selectionColor);
1836 void MapEditor::updateData (const QModelIndex &sel)
1838 TreeItem *ti= static_cast<TreeItem*>(sel.internalPointer());
1841 qDebug() << "ME::updateData\n";
1843 qDebug() << " ti="<<ti;
1844 qDebug() << " h="<<ti->getHeading();
1847 if (ti->isBranchLikeType())
1849 // qDebug() << " ->updating...\n";
1850 BranchObj *bo=(BranchObj*) ( ((MapItem*)ti)->getLMO());
1855 void MapEditor::setSelectionColor (QColor col)
1858 QItemSelection sel=model->getSelectionModel()->selection();
1859 updateSelection(sel,sel);
1863 QColor MapEditor::getSelectionColor ()
1865 return selectionColor;