diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressItem.cpp index 1a55cbba..c1862ed5 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressItem.cpp @@ -12,11 +12,15 @@ void ByteAddressItem::setAddressHex(const QString& addressHex) { void ByteAddressItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { painter->setRenderHints(QPainter::RenderHint::Antialiasing | QPainter::RenderHint::SmoothPixmapTransform, true); - static const auto fontColor = QColor(0x8F, 0x91, 0x92); static const auto widgetRect = this->boundingRect(); + auto fontColor = QColor(0x8F, 0x91, 0x92); static auto font = painter->font(); font.setPixelSize(12); + if (!this->isEnabled()) { + fontColor.setAlpha(100); + } + painter->setFont(font); painter->setPen(fontColor); painter->drawText(widgetRect, Qt::AlignCenter, this->addressHex); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItem.hpp index e8f05a35..6a265660 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItem.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItem.hpp @@ -19,11 +19,10 @@ namespace Bloom::Widgets static constexpr int BOTTOM_MARGIN = 5; std::size_t byteIndex; - unsigned char value = 0x00; std::uint32_t address = 0x00; + QString addressHex; QString relativeAddressHex; - bool valueInitialised = false; std::size_t currentRowIndex = 0; std::size_t currentColumnIndex = 0; @@ -33,6 +32,7 @@ namespace Bloom::Widgets std::uint32_t address, std::optional& hoveredByteItem ); + void setValue(unsigned char value); [[nodiscard]] QRectF boundingRect() const override { @@ -46,6 +46,8 @@ namespace Bloom::Widgets void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override; private: + unsigned char value = 0x00; + bool valueInitialised = false; bool valueChanged = false; QString hexValue; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemContainerGraphicsView.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemContainerGraphicsView.cpp index dcd26208..94a96fc5 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemContainerGraphicsView.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemContainerGraphicsView.cpp @@ -35,6 +35,14 @@ ByteItemContainerGraphicsView::ByteItemContainerGraphicsView( this->setScene(this->scene); } +bool ByteItemContainerGraphicsView::event(QEvent* event) { + if (event->type() == QEvent::Type::EnabledChange) { + this->scene->setEnabled(this->isEnabled()); + } + + return QGraphicsView::event(event); +} + void ByteItemContainerGraphicsView::resizeEvent(QResizeEvent* event) { Logger::warning("Resizing"); this->scene->adjustByteWidgets(); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemContainerGraphicsView.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemContainerGraphicsView.hpp index c573714f..97b0039e 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemContainerGraphicsView.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemContainerGraphicsView.hpp @@ -39,6 +39,7 @@ namespace Bloom::Widgets } protected: + bool event(QEvent* event) override; void resizeEvent(QResizeEvent* event) 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 649cb3c4..b6db1472 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.cpp @@ -40,7 +40,7 @@ parent(parent) { const auto address = startAddress + i; auto* byteWidget = new ByteItem(i, address, this->hoveredByteWidget); - this->byteWidgetsByAddress.insert(std::pair( + this->byteItemsByAddress.insert(std::pair( address, byteWidget )); @@ -59,7 +59,7 @@ parent(parent) { } void ByteItemGraphicsScene::updateValues(const Targets::TargetMemoryBuffer& buffer) { - for (auto& [address, byteWidget] : this->byteWidgetsByAddress) { + for (auto& [address, byteWidget] : this->byteItemsByAddress) { byteWidget->setValue(buffer.at(byteWidget->byteIndex)); byteWidget->update(); } @@ -75,7 +75,7 @@ void ByteItemGraphicsScene::adjustByteWidgets() { std::floor((width - margins.left() - margins.right() - ByteAddressContainer::WIDTH) / byteWidgetWidth) ); const auto rowCount = static_cast( - std::ceil(static_cast(this->byteWidgetsByAddress.size()) / static_cast(rowCapacity)) + std::ceil(static_cast(this->byteItemsByAddress.size()) / static_cast(rowCapacity)) ); this->setSceneRect( @@ -86,14 +86,14 @@ void ByteItemGraphicsScene::adjustByteWidgets() { ); // Don't bother recalculating the byte item positions if the number of rows have not changed. - if (rowCount == this->byteWidgetsByRowIndex.size()) { + if (rowCount == this->byteItemsByRowIndex.size()) { return; } std::map> byteWidgetsByRowIndex; std::map> byteWidgetsByColumnIndex; - for (auto& [address, byteWidget] : this->byteWidgetsByAddress) { + for (auto& [address, byteWidget] : this->byteItemsByAddress) { const auto rowIndex = static_cast( std::ceil(static_cast(byteWidget->byteIndex + 1) / static_cast(rowCapacity)) - 1 ); @@ -116,10 +116,23 @@ void ByteItemGraphicsScene::adjustByteWidgets() { byteWidget->update(); } - this->byteWidgetsByRowIndex = std::move(byteWidgetsByRowIndex); - this->byteWidgetsByColumnIndex = std::move(byteWidgetsByColumnIndex); + this->byteItemsByRowIndex = std::move(byteWidgetsByRowIndex); + this->byteItemsByColumnIndex = std::move(byteWidgetsByColumnIndex); - this->byteAddressContainer->adjustAddressLabels(this->byteWidgetsByRowIndex); + this->byteAddressContainer->adjustAddressLabels(this->byteItemsByRowIndex); +} + +void ByteItemGraphicsScene::setEnabled(bool enabled) { + if (this->enabled != enabled) { + this->enabled = enabled; + + for (auto& [byteAddress, byteItem] : this->byteItemsByAddress) { + byteItem->setEnabled(this->enabled); + } + + this->byteAddressContainer->setEnabled(enabled); + this->update(); + } } void ByteItemGraphicsScene::onTargetStateChanged(Targets::TargetState newState) { @@ -144,12 +157,12 @@ void ByteItemGraphicsScene::onByteWidgetEnter(ByteItem* widget) { "Relative Address (Absolute Address): " + widget->relativeAddressHex + " (" + widget->addressHex + ")" ); - if (!this->byteWidgetsByRowIndex.empty()) { - for (auto& byteWidget : this->byteWidgetsByColumnIndex.at(widget->currentColumnIndex)) { + if (!this->byteItemsByRowIndex.empty()) { + for (auto& byteWidget : this->byteItemsByColumnIndex.at(widget->currentColumnIndex)) { byteWidget->update(); } - for (auto& byteWidget : this->byteWidgetsByRowIndex.at(widget->currentRowIndex)) { + for (auto& byteWidget : this->byteItemsByRowIndex.at(widget->currentRowIndex)) { byteWidget->update(); } } @@ -161,12 +174,12 @@ void ByteItemGraphicsScene::onByteWidgetLeave() { this->hoveredAddressLabel->setText("Relative Address (Absolute Address):"); - if (!this->byteWidgetsByRowIndex.empty()) { - for (auto& byteWidget : this->byteWidgetsByColumnIndex.at(byteItem->currentColumnIndex)) { + if (!this->byteItemsByRowIndex.empty()) { + for (auto& byteWidget : this->byteItemsByColumnIndex.at(byteItem->currentColumnIndex)) { byteWidget->update(); } - for (auto& byteWidget : this->byteWidgetsByRowIndex.at(byteItem->currentRowIndex)) { + for (auto& byteWidget : this->byteItemsByRowIndex.at(byteItem->currentRowIndex)) { byteWidget->update(); } } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.hpp index 7c3bef76..55040a72 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.hpp @@ -29,9 +29,9 @@ namespace Bloom::Widgets public: std::optional hoveredByteWidget; - std::map byteWidgetsByAddress; - std::map> byteWidgetsByRowIndex; - std::map> byteWidgetsByColumnIndex; + std::map byteItemsByAddress; + std::map> byteItemsByRowIndex; + std::map> byteItemsByColumnIndex; ByteItemGraphicsScene( const Targets::TargetMemoryDescriptor& targetMemoryDescriptor, @@ -44,6 +44,8 @@ namespace Bloom::Widgets void adjustByteWidgets(); + void setEnabled(bool enabled); + signals: void byteWidgetsAdjusted(); @@ -61,6 +63,8 @@ namespace Bloom::Widgets ByteAddressContainer* byteAddressContainer = nullptr; + bool enabled = true; + private slots: void onTargetStateChanged(Targets::TargetState newState); void onByteWidgetEnter(Bloom::Widgets::ByteItem* widget);