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

void Q3TextEdit::doKeyboardAction ( Q3TextEdit::KeyboardAction  action  )  [virtual, slot, inherited]

Executes keyboard action action. This is normally called by a key event handler.

Definition at line 1613 of file q3textedit.cpp.

References Q3TextEdit::cursor, Q3TextEdit::drawCursor(), Q3TextEdit::ensureCursorVisible(), Q3TextEdit::removeSelectedText(), Q3TextEdit::repaintChanged(), Q3TextEdit::textChanged(), and Q3TextEdit::textFormat.

Referenced by Q3MultiLineEdit::backspace(), Q3TextEdit::del(), Q3TextEdit::insertParagraph(), Q3TextEdit::keyPressEvent(), and Q3MultiLineEdit::killLine().

{
    if (isReadOnly() && !qtextedit_ignore_readonly)
        return;

    if (cursor->nestedDepth() != 0)
        return;

    lastFormatted = cursor->paragraph();
    drawCursor(false);
    bool doUpdateCurrentFormat = true;

    switch (action) {
    case ActionWordDelete:
    case ActionDelete:
        if (action == ActionDelete && !cursor->atParagEnd()) {
            if (undoEnabled) {
                checkUndoRedoInfo(UndoRedoInfo::Delete);
                if (!undoRedoInfo.valid()) {
                    undoRedoInfo.id = cursor->paragraph()->paragId();
                    undoRedoInfo.index = cursor->index();
                    undoRedoInfo.d->text.clear();
                }
                int idx = cursor->index();
                do {
                    undoRedoInfo.d->text.insert(undoRedoInfo.d->text.length(), cursor->paragraph()->at(idx++), true);
                } while (!cursor->paragraph()->string()->validCursorPosition(idx));
            }
            cursor->remove();
        } else {
            clearUndoRedo();
            doc->setSelectionStart(Q3TextDocument::Temp, *cursor);
            if (action == ActionWordDelete && !cursor->atParagEnd()) {
                cursor->gotoNextWord();
            } else {
                cursor->gotoNextLetter();
            }
            doc->setSelectionEnd(Q3TextDocument::Temp, *cursor);
            removeSelectedText(Q3TextDocument::Temp);
        }
        break;
    case ActionWordBackspace:
    case ActionBackspace:
        if (textFormat() == Qt::RichText
             && (cursor->paragraph()->isListItem()
                 || cursor->paragraph()->listDepth())
             && cursor->index() == 0) {
            if (undoEnabled) {
                clearUndoRedo();
                undoRedoInfo.type = UndoRedoInfo::Style;
                undoRedoInfo.id = cursor->paragraph()->paragId();
                undoRedoInfo.eid = undoRedoInfo.id;
                undoRedoInfo.styleInformation = Q3TextStyleCommand::readStyleInformation(doc, undoRedoInfo.id, undoRedoInfo.eid);
            }
            int ldepth = cursor->paragraph()->listDepth();
            if (cursor->paragraph()->isListItem() && ldepth == 1) {
                cursor->paragraph()->setListItem(false);
            } else if (qMax(ldepth, 1) == 1) {
                cursor->paragraph()->setListItem(false);
                cursor->paragraph()->setListDepth(0);
            } else {
                cursor->paragraph()->setListDepth(ldepth - 1);
            }
            clearUndoRedo();
            lastFormatted = cursor->paragraph();
            repaintChanged();
            drawCursor(true);
            return;
        }

        if (action == ActionBackspace && !cursor->atParagStart()) {
            if (undoEnabled) {
                checkUndoRedoInfo(UndoRedoInfo::Delete);
                if (!undoRedoInfo.valid()) {
                    undoRedoInfo.id = cursor->paragraph()->paragId();
                    undoRedoInfo.index = cursor->index();
                    undoRedoInfo.d->text.clear();
                }
                undoRedoInfo.d->text.insert(0, cursor->paragraph()->at(cursor->index()-1), true);
                undoRedoInfo.index = cursor->index()-1;
            }
            cursor->removePreviousChar();
            lastFormatted = cursor->paragraph();
        } else if (cursor->paragraph()->prev()
                    || (action == ActionWordBackspace
                        && !cursor->atParagStart())) {
            clearUndoRedo();
            doc->setSelectionStart(Q3TextDocument::Temp, *cursor);
            if (action == ActionWordBackspace && !cursor->atParagStart()) {
                cursor->gotoPreviousWord();
            } else {
                cursor->gotoPreviousLetter();
            }
            doc->setSelectionEnd(Q3TextDocument::Temp, *cursor);
            removeSelectedText(Q3TextDocument::Temp);
        }
        break;
    case ActionReturn:
        if (undoEnabled) {
            checkUndoRedoInfo(UndoRedoInfo::Return);
            if (!undoRedoInfo.valid()) {
                undoRedoInfo.id = cursor->paragraph()->paragId();
                undoRedoInfo.index = cursor->index();
                undoRedoInfo.d->text.clear();
            }
            undoRedoInfo.d->text += "\n";
        }
        cursor->splitAndInsertEmptyParagraph();
        if (cursor->paragraph()->prev()) {
            lastFormatted = cursor->paragraph()->prev();
            lastFormatted->invalidate(0);
        }
        doUpdateCurrentFormat = false;
        break;
    case ActionKill:
        clearUndoRedo();
        doc->setSelectionStart(Q3TextDocument::Temp, *cursor);
        if (cursor->atParagEnd())
            cursor->gotoNextLetter();
        else
            cursor->setIndex(cursor->paragraph()->length() - 1);
        doc->setSelectionEnd(Q3TextDocument::Temp, *cursor);
        removeSelectedText(Q3TextDocument::Temp);
        break;
    }

    formatMore();
    repaintChanged();
    ensureCursorVisible();
    drawCursor(true);
    if (doUpdateCurrentFormat)
        updateCurrentFormat();
    setModified();
    emit textChanged();
}


Generated by  Doxygen 1.6.0   Back to index