本文整理汇总了C++中QTextCursor::atEnd方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextCursor::atEnd方法的具体用法?C++ QTextCursor::atEnd怎么用?C++ QTextCursor::atEnd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextCursor
的用法示例。
在下文中一共展示了QTextCursor::atEnd方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: insertLineBeforeBracket
int OpenedFile::insertLineBeforeBracket(const int start_line, const QString &new_line)
{
QTextCursor parsingCursor = textCursor();
QString new_text = new_line;
parsingCursor.setPosition(0);
while(parsingCursor.blockNumber() != start_line)
{
parsingCursor.movePosition(QTextCursor::Down);
}
while(!parsingCursor.atEnd())
{
if(parsingCursor.block().text().contains('}'))
break;
parsingCursor.movePosition(QTextCursor::Down);
}
parsingCursor.movePosition(QTextCursor::StartOfLine);
new_text.remove(".0000", Qt::CaseInsensitive);
parsingCursor.insertText(new_text);
parsingCursor.insertText("\n");
parsingCursor.movePosition(QTextCursor::Up);
setTextCursor(parsingCursor);
return parsingCursor.blockNumber();
}
示例2: nextWord
void Widget::nextWord()
{
QTextCursor cur = m_text->textCursor();
cur.movePosition(QTextCursor::NextWord);
cur.select(QTextCursor::WordUnderCursor);
m_label->setText(cur.selectedText());
m_text->setTextCursor(cur);
if (cur.atEnd())
stopReading();
}
示例3: isAllSelected
bool TextEditEx::isAllSelected()
{
QTextCursor cur = textCursor();
if (!cur.hasSelection())
return false;
const int start = cur.selectionStart();
const int end = cur.selectionEnd();
cur.setPosition(start);
if (cur.atStart())
{
cur.setPosition(end);
return cur.atEnd();
}
else if (cur.atEnd())
{
cur.setPosition(start);
return cur.atStart();
}
return false;
}
示例4: flushText
void QSerialTerminal::flushText(QString& text, QTextCursor& cursor)
{
if(text.size() == 0)
{
return;
}
if(!cursor.atEnd())
{
cursor.clearSelection();
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, text.size());
}
cursor.insertText(text);
text.clear();
}
示例5: deleteTrailingSpaces
void Document::deleteTrailingSpaces()
{
QTextCursor cursor (textDocument());
cursor.beginEditBlock();
cursor.movePosition(QTextCursor::EndOfBlock);
QTextDocument * doc = textDocument();
while( !cursor.atEnd() ) {
while( (cursor.block().length() > 1) && doc->characterAt(cursor.position() - 1).isSpace())
cursor.deletePreviousChar();
cursor.movePosition(QTextCursor::NextBlock);
cursor.movePosition(QTextCursor::EndOfBlock);
}
cursor.endEditBlock();
}
示例6: startReading
void Widget::startReading()
{
QPalette pal;
pal.setColor(QPalette::Base, Qt::darkGray);
pal.setColor(QPalette::Text, Qt::gray);
m_text->setPalette(pal);
statusBar()->showMessage("Start reading", 1000);
QTextCursor cur = m_text->textCursor();
if (cur.atEnd())
cur.movePosition(QTextCursor::Start);
cur.select(QTextCursor::WordUnderCursor);
m_label->setText(cur.selectedText());
m_text->setTextCursor(cur);
m_timer->start();
}
示例7: findLineNumber
int OpenedFile::findLineNumber(const QString &str, const int start_line_number)
{
QTextCursor parsingCursor = textCursor();
parsingCursor.setPosition(0);
while(parsingCursor.blockNumber() != start_line_number)
{
parsingCursor.movePosition(QTextCursor::Down);
}
while(!parsingCursor.atEnd())
{
if(parsingCursor.block().text().contains(str))
return parsingCursor.blockNumber();
parsingCursor.movePosition(QTextCursor::Down);
}
return -1;
}
示例8: 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();
}
}
示例9: matchBrackets
void TikzEditor::matchBrackets()
{
// clear previous bracket highlighting
QList<QTextEdit::ExtraSelection> extraSelections;
if (!isReadOnly())
{
QTextEdit::ExtraSelection selection;
selection.cursor = textCursor();
selection.cursor.clearSelection();
extraSelections.append(selection);
}
setExtraSelections(extraSelections);
// find current matching brackets
m_matchingBegin = -1;
m_matchingEnd = -1;
if (!m_showMatchingBrackets) return;
m_plainText = toPlainText();
// QString matchText = simplifiedText(plainText);
const QString matchText = m_plainText;
const QTextCursor cursor = textCursor();
int pos = cursor.position();
if (pos == -1)
return;
else if (cursor.atEnd() || !QString("({[]})").contains(m_plainText.at(pos))) // if the cursor is not next to a bracket, then there is nothing to match, so return
{
if (pos <= 0 || !QString("({[]})").contains(m_plainText.at(--pos)))
return;
}
// get corresponding opening/closing bracket and search direction
QChar car = (!cursor.atEnd()) ? matchText.at(pos) : matchText.at(pos - 1);
QChar matchCar;
long inc = 1;
if (car == '(') matchCar = ')';
else if (car == '{') matchCar = '}';
else if (car == '[') matchCar = ']';
else
{
inc = -1;
if (car == ')') matchCar = '(';
else if (car == '}') matchCar = '{';
else if (car == ']') matchCar = '[';
else
return;
}
// find location of the corresponding bracket
m_matchingBegin = pos;
int numOfMatchCharsToSkip = 0;
do
{
if (matchText.at(pos) == car)
numOfMatchCharsToSkip++;
else if (matchText.at(pos) == matchCar)
{
numOfMatchCharsToSkip--;
if (numOfMatchCharsToSkip == 0)
{
m_matchingEnd = pos;
break;
}
}
pos += inc;
}
while (pos >= 0 && pos < matchText.length());
if (m_matchingBegin > m_matchingEnd)
qSwap(m_matchingBegin, m_matchingEnd);
// if there is a match, then show it
if (m_matchingBegin != -1)
showMatchingBrackets();
}
示例10: handleKeyPressEvent
bool CppDocumentationCommentHelper::handleKeyPressEvent(QKeyEvent *e) const
{
if (!m_settings.m_enableDoxygen && !m_settings.m_leadingAsterisks)
return false;
if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
QTextCursor cursor = m_editorWidget->textCursor();
if (!m_editorWidget->autoCompleter()->isInComment(cursor))
return false;
// We are interested on two particular cases:
// 1) The cursor is right after a /**, /*!, /// or ///! and the user pressed enter.
// If Doxygen is enabled we need to generate an entire comment block.
// 2) The cursor is already in the middle of a multi-line comment and the user pressed
// enter. If leading asterisk(s) is set we need to write a comment continuation
// with those.
if (m_settings.m_enableDoxygen && cursor.positionInBlock() >= 3) {
const int pos = cursor.position();
if (isStartOfDoxygenComment(cursor)) {
QTextDocument *textDocument = m_editorWidget->document();
DoxygenGenerator::DocumentationStyle style = doxygenStyle(cursor, textDocument);
// Check if we're already in a CppStyle Doxygen comment => continuation
// Needs special handling since CppStyle does not have start and end markers
if ((style == DoxygenGenerator::CppStyleA || style == DoxygenGenerator::CppStyleB)
&& isCppStyleContinuation(cursor)) {
return handleDoxygenCppStyleContinuation(cursor, e);
}
DoxygenGenerator doxygen;
doxygen.setStyle(style);
doxygen.setAddLeadingAsterisks(m_settings.m_leadingAsterisks);
doxygen.setGenerateBrief(m_settings.m_generateBrief);
doxygen.setStartComment(false);
// Move until we reach any possibly meaningful content.
while (textDocument->characterAt(cursor.position()).isSpace()
&& cursor.movePosition(QTextCursor::NextCharacter)) {
}
if (!cursor.atEnd()) {
const QString &comment = doxygen.generate(cursor);
if (!comment.isEmpty()) {
cursor.beginEditBlock();
cursor.setPosition(pos);
cursor.insertText(comment);
cursor.setPosition(pos - 3, QTextCursor::KeepAnchor);
m_editorWidget->textDocument()->autoIndent(cursor);
cursor.endEditBlock();
e->accept();
return true;
}
}
}
} // right after first doxygen comment
return handleDoxygenContinuation(cursor,
e,
m_editorWidget->document(),
m_settings.m_enableDoxygen,
m_settings.m_leadingAsterisks);
}
return false;
}
示例11: linkDialog
void Note::linkDialog() {
QTextCursor textCursor = m_graphicsTextItem->textCursor();
bool gotUrl = false;
if (textCursor.anchor() == textCursor.selectionStart()) {
// the selection returns empty since we're between characters
// so select one character forward or one character backward
// to see whether we're in a url
int wasAnchor = textCursor.anchor();
bool atEnd = textCursor.atEnd();
bool atStart = textCursor.atStart();
if (!atStart) {
textCursor.setPosition(wasAnchor - 1, QTextCursor::KeepAnchor);
QString html = textCursor.selection().toHtml();
if (UrlTag.indexIn(html) >= 0) {
gotUrl = true;
}
}
if (!gotUrl && !atEnd) {
textCursor.setPosition(wasAnchor + 1, QTextCursor::KeepAnchor);
QString html = textCursor.selection().toHtml();
if (UrlTag.indexIn(html) >= 0) {
gotUrl = true;
}
}
textCursor.setPosition(wasAnchor, QTextCursor::MoveAnchor);
}
else {
QString html = textCursor.selection().toHtml();
DebugDialog::debug(html);
if (UrlTag.indexIn(html) >= 0) {
gotUrl = true;
}
}
LinkDialog ld;
QString originalText;
QString originalUrl;
if (gotUrl) {
originalUrl = UrlTag.cap(1);
ld.setUrl(originalUrl);
QString html = m_graphicsTextItem->toHtml();
// assumes html is in xml form
QString errorStr;
int errorLine;
int errorColumn;
QDomDocument domDocument;
if (!domDocument.setContent(html, &errorStr, &errorLine, &errorColumn)) {
return;
}
QDomElement root = domDocument.documentElement();
if (root.isNull()) {
return;
}
if (root.tagName() != "html") {
return;
}
DebugDialog::debug(html);
QList<QDomElement> aElements;
findA(root, aElements);
foreach (QDomElement a, aElements) {
// TODO: if multiple hrefs point to the same url this will only find the first one
QString href = a.attribute("href");
if (href.isEmpty()) {
href = a.attribute("HREF");
}
if (href.compare(originalUrl) == 0) {
QString text;
if (TextUtils::findText(a, text)) {
ld.setText(text);
break;
}
else {
return;
}
}
}
}
示例12: ensureAtTheLast
void BaseEditor::ensureAtTheLast()
{
QTextCursor tc = textCursor();
if(tc.atEnd())
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
}
示例13: HighlightClosingTag
void CodeEditor::HighlightClosingTag()
{
if(textCursor().hasSelection())
return;
QTextCursor parsingTextCursor = textCursor();
QTextCursor unHighlightingTextCursor = textCursor();
QString plain_text = toPlainText();
QString opening_tag;
QStringList opened_tag_list;
int opened_quote = 0,
tag_delimiter_balance = 0,
start_parse_position = 0;
BlockData
* data;
if(!PreviousHighlightedOpeningTag.isNull())
{
unHighlightingTextCursor.setPosition(PreviousHighlightedOpeningTag.x());
unHighlightingTextCursor.setPosition(PreviousHighlightedOpeningTag.y(), QTextCursor::KeepAnchor);
unHighlightingTextCursor.block().setUserData(NULL);
//unHighlightingTextCursor.mergeCharFormat(format);
PreviousHighlightedOpeningTag.setX(0);
PreviousHighlightedOpeningTag.setY(0);
}
if(!PreviousHighlightedClosingTag.isNull())
{
unHighlightingTextCursor.setPosition(PreviousHighlightedClosingTag.x());
unHighlightingTextCursor.setPosition(PreviousHighlightedClosingTag.y(), QTextCursor::KeepAnchor);
unHighlightingTextCursor.block().setUserData(NULL);
//unHighlightingTextCursor.mergeCharFormat(format);
PreviousHighlightedClosingTag.setX(0);
PreviousHighlightedClosingTag.setY(0);
}
parsingTextCursor.movePosition(QTextCursor::StartOfWord);
parsingTextCursor.movePosition(QTextCursor::Left);
if(plain_text[parsingTextCursor.position()] != '<')
return; // not a(n opening) tag
parsingTextCursor.movePosition(QTextCursor::Right);
do
{
parsingTextCursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
} while (plain_text[parsingTextCursor.position()] != '>');
start_parse_position = parsingTextCursor.position();
opening_tag = parsingTextCursor.selectedText();
opening_tag = opening_tag.trimmed();
if(opening_tag.endsWith("/"))
return; // closing tag is the opening one
if(opening_tag.contains(' '))
{
int index_space;
index_space = opening_tag.indexOf(' ');
opening_tag.chop(opening_tag.count() - index_space);
}
parsingTextCursor.setPosition(parsingTextCursor.selectionStart());
do
{
parsingTextCursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
} while (plain_text[parsingTextCursor.position()] != '>' && plain_text[parsingTextCursor.position()] != ' ');
data = new BlockData();
data->format.setFontUnderline(true);
data->format.setFontOverline(true);
parsingTextCursor.block().setUserData(data);
PreviousHighlightedOpeningTag.setX(parsingTextCursor.selectionStart());
PreviousHighlightedOpeningTag.setY(parsingTextCursor.selectionEnd());
parsingTextCursor.setPosition(start_parse_position+1);
while(!parsingTextCursor.atEnd())
{
if( opened_quote == 0 && plain_text[parsingTextCursor.position()] == '"' && plain_text[parsingTextCursor.position()-1] != '\\')
{
opened_quote++;
}
else if(opened_quote > 0 && plain_text[parsingTextCursor.position()] == '"' && plain_text[parsingTextCursor.position()-1] != '\\')
{
opened_quote--;
}
if (opened_quote == 0)
{
if(plain_text[parsingTextCursor.position()] == '>')
{
tag_delimiter_balance--;
}
else if(plain_text[parsingTextCursor.position()] == '<')
{
tag_delimiter_balance++;
}
//.........这里部分代码省略.........
示例14: keyPressEvent
void ConsoleWidget::keyPressEvent(QKeyEvent* event)
{
switch(event->key())
{
case Qt::Key_Tab:
case Qt::Key_Backtab:
event->accept();
{
QTextCursor cursor = textCursor();
int begin = cursor.position();
int end = cursor.anchor();
if(end < begin)
{
int tmp = end;
end = begin;
begin = tmp;
}
cursor.setPosition(end);
cursor.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor);
QString line = cursor.selectedText();
std::string command(line.toAscii().constData());
std::string inputCommand = command;
console.completeConsoleCommand(command, event->key() == Qt::Key_Tab, begin == end);
if(command == inputCommand)
QApplication::beep();
else
{
QString newLine = command.c_str();
int newBegin = cursor.position();
int newEnd = newBegin + newLine.length();
cursor.insertText(newLine);
/*
int i = 0;
for(int len = std::min(line.length(), newLine.length()); i < len && line.at(i) == newLine.at(i); ++i);
newBegin += i;
*/
for(int i = command.length() - 2; i >= 0; --i)
{
char c = command[i];
if(c == ' ' || c == ':' || c == '.')
{
newBegin += i + 1;
break;
}
}
cursor.setPosition(newBegin);
cursor.setPosition(newEnd, QTextCursor::KeepAnchor);
setTextCursor(cursor);
}
}
break;
case Qt::Key_Return:
case Qt::Key_Enter:
if(event->modifiers() & (Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier))
{
QTextCursor cursor = textCursor();
cursor.insertBlock();
setTextCursor(cursor);
}
else
{
event->accept();
{
QTextCursor cursor = textCursor();
cursor.movePosition(QTextCursor::StartOfBlock);
cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
QString line = cursor.selectedText();
cursor.movePosition(QTextCursor::EndOfLine);
if(cursor.atEnd())
cursor.insertText("\n");
cursor.movePosition(QTextCursor::NextBlock);
setTextCursor(cursor);
// save output for the case that the simulator crashes
if(consoleView.loadAndSaveOutput)
{
QSettings& settings = RoboCupCtrl::application->getLayoutSettings();
settings.beginGroup(consoleView.fullName);
settings.setValue("Output", toPlainText());
settings.endGroup();
output.clear();
}
// execute the command
console.executeConsoleCommand(line.toAscii().constData());
// stores unix like history entry
history.removeAll(line);
history.append(line);
history_iter = history.end();
}
}
break;
case Qt::Key_Right:
{ // avoid jumping to the next line when the right arrow key is used to accept suggestions from tab completion
//.........这里部分代码省略.........
示例15: keyPressEvent
//.........这里部分代码省略.........
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('{')) {
block_stack++;
} else if (text[count] == QChar('}')) {
block_stack--;
}
count++;
}
}
cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor);
setTextCursor(cursor);
std::cout << block_stack << std::endl;
return;
case Qt::Key_Down:
block = cursor.block();
if ((block.blockNumber() + 1 ) == blockCount()) {
return;
} else {
position = cursor.position();
cursor.movePosition(QTextCursor::StartOfLine, QTextCursor::MoveAnchor);
cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
text = cursor.selectedText();
count = 0;