本文整理汇总了C++中QTextDocument::lastBlock方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextDocument::lastBlock方法的具体用法?C++ QTextDocument::lastBlock怎么用?C++ QTextDocument::lastBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextDocument
的用法示例。
在下文中一共展示了QTextDocument::lastBlock方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: textEditToPlainText
QString ChatEdit::textEditToPlainText()
{
QTextDocument *doc = document();
QString result;
result.reserve(doc->characterCount());
QTextCursor begin(doc);
QTextCursor end;
QString specialChar = QChar(QChar::ObjectReplacementCharacter);
bool first = true;
while (!begin.atEnd()) {
end = doc->find(specialChar, begin, QTextDocument::FindCaseSensitively);
QString postValue;
bool atEnd = end.isNull();
if (atEnd) {
end = QTextCursor(doc);
QTextBlock block = doc->lastBlock();
end.setPosition(block.position() + block.length() - 1);
} else {
postValue = end.charFormat().toolTip();
}
begin.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor,
end.position() - begin.position() - (atEnd ? 0 : 1));
QString selectionText = begin.selection().toPlainText();
if (!first)
result += selectionText.midRef(1);
else
result += selectionText;
result += postValue;
begin = end;
end.clearSelection();
first = false;
}
return result;
}
示例2: lastBlock
QTextBlock QTextDocumentProto::lastBlock() const
{
QTextDocument *item = qscriptvalue_cast<QTextDocument*>(thisObject());
if (item)
return item->lastBlock();
return QTextBlock();
}
示例3: setCursorToTheEnd
void UBTGAdaptableText::setCursorToTheEnd()
{
QTextDocument* doc = document();
if(NULL != doc){
QTextBlock block = doc->lastBlock();
QTextCursor cursor(doc);
cursor.setPosition(block.position() + block.length() - 1);
setTextCursor(cursor);
}
}
示例4: paragraphSeparatorAboutToBeInserted
int AutoCompleter::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor,
const TabSettings &tabSettings)
{
if (!m_autoParenthesesEnabled)
return 0;
QTextDocument *doc = cursor.document();
if (doc->characterAt(cursor.position() - 1) != QLatin1Char('{'))
return 0;
if (!contextAllowsAutoParentheses(cursor))
return 0;
// verify that we indeed do have an extra opening brace in the document
QTextBlock block = cursor.block();
const QString textFromCusror = block.text().mid(cursor.positionInBlock()).trimmed();
int braceDepth = TextDocumentLayout::braceDepth(doc->lastBlock());
if (braceDepth <= 0 && (textFromCusror.isEmpty() || textFromCusror.at(0) != QLatin1Char('}')))
return 0; // braces are all balanced or worse, no need to do anything and separator inserted not between '{' and '}'
// we have an extra brace , let's see if we should close it
/* verify that the next block is not further intended compared to the current block.
This covers the following case:
if (condition) {|
statement;
*/
int indentation = tabSettings.indentationColumn(block.text());
if (block.next().isValid()) { // not the last block
block = block.next();
//skip all empty blocks
while (block.isValid() && tabSettings.onlySpace(block.text()))
block = block.next();
if (block.isValid()
&& tabSettings.indentationColumn(block.text()) > indentation)
return 0;
}
const QString &textToInsert = insertParagraphSeparator(cursor);
int pos = cursor.position();
cursor.insertBlock();
cursor.insertText(textToInsert);
cursor.setPosition(pos);
// if we actually insert a separator, allow it to be overwritten if
// user types it
if (!textToInsert.isEmpty())
m_allowSkippingOfBlockEnd = true;
return 1;
}
示例5: getFirstAndLastVisiblePosition
QPair<int, int> getFirstAndLastVisiblePosition(Editor *editor)
{
QTextCursor cursor = editor->textCursor();
QTextDocument *doc = editor->document();
int currentLine = doc->findBlock(cursor.position()).blockNumber();
int cursorHeight = editor->cursorRect().height();
int lineCountToFirstVisibleLine = editor->cursorRect().top() / cursorHeight;
int firstVisibleLineNum = currentLine - lineCountToFirstVisibleLine;
if (firstVisibleLineNum < 0) {
firstVisibleLineNum = 0;
}
int maxLineNumOnScreen = (editor->viewport()->height() / cursorHeight);
if (maxLineNumOnScreen < 1) {
maxLineNumOnScreen = 1;
}
int firstPos = doc->findBlockByNumber(firstVisibleLineNum).position();
int lastVisibleLineNum = firstVisibleLineNum + maxLineNumOnScreen - 1;
QTextBlock lastVisibleTextBlock = doc->findBlockByNumber(lastVisibleLineNum);
if (!lastVisibleTextBlock.isValid()) {
lastVisibleTextBlock = doc->lastBlock();
}
int lastPos = lastVisibleTextBlock.position() + lastVisibleTextBlock.length() - 1;
return QPair<int, int>(firstPos, lastPos);
}