diff --git a/src/Insight/UserInterfaces/InsightWindow/Stylesheets/InsightWindow.qss b/src/Insight/UserInterfaces/InsightWindow/Stylesheets/InsightWindow.qss index f2968127..19f39fa7 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Stylesheets/InsightWindow.qss +++ b/src/Insight/UserInterfaces/InsightWindow/Stylesheets/InsightWindow.qss @@ -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; +} diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressContainer.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressContainer.cpp index 7dd0d778..7f9198e1 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressContainer.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressContainer.cpp @@ -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); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressContainer.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressContainer.hpp index 55481395..a00eb3b3 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressContainer.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressContainer.hpp @@ -30,6 +30,7 @@ namespace Bloom::Widgets } void adjustAddressLabels(const std::map>& byteItemsByRowIndex); + void invalidateChildItemCaches(); void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override; private: diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.cpp index 3a0bdac1..a9675a41 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.cpp @@ -1,6 +1,7 @@ #include "ByteItemGraphicsScene.hpp" #include +#include #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(); + } } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.hpp index 083a0a46..6f271f5b 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.hpp @@ -13,10 +13,12 @@ #include #include #include +#include #include #include #include #include +#include #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 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(this->parent()); } @@ -133,5 +141,6 @@ namespace Bloom::Widgets void toggleByteItemSelection(ByteItem* byteItem); void clearByteItemSelection(); void selectAllByteItems(); + void setAddressType(AddressType type); }; }