-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tooltip for displaying flag and comment in hexdump (#1471) #2116
Changes from 1 commit
08867b7
5fd4aaf
acabc81
f25106d
e872187
f433ad3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
#include <QJsonObject> | ||
#include <QJsonArray> | ||
#include <QRegularExpression> | ||
#include <QToolTip> | ||
|
||
static constexpr uint64_t MAX_COPY_SIZE = 128 * 1024 * 1024; | ||
static constexpr int MAX_LINE_WIDTH_PRESET = 32; | ||
|
@@ -467,6 +468,15 @@ void HexWidget::mouseMoveEvent(QMouseEvent *event) | |
QPoint pos = event->pos(); | ||
pos.rx() += horizontalScrollBar()->value(); | ||
|
||
auto addr = currentAreaPosToAddr(pos, true); | ||
|
||
QString ret = getFlagAndComment(addr.address); | ||
karliss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!ret.isEmpty() && itemArea.contains(pos)) { | ||
QToolTip::showText(event->globalPos(), ret, this); | ||
} else { | ||
QToolTip::hideText(); | ||
} | ||
|
||
if (!updatingSelection) { | ||
if (itemArea.contains(pos) || asciiArea.contains(pos)) | ||
setCursor(Qt::IBeamCursor); | ||
|
@@ -480,7 +490,6 @@ void HexWidget::mouseMoveEvent(QMouseEvent *event) | |
pos.setX(area.left()); | ||
else if (pos.x() > area.right()) | ||
pos.setX(area.right()); | ||
auto addr = currentAreaPosToAddr(pos, true); | ||
setCursorAddr(addr, true); | ||
|
||
/* Stop blinking */ | ||
|
@@ -1010,6 +1019,11 @@ void HexWidget::drawItemArea(QPainter &painter) | |
for (int j = 0; j < itemColumns; ++j) { | ||
for (int k = 0; k < itemGroupSize && itemAddr <= data->maxIndex(); ++k, itemAddr += itemByteLen) { | ||
itemString = renderItem(itemAddr - startAddress, &itemColor); | ||
|
||
if (!getFlagAndComment(itemAddr).isEmpty()) { | ||
painter.setPen(QColor(255, 255, 0)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hardcoded color doesn't honor theme. Use the "borderColor" variable which equals to Also, the solution does not support padding, the border is too narrow and covers the font. Check the margin in the selection implementation. Also, does not support flag-size. Some flags are too big though (like sections) and it would be crazy to have them shown. In 010 Editor flags are only shown when hovering. So you don't know that there is a flag there until hovering with the mouse. But then, it shows the mark very softly, with brackets, and I like this: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ITAYC0HEN Your comment about size support seems somewhat contradicting. Do you want the size to be displayed only if it's small? I don't think it's worth implementing proper size handling specifically for this without making the generic mechanism described in https://github.com/radareorg/cutter/issues/1945#issuecomment-598440589 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, I have addressed other changes but I'm not quite clear about the way the flags should be displayed and also, about supporting flag-size. This is what it looks like now: I have used |
||
painter.drawRect(itemRect); | ||
} | ||
if (selection.contains(itemAddr) && !cursorOnAscii) { | ||
itemColor = palette().highlightedText().color(); | ||
} | ||
|
@@ -1454,6 +1468,38 @@ QChar HexWidget::renderAscii(int offset, QColor *color) | |
return QChar(byte); | ||
} | ||
|
||
QString HexWidget::getFlagAndComment(uint64_t address) | ||
ITAYC0HEN marked this conversation as resolved.
Show resolved
Hide resolved
karliss marked this conversation as resolved.
Show resolved
Hide resolved
karliss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
QString ret = ""; | ||
QString flagName = ""; | ||
|
||
RCore *core = Core()->core(); | ||
RFlagItem *f = r_flag_get_i (core->flags, address); | ||
karliss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (f) { | ||
// Check if Realname is enabled. If yes, show it instead of the full flag-name. | ||
if (Config()->getConfigBool("asm.flags.real") && f->realname) { | ||
flagName = f->realname; | ||
} else { | ||
flagName = f->name; | ||
} | ||
|
||
ret = "Flag: " + flagName.trimmed(); | ||
} | ||
|
||
QString comment = Core()->cmd("CC." + RAddressString(address)); | ||
karliss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (!(comment.isNull() || comment.isEmpty())) { | ||
karliss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (ret.isEmpty()) { | ||
ret = "Comment: " + comment.trimmed(); | ||
} else { | ||
ret += "\nComment: " + comment.trimmed(); | ||
} | ||
karliss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
return ret; | ||
} | ||
|
||
void HexWidget::fetchData() | ||
{ | ||
data.swap(oldData); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For tooltip it's better to use
mousePosToAddr(pos, false)
.mousePosToAddr
because tooltip shouldn't be affect which part hex or text was last clicked. Try clicking on text side and then hover over flag or comment on the hex side to see the difference.For
middle=false
see the documentation commnent.In this case you are interested in "symbol under cursor"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if mouse is in any of relevant areas would also be helpful.you are already doing that. It should would be better to do that as early as possible before operating with address obtained using bad mouse position.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, what about using mouseHoverEvent instead of mouseMoveEvent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think mouseHover is appropriate in this case, but
QEvent::ToolTip
could be.