本文整理汇总了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();
}
}
示例2: assignCommentOffset
void DoxygenGenerator::assignCommentOffset(QTextCursor cursor)
{
if (cursor.hasSelection()) {
if (cursor.anchor() < cursor.position())
cursor.setPosition(cursor.anchor());
}
m_commentOffset = cursor.positionInBlock();
}
示例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;
}
示例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);
}
示例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); }
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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;
}
}