mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-20 20:06:12 +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) :
|
RegistersWidget::RegistersWidget(MainWindow *main, QAction *action) :
|
||||||
CutterDockWidget(main, action),
|
CutterDockWidget(main, action),
|
||||||
ui(new Ui::RegistersWidget)
|
ui(new Ui::RegistersWidget),
|
||||||
|
addressContextMenu(this, main)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
@ -24,6 +25,12 @@ RegistersWidget::RegistersWidget(MainWindow *main, QAction *action) :
|
|||||||
|
|
||||||
connect(Core(), &CutterCore::refreshAll, this, &RegistersWidget::updateContents);
|
connect(Core(), &CutterCore::refreshAll, this, &RegistersWidget::updateContents);
|
||||||
connect(Core(), &CutterCore::registersChanged, 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;
|
RegistersWidget::~RegistersWidget() = default;
|
||||||
@ -63,6 +70,14 @@ void RegistersWidget::setRegisterGrid()
|
|||||||
registerEditValue = new QLineEdit;
|
registerEditValue = new QLineEdit;
|
||||||
registerEditValue->setFixedWidth(140);
|
registerEditValue->setFixedWidth(140);
|
||||||
registerEditValue->setFont(Config()->getFont());
|
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
|
// add label and register value to grid
|
||||||
registerLayout->addWidget(registerLabel, i, col);
|
registerLayout->addWidget(registerLabel, i, col);
|
||||||
registerLayout->addWidget(registerEditValue, i, col + 1);
|
registerLayout->addWidget(registerEditValue, i, col + 1);
|
||||||
@ -98,9 +113,15 @@ void RegistersWidget::setRegisterGrid()
|
|||||||
registerEditValue->setText(regValue);
|
registerEditValue->setText(regValue);
|
||||||
i++;
|
i++;
|
||||||
// decide if we should change column
|
// decide if we should change column
|
||||||
if (i >= registerLen / numCols + 1) {
|
if (i >= (registerLen + numCols - 1) / numCols) {
|
||||||
i = 0;
|
i = 0;
|
||||||
col += 2;
|
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 "core/Cutter.h"
|
||||||
#include "CutterDockWidget.h"
|
#include "CutterDockWidget.h"
|
||||||
|
#include "menus/AddressableItemContextMenu.h"
|
||||||
|
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
|
|
||||||
@ -26,10 +27,12 @@ public:
|
|||||||
private slots:
|
private slots:
|
||||||
void updateContents();
|
void updateContents();
|
||||||
void setRegisterGrid();
|
void setRegisterGrid();
|
||||||
|
void openContextMenu(QPoint point, QString address);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Ui::RegistersWidget> ui;
|
std::unique_ptr<Ui::RegistersWidget> ui;
|
||||||
QGridLayout *registerLayout = new QGridLayout;
|
QGridLayout *registerLayout = new QGridLayout;
|
||||||
|
AddressableItemContextMenu addressContextMenu;
|
||||||
int numCols = 2;
|
int numCols = 2;
|
||||||
int registerLen = 0;
|
int registerLen = 0;
|
||||||
RefreshDeferrer *refreshDeferrer;
|
RefreshDeferrer *refreshDeferrer;
|
||||||
|
Loading…
Reference in New Issue
Block a user