Go-to-address function in hex viewer
This commit is contained in:
@@ -34,6 +34,10 @@ ByteItemContainerGraphicsView::ByteItemContainerGraphicsView(
|
||||
|
||||
}
|
||||
|
||||
void ByteItemContainerGraphicsView::scrollToByteItemAtAddress(std::uint32_t address) {
|
||||
this->centerOn(this->scene->getByteItemPositionByAddress(address));
|
||||
}
|
||||
|
||||
bool ByteItemContainerGraphicsView::event(QEvent* event) {
|
||||
const auto eventType = event->type();
|
||||
if (eventType == QEvent::Type::EnabledChange) {
|
||||
|
||||
@@ -34,6 +34,8 @@ namespace Bloom::Widgets
|
||||
return this->scene;
|
||||
}
|
||||
|
||||
void scrollToByteItemAtAddress(std::uint32_t address);
|
||||
|
||||
protected:
|
||||
bool event(QEvent* event) override;
|
||||
void resizeEvent(QResizeEvent* event) override;
|
||||
|
||||
@@ -221,6 +221,14 @@ void ByteItemGraphicsScene::invalidateChildItemCaches() {
|
||||
}
|
||||
}
|
||||
|
||||
QPointF ByteItemGraphicsScene::getByteItemPositionByAddress(std::uint32_t address) {
|
||||
if (this->byteItemsByAddress.contains(address)) {
|
||||
return this->byteItemsByAddress.at(address)->pos();
|
||||
}
|
||||
|
||||
return QPointF();
|
||||
}
|
||||
|
||||
bool ByteItemGraphicsScene::event(QEvent* event) {
|
||||
if (event->type() == QEvent::Type::GraphicsSceneLeave && this->hoveredByteWidget.has_value()) {
|
||||
this->onByteWidgetLeave();
|
||||
|
||||
@@ -55,6 +55,7 @@ namespace Bloom::Widgets
|
||||
void adjustSize(bool forced = false);
|
||||
void setEnabled(bool enabled);
|
||||
void invalidateChildItemCaches();
|
||||
QPointF getByteItemPositionByAddress(std::uint32_t address);
|
||||
|
||||
signals:
|
||||
void byteWidgetsAdjusted();
|
||||
|
||||
@@ -58,6 +58,8 @@ HexViewerWidget::HexViewerWidget(
|
||||
this->displayAnnotationsButton = this->container->findChild<SvgToolButton*>("display-annotations-btn");
|
||||
this->displayAsciiButton = this->container->findChild<SvgToolButton*>("display-ascii-btn");
|
||||
|
||||
this->goToAddressInput = this->container->findChild<TextInput*>("go-to-address-input");
|
||||
|
||||
this->toolBar->setContentsMargins(0, 0, 0, 0);
|
||||
this->toolBar->layout()->setContentsMargins(5, 0, 5, 1);
|
||||
|
||||
@@ -137,6 +139,20 @@ HexViewerWidget::HexViewerWidget(
|
||||
}
|
||||
);
|
||||
|
||||
QObject::connect(
|
||||
this->goToAddressInput,
|
||||
&QLineEdit::textEdited,
|
||||
this,
|
||||
&HexViewerWidget::onGoToAddressInputChanged
|
||||
);
|
||||
|
||||
QObject::connect(
|
||||
this->goToAddressInput,
|
||||
&TextInput::focusChanged,
|
||||
this,
|
||||
&HexViewerWidget::onGoToAddressInputChanged
|
||||
);
|
||||
|
||||
QObject::connect(
|
||||
&insightWorker,
|
||||
&InsightWorker::targetStateUpdated,
|
||||
@@ -211,3 +227,18 @@ void HexViewerWidget::setDisplayAsciiEnabled(bool enabled) {
|
||||
|
||||
this->byteItemGraphicsScene->invalidateChildItemCaches();
|
||||
}
|
||||
|
||||
void HexViewerWidget::onGoToAddressInputChanged() {
|
||||
auto addressConversionOk = false;
|
||||
const auto address = this->goToAddressInput->text().toUInt(&addressConversionOk, 16);
|
||||
|
||||
const auto& memoryAddressRange = this->targetMemoryDescriptor.addressRange;
|
||||
|
||||
if (addressConversionOk && memoryAddressRange.contains(address) && this->goToAddressInput->hasFocus()) {
|
||||
this->byteItemGraphicsScene->setHighlightedAddresses({address});
|
||||
this->byteItemGraphicsView->scrollToByteItemAtAddress(address);
|
||||
return;
|
||||
}
|
||||
|
||||
this->byteItemGraphicsScene->setHighlightedAddresses({});
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "src/Insight/InsightWorker/InsightWorker.hpp"
|
||||
|
||||
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/SvgToolButton.hpp"
|
||||
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/TextInput.hpp"
|
||||
|
||||
#include "HexViewerWidgetSettings.hpp"
|
||||
#include "ByteItemContainerGraphicsView.hpp"
|
||||
@@ -70,6 +71,8 @@ namespace Bloom::Widgets
|
||||
SvgToolButton* displayAnnotationsButton = nullptr;
|
||||
SvgToolButton* displayAsciiButton = nullptr;
|
||||
|
||||
TextInput* goToAddressInput = nullptr;
|
||||
|
||||
Targets::TargetState targetState = Targets::TargetState::UNKNOWN;
|
||||
|
||||
void onTargetStateChanged(Targets::TargetState newState);
|
||||
@@ -78,5 +81,6 @@ namespace Bloom::Widgets
|
||||
void setFocusedMemoryHighlightingEnabled(bool enabled);
|
||||
void setAnnotationsEnabled(bool enabled);
|
||||
void setDisplayAsciiEnabled(bool enabled);
|
||||
void onGoToAddressInputChanged();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -162,6 +162,28 @@
|
||||
<item>
|
||||
<widget class="QFrame" name="separator"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontal-spacer">
|
||||
<property name="sizeHint">
|
||||
<size>
|
||||
<width>1</width>
|
||||
</size>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="TextInput" name="go-to-address-input">
|
||||
<property name="placeholderText">
|
||||
<string>Go to address...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="separator"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontal-spacer">
|
||||
<property name="orientation">
|
||||
|
||||
Reference in New Issue
Block a user