当前位置: 首页>>代码示例>>C++>>正文


C++ QTextCursor::atBlockStart方法代码示例

本文整理汇总了C++中QTextCursor::atBlockStart方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextCursor::atBlockStart方法的具体用法?C++ QTextCursor::atBlockStart怎么用?C++ QTextCursor::atBlockStart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QTextCursor的用法示例。


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

示例1: keyPressEvent

void QSAEditor::keyPressEvent(QKeyEvent *e)
{
    QTextCursor cursor = textCursor();
    const QChar leftChar = charFromCursor(cursor, QTextCursor::PreviousCharacter);

    if (e->key() == Qt::Key_Tab) {
        QString leftText = cursor.block().text().left(cursor.position() - cursor.block().position());
        if (cursor.hasSelection() || leftText.simplified().isEmpty()) {
            indent(document(), cursor);
            e->accept();
            return;
        }
    }

    if ((e->key() == Qt::Key_Period
         && (cursor.atBlockStart() || leftChar != QLatin1Char('.'))
        )
        || (e->key() == Qt::Key_Greater
            && !cursor.atBlockStart()
            && leftChar == QLatin1Char('-'))
       ) {
        doObjectCompletion();
    }
    QTextEdit::keyPressEvent(e);
}
开发者ID:aschet,项目名称:qsaqt5,代码行数:25,代码来源:qsaeditor.cpp

示例2: textUnderCursor

QString ScriptEditorWidget::textUnderCursor() const
{
	QString szWord;
	QTextCursor tc = textCursor();
	if(tc.atBlockStart())
		return QString();
	tc.clearSelection();
	tc.movePosition(QTextCursor::StartOfWord,QTextCursor::KeepAnchor);
	if(tc.atBlockStart())
	{
		szWord.append(tc.selectedText());
		tc.movePosition(QTextCursor::EndOfWord,QTextCursor::KeepAnchor);
		szWord.append(tc.selectedText());
		if(tc.atBlockEnd()){
			return szWord;
		}
		tc.movePosition(QTextCursor::NextCharacter,QTextCursor::KeepAnchor);
		szWord.append(tc.selectedText());
		if(szWord.right(1)!=".")
			szWord.chop(1);
		return szWord;
	}

	tc.movePosition(QTextCursor::PreviousCharacter,QTextCursor::KeepAnchor);
	szWord=tc.selectedText();
	if(szWord.left(1)==".")
	{
		tc.movePosition(QTextCursor::StartOfWord);
		tc.movePosition(QTextCursor::PreviousCharacter);
		tc.movePosition(QTextCursor::PreviousWord);
		tc.movePosition(QTextCursor::EndOfWord,QTextCursor::KeepAnchor,1);
		szWord.prepend(tc.selectedText());
	} else szWord.remove(0,1);
	return szWord;
}
开发者ID:philouvb,项目名称:KVIrc,代码行数:35,代码来源:ScriptEditorImplementation.cpp

示例3: moveLineUpDown

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);
}
开发者ID:ARTisERR0R,项目名称:supercollider,代码行数:58,代码来源:editor.cpp

示例4: copyUpDown

void GenericCodeEditor::copyUpDown(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.beginEditBlock();

    bool hasSelection = cursor.hasSelection();

    if (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();

    if (up) {
        move.setPosition(cursor.selectionStart());
        move.movePosition(QTextCursor::StartOfBlock);
        move.insertBlock();
        move.movePosition(QTextCursor::Left);
    } else {
        move.movePosition(QTextCursor::EndOfBlock);
        if (move.atBlockStart()) {
            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();

    move.setPosition(start);
    move.setPosition(end, QTextCursor::KeepAnchor);

    move.endEditBlock();

    setTextCursor(move);
}
开发者ID:ARTisERR0R,项目名称:supercollider,代码行数:52,代码来源:editor.cpp

示例5: changeUnderCursor

QString CvsEditorWidget::changeUnderCursor(const QTextCursor &c) const
{
    // Try to match "1.1" strictly:
    // 1) Annotation: Check for a revision number at the beginning of the line.
    //    Note that "cursor.select(QTextCursor::WordUnderCursor)" will
    //    only select the part up until the dot.
    //    Check if we are at the beginning of a line within a reasonable offset.
    // 2) Log: check for lines like "revision 1.1", cursor past "revision"
    switch (contentType()) {
    case VcsBase::OtherContent:
    case VcsBase::DiffOutput:
        break;
    case VcsBase::AnnotateOutput: {
            const QTextBlock block = c.block();
            if (c.atBlockStart() || (c.position() - block.position() < 3)) {
                const QString line = block.text();
                if (m_revisionAnnotationPattern.exactMatch(line))
                    return m_revisionAnnotationPattern.cap(1);
            }
        }
        break;
    case VcsBase::LogOutput: {
            const QTextBlock block = c.block();
            if (c.position() - block.position() > 8 && m_revisionLogPattern.exactMatch(block.text()))
                return m_revisionLogPattern.cap(1);
        }
        break;
    }
    return QString();
}
开发者ID:acacid,项目名称:qt-creator,代码行数:30,代码来源:cvseditor.cpp

示例6: textChangeEvent

void TextProcessor::textChangeEvent() {
	if (autoInsertion_)
		return;

	QTextCursor c = edit_->textCursor();
	if (c.atBlockStart()) {
		QTextBlock bl = c.block();
		QTextBlock prevBl = bl.previous();
		if (bl.isValid() && prevBl.isValid()) {

			//	ensure that cursor was moved from the previous row
			if (lastRow_ - 1 != preLastRow_)
				return;

			QString text = bl.text();
			QString prevText = prevBl.text();
			if (/*text.isEmpty() &&*/ !prevText.isEmpty()) {
				int lineBeginIndex = prevText.indexOf(QRegExp("[^ \t]"));
				QString lineBegin = prevText.left(lineBeginIndex);

				autoInsertion_ = true;
				while (bl.text().startsWith('\t') || bl.text().startsWith(' ')) {
					c.deleteChar();
				}
				c.insertText(lineBegin);
				autoInsertion_ = false;
			}
		}
	}
}
开发者ID:harsha-mudi,项目名称:wily,代码行数:30,代码来源:TextProcessor.cpp

示例7: moveToPreviousToken

void ScCodeEditor::moveToPreviousToken( QTextCursor & cursor, QTextCursor::MoveMode mode )
{
    if (cursor.atBlockStart()) {
        cursor.movePosition( QTextCursor::PreviousCharacter, mode );
        return;
    }

    QTextBlock block( cursor.block() );
    QString blockText = block.text();
    int positionInBlock = cursor.position() - block.position() - 1;

    // skip whitespace
    while (positionInBlock > 0 && blockText[positionInBlock].isSpace())
        --positionInBlock;

    cursor.setPosition(positionInBlock + block.position(), mode);
    if (positionInBlock == 0)
        return;

    // go to beginning of token or beginning of word
    TokenIterator tokenIt( block, positionInBlock );
    if (tokenIt.isValid()) {
        cursor.setPosition( tokenIt.position(), mode );
    } else {
        int pos = positionInBlock;
        if (blockText[pos].isLetterOrNumber()) {
            while (pos > 0 && blockText[pos-1].isLetterOrNumber())
                --pos;
        }
        cursor.setPosition( pos + block.position(), mode );
    }
}
开发者ID:vanhuman,项目名称:supercollider-rvh,代码行数:32,代码来源:sc_editor.cpp

示例8: isBlockOnlySelection

static bool isBlockOnlySelection(QTextCursor cursor)
{
    Q_ASSERT(cursor.hasSelection());

    QTextCursor begin(cursor);
    begin.setPosition(begin.anchor());

    if (begin.atBlockStart() && (cursor.atBlockStart() || cursor.atBlockEnd()))
        return true;
    else
        return false;
}
开发者ID:vanhuman,项目名称:supercollider-rvh,代码行数:12,代码来源:sc_editor.cpp

示例9: indentText

void SyntaxTextEditor::indentText(QTextDocument *doc, QTextCursor cur, bool bIndent)
{
    cur.beginEditBlock();
    if (!cur.hasSelection()) {
        indentCursor(cur,bIndent);
    } else {
        QTextBlock block = doc->findBlock(cur.selectionStart());
        QTextBlock end = doc->findBlock(cur.selectionEnd());
        if (!cur.atBlockStart()) {
            end = end.next();
        }
        do {
            indentBlock(block,bIndent);
            block = block.next();
        } while (block.isValid() && block != end);
    }
    cur.endEditBlock();
}
开发者ID:bezigon,项目名称:liteide,代码行数:18,代码来源:syntaxtexteditor.cpp

示例10: textUnderCursor

QString TikzEditor::textUnderCursor() const
{
	QTextCursor cursor = textCursor();
	const int oldPos = cursor.position();
//	cursor.select(QTextCursor::WordUnderCursor);
//	const int newPos = cursor.selectionStart();
	int newPos;
	for (newPos = oldPos; newPos > 0;) // move the cursor to the beginning of the word
	{
		cursor.setPosition(--newPos, QTextCursor::KeepAnchor);
		if (cursor.selectedText().trimmed().isEmpty()) // if the current char is a whitespace, then we have reached the beginning of the word
		{
			cursor.clearSelection();
			cursor.setPosition(++newPos, QTextCursor::MoveAnchor);
			break;
		}
		else if (cursor.selectedText() == "\\" || cursor.atBlockStart()) // these characters also delimit the beginning of the word (the beginning of a TikZ command)
		{
			cursor.clearSelection();
			break;
		}
		else if (cursor.selectedText() == "["
		    || cursor.selectedText() == ",") // these characters also delimit the beginning of the word (the beginning of a TikZ option)
		{
			cursor.clearSelection();
			cursor.setPosition(++newPos, QTextCursor::MoveAnchor);
			break;
		}
		cursor.clearSelection();
	}
//	cursor.setPosition(newPos, QTextCursor::MoveAnchor);
	cursor.setPosition(oldPos, QTextCursor::KeepAnchor);
	QString word = cursor.selectedText();
//	if (word.right(1) != word.trimmed().right(1))
//		word = "";
	return word;
}
开发者ID:jfmcarreira,项目名称:ktikz-old,代码行数:37,代码来源:tikzeditor.cpp

示例11: keyPressEvent

void CodeEditor::keyPressEvent(QKeyEvent* event)
{
    if (event->key() == Qt::Key_Return && event->modifiers() == Qt::SHIFT)
        return;

    if (event->key() == Qt::Key_E && event->modifiers() == Qt::CTRL) {
        QTextBlock block = textCursor().block();
        foldUnfold(block);
        FULLRESIZE;
        return;
    }

    if (event->key() == Qt::Key_Space && event->modifiers() == Qt::CTRL) {
        performCompletion();
        return;
    }

    if (event->key() == Qt::Key_Backspace && config->backUnindent) {
        QTextCursor cursor = textCursor();

        if (!cursor.hasSelection() && !cursor.atBlockStart() && cursor.block().text().          \
                                                                left(cursor.positionInBlock()). \
                                                                trimmed().isEmpty()) {
            cursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor,
                                qMin(config->indentSize, cursor.positionInBlock()));
            cursor.removeSelectedText();
            return;
        }
    }

    if (event->key() == Qt::Key_Tab && config->tabIndents) {
        QTextCursor cursor = textCursor();

        if (cursor.hasSelection()) {

            QTextBlock block = document()->findBlock(cursor.selectionStart());

            int end = document()->findBlock(cursor.selectionEnd()).blockNumber();

            if (end - block.blockNumber()) {

                cursor.beginEditBlock();

                do {
                    cursor.setPosition(block.position(), QTextCursor::MoveAnchor);
                    cursor.insertText(QString().fill(' ', config->indentSize));
                } while ((block = block.next()).isValid() && block.blockNumber() <= end);

                cursor.endEditBlock();

                return;
            }

        } else if (textCursor().block().text().          \
                   left(textCursor().positionInBlock()). \
                   trimmed().isEmpty()) {
                   textCursor().insertText(QString().fill(' ', config->indentSize));
                   return;
        }
    }

    if (event->key() == Qt::Key_Tab && config->spaceTabs) {
        textCursor().insertText(QString().fill(' ', config->tabSize));
        return;
    }

    if (completer->popup()->isVisible()) {
        switch (event->key()) {
            case Qt::Key_Up:
            case Qt::Key_Down:
            case Qt::Key_Enter:
            case Qt::Key_Return:
            case Qt::Key_Escape:
                event->ignore();
                return;
        }
    }

    QPlainTextEdit::keyPressEvent(event);

    if (completer->popup()->isVisible())
        performCompletion();

    if (event->key() == Qt::Key_Return && config->autoIndent) {
        int state = textCursor().block().userState();

        if (!(state & Error) && (state & Nested)) {
            QString txt = textCursor().block().previous().text();

            int i = 0;

            while (txt[i].isSpace()) ++i;

            int previousBlockState = textCursor().block().previous().userState();

            if (!(previousBlockState & Error) && previousBlockState & Begin)
                i += config->indentSize;

            textCursor().insertText(QString().fill(' ', i));
        }
//.........这里部分代码省略.........
开发者ID:MichaelJE,项目名称:Clips,代码行数:101,代码来源:codeeditor.cpp

示例12: keyPressEvent


//.........这里部分代码省略.........
			}

			cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
			text = cursor.selectedText();
			switch (checkType(text)) {
			case t_TYPE:
				cursor.insertText(text, colorFormat(type_color));
				break;
			case t_KEYWORD:
				cursor.insertText(text, colorFormat(keyword_color));
				break;
			case t_DEFAULT:
				cursor.insertText(text, colorFormat(default_color));
			}

			cursor.setPosition(position);
			cursor.insertText(input->text());
			position++;
		}

		position = autoIndent(cursor);
		cursor.setPosition(position);
		setTextCursor(cursor);
		return;

	case Qt::Key_Tab:
		cout << "tab" << endl;
		position = autoIndent(cursor);
		cursor.setPosition(position);
		setTextCursor(cursor);
		std::cout << "block_stack" << block_stack << std::endl;
		return;
	case Qt::Key_Left:
		if (cursor.atBlockStart()) {
			cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor);
			position = cursor.position();
			cursor.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor);
			text = cursor.selectedText();

			count = 0;
			while (count < text.size()) {
				if (text[count] == QChar('{')) {
					block_stack--;
				} else if (text[count] == QChar('}')) {
					block_stack++;
				}
				count++;
			}
			cursor.setPosition(position, QTextCursor::MoveAnchor);
		} else {
			cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor);
		}
		setTextCursor(cursor);
		std::cout << block_stack << std::endl;
		return;
	case Qt::Key_Right:
		if (cursor.atEnd()) {
			return;
		} else if (cursor.atBlockEnd()) {
			cursor.movePosition(QTextCursor::StartOfLine, QTextCursor::MoveAnchor);
			cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
			text = cursor.selectedText();

			count = 0;
			while (count < text.size()) {
				if (text[count] == QChar('{')) {
开发者ID:sugie1616,项目名称:soeditor,代码行数:67,代码来源:sotextedit.cpp


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