ByteItem highlighting and centering via HexViewerWidget
This commit is contained in:
@@ -25,6 +25,7 @@ namespace Widgets
|
|||||||
bool grouped:1 = false;
|
bool grouped:1 = false;
|
||||||
bool stackMemory:1 = false;
|
bool stackMemory:1 = false;
|
||||||
bool changed:1 = false;
|
bool changed:1 = false;
|
||||||
|
bool highlighted:1 = false;
|
||||||
|
|
||||||
explicit ByteItem(Targets::TargetMemoryAddress address);
|
explicit ByteItem(Targets::TargetMemoryAddress address);
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,13 @@ namespace Widgets
|
|||||||
const auto position = item->position();
|
const auto position = item->position();
|
||||||
const auto boundingRect = QRect(position.x(), position.y(), ByteItem::WIDTH, ByteItem::HEIGHT);
|
const auto boundingRect = QRect(position.x(), position.y(), ByteItem::WIDTH, ByteItem::HEIGHT);
|
||||||
|
|
||||||
painter->setOpacity(!this->isEnabled() || (item->excluded && !item->selected) ? 0.6 : 1);
|
painter->setOpacity(
|
||||||
|
!this->isEnabled()
|
||||||
|
|| (item->excluded && !item->selected)
|
||||||
|
|| (this->hexViewerState.highlightingEnabled && !item->highlighted)
|
||||||
|
? 0.6
|
||||||
|
: 1
|
||||||
|
);
|
||||||
|
|
||||||
if (item->excluded || !this->hexViewerState.data.has_value()) {
|
if (item->excluded || !this->hexViewerState.data.has_value()) {
|
||||||
if (item->selected) {
|
if (item->selected) {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ namespace Widgets
|
|||||||
|
|
||||||
ByteItem* hoveredByteItem = nullptr;
|
ByteItem* hoveredByteItem = nullptr;
|
||||||
std::optional<Targets::TargetStackPointer> currentStackPointer;
|
std::optional<Targets::TargetStackPointer> currentStackPointer;
|
||||||
|
bool highlightingEnabled = false;
|
||||||
|
|
||||||
HexViewerSharedState(
|
HexViewerSharedState(
|
||||||
const Targets::TargetMemoryDescriptor& memoryDescriptor,
|
const Targets::TargetMemoryDescriptor& memoryDescriptor,
|
||||||
|
|||||||
@@ -242,6 +242,28 @@ namespace Widgets
|
|||||||
this->byteItemGraphicsScene->addExternalContextMenuAction(action);
|
this->byteItemGraphicsScene->addExternalContextMenuAction(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HexViewerWidget::highlightBytes(const std::set<Targets::TargetMemoryAddress>& addresses) {
|
||||||
|
this->byteItemGraphicsScene->highlightByteItems(addresses);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HexViewerWidget::highlightBytes(const std::set<Targets::TargetMemoryAddressRange>& addressRanges) {
|
||||||
|
this->byteItemGraphicsScene->highlightByteItems(this->addressRangesToAddresses(addressRanges));
|
||||||
|
}
|
||||||
|
|
||||||
|
void HexViewerWidget::clearHighlighting() {
|
||||||
|
this->highlightBytes(std::set<Targets::TargetMemoryAddress>());
|
||||||
|
}
|
||||||
|
|
||||||
|
void HexViewerWidget::selectAndHighlightBytes(const std::set<Targets::TargetMemoryAddressRange>& addressRanges) {
|
||||||
|
const auto addresses = this->addressRangesToAddresses(addressRanges);
|
||||||
|
this->byteItemGraphicsScene->highlightByteItems(addresses);
|
||||||
|
this->byteItemGraphicsScene->selectByteItems(addresses);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HexViewerWidget::centerOnByte(Targets::TargetMemoryAddress address) {
|
||||||
|
this->byteItemGraphicsView->scrollToByteItemAtAddress(address);
|
||||||
|
}
|
||||||
|
|
||||||
void HexViewerWidget::resizeEvent(QResizeEvent* event) {
|
void HexViewerWidget::resizeEvent(QResizeEvent* event) {
|
||||||
this->container->setFixedSize(
|
this->container->setFixedSize(
|
||||||
this->width(),
|
this->width(),
|
||||||
@@ -370,4 +392,19 @@ namespace Widgets
|
|||||||
);
|
);
|
||||||
this->selectionCountLabel->show();
|
this->selectionCountLabel->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::set<Targets::TargetMemoryAddress> HexViewerWidget::addressRangesToAddresses(
|
||||||
|
const std::set<Targets::TargetMemoryAddressRange>& addressRanges
|
||||||
|
) {
|
||||||
|
auto addresses = std::set<Targets::TargetMemoryAddress>();
|
||||||
|
auto addressesIt = addresses.end();
|
||||||
|
|
||||||
|
for (const auto& range : addressRanges) {
|
||||||
|
for (auto i = range.startAddress; i <= range.endAddress; ++i) {
|
||||||
|
addressesIt = addresses.insert(addressesIt, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return addresses;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,11 @@ namespace Widgets
|
|||||||
void refreshRegions();
|
void refreshRegions();
|
||||||
void setStackPointer(Targets::TargetStackPointer stackPointer);
|
void setStackPointer(Targets::TargetStackPointer stackPointer);
|
||||||
void addExternalContextMenuAction(ContextMenuAction* action);
|
void addExternalContextMenuAction(ContextMenuAction* action);
|
||||||
|
void highlightBytes(const std::set<Targets::TargetMemoryAddress>& addresses);
|
||||||
|
void highlightBytes(const std::set<Targets::TargetMemoryAddressRange>& addressRanges);
|
||||||
|
void clearHighlighting();
|
||||||
|
void selectAndHighlightBytes(const std::set<Targets::TargetMemoryAddressRange>& addressRanges);
|
||||||
|
void centerOnByte(Targets::TargetMemoryAddress address);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void ready();
|
void ready();
|
||||||
@@ -89,5 +94,8 @@ namespace Widgets
|
|||||||
void onByteSelectionChanged(
|
void onByteSelectionChanged(
|
||||||
const std::unordered_map<Targets::TargetMemoryAddress, ByteItem*>& selectedByteItemsByAddress
|
const std::unordered_map<Targets::TargetMemoryAddress, ByteItem*>& selectedByteItemsByAddress
|
||||||
);
|
);
|
||||||
|
std::set<Targets::TargetMemoryAddress> addressRangesToAddresses(
|
||||||
|
const std::set<Targets::TargetMemoryAddressRange>& addressRanges
|
||||||
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -237,6 +237,15 @@ namespace Widgets
|
|||||||
emit this->selectionChanged(this->selectedByteItemsByAddress);
|
emit this->selectionChanged(this->selectedByteItemsByAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ItemGraphicsScene::highlightByteItems(const std::set<std::uint32_t>& addresses) {
|
||||||
|
for (auto& [address, byteItem] : this->topLevelGroup->byteItemsByAddress) {
|
||||||
|
byteItem.highlighted = addresses.contains(address);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->state.highlightingEnabled = !addresses.empty();
|
||||||
|
this->update();
|
||||||
|
}
|
||||||
|
|
||||||
void ItemGraphicsScene::rebuildItemHierarchy() {
|
void ItemGraphicsScene::rebuildItemHierarchy() {
|
||||||
this->topLevelGroup->rebuildItemHierarchy();
|
this->topLevelGroup->rebuildItemHierarchy();
|
||||||
this->itemIndex->refreshFlattenedItems();
|
this->itemIndex->refreshFlattenedItems();
|
||||||
@@ -357,6 +366,11 @@ namespace Widgets
|
|||||||
const auto button = mouseEvent->button();
|
const auto button = mouseEvent->button();
|
||||||
const auto mousePosition = mouseEvent->buttonDownScenePos(button);
|
const auto mousePosition = mouseEvent->buttonDownScenePos(button);
|
||||||
|
|
||||||
|
if (this->state.highlightingEnabled) {
|
||||||
|
this->state.highlightingEnabled = false;
|
||||||
|
this->update();
|
||||||
|
}
|
||||||
|
|
||||||
if (mousePosition.x() <= this->byteAddressContainer->boundingRect().width()) {
|
if (mousePosition.x() <= this->byteAddressContainer->boundingRect().width()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ namespace Widgets
|
|||||||
void init();
|
void init();
|
||||||
void updateStackPointer(Targets::TargetStackPointer stackPointer);
|
void updateStackPointer(Targets::TargetStackPointer stackPointer);
|
||||||
void selectByteItems(const std::set<Targets::TargetMemoryAddress>& addresses);
|
void selectByteItems(const std::set<Targets::TargetMemoryAddress>& addresses);
|
||||||
|
void highlightByteItems(const std::set<Targets::TargetMemoryAddress>& addresses);
|
||||||
void rebuildItemHierarchy();
|
void rebuildItemHierarchy();
|
||||||
void adjustSize();
|
void adjustSize();
|
||||||
void setEnabled(bool enabled);
|
void setEnabled(bool enabled);
|
||||||
|
|||||||
Reference in New Issue
Block a user