//! 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; } }
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; } }
/************************************************* // 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; } }
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; } }
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; } }
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 ); }
void GenericCodeEditor::paintEvent( QPaintEvent *event ) { if (mHighlightCurrentLine) { int cursor_block_num = textCursor().blockNumber(); QTextBlock block = firstVisibleBlock(); int block_num = block.blockNumber(); qreal top = blockBoundingGeometry(block).translated(contentOffset()).top(); qreal max_top = event->rect().bottom(); while (block.isValid() && block_num <= cursor_block_num && top <= max_top) { QRectF block_rect = blockBoundingRect(block); if (block_num == cursor_block_num) { QPainter painter(viewport()); painter.fillRect( block_rect.translated(0, top), mCurrentLineTextFormat.background().color() ); painter.end(); break; } top += block_rect.height(); block = block.next(); ++block_num; } } QPlainTextEdit::paintEvent(event); }
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; } }
void TextEdit::gutterPaintEvent(QPaintEvent *event) { QPainter painter(gutter); painter.fillRect(event->rect(), QColor(0xee, 0xee, 0xee)); QTextBlock block = firstVisibleBlock(); int blockNumber = block.blockNumber(); int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top(); int bottom = top + (int) blockBoundingRect(block).height(); int digiW = fontMetrics().width(QLatin1Char('9')); while (block.isValid() && top <= event->rect().bottom()) { if (block.isVisible() && bottom >= event->rect().top()) { QString number = QString::number(blockNumber + 1); painter.setPen(QColor(0x88, 0x88, 0x88)); painter.drawText(0, top, gutter->width() - digiW / 2, fontMetrics().height(), Qt::AlignRight, number); } block = block.next(); top = bottom; bottom = top + (int) blockBoundingRect(block).height(); ++blockNumber; } }
void CodeEditorWidget::paintLines( LinesWidget* linesWidget, QPaintEvent* event ) { QPainter painter( linesWidget ); painter.fillRect( event->rect(), Qt::lightGray ); //The lineNumberAreaPaintEvent() is called from LineNumberArea whenever it receives a paint event. We start off by painting the widget's background. QTextBlock block = firstVisibleBlock(); int blockNumber = block.blockNumber(); int top = (int)blockBoundingGeometry(block).translated( contentOffset() ).top(); int bottom = top + (int)blockBoundingRect( block ).height(); // We will now loop through all visible lines and paint the line numbers in the extra area for each line. // Notice that in a plain text edit each line will consist of one QTextBlock; though, if line wrapping is enabled, a line may span several rows in the text edit's viewport. // We get the top and bottom y-coordinate of the first text block, and adjust these values by the height of the current text block in each iteration in the loop. 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, linesWidget->width(), fontMetrics().height(), Qt::AlignRight, number ); } block = block.next(); top = bottom; bottom = top + (int)blockBoundingRect( block ).height(); ++blockNumber; } }
void ScriptView::paintLineNumberArea(QPaintEvent* pevent) { QPainter painter(mpLineNumberArea); 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 <= pevent->rect().bottom() ) { if ( block.isVisible() && bottom >= pevent->rect().top()) { QString number = QString::number(blocknumber + 1); painter.setPen(Qt::darkGray); painter.drawText(0, top, mpLineNumberArea->width(), fontMetrics().height(), Qt::AlignRight, number); } block = block.next(); top = bottom; bottom = top + (int) + blockBoundingRect(block).height(); ++blocknumber; } }
//------------------------------------------------------------------------- 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; } }
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++; } }
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; } }
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 ; } }
void GenericCodeEditor::paintLineIndicator( QPaintEvent *e ) { QPalette plt( mLineIndicator->palette() ); QRect r( e->rect() ); QPainter p( mLineIndicator ); p.fillRect( r, plt.color( QPalette::Mid ) ); p.setPen( plt.color(QPalette::Dark) ); p.drawLine( r.topRight(), r.bottomRight() ); p.setPen( plt.color(QPalette::ButtonText) ); QTextDocument *doc = QPlainTextEdit::document(); QTextCursor cursor(textCursor()); int selStartBlock, selEndBlock; if (cursor.hasSelection()) { selStartBlock = doc->findBlock(cursor.selectionStart()).blockNumber(); selEndBlock = doc->findBlock(cursor.selectionEnd()).blockNumber(); } else selStartBlock = selEndBlock = -1; QTextBlock block = firstVisibleBlock(); int blockNumber = block.blockNumber(); qreal top = blockBoundingGeometry(block).translated(contentOffset()).top(); qreal bottom = top + blockBoundingRect(block).height(); while (block.isValid() && top <= e->rect().bottom()) { if (block.isVisible() && bottom >= e->rect().top()) { p.save(); QRectF numRect( 0, top, mLineIndicator->width() - 1, bottom - top ); int num = blockNumber; if (num >= selStartBlock && num <= selEndBlock) { num -= selStartBlock; p.setPen(Qt::NoPen); p.setBrush(plt.color(QPalette::Highlight)); p.drawRect(numRect); p.setPen(plt.color(QPalette::HighlightedText)); } QString number = QString::number(num + 1); p.drawText(0, top, mLineIndicator->width() - 4, bottom - top, Qt::AlignRight, number); p.restore(); } block = block.next(); top = bottom; bottom = top + blockBoundingRect(block).height(); ++blockNumber; } }
void CSVWorld::ScriptEdit::lineNumberAreaPaintEvent(QPaintEvent *event) { QPainter painter(mLineNumberArea); QTextBlock block = firstVisibleBlock(); int blockNumber = block.blockNumber(); int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top(); int bottom = top + (int) blockBoundingRect(block).height(); int startBlock = textCursor().blockNumber(); int endBlock = textCursor().blockNumber(); if(textCursor().hasSelection()) { QString str = textCursor().selection().toPlainText(); int selectedLines = str.count("\n")+1; if(textCursor().position() < textCursor().anchor()) endBlock += selectedLines; else startBlock -= selectedLines; } painter.setBackgroundMode(Qt::OpaqueMode); QFont font = painter.font(); QBrush background = painter.background(); while (block.isValid() && top <= event->rect().bottom()) { if (block.isVisible() && bottom >= event->rect().top()) { QFont newFont = painter.font(); QString number = QString::number(blockNumber + 1); if(blockNumber >= startBlock && blockNumber <= endBlock) { painter.setBackground(Qt::cyan); painter.setPen(Qt::darkMagenta); newFont.setBold(true); } else { painter.setBackground(background); painter.setPen(Qt::black); } painter.setFont(newFont); painter.drawText(0, top, mLineNumberArea->width(), fontMetrics().height(), Qt::AlignRight, number); painter.setFont(font); } block = block.next(); top = bottom; bottom = top + (int) blockBoundingRect(block).height(); ++blockNumber; } }
FloatSize TopControls::scrollBy(FloatSize pendingDelta) { if ((m_permittedState == WebTopControlsShown && pendingDelta.height() < 0) || (m_permittedState == WebTopControlsHidden && pendingDelta.height() > 0)) return pendingDelta; if (m_height == 0) return pendingDelta; float oldOffset = contentOffset(); // Update accumulated vertical scroll and apply it to top controls m_accumulatedScrollDelta += pendingDelta.height(); setShownRatio((m_baselineContentOffset + m_accumulatedScrollDelta) / m_height); // Reset baseline when controls are fully visible if (m_shownRatio == 1) resetBaseline(); FloatSize appliedDelta(0, contentOffset() - oldOffset); return pendingDelta - appliedDelta; }
void CodeEditor::extraAreaMouseEvent(QMouseEvent* event) { if (event->button() == Qt::LeftButton) { QTextBlock block = findBlockByY(event->pos().y()); if (FOLDBOXRECT(blockBoundingGeometry(block).translated(contentOffset()).y() + fontMetrics().height() / 2).contains(event->pos())) { foldUnfold(block); ensureCursorVisible(); FULLRESIZE; } } }
void MarkdownEditor::lineNumberAreaPaintEvent(QPaintEvent *event) { QPainter painter(lineNumberArea); int selStart = textCursor().selectionStart(); int selEnd = textCursor().selectionEnd(); QPalette palette = lineNumberArea->palette(); palette.setCurrentColorGroup(QPalette::Active); painter.fillRect(event->rect(), palette.color(QPalette::Background)); QTextBlock block = firstVisibleBlock(); int blockNumber = block.blockNumber(); qreal top = blockBoundingGeometry(block).translated(contentOffset()).top(); qreal bottom = top; while (block.isValid() && top <= event->rect().bottom()) { top = bottom; const qreal height = blockBoundingRect(block).height(); bottom = top + height; if (block.isVisible() && bottom >= event->rect().top()) { painter.setPen(palette.color(QPalette::Dark)); bool selected = ( (selStart < block.position() + block.length() && selEnd > block.position()) || (selStart == selEnd && selStart == block.position()) ); if (selected) { painter.save(); painter.setPen(Qt::black); } const QString number = QString::number(blockNumber + 1); painter.drawText(0, top, lineNumberArea->width() - 4, height, Qt::AlignRight, number); if (selected) painter.restore(); } block = block.next(); ++blockNumber; } }
void SparqlTextEdit::paintLineNumbers(QPaintEvent *e) { QFontMetrics metrics(currentCharFormat().font()); int digits = 0; int blocks = blockCount(); do { blocks /= 10; ++digits; } while (blocks); int maxCharWidth = 0; for (char c = '0'; c <= '9'; c++) { maxCharWidth = qMax(maxCharWidth, metrics.width(c)); } int newLeftMargin = frameWidth() + maxCharWidth * digits; if (leftMargin != newLeftMargin) { leftMargin = newLeftMargin; setViewportMargins(leftMargin, 0, 0, 0); } QPainter painter(this); painter.setClipRect(lineNumbersRect(), Qt::IntersectClip); painter.fillRect(e->rect(), palette().window()); painter.setPen(palette().windowText().color()); painter.setFont(currentCharFormat().font()); QTextBlock block = firstVisibleBlock(); int blockNumber = block.blockNumber(); int top = (int) blockBoundingGeometry(block) .translated(contentOffset()).top() + lineNumbersRect().top(); int bottom = top + (int) blockBoundingRect(block).height(); while (block.isValid() && top <= e->rect().bottom()) { if (block.isVisible() && bottom >= e->rect().top()) { QString number = QString::number(blockNumber + 1); painter.drawText(0, top, leftMargin, metrics.height(), Qt::AlignRight, number); } block = block.next(); top = bottom; bottom = top + (int) blockBoundingRect(block).height(); ++blockNumber; } }
void CodeEditor::paintEvent(QPaintEvent* event) { QPlainTextEdit::paintEvent(event); QPainter painter(viewport()); painter.setPen(Qt::darkGray); QTextBlock block = firstVisibleBlock(); QRectF rect; do { if (!block.isVisible()) continue; rect = blockBoundingGeometry(block).translated(contentOffset()); QTextLine line = block.layout()->lineAt(0); if (config->whitespaces) { QString txt = block.text(); for (int i = 0; i < txt.length(); i++) { // rect.x() <- учитывая горизонтальный скролинг QPoint point(rect.x() + line.cursorToX(i), rect.y() + line.ascent()); if (txt[i] == ' ') painter.drawText(point, QChar(0x00b7)); else if (txt[i] == '\t') painter.drawText(point, QChar(0x21b9)); } } int state = block.userState(); if (!(state & Error) && state & Folded) { QRect collapseRect(rect.x() + line.rect().x() + line.naturalTextWidth() + FONTWIDTH * 2, rect.y() + 2, FONTWIDTH * 6, line.height() - 4); painter.drawText(collapseRect, Qt::AlignCenter, state & Comment ? "...;" : "...)"); painter.drawRoundedRect(collapseRect, 4, 6); } } while ((block = block.next()).isValid() && rect.y() < viewport()->height()); }
void CodeEditor::mouseMoveEvent(QMouseEvent* event) { QTextBlock block = findBlockByY(event->pos().y()); QRect collapseRect; if (block.isValid()) { QRectF rect = blockBoundingGeometry(block).translated(contentOffset()); QTextLine line = block.layout()->lineAt(0); collapseRect = QRect(rect.x() + line.rect().x() + line.naturalTextWidth() + FONTWIDTH * 2, rect.y() + 2, FONTWIDTH * 6, line.height() - 4); } int state = block.userState(); if (!(state & Error) && state & Folded && collapseRect.contains(event->pos())) { pointedBlock = block; viewport()->setCursor(Qt::PointingHandCursor); QString str; while ((block = block.next()).isValid() && !block.isVisible()) { if (str.count() > 1) str += "\n"; if (block.blockNumber() - pointedBlock.blockNumber() > 50) { str += "..."; // "\n..."; break; } str += block.text(); } QToolTip::showText(event->globalPos(), str, this); } else { pointedBlock = QTextBlock(); viewport()->setCursor(Qt::IBeamCursor); } QPlainTextEdit::mouseMoveEvent(event); }
void CodeEdit::lineNumberWidgetPaintEvent(QPaintEvent* event) { // qDebug() << "CodeEdit::lineNumberWidgetPaintEvent()"; QPainter painter(m_lineNumberWidget); painter.setPen(QPen(ApplicationManager::settings()->lineNumberColor())); painter.fillRect(event->rect(), QBrush(ApplicationManager::settings()->lineNumberBackgroundColor())); QTextBlock block = firstVisibleBlock(); int top = (int)blockBoundingGeometry(block).translated(contentOffset()).top(); int bottom; while (block.isValid() && top <= event->rect().bottom()) { bottom = top + (int)blockBoundingRect(block).height(); if (block.isVisible() && bottom >= event->rect().top()) { painter.drawText(0, top, m_lineNumberWidget->width(), fontMetrics().height(),Qt::AlignRight, QString::number(block.blockNumber() + 1)); } block = block.next(); top = bottom; } }
void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event) { QPainter painter( lineNumberArea ); //painter.fillRect(event->rect(), Qt::lightGray); painter.fillRect( event->rect(), lineNumberArea->palette().base() ); 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( lineNumberArea->palette().text().color() ); for( const fugio::SyntaxError &SE : mSyntaxErrors ) { if( SE.mLineStart <= blockNumber + 1 && SE.mLineEnd >= blockNumber + 1 ) { QRectF R( event->rect().left(), top, event->rect().width(), blockBoundingRect( block ).height() ); painter.fillRect( R, Qt::red ); painter.setPen( Qt::white ); break; } } painter.drawText( 0, top, lineNumberArea->width(), fontMetrics().height(), Qt::AlignRight, number ); } block = block.next(); top = bottom; bottom = top + (int) blockBoundingRect(block).height(); ++blockNumber; } }
CodeEditor::CodeEditor(QWidget *parent, bool withBeakpoints) : RuQPlainTextEdit(parent), debugImage(":/images/debugLine.png"), breakpointImage(":/images/breakpoint.png"), settings("SASM Project", "SASM") { hasBreakpoints = withBeakpoints; prevBlockCount = -1; setDebugMode(false); debugAreaWidth = 3 + debugImage.width() + 1; setWordWrapMode(QTextOption::NoWrap); firstTopMargin = contentOffset().y(); lineNumberArea = new LineNumberArea(this); connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int))); connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int))); connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine())); connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(shiftBreakpoints(int))); updateLineNumberAreaWidth(0); highlightCurrentLine(); currentDebugLine = -1; }
/** * @brief Draws the line number area. * @param event The paint event to handle. */ void TextEditorWidget::line_number_area_paint_event(QPaintEvent* event) { QPainter painter(line_number_area); QTextBlock block = firstVisibleBlock(); int block_number = 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(block_number + 1) + " "; painter.setPen(Qt::black); painter.drawText(0, top, line_number_area->width(), fontMetrics().height(), Qt::AlignRight, number); } block = block.next(); top = bottom; bottom = top + (int) blockBoundingRect(block).height(); ++block_number; } }
/* Line numbers */ void JBEAM_TextBox::LineNumbersPaintEvent(QPaintEvent *event) { QPainter painter(LineNumbersA); painter.fillRect(event->rect(), Qt::white); 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::gray); painter.drawText(0, top, LineNumbersA->width(), fontMetrics().height(), Qt::AlignRight, number); } block = block.next(); top = bottom; bottom = top + (int) blockBoundingRect(block).height(); ++blockNumber; } }
void PgxEditor::breakpointAreaPaintEvent(QPaintEvent *event) { QPainter painter(breakpointArea); painter.fillRect(event->rect(), QColor(230,230,230,128)); 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::black); painter.drawText(-1, top+2, breakpointArea->width(), fontMetrics().height(), Qt::AlignRight, ""); } block = block.next(); top = bottom; bottom = top + (int) blockBoundingRect(block).height(); ++blockNumber; } }
void ScriptTextEdit::lineNumberAreaPaintEvent(QPaintEvent *event) { int lineAreaWidth = mLineNumberArea->width(); QPainter painter(mLineNumberArea); painter.fillRect(event->rect(), Qt::white); QPen linepen; linepen.setWidth(1); linepen.setColor( Qt::lightGray ); painter.setPen(linepen); painter.drawLine(lineAreaWidth-1,0,lineAreaWidth-1,mLineNumberArea->height()); int currentLine = textCursor().blockNumber(); QTextBlock block = firstVisibleBlock(); int blockNumber = block.blockNumber(); QFont font=painter.font(); 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); font.setBold(blockNumber==currentLine); painter.setFont( font ); painter.drawText(-2, top, lineAreaWidth, fontMetrics().height(), Qt::AlignRight | Qt::AlignVCenter, number); } block = block.next(); top = bottom; bottom = top + (int) blockBoundingRect(block).height(); ++blockNumber; } }