| 976 | } |
| 977 | |
| 978 | QTextCharFormat QHexView::drawFormat(QTextCursor& c, quint8 b, const QString& s, |
| 979 | QHexArea area, qint64 line, qint64 column, |
| 980 | bool applyformat) const { |
| 981 | QTextCharFormat cf, selcf; |
| 982 | QHexPosition pos{line, column}; |
| 983 | |
| 984 | if(applyformat) { |
| 985 | auto offset = m_hexcursor->positionToOffset(pos); |
| 986 | bool hasdelegate = |
| 987 | m_hexdelegate && m_hexdelegate->render(offset, b, cf, this); |
| 988 | |
| 989 | if(!hasdelegate) { |
| 990 | auto it = m_options.bytecolors.find(b); |
| 991 | |
| 992 | if(it != m_options.bytecolors.end()) { |
| 993 | if(it->background.isValid()) |
| 994 | cf.setBackground(it->background); |
| 995 | if(it->foreground.isValid()) |
| 996 | cf.setForeground(it->foreground); |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | const auto* metadataline = m_hexmetadata->find(line); |
| 1001 | |
| 1002 | if(metadataline) { |
| 1003 | for(const auto& metadata : *metadataline) { |
| 1004 | if(offset < metadata.begin || offset >= metadata.end) |
| 1005 | continue; |
| 1006 | |
| 1007 | if(!hasdelegate) { |
| 1008 | if(metadata.foreground.isValid()) |
| 1009 | cf.setForeground(metadata.foreground); |
| 1010 | |
| 1011 | if(metadata.background.isValid()) { |
| 1012 | cf.setBackground(metadata.background); |
| 1013 | |
| 1014 | if(!metadata.foreground.isValid()) |
| 1015 | cf.setForeground( |
| 1016 | this->getReadableColor(metadata.background)); |
| 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | if(!metadata.comment.isEmpty()) { |
| 1021 | cf.setUnderlineColor( |
| 1022 | m_options.commentcolor.isValid() |
| 1023 | ? m_options.commentcolor |
| 1024 | : this->palette().color(QPalette::WindowText)); |
| 1025 | cf.setUnderlineStyle( |
| 1026 | QTextCharFormat::UnderlineStyle::SingleUnderline); |
| 1027 | } |
| 1028 | |
| 1029 | if(offset == |
| 1030 | metadata |
| 1031 | .begin) // Remove previous metadata's style, if needed |
| 1032 | { |
| 1033 | if(metadata.comment.isEmpty()) |
| 1034 | selcf.setUnderlineStyle( |
| 1035 | QTextCharFormat::UnderlineStyle::NoUnderline); |
no test coverage detected