Skip to content
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

Merged
merged 6 commits into from
Apr 4, 2020

Conversation

dhavalpur0hit
Copy link
Contributor

@dhavalpur0hit dhavalpur0hit commented Mar 28, 2020

Your checklist for this pull request

Detailed description

Functional Changes

  • Mark and show the available flags and comments in a tooltip in the hex dump.

Code Changes
HexWidget.cpp:

  • Created a new function getFlagAndComment(uint64_t address) to retrieve the flag and comment for an address.
    • Fetched all the flags info for the address using r_flag_get_liststr (core->flags, address)
    • Fetched the comments for the address using Core()->cmdRawAt("CC.", address)
  • Marked the address in the drawItemArea(QPainter &painter) function with available flag/comment.
  • Added the tooltip in mouseMoveEvent(QMouseEvent *event) to display flag/comment on hover.

Test plan (required)

  • Marked position of comment or flag using the borderColor with alpha 50% in the hex section
    hexdump

  • Both flag and comment are present:
    hexdump-final

  • Only the flag is present:
    hex-dump-final-2

  • Only the Comment is present:
    hexdump-3

Closing issues
Closes #1471

@dhavalpur0hit
Copy link
Contributor Author

Hi @karliss, please review if this conforms with the expected design behavior.

src/widgets/HexWidget.cpp Outdated Show resolved Hide resolved
src/widgets/HexWidget.cpp Outdated Show resolved Hide resolved
src/widgets/HexWidget.cpp Outdated Show resolved Hide resolved
src/widgets/HexWidget.cpp Outdated Show resolved Hide resolved
src/widgets/HexWidget.cpp Outdated Show resolved Hide resolved
@@ -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));
Copy link
Member

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:
image

Copy link
Member

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

Copy link
Contributor Author

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:

hexdump-new

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?

@@ -467,6 +468,15 @@ void HexWidget::mouseMoveEvent(QMouseEvent *event)
QPoint pos = event->pos();
pos.rx() += horizontalScrollBar()->value();

auto addr = currentAreaPosToAddr(pos, true);
Copy link
Member

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"

Copy link
Member

@karliss karliss Mar 28, 2020

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.

Copy link
Member

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?

Copy link
Member

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.

Copy link
Member

@karliss karliss left a 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 Show resolved Hide resolved
@@ -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));
Copy link
Member

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

@dhavalpur0hit
Copy link
Contributor Author

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.

Copy link
Member

@ITAYC0HEN ITAYC0HEN left a 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 Show resolved Hide resolved

QString metaData = getFlagAndComment(mouseAddr);
if (!metaData.isEmpty() && itemArea.contains(pos)) {
QToolTip::showText(event->globalPos(), metaData, this);
Copy link
Member

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"

src/widgets/HexWidget.cpp Outdated Show resolved Hide resolved
@dhavalpur0hit
Copy link
Contributor Author

Hi, I have made the remaining changes:).

Copy link
Member

@ITAYC0HEN ITAYC0HEN left a 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 :)

src/widgets/HexWidget.cpp Outdated Show resolved Hide resolved
src/widgets/HexWidget.cpp Outdated Show resolved Hide resolved
@@ -775,6 +775,11 @@ void CutterCore::delComment(RVA addr)
emit commentsChanged();
}

QString CutterCore::getCommentAt(RVA addr)
Copy link
Member

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 :)

Copy link
Contributor Author

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.

Copy link
Member

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

@dhavalpur0hit
Copy link
Contributor Author

I have added the changes:).

Copy link
Member

@ITAYC0HEN ITAYC0HEN left a 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!

@dhavalpur0hit
Copy link
Contributor Author

Yes, indeed. Thank you for guiding me through this:).

src/core/Cutter.cpp Outdated Show resolved Hide resolved
@ITAYC0HEN ITAYC0HEN merged commit 7110d73 into rizinorg:master Apr 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mark available flags and available comments in hexdump
3 participants