Made addressLabelType changeable via context menu

This commit is contained in:
Nav
2022-09-11 01:50:36 +01:00
parent 8574918f81
commit 463b57ec83
5 changed files with 74 additions and 0 deletions

View File

@@ -454,3 +454,14 @@ QScrollBar::sub-line:vertical {
width: 12px;
margin: 1px 3px 1px 0px;
}
#hex-viewer-container #byte-item-address-container-context-menu.QMenu,
#hex-viewer-container #byte-item-address-container-context-menu QMenu {
min-width: 0;
}
#hex-viewer-container #byte-item-address-container-context-menu.QMenu::item,
#hex-viewer-container #byte-item-address-container-context-menu QMenu::item {
padding-left: 10px;
min-width: 150px;
}

View File

@@ -47,6 +47,12 @@ namespace Bloom::Widgets
this->update();
}
void ByteAddressContainer::invalidateChildItemCaches() {
for (auto& [rowIndex, addressItem] : this->addressItemsByRowIndex) {
addressItem->update();
}
}
void ByteAddressContainer::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
static const auto backgroundColor = QColor(0x35, 0x36, 0x33);
static const auto borderColor = QColor(0x41, 0x42, 0x3F);

View File

@@ -30,6 +30,7 @@ namespace Bloom::Widgets
}
void adjustAddressLabels(const std::map<std::size_t, std::vector<ByteItem*>>& byteItemsByRowIndex);
void invalidateChildItemCaches();
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
private:

View File

@@ -1,6 +1,7 @@
#include "ByteItemGraphicsScene.hpp"
#include <cmath>
#include <QMenu>
#include "src/Insight/InsightSignals.hpp"
@@ -52,6 +53,11 @@ namespace Bloom::Widgets
this->addItem(byteWidget);
}
this->displayRelativeAddressAction->setCheckable(true);
this->displayAbsoluteAddressAction->setCheckable(true);
this->setAddressType(this->settings.addressLabelType);
QObject::connect(
InsightSignals::instance(),
&InsightSignals::targetStateUpdated,
@@ -59,6 +65,23 @@ namespace Bloom::Widgets
&ByteItemGraphicsScene::onTargetStateChanged
);
QObject::connect(
this->displayRelativeAddressAction,
&QAction::triggered,
this,
[this] {
this->setAddressType(AddressType::RELATIVE);
}
);
QObject::connect(
this->displayAbsoluteAddressAction,
&QAction::triggered,
this,
[this] {
this->setAddressType(AddressType::ABSOLUTE);
}
);
}
void ByteItemGraphicsScene::updateValues(const Targets::TargetMemoryBuffer& buffer) {
@@ -389,6 +412,21 @@ namespace Bloom::Widgets
}
}
void ByteItemGraphicsScene::contextMenuEvent(QGraphicsSceneContextMenuEvent* event) {
if (event->scenePos().x() <= ByteAddressContainer::WIDTH) {
auto* menu = new QMenu(this->getParent());
menu->setObjectName("byte-item-address-container-context-menu");
auto* addressTypeMenu = new QMenu("Address Type", menu);
addressTypeMenu->addAction(this->displayAbsoluteAddressAction);
addressTypeMenu->addAction(this->displayRelativeAddressAction);
menu->addMenu(addressTypeMenu);
menu->exec(event->screenPos());
return;
}
}
void ByteItemGraphicsScene::updateAnnotationValues(const Targets::TargetMemoryBuffer& buffer) {
const auto memoryStartAddress = this->targetMemoryDescriptor.addressRange.startAddress;
for (auto* valueAnnotationItem : this->valueAnnotationItems) {
@@ -660,4 +698,13 @@ namespace Bloom::Widgets
this->selectByteItem(byteItem);
}
}
void ByteItemGraphicsScene::setAddressType(AddressType type) {
this->settings.addressLabelType = type;
this->displayRelativeAddressAction->setChecked(this->settings.addressLabelType == AddressType::RELATIVE);
this->displayAbsoluteAddressAction->setChecked(this->settings.addressLabelType == AddressType::ABSOLUTE);
this->byteAddressContainer->invalidateChildItemCaches();
}
}

View File

@@ -13,10 +13,12 @@
#include <QString>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsSceneWheelEvent>
#include <QGraphicsSceneContextMenuEvent>
#include <QKeyEvent>
#include <optional>
#include <QGraphicsRectItem>
#include <QPointF>
#include <QAction>
#include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetState.hpp"
@@ -32,6 +34,7 @@
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/FocusedMemoryRegion.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ExcludedMemoryRegion.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/AddressType.hpp"
namespace Bloom::Widgets
{
@@ -67,6 +70,7 @@ namespace Bloom::Widgets
void mouseMoveEvent(QGraphicsSceneMouseEvent* mouseEvent) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent* mouseEvent) override;
void keyPressEvent(QKeyEvent* keyEvent) override;
void contextMenuEvent(QGraphicsSceneContextMenuEvent* event) override;
private:
const Targets::TargetMemoryDescriptor& targetMemoryDescriptor;
@@ -104,6 +108,10 @@ namespace Bloom::Widgets
std::optional<QPointF> rubberBandInitPoint = std::nullopt;
// Address label container context menu actions
QAction* displayRelativeAddressAction = new QAction("Relative", this);
QAction* displayAbsoluteAddressAction = new QAction("Absolute", this);
QGraphicsView* getParent() const {
return dynamic_cast<QGraphicsView*>(this->parent());
}
@@ -133,5 +141,6 @@ namespace Bloom::Widgets
void toggleByteItemSelection(ByteItem* byteItem);
void clearByteItemSelection();
void selectAllByteItems();
void setAddressType(AddressType type);
};
}