| 532 | |
| 533 | |
| 534 | void ByteView::paintEvent(QPaintEvent* event) |
| 535 | { |
| 536 | QPainter p(viewport()); |
| 537 | m_render.init(p); |
| 538 | int charWidth = m_render.getFontWidth(); |
| 539 | int charHeight = m_render.getFontHeight(); |
| 540 | |
| 541 | // Compute range that needs to be updated |
| 542 | int topY = event->rect().y(); |
| 543 | int botY = topY + event->rect().height(); |
| 544 | topY = (topY - 2) / charHeight; |
| 545 | botY = ((botY - 2) / charHeight) + 1; |
| 546 | |
| 547 | // Compute selection range |
| 548 | bool selection = false; |
| 549 | BNAddressRange selectionRange = getSelectionOffsets(); |
| 550 | if (selectionRange.start != selectionRange.end) |
| 551 | selection = true; |
| 552 | |
| 553 | // Draw selection |
| 554 | if (selection) |
| 555 | { |
| 556 | bool startValid = false; |
| 557 | bool endValid = false; |
| 558 | int startY = 0; |
| 559 | int endY = 0; |
| 560 | int startX = 0; |
| 561 | int endX = 0; |
| 562 | for (size_t i = 0; i < m_lines.size(); i++) |
| 563 | { |
| 564 | if (selectionRange.start >= m_lines[i].address) |
| 565 | { |
| 566 | startY = (int)(i - m_topLine); |
| 567 | startX = (int)(selectionRange.start - m_lines[i].address); |
| 568 | if (startX > (int)m_cols) |
| 569 | startX = (int)m_cols; |
| 570 | startValid = true; |
| 571 | } |
| 572 | if (selectionRange.end >= m_lines[i].address) |
| 573 | { |
| 574 | endY = (int)(i - m_topLine); |
| 575 | endX = (int)(selectionRange.end - m_lines[i].address); |
| 576 | if (endX > (int)m_cols) |
| 577 | endX = (int)m_cols; |
| 578 | endValid = true; |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | if (startValid && endValid) |
| 583 | { |
| 584 | p.setPen(getThemeColor(SelectionColor)); |
| 585 | p.setBrush(getThemeColor(SelectionColor)); |
| 586 | if (startY == endY) |
| 587 | { |
| 588 | p.drawRect(2 + ((int)m_addrWidth + 2 + startX) * charWidth, 2 + startY * charHeight, |
| 589 | (endX - startX) * charWidth, charHeight + 1); |
| 590 | } |
| 591 | else |