bool TableDataElement::moveCursor ( FormulaCursor& newcursor, FormulaCursor& oldcursor ) { if (newcursor.isSelecting() || newcursor.direction()==MoveLeft || newcursor.direction()==MoveRight) { return RowElement::moveCursor(newcursor,oldcursor); } else { TableRowElement* tr= static_cast<TableRowElement*>(parentElement()); TableElement* te = static_cast<TableElement*>(tr->parentElement()); int rn=te->positionOfChild(tr)/2; //table elements have a cursor int cn=tr->positionOfChild(this); //positions before and after each element if (newcursor.direction()==MoveUp) { if (rn>1) { return newcursor.moveCloseTo(te->childElements()[rn-1]->childElements()[cn],oldcursor); } else { return false; } } else { if (rn < te->endPosition()/2) { return newcursor.moveCloseTo(te->childElements()[rn+1]->childElements()[cn],oldcursor); } else { return false; } } } }
bool TableRowElement::moveCursor(FormulaCursor& newcursor, FormulaCursor& oldcursor) { //TODO: Moving the cursor vertically in the tableelement is a little bit fragile if ( (newcursor.isHome() && newcursor.direction()==MoveLeft) || (newcursor.isEnd() && newcursor.direction()==MoveRight) ) { return false; } int rowpos=parentElement()->positionOfChild(this); int colpos=(newcursor.position()!=endPosition() ? newcursor.position() : newcursor.position()-1); if (newcursor.isSelecting()) { switch(newcursor.direction()) { case MoveLeft: newcursor.moveTo(this,newcursor.position()-1); break; case MoveRight: newcursor.moveTo(this,newcursor.position()+1); break; case MoveUp: case MoveDown: return false; default: break; } } else { switch(newcursor.direction()) { case MoveLeft: newcursor.setCurrentElement(m_data[newcursor.position()-1]); newcursor.moveEnd(); break; case MoveRight: newcursor.setCurrentElement(m_data[newcursor.position()]); newcursor.moveHome(); break; case MoveUp: if ( rowpos>1 ) { BasicElement* b=parentElement()->childElements()[rowpos/2-1]->childElements()[colpos]; return newcursor.moveCloseTo(b, oldcursor); } else { return false; } case MoveDown: if ( rowpos<endPosition()-1 ) { BasicElement* b=parentElement()->childElements()[rowpos/2+1]->childElements()[colpos]; return newcursor.moveCloseTo(b, oldcursor); } else { return false; } default: break; } } return true; }
bool FixedElement::moveHorSituation(FormulaCursor& newcursor, FormulaCursor& oldcursor, int pos1, int pos2) { if ((newcursor.position()/2==pos1 && newcursor.direction()==MoveUp) || (newcursor.position()/2==pos2 && newcursor.direction()==MoveDown) || (newcursor.position()==2*pos1 && newcursor.direction()==MoveLeft) || (newcursor.position()==2*pos2+1 && newcursor.direction()==MoveRight) ) { return false; } switch (newcursor.direction()) { case MoveLeft: if (newcursor.position()==2*pos2+1) { newcursor.moveTo(newcursor.currentElement()->childElements()[pos2]); } else { newcursor.moveTo(newcursor.currentElement()->childElements()[pos1]); } break; case MoveRight: if (newcursor.position()==2*pos1) { newcursor.moveTo(newcursor.currentElement()->childElements()[pos1]); } else { newcursor.moveTo(newcursor.currentElement()->childElements()[pos2]); } break; case MoveUp: case MoveDown: return newcursor.moveCloseTo(childElements()[newcursor.direction()==MoveUp ? pos1 : pos2],oldcursor); case NoDirection: break; } return true; }