diff -r 7a96bd401351 -r e90f5bef70c8 mapeditor.cpp --- a/mapeditor.cpp Sun Jan 30 12:58:47 2005 +0000 +++ b/mapeditor.cpp Sun Jan 30 23:25:47 2005 +0000 @@ -300,6 +300,8 @@ pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 ); #endif + modifierMode=pickColorMode; + modifierMode=linkObjectsMode; // FIXME testing pickingColor=false; @@ -1179,11 +1181,6 @@ LinkableMapObj* MapEditor::pasteNoSave() { - return pasteAtNoSave (-1); -} - -LinkableMapObj* MapEditor::pasteAtNoSave(int pos) -{ // Finish open lineEdits if (lineedit) finishedLineEditNoSave(); @@ -1201,13 +1198,7 @@ ((BranchObj*)(returnLMO))->move2RelPos(normalise(fromLMO->getRelPos() ) ); } if (typeid(*selection) == typeid(BranchObj)) - if (pos<0) returnLMO=((BranchObj*)(selection))->addBranch((BranchObj*)(fromLMO) ); - else - { - BranchObj *par=(BranchObj*)(selection->getParObj()); - if (par) returnLMO=par->insertBranch((BranchObj*)(fromLMO),pos ); - } } if (typeid(*fromLMO) == typeid(FloatImageObj) && @@ -1449,7 +1440,7 @@ return selection; } -bool MapEditor::select (QString s) +LinkableMapObj* MapEditor::findObj (QString s) { LinkableMapObj *lmo=mapCenter; QString part; @@ -1473,9 +1464,6 @@ else if (typ=="fi:") lmo=((BranchObj*)(lmo))->getFloatImageNum (num.toUInt()); - - - if (!lmo) break; if (s.contains(",")) @@ -1483,6 +1471,12 @@ else break; } + return lmo; +} + +bool MapEditor::select (const QString &s) +{ + LinkableMapObj *lmo=findObj(s); // Finally select the found object if (lmo) @@ -1495,8 +1489,6 @@ return true; } else return false; - - } void MapEditor::unselect() @@ -2654,6 +2646,10 @@ void MapEditor::testFunction() { cout << "MapEditor::testFunction() called\n"; + if (modifierMode==pickColorMode) + modifierMode=linkObjectsMode; + else + modifierMode=pickColorMode; } void MapEditor::ensureSelectionVisible() @@ -2729,12 +2725,34 @@ QPoint p = inverseWorldMatrix().map(e->pos()); LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL); - // Special case: CTRL is pressed, don't select anything + // Special case: CTRL is pressed if (e->state() & QMouseEvent::ControlButton) { - pickingColor=true; - setCursor (pickColorCursor); - return; + if (modifierMode==pickColorMode) + { + if (e->state() & QMouseEvent::ControlButton) + { + pickingColor=true; + setCursor (pickColorCursor); + return; + } + } + if (modifierMode==linkObjectsMode) + { + if (lmo && + (typeid(*lmo) == typeid(BranchObj)) || + (typeid(*lmo) == typeid(MapCenterObj)) ) + { + drawingLink=true; + linkingObj_src=selection; + tmpLink=new LinkObj (mapCanvas); + tmpLink->setBegin ( ((BranchObj*)(lmo)) ); + tmpLink->setEnd (p); + tmpLink->updateLink(); + tmpLink->setVisibility (true); + return; + } + } } if (lmo) @@ -2803,14 +2821,15 @@ void MapEditor::contentsMouseMoveEvent(QMouseEvent* e) { + QPoint p = inverseWorldMatrix().map(e->pos()); + // Move the selected MapObj if ( selection && movingObj) { - QPoint p = inverseWorldMatrix().map(e->pos()); - // Now move the selection, but add relative position (movingObj_start) - // where selection - // was chosen with mousepointer. (This avoids flickering resp. jumping + // Now move the selection, but add relative position + // (movingObj_start) where selection was chosen with + // mousepointer. (This avoids flickering resp. jumping // of selection back to absPos) LinkableMapObj *lmosel; @@ -2923,8 +2942,15 @@ return; } // selection && moving_obj + // Draw a link from one branch to another + if (drawingLink) + { + tmpLink->setEnd (p); + tmpLink->updateLink(); + } + // Move CanvasView - if (!movingObj && !pickingColor) + if (!movingObj && !pickingColor &&!drawingLink) { QPoint p=e->globalPos(); movingVec.setX(-p.x() + movingObj_start.x() ); @@ -2962,6 +2988,27 @@ } return; } + + // Have we been drawing a link? + if (drawingLink) + { + drawingLink=false; + // Check if we are over another branch + dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL); + if (dst && selection) + { + tmpLink->setEnd ( ((BranchObj*)(dst)) ); + tmpLink->updateLink(); + tmpLink->activate(); + + } else + { + delete(tmpLink); + tmpLink=NULL; + } + return; + } + // Have we been moving something? if ( selection && movingObj ) { @@ -2992,30 +3039,30 @@ // TODO we also could check, if dest and src are on same branch, // then it would be sufficient to saveState of this branch - // FIXME better introduce BO::move to speed up and keep IDs - copy(); // copy selection to clipboard - cutNoSave(); // remove selection here - - selection->unselect(); - selection=dst; // Modifiers allow to insert above/below dst if (e->state() & QMouseEvent::ShiftButton) { - selection=pasteAtNoSave (((BranchObj*)(dst))->getNum()); - if (selection) selection->select(); - } - else if (e->state() & QMouseEvent::ControlButton) - { - selection=pasteAtNoSave (((BranchObj*)(dst))->getNum()+1); - if (selection) selection->select(); - } - else - { - selection=pasteNoSave(); - selection->select(); - if (dst->getDepth()==0) - ((BranchObj*)(selection))->move (savePos); - } + ((BranchObj*)(selection))->moveBranchTo + ( + (BranchObj*)(dst), + ((BranchObj*)(dst))->getNum() + ); + //if (selection) selection->select(); + } else + if (e->state() & QMouseEvent::ControlButton) + { + ((BranchObj*)(selection))->moveBranchTo + ( + (BranchObj*)(dst), + ((BranchObj*)(dst))->getNum()+1 + ); + //if (selection) selection->select(); + } else + { + ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1); + if (dst->getDepth()==0) + ((BranchObj*)(selection))->move (savePos); + } } // Draw the original link, before selection was moved around mapCenter->reposition(); @@ -3025,9 +3072,9 @@ canvas()->update(); movingObj=NULL; } else - { // maybe we moved View: set old cursor + // maybe we moved View: set old cursor setCursor (ArrowCursor); - } + } void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)