Exemplo n.º 1
0
void TikzEditorView::editUncomment()
{
	bool go = true;
	QTextCursor textCursor = m_tikzEditor->textCursor();
	if (textCursor.hasSelection())
	{
		textCursor.beginEditBlock();
		const int start = textCursor.selectionStart();
		int end = textCursor.selectionEnd() - 2;
		textCursor.setPosition(start, QTextCursor::MoveAnchor);
		textCursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor);
		while (textCursor.position() < end && go)
		{
			textCursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 2);
			if (textCursor.selectedText() == QLatin1String("% "))
			{
				textCursor.removeSelectedText();
				--end;
			}
			go = textCursor.movePosition(QTextCursor::NextBlock, QTextCursor::MoveAnchor);
		}
		textCursor.endEditBlock();
	}
	else
	{
		textCursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor);
		textCursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 2);
		if (textCursor.selectedText() == QLatin1String("% "))
			textCursor.removeSelectedText();
	}
}
Exemplo n.º 2
0
void TextZone::preventDoubleSpace()
{

    QTextCursor *tCursor = new QTextCursor(document());
    int cursorPos = this->textCursor().position();
    QString prevChar;
    QString nextChar;

    if(this->textCursor().atBlockStart() == false){
        do {tCursor->setPosition(cursorPos);
            tCursor->movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor,1);
            prevChar = tCursor->selectedText();
            if(prevChar == " "){
                tCursor->removeSelectedText();
                cursorPos -= 1;
            }
        }
        while(prevChar == " ");

    }
    if(this->textCursor().atBlockEnd() == false){
        do {tCursor->setPosition(cursorPos);
            tCursor->movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor,1);
            nextChar = tCursor->selectedText();
            if(nextChar == " "){
                tCursor->removeSelectedText();
            }
        }
        while(nextChar == " ");

    }

    this->textCursor().insertText(" ");
}
Exemplo n.º 3
0
void GLFOutputWindow::printMessage(const char* message)
{
    static int index = 1;
    // Remove the first few lines when the buffer is overflow.
    int nlines = _pTextEdit->document()->lineCount();
    if (nlines > MAX_NUM_LINES)
    {
        int deleteNumLines = nlines / 2;
        for (int i = 0; i < deleteNumLines; ++i)
        {
            QTextCursor tc = _pTextEdit->textCursor();

            tc.movePosition(QTextCursor::Start);
            tc.select(QTextCursor::LineUnderCursor);
            tc.removeSelectedText();
        }

        QTextCursor tc = _pTextEdit->textCursor();
        tc.movePosition(QTextCursor::End);
        _pTextEdit->setTextCursor(tc);            
    }

    // Insert the new message
    char buffer[1024];
    sprintf(buffer, "%d: %s", index++, message);
    _pTextEdit->insertPlainText(QString(buffer));

    // Scroll to the bottom
    QScrollBar *sb = _pTextEdit->verticalScrollBar();
    sb->setValue(sb->maximum());
}
Exemplo n.º 4
0
void ConsoleWidget::handleHistory(bool down)
{
    int index;
    moveCursor(QTextCursor::End);
    QTextCursor cursor = textCursor();

    if (m_history.size()==0)
        return;

    if (down)
        m_histIndex--;
    else
        m_histIndex++;

    if (m_histIndex>m_history.size()-1)
        m_histIndex = m_history.size()-1;
    if (m_histIndex<0)
        m_histIndex = 0;
    index = m_history.size()-1-m_histIndex;

    cursor.select(QTextCursor::LineUnderCursor);
    cursor.removeSelectedText();

    handleColor();
    insertPlainText(m_prompt + m_history[index]);
    moveCursor(QTextCursor::End);
}
Exemplo n.º 5
0
bool ChatWindow::eventFilter(QObject* sender, QEvent* event) {
    if (sender == ui->messagePlainTextEdit) {
        if (event->type() != QEvent::KeyPress) {
            return false;
        }
        QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
        if ((keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) &&
            (keyEvent->modifiers() & Qt::ShiftModifier) == 0) {
            QString messageText = ui->messagePlainTextEdit->document()->toPlainText().trimmed();
            if (!messageText.isEmpty()) {
#ifdef HAVE_QXMPP
                const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
                QXmppMessage message;
                message.setTo(publicChatRoom->jid());
                message.setType(QXmppMessage::GroupChat);
                message.setBody(messageText);
                XmppClient::getInstance().getXMPPClient().sendPacket(message);
#endif // HAVE_QXMPP
                QTextCursor cursor = ui->messagePlainTextEdit->textCursor();
                cursor.select(QTextCursor::Document);
                cursor.removeSelectedText();
            }
            return true;
        }
    } else if (event->type() == QEvent::MouseButtonRelease) {
        QVariant userVar = sender->property("user");
        if (userVar.isValid()) {
            AddressManager::getInstance().goToUser(userVar.toString());
            return true;
        }
    }
    return QWidget::eventFilter(sender, event);
}
Exemplo n.º 6
0
void GenericCodeEditor::handleKeyBackspace(QKeyEvent * event, QTextCursor & textCursor, bool & updateCursor)
{
    if (event->modifiers() & Qt::META) {
        textCursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor);
        textCursor.removeSelectedText();
    } else {
        if ( !overwriteMode()
             || (textCursor.positionInBlock() == 0)
             || textCursor.hasSelection() ) {
            QPlainTextEdit::keyPressEvent(event);
        } else {
            // in overwrite mode, backspace should insert a space
            textCursor.beginEditBlock();
            textCursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor);
            QString selectedText = textCursor.selectedText();
            if (selectedText == QStringLiteral(" ") ||
                selectedText == QStringLiteral("\t") ) {
                textCursor.clearSelection();
            } else {
                textCursor.insertText(QString(QChar(' ')));
                textCursor.movePosition(QTextCursor::PreviousCharacter);
            }
            textCursor.endEditBlock();
        }
        updateCursor = true;
    }
}
/**
 * @brief Increases (or decreases) the indention of the selected text (if there is a text selected) in the noteTextEdit
 * @return
 */
bool QMarkdownTextEdit::increaseSelectedTextIndention( bool reverse )
{
    QTextCursor c = this->textCursor();
    QString selectedText = c.selectedText();

    if ( selectedText != "" )
    {
        // we need this strange newline character we are getting in the selected text for newlines
        QString newLine = QString::fromUtf8( QByteArray::fromHex( "e280a9" ) );
        QString newText;

        if ( reverse )
        {
            // unindent text
            newText = selectedText.replace( newLine + "\t", "\n" );

            // remove leading \t
            newText.replace( QRegularExpression( "^\\t" ), "" );
        }
        else
        {
            // indent text
            newText = selectedText.replace( newLine, "\n\t" ).prepend( "\t" );

            // remove trailing \t
            newText.replace( QRegularExpression( "\\t$" ), "" );
        }

        // insert the new text
        c.insertText( newText );

        // update the selection to the new text
        c.setPosition( c.position() - newText.size(), QTextCursor::KeepAnchor );
        this->setTextCursor( c );

        return true;
    }
    // if nothing was selected but we want to reverse the indention check if there is a \t in front or after the cursor and remove it if so
    else if ( reverse )
    {
        int pos = c.position();
        // check for \t in front of cursor
        c.setPosition( pos - 1, QTextCursor::KeepAnchor );
        if ( c.selectedText() != "\t" )
        {
            // (select to) check for \t after the cursor
            c.setPosition( pos );
            c.setPosition( pos + 1, QTextCursor::KeepAnchor );
        }

        if ( c.selectedText() == "\t" )
        {
            c.removeSelectedText();
        }

        return true;
    }

    return false;
}
Exemplo n.º 8
0
void CodeEditor::completeTagText(const QString &text)
{
    textCursor().beginEditBlock();
    QString adding_text;
    QTextCursor editingTextCursor = textCursor();

    editingTextCursor.setPosition(textCursor().selectionStart());
    editingTextCursor.movePosition( QTextCursor::EndOfWord, QTextCursor::MoveAnchor );
    editingTextCursor.movePosition( QTextCursor::StartOfWord, QTextCursor::KeepAnchor );
    editingTextCursor.removeSelectedText();
    adding_text = text;

    adding_text += ">";
    adding_text += "</";
    adding_text += text;
    adding_text += ">";

    editingTextCursor.insertText(adding_text);
    editingTextCursor.movePosition( QTextCursor::PreviousWord, QTextCursor::MoveAnchor );
    editingTextCursor.movePosition( QTextCursor::PreviousWord, QTextCursor::MoveAnchor );
    editingTextCursor.movePosition( QTextCursor::PreviousWord, QTextCursor::MoveAnchor );
    editingTextCursor.movePosition( QTextCursor::Right, QTextCursor::MoveAnchor );
    setTextCursor(editingTextCursor);

    textCursor().endEditBlock();
}
Exemplo n.º 9
0
void CodeEditor::deleteTab()
{
    QString deletion = "    ";

    QTextCursor cursor = textCursor();
    if (cursor.selectionEnd() - cursor.selectionStart() <= 0) {
        //delete 4 spaces (tab)
        cursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor, deletion.length());
        QString selected = cursor.selectedText();
        if (selected.startsWith(deletion))
            cursor.deletePreviousChar();
    } else {
        QTextBlock firstBlock = document()->findBlock(cursor.selectionStart());
        QTextBlock lastBlock = document()->findBlock(cursor.selectionEnd() - 1);

        cursor.setPosition(firstBlock.position());
        cursor.beginEditBlock();
        do {
            if (cursor.block().text().startsWith(deletion)) {
                cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, deletion.length());
                cursor.removeSelectedText();
            }
        } while (cursor.movePosition(QTextCursor::NextBlock) && cursor.position() <= lastBlock.position());
        cursor.endEditBlock();
    }
}
Exemplo n.º 10
0
void LrcEditor::removeMark()
{
	QTextCursor cursor = textCursor();
	QString strText = cursor.block().text();

	if (strText.isEmpty())
		return ;

	const QRegExp exp("^\\[\\d+:\\d+\\.\\d+\\]");

	int index = exp.indexIn(strText);
	// no time tags
	if (index == -1)
		return ;

	strText.remove(index, exp.matchedLength());

	cursor.beginEditBlock();

	cursor.select(QTextCursor::LineUnderCursor);
	cursor.removeSelectedText();
	cursor.insertText(strText);

	cursor.movePosition(QTextCursor::StartOfLine, QTextCursor::MoveAnchor);

	cursor.endEditBlock();

	setTextCursor(cursor);
}
Exemplo n.º 11
0
template<> bool
QConsoleWidget::_pf<bool, SelectKeyPressedAll>(
        QConsoleWidget * thisp,
        QKeyEvent * e) {

    auto resetSelect = [](QConsoleWidget * _thisp)->void{
        QTextCursor textCursor = _thisp->textCursor();
        auto epos = textCursor.selectionEnd();
        textCursor.setPosition( _thisp->promptEndPos_);
        textCursor.setPosition( epos, QTextCursor::KeepAnchor);
        _thisp->setTextCursor(textCursor);
    };

    auto key_ = e->key();

    switch (key_)
    {
    case Qt::Key_Shift:
    case Qt::Key_Control:
    case Qt::Key_Meta:
    case Qt::Key_Alt:
    case Qt::Key_CapsLock:
    case Qt::Key_NumLock:
    case Qt::Key_ScrollLock:
    case Qt::Key_Up:
    case Qt::Key_Down:
    case Qt::Key_Left:
    case Qt::Key_Right:
    case Qt::Key_PageDown:
    case Qt::Key_PageUp:
    case Qt::Key_Home:
    case Qt::Key_End:return false;
    }

    if (e->modifiers() & Qt::ControlModifier) {
        switch (key_)
        {
        case Qt::Key_C:
        case Qt::Key_A:return false;
        case Qt::Key_X:/*剪贴*/ {
            class EventKey :public QKeyEvent {
            public:
                void setKey() { k = Qt::Key_C; }
            };
            EventKey * fk = (EventKey*)(e);
            fk->setKey();
            thisp->TP::keyPressEvent(fk);
            resetSelect(thisp);
            QTextCursor textCursor = thisp->textCursor();
            textCursor.removeSelectedText();
            thisp->setTextCursor(textCursor);
            return true;
        }
        }
    }

    resetSelect(thisp);

    return false;
}
Exemplo n.º 12
0
void StyleSheetEditorDialog::insertCssProperty(const QString &name, const QString &value)
{
    if (!value.isEmpty()) {
        QTextCursor cursor = m_editor->textCursor();
        if (!name.isEmpty()) {
            cursor.beginEditBlock();
            cursor.removeSelectedText();
            cursor.movePosition(QTextCursor::EndOfLine);

            // Simple check to see if we're in a selector scope
            const QTextDocument *doc = m_editor->document();
            const QTextCursor closing = doc->find(QLatin1String("}"), cursor, QTextDocument::FindBackward);
            const QTextCursor opening = doc->find(QLatin1String("{"), cursor, QTextDocument::FindBackward);
            const bool inSelector = !opening.isNull() && (closing.isNull() ||
                                                          closing.position() < opening.position());
            QString insertion;
            if (m_editor->textCursor().block().length() != 1)
                insertion += QLatin1Char('\n');
            if (inSelector)
                insertion += QLatin1Char('\t');
            insertion += name;
            insertion += QLatin1String(": ");
            insertion += value;
            insertion += QLatin1Char(';');
            cursor.insertText(insertion);
            cursor.endEditBlock();
        } else {
            cursor.insertText(value);
        }
    }
}
Exemplo n.º 13
0
void DrugInputEdit::handleCompleteDrugName(QString addName) {
    QTextCursor tc = textCursor();
    tc.select(QTextCursor::LineUnderCursor);
    tc.removeSelectedText();
    tc.insertText(addName + "\n");
    setTextCursor(tc);
}
Exemplo n.º 14
0
void SpellCheckerCore::replaceWordsInCurrentEditor(const WordList &wordsToReplace, const QString &replacementWord)
{
    if(wordsToReplace.count() == 0) {
        Q_ASSERT(wordsToReplace.count() != 0);
        return;
    }
    if(d->currentEditor == NULL) {
        Q_ASSERT(d->currentEditor != NULL);
        return;
    }
    TextEditor::TextEditorWidget* editorWidget = qobject_cast<TextEditor::TextEditorWidget*>(d->currentEditor->widget());
    if(editorWidget == NULL) {
        Q_ASSERT(editorWidget != NULL);
        return;
    }

    QTextCursor cursor = editorWidget->textCursor();
    /* Iterate the words and replace all one by one */
    foreach(const Word& wordToReplace, wordsToReplace) {
        editorWidget->gotoLine(wordToReplace.lineNumber, wordToReplace.columnNumber - 1);
        int wordStartPos = editorWidget->textCursor().position();
        editorWidget->gotoLine(wordToReplace.lineNumber, wordToReplace.columnNumber + wordToReplace.length - 1);
        int wordEndPos = editorWidget->textCursor().position();

        cursor.beginEditBlock();
        cursor.setPosition(wordStartPos);
        cursor.setPosition(wordEndPos, QTextCursor::KeepAnchor);
        cursor.removeSelectedText();
        cursor.insertText(replacementWord);
        cursor.endEditBlock();
    }
Exemplo n.º 15
0
void QtChatWindow::tabComplete() {
	if (!completer_) {
		return;
	}

	QTextCursor cursor;
	if (tabCompleteCursor_.hasSelection()) {
		cursor = tabCompleteCursor_;
	}
	else {
		cursor = input_->textCursor();
		while(cursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor) && cursor.document()->characterAt(cursor.position() - 1) != ' ') { }
	}
	QString root = cursor.selectedText();
	if (root.isEmpty()) {
		return;
	}
	QString suggestion = P2QSTRING(completer_->completeWord(Q2PSTRING(root)));
	if (root == suggestion) {
		return;
	}
	tabCompletion_ = true;
	cursor.beginEditBlock();
	cursor.removeSelectedText();
	int oldPosition = cursor.position();

	cursor.insertText(suggestion);
	tabCompleteCursor_ = cursor;
	tabCompleteCursor_.setPosition(oldPosition, QTextCursor::KeepAnchor);

	cursor.endEditBlock();
	tabCompletion_ = false;
}
Exemplo n.º 16
0
void TextResultItem::setLatex(Cantor::LatexResult* result)
{
    QTextCursor cursor = textCursor();
    cursor.movePosition(QTextCursor::Start);
    cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
    QString latex = result->toLatex().trimmed();
    if (latex.startsWith(QLatin1String("\\begin{eqnarray*}")) &&
        latex.endsWith(QLatin1String("\\end{eqnarray*}"))) {
        latex = latex.mid(17);
        latex = latex.left(latex.size() - 15);
    }
    if (result->isCodeShown()) {
        if (latex.isEmpty())
            cursor.removeSelectedText();
        else
            cursor.insertText(latex);
    } else {
        QTextImageFormat format;
        format = epsRenderer()->render(cursor.document(),
                                       result->data().toUrl());
        format.setProperty(EpsRenderer::CantorFormula,
                           EpsRenderer::LatexFormula);
        format.setProperty(EpsRenderer::Code, latex);
        format.setProperty(EpsRenderer::Delimiter, QLatin1String("$$"));
        if(format.isValid())
            cursor.insertText(QString(QChar::ObjectReplacementCharacter), format);
        else
            cursor.insertText(i18n("Cannot render Eps file. You may need additional packages"));
    }
}
Exemplo n.º 17
0
void TabTerminal::_clearLine()
{
	QTextCursor c = this->textCursor();
	c.select(QTextCursor::LineUnderCursor);
	c.removeSelectedText();
	this->insertHtml(_userPrompt);
}
Exemplo n.º 18
0
void CodeEditor::deleteLine(){
    QTextCursor selection = getSelectedLines();
    selection.beginEditBlock();
    selection.removeSelectedText();
    selection.deleteChar();
    selection.endEditBlock();
}
Exemplo n.º 19
0
void ScriptingWidget::clipToMaxParagraphs()
{
   while (getNumParagraphs() > mMaxParagraphs)
   {
      QString strText = toPlainText();
      if (strText.isEmpty() == true)
      {
         break;
      }

      int iPos = strText.indexOf("\n");
      if (iPos == -1)
      {
         break;
      }

      QTextCursor paragraphSelection = textCursor();
      paragraphSelection.setPosition(0);
      paragraphSelection.setPosition(iPos + 1, QTextCursor::KeepAnchor);
      paragraphSelection.removeSelectedText();
      mCommandStartPos -= iPos + 1;
      paragraphSelection.movePosition(QTextCursor::End);

      setTextCursor(paragraphSelection);
   }
}
Exemplo n.º 20
0
void CCodeEdit::insertCompletion(const QString& completion)
{
	if( m_completer->widget() != this ) {
		return;
	}

	QTextCursor cursor = textCursor();
	QString completionPrefix = m_completer->completionPrefix();
	int len = completionPrefix.length();
	int extra = completion.length() - len;

	if( completionPrefix == completion.left(len) )
	{
		cursor.movePosition(QTextCursor::EndOfWord);
		cursor.insertText(completion.right(extra));
	}
	else
	{
		cursor.movePosition(QTextCursor::StartOfWord);
		cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
		cursor.removeSelectedText();
		cursor.insertText(completion);
	}
	setTextCursor(cursor);
}
Exemplo n.º 21
0
/** \brief Anhängen einer Zeile ans Ende.

  Am Ende der Ausgabe wird immer ein Newline + Prompt ausgegeben!
*/
void QCommandPrompt::write(QString sMsg, QColor /*col*/)
{
    // Überprüfen, ob die Zeile mit einem Prompt anfängt
    QTextCursor tc = textCursor();
    tc.movePosition(QTextCursor::StartOfLine);
    tc.select(QTextCursor::LineUnderCursor);
    tc.removeSelectedText();
    setTextCursor(tc);

    // old: simple text
    insertPlainText(sMsg + "\n" + m_sPrompt);
/*
    // colored version
    QBrush brush(Qt::SolidPattern);
    brush.setColor(col);

    QTextCharFormat fmt;
    fmt.setForeground(brush);
    tc.insertText(sMsg + "\n", fmt);

    brush.setColor(m_colDefault);
    fmt.setForeground(brush);
    tc.insertText(m_sPrompt, fmt);
*/
    m_nPromptPos = tc.position();

    ensureCursorVisible();
}
Exemplo n.º 22
0
void MainWindow::cutSelection()
{
    QTextCursor cursor = editor->textCursor();
    if (cursor.hasSelection()) {
        selection = cursor.selection();
        cursor.removeSelectedText();
    }
}
Exemplo n.º 23
0
void GenericCodeEditor::handleKeyDelete(QKeyEvent *event, QTextCursor & textCursor)
{
    if (event->modifiers() & Qt::META) {
         textCursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
         textCursor.removeSelectedText();
    } else
        QPlainTextEdit::keyPressEvent(event);
}
Exemplo n.º 24
0
/**
 * Delete all chars from current cursor position to end of word
 */
void HaiQTextEdit::delete_end_of_word() {
    QTextCursor cursor = textCursor();
    cursor.beginEditBlock();
    cursor.clearSelection();
    cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
    cursor.removeSelectedText();
    cursor.endEditBlock();
}
Exemplo n.º 25
0
void MLEdit::deleteLineBackwards()
{
  QTextCursor cr = textCursor();
  cr.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor);
  if (!cr.hasSelection())
    cr.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor);
  cr.removeSelectedText();
}
Exemplo n.º 26
0
void TabSettings::removeTrailingWhitespace(QTextCursor cursor, QTextBlock &block)
{
    if (const int trailing = trailingWhitespaces(block.text())) {
        cursor.setPosition(block.position() + block.length() - 1);
        cursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor, trailing);
        cursor.removeSelectedText();
    }
}
Exemplo n.º 27
0
void GenericCodeEditor::moveLineUpDown(bool up)
{
    // directly taken from qtcreator
    // Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
    // GNU Lesser General Public License
    QTextCursor cursor = textCursor();
    QTextCursor move = cursor;

    move.setVisualNavigation(false); // this opens folded items instead of destroying them

    move.beginEditBlock();

    bool hasSelection = cursor.hasSelection();

    if (cursor.hasSelection()) {
        move.setPosition(cursor.selectionStart());
        move.movePosition(QTextCursor::StartOfBlock);
        move.setPosition(cursor.selectionEnd(), QTextCursor::KeepAnchor);
        move.movePosition(move.atBlockStart() ? QTextCursor::Left: QTextCursor::EndOfBlock,
                          QTextCursor::KeepAnchor);
    } else {
        move.movePosition(QTextCursor::StartOfBlock);
        move.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
    }
    QString text = move.selectedText();

    move.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
    move.removeSelectedText();

    if (up) {
        move.movePosition(QTextCursor::PreviousBlock);
        move.insertBlock();
        move.movePosition(QTextCursor::Left);
    } else {
        move.movePosition(QTextCursor::EndOfBlock);
        if (move.atBlockStart()) { // empty block
            move.movePosition(QTextCursor::NextBlock);
            move.insertBlock();
            move.movePosition(QTextCursor::Left);
        } else {
            move.insertBlock();
        }
    }

    int start = move.position();
    move.clearSelection();
    move.insertText(text);
    int end = move.position();

    if (hasSelection) {
        move.setPosition(start);
        move.setPosition(end, QTextCursor::KeepAnchor);
    }

    move.endEditBlock();

    setTextCursor(move);
}
Exemplo n.º 28
0
void CCodeEditor::_UpdateCurrentLine(const QString& text)
{
	QTextCursor textCursor = this->textCursor();
	textCursor.select(QTextCursor::LineUnderCursor);
	textCursor.removeSelectedText();
	++m_textChangeTime;
	textCursor.insertText(text);
	++m_textChangeTime;
}
Exemplo n.º 29
0
void
SimpleRichTextEdit::deleteText()
{
	QTextCursor cursor = textCursor();
	if(cursor.hasSelection())
		cursor.removeSelectedText();
	else
		cursor.deleteChar();
}
Exemplo n.º 30
0
void CodeTextEdit::insertCompletion(const QString &completion) {
	if(completerPopup->widget() != this)
		return;
	QTextCursor tc = textCursor();
	tc.select(QTextCursor::WordUnderCursor);
	tc.removeSelectedText(); //capitalization may have been wrong, since we're doing case insensitive completing
	tc.insertText(completion);
	setTextCursor(tc);
}