| 675 | } |
| 676 | |
| 677 | void QHexView::drawDocument(QTextCursor& c) const { |
| 678 | if(!m_hexdocument) |
| 679 | return; |
| 680 | |
| 681 | qreal y = !m_options.hasFlag(QHexFlags::NoHeader) ? this->lineHeight() : 0; |
| 682 | quint64 line = static_cast<quint64>(this->verticalScrollBar()->value()); |
| 683 | |
| 684 | QTextCharFormat addrformat; |
| 685 | addrformat.setForeground( |
| 686 | this->palette().color(QPalette::Normal, QPalette::Highlight)); |
| 687 | |
| 688 | for(qint64 l = 0; m_hexdocument->isEmpty() || |
| 689 | (line < this->lines() && l < this->visibleLines()); |
| 690 | l++, line++, y += this->lineHeight()) { |
| 691 | quint64 address = line * m_options.linelength + this->baseAddress(); |
| 692 | QString addrstr = QString::number(address, 16) |
| 693 | .rightJustified(this->addressWidth(), '0') |
| 694 | .toUpper(); |
| 695 | |
| 696 | // Address Part |
| 697 | QTextCharFormat acf; |
| 698 | acf.setForeground(m_options.headercolor); |
| 699 | |
| 700 | if(m_options.hasFlag(QHexFlags::StyledAddress)) |
| 701 | acf.setBackground(this->palette().color(QPalette::Window)); |
| 702 | |
| 703 | if(m_hexdelegate) |
| 704 | m_hexdelegate->renderAddress(address, acf, this); |
| 705 | |
| 706 | if(m_hexcursor->line() == static_cast<qint64>(line) && |
| 707 | m_options.hasFlag(QHexFlags::HighlightAddress)) { |
| 708 | acf.setBackground(this->palette().color(QPalette::Highlight)); |
| 709 | acf.setForeground(this->palette().color(QPalette::HighlightedText)); |
| 710 | } |
| 711 | |
| 712 | c.insertText(" " + addrstr + " ", acf); |
| 713 | |
| 714 | auto linebytes = this->getLine(line); |
| 715 | c.insertText(" ", {}); |
| 716 | |
| 717 | // Hex Part |
| 718 | for(auto column = 0u; column < m_options.linelength;) { |
| 719 | QTextCharFormat cf; |
| 720 | |
| 721 | for(auto byteidx = 0u; byteidx < m_options.grouplength; |
| 722 | byteidx++, column++) { |
| 723 | QString s = |
| 724 | linebytes.isEmpty() || |
| 725 | column >= static_cast<qint64>(linebytes.size()) |
| 726 | ? " " |
| 727 | : QString(QHexUtils::toHex(linebytes.mid(column, 1)) |
| 728 | .toUpper()); |
| 729 | quint8 b = static_cast<int>(column) < linebytes.size() |
| 730 | ? linebytes.at(column) |
| 731 | : 0x00; |
| 732 | cf = this->drawFormat(c, b, s, QHexArea::Hex, line, column, |
| 733 | static_cast<int>(column) < |
| 734 | linebytes.size()); |
no test coverage detected