-
-
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
Conversation
Hi @karliss, please review if this conforms with the expected design behavior. |
src/widgets/HexWidget.cpp
Outdated
@@ -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 comment
The 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 Config()->getColor("gui.border");
. I suggest to try it with alpha 50% to reduce noise.
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 comment
The 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 comment
The 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 r_flag_get_liststr(RFlag *f, ut64 off)
which returns a comma-separated list of flags and also, uses an ellipsis for a flag. Would this be the right way to display them or, is something else expected here?
src/widgets/HexWidget.cpp
Outdated
@@ -467,6 +468,15 @@ void HexWidget::mouseMoveEvent(QMouseEvent *event) | |||
QPoint pos = event->pos(); | |||
pos.rx() += horizontalScrollBar()->value(); | |||
|
|||
auto addr = currentAreaPosToAddr(pos, true); |
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.
* @param middle start next position from middle of symbol. Use middle=true for vertical cursror position between symbols, middle=false for insert mode cursor and getting symbol under cursor.
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.
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.
My overall opinion is that when the generic mechanism gets implemented this will have to be more or less rewritten. This PR still provides useful functionality and could be merged after dealing with the review comment but keeping in mind rewrite this isn't the right place for spending too much time on handling the tricky cases.
src/widgets/HexWidget.cpp
Outdated
@@ -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 comment
The 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
Hi, I have handled the review changes and also, updated the test plan. Please provide your feedback regarding the way the flags are displayed and in general, about the other changes too. Thanks. |
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.
Good work, almost done :))
src/widgets/HexWidget.cpp
Outdated
|
||
QString metaData = getFlagAndComment(mouseAddr); | ||
if (!metaData.isEmpty() && itemArea.contains(pos)) { | ||
QToolTip::showText(event->globalPos(), metaData, this); |
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.
Please add a space after each comma. "item1,item2,item3" -> "item1, item2, item3"
Hi, I have made the remaining changes:). |
6db631b
to
f25106d
Compare
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.
Good work. Almost there :)
@@ -775,6 +775,11 @@ void CutterCore::delComment(RVA addr) | |||
emit commentsChanged(); | |||
} | |||
|
|||
QString CutterCore::getCommentAt(RVA addr) |
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.
docstrings :) Try to not forget to document everything. This was a decision we made not so long ago, and this is why you see a lot of undocumented places in the code. Please pay attention to this :)
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.
Sure, I'll keep that in mind. Yeah, looking at other places in the code, I wasn't sure about what all is supposed to be documented.
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.
everything :) Every function, and every coding decision that might not be clear for the reader
I have added the changes:). |
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.
Thank you! Good work :)
In a simple PR, you got the opportunity to understand the code base of cutter, how it interacts with radare2 via commands. You learned about CmdRaw and CmdRawAt and why they're a good practice. You learned about the importance of documentation and the usage of dynamic variables instead of hard-coded (for border color)
Good work!
Yes, indeed. Thank you for guiding me through this:). |
Co-Authored-By: karliss <[email protected]>
Your checklist for this pull request
Detailed description
Functional Changes
Code Changes
HexWidget.cpp:
getFlagAndComment(uint64_t address)
to retrieve the flag and comment for an address.r_flag_get_liststr (core->flags, address)
Core()->cmdRawAt("CC.", address)
drawItemArea(QPainter &painter)
function with available flag/comment.Test plan (required)
Marked position of comment or flag using the borderColor with alpha 50% in the hex section
Both flag and comment are present:
Only the flag is present:
Only the Comment is present:
Closing issues
Closes #1471