| 1 | // QCodeEditorcxx . . $ `<file>/src/internal/QLineNumberArea.cpp`/ |
| 2 | #include <QLineNumberArea>cxx . . $ `<file>/include/QLineNumberArea`/ |
| 3 | #include <QSyntaxStyle>cxx . . $ `<file>/include/QSyntaxStyle`/ |
| 4 | #include <QCodeEditor>cxx . . $ `<file>/include/QCodeEditor`/ |
| 5 | |
| 6 | // Qt |
| 7 | #include <QTextEdit> |
| 8 | #include <QPainter> |
| 9 | #include <QPaintEvent> |
| 10 | #include <QTextBlock> |
| 11 | #include <QScrollBar> |
| 12 | #include <QAbstractTextDocumentLayout> |
| 13 | |
| 14 | QLineNumberAreacxx . . $ QLineNumberArea#::QLineNumberAreacxx . . $ QLineNumberArea#QLineNumberArea(cf07aa72b82921fb).(QCodeEditorcxx . . $ QCodeEditor#* parent) : |
| 15 | QWidgetcxx . . $ QWidget#QWidget(872e7b0c281abd8d).(parent), |
| 16 | m_syntaxStylecxx . . $ QLineNumberArea#m_syntaxStyle.(nullptr), |
| 17 | m_codeEditParentcxx . . $ QLineNumberArea#m_codeEditParent.(parent) |
| 18 | { |
| 19 | |
| 20 | } |
| 21 | |
| 22 | QSizecxx . . $ QSize# QLineNumberAreacxx . . $ QLineNumberArea#::sizeHintcxx . . $ QLineNumberArea#sizeHint(4b3b776e5ee2b367).() const |
| 23 | { |
| 24 | if (m_codeEditParentcxx . . $ QLineNumberArea#m_codeEditParent. == nullptr) |
| 25 | { |
| 26 | return QWidgetcxx . . $ QWidget#::sizeHintcxx . . $ QWidget#sizeHint(4b3b776e5ee2b367).(); |
| 27 | } |
| 28 | |
| 29 | // Calculating width |
| 30 | int digits = 1; |
| 31 | int max = qMaxcxx . . $ qMax(2a338fce5842aa6a).(1, m_codeEditParentcxx . . $ QLineNumberArea#m_codeEditParent.->documentcxx . . $ QTextEdit#document(f21741221844491e).()->blockCountcxx . . $ QTextDocument#blockCount(455f465bc33b4cdf).()); |
| 32 | while (max >= 10) { |
| 33 | max /= 10; |
| 34 | ++digits; |
| 35 | } |
| 36 | |
| 37 | #if QT_VERSIONcxx . . $ `<external>/15045578679651060896/qglobal.h:57:9`! >= 0x050B00 |
| 38 | int space = 13 + m_codeEditParentcxx . . $ QLineNumberArea#m_codeEditParent.->fontMetricscxx . . $ QWidget#fontMetrics(ee264e9e8967f9a7).().horizontalAdvancecxx . . $ QFontMetrics#horizontalAdvance(cb11a8ddef27242a).(QLatin1Charcxx . . $ QChar#QChar(3c55a7a0aea1b63a).('9')) * digits; |
| 39 | #else |
| 40 | int space = 13 + m_codeEditParent->fontMetrics().width(QLatin1Char('9')) * digits; |
| 41 | #endif |
| 42 | |
| 43 | return {cxx . . $ QSize#QSize(3e454b8ccf442868).space, 0}; |
| 44 | } |
| 45 | |
| 46 | void QLineNumberAreacxx . . $ QLineNumberArea#::setSyntaxStylecxx . . $ QLineNumberArea#setSyntaxStyle(1fc7b27a9b6cc29c).(QSyntaxStylecxx . . $ QSyntaxStyle#* style) |
| 47 | { |
| 48 | m_syntaxStylecxx . . $ QLineNumberArea#m_syntaxStyle. = style; |
| 49 | } |
| 50 | |
| 51 | QSyntaxStylecxx . . $ QSyntaxStyle#* QLineNumberAreacxx . . $ QLineNumberArea#::syntaxStylecxx . . $ QLineNumberArea#syntaxStyle(8b4bb56ba20b4a4a).() const |
| 52 | { |
| 53 | return m_syntaxStylecxx . . $ QLineNumberArea#m_syntaxStyle.; |
| 54 | } |
| 55 | |
| 56 | void QLineNumberAreacxx . . $ QLineNumberArea#::paintEventcxx . . $ QLineNumberArea#paintEvent(f239c9e85d61a220).(QPaintEventcxx . . $ QPaintEvent#* event) |
| 57 | { |
| 58 | QPaintercxx . . $ QPainter# paintercxx . . $ QPainter#QPainter(dd2eedc069b0ab5f).(this); |
| 59 | |
| 60 | // Clearing rect to update |
| 61 | painter.fillRectcxx . . $ QPainter#fillRect(b5c43933f089f858).( |
| 62 | event->rectcxx . . $ QPaintEvent#rect(f4023511c62cad66).(), |
| 63 | m_syntaxStylecxx . . $ QLineNumberArea#m_syntaxStyle.->getFormatcxx . . $ QSyntaxStyle#getFormat(5b7fd501ba56a402).("Text"cxx . . $ QString#QString(e1217c004a86c950).).backgroundcxx . . $ QTextFormat#background(583354ac483a5b23).().colorcxx . . $ QBrush#color(a1044652a6e0ddd).() |
| 64 | ); |
| 65 | |
| 66 | auto blockNumber = m_codeEditParentcxx . . $ QLineNumberArea#m_codeEditParent.->getFirstVisibleBlockcxx . . $ QCodeEditor#getFirstVisibleBlock(b126dc7c1de90089).(); |
| 67 | auto block = m_codeEditParentcxx . . $ QTextBlock#QTextBlock(ca9d602f58d4ee04).->documentcxx . . $ QTextEdit#document(f21741221844491e).()->findBlockByNumbercxx . . $ QTextDocument#findBlockByNumber(c1425046715037b8).(blockNumber); |
| 68 | auto top = (int) m_codeEditParentcxx . . $ QLineNumberArea#m_codeEditParent.->documentcxx . . $ QTextEdit#document(f21741221844491e).()->documentLayoutcxx . . $ QTextDocument#documentLayout(135eff1e02365923).()->blockBoundingRectcxx . . $ QAbstractTextDocumentLayout#blockBoundingRect(b25b5125f533bbfc).(block).translatedcxx . . $ QRectF#translated(3dca8665d0298123).(0, -m_codeEditParentcxx . . $ QLineNumberArea#m_codeEditParent.->verticalScrollBarcxx . . $ QAbstractScrollArea#verticalScrollBar(49d9510c6adf8c19).()->valuecxx . . $ QAbstractSlider#value(455f465bc33b4cdf).()).topcxx . . $ QRectF#top(21b6c25e127938e2).(); |
| 69 | auto bottom = top + (int) m_codeEditParentcxx . . $ QLineNumberArea#m_codeEditParent.->documentcxx . . $ QTextEdit#document(f21741221844491e).()->documentLayoutcxx . . $ QTextDocument#documentLayout(135eff1e02365923).()->blockBoundingRectcxx . . $ QAbstractTextDocumentLayout#blockBoundingRect(b25b5125f533bbfc).(block).heightcxx . . $ QRectF#height(21b6c25e127938e2).(); |
| 70 | |
| 71 | auto currentLine = m_syntaxStylecxx . . $ QColor#QColor(129a55e114526ad3).->getFormatcxx . . $ QSyntaxStyle#getFormat(5b7fd501ba56a402).("CurrentLineNumber"cxx . . $ QString#QString(e1217c004a86c950).).foregroundcxx . . $ QTextFormat#foreground(583354ac483a5b23).().colorcxx . . $ QBrush#color(a1044652a6e0ddd).(); |
| 72 | auto otherLines = m_syntaxStylecxx . . $ QColor#QColor(129a55e114526ad3).->getFormatcxx . . $ QSyntaxStyle#getFormat(5b7fd501ba56a402).("LineNumber"cxx . . $ QString#QString(e1217c004a86c950).).foregroundcxx . . $ QTextFormat#foreground(583354ac483a5b23).().colorcxx . . $ QBrush#color(a1044652a6e0ddd).(); |
| 73 | |
| 74 | painter.setFontcxx . . $ QPainter#setFont(d0a4bd0c8524b912).(m_codeEditParentcxx . . $ QLineNumberArea#m_codeEditParent.->fontcxx . . $ QWidget#font(c5040538afc47120).()); |
| 75 | |
| 76 | while (block.isValidcxx . . $ QTextBlock#isValid(50ce9a9e25b4a850).() && top <= event->rectcxx . . $ QPaintEvent#rect(f4023511c62cad66).().bottomcxx . . $ QRect#bottom(455f465bc33b4cdf).()) |
| 77 | { |
| 78 | if (block.isVisiblecxx . . $ QTextBlock#isVisible(50ce9a9e25b4a850).() && bottom >= event->rectcxx . . $ QPaintEvent#rect(f4023511c62cad66).().topcxx . . $ QRect#top(455f465bc33b4cdf).()) |
| 79 | { |
| 80 | QStringcxx . . $ QString# number = QStringcxx . . $ QString#QString(e1217c004a86c950).::numbercxx . . $ QString#number(f4fd9db251ca774b).(blockNumber + 1); |
| 81 | |
| 82 | auto isCurrentLine = m_codeEditParentcxx . . $ QLineNumberArea#m_codeEditParent.->textCursorcxx . . $ QTextEdit#textCursor(878247cba2fd3c00).().blockNumbercxx . . $ QTextCursor#blockNumber(455f465bc33b4cdf).() == blockNumber; |
| 83 | painter.setPencxx . . $ QPainter#setPen(129a55e114526ad3).(isCurrentLine ? currentLine : otherLines); |
| 84 | |
| 85 | painter.drawTextcxx . . $ QPainter#drawText(26e93c81cbf08633).( |
| 86 | -5, |
| 87 | top, |
| 88 | sizeHintcxx . . $ QLineNumberArea#sizeHint(4b3b776e5ee2b367).().widthcxx . . $ QSize#width(455f465bc33b4cdf).(), |
| 89 | m_codeEditParentcxx . . $ QLineNumberArea#m_codeEditParent.->fontMetricscxx . . $ QWidget#fontMetrics(ee264e9e8967f9a7).().heightcxx . . $ QFontMetrics#height(455f465bc33b4cdf).(), |
| 90 | Qtcxx . . $ Qt/::AlignRightcxx . . $ Qt/AlignRight., |
| 91 | number |
| 92 | ); |
| 93 | } |
| 94 | |
| 95 | block =cxx . . $ QTextBlock#`operator=`(b837fc91fbe92fa9). block.nextcxx . . $ QTextBlock#next(fcb2c37f271a2a41).(); |
| 96 | top = bottom; |
| 97 | bottom = top + (int) m_codeEditParentcxx . . $ QLineNumberArea#m_codeEditParent.->documentcxx . . $ QTextEdit#document(f21741221844491e).()->documentLayoutcxx . . $ QTextDocument#documentLayout(135eff1e02365923).()->blockBoundingRectcxx . . $ QAbstractTextDocumentLayout#blockBoundingRect(b25b5125f533bbfc).(block).heightcxx . . $ QRectF#height(21b6c25e127938e2).(); |
| 98 | ++blockNumber; |
| 99 | } |
| 100 | } |