Skip to content

Commit

Permalink
feat: Added right click menu to copy pointer address in Edit Address …
Browse files Browse the repository at this point in the history
…widget

Added a right click menu to m_pointerWidget which activates only if an address label is right clicked. It provides a single option (Copy address) which copies the address from that pointer level to clipboard.

ref: #160
  • Loading branch information
jahorta committed Jul 7, 2024
1 parent 277ff8d commit 17ed8bf
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Source/GUI/MemWatcher/Dialogs/DlgAddWatchEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include <QHBoxLayout>
#include <QMessageBox>
#include <QVBoxLayout>
#include <QMenu>
#include <QApplication>
#include <QClipboard>
#include <sstream>

#include "../../../DolphinProcess/DolphinAccessor.h"
Expand Down Expand Up @@ -58,6 +61,9 @@ void DlgAddWatchEntry::initialiseWidgets()
connect(m_btnRemoveOffset, &QPushButton::clicked, this, &DlgAddWatchEntry::removePointerOffset);

m_pointerWidget = new QGroupBox("Offsets (in hex)", this);
m_pointerWidget->setContextMenuPolicy(Qt::CustomContextMenu);
connect(m_pointerWidget, &QWidget::customContextMenuRequested, this,
&DlgAddWatchEntry::onPointerOffsetContextMenuRequested);

m_txbLabel = new QLineEdit(this);

Expand Down Expand Up @@ -424,3 +430,32 @@ MemWatchEntry* DlgAddWatchEntry::stealEntry()
m_entry = nullptr;
return entry;
}

void DlgAddWatchEntry::onPointerOffsetContextMenuRequested(const QPoint& pos)
{
QMenu* contextMenu = new QMenu(this);

for (int i = 0; i < m_offsetsLayout->rowCount(); i++)
{
QLabel* lbl = (QLabel*)m_offsetsLayout->itemAtPosition(i, 2)->widget();

QPoint click_pos = lbl->mapFrom(m_pointerWidget, pos);
int xPos = click_pos.x();
int yPos = click_pos.y();

if (0 < yPos && yPos < lbl->height() && 0 < xPos && xPos < lbl->width())
{
QAction* copyAddr = new QAction(tr("&Copy Address"), this);
connect(copyAddr, &QAction::triggered, this, [this, lbl] {
QApplication::clipboard()->setText(lbl->text().mid(4, lbl->text().length() - 4));
});
contextMenu->addAction(copyAddr);
if (lbl->text().contains(QString("??")))
{
copyAddr->setEnabled(false);
}
contextMenu->popup(lbl->mapToGlobal(click_pos));
break;
}
}
}
1 change: 1 addition & 0 deletions Source/GUI/MemWatcher/Dialogs/DlgAddWatchEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class DlgAddWatchEntry : public QDialog
void addPointerOffset();
void removePointerOffset();
void removeAllPointerOffset();
void onPointerOffsetContextMenuRequested(const QPoint& pos);

MemWatchEntry* m_entry{};
AddressInputWidget* m_txbAddress{};
Expand Down

0 comments on commit 17ed8bf

Please sign in to comment.