19 QPlainTextEdit(pc_parent) {
22 cFont.setFamily(
"Monospace");
23 cFont.setStyleHint(QFont::Monospace);
24 cFont.setFixedPitch(
true);
27 QFontMetrics cFontMetrics(cFont);
28 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
29 setTabStopDistance(3 * cFontMetrics.horizontalAdvance(
' '));
31 setTabStopWidth(3 * cFontMetrics.width(
' '));
36 m_pcLineNumberArea =
new CLineNumberArea(
this);
38 connect(
this, SIGNAL(blockCountChanged(
int)),
39 this, SLOT(UpdateLineNumberAreaWidth(
int)));
40 connect(
this, SIGNAL(updateRequest(
const QRect&,
int)),
41 this, SLOT(UpdateLineNumberArea(
const QRect&,
int)));
42 connect(
this, SIGNAL(cursorPositionChanged()),
43 this, SLOT(HighlightCurrentLine()));
45 UpdateLineNumberAreaWidth(0);
46 HighlightCurrentLine();
53 QPainter cPainter(m_pcLineNumberArea);
54 cPainter.fillRect(pc_event->rect(), Qt::lightGray);
57 QTextBlock cBlock = firstVisibleBlock();
58 int nBlockNumber = cBlock.blockNumber();
59 int nTop = (int) blockBoundingGeometry(cBlock).translated(contentOffset()).top();
60 int nBottom = nTop + (int) blockBoundingRect(cBlock).height();
62 while (cBlock.isValid() && nTop <= pc_event->rect().bottom()) {
63 if (cBlock.isVisible() && nBottom >= pc_event->rect().top()) {
64 QString strNumber = QString::number(nBlockNumber + 1);
65 cPainter.setPen(Qt::black);
66 cPainter.drawText(0, nTop,
67 m_pcLineNumberArea->width(), fontMetrics().height(),
68 Qt::AlignRight, strNumber);
71 cBlock = cBlock.next();
73 nBottom = nTop + (int) blockBoundingRect(cBlock).height();
83 int nMax = qMax(1, blockCount());
88 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
89 int nSpace = 3 + fontMetrics().horizontalAdvance(QLatin1Char(
'9')) * nDigits;
91 int nSpace = 3 + fontMetrics().width(QLatin1Char(
'9')) * nDigits;
100 QPlainTextEdit::resizeEvent(pc_event);
101 QRect cRect = contentsRect();
102 m_pcLineNumberArea->setGeometry(QRect(cRect.left(), cRect.top(),
109 void CQTOpenGLLuaEditor::UpdateLineNumberAreaWidth(
int) {
116 void CQTOpenGLLuaEditor::HighlightCurrentLine() {
117 QList<QTextEdit::ExtraSelection> cListExtraSel;
120 QTextEdit::ExtraSelection cSel;
121 QColor cLineColor = QColor(Qt::yellow).lighter(160);
122 cSel.format.setBackground(cLineColor);
123 cSel.format.setProperty(QTextFormat::FullWidthSelection,
true);
124 cSel.cursor = textCursor();
125 cSel.cursor.clearSelection();
126 cListExtraSel.append(cSel);
128 setExtraSelections(cListExtraSel);
134 void CQTOpenGLLuaEditor::UpdateLineNumberArea(
const QRect& c_rect,
137 m_pcLineNumberArea->scroll(0, n_dy);
140 m_pcLineNumberArea->update(0, c_rect.y(),
141 m_pcLineNumberArea->width(), c_rect.height());
143 if(c_rect.contains(viewport()->rect())) {
144 UpdateLineNumberAreaWidth(0);
The namespace containing all the ARGoS related code.
void LineNumberAreaPaintEvent(QPaintEvent *pc_event)
void resizeEvent(QResizeEvent *pc_event)
int LineNumberAreaWidth()
CQTOpenGLLuaEditor(QWidget *pc_parent)