diff -r 6269016c9905 -r c6bb4fdcc55f mapeditor.cpp --- a/mapeditor.cpp Thu Aug 06 10:42:17 2009 +0000 +++ b/mapeditor.cpp Sat Aug 08 21:58:26 2009 +0000 @@ -555,25 +555,185 @@ */ } +BranchItem* MapEditor::getBranchDirectAbove (BranchItem *bi) +{ + if (bi) + { + int i=bi->num(); + if (i>0) return bi->parent()->getBranchNum(i-1); + } + return NULL; +} + +BranchItem* MapEditor::getBranchAbove (BranchItem *selbi) +{ + if (selbi) + { + int dz=selbi->depth(); // original depth + bool invert=false; + if (selbi->getLMO()->getOrientation()==LinkableMapObj::LeftOfCenter) + invert=true; + + BranchItem *bi; + + // Look for branch with same parent but directly above + if (dz==1 && invert) + bi=getBranchDirectBelow(selbi); + else + bi=getBranchDirectAbove (selbi); + + if (bi) + // direct predecessor + return bi; + + // Go towards center and look for predecessor + while (selbi->depth()>0) + { + selbi=(BranchItem*)(selbi->parent()); + if (selbi->depth()==1 && invert) + bi=getBranchDirectBelow (selbi); + else + bi=getBranchDirectAbove (selbi); + if (bi) + { + // turn + selbi=bi; + while (selbi->depth()getLastBranch(); + if (!bi) + { + return selbi; + } + selbi=bi; + } + return selbi; + } + } + } + return NULL; +} + +BranchItem* MapEditor::getBranchDirectBelow(BranchItem *bi) +{ + if (bi) + { + int i=bi->num(); + if (i+1parent()->branchCount()) return bi->parent()->getBranchNum(i+1); + } + return NULL; +} + +BranchItem* MapEditor::getBranchBelow (BranchItem *selbi) +{ + if (selbi) + { + BranchItem *bi; + int dz=selbi->depth(); // original depth + bool invert=false; + if (selbi->getLMO()->getOrientation()==LinkableMapObj::LeftOfCenter) + invert=true; + + + // Look for branch with same parent but directly below + if (dz==1 && invert) + bi=getBranchDirectAbove (selbi); + else + bi=getBranchDirectBelow (selbi); + if (bi) + // direct successor + return bi; + + + // Go towards center and look for neighbour + while (selbi->depth()>0) + { + selbi=(BranchItem*)(selbi->parent()); + if (selbi->depth()==1 && invert) + bi=getBranchDirectAbove (selbi); + else + bi=getBranchDirectBelow (selbi); + if (bi) + { + // turn + selbi=bi; + while (selbi->depth()getFirstBranch(); + if (!bi) + { + return selbi; + } + selbi=bi; + } + return selbi; + } + } + } + return NULL; +} + +BranchItem* MapEditor::getLeftBranch (BranchItem *bi) +{ + if (bi) + { + if (bi->depth()==0) + // Special case: use alternative selection index + return bi->getLastSelectedBranchAlt(); + if (bi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) + // right of center + return (BranchItem*)(bi->parent()); + else + // left of center + if (bi->getType()== TreeItem::Branch ) + return bi->getLastSelectedBranch(); + } + return NULL; +} + +BranchItem* MapEditor::getRightBranch(BranchItem *bi) +{ + if (bi) + { + if (bi->depth()==0) return bi->getLastSelectedBranch(); + if (bi->getBranchObj()->getOrientation()==LinkableMapObj::LeftOfCenter) + // left of center + return (BranchItem*)(bi->parent()); + else + // right of center + if (bi->getType()== TreeItem::Branch ) + return (BranchItem*)bi->getLastSelectedBranch(); + } + return NULL; +} + + + void MapEditor::cursorUp() { - model->selectUpperBranch(); + BranchItem *bi=model->getSelectedBranch(); + if (bi) model->select (getBranchAbove(bi)); } void MapEditor::cursorDown() { - model->selectLowerBranch(); + BranchItem *bi=model->getSelectedBranch(); + if (bi) model->select (getBranchBelow(bi)); } void MapEditor::cursorLeft() { - model->selectLeftBranch(); + BranchItem *bi=getLeftBranch (model->getSelectedBranch()); + if (bi) model->select (bi); } void MapEditor::cursorRight() { - model->selectRightBranch(); + BranchItem *bi=getRightBranch (model->getSelectedBranch()); + if (bi) model->select (bi); } void MapEditor::cursorFirst() @@ -595,7 +755,7 @@ return; } BranchObj *bo=model->getSelectedBranchObj(); - BranchItem *bi=model->getSelectedBranchItem(); + BranchItem *bi=model->getSelectedBranch(); if (bo) { model->setSelectionBlocked(true); @@ -649,7 +809,7 @@ branchContextMenu->popup(e->globalPos() ); } else { - if (model->getSelectedImageItem() ) + if (model->getSelectedImage() ) { // Context Menu on floatimage // model->updateActions(); FIXME-3 needed? @@ -808,12 +968,12 @@ if (mainWindow->getModMode()==Main::ModModeCopy && e->state() & Qt::ControlModifier) { - BranchItem *bi=model->getSelectedBranchItem(); + BranchItem *bi=model->getSelectedBranch(); if (bi) { copyingObj=true; //FIXME-2 TreeItem::addBranch (BranchItem still missing) - //bi->addBranch (model->getSelectedBranchItem()); + //bi->addBranch (model->getSelectedBranch()); model->unselect(); model->select(bi->getLastBranch()); model->reposition(); @@ -1065,7 +1225,7 @@ } } - BranchItem *bi=model->getSelectedBranchItem(); + BranchItem *bi=model->getSelectedBranch(); if (bi && bi->depth()==0) { if (movingObj_orgPos != bi->getBranchObj()->getAbsPos()) // FIXME-3 check getBO here... @@ -1242,7 +1402,7 @@ void MapEditor::dropEvent(QDropEvent *event) { - BranchItem *selbi=model->getSelectedBranchItem(); + BranchItem *selbi=model->getSelectedBranch(); if (selbi) { if (debug) @@ -1317,13 +1477,13 @@ foreach (ix,newsel.indexes() ) { TreeItem *ti= static_cast(ix.internalPointer()); - if (ti->getType()==TreeItem::Branch || ti->getType()==TreeItem::Image ) + if (ti->isBranchLikeType() || ti->getType()==TreeItem::Image ) if (!treeItemsNew.contains(ti)) treeItemsNew.append (ti); } foreach (ix,oldsel.indexes() ) { TreeItem *ti= static_cast(ix.internalPointer()); - if (ti->getType()==TreeItem::Branch || ti->getType()==TreeItem::Image ) + if (ti->isBranchLikeType() || ti->getType()==TreeItem::Image ) if (!treeItemsOld.contains(ti)) treeItemsOld.append (ti); }