From c1af6b9f03e08b9027eb854bc8149b4359e6662f Mon Sep 17 00:00:00 2001 From: Nav Date: Thu, 16 Mar 2023 18:45:03 +0000 Subject: [PATCH] Added selection count label to hex viewer --- .../HexViewerWidget/HexViewerWidget.cpp | 22 +++++++++++++++++++ .../HexViewerWidget/HexViewerWidget.hpp | 2 ++ .../HexViewerWidget/ItemGraphicsScene.cpp | 5 +++++ .../HexViewerWidget/ItemGraphicsScene.hpp | 1 + .../UiFiles/HexViewerWidget.ui | 7 ++++++ .../TargetMemoryInspectionPane.qss | 8 +++++++ 6 files changed, 45 insertions(+) diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerWidget.cpp index ee27328e..9a376787 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerWidget.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "src/Insight/UserInterfaces/InsightWindow/UiLoader.hpp" #include "src/Insight/InsightSignals.hpp" @@ -75,6 +76,7 @@ namespace Bloom::Widgets this->bottomBar->layout()->setContentsMargins(5, 0, 5, 0); this->hoveredAddressLabel = this->bottomBar->findChild("byte-address-label"); + this->selectionCountLabel = this->bottomBar->findChild("selection-count-label"); this->loadingHexViewerLabel = this->container->findChild("loading-hex-viewer-label"); @@ -188,6 +190,13 @@ namespace Bloom::Widgets &HexViewerWidget::onHoveredAddress ); + QObject::connect( + this->byteItemGraphicsScene, + &ItemGraphicsScene::selectionChanged, + this, + &HexViewerWidget::onByteSelectionChanged + ); + this->loadingHexViewerLabel->hide(); this->byteItemGraphicsView->show(); @@ -317,4 +326,17 @@ namespace Bloom::Widgets "Relative address / Absolute address: " + relativeAddressHex + " / " + addressHex ); } + + void HexViewerWidget::onByteSelectionChanged(Targets::TargetMemorySize selectionCount) { + if (selectionCount == 0) { + this->selectionCountLabel->hide(); + return; + } + + this->selectionCountLabel->setText( + QLocale(QLocale::English).toString(selectionCount) + " " + QString(selectionCount == 1 ? "byte" : "bytes") + + " selected" + ); + this->selectionCountLabel->show(); + } } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerWidget.hpp index 55d0f028..13c6b90c 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerWidget.hpp @@ -65,6 +65,7 @@ namespace Bloom::Widgets ItemGraphicsView* byteItemGraphicsView = nullptr; ItemGraphicsScene* byteItemGraphicsScene = nullptr; Label* hoveredAddressLabel = nullptr; + Label* selectionCountLabel = nullptr; SvgToolButton* groupStackMemoryButton = nullptr; SvgToolButton* highlightFocusedMemoryButton = nullptr; @@ -84,5 +85,6 @@ namespace Bloom::Widgets void setDisplayAsciiEnabled(bool enabled); void onGoToAddressInputChanged(); void onHoveredAddress(const std::optional& address); + void onByteSelectionChanged(Targets::TargetMemorySize selectionCount); }; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.cpp index 6cc89f1e..a428ad4c 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.cpp @@ -464,6 +464,7 @@ namespace Bloom::Widgets this->selectByteItem(*byteItem); } } + emit this->selectionChanged(static_cast(this->selectedByteItemsByAddress.size())); } for (const auto& item : hoveredItems) { @@ -649,10 +650,12 @@ namespace Bloom::Widgets void ItemGraphicsScene::toggleByteItemSelection(ByteItem& byteItem) { if (byteItem.selected) { this->deselectByteItem(byteItem); + emit this->selectionChanged(static_cast(this->selectedByteItemsByAddress.size())); return; } this->selectByteItem(byteItem); + emit this->selectionChanged(static_cast(this->selectedByteItemsByAddress.size())); } void ItemGraphicsScene::clearByteItemSelection() { @@ -662,6 +665,7 @@ namespace Bloom::Widgets this->selectedByteItemsByAddress.clear(); this->update(); + emit this->selectionChanged(0); } void ItemGraphicsScene::selectAllByteItems() { @@ -672,6 +676,7 @@ namespace Bloom::Widgets } this->update(); + emit this->selectionChanged(static_cast(this->selectedByteItemsByAddress.size())); } void ItemGraphicsScene::setAddressType(AddressType type) { diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.hpp index 93261418..3289e4cb 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.hpp @@ -64,6 +64,7 @@ namespace Bloom::Widgets signals: void ready(); void hoveredAddress(const std::optional& address); + void selectionChanged(Targets::TargetMemorySize selectionCount); protected: bool event(QEvent* event) override; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/UiFiles/HexViewerWidget.ui b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/UiFiles/HexViewerWidget.ui index 67bd58c3..258c4c7f 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/UiFiles/HexViewerWidget.ui +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/UiFiles/HexViewerWidget.ui @@ -226,6 +226,13 @@ + + + + false + + + diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/Stylesheets/TargetMemoryInspectionPane.qss b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/Stylesheets/TargetMemoryInspectionPane.qss index ce150cd0..3552215f 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/Stylesheets/TargetMemoryInspectionPane.qss +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/Stylesheets/TargetMemoryInspectionPane.qss @@ -190,6 +190,14 @@ font-size: 14px; } +#hex-viewer-container #bottom-bar #selection-count-label { + border: none; + /*border-left: 1px solid red;*/ + border-left: 1px solid #41423f; + padding-left: 4px; + min-width: 140px; +} + #hex-viewer-container QScrollBar:vertical { background-color: transparent; width: 12px;