Logo Search packages:      
Sourcecode: qt4-x11 version File versions

void Q3TextEdit::setSelection ( int  paraFrom,
int  indexFrom,
int  paraTo,
int  indexTo,
int  selNum = 0 
) [virtual, slot, inherited]

Sets a selection which starts at position indexFrom in paragraph paraFrom and ends at position indexTo in paragraph paraTo.

Any existing selections which have a different id (selNum) are left alone, but if an existing selection has the same id as selNum it is removed and replaced by this selection.

Uses the selection settings of selection selNum. If selNum is 0, this is the default selection.

The cursor is moved to the end of the selection if selNum is 0, otherwise the cursor position remains unchanged.

See also:
getSelection() selectedText

Definition at line 3964 of file q3textedit.cpp.

References Q3TextEdit::cursor, Q3TextEdit::drawCursor(), Q3TextEdit::ensureCursorVisible(), Q3TextEdit::optimSetSelection(), Q3TextEdit::repaintChanged(), and Q3ScrollView::repaintContents().

Referenced by Q3MultiLineEdit::insertAt().

{
#ifdef QT_TEXTEDIT_OPTIMIZATION
    if (d->optimMode) {
        optimSetSelection(paraFrom, indexFrom, paraTo, indexTo);
        repaintContents();
        return;
    }
#endif
    if (doc->hasSelection(selNum)) {
        doc->removeSelection(selNum);
        repaintChanged();
    }
    if (selNum > doc->numSelections() - 1)
        doc->addSelection(selNum);
    Q3TextParagraph *p1 = doc->paragAt(paraFrom);
    if (!p1)
        return;
    Q3TextParagraph *p2 = doc->paragAt(paraTo);
    if (!p2)
        return;

    if (indexFrom > p1->length() - 1)
        indexFrom = p1->length() - 1;
    if (indexTo > p2->length() - 1)
        indexTo = p2->length() - 1;

    drawCursor(false);
    Q3TextCursor c = *cursor;
    Q3TextCursor oldCursor = *cursor;
    c.setParagraph(p1);
    c.setIndex(indexFrom);
    cursor->setParagraph(p2);
    cursor->setIndex(indexTo);
    doc->setSelectionStart(selNum, c);
    doc->setSelectionEnd(selNum, *cursor);
    repaintChanged();
    ensureCursorVisible();
    if (selNum != Q3TextDocument::Standard)
        *cursor = oldCursor;
    drawCursor(true);
}


Generated by  Doxygen 1.6.0   Back to index