mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-18 19:06:10 +00:00
Use AddressableItemContextMenu in Registers widgtet. (#1794)
* Use AddressableItemContextMenu in Registers widgtet. * Hide shortcuts becasue they can't be used in register widget.
This commit is contained in:
parent
59161e633f
commit
1cef190d29
@ -10,7 +10,8 @@
|
||||
|
||||
RegistersWidget::RegistersWidget(MainWindow *main, QAction *action) :
|
||||
CutterDockWidget(main, action),
|
||||
ui(new Ui::RegistersWidget)
|
||||
ui(new Ui::RegistersWidget),
|
||||
addressContextMenu(this, main)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
@ -24,6 +25,12 @@ RegistersWidget::RegistersWidget(MainWindow *main, QAction *action) :
|
||||
|
||||
connect(Core(), &CutterCore::refreshAll, this, &RegistersWidget::updateContents);
|
||||
connect(Core(), &CutterCore::registersChanged, this, &RegistersWidget::updateContents);
|
||||
|
||||
// Hide shortcuts because there is no way of selecting an item and triger them
|
||||
for (auto &action : addressContextMenu.actions()) {
|
||||
action->setShortcut(QKeySequence());
|
||||
// setShortcutVisibleInContextMenu(false) doesn't work
|
||||
}
|
||||
}
|
||||
|
||||
RegistersWidget::~RegistersWidget() = default;
|
||||
@ -63,6 +70,14 @@ void RegistersWidget::setRegisterGrid()
|
||||
registerEditValue = new QLineEdit;
|
||||
registerEditValue->setFixedWidth(140);
|
||||
registerEditValue->setFont(Config()->getFont());
|
||||
registerLabel->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(registerLabel, &QWidget::customContextMenuRequested, this, [this, registerEditValue, registerLabel](QPoint p){
|
||||
openContextMenu(registerLabel->mapToGlobal(p), registerEditValue->text());
|
||||
});
|
||||
registerEditValue->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(registerEditValue, &QWidget::customContextMenuRequested, this, [this, registerEditValue](QPoint p){
|
||||
openContextMenu(registerEditValue->mapToGlobal(p), registerEditValue->text());
|
||||
});
|
||||
// add label and register value to grid
|
||||
registerLayout->addWidget(registerLabel, i, col);
|
||||
registerLayout->addWidget(registerEditValue, i, col + 1);
|
||||
@ -98,9 +113,15 @@ void RegistersWidget::setRegisterGrid()
|
||||
registerEditValue->setText(regValue);
|
||||
i++;
|
||||
// decide if we should change column
|
||||
if (i >= registerLen / numCols + 1) {
|
||||
if (i >= (registerLen + numCols - 1) / numCols) {
|
||||
i = 0;
|
||||
col += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RegistersWidget::openContextMenu(QPoint point, QString address)
|
||||
{
|
||||
addressContextMenu.setTarget(address.toULongLong(nullptr, 16));
|
||||
addressContextMenu.exec(point);
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include "core/Cutter.h"
|
||||
#include "CutterDockWidget.h"
|
||||
#include "menus/AddressableItemContextMenu.h"
|
||||
|
||||
class MainWindow;
|
||||
|
||||
@ -26,11 +27,13 @@ public:
|
||||
private slots:
|
||||
void updateContents();
|
||||
void setRegisterGrid();
|
||||
void openContextMenu(QPoint point, QString address);
|
||||
|
||||
private:
|
||||
std::unique_ptr<Ui::RegistersWidget> ui;
|
||||
QGridLayout *registerLayout = new QGridLayout;
|
||||
AddressableItemContextMenu addressContextMenu;
|
||||
int numCols = 2;
|
||||
int registerLen = 0;
|
||||
RefreshDeferrer *refreshDeferrer;
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user