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


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

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


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

示例1: KoTextCommandBase

ChangeListLevelCommand::ChangeListLevelCommand(const QTextCursor &cursor, ChangeListLevelCommand::CommandType type,
                                               int coef, KUndo2Command *parent)
    : KoTextCommandBase(parent),
      m_type(type),
      m_coefficient(coef),
      m_first(true)
{
    setText(kundo2_i18n("Change List Level"));

    int selectionStart = qMin(cursor.anchor(), cursor.position());
    int selectionEnd = qMax(cursor.anchor(), cursor.position());

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

    bool oneOf = (selectionStart == selectionEnd); //ensures the block containing the cursor is selected in that case

    while (block.isValid() && ((block.position() < selectionEnd) || oneOf)) {
        m_blocks.append(block);
        if (block.textList()) {
            m_lists.insert(m_blocks.size() - 1, KoTextDocument(block.document()).list(block.textList()));
            Q_ASSERT(m_lists.value(m_blocks.size() - 1));
            m_levels.insert(m_blocks.size() - 1, effectiveLevel(m_lists.value(m_blocks.size() - 1)->level(block)));
        }
        oneOf = false;
        block = block.next();
    }
}
开发者ID:TheTypoMaster,项目名称:calligra,代码行数:27,代码来源:ChangeListLevelCommand.cpp

示例2: assignCommentOffset

void DoxygenGenerator::assignCommentOffset(QTextCursor cursor)
{
    if (cursor.hasSelection()) {
        if (cursor.anchor() < cursor.position())
            cursor.setPosition(cursor.anchor());
    }

    m_commentOffset = cursor.positionInBlock();
}
开发者ID:hdweiss,项目名称:qt-creator-visualizer,代码行数:9,代码来源:doxygengenerator.cpp

示例3: batchReplace

FindResult batchReplace(QTextCursor &cursor, QTextDocument const &document,
                        ReplaceQuery const &query, boost::optional<int> start,
                        boost::optional<int> end)
{
	// If we weren't given a start position, use the current cursor.
	if(!start)
		start = std::min(cursor.anchor(), cursor.position());

	// We can't enable wrapping, when replacing inside a specific range.
	ReplaceQuery rangeQuery = query;
	rangeQuery.wrap = false;

	// Replace each match we find after our start position.

	cursor.setPosition(*start, QTextCursor::MoveAnchor);
	FindResult result = find(cursor, document, true, rangeQuery);
	bool foundAny = false;
	cursor.beginEditBlock();

	while(result == FindResult::Found)
	{
		// Make sure this match is in range.
		int foundAnchor = cursor.anchor();
		int foundPosition = cursor.position();
		if(!!end && (std::max(foundAnchor, foundPosition) > *end))
			break;

		foundAny = true;

		// Replace this match, and move the cursor after it. We also
		// need to update the "end" value, since we may have changed
		// the length of the document.
		if(!!end)
		{
			int selectionLength = cursor.selectedText().length();
			end = *end + (rangeQuery.replaceValue.length() -
			              selectionLength);
		}
		cursor.insertText(rangeQuery.replaceValue);
		cursor.setPosition(std::min(foundAnchor, foundPosition),
		                   QTextCursor::MoveAnchor);
		cursor.movePosition(QTextCursor::NextCharacter,
		                    QTextCursor::KeepAnchor,
		                    rangeQuery.replaceValue.length());

		// Find the next match (if any).
		result = find(cursor, document, true, rangeQuery);
	};

	cursor.endEditBlock();

	return foundAny ? FindResult::Found : result;
}
开发者ID:CmdrMoozy,项目名称:qompose,代码行数:53,代码来源:Replace.cpp

示例4: increaseSelectionIndent

void SqlTextEdit::increaseSelectionIndent()
{
    QTextCursor cursor = textCursor();
    int spos = cursor.anchor();
    int epos = cursor.position();
    if (spos > epos) std::swap(spos, epos);

    cursor.setPosition(spos, QTextCursor::MoveAnchor);
    int sblock = cursor.block().blockNumber();

    cursor.setPosition(epos, QTextCursor::MoveAnchor);
    int eblock = cursor.block().blockNumber();

    cursor.setPosition(spos, QTextCursor::MoveAnchor);
    const int diff = eblock - sblock;

    cursor.beginEditBlock();
    for (int i = 0; i <= diff; ++i)
    {
        cursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor);
        cursor.insertText("    ");
        cursor.movePosition(QTextCursor::NextBlock, QTextCursor::MoveAnchor);
    }
    cursor.endEditBlock();

    cursor.setPosition(spos, QTextCursor::MoveAnchor);
    cursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor);

    while (cursor.block().blockNumber() < eblock)
        cursor.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor);

    cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
    setTextCursor(cursor);
}
开发者ID:eyohansa,项目名称:sqlitebrowser,代码行数:34,代码来源:sqltextedit.cpp

示例5: append

void FLogTextBrowser::append(const QString & text)
{
	QTextCursor cur = textCursor();
	if (cur.hasSelection())
	{
		int oldPosition = cur.position();
		int oldAnchor = cur.anchor();

		int vpos = verticalScrollBar()->value();
		int vmax = verticalScrollBar()->maximum();

		QTextBrowser::append(text);

		cur.setPosition(oldAnchor, QTextCursor::MoveAnchor);
		cur.setPosition(oldPosition, QTextCursor::KeepAnchor);
		setTextCursor(cur);
		if (vpos != vmax) { verticalScrollBar()->setValue(vpos); }
		else
		{
			vmax = verticalScrollBar()->maximum();
			verticalScrollBar()->setValue(vmax);
		}
	}
	else { QTextBrowser::append(text); }
}
开发者ID:kythyria,项目名称:flist-messenger,代码行数:25,代码来源:flist_logtextbrowser.cpp

示例6: executeAsScript

void WorksheetQueryPane::executeAsScript()
{
    if(!canExecute()){
        return;
    }

    CodeEditor *editor = currentEditor()->editor();
    QTextCursor cur;
    QString queryText = editor->getCurrentText(cur, true);

    sequentialRunnerStartPos = qMin(cur.position(), cur.anchor());

    if(queryText.trimmed().isEmpty()){
        emitMessage(tr("Query text cannot be empty"));
        return;
    }

    this->currentQueryCursor = cur;

    emit scriptModeStarted();

    multiEditor->setReadOnly(true);
    setInProgress(true);

    sequentialRunner.execute(queryText, this);
}
开发者ID:rovshan-b,项目名称:oraexp,代码行数:26,代码来源:worksheetquerypane.cpp

示例7: requestSetBlockSelection

void FakeVimProxy::requestSetBlockSelection(const QTextCursor &tc) {
    QPlainTextEdit *ed = qobject_cast<QPlainTextEdit *>(m_widget);
    if (!ed)
        return;

    QPalette pal = ed->parentWidget() != NULL ? ed->parentWidget()->palette()
                                              : QApplication::palette();

    m_blockSelection.clear();
    m_clearSelection.clear();

    QTextCursor cur = tc;

    QTextEdit::ExtraSelection selection;
    selection.format.setBackground( pal.color(QPalette::Base) );
    selection.format.setForeground( pal.color(QPalette::Text) );
    selection.cursor = cur;
    m_clearSelection.append(selection);

    selection.format.setBackground( pal.color(QPalette::Highlight) );
    selection.format.setForeground( pal.color(QPalette::HighlightedText) );

    int from = cur.positionInBlock();
    int to = cur.anchor() - cur.document()->findBlock(cur.anchor()).position();
    const int min = qMin(cur.position(), cur.anchor());
    const int max = qMax(cur.position(), cur.anchor());
    for ( QTextBlock block = cur.document()->findBlock(min);
          block.isValid() && block.position() < max; block = block.next() ) {
        cur.setPosition( block.position() + qMin(from, block.length()) );
        cur.setPosition( block.position() + qMin(to, block.length()), QTextCursor::KeepAnchor );
        selection.cursor = cur;
        m_blockSelection.append(selection);
    }

    disconnect( ed, &QPlainTextEdit::selectionChanged,
                this, &FakeVimProxy::updateBlockSelection );
    ed->setTextCursor(tc);
    connect( ed, &QPlainTextEdit::selectionChanged,
             this, &FakeVimProxy::updateBlockSelection );

    QPalette pal2 = ed->palette();
    pal2.setColor(QPalette::Highlight, Qt::transparent);
    pal2.setColor(QPalette::HighlightedText, Qt::transparent);
    ed->setPalette(pal2);

    updateExtraSelections();
}
开发者ID:pbek,项目名称:QOwnNotes,代码行数:47,代码来源:fakevimproxy.cpp

示例8: findMatchFound

void CAPresentationHandler::findMatchFound (const KoFindMatch& match)
{
    QTextCursor cursor = match.location().value<QTextCursor>();
    updateCanvas();

    canvas()->resourceManager()->setResource (KoText::CurrentTextAnchor, cursor.anchor());
    canvas()->resourceManager()->setResource (KoText::CurrentTextPosition, cursor.position());
    d->matchFound = true;
}
开发者ID:nemomobile-packages,项目名称:calligra,代码行数:9,代码来源:CAPresentationHandler.cpp

示例9: cursorIsInEditingRegion

bool LuaConsole::cursorIsInEditingRegion(const QTextCursor& cursor)
{
    // Want to be to the right of the prompt...
    if (positionInBlock(cursor) < promptLength)
        return false;
    // ... and in the final line.
    if (cursor.blockNumber() != ui->plainTextEdit->blockCount() - 1)
        return false;
    if (cursor.anchor() != cursor.position()) {
        // Anchor might be outside of editing region
        QTextCursor anchorCursor(cursor);
        anchorCursor.setPosition(cursor.anchor());
        if (positionInBlock(anchorCursor) < promptLength)
            return false;
        if (anchorCursor.blockNumber() != ui->plainTextEdit->blockCount() - 1)
            return false;
    }
    return true;
}
开发者ID:zonedoutspace,项目名称:Sapience,代码行数:19,代码来源:luaconsole.cpp

示例10: shouldSkipASTNodeBasedOnPosition

bool CppSelectionChanger::shouldSkipASTNodeBasedOnPosition(
        const ASTNodePositions &positions,
        const QTextCursor &cursor) const
{
    bool shouldSkipNode = false;

    bool isEqual = cursor.anchor() == positions.astPosStart
                   && cursor.position() == positions.astPosEnd;

    // New selections should include initial selection.
    bool includesInitialSelection =
            m_initialChangeSelectionCursor.anchor() >= positions.astPosStart &&
            m_initialChangeSelectionCursor.position() <= positions.astPosEnd;

    // Prefer new selections to start with initial cursor if anchor == position.
    if (!m_initialChangeSelectionCursor.hasSelection()) {
        includesInitialSelection =
                m_initialChangeSelectionCursor.position() < positions.astPosEnd;
    }

    // When expanding: Skip if new selection is smaller than current cursor selection.
    // When shrinking: Skip if new selection is bigger than current cursor selection.
    bool isNewSelectionSmaller = positions.astPosStart > cursor.anchor()
                                 || positions.astPosEnd < cursor.position();
    bool isNewSelectionBigger = positions.astPosStart < cursor.anchor()
                                || positions.astPosEnd > cursor.position();

    if (m_direction == CppSelectionChanger::ExpandSelection
        && (isNewSelectionSmaller || isEqual || !includesInitialSelection)) {
        shouldSkipNode = true;
    } else if (m_direction == CppSelectionChanger::ShrinkSelection
               && (isNewSelectionBigger || isEqual || !includesInitialSelection)) {
        shouldSkipNode = true;
    }

    if (debug && shouldSkipNode) {
        qDebug() << "isEqual:" << isEqual << "includesInitialSelection:" << includesInitialSelection
                 << "isNewSelectionSmaller:" << isNewSelectionSmaller << "isNewSelectionBigger:"
                 << isNewSelectionBigger;
    }

    return shouldSkipNode;
}
开发者ID:kai66673,项目名称:qt-creator,代码行数:43,代码来源:cppselectionchanger.cpp

示例11: LimitCursorSelectionTo

void ConsoleWidget::LimitCursorSelectionTo(int start)
{
    QTextCursor cursor = textCursor();
    int anchor = cursor.anchor(), position = cursor.position();
    if (anchor != position && (anchor < start || position < start))
    {
        cursor.setPosition(qMax(start, anchor), QTextCursor::MoveAnchor);
        cursor.setPosition(qMax(start, position), QTextCursor::KeepAnchor);
        setTextCursor(cursor);
    }
}
开发者ID:TeamKami,项目名称:KamiCmd,代码行数:11,代码来源:ConsoleWidget.cpp

示例12: editorSelectionChange

void PersistentState::editorSelectionChange() {
	QTextCursor cursor = editor()->textCursor();
	if (cursor.hasSelection()) {
		if (cursor.anchor() == _persistentCursor.position())
			_persistentCursor.setPosition(cursor.position(), QTextCursor::KeepAnchor);
		else
			_persistentCursor = cursor;
			
		cursor.clearSelection();
		editor()->setTextCursor(cursor);
		editor()->update();
		emit copyAvailable(true);
	}
}
开发者ID:BackupTheBerlios,项目名称:devqt-svn,代码行数:14,代码来源:persistentstate.cpp

示例13: find

/*!
    \reimp
 */
void TextEditFindWidget::find(const QString &ttf, bool skipCurrent, bool backward, bool *found, bool *wrapped)
{
    if (!m_textEdit)
        return;

    QTextCursor cursor = m_textEdit->textCursor();
    QTextDocument *doc = m_textEdit->document();

    if (!doc || cursor.isNull())
        return;

    if (cursor.hasSelection())
        cursor.setPosition((skipCurrent && !backward) ? cursor.position() : cursor.anchor());

    *found = true;
    QTextCursor newCursor = cursor;

    if (!ttf.isEmpty()) {
        QTextDocument::FindFlags options;

        if (backward)
            options |= QTextDocument::FindBackward;

        if (caseSensitive())
            options |= QTextDocument::FindCaseSensitively;

        if (wholeWords())
            options |= QTextDocument::FindWholeWords;

        newCursor = doc->find(ttf, cursor, options);
        if (newCursor.isNull()) {
            QTextCursor ac(doc);
            ac.movePosition(options & QTextDocument::FindBackward
                    ? QTextCursor::End : QTextCursor::Start);
            newCursor = doc->find(ttf, ac, options);
            if (newCursor.isNull()) {
                *found = false;
                newCursor = cursor;
            } else {
                *wrapped = true;
            }
        }
    }

    if (!isVisible())
        show();

    m_textEdit->setTextCursor(newCursor);
}
开发者ID:wpbest,项目名称:copperspice,代码行数:52,代码来源:texteditfindwidget.cpp

示例14: fromSelection

void BaseTextBlockSelection::fromSelection(const TabSettings &ts, const QTextCursor &selection)
{
    firstBlock = selection;
    firstBlock.setPosition(selection.selectionStart());
    firstVisualColumn = ts.columnAt(firstBlock.block().text(), firstBlock.positionInBlock());
    lastBlock = selection;
    lastBlock.setPosition(selection.selectionEnd());
    lastVisualColumn = ts.columnAt(lastBlock.block().text(), lastBlock.positionInBlock());
    if (selection.anchor() > selection.position())
        anchor = TopLeft;
    else
        anchor = BottomRight;

    firstBlock.movePosition(QTextCursor::StartOfBlock);
    lastBlock.movePosition(QTextCursor::EndOfBlock);
}
开发者ID:AChinaProgrammer,项目名称:liteide,代码行数:16,代码来源:basetextblockselection.cpp

示例15: keyReleaseEvent

void Editor::keyReleaseEvent (QKeyEvent *e)
{
    QTextCursor cur = this->textCursor();
    if(ctrlPressed) {
        ctrlPressed = false;
        cur.setPosition(cur.anchor());
        //qDebug() << "keyReleaseEvent ctrlReleased";
    }
    QPlainTextEdit::keyReleaseEvent(e);
    if(expectAutoComplete) {
#if defined(Q_OS_MAC)
        if(e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return)
            this->undo();
#endif
        expectAutoComplete = false;
    }
}
开发者ID:FeodorFitsner,项目名称:PropellerIDE,代码行数:17,代码来源:editor.cpp


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