| 606 | } |
| 607 | |
| 608 | void CodeEditor::paintDebugInfo(QPaintEvent *event) |
| 609 | { |
| 610 | QPainter painter(debugInfo); |
| 611 | QFont lineNoFont = font(); |
| 612 | QFontMetrics fm(lineNoFont); |
| 613 | int origFontHeight = fm.height(); |
| 614 | lineNoFont.setPointSizeF(lineNoFont.pointSizeF()*0.8); |
| 615 | QFontMetrics fm2(lineNoFont); |
| 616 | int heightDiff = (origFontHeight-fm2.height()); |
| 617 | painter.setFont(lineNoFont); |
| 618 | |
| 619 | painter.fillRect(event->rect(), theme.backgroundColor.get(darkMode)); |
| 620 | |
| 621 | // TODO: This should be pre-computed only once and stored in each block. |
| 622 | // Statistics should not be recounted at eack redraw... |
| 623 | |
| 624 | QTextBlock block = firstVisibleBlock(); |
| 625 | int blockNumber = block.blockNumber(); |
| 626 | int top = static_cast<int>(blockBoundingGeometry(block).translated(contentOffset()).top()); |
| 627 | int bottom = top + static_cast<int>(blockBoundingRect(block).height()); |
| 628 | |
| 629 | int curLine = textCursor().blockNumber(); |
| 630 | |
| 631 | painter.setPen(theme.foregroundActiveColor.get(darkMode)); |
| 632 | while (block.isValid() && top <= event->rect().bottom()) { |
| 633 | BracketData* bd = static_cast<BracketData*>(block.userData()); |
| 634 | if (block.isVisible() && bottom >= event->rect().top() && bd->d.hasData()) { |
| 635 | // int textTop = top+fontMetrics().leading()+heightDiff; |
| 636 | int textTop = top+heightDiff; |
| 637 | // num constraints |
| 638 | painter.fillRect(0, top, DEBUG_TAB_SIZE, static_cast<int>(blockBoundingRect(block).height()), |
| 639 | heatColor(static_cast<double>(bd->d.con)/bd->d.totalCon)); |
| 640 | QString numConstraints = QString().number(bd->d.con); |
| 641 | painter.drawText(0, textTop, DEBUG_TAB_SIZE, fm2.height(), Qt::AlignCenter, numConstraints); |
| 642 | // num vars |
| 643 | painter.fillRect(DEBUG_TAB_SIZE, top, DEBUG_TAB_SIZE, static_cast<int>(blockBoundingRect(block).height()), |
| 644 | heatColor(static_cast<double>(bd->d.var)/bd->d.totalVar)); |
| 645 | QString numVars = QString().number(bd->d.var); |
| 646 | painter.drawText(DEBUG_TAB_SIZE, textTop, DEBUG_TAB_SIZE, fm2.height(), Qt::AlignCenter, numVars); |
| 647 | // flatten time |
| 648 | painter.fillRect(DEBUG_TAB_SIZE*2, top, DEBUG_TAB_SIZE, static_cast<int>(blockBoundingRect(block).height()), |
| 649 | heatColor(static_cast<double>(bd->d.ms)/bd->d.totalMs)); |
| 650 | QString flattenTime = QString().number(bd->d.ms); |
| 651 | painter.drawText(DEBUG_TAB_SIZE*2, textTop, DEBUG_TAB_SIZE, fm2.height(), Qt::AlignCenter, flattenTime+"ms"); |
| 652 | // painter.drawText(0, textTop, debugInfo->width(), fm2.height(), |
| 653 | // Qt::AlignLeft, number); |
| 654 | } |
| 655 | |
| 656 | block = block.next(); |
| 657 | top = bottom; |
| 658 | bottom = top + static_cast<int>(blockBoundingRect(block).height()); |
| 659 | ++blockNumber; |
| 660 | } |
| 661 | |
| 662 | painter.setPen(theme.foregroundInactiveColor.get(darkMode)); |
| 663 | painter.drawLine(0,0,0,event->rect().bottom()); |
| 664 | } |
| 665 | |