diff -r 3988818e8087 -r b7447adddc9a mapeditor.cpp --- a/mapeditor.cpp Fri Jan 05 11:17:33 2007 +0000 +++ b/mapeditor.cpp Wed Jan 10 13:26:12 2007 +0000 @@ -165,7 +165,7 @@ return blockReposition; } -QString MapEditor::getName (LinkableMapObj *lmo) +QString MapEditor::getName (const LinkableMapObj *lmo) { QString s; if (!lmo) return QString("Error: NULL has no name!"); @@ -638,6 +638,29 @@ } } } + } else if (com=="linkTo") + { + if (!selection) + { + api.setError (Aborted,"Nothing selected"); + } else if ( (typeid(*selection) != typeid(BranchObj) && + typeid(*selection) != typeid(MapCenterObj) && + typeid(*selection) != typeid(FloatImageObj))) + { + api.setError (Aborted,"Type of selection is not a floatimage"); + } else if (api.checkParamCount(1)) + { + // 0 selectstring of parent + s=api.parString(ok,0); + LinkableMapObj *dst=mapCenter->findObjBySelect (s); + if (dst) + { + if (typeid(*dst) == typeid(BranchObj) || + typeid(*dst) == typeid(MapCenterObj)) + linkTo (dst->getSelectString()); + } else + api.setError (Aborted,"Destination is not a branch"); + } } else if (com=="moveBranchUp") { if (!selection) @@ -1208,10 +1231,12 @@ QPixmap MapEditor::getPixmap() { -/* FIXME getPixmap not ported yet to QT4 QRectF mapRect=mapCenter->getTotalBBox(); - QPixmap pix (); + QPixmap pix((int)mapRect.width(),(int)mapRect.height()); + cout << "w.h="<<(int)mapRect.width()<<","<<(int)mapRect.height()<unselect(); } - pp.setWindow (mapRect); - - //mapScene->drawArea(mapRect, &pp); // draw scene to painter - mapScene->render(&pp); // draw scene to painter + mapScene->render ( &pp, + QRectF(0,0,mapRect.width(),mapRect.height()), + QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() )); + +// mapScene->render(&pp); // draw scene to painter @@ -1236,7 +1262,6 @@ } return pix; -*/ } void MapEditor::setHideTmpMode (HideTmpMode mode) @@ -1513,6 +1538,7 @@ mainWindow->updateHistory (undoSet); updateActions(); + ensureSelectionVisible(); } bool MapEditor::isUndoAvailable() @@ -1689,6 +1715,7 @@ QString("Move %1 to relativ position %2").arg(getName(selection)).arg(ps)); ((OrnamentedObj*)selection)->move2RelPos (x,y); mapCenter->reposition(); + selection->updateLink(); } } @@ -1706,6 +1733,7 @@ selection->select(); saveState (selection,"moveBranchDown ()",bo,"moveBranchUp ()",QString("Move up %1").arg(getName(bo))); mapCenter->reposition(); + scene()->update(); ensureSelectionVisible(); } } @@ -1724,10 +1752,42 @@ selection->select(); saveState(selection,"moveBranchUp ()",bo,"moveBranchDown ()",QString("Move down %1").arg(getName(bo))); mapCenter->reposition(); + scene()->update(); ensureSelectionVisible(); } } +void MapEditor::linkTo(const QString &dstString) +{ + BranchObj *dst=(BranchObj*)(mapCenter->findObjBySelect(dstString)); + if (dst && (typeid(*dst)==typeid (BranchObj) || + typeid(*dst)==typeid (MapCenterObj))) + { + LinkableMapObj *dstPar=dst->getParObj(); + QString parString=dstPar->getSelectString(); + if (typeid(*selection)==typeid(FloatImageObj)) + { + FloatImageObj *fio=(FloatImageObj*)selection; + QString fioPreSelectString=fio->getSelectString(); + QString fioPreParentSelectString=fio->getParObj()->getSelectString(); + ((BranchObj*)(dst))->addFloatImage (fio); + fio->unselect(); + ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio); + fio=((BranchObj*)(dst))->getLastFloatImage(); + fio->setRelPos(); + fio->reposition(); + selection=(LinkableMapObj*)fio; + selection->select(); + saveState( + fio->getSelectString(), + QString("linkTo (\"%1\")").arg(fioPreParentSelectString), + fioPreSelectString, + QString ("linkTo (\"%1\")").arg(dstString), + QString ("Link floatimage to %1").arg(getName(dst))); + } + } +} + QString MapEditor::getHeading(bool &ok, QPoint &p) { if (selection && @@ -3310,7 +3370,7 @@ cout << "canceled!\n"; return; -/* Hide hidden stuff temporary, maybe add this as regular function somewhere +/* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere if (hidemode==HideNone) { setHideTmpMode (HideExport); @@ -3593,21 +3653,32 @@ ( lmo != fo->getParObj()) ) { - if (typeid(*fo) == typeid(FloatImageObj)) + if (typeid(*fo) == typeid(FloatImageObj) && + ( (typeid(*lmo)==typeid(BranchObj) || + typeid(*lmo)==typeid(MapCenterObj)) )) { - //FIXME undocom for relinking of floats - - //saveStateComplete(QString("Relink %1 to %2").arg(getName(fo)).arg(getName(lmo) ) ); - FloatImageObj *fio=(FloatImageObj*)(fo); - ((BranchObj*)(lmo))->addFloatImage (fio); - fio->unselect(); - ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio); - fio=((BranchObj*)(lmo))->getLastFloatImage(); - fio->setRelPos(); - fio->reposition(); - selection=(LinkableMapObj*)(fio); - selection->select(); - movingObj=(MapObj*)(fio); + + // Also save the move which was done so far + FloatImageObj *fio=(FloatImageObj*)selection; + QString pold=qpointfToString(movingObj_orgRelPos); + QString pnow=qpointfToString(fio->getRelPos()); + saveState( + selection, + "moveRel "+pold, + selection, + "moveRel "+pnow, + QString("Move %1 to relativ position %2").arg(getName(selection)).arg(pnow)); + fio->getParObj()->requestReposition(); + mapCenter->reposition(); + + cout << "current relPos="<getSelectString()); + cout << "setting movingObj\n"; + movingObj=(MapObj*)selection; + movingObj_orgRelPos=selection->getRelPos(); + cout <<"ok 0\n"; + + mapCenter->reposition(); } } } else @@ -3929,7 +4000,7 @@ bo->setHeading(uris.at(i).toString()); } } - mapCenter->reposition(); + mapCenter->reposition(); } } event->acceptProposedAction();