本文整理汇总了C++中QTextBlock::blockNumber方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextBlock::blockNumber方法的具体用法?C++ QTextBlock::blockNumber怎么用?C++ QTextBlock::blockNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextBlock
的用法示例。
在下文中一共展示了QTextBlock::blockNumber方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateSidebar
void NCEdit::updateSidebar() {
if (!showLineNumbers && !codeFolding) {
sidebar->hide();
setViewportMargins(0, 0, 0, 0);
sidebar->setGeometry(3, 0, 0, height());
return;
}
sidebar->foldIndicatorWidth = 0;
sidebar->font = this->font();
sidebar->show();
int sw = 0;
if (showLineNumbers) {
int digits = 2;
int maxLines = blockCount();
for (int number = 10; number < maxLines; number *= 10)
++digits;
sw += fontMetrics().width('w') * digits;
}
if (codeFolding) {
int fh = fontMetrics().lineSpacing();
int fw = fontMetrics().width('w');
sidebar->foldIndicatorWidth = qMax(fw, fh);
sw += sidebar->foldIndicatorWidth;
}
setViewportMargins(sw, 0, 0, 0);
sidebar->setGeometry(0, 0, sw, height());
QRectF sidebarRect(0, 0, sw, height());
QTextBlock block = firstVisibleBlock();
int index = 0;
while (block.isValid()) {
if (block.isVisible()) {
QRectF rect = blockBoundingGeometry(block).translated(contentOffset());
if (sidebarRect.intersects(rect)) {
if (sidebar->lineNumbers.count() >= index)
sidebar->lineNumbers.resize(index + 1);
sidebar->lineNumbers[index].position = rect.top();
sidebar->lineNumbers[index].number = block.blockNumber() + 1;
sidebar->lineNumbers[index].foldable =
codeFolding ? isFoldable(block.blockNumber() + 1) : false;
sidebar->lineNumbers[index].folded =
codeFolding ? isFolded(block.blockNumber() + 1) : false;
index++;
}
if (rect.top() > sidebarRect.bottom()) break;
}
block = block.next();
}
sidebar->lineNumbers.resize(index);
sidebar->update();
}
示例2: lineNumberAreaPaintEvent
void ScriptEditBox::lineNumberAreaPaintEvent(QPaintEvent* event)
{
QPainter painter(_scriptLineNumberArea);
painter.fillRect(event->rect(), Qt::lightGray);
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()) {
QFont font = painter.font();
font.setBold(this->textCursor().blockNumber() == block.blockNumber());
painter.setFont(font);
QString number = QString::number(blockNumber + 1);
painter.setPen(Qt::black);
painter.drawText(0, top, _scriptLineNumberArea->width(), fontMetrics().height(),
Qt::AlignRight, number);
}
block = block.next();
top = bottom;
bottom = top + (int) blockBoundingRect(block).height();
blockNumber++;
}
}
示例3: findBraceLeft
int SoTextEdit::findBraceLeft(void)
{
QTextCursor cursor = textCursor();
QTextBlock block = cursor.block();
int brace_count = 0, i, blockNumber = block.blockNumber();
QString text;
while (blockNumber != UNVALID_BLOCK) {
text = block.text();
i = text.size();
for (; 0 <= i; i--) {
if (text[i] == QChar('}')) {
brace_count++;
} else if (text[i] == QChar('{')) {
brace_count--;
if (brace_count == 0) {
// cursor.deletePreviousChar();
// cursor.insertText("}", colorFormat(Qt::darkCyan));
cursor.setPosition((block.position()) + i);
// cursor.deleteChar();
// cursor.insertText("{", colorFormat(Qt::darkCyan));
return (block.position() + i);
}
}
}
block = block.previous();
blockNumber = block.blockNumber();
}
return -1;
}
示例4: paintEvent
void MarginWidget::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.fillRect(event->rect(), Qt::transparent);
QTextBlock block = m_sourceViewer->firstVisibleBlock();
int top = m_sourceViewer->blockBoundingGeometry(block).translated(m_sourceViewer->contentOffset()).top();
int bottom = (top + m_sourceViewer->blockBoundingRect(block).height());
const int right = (width() - 5);
const int selectionStart = m_sourceViewer->document()->findBlock(m_sourceViewer->textCursor().selectionStart()).blockNumber();
const int selectionEnd = m_sourceViewer->document()->findBlock(m_sourceViewer->textCursor().selectionEnd()).blockNumber();
while (block.isValid() && top <= event->rect().bottom())
{
if (block.isVisible() && bottom >= event->rect().top())
{
QColor textColor(palette().color(QPalette::Text));
textColor.setAlpha((block.blockNumber() >= selectionStart && block.blockNumber() <= selectionEnd) ? 250 : 150);
painter.setPen(textColor);
painter.drawText(0, top, right, fontMetrics().height(), Qt::AlignRight, QString::number(block.blockNumber() + 1));
}
block = block.next();
top = bottom;
bottom = (top + m_sourceViewer->blockBoundingRect(block).height());
}
}
示例5: blockModified
void AeHighlighter::blockModified(QTextBlock block, unsigned column, unsigned added, unsigned removed) {
// We have to lock the mutex since a background thread may be
// attempting to update the StyleVector pointer
mutex_.lock();
for(int i = 0, N = styles_->value(block.blockNumber()).size(); i != N; ++i) {
AeCodeDecoration& ts = (*styles_)[block.blockNumber()][i];
AeCodeDecoration::Extents extents = ts.extents();
// if the highlight begins after our cursor position, advance
// or subtract it by the amount of characters changed
if(extents.start >= column)
extents.start += added - removed;
// if the highlight ends before our cursor position,
// leave it unchanged
else if(extents.start + extents.length <= column)
{}
// otherwise, we're in the middle of it. extend it. The normal
// highlighting algorithm will correct this later.
else
extents.length += added - removed;
ts.move(extents);
}
mutex_.unlock();
// We've changed the colours so have to rehighlight this line
rehighlightBlock(block);
}
示例6: lineNumberAreaPaintEvent
void BaseEditor::lineNumberAreaPaintEvent(QPaintEvent *event)
{
QPainter painter(lineNumberArea);
painter.fillRect(event->rect(), QColor::fromRgb(0xEA,0xEA,0xEA));
painter.setFont(document()->defaultFont());
QTextBlock block = firstVisibleBlock();
int blockNumber = block.blockNumber();
int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top();
int bottom = top + (int) blockBoundingRect(block).height();
int height = QFontMetrics(document()->defaultFont()).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, lineNumberArea->width(), height,
Qt::AlignRight, number);
}
block = block.next();
top = bottom;
bottom = top + (int) blockBoundingRect(block).height();
++blockNumber;
}
}
示例7: lineNumberAreaPaintEvent
void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event)
{
QPainter painter(lineNumberArea);
painter.fillRect(event->rect(), QWidget::palette().color(QWidget::backgroundRole()).darker(50));
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(QWidget::palette().color(QWidget::foregroundRole()).darker(50));
painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(),
Qt::AlignRight, number);
}
block = block.next();
top = bottom;
bottom = top + (int) blockBoundingRect(block).height();
++blockNumber;
}
}
示例8: 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;
}
}
示例9: paintBlock
void SelectableTextEditorWidget::paintBlock(QPainter *painter,
const QTextBlock &block,
const QPointF &offset,
const QVector<QTextLayout::FormatRange> &selections,
const QRect &clipRect) const
{
const int blockNumber = block.blockNumber();
QList<DiffSelection> diffs = m_diffSelections.value(blockNumber);
QVector<QTextLayout::FormatRange> newSelections;
for (const DiffSelection &diffSelection : diffs) {
if (diffSelection.format) {
QTextLayout::FormatRange formatRange;
formatRange.start = qMax(0, diffSelection.start);
const int end = diffSelection.end < 0
? block.text().count() + 1
: qMin(block.text().count(), diffSelection.end);
formatRange.length = end - formatRange.start;
formatRange.format = *diffSelection.format;
if (diffSelection.end < 0)
formatRange.format.setProperty(QTextFormat::FullWidthSelection, true);
newSelections.append(formatRange);
}
}
newSelections += selections;
TextEditorWidget::paintBlock(painter, block, offset, newSelections, clipRect);
}
示例10: lineNumberAreaPaintEvent
void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event) {
QPainter painter( lineNumberArea ) ;
painter.fillRect( event->rect(), QColor( Qt::lightGray ).lighter( 120 ) ) ;
QTextBlock block = firstVisibleBlock() ;
QTextCursor cursor = textCursor() ;
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 ) ;
if ( block == cursor.block() )
painter.setPen( QColor( Qt::black ) ) ;
else
painter.setPen( Qt::gray ) ;
painter.drawText(
0, top, lineNumberArea->width(), fontMetrics().height(),
Qt::AlignHCenter, number
) ;
}
block = block.next() ;
top = bottom ;
bottom = top + (int)blockBoundingRect( block ).height() ;
blockNumber += 1 ;
}
}
示例11: lineNumberAreaPaintEvent
void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event)
{
QPainter painter(lineNumberArea);
painter.fillRect(event->rect(), Qt::lightGray);
//![extraAreaPaintEvent_0]
//![extraAreaPaintEvent_1]
QTextBlock block = firstVisibleBlock();
int blockNumber = block.blockNumber();
int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top();
int bottom = top + (int) blockBoundingRect(block).height();
//![extraAreaPaintEvent_1]
//![extraAreaPaintEvent_2]
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, lineNumberArea->width(), fontMetrics().height(),
Qt::AlignRight, number);
}
block = block.next();
top = bottom;
bottom = top + (int) blockBoundingRect(block).height();
++blockNumber;
}
}
示例12: lineNumberAreaPaintEvent
void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event)
{
QPainter painter(lineNumberArea);
QColor q = QColor();
q.setNamedColor("#323232");
QColor q2 = QColor();
q2.setNamedColor("#247EAF");
painter.fillRect(event->rect(), q);
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(q2);
painter.drawText(0, top, lineNumberArea->width()-5 , fontMetrics().height(),
Qt::AlignRight, number);
}
block = block.next();
top = bottom;
bottom = top + (int) blockBoundingRect(block).height();
++blockNumber;
}
}
示例13: 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 );
}
示例14: lineNumberAreaPaintEvent
//-------------------------------------------------------------------------
void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event)
{
QPainter painter(lineNumberArea);
painter.setPen(Qt::gray);
QFont lineFont = document()->defaultFont();
lineFont.setPointSize( lineFont.pointSize()*2/3 );
painter.setFont( lineFont );
QTextBlock block = firstVisibleBlock();
int blockNumber = block.blockNumber();
int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top() + fontMetrics().leading();
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.drawText(0, top, lineNumberArea->width(), fontMetrics().height(),
Qt::AlignRight | Qt::AlignBottom, number);
}
block = block.next();
top = bottom;
bottom = top + (int) blockBoundingRect(block).height();
++blockNumber;
}
}
示例15: lineNumberAreaPaintEvent
void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event)
{
QPainter painter(lineNumberArea);
painter.fillRect(event->rect(), QColor(Qt::gray).lighter(140));
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())
{
int rowId = blockNumber + 1;
QString number = QString::number(rowId);
if (errorLines.indexOf(rowId)!=-1) {
painter.setPen(Qt::red);
} else if (warningLines.indexOf(rowId)!=-1) {
painter.setPen(Qt::yellow);
} else {
painter.setPen(Qt::gray);
}
painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(), Qt::AlignRight, number);
}
block = block.next();
top = bottom;
bottom = top + (int) blockBoundingRect(block).height();
++blockNumber;
}
}