@@ -747,9 +747,8 @@ void QHexRenderer::applyDocumentStyles(QPainter *painter,
747747 textdocument->setDefaultTextOption (textopt);
748748}
749749
750- void QHexRenderer::applyBasicStyle (QTextCursor &textcursor,
751- const QByteArray &rawline,
752- Factor factor) const {
750+ void QHexRenderer::applyHexBasicStyle (QTextCursor &textcursor,
751+ const QByteArray &rawline) const {
753752 QColor color = m_bytesColor;
754753
755754 if (color.lightness () < 50 ) {
@@ -769,15 +768,15 @@ void QHexRenderer::applyBasicStyle(QTextCursor &textcursor,
769768 if ((rawline[i] != 0x00 ) && (uchar (rawline[i]) != 0xFF ))
770769 continue ;
771770
772- textcursor.setPosition (i * factor );
771+ textcursor.setPosition (i * Hex );
773772 textcursor.movePosition (QTextCursor::Right, QTextCursor::KeepAnchor,
774- factor );
773+ Hex );
775774 textcursor.mergeCharFormat (charformat);
776775 }
777776}
778777
779- void QHexRenderer::applyMetadata (QTextCursor &textcursor, qsizetype line ,
780- Factor factor ) const {
778+ void QHexRenderer::applyHexMetadata (QTextCursor &textcursor,
779+ qsizetype line ) const {
781780 QHexMetadata *metadata = m_document->metadata ();
782781
783782 if (!metadata->lineHasMetadata (line))
@@ -817,37 +816,36 @@ void QHexRenderer::applyMetadata(QTextCursor &textcursor, qsizetype line,
817816 CONTRASTING_COLOR_BORDER , Qt::SolidLine));
818817 }
819818
820- textcursor.setPosition (int (mi.start * factor ));
819+ textcursor.setPosition (int (mi.start * Hex ));
821820 textcursor.movePosition (QTextCursor::Right, QTextCursor::KeepAnchor,
822- int ((mi.length * factor )));
821+ int ((mi.length * Hex )));
823822 textcursor.mergeCharFormat (charformat);
824823 }
825824}
826825
827- void QHexRenderer::applySelection (QTextCursor &textcursor, qsizetype line ,
828- Factor factor ) const {
826+ void QHexRenderer::applyHexSelection (QTextCursor &textcursor,
827+ qsizetype line ) const {
829828 if (!m_cursor->isLineSelected (line))
830829 return ;
831830
832831 auto total = m_cursor->selectionCount ();
833832 for (int i = 0 ; i < total; ++i) {
834- applySelection (m_cursor->selection (i), textcursor, line, factor , false ,
835- false );
833+ applyHexSelection (m_cursor->selection (i), textcursor, line, false ,
834+ false );
836835 }
837836
838837 if (m_cursor->hasPreviewSelection ()) {
839- applySelection (
840- m_cursor->previewSelection (), textcursor, line, factor,
838+ applyHexSelection (
839+ m_cursor->previewSelection (), textcursor, line,
841840 m_cursor->previewSelectionMode () == QHexCursor::SelectionRemove,
842841 m_cursor->previewSelectionMode () == QHexCursor::SelectionNormal &&
843842 m_cursor->hasInternalSelection ());
844843 }
845844}
846845
847- void QHexRenderer::applySelection (const QHexSelection &selection,
848- QTextCursor &textcursor, qsizetype line,
849- Factor factor, bool strikeOut,
850- bool hasSelection) const {
846+ void QHexRenderer::applyHexSelection (const QHexSelection &selection,
847+ QTextCursor &textcursor, qsizetype line,
848+ bool strikeOut, bool hasSelection) const {
851849 if (!selection.isLineSelected (line)) {
852850 return ;
853851 }
@@ -902,16 +900,14 @@ void QHexRenderer::applySelection(const QHexSelection &selection,
902900 end = startsel.lineWidth - 1 ;
903901 }
904902
905- applySelection (metas, textcursor, line * startsel.lineWidth , begin, end,
906- factor, strikeOut, hasSelection);
903+ applyHexSelection (metas, textcursor, line * startsel.lineWidth , begin, end,
904+ strikeOut, hasSelection);
907905}
908906
909- void QHexRenderer::applySelection (const QVector<QHexMetadata::MetaInfo> &metas,
910- QTextCursor &textcursor,
911- qsizetype startLineOffset,
912- qsizetype lineStart, qsizetype lineEnd,
913- Factor factor, bool strikeOut,
914- bool hasSelection) const {
907+ void QHexRenderer::applyHexSelection (
908+ const QVector<QHexMetadata::MetaInfo> &metas, QTextCursor &textcursor,
909+ qsizetype startLineOffset, qsizetype lineStart, qsizetype lineEnd,
910+ bool strikeOut, bool hasSelection) const {
915911 auto totallen = lineEnd - lineStart + 1 ;
916912
917913 QTextCharFormat charfmt;
@@ -936,16 +932,16 @@ void QHexRenderer::applySelection(const QVector<QHexMetadata::MetaInfo> &metas,
936932
937933 auto blen = begin - fmtBegin;
938934
939- textcursor.setPosition (fmtBegin * factor );
935+ textcursor.setPosition (fmtBegin * Hex );
940936 textcursor.movePosition (QTextCursor::Right, QTextCursor::KeepAnchor,
941- blen * factor );
937+ blen * Hex );
942938
943939 textcursor.mergeCharFormat (charfmt);
944940 textcursor.clearSelection ();
945941 totallen -= blen;
946942
947943 textcursor.movePosition (QTextCursor::Right, QTextCursor::KeepAnchor,
948- mlen * factor );
944+ mlen * Hex );
949945
950946 if (!strikeOut) {
951947 QColor fg, bg = charfmt.background ().color ();
@@ -981,20 +977,21 @@ void QHexRenderer::applySelection(const QVector<QHexMetadata::MetaInfo> &metas,
981977
982978 if (totallen > 0 ) {
983979 textcursor.movePosition (QTextCursor::Right, QTextCursor::KeepAnchor,
984- totallen * factor );
980+ totallen * Hex );
985981 textcursor.mergeCharFormat (charfmt);
986982 textcursor.clearSelection ();
987983 }
988984 } else {
989- textcursor.setPosition (lineStart * factor );
985+ textcursor.setPosition (lineStart * Hex );
990986 textcursor.movePosition (QTextCursor::Right, QTextCursor::KeepAnchor,
991- totallen * factor );
987+ totallen * Hex );
992988 textcursor.mergeCharFormat (charfmt);
993989 }
994990}
995991
996- bool QHexRenderer::isByteSelected (qsizetype line, int column, bool *strikeOut,
997- bool *hasSelection) const {
992+ bool QHexRenderer::isStrByteSelected (qsizetype line, int column,
993+ bool *strikeOut,
994+ bool *hasSelection) const {
998995 if (strikeOut) {
999996 *strikeOut = false ;
1000997 }
@@ -1092,7 +1089,7 @@ QHexRenderer::asciiCellFormat(qsizetype line, int column, uchar value) const {
10921089
10931090 bool strikeOut = false ;
10941091 bool hasSelection = false ;
1095- if (isByteSelected (line, column, &strikeOut, &hasSelection)) {
1092+ if (isStrByteSelected (line, column, &strikeOut, &hasSelection)) {
10961093 fmt.background = (strikeOut || hasSelection)
10971094 ? m_selBackgroundColor.darker ()
10981095 : m_selBackgroundColor;
@@ -1239,14 +1236,15 @@ void QHexRenderer::drawHex(QPainter *painter, const QRect &linerect,
12391236 hexrect.setX (this ->getHexColumnX () + this ->borderSize ());
12401237
12411238 this ->applyDocumentStyles (painter, &textdocument);
1242- this ->applyBasicStyle (textcursor, rawline, Hex );
1239+ this ->applyHexBasicStyle (textcursor, rawline);
12431240
12441241 auto dis = !m_document->metabgVisible () && !m_document->metafgVisible () &&
12451242 !m_document->metaCommentVisible ();
1246- if (!dis)
1247- this ->applyMetadata (textcursor, line, Hex);
1243+ if (!dis) {
1244+ this ->applyHexMetadata (textcursor, line);
1245+ }
12481246
1249- this ->applySelection (textcursor, line, Hex );
1247+ this ->applyHexSelection (textcursor, line);
12501248 this ->applyCursorHex (textcursor, line);
12511249
12521250 painter->save ();
@@ -1256,12 +1254,12 @@ void QHexRenderer::drawHex(QPainter *painter, const QRect &linerect,
12561254 ctx.palette .setColor (QPalette::Text, m_bytesColor);
12571255 textdocument.documentLayout ()->draw (painter, ctx);
12581256
1259- this ->applyBookMark (painter, textcursor, line, Hex );
1257+ this ->applyHexBookMark (painter, textcursor, line);
12601258 painter->restore ();
12611259}
12621260
1263- void QHexRenderer::applyBookMark (QPainter *painter, QTextCursor &textcursor,
1264- qsizetype line, Factor factor ) {
1261+ void QHexRenderer::applyHexBookMark (QPainter *painter, QTextCursor &textcursor,
1262+ qsizetype line ) {
12651263
12661264 if (!m_document->lineHasBookMark (line))
12671265 return ;
@@ -1275,18 +1273,11 @@ void QHexRenderer::applyBookMark(QPainter *painter, QTextCursor &textcursor,
12751273 auto off = item % hexLineWidth ();
12761274
12771275 qreal begin, width;
1278-
12791276 // add some paddings
1280- if (factor == Hex) {
1281- begin = getCellWidth () * off * 3 + 1 ;
1282- begin += getCellWidth () / 2 ;
1283- width = getCellWidth () * 2 ;
1284- textcursor.setPosition (off * factor);
1285- } else {
1286- begin = getCellWidth () * off + 1 ;
1287- width = getCellWidth ();
1288- textcursor.setPosition (m_cursor->currentColumn ());
1289- }
1277+ begin = getCellWidth () * off * 3 + 1 ;
1278+ begin += getCellWidth () / 2 ;
1279+ width = getCellWidth () * 2 ;
1280+ textcursor.setPosition (off * Hex);
12901281
12911282 textcursor.movePosition (QTextCursor::NextCharacter);
12921283 auto charformat = textcursor.charFormat ();
@@ -1343,7 +1334,7 @@ QRect QHexRenderer::byteRectAt(qreal cellWidth, int height,
13431334 return QRect (x, 0 , w, height);
13441335}
13451336
1346- void QHexRenderer::drawBookmarkRect (QPainter *painter, qreal cellWidth,
1337+ void QHexRenderer::applyStrBookmark (QPainter *painter, qreal cellWidth,
13471338 int height, int byteIndex,
13481339 const QColor &fallbackColor) const {
13491340 QRect byteRect = byteRectAt (cellWidth, height, byteIndex);
@@ -1514,7 +1505,7 @@ void QHexRenderer::drawString(QPainter *painter, const QRect &linerect,
15141505 if (!hasBookmark (line, byteIndex)) {
15151506 continue ;
15161507 }
1517- drawBookmarkRect (painter, cellWidth, height, byteIndex,
1508+ applyStrBookmark (painter, cellWidth, height, byteIndex,
15181509 prepared.formats .at (i).foreground );
15191510 }
15201511
@@ -1531,7 +1522,7 @@ void QHexRenderer::drawString(QPainter *painter, const QRect &linerect,
15311522 if (!hasBookmark (line, byteIndex)) {
15321523 continue ;
15331524 }
1534- drawBookmarkRect (painter, cellWidth, height, byteIndex,
1525+ applyStrBookmark (painter, cellWidth, height, byteIndex,
15351526 prepared.formats .at (i).foreground );
15361527 }
15371528 }
0 commit comments