@@ -131,6 +131,19 @@ void HexWidget::setOffset(int offset) {
131
131
}
132
132
133
133
void HexWidget::setCursorOffset (int offset, bool selection) {
134
+ setCursorOffset (offset, selection, true );
135
+ }
136
+
137
+ void HexWidget::setHighlight (const int address) {
138
+ const int normalized = address < 0 ? -1 : address;
139
+ if (m_highlightedAddr == normalized) {
140
+ return ;
141
+ }
142
+ m_highlightedAddr = normalized;
143
+ viewport ()->update ();
144
+ }
145
+
146
+ void HexWidget::setCursorOffset (int offset, bool selection, bool clearHighlight) {
134
147
if (offset > m_size * 2 ) {
135
148
offset = m_size * 2 ;
136
149
}
@@ -141,6 +154,10 @@ void HexWidget::setCursorOffset(int offset, bool selection) {
141
154
resetSelection ();
142
155
}
143
156
157
+ if (clearHighlight) {
158
+ m_highlightedAddr = -1 ;
159
+ }
160
+
144
161
m_cursorOffset = offset;
145
162
adjust ();
146
163
showCursor ();
@@ -254,18 +271,19 @@ void HexWidget::setSelection(int addr) {
254
271
addr = 0 ;
255
272
}
256
273
257
- if (m_selectStart == -1 ) {
258
- m_selectStart = addr;
259
- m_selectEnd = addr;
260
- m_selectLen = 0 ;
274
+ if (m_selectAnchor == -1 ) {
275
+ m_selectAnchor = addr;
261
276
}
262
- if (addr > m_selectStart) {
277
+
278
+ if (addr >= m_selectAnchor) {
279
+ m_selectStart = m_selectAnchor;
263
280
m_selectEnd = addr;
264
- m_selectLen = addr - m_selectStart + 1 ;
265
281
} else {
266
282
m_selectStart = addr;
267
- m_selectLen = m_selectEnd - addr + 1 ;
283
+ m_selectEnd = m_selectAnchor ;
268
284
}
285
+
286
+ m_selectLen = (m_selectStart == -1 || m_selectEnd == -1 ) ? 0 : (m_selectEnd - m_selectStart + 1 );
269
287
}
270
288
271
289
void HexWidget::undo () {
@@ -310,12 +328,27 @@ void HexWidget::paintEvent(QPaintEvent *event) {
310
328
const QColor &cSelected = pal.color (QPalette::Highlight);
311
329
const QColor cModified = QColor (Qt::blue).lighter (160 );
312
330
const QColor cBoth = QColor (Qt::green).lighter (160 );
331
+ const bool darkMode = isRunningInDarkMode ();
332
+ const QColor boxBorder = darkMode ? QColor (0xdb , 0xdb , 0xdb ) : QColor (0x66 , 0x66 , 0x66 );
333
+ QColor boxFill = darkMode ? QColor (0x55 , 0x55 , 0x55 ) : QColor (0xd0 , 0xd0 , 0xd0 );
334
+ boxFill.setAlpha (140 );
313
335
const int xOffset = horizontalScrollBar ()->value ();
314
336
const int xAddr = m_addrLoc - xOffset;
315
337
316
338
painter.setRenderHint (QPainter::Antialiasing);
317
339
painter.fillRect (region, cBg);
318
340
341
+ const auto drawHighlightBox = [&](const QRect &rect) {
342
+ if (!rect.isValid () || rect.isNull ()) {
343
+ return ;
344
+ }
345
+ painter.save ();
346
+ painter.setPen (QPen (boxBorder, 1 ));
347
+ painter.setBrush (boxFill);
348
+ painter.drawRoundedRect (rect.adjusted (0 , 0 , -1 , -1 ), 2 , 2 );
349
+ painter.restore ();
350
+ };
351
+
319
352
painter.setPen (Qt::gray);
320
353
painter.drawLine (m_dataLine - xOffset, region.top (), m_dataLine - xOffset, height ());
321
354
if (m_asciiArea) {
@@ -338,6 +371,22 @@ void HexWidget::paintEvent(QPaintEvent *event) {
338
371
uint8_t flags = debug.addr [addr + m_base];
339
372
bool selected = addr >= m_selectStart && addr <= m_selectEnd;
340
373
bool modified = !m_modified.isEmpty () && m_modified[addr];
374
+ const bool highlighted = m_highlightedAddr >= 0 && (m_base + addr) == m_highlightedAddr;
375
+ const int xDataStart = xData;
376
+ const int xAsciiStart = xAscii;
377
+ QRect dataHighlightRect;
378
+ QRect asciiHighlightRect;
379
+
380
+ if (highlighted) {
381
+ if (!col) {
382
+ dataHighlightRect.setRect (xDataStart, y - m_charHeight + m_margin, 2 * m_charWidth + 3 , m_charHeight);
383
+ } else {
384
+ dataHighlightRect.setRect (xDataStart - m_charWidth, y - m_charHeight + m_margin, 3 * m_charWidth + 3 , m_charHeight);
385
+ }
386
+ if (m_asciiArea) {
387
+ asciiHighlightRect.setRect (xAsciiStart, y - m_charHeight + m_margin, m_charWidth + 1 , m_charHeight);
388
+ }
389
+ }
341
390
342
391
QFont font = painter.font ();
343
392
const QFont fontorig = painter.font ();
@@ -367,6 +416,10 @@ void HexWidget::paintEvent(QPaintEvent *event) {
367
416
painter.fillRect (r, modified ? selected ? cBoth : cModified : cSelected);
368
417
}
369
418
419
+ if (highlighted) {
420
+ drawHighlightBox (dataHighlightRect);
421
+ }
422
+
370
423
QString hex = int2hex (data, 2 );
371
424
if ((flags & DBG_MASK_READ) && (flags & DBG_MASK_WRITE)) {
372
425
painter.setPen (Qt::darkGreen);
@@ -391,6 +444,9 @@ void HexWidget::paintEvent(QPaintEvent *event) {
391
444
r.setRect (xAscii, y - m_charHeight + m_margin, m_charWidth, m_charHeight);
392
445
painter.fillRect (r, modified ? selected ? cBoth : cModified : cSelected);
393
446
}
447
+ if (highlighted) {
448
+ drawHighlightBox (asciiHighlightRect);
449
+ }
394
450
painter.drawText (xAscii, y, QChar (ch));
395
451
xAscii += m_charWidth;
396
452
}
@@ -421,6 +477,9 @@ void HexWidget::mousePressEvent(QMouseEvent *event) {
421
477
int addr = getPosition (event->pos ());
422
478
if (addr >= 0 ) {
423
479
setCursorOffset (addr, true );
480
+ m_selectAnchor = addr / 2 ;
481
+ m_selectStart = m_selectEnd = -1 ;
482
+ m_selectLen = 0 ;
424
483
}
425
484
}
426
485
0 commit comments