| 552 | } |
| 553 | |
| 554 | void QHexView::drawHeader(QTextCursor& c) const { |
| 555 | if(m_options.hasFlag(QHexFlags::NoHeader)) |
| 556 | return; |
| 557 | |
| 558 | static const auto RESET_FORMAT = [](const QHexOptions& options, |
| 559 | QTextCharFormat& cf) { |
| 560 | cf = {}; |
| 561 | cf.setForeground(options.headercolor); |
| 562 | }; |
| 563 | |
| 564 | QString addresslabel; |
| 565 | if(m_hexdelegate) |
| 566 | addresslabel = m_hexdelegate->addressHeader(this); |
| 567 | if(addresslabel.isEmpty() && !m_options.addresslabel.isEmpty()) |
| 568 | addresslabel = m_options.addresslabel; |
| 569 | |
| 570 | QTextCharFormat cf; |
| 571 | RESET_FORMAT(m_options, cf); |
| 572 | if(m_hexdelegate) |
| 573 | m_hexdelegate->renderHeaderPart(addresslabel, QHexArea::Address, cf, |
| 574 | this); |
| 575 | c.insertText( |
| 576 | " " + QHexView::reduced(addresslabel, this->addressWidth()) + " ", cf); |
| 577 | |
| 578 | if(m_hexdelegate) |
| 579 | RESET_FORMAT(m_options, cf); |
| 580 | |
| 581 | QString hexlabel; |
| 582 | if(m_hexdelegate) |
| 583 | hexlabel = m_hexdelegate->hexHeader(this); |
| 584 | if(hexlabel.isEmpty()) |
| 585 | hexlabel = m_options.hexlabel; |
| 586 | |
| 587 | if(hexlabel.isNull()) { |
| 588 | c.insertText(" ", {}); |
| 589 | |
| 590 | for(auto i = 0u; i < m_options.linelength; i += m_options.grouplength) { |
| 591 | QString h = QString::number(i, 16) |
| 592 | .rightJustified(m_options.grouplength * 2, '0') |
| 593 | .toUpper(); |
| 594 | |
| 595 | if(m_hexdelegate) { |
| 596 | RESET_FORMAT(m_options, cf); |
| 597 | m_hexdelegate->renderHeaderPart(h, QHexArea::Hex, cf, this); |
| 598 | } |
| 599 | |
| 600 | if(m_hexcursor->column() == static_cast<qint64>(i) && |
| 601 | m_options.hasFlag(QHexFlags::HighlightColumn)) { |
| 602 | cf.setBackground(this->palette().color(QPalette::Highlight)); |
| 603 | cf.setForeground( |
| 604 | this->palette().color(QPalette::HighlightedText)); |
| 605 | } |
| 606 | |
| 607 | c.insertText(h, cf); |
| 608 | c.insertText(" ", {}); |
| 609 | RESET_FORMAT(m_options, cf); |
| 610 | } |
| 611 | } |
no test coverage detected