Skip to content

Commit

Permalink
Add tooltip for displaying flag and comment in hexdump (rizinorg#1471)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhavalpur0hit committed Mar 28, 2020
1 parent b06a6d0 commit 08867b7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
48 changes: 47 additions & 1 deletion src/widgets/HexWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
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);
Expand All @@ -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 */
Expand Down Expand Up @@ -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));
painter.drawRect(itemRect);
}
if (selection.contains(itemAddr) && !cursorOnAscii) {
itemColor = palette().highlightedText().color();
}
Expand Down Expand Up @@ -1454,6 +1468,38 @@ QChar HexWidget::renderAscii(int offset, QColor *color)
return QChar(byte);
}

QString HexWidget::getFlagAndComment(uint64_t address)
{
QString ret = "";
QString flagName = "";

RCore *core = Core()->core();
RFlagItem *f = r_flag_get_i (core->flags, address);

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

if (!(comment.isNull() || comment.isEmpty())) {
if (ret.isEmpty()) {
ret = "Comment: " + comment.trimmed();
} else {
ret += "\nComment: " + comment.trimmed();
}
}

return ret;
}

void HexWidget::fetchData()
{
data.swap(oldData);
Expand Down
1 change: 1 addition & 0 deletions src/widgets/HexWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ private slots:
QVariant readItem(int offset, QColor *color = nullptr);
QString renderItem(int offset, QColor *color = nullptr);
QChar renderAscii(int offset, QColor *color = nullptr);
QString getFlagAndComment(uint64_t address);
/**
* @brief Get the location on which operations such as Writing should apply.
* @return Start of selection if multiple bytes are selected. Otherwise, the curren seek of the widget.
Expand Down

0 comments on commit 08867b7

Please sign in to comment.