コード例 #1
0
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;
            }
        }
    }
}
コード例 #2
0
ファイル: FormulaCursor.cpp プロジェクト: KDE/calligra
FormulaCursor::FormulaCursor (const FormulaCursor& other )
{
    m_currentElement=other.currentElement();
    m_position=other.position();
    m_mark=other.mark();
    m_selecting=other.isSelecting();
}
コード例 #3
0
ファイル: FormulaCursor.cpp プロジェクト: KDE/calligra
void FormulaCursor::moveTo ( const FormulaCursor& pos )
{
    m_currentElement=pos.currentElement();
    m_position=pos.position();
    m_selecting=pos.isSelecting();
    m_mark=pos.mark();
}
コード例 #4
0
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;	
}
コード例 #5
0
bool TableRowElement::setCursorTo(FormulaCursor& cursor, QPointF point)
{
    if (cursor.isSelecting()) {
        if (m_data.isEmpty() || point.x()<0.0) {
            cursor.setCurrentElement(this);
            cursor.setPosition(0);
            return true;
        }
        //check if the point is behind all child elements
        if (point.x() >= width()) {
            cursor.setCurrentElement(this);
            cursor.setPosition(endPosition());
            return true;
        }
    }
    int i=0;
    qreal x=0.0;
    TableElement* parentTable = static_cast<TableElement*>( parentElement() );
    for (; i<m_data.count()-1; ++i) {
        //Find the child element the point is in
        x+=parentTable->columnWidth( i );
        if (x>=point.x()) {
            break;
        }
    }
    if (cursor.isSelecting()) {
        //we don't need to change current element because we are already in this element
        if (cursor.mark()<=i) {
            cursor.setPosition(i+1);
        }
        else {
            cursor.setPosition(i);
        }
        return true;
        } else {
        point-=m_data[i]->origin();
        return m_data[i]->setCursorTo(cursor,point);
    }
}
コード例 #6
0
bool TableRowElement::acceptCursor( const FormulaCursor& cursor )
{
     return (cursor.isSelecting());
}