• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ setTextCursor函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中setTextCursor函数的典型用法代码示例。如果您正苦于以下问题:C++ setTextCursor函数的具体用法?C++ setTextCursor怎么用?C++ setTextCursor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了setTextCursor函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: textCursor

void CodeEditer::keyPressEvent(QKeyEvent *e)
{
	if (e == QKeySequence::InsertParagraphSeparator
		|| e == QKeySequence::InsertLineSeparator) {
		QTextCursor cursor = textCursor();
		//if (d->m_inBlockSelectionMode)
		//cursor.clearSelection();
		//if (d->m_document->tabSettings().m_autoIndent) {
		cursor.beginEditBlock();
		cursor.insertBlock();
		indent(document(), cursor, QChar::Null);
		cursor.endEditBlock();
		//} else {
		//cursor.insertBlock();
		//}
		e->accept();
		setTextCursor(cursor);
		return;
	}

	e->accept();
	QPlainTextEdit::keyPressEvent(e);
}
开发者ID:rccoder,项目名称:codeview,代码行数:23,代码来源:linenumberarea.cpp


示例2: c

void CompleterTextEditWidget::comment(){
    QTextCursor c(textCursor());
    if (c.selectionStart() == c.selectionEnd()) {
        c.movePosition(QTextCursor::StartOfLine);
        c.insertText(commentString+" ");
        //setTextCursor(c);
    } else {
        // now we have to iterate through all selected blocks (lines) and indent them
        QTextCursor c1(c);
        c1.setPosition(c.selectionStart());
        QTextCursor c2(c);
        c2.setPosition(c.selectionEnd());
        c1.beginEditBlock();
        while (c1.blockNumber() <= c2.blockNumber()) {
            c1.movePosition(QTextCursor::StartOfBlock);
            c1.insertText(commentString+" ");
            if (!c1.movePosition(QTextCursor::NextBlock))
                break;
        }
        c1.endEditBlock();
        setTextCursor(c);
    }
}
开发者ID:jkriege2,项目名称:LitSoz3,代码行数:23,代码来源:completertextedit.cpp


示例3: poll

void ConsoleOutput::timerEvent(QTimerEvent *e)
{
    if(e->timerId() != m_timerId)
        return;

    poll();
    if(m_captured.isEmpty())
        return;

    // make sure no text is selected, move cursor to end of document
    QTextCursor crs = textCursor();
    crs.clearSelection();
    crs.movePosition(QTextCursor::End);
    setTextCursor(crs);

    if (m_parseColors) {
        printColorCoded(m_captured);
    } else {
        QRegExp rx("\033\[[0-9;]*m");
        QString str = m_captured;
        str.remove(rx);
        textCursor().insertText(str);
    }
开发者ID:cptG,项目名称:qling,代码行数:23,代码来源:consoleoutput.cpp


示例4: setTextCursor

void PythonQtScriptingConsole::executeCode(const QString& code)
{
  // put visible cursor to the end of the line
  QTextCursor cursor = QTextEdit::textCursor();
  cursor.movePosition(QTextCursor::End);
  setTextCursor(cursor);

  int cursorPosition = this->textCursor().position();

  // evaluate the code
  _stdOut = "";
  _stdErr = "";
  PythonQtObjectPtr p;
  PyObject* dict = NULL;
  if (PyModule_Check(_context)) {
    dict = PyModule_GetDict(_context);
  } else if (PyDict_Check(_context)) {
    dict = _context;
  }
  if (dict) {
    p.setNewRef(PyRun_String(code.toLatin1().data(), Py_single_input, dict, dict));
  }

  if (!p) {
    PythonQt::self()->handleError();
  }

  flushStdOut();

  bool messageInserted = (this->textCursor().position() != cursorPosition);

  // If a message was inserted, then put another empty line before the command prompt
  // to improve readability.
  if (messageInserted) {
    append(QString());
  }
}
开发者ID:AlphaStaxLLC,项目名称:TundraAddons,代码行数:37,代码来源:PythonQtScriptingConsole.cpp


示例5: textCursor

void ScCodeEditor::evaluateRegion()
{
    QString text;

    // Try current selection
    QTextCursor cursor = textCursor();
    if (cursor.hasSelection())
        text = cursor.selectedText();
    else {
        // If no selection, try current region
        cursor = currentRegion();
        if (!cursor.isNull()) {
            text = cursor.selectedText();
        } else {
            // If no current region, try current line
            cursor = textCursor();
            text = cursor.block().text();
            if( mStepForwardEvaluation ) {
                QTextCursor newCursor = cursor;
                newCursor.movePosition(QTextCursor::NextBlock);
                setTextCursor(newCursor);
            }
            // Adjust cursor for code blinking:
            cursor.movePosition(QTextCursor::StartOfBlock);
            cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
        }
    }

    if (text.isEmpty())
        return;

    text.replace( QChar( 0x2029 ), QChar( '\n' ) );

    Main::evaluateCode(text);

    blinkCode( cursor );
}
开发者ID:vanhuman,项目名称:supercollider-rvh,代码行数:37,代码来源:sc_editor.cpp


示例6: textCursor

void OpenedFile::replaceLine(const int line_number, const QString &new_line)
{
    QString old_text;
    QString new_text = new_line;
    QTextCursor parsingCursor = textCursor();
    int space_count = 0;

    parsingCursor.setPosition(0);

    while(parsingCursor.blockNumber() != line_number)
    {
        parsingCursor.movePosition(QTextCursor::Down);
    }

    parsingCursor.movePosition(QTextCursor::StartOfLine);
    parsingCursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);

    old_text = parsingCursor.selectedText();

    while(old_text.startsWith(" "))
    {
        old_text.remove(0,1);
        space_count++;
    }

    while(space_count>0)
    {
        new_text.prepend(" ");
        space_count--;
    }
    new_text.remove(".0000");
    parsingCursor.insertText(new_text);
    parsingCursor.clearSelection();

    setTextCursor(parsingCursor);
}
开发者ID:bkchr,项目名称:Rockete,代码行数:36,代码来源:OpenedFile.cpp


示例7: setTextCursor

void CSVWorld::ScriptEdit::dropEvent (QDropEvent* event)
{
    const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());

    setTextCursor (cursorForPosition (event->pos()));

    if (mime->fromDocument (mDocument))
    {
        std::vector<CSMWorld::UniversalId> records (mime->getData());

        for (std::vector<CSMWorld::UniversalId>::iterator it = records.begin(); it != records.end(); ++it)
        {
            if (mAllowedTypes.contains (it->getType()))
            {
                if (stringNeedsQuote(it->getId()))
                {
                    insertPlainText(QString::fromUtf8 (('"' + it->getId() + '"').c_str()));
                } else {
                    insertPlainText(QString::fromUtf8 (it->getId().c_str()));
                }
            }
        }
    }
}
开发者ID:0xmono,项目名称:openmw,代码行数:24,代码来源:scriptedit.cpp


示例8: textCursor

void CodeEditor::completeText(const QString &text)
{
    textCursor().beginEditBlock();
    QTextCursor editingTextCursor = textCursor();

    editingTextCursor.setPosition(textCursor().selectionEnd());

    editingTextCursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor);
    editingTextCursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor);
    if(editingTextCursor.selectedText().contains('-'))
    {
        editingTextCursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor);
    }
    else
    {
        editingTextCursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
    }
    editingTextCursor.removeSelectedText();

    editingTextCursor.insertText(text);
    setTextCursor(editingTextCursor);

    textCursor().endEditBlock();
}
开发者ID:Shando,项目名称:Rockete,代码行数:24,代码来源:CodeEditor.cpp


示例9: verticalScrollBar

void QScrollDownTextBrowser::insertHtml(const QString &text)
{
    QScrollBar * b = verticalScrollBar();
    if (linecount >= 2000 && autoClear) {
        keepLines(1000);
        moveCursor(QTextCursor::End);
        linecount = 1000;
        QTextBrowser::insertHtml(text);
        b->setValue(b->maximum());
        return;
    }

    int f = b->value();
    int e = b->maximum();

    /* Stores cursor state before moving it in case we need it later */
    QTextCursor cursor = this->textCursor();

    moveCursor(QTextCursor::End);
    QTextBrowser::insertHtml(text);

    /* If we had something highlighted, restore it */
    if (cursor.selectionEnd() != cursor.selectionStart()) {
        setTextCursor(cursor);
    }

    if(f != e)
    {
        b->setValue(f);
    }
    else
    {
        b->setValue(b->maximum());
    }
    linecount++;
}
开发者ID:Antar1011,项目名称:pokemon-online-1.0.53,代码行数:36,代码来源:otherwidgets.cpp


示例10: textCursor

void AMGraphicsTextItem::changingText()
{
	int initialPosition = textCursor().position();

	QTextCursor newPosition = textCursor();
	int anchorPositon = newPosition.anchor();

	if(textCursor().atStart())
		initialPosition = -2;
	emit textChanged(shapeIndex_);
	if(initialPosition == -1)
	{
		initialPosition++;
	}
	else if (initialPosition == -2)
	{
		newPosition.setPosition(0);
	}
	else
		newPosition.setPosition(initialPosition);
	newPosition.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor,newPosition.position() - anchorPositon);
	setTextCursor(newPosition);
	setSelectAll(false);
}
开发者ID:acquaman,项目名称:acquaman,代码行数:24,代码来源:AMGraphicsTextItem.cpp


示例11: c

void QFCompleterTextEditWidget::uncomment(){
    QTextCursor c(textCursor());
    if (c.selectionStart() == c.selectionEnd()) {
        c.select(QTextCursor::LineUnderCursor);
        c.insertText(removeComments(c.selectedText()));
        //setTextCursor(c);
    } else {
        // now we have to iterate through all selected blocks (lines) and indent them
        QTextCursor c1(c);
        c1.setPosition(c.selectionStart());
        QTextCursor c2(c);
        c2.setPosition(c.selectionEnd());
        c1.beginEditBlock();
        while (c1.blockNumber() <= c2.blockNumber()) {
            c1.select(QTextCursor::BlockUnderCursor);
            //std::cout<<"'"<<c1.selectedText().toLatin1().data()<<"'  =>  '"<<removeComments(c1.selectedText()).toLatin1().data()<<"'"<<std::endl;
            c1.insertText(removeComments(c1.selectedText()));
            if (!c1.movePosition(QTextCursor::NextBlock))
                break;
        }
        c1.endEditBlock();
        setTextCursor(c);
    }
}
开发者ID:jkriege2,项目名称:QuickFit3,代码行数:24,代码来源:qfcompletertextedit.cpp


示例12: c

bool GenericCodeEditor::find( const QRegExp &expr, QTextDocument::FindFlags options )
{
    // Although QTextDocument provides a find() method, we implement
    // our own, because the former one is not adequate.

    if(expr.isEmpty()) return true;

    bool backwards = options & QTextDocument::FindBackward;

    QTextCursor c( textCursor() );
    int pos;
    if (c.hasSelection())
    {
        bool matching = expr.exactMatch(c.selectedText());

        if( backwards == matching )
            pos = c.selectionStart();
        else
            pos = c.selectionEnd();
    }
    else
        pos = c.position();

    QTextDocument *doc = QPlainTextEdit::document();
    QTextBlock startBlock = doc->findBlock(pos);
    int startBlockOffset = pos - startBlock.position();

    QTextCursor cursor;

    if (!backwards) {
        int blockOffset = startBlockOffset;
        QTextBlock block = startBlock;
        while (block.isValid()) {
            if (findInBlock(doc, block, expr, blockOffset, options, cursor))
                break;
            blockOffset = 0;
            block = block.next();
        }
        if(cursor.isNull())
        {
            blockOffset = 0;
            block = doc->begin();
            while(true) {
                if (findInBlock(doc, block, expr, blockOffset, options, cursor)
                    || block == startBlock)
                    break;
                block = block.next();
            }
        }
    } else {
        int blockOffset = startBlockOffset;
        QTextBlock block = startBlock;
        while (block.isValid()) {
            if (findInBlock(doc, block, expr, blockOffset, options, cursor))
                break;
            block = block.previous();
            blockOffset = block.length() - 1;
        }
        if(cursor.isNull())
        {
            block = doc->end();
            while(true) {
                blockOffset = block.length() - 1;
                if (findInBlock(doc, block, expr, blockOffset, options, cursor)
                    || block == startBlock)
                    break;
                block = block.previous();
            }
        }
    }

    if(!cursor.isNull()) {
        setTextCursor(cursor);
        return true;
    }
    else
        return false;
}
开发者ID:ARTisERR0R,项目名称:supercollider,代码行数:78,代码来源:editor.cpp


示例13: switch

//-------------------------------------------------------------------------------------------------
void QCommandPrompt::keyPressEvent(QKeyEvent *e)
{
    // Wenn Enter gedrückt wird, wird die Eingabe als Kommando interpretiert
    switch(e->key())
    {
    case Qt::Key_Return:
        {
            // Alles zwischen Promptposition und dem Textende ist das Kommando
            QString sAll = toPlainText();
            QString sCmd = sAll.right(sAll.count() - m_nPromptPos);

            if (sCmd.length()>0 && (m_vHistory.size()==0 || m_vHistory.back()!=sCmd) )
            {
                m_vHistory.push_back(sCmd);

                while (m_vHistory.size() > m_nMaxHist)
                    m_vHistory.removeFirst();

                m_nHistPos = m_vHistory.size() - 1;
            }

            sCmd = sCmd.trimmed();
            if (!sCmd.isEmpty())
            {
                addLine(getPrompt() + sCmd.trimmed());
                emit commandInput(sCmd);
            }

            // Textcursor ans Ende versetzen
            QTextCursor tc = textCursor();
            tc.movePosition(QTextCursor::End);
            setTextCursor(tc);
        }
        break;

    case Qt::Key_Up:
    case Qt::Key_Down:
        if (m_vHistory.size()==0)
            break;

        clearLineExceptPrompt();
        insertPlainText(m_vHistory[m_nHistPos]);

        m_nHistPos = m_nHistPos + ((e->key()==Qt::Key_Up) ? -1 : 1);
        m_nHistPos = Utils::clamp(0, m_vHistory.size()-1, m_nHistPos);
        break;

    case Qt::Key_Home:
        {
            QTextCursor tc = textCursor();
            Qt::KeyboardModifiers mod = e->modifiers();
            if (mod & Qt::ShiftModifier)
                tc.setPosition(m_nPromptPos, QTextCursor::KeepAnchor);
            else
                tc.setPosition(m_nPromptPos, QTextCursor::MoveAnchor);

            setTextCursor(tc);

        }
        break;

    case Qt::Key_Backspace:
    case Qt::Key_Left:
        {
            int nPos = textCursor().position();
            if (nPos > m_nPromptPos)
                QPlainTextEdit::keyPressEvent(e);
        }
        break;

    default:
        {
            int nPos = textCursor().position();
            if (nPos < m_nPromptPos)
            {
                QTextCursor tc = textCursor();
                tc.movePosition(QTextCursor::End);
                setTextCursor(tc);
            }

            QPlainTextEdit::keyPressEvent(e);
        }
    }
}
开发者ID:beltoforion,项目名称:InstantLua,代码行数:85,代码来源:QCommandPrompt.cpp


示例14: setTextInteractionFlags

void UBGraphicsTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
    setTextInteractionFlags(Qt::TextEditorInteraction);

    // scene()->itemAt(pos) returns 0 if pos is not over text, but over text item, but mouse press comes.
    // It is a cludge...
    if (UBStylusTool::Play == UBDrawingController::drawingController()->stylusTool())
    {
        QGraphicsTextItem::mousePressEvent(event);
        event->accept();
        clearFocus();
        return;
    }

    if (Delegate())
    {
        Delegate()->mousePressEvent(event);
        if (Delegate() && parentItem() && UBGraphicsGroupContainerItem::Type == parentItem()->type())
        {
            UBGraphicsGroupContainerItem *group = qgraphicsitem_cast<UBGraphicsGroupContainerItem*>(parentItem());
            if (group)
            {
                QGraphicsItem *curItem = group->getCurrentItem();
                if (curItem && this != curItem)
                {
                    group->deselectCurrentItem();
                }
                group->setCurrentItem(this);
                this->setSelected(true);
                Delegate()->positionHandles();
            }

        }
        else
        {
            Delegate()->getToolBarItem()->show();
        }

    }

    if (!data(UBGraphicsItemData::ItemEditable).toBool())
        return;

    int elapsed = mLastMousePressTime.msecsTo(QTime::currentTime());

    if (elapsed < UBApplication::app()->doubleClickInterval())
    {
        mMultiClickState++;
        if (mMultiClickState > 3)
            mMultiClickState = 1;
    }
    else
    {
        mMultiClickState = 1;
    }

    mLastMousePressTime = QTime::currentTime();

    if (mMultiClickState == 1)
    {
        QGraphicsTextItem::mousePressEvent(event);
        setFocus();
    }
    else if (mMultiClickState == 2)
    {
        QTextCursor tc= textCursor();
        tc.select(QTextCursor::WordUnderCursor);
        setTextCursor(tc);
    }
    else if (mMultiClickState == 3)
    {
        QTextCursor tc= textCursor();
        tc.select(QTextCursor::Document);
        setTextCursor(tc);
    }
    else
    {
        mMultiClickState = 0;
    }
}
开发者ID:zhgn,项目名称:OpenBoard,代码行数:80,代码来源:UBGraphicsTextItem.cpp


示例15: QStringLiteral

void Console::printWithFormat(const QString& str, const QTextCharFormat& fmt)
{
    const QString escape = QStringLiteral("\x1b[");

    QTextCursor cur(document()->lastBlock());
    cur.movePosition((QTextCursor::StartOfBlock));
    cur.setCharFormat(fmt);

    int startIndex = 0;
    while(true) {
        int escapeIndex = str.indexOf(escape, startIndex);
        if (escapeIndex == -1) {
            // no more escape codes found, output rest of string
            cur.insertText(str.mid(startIndex, str.length()-startIndex));
            break;
        }

        // escape code found, output everything up to it
        cur.insertText(str.mid(startIndex, escapeIndex-startIndex));

        // look for 'm', the termination character for graphic escape codes
        int termIndex = str.indexOf('m', escapeIndex);

        // if didn't find termination code, jump over escape sequence and loop
        if (termIndex == -1) {
            startIndex = escapeIndex + escape.size();
            continue;
        }

        // found termination code, set startIndex for next loop iteration
        startIndex = termIndex + 1;

        // extract payload: should be one or more numbers separated by semicolons
        int formatCodeStart = escapeIndex + escape.size();

        // read format codes
        while (formatCodeStart < termIndex) {
            // Look for digits
            int formatCodeEnd = formatCodeStart;
            while (str[formatCodeEnd].isDigit() && formatCodeEnd < termIndex) {
                formatCodeEnd++;
            }

            // abort if we overran the escape sequence
            if (formatCodeEnd > termIndex) break;

            // convert to number
            QStringRef formatCodeString = str.midRef(formatCodeStart, formatCodeEnd-formatCodeStart);
            bool ok = false;
            int formatCode = formatCodeString.toUInt(&ok);
            if (!ok) break;
            applyFormatCode(cur, formatCode);

            // if a semicolon follows, loop again, otherwise we're done
            if (str[formatCodeEnd] != ';') break;
            formatCodeStart = formatCodeEnd + 1;
        }
    }

    if (!str.endsWith("\n")) {
        cur.insertBlock();
    }
    setTextCursor(cur);
    moveToEndOfCommandLine();
}
开发者ID:wdobbie,项目名称:Nexpo,代码行数:65,代码来源:console.cpp


示例16: processCommand

void Console::keyPressEvent(QKeyEvent *event)
{
    if (event->key() == Qt::Key_Return) // process command
    {
        if (m_completer && m_completer->popup()->isVisible()) {
            event->ignore();
            return;
        } else {
            processCommand();
        }
        return;
    }

  if (inCommandLine())
  {
    // clear selection that spans multiple blocks (or prefix characters) (would overwrite previous command lines):
    QTextCursor cur = textCursor();
    if (cur.hasSelection())
    {
      if (document()->findBlock(cur.selectionStart()) != document()->findBlock(cur.selectionEnd()) || // spans multiple blocks (including command line)
          cur.selectionStart()-cur.block().position() < m_prefix.length() || // spans prefix
          cur.selectionEnd()-cur.block().position() < m_prefix.length() ) // spans prefix
      {
        cur.clearSelection();
        if (cur.positionInBlock() < m_prefix.length())
          cur.setPosition(cur.block().position()+m_prefix.length());
        setTextCursor(cur);
      }
    }
    if (cur.positionInBlock() == m_prefix.length())
    {
      cur.setCharFormat(QTextCharFormat()); // make sure we don't pick up format from prefix
      setTextCursor(cur);
    }
    // react to keystroke:
    if (event->matches(QKeySequence::MoveToPreviousLine)) // history up
    {

      if (m_history.isEmpty() || m_historyPos >= m_history.size()-1)
        return;
      ++m_historyPos;
      int index = m_history.size()-m_historyPos-1;
      QTextCursor cur(document()->lastBlock());
      cur.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, m_prefix.length());
      cur.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
      cur.removeSelectedText();
      cur.setCharFormat(QTextCharFormat());
      cur.insertText(m_history.at(index));
      setTextCursor(cur);

    } else if (event->matches(QKeySequence::MoveToNextLine)) // history down
    {

      if (m_history.isEmpty() || m_historyPos <= 0)
        return;
      --m_historyPos;
      int index = m_history.size()-m_historyPos-1;
      QTextCursor cur(document()->lastBlock());
      cur.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, m_prefix.length());
      cur.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
      cur.removeSelectedText();
      cur.setCharFormat(QTextCharFormat());
      cur.insertText(m_history.at(index));
      setTextCursor(cur);
    } else if (event->matches(QKeySequence::Paste)) // paste text, do it manually to remove text char formatting and newlines
    {
      QString pasteText = QApplication::clipboard()->text();
      pasteText.replace("\n", "").replace("\r", "");
      cur.setCharFormat(QTextCharFormat());
      cur.insertText(pasteText);
      setTextCursor(cur);
    } else if (event->key() == Qt::Key_Backspace || event->matches(QKeySequence::MoveToPreviousChar)) // only allow backspace if we wouldn't delete last char of prefix, similar left arrow
    {
      if (cur.positionInBlock() > m_prefix.length())
        QPlainTextEdit::keyPressEvent(event);
    } else if (event->matches(QKeySequence::MoveToStartOfLine) || event->key() == Qt::Key_Home) {
        // Don't move past prefix when pressing home
        // OSX treats the home key as MoveToStartOfDocument, so including the key code here too
        cur.movePosition(QTextCursor::PreviousCharacter,
                         event->modifiers() & Qt::ShiftModifier ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor,
                         cur.positionInBlock() - m_prefix.length());
        cur.setCharFormat(QTextCharFormat());
        setTextCursor(cur);
    } else if (event->key() == Qt::Key_Escape) {
        if (m_completer && m_completer->popup()->isVisible()) {
            m_completer->popup()->hide();
        } else {
            QTextCursor cur(document()->lastBlock());
            cur.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, m_prefix.length());
            cur.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
            cur.removeSelectedText();
            setTextCursor(cur);
        }
    } else if (event->key() == Qt::Key_Tab) {
        if (m_completer) {
            m_completer->setCompletionPrefix(currentWord());
            QRect cr = cursorRect();
            cr.setWidth(m_completer->popup()->sizeHintForColumn(0)
                        + m_completer->popup()->verticalScrollBar()->sizeHint().width());
            m_completer->complete(cr);
//.........这里部分代码省略.........
开发者ID:wdobbie,项目名称:Nexpo,代码行数:101,代码来源:console.cpp


示例17: currentRegion

void ScCodeEditor::selectCurrentRegion()
{
    QTextCursor selectedRegionCursor = currentRegion();
    if (!selectedRegionCursor.isNull() && selectedRegionCursor.hasSelection())
        setTextCursor(selectedRegionCursor);
}
开发者ID:vanhuman,项目名称:supercollider-rvh,代码行数:6,代码来源:sc_editor.cpp


示例18: textCursor

void GroupedLineEdit::selectAll()
{
	QTextCursor c = textCursor();
	c.select(QTextCursor::LineUnderCursor);
	setTextCursor(c);
}
开发者ID:B-Rich,项目名称:subsurface,代码行数:6,代码来源:groupedlineedit.cpp


示例19: switch

 void QFCompleterTextEditWidget::keyPressEvent(QKeyEvent *event) {
     if (c && c->popup()->isVisible()) {
         // The following keys are forwarded by the completer to the widget
        switch (event->key()) {
            case Qt::Key_Enter:
            case Qt::Key_Return:
            case Qt::Key_Escape:
            case Qt::Key_Tab:
            case Qt::Key_Backtab:
                 event->ignore();
                 return; // completer widgets handles these keys!
            default:
                break;
        }
     } else {
        // if the completer is not visible, we may treat some special
        // key press events (convert TAB to spaces ...
        if (event->key()==Qt::Key_Tab) { // convert TAB to <tabwidth> spaces
            processTab(event);
            return; // let the completer do default behavior
        } else if (event->key()==Qt::Key_Backtab || (event->key()==Qt::Key_Tab && event->modifiers()==Qt::ShiftModifier)) {
            indentDec();
            return; // let the completer do default behavior
        } else if (event->key()==Qt::Key_Return || event->key()==Qt::Key_Enter) {
            // indent when last non-space character in current line is '{'
            QTextCursor tc = textCursor();

            // if text has been selected, the user wants to overwrite this text
            // with a linebreak, so we first delete the text
            if (tc.hasSelection()) tc.deleteChar();
            //tc.select(QTextCursor::LineUnderCursor);
            tc.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor);
            QString line=tc.selectedText();

            // count leading spaces
            int lspaces=0;
            QChar* data=line.data();
            while (data->isSpace()) {
                ++data;
                lspaces++;
            }
            // get right-most non-space character
            int indx=line.size()-1;
            data=line.data();
            if (indx>=0) while (data[indx].isSpace() && (indx>0)) {
                indx--;
            }
            QChar last=data[indx];

            if (last=='{') {
                QTextCursor c(textCursor());
                c.insertText("\n"+QString(lspaces, QChar(' '))+tabToSpaces());
                setTextCursor(c);
            } else if (last=='}' && line.indexOf('}')==lspaces) {
                // '}' is the first non-space character in this line
                QTextCursor c(textCursor());
                QTextCursor c1(textCursor());
                c1.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor);
                QString left=c1.selectedText();
                if (lspaces>0 && left=="}") {
                    long clspaces=lspaces; // the number of leading spaces in the current line
                    long indention=qMax((long)0, (long)lspaces-(long)tabwidth); // new number of leading spaces
                    // here we try to find the matching '{' and reduce the indention to the
                    // indention of the matching '{'. If the matching '{' was not found,
                    // the indention will not be reduced
                    QTextCursor cc(textCursor());
                    int cnt=1;
                    int pos=cc.selectionStart()-2;
                    while ((cnt>0) && (pos>=0)) {
                        cc.setPosition(pos);
                        cc.setPosition(pos+1, QTextCursor::KeepAnchor);
                        QString curChar=cc.selectedText();
                        if (curChar=="{") cnt--;
                        if (curChar=="}") cnt++;
                        //std::cout<<"'"<<(char*)curChar.toLatin1().data()<<"'  cnt="<<cnt<<"  pos="<<pos<<std::endl;
                        pos--;
                    }
                    // here we found the matching '{' and count its leading spaces
                    if (pos>=0){
                        cc.select(QTextCursor::LineUnderCursor);
                        lspaces=0;
                        QChar* data=cc.selectedText().data();
                        while (data->isSpace()) {
                            ++data;
                            lspaces++;
                        }
                        indention=lspaces;
                    }
                    //std::cout<<"indention="<<indention<<"   clspaces="<<clspaces<<"    lspaces="<<lspaces<<std::endl;
                    c=textCursor();
                    c.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor);
                    c.insertText(QString(indention, QChar(' '))+line.right(qMax((long)1,(long)line.size()-clspaces))+"\n"+QString(indention, QChar(' ')));
                    //c.movePosition(QTextCursor::Left);
                    //c.insertText("\n"+QString(lspaces, QChar(' ')));
                } else {
                    c=textCursor();
                    c.insertText("\n");
                }
                setTextCursor(c);
            } else {
//.........这里部分代码省略.........
开发者ID:jkriege2,项目名称:QuickFit3,代码行数:101,代码来源:qfcompletertextedit.cpp


示例20: hideMouseCursor

void GenericCodeEditor::keyPressEvent(QKeyEvent * e)
{
    hideMouseCursor(e);

    QTextCursor cursor( textCursor() );

    bool updateCursor = false;

    if (e == QKeySequence::InsertLineSeparator) {
        // override to avoid entering a "soft" new line
        cursor.insertBlock();
        updateCursor = true;
    } else {
        switch (e->key()) {

        case Qt::Key_Delete:
            if (e->modifiers() & Qt::META) {
                cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
                cursor.removeSelectedText();
            } else
                QPlainTextEdit::keyPressEvent(e);
            break;

        case Qt::Key_Backspace:
            if (e->modifiers() & Qt::META) {
                cursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor);
                cursor.removeSelectedText();
            } else {
                if ( !overwriteMode()
                     || (cursor.positionInBlock() == 0)
                     || cursor.hasSelection() ) {
                    QPlainTextEdit::keyPressEvent(e);
                } else {
                    // in overwrite mode, backspace should insert a space
                    cursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor);
                    QString selectedText = cursor.selectedText();
                    if (selectedText == QString(" ") ||
                        selectedText == QString("\t") ) {
                        cursor.clearSelection();
                    } else {
                        cursor.insertText(QString(QChar(' ')));
                        cursor.movePosition(QTextCursor::PreviousCharacter);
                    }
                }
                updateCursor = true;
            }
            break;

        case Qt::Key_Down:
        {
            if (cursor.block() == textDocument()->lastBlock()) {
                QTextCursor::MoveMode moveMode = e->modifiers() & Qt::SHIFT ? QTextCursor::KeepAnchor
                                                                            : QTextCursor::MoveAnchor;

                cursor.movePosition(QTextCursor::EndOfBlock, moveMode);
                setTextCursor(cursor);
            } else
                QPlainTextEdit::keyPressEvent(e);
            break;
        }

        case Qt::Key_Up:
        {
            if (cursor.block() == textDocument()->firstBlock()) {
                QTextCursor::MoveMode moveMode = e->modifiers() & Qt::SHIFT ? QTextCursor::KeepAnchor
                                                                            : QTextCursor::MoveAnchor;

                cursor.movePosition(QTextCursor::StartOfBlock, moveMode);
                setTextCursor(cursor);
            } else
                QPlainTextEdit::keyPressEvent(e);
            break;
        }

        default:
            QPlainTextEdit::keyPressEvent(e);

        }
    } // else...

    if (updateCursor) {
        cursor.setVerticalMovementX(-1);
        setTextCursor( cursor );
        ensureCursorVisible();
    }
    doKeyAction(e);
}
开发者ID:brunoruviaro,项目名称:supercollider,代码行数:87,代码来源:editor.cpp



注:本文中的setTextCursor函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ setTextFormat函数代码示例发布时间:2022-05-30
下一篇:
C++ setTextColor函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap