Skip to content

Commit 044d454

Browse files
committed
Unification of area margins
1 parent f2924f1 commit 044d454

2 files changed

Lines changed: 14 additions & 18 deletions

File tree

src/qhexedit.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ void QHexEdit::setCursorPosition(qint64 position)
158158
_pxCursorX = x / 2 * _pxCharWidth + _pxPosAsciiX;
159159
_cursorPosition = position & 0xFFFFFFFFFFFFFFFE;
160160
} else {
161-
_pxCursorX = (((x / 2) * 3) + (x % 2) + 1) * _pxCharWidth + _pxPosHexX;
161+
_pxCursorX = (((x / 2) * 3) + (x % 2)) * _pxCharWidth + _pxPosHexX;
162162
_cursorPosition = position;
163163
}
164164

@@ -438,9 +438,7 @@ void QHexEdit::setFont(const QFont &font)
438438
_pxCharWidth = metrics.width(QLatin1Char('2'));
439439
#endif
440440
_pxCharHeight = metrics.height();
441-
_pxGapAdr = _pxCharWidth / 2;
442-
_pxGapAdrHex = _pxCharWidth;
443-
_pxGapHexAscii = 2 * _pxCharWidth;
441+
_pxAreaMargin = _pxCharWidth / 2;
444442
_pxCursorWidth = _pxCharHeight / 7;
445443
_pxSelectionSub = _pxCharHeight / 5;
446444
viewport()->update();
@@ -861,9 +859,9 @@ void QHexEdit::paintEvent(QPaintEvent *event)
861859
{
862860
painter.fillRect(
863861
QRect(
864-
pxPosAsciiX2,
862+
pxPosAsciiX2 - _pxAreaMargin,
865863
event->rect().top(),
866-
_pxCharWidth * _bytesPerLine,
864+
_pxCharWidth * _bytesPerLine + 2 * _pxAreaMargin,
867865
height()
868866
),
869867
_colorManager->notMarked(Area::Ascii).areaStyle()
@@ -875,7 +873,7 @@ void QHexEdit::paintEvent(QPaintEvent *event)
875873
{
876874
QByteArray hex;
877875
qint64 bPosLine = row * _bytesPerLine;
878-
int pxPosX = _pxPosHexX - pxOfsX + _pxCharWidth;
876+
int pxPosX = _pxPosHexX - pxOfsX;
879877
int pxPosAsciiX2 = _pxPosAsciiX - pxOfsX;
880878

881879
// *** address info
@@ -987,17 +985,17 @@ void QHexEdit::resizeEvent(QResizeEvent *)
987985
{
988986
int pxFixGaps = 0;
989987
if (_addressArea)
990-
pxFixGaps = addressWidth() * _pxCharWidth + _pxGapAdr;
991-
pxFixGaps += _pxGapAdrHex;
988+
pxFixGaps = addressWidth() * _pxCharWidth + 2 * _pxAreaMargin;
989+
pxFixGaps += 2 * _pxAreaMargin;
992990
if (_asciiArea)
993-
pxFixGaps += _pxGapHexAscii;
991+
pxFixGaps += 2 * _pxAreaMargin;
994992

995993
// +1 because the last hex value do not have space. so it is effective one char more
996994
int charWidth = (viewport()->width() - pxFixGaps ) / _pxCharWidth + 1;
997995

998996
// 2 hex alfa-digits 1 space 1 ascii per byte = 4; if ascii is disabled then 3
999997
// to prevent devision by zero use the min value 1
1000-
setBytesPerLine(std::max(charWidth / (_asciiArea ? 4 : 3),1));
998+
setBytesPerLine(std::max(charWidth / (_asciiArea ? 4 : 3), 1));
1001999
}
10021000
adjust();
10031001
}
@@ -1094,12 +1092,12 @@ void QHexEdit::adjust()
10941092
if (_addressArea)
10951093
{
10961094
_addrDigits = addressWidth();
1097-
_pxPosHexX = _pxGapAdr + _addrDigits*_pxCharWidth + _pxGapAdrHex;
1095+
_pxPosHexX = _pxAreaMargin + _addrDigits*_pxCharWidth + 2 * _pxAreaMargin;
10981096
}
10991097
else
1100-
_pxPosHexX = _pxGapAdrHex;
1101-
_pxPosAdrX = _pxGapAdr;
1102-
_pxPosAsciiX = _pxPosHexX + _hexCharsInLine * _pxCharWidth + _pxGapHexAscii;
1098+
_pxPosHexX = _pxAreaMargin;
1099+
_pxPosAdrX = _pxAreaMargin;
1100+
_pxPosAsciiX = _pxPosHexX + _hexCharsInLine * _pxCharWidth + 2 * _pxAreaMargin;
11031101

11041102
// set horizontalScrollBar()
11051103
int pxWidth = _pxPosAsciiX;

src/qhexedit.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,7 @@ private slots:
368368
int _pxPosHexX; // X-Pos of HeaxArea
369369
int _pxPosAdrX; // X-Pos of Address Area
370370
int _pxPosAsciiX; // X-Pos of Ascii Area
371-
int _pxGapAdr; // gap left from AddressArea
372-
int _pxGapAdrHex; // gap between AddressArea and HexAerea
373-
int _pxGapHexAscii; // gap between HexArea and AsciiArea
371+
int _pxAreaMargin; // gap left and right from areas
374372
int _pxCursorWidth; // cursor width
375373
int _pxSelectionSub; // offset selection rect
376374
int _pxCursorX; // current cursor pos

0 commit comments

Comments
 (0)