本文整理汇总了C++中QTextCursor::movePosition方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextCursor::movePosition方法的具体用法?C++ QTextCursor::movePosition怎么用?C++ QTextCursor::movePosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextCursor
的用法示例。
在下文中一共展示了QTextCursor::movePosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Assert
void
VBoxDbgConsoleOutput::appendText(const QString &rStr, bool fClearSelection)
{
Assert(m_hGUIThread == RTThreadNativeSelf());
if (rStr.isEmpty() || rStr.isNull() || !rStr.length())
return;
/*
* Insert all in one go and make sure it's visible.
*
* We need to move the cursor and unselect any selected text before
* inserting anything, otherwise, text will disappear.
*/
QTextCursor Cursor = textCursor();
if (!fClearSelection && Cursor.hasSelection())
{
QTextCursor SavedCursor = Cursor;
Cursor.clearSelection();
Cursor.movePosition(QTextCursor::End);
Cursor.insertText(rStr);
setTextCursor(SavedCursor);
}
else
{
if (Cursor.hasSelection())
Cursor.clearSelection();
if (!Cursor.atEnd())
Cursor.movePosition(QTextCursor::End);
Cursor.insertText(rStr);
setTextCursor(Cursor);
ensureCursorVisible();
}
}
示例2: if
ParenMatching::ParenMatching(QTextCursor c)
: onOpen(false)
{
int save_p = c.position();
QChar p = cc(c), q;
QTextCursor::MoveOperation d = c.NoMove;
if (p == '(') q = ')', d = c.Right, onOpen = true;
if (p == '[') q = ']', d = c.Right, onOpen = true;
if (p == '{') q = '}', d = c.Right, onOpen = true;
if (d == c.NoMove && c.movePosition(c.Left)) {
p = cc(c);
if (p == ')') q = '(', d = c.Left;
if (p == ']') q = '[', d = c.Left;
if (p == '}') q = '{', d = c.Left;
}
if (d != c.NoMove) {
int n = 0;
while (c.movePosition(d)) {
QChar z = cc(c);
if (z == q) {
if (n-- == 0) {
if (onOpen)
positions = range(save_p, c.position());
else
positions = range(c.position(), save_p - 1);
break;
}
}
else if (z == p)
++n;
}
}
c.setPosition(save_p);
}
示例3: duplicate_line
/**
* Duplicates the current line and inserts the copy below the line
*/
void HaiQTextEdit::duplicate_line() {
QTextCursor cursor = textCursor();
int pos(cursor.position());
cursor.beginEditBlock();
cursor.clearSelection();
cursor.movePosition(QTextCursor::EndOfLine);
cursor.select(QTextCursor::LineUnderCursor);
QTextDocumentFragment text( cursor.selection() );
cursor.clearSelection();
cursor.insertText( QString(QChar::LineSeparator) );
cursor.insertFragment( text );
cursor.setPosition(pos);
cursor.endEditBlock();
}
示例4: AppendFile
int CDlgAbout::AppendFile(QTextEdit* pEdit, const QString &szFile)
{
QFile readme(szFile);
if(readme.open(QFile::ReadOnly))
{
pEdit->append(readme.readAll());
//把光标移动文档开始处
QTextCursor cursor = pEdit->textCursor();
cursor.movePosition(QTextCursor::Start);
pEdit->setTextCursor(cursor);
readme.close();
}
return 0;
}
示例5: delete_current_line
/**
* Deletes the current line
*/
void HaiQTextEdit::delete_current_line() {
QTextCursor cursor = textCursor();
cursor.beginEditBlock();
cursor.clearSelection();
cursor.movePosition(QTextCursor::StartOfLine);
int pos(cursor.position());
cursor.select(QTextCursor::LineUnderCursor);
// remove line (and line feed char)
cursor.removeSelectedText();
cursor.deleteChar();
// goto start of next line
cursor.setPosition(pos);
cursor.endEditBlock();
}
示例6: replaceAll
void FindDialog::replaceAll()
{
QString text = m_find_string->text();
if (text.isEmpty()) {
return;
}
QTextDocument::FindFlags flags;
if (!m_ignore_case->isChecked()) {
flags |= QTextDocument::FindCaseSensitively;
}
if (m_whole_words->isChecked()) {
flags |= QTextDocument::FindWholeWords;
}
// Count instances
int found = 0;
QTextEdit* document = m_documents->currentDocument()->text();
QTextCursor cursor = document->textCursor();
cursor.movePosition(QTextCursor::Start);
forever {
cursor = document->document()->find(text, cursor, flags);
if (!cursor.isNull()) {
found++;
} else {
break;
}
}
if (found) {
if (QMessageBox::question(this, tr("Question"), tr("Replace %n instance(s)?", "", found), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) {
return;
}
} else {
QMessageBox::information(this, tr("Sorry"), tr("Phrase not found."));
return;
}
// Replace instances
QTextCursor start_cursor = document->textCursor();
forever {
cursor = document->document()->find(text, cursor, flags);
if (!cursor.isNull()) {
cursor.insertText(m_replace_string->text());
document->setTextCursor(cursor);
} else {
break;
}
}
document->setTextCursor(start_cursor);
}
示例7: hasOnlyBlanksBeforeCursorInLine
static bool hasOnlyBlanksBeforeCursorInLine(QTextCursor textCursor)
{
textCursor.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor);
const auto textBeforeCursor = textCursor.selectedText();
const auto nonSpace = std::find_if(textBeforeCursor.cbegin(),
textBeforeCursor.cend(),
[] (const QChar &signBeforeCursor) {
return !signBeforeCursor.isSpace();
});
return nonSpace == textBeforeCursor.cend();
}
示例8: mouseMoveEvent
void MarginWidget::mouseMoveEvent(QMouseEvent *event)
{
QTextCursor textCursor = m_sourceViewer->cursorForPosition(QPoint(1, event->y()));
int currentLine = textCursor.blockNumber();
if (currentLine == m_lastClickedLine)
{
return;
}
textCursor.movePosition(((currentLine > m_lastClickedLine) ? QTextCursor::Up : QTextCursor::Down), QTextCursor::KeepAnchor, qAbs(m_lastClickedLine - currentLine));
m_sourceViewer->setTextCursor(textCursor);
}
示例9: doControlSeq
void QTerminal::doControlSeq(const QByteArray & seq) {
switch (seq.right(1).at(0)) {
case '@':
this->insertPlainText(QString().fill(' ', seq.left(seq.length() - 1).toInt()));
break;
case 'C':
for (int i = 0; i < seq.left(seq.length() - 1).toInt(); ++i) {
if (this->textCursor().atEnd()) {
this->insertPlainText(" ");
} else {
this->moveCursor(QTextCursor::Right, QTextCursor::MoveAnchor);
}
}
break;
case 'D':
{
QTextCursor cursor = this->textCursor();
cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor,
seq.left(seq.length() - 1).toInt());
}
break;
case 'J':
eraseDisplay(seq.left(seq.length() - 1).toInt());
/* Perl would parse the number at the beginning of the string :-P */
break;
case 'K':
eraseInLine(seq.left(seq.length() - 1).toInt());
break;
case 'P':
deleteChars(seq.left(seq.length() - 1).toInt());
break;
case 'h':
if (seq.left(seq.length() -1).toInt() == 4) {
insertMode = true;
} else {
qDebug("No Can Do ESC [ %s", seq.constData());
}
break;
case 'l':
if (seq.left(seq.length() -1).toInt() == 4) {
insertMode = false;
} else {
qDebug("No Can Do ESC [ %s", seq.constData());
}
break;
default:
qDebug("No Can Do ESC [ %s", seq.constData());
break;
}
}
示例10: textAt
QString textAt(QTextCursor tc, int pos, int length)
{
if (pos < 0)
pos = 0;
tc.movePosition(QTextCursor::End);
if (pos + length > tc.position())
length = tc.position() - pos;
tc.setPosition(pos);
tc.setPosition(pos + length, QTextCursor::KeepAnchor);
// selectedText() returns U+2029 (PARAGRAPH SEPARATOR) instead of newline
return tc.selectedText().replace(QChar::ParagraphSeparator, QLatin1Char('\n'));
}
示例11: updateFromResult
ResultItem* TextResultItem::updateFromResult(Cantor::Result* result)
{
switch(result->type()) {
case Cantor::TextResult::Type:
{
QTextCursor cursor = textCursor();
cursor.movePosition(QTextCursor::Start);
cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
QString html = result->toHtml();
if (html.isEmpty())
cursor.removeSelectedText();
else
cursor.insertHtml(html);
return this;
}
case Cantor::LatexResult::Type:
setLatex(dynamic_cast<Cantor::LatexResult*>(result));
return this;
default:
deleteLater();
return create(parentEntry(), result);
}
}
示例12: insertCompletion
void MimeTextEdit::insertCompletion(const QString& completion)
{
if (mCompleter->widget() != this)
return;
QTextCursor tc = textCursor();
if (mCompleter->completionPrefix().length() > 0) {
tc.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor);
}
tc.removeSelectedText();
tc.insertText(mCompleterStartString+completion);
mCompleterStartString.clear();
setTextCursor(tc);
}
示例13: evaluateRegion
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 );
}
示例14: highlightMatches
void highlightMatches(const QString &pattern)
{
QTextEdit *ed = qobject_cast<QTextEdit *>(m_widget);
if (!ed)
return;
// Clear previous highlights.
ed->selectAll();
QTextCursor cur = ed->textCursor();
QTextCharFormat fmt = cur.charFormat();
fmt.setBackground(Qt::transparent);
cur.setCharFormat(fmt);
// Highlight matches.
QTextDocument *doc = ed->document();
QRegExp re(pattern);
cur = doc->find(re);
int a = cur.position();
while ( !cur.isNull() ) {
if ( cur.hasSelection() ) {
fmt.setBackground(Qt::yellow);
cur.setCharFormat(fmt);
} else {
cur.movePosition(QTextCursor::NextCharacter);
}
cur = doc->find(re, cur);
int b = cur.position();
if (a == b) {
cur.movePosition(QTextCursor::NextCharacter);
cur = doc->find(re, cur);
b = cur.position();
if (a == b) break;
}
a = b;
}
}
示例15: highlight
void ItemSync::highlight(const QRegExp &re, const QFont &highlightFont, const QPalette &highlightPalette)
{
ItemWidgetWrapper::highlight(re, highlightFont, highlightPalette);
QList<QTextEdit::ExtraSelection> selections;
if ( !re.isEmpty() ) {
QTextEdit::ExtraSelection selection;
selection.format.setBackground( highlightPalette.base() );
selection.format.setForeground( highlightPalette.text() );
selection.format.setFont(highlightFont);
QTextCursor cur = m_label->document()->find(re);
int a = cur.position();
while ( !cur.isNull() ) {
if ( cur.hasSelection() ) {
selection.cursor = cur;
selections.append(selection);
} else {
cur.movePosition(QTextCursor::NextCharacter);
}
cur = m_label->document()->find(re, cur);
int b = cur.position();
if (a == b) {
cur.movePosition(QTextCursor::NextCharacter);
cur = m_label->document()->find(re, cur);
b = cur.position();
if (a == b) break;
}
a = b;
}
}
m_label->setExtraSelections(selections);
update();
}