本文整理汇总了C++中setTextCursor函数的典型用法代码示例。如果您正苦于以下问题:C++ setTextCursor函数的具体用法?C++ setTextCursor怎么用?C++ setTextCursor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setTextCursor函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
}
示例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);
}
示例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());
}
}
示例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 );
}
示例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);
}
示例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()));
}
}
}
}
}
示例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();
}
示例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++;
}
示例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);
}
示例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);
}
}
示例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;
}
示例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);
}
}
}
示例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;
}
}
示例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();
}