19 QPlainTextEdit(pc_parent) {
22 cFont.setFamily(
"Monospace");
23 cFont.setStyleHint(QFont::Monospace);
24 cFont.setFixedPitch(
true);
27 QFontMetrics cFontMetrics(cFont);
28 setTabStopWidth(3 * cFontMetrics.width(
' '));
32 m_pcLineNumberArea =
new CLineNumberArea(
this);
34 connect(
this, SIGNAL(blockCountChanged(
int)),
35 this, SLOT(UpdateLineNumberAreaWidth(
int)));
36 connect(
this, SIGNAL(updateRequest(
const QRect&,
int)),
37 this, SLOT(UpdateLineNumberArea(
const QRect&,
int)));
38 connect(
this, SIGNAL(cursorPositionChanged()),
39 this, SLOT(HighlightCurrentLine()));
41 UpdateLineNumberAreaWidth(0);
42 HighlightCurrentLine();
49 QPainter cPainter(m_pcLineNumberArea);
50 cPainter.fillRect(pc_event->rect(), Qt::lightGray);
53 QTextBlock cBlock = firstVisibleBlock();
54 int nBlockNumber = cBlock.blockNumber();
55 int nTop = (int) blockBoundingGeometry(cBlock).translated(contentOffset()).top();
56 int nBottom = nTop + (int) blockBoundingRect(cBlock).height();
58 while (cBlock.isValid() && nTop <= pc_event->rect().bottom()) {
59 if (cBlock.isVisible() && nBottom >= pc_event->rect().top()) {
60 QString strNumber = QString::number(nBlockNumber + 1);
61 cPainter.setPen(Qt::black);
62 cPainter.drawText(0, nTop,
63 m_pcLineNumberArea->width(), fontMetrics().height(),
64 Qt::AlignRight, strNumber);
67 cBlock = cBlock.next();
69 nBottom = nTop + (int) blockBoundingRect(cBlock).height();
79 int nMax = qMax(1, blockCount());
84 int nSpace = 3 + fontMetrics().width(QLatin1Char(
'9')) * nDigits;
92 QPlainTextEdit::resizeEvent(pc_event);
93 QRect cRect = contentsRect();
94 m_pcLineNumberArea->setGeometry(QRect(cRect.left(), cRect.top(),
101 void CQTOpenGLLuaEditor::UpdateLineNumberAreaWidth(
int) {
108 void CQTOpenGLLuaEditor::HighlightCurrentLine() {
109 QList<QTextEdit::ExtraSelection> cListExtraSel;
112 QTextEdit::ExtraSelection cSel;
113 QColor cLineColor = QColor(Qt::yellow).lighter(160);
114 cSel.format.setBackground(cLineColor);
115 cSel.format.setProperty(QTextFormat::FullWidthSelection,
true);
116 cSel.cursor = textCursor();
117 cSel.cursor.clearSelection();
118 cListExtraSel.append(cSel);
120 setExtraSelections(cListExtraSel);
126 void CQTOpenGLLuaEditor::UpdateLineNumberArea(
const QRect& c_rect,
129 m_pcLineNumberArea->scroll(0, n_dy);
132 m_pcLineNumberArea->update(0, c_rect.y(),
133 m_pcLineNumberArea->width(), c_rect.height());
135 if(c_rect.contains(viewport()->rect())) {
136 UpdateLineNumberAreaWidth(0);