本文整理汇总了C++中QTextBlock::next方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextBlock::next方法的具体用法?C++ QTextBlock::next怎么用?C++ QTextBlock::next使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextBlock
的用法示例。
在下文中一共展示了QTextBlock::next方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getPlainText
/*!
* \brief ModelicaEditor::getPlainText
* Reads the leading spaces information from the text block user data and inserts them to the actual string.
* \return
*/
QString ModelicaEditor::getPlainText()
{
if (mpModelWidget->getLibraryTreeItem()->isInPackageOneFile()) {
QString text;
QTextBlock block = mpPlainTextEdit->document()->firstBlock();
while (block.isValid()) {
TextBlockUserData *pTextBlockUserData = BaseEditorDocumentLayout::userData(block);
if (pTextBlockUserData) {
if (pTextBlockUserData->getLeadingSpaces() == -1) {
TextBlockUserData *pFirstBlockUserData = BaseEditorDocumentLayout::userData(mpPlainTextEdit->document()->firstBlock());
if (pFirstBlockUserData) {
pTextBlockUserData->setLeadingSpaces(pFirstBlockUserData->getLeadingSpaces());
} else {
pTextBlockUserData->setLeadingSpaces(0);
}
}
text += QString(pTextBlockUserData->getLeadingSpaces(), ' ');
}
text += block.text();
block = block.next();
if (block.isValid()) { // not last block
text += "\n";
}
}
return text;
} else {
return mpPlainTextEdit->toPlainText();
}
}
示例2: showMatchingBrackets
void TikzEditor::showMatchingBrackets()
{
for (QTextBlock block = firstVisibleBlock(); block.isValid(); block = block.next())
{
if (blockBoundingGeometry(block).top() > viewport()->height())
break;
const QString text = block.text();
const int textLength = text.length();
for (int i = 0; i < textLength; ++i)
{
if (block.position() + i == m_matchingBegin || block.position() + i == m_matchingEnd)
{
QList<QTextEdit::ExtraSelection> extraSelectionList = extraSelections();
if (!isReadOnly())
{
QTextEdit::ExtraSelection selection;
selection.format.setBackground(m_matchingColor);
selection.cursor = textCursor();
selection.cursor.setPosition(block.position() + i, QTextCursor::MoveAnchor);
selection.cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
extraSelectionList.append(selection);
}
setExtraSelections(extraSelectionList);
}
}
}
}
示例3: PaintLineNumberArea
/*************************************************
// Function: PaintLineNumberArea
// Description: 绘制左侧行号区域
// Calls:
// Called By: CLineNumberArea::paintEvent
// Parameter: QPaintEvent *event
// Return: void
// Others: 通过CLineNumberArea类的paintEvent函数来调用本函数,
以保证能够实时更新该行数
*************************************************/
void CCodeEditor::PaintLineNumberArea(QPaintEvent *event)
{
QPainter painter(m_lineNumberArea);
painter.fillRect(event->rect(), Qt::lightGray); /*行数背景颜色*/
QTextBlock block = firstVisibleBlock();
int blockNumber = block.blockNumber(); /*当前行(从0开始)*/
int top = (int)blockBoundingGeometry(block).translated(contentOffset()).top() + fontMetrics().descent();/*绘制区域的顶部*/
int bottom = top + (int)blockBoundingRect(block).height(); /*绘制区域的底部*/
/*绘制可见区域*/
while (block.isValid() && top <= event->rect().bottom())
{
if (block.isVisible() && bottom >= event->rect().top())
{
QString number = QString::number(blockNumber + 1);
painter.setPen(Qt::black); /*行号颜色*/
painter.drawText(0, top, m_lineNumberArea->width(), fontMetrics().height(),
Qt::AlignCenter, number);
}
block = block.next();
top = bottom;
bottom = top + (int)blockBoundingRect(block).height();
++blockNumber;
}
}
示例4: updatePreview
void CppCodeStylePreferencesWidget::updatePreview()
{
CppCodeStylePreferences *cppCodeStylePreferences = m_preferences
? m_preferences
: CppToolsSettings::instance()->cppCodeStyle();
const CppCodeStyleSettings ccss = cppCodeStylePreferences->currentCodeStyleSettings();
const TextEditor::TabSettings ts = cppCodeStylePreferences->currentTabSettings();
QtStyleCodeFormatter formatter(ts, ccss);
foreach (TextEditor::SnippetEditorWidget *preview, m_previews) {
preview->setTabSettings(ts);
preview->setCodeStyle(cppCodeStylePreferences);
QTextDocument *doc = preview->document();
formatter.invalidateCache(doc);
QTextBlock block = doc->firstBlock();
QTextCursor tc = preview->textCursor();
tc.beginEditBlock();
while (block.isValid()) {
preview->indenter()->indentBlock(doc, block, QChar::Null, ts);
block = block.next();
}
tc.endEditBlock();
}
示例5: findNextBlockClosingParenthesis
bool TextBlockUserData::findNextBlockClosingParenthesis(QTextCursor *cursor)
{
QTextBlock block = cursor->block();
int position = cursor->position();
int ignore = 0;
while (block.isValid()) {
Parentheses parenList = BaseTextDocumentLayout::parentheses(block);
if (!parenList.isEmpty() && !BaseTextDocumentLayout::ifdefedOut(block)) {
for (int i = 0; i < parenList.count(); ++i) {
Parenthesis paren = parenList.at(i);
if (paren.chr != QLatin1Char('{') && paren.chr != QLatin1Char('}')
&& paren.chr != QLatin1Char('+') && paren.chr != QLatin1Char('-')
&& paren.chr != QLatin1Char('[') && paren.chr != QLatin1Char(']'))
continue;
if (block == cursor->block() &&
(position - block.position() > paren.pos - (paren.type == Parenthesis::Opened ? 1 : 0)))
continue;
if (paren.type == Parenthesis::Opened) {
++ignore;
} else if (ignore > 0) {
--ignore;
} else {
cursor->setPosition(block.position() + paren.pos+1);
return true;
}
}
}
block = block.next();
}
return false;
}
示例6: printWhiteSpaces
void TikzEditor::printWhiteSpaces(QPainter &painter)
{
const QFontMetrics fontMetrics = QFontMetrics(document()->defaultFont());
for (QTextBlock block = firstVisibleBlock(); block.isValid(); block = block.next())
{
if (blockBoundingGeometry(block).top() > viewport()->height())
break;
const QString text = block.text();
const int textLength = text.length();
for (int i = 0; i < textLength; ++i)
{
QTextCursor cursor = textCursor();
cursor.setPosition(block.position() + i, QTextCursor::MoveAnchor);
const QRect rect = cursorRect(cursor);
// const QFontMetrics fontMetrics = QFontMetrics(cursor.charFormat().font());
if (m_showWhiteSpaces && text.at(i) == ' ')
paintSpace(painter, rect.x() + spaceWidth() / 2.0, rect.y() + fontMetrics.height() / 2.0);
else if (m_showTabulators && text.at(i) == '\t')
paintTabstop(painter, rect.x() + spaceWidth() / 2.0, rect.y() + fontMetrics.height() / 2.0);
}
}
}
示例7: lineNumberAreaPaintEvent
//! Activated whenever LineNumberArea Widget paint event is raised.
//! Writes the line numbers for the visible blocks.
void ModelicaEditor::lineNumberAreaPaintEvent(QPaintEvent *event)
{
QPainter painter(mpLineNumberArea);
painter.fillRect(event->rect(), QColor(240, 240, 240));
QTextBlock block = firstVisibleBlock();
int blockNumber = block.blockNumber();
int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top();
int bottom = top + (int) blockBoundingRect(block).height();
while (block.isValid() && top <= event->rect().bottom())
{
if (block.isVisible() && bottom >= event->rect().top())
{
QString number = QString::number(blockNumber + 1);
// make the current highlighted line number darker
if (blockNumber == textCursor().blockNumber())
{
painter.setPen(QColor(64, 64, 64));
}
else
{
painter.setPen(Qt::gray);
}
painter.setFont(document()->defaultFont());
QFontMetrics fontMetrics (document()->defaultFont());
painter.drawText(0, top, mpLineNumberArea->width() - 5, fontMetrics.height(), Qt::AlignRight, number);
}
block = block.next();
top = bottom;
bottom = top + (int) blockBoundingRect(block).height();
++blockNumber;
}
}
示例8: updateCurrentLineHighlighting
void GenericCodeEditor::updateCurrentLineHighlighting()
{
int currentCursorBlock = textCursor().blockNumber();
int first_block_num = qMin(mLastCursorBlock, currentCursorBlock);
int second_block_num = qMax(mLastCursorBlock, currentCursorBlock);
QRegion region(0,0,0,0);
QTextBlock block = firstVisibleBlock();
int block_num = block.blockNumber();
qreal top = blockBoundingGeometry(block).translated(contentOffset()).top();
qreal max_top = viewport()->rect().bottom();
while (block.isValid() && block_num <= second_block_num && top <= max_top)
{
QRectF block_rect = blockBoundingRect(block);
if (block_num == first_block_num || block_num == second_block_num) {
region += block_rect.translated(0, top).toRect();
}
top += block_rect.height();
block = block.next();
++block_num;
}
viewport()->update( region );
}
示例9: indent
void CppQtStyleIndenter::indent(QTextDocument *doc,
const QTextCursor &cursor,
const QChar &typedChar,
const TextEditor::TabSettings &tabSettings)
{
if (cursor.hasSelection()) {
QTextBlock block = doc->findBlock(cursor.selectionStart());
const QTextBlock end = doc->findBlock(cursor.selectionEnd()).next();
CppTools::QtStyleCodeFormatter codeFormatter(tabSettings, codeStyleSettings());
codeFormatter.updateStateUntil(block);
QTextCursor tc = cursor;
tc.beginEditBlock();
do {
int indent;
int padding;
codeFormatter.indentFor(block, &indent, &padding);
tabSettings.indentLine(block, indent + padding, padding);
codeFormatter.updateLineStateChange(block);
block = block.next();
} while (block.isValid() && block != end);
tc.endEditBlock();
} else {
indentBlock(doc, cursor.block(), typedChar, tabSettings);
}
}
示例10: reformatBlocks
void DevHighlighter::reformatBlocks(int from, int charsRemoved, int charsAdded)
{
QTextBlock block = doc->findBlock(from);
if (!block.isValid())
return;
QTextBlock endBlock;
if (charsAdded > charsRemoved || charsAdded == charsRemoved)
endBlock = doc->findBlock(from + charsAdded);
else
endBlock = block;
bool forceHighlightOfNextBlock = false;
while (block.isValid() && (!(endBlock < block) || forceHighlightOfNextBlock) )
{
const int stateBeforeHighlight = block.userState();
reformatBlock(block);
forceHighlightOfNextBlock = (block.userState() != stateBeforeHighlight);
block = block.next();
}
formatChanges.clear();
}
示例11: findAll
int GenericCodeEditor::findAll( const QRegExp &expr, QTextDocument::FindFlags options )
{
mSearchSelections.clear();
if(expr.isEmpty()) {
this->updateExtraSelections();
return 0;
}
QTextEdit::ExtraSelection selection;
selection.format = mSearchResultTextFormat;
QTextDocument *doc = QPlainTextEdit::document();
QTextBlock block = doc->begin();
QTextCursor cursor;
while (block.isValid()) {
int blockPos = block.position();
int offset = 0;
while(findInBlock(doc, block, expr, offset, options, cursor)) {
offset = cursor.selectionEnd() - blockPos;
if (cursor.hasSelection()) {
selection.cursor = cursor;
mSearchSelections.append(selection);
} else
offset += 1;
}
block = block.next();
}
this->updateExtraSelections();
return mSearchSelections.count();
}
示例12: updateFormatting
void CodeHighlighter::updateFormatting(QTextDocument* _document, CodeHighlighterSettings const& _settings)
{
QTextBlock block = _document->firstBlock();
QList<QTextLayout::FormatRange> ranges;
Formats::const_iterator format = m_formats.begin();
while (true)
{
while ((format == m_formats.end() || (block.position() + block.length() <= format->start)) && block.isValid())
{
auto layout = block.layout();
layout->clearAdditionalFormats();
layout->setAdditionalFormats(ranges);
_document->markContentsDirty(block.position(), block.length());
block = block.next();
ranges.clear();
}
if (!block.isValid())
break;
int intersectionStart = std::max(format->start, block.position());
int intersectionLength = std::min(format->start + format->length, block.position() + block.length()) - intersectionStart;
if (intersectionLength > 0)
{
QTextLayout::FormatRange range;
range.format = _settings.formats[format->token];
range.start = format->start - block.position();
range.length = format->length;
ranges.append(range);
}
++format;
}
}
示例13: lineNumberAreaPaintEvent
void TextEditor::lineNumberAreaPaintEvent(QPaintEvent *event)
{
QPainter painter(lineNumberArea);
// painter.fillRect(event->rect(), Qt::black);
QTextBlock block = firstVisibleBlock();
int blockNumber = block.blockNumber();
int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top();
int bottom = top + (int) blockBoundingRect(block).height();
while (block.isValid() && top <= event->rect().bottom()) {
if (block.isVisible() && bottom >= event->rect().top()) {
QString number = QString::number(blockNumber + 1);
painter.setPen(Qt::darkGray);
painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(),
Qt::AlignRight, number);
}
block = block.next();
top = bottom;
bottom = top + (int) blockBoundingRect(block).height();
++blockNumber;
}
}
示例14: findClosingMatch
static int findClosingMatch(const QTextDocument *doc, int cursorPosition)
{
QTextBlock block = doc->findBlock(cursorPosition);
JSBlockData *blockData = reinterpret_cast<JSBlockData*>(block.userData());
if (!blockData->bracketPositions.isEmpty()) {
int depth = 1;
while (block.isValid()) {
blockData = reinterpret_cast<JSBlockData*>(block.userData());
if (blockData && !blockData->bracketPositions.isEmpty()) {
for (int c = 0; c < blockData->bracketPositions.count(); ++c) {
int absPos = block.position() + blockData->bracketPositions.at(c);
if (absPos <= cursorPosition)
continue;
if (doc->characterAt(absPos) == '{')
depth++;
else
depth--;
if (depth == 0)
return absPos;
}
}
block = block.next();
}
}
return -1;
}
示例15: spatiumChanged
void Text::spatiumChanged(qreal oldVal, qreal newVal)
{
Element::spatiumChanged(oldVal, newVal);
if (!sizeIsSpatiumDependent() || styled())
return;
qreal v = newVal / oldVal;
QTextCursor c(_doc);
QTextBlock cb = _doc->begin();
while (cb.isValid()) {
QTextBlock::iterator i(cb.begin());
for (; !i.atEnd(); ++i) {
QTextFragment f = i.fragment();
if (f.isValid()) {
int pos = f.position();
int len = f.length();
c.setPosition(pos, QTextCursor::MoveAnchor);
c.setPosition(pos + len, QTextCursor::KeepAnchor);
QTextCharFormat cf = c.charFormat();
QFont font = cf.font();
font.setPointSizeF(font.pointSizeF() * v);
cf.setFont(font);
c.setCharFormat(cf);
}
}
cb = cb.next();
}
}