From 9631626228e3d9b41fd562ffdc869280b5d5c889 Mon Sep 17 00:00:00 2001 From: Nav Date: Mon, 25 Sep 2023 22:36:35 +0100 Subject: [PATCH] Moved painting of hex viewer hover rectangles to scene renderer (it's faster and more efficient) --- .../HexViewerWidget/HexViewerItemRenderer.cpp | 18 ++++++- .../HexViewerWidget/ItemGraphicsScene.cpp | 47 +------------------ .../HexViewerWidget/ItemGraphicsScene.hpp | 3 -- 3 files changed, 18 insertions(+), 50 deletions(-) diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerItemRenderer.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerItemRenderer.cpp index 11b04e0e..15b2e89c 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerItemRenderer.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerItemRenderer.cpp @@ -27,8 +27,9 @@ namespace Widgets } void HexViewerItemRenderer::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { + const auto viewportSize = this->viewport->size(); const auto viewportYStart = this->view->verticalScrollBar()->value(); - const auto viewportYEnd = viewportYStart + this->viewport->size().height(); + const auto viewportYEnd = viewportYStart + viewportSize.height(); const auto visibleItems = this->itemIndex.items(viewportYStart, viewportYEnd); @@ -68,6 +69,21 @@ namespace Widgets this->paintPrimaryHighlightBorder(&startItem, &endItem, painter); } } + + if ( + this->hexViewerState.hoveredByteItem != nullptr + && this->hexViewerState.settings.highlightHoveredRowAndCol + ) { + static const auto hoverRectBackgroundColor = QColor(0x8E, 0x8B, 0x83, 45); + + painter->setBrush(hoverRectBackgroundColor); + painter->setPen(Qt::NoPen); + + const auto byteItemScenePos = this->hexViewerState.hoveredByteItem->position(); + + painter->drawRect(0, byteItemScenePos.y(), viewportSize.width(), ByteItem::HEIGHT); + painter->drawRect(byteItemScenePos.x(), viewportYStart, ByteItem::WIDTH, viewportSize.height()); + } } void HexViewerItemRenderer::paintItem(const HexViewerItem* item, QPainter* painter) { diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.cpp index 7b94d03c..39289365 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.cpp @@ -163,22 +163,6 @@ namespace Widgets ); this->setSceneRect(0, 0, this->getSceneWidth(), 0); - - static const auto hoverRectBackgroundColor = QColor(0x8E, 0x8B, 0x83, 45); - - this->hoverRectX->setBrush(hoverRectBackgroundColor); - this->hoverRectY->setBrush(hoverRectBackgroundColor); - this->hoverRectX->setPen(Qt::NoPen); - this->hoverRectY->setPen(Qt::NoPen); - - this->hoverRectX->setVisible(false); - this->hoverRectY->setVisible(false); - - this->hoverRectX->setZValue(100); - this->hoverRectY->setZValue(100); - - this->addItem(this->hoverRectX); - this->addItem(this->hoverRectY); } void ItemGraphicsScene::init() { @@ -280,14 +264,6 @@ namespace Widgets const auto width = this->getSceneWidth(); const auto availableWidth = width - ByteAddressContainer::WIDTH - margins.left() - margins.right(); - auto hoverRectX = this->hoverRectX->rect(); - hoverRectX.setWidth(width); - this->hoverRectX->setRect(hoverRectX); - - auto hoverRectY = this->hoverRectY->rect(); - hoverRectY.setHeight(this->views().first()->viewport()->height() + (ByteItem::HEIGHT * 2)); - this->hoverRectY->setRect(hoverRectY); - this->topLevelGroup->adjustItemPositions(availableWidth); this->itemIndex->refreshIndex(); @@ -602,32 +578,11 @@ namespace Widgets this->state.hoveredByteItem = &byteItem; this->update(); - if (this->state.settings.highlightHoveredRowAndCol) { - const auto byteItemScenePos = byteItem.position(); - this->hoverRectX->setPos(0, byteItemScenePos.y()); - this->hoverRectY->setPos( - byteItemScenePos.x(), - std::max(this->getScrollbarValue() - ByteItem::HEIGHT, 0) - ); - - this->hoverRectX->setVisible(true); - this->hoverRectY->setVisible(true); - this->hoverRectX->update(); - this->hoverRectY->update(); - } - emit this->hoveredAddress(byteItem.startAddress); } void ItemGraphicsScene::onByteItemLeave() { - if (this->state.hoveredByteItem != nullptr) { - this->state.hoveredByteItem = nullptr; - } - - this->hoverRectX->setVisible(false); - this->hoverRectY->setVisible(false); - this->hoverRectX->update(); - this->hoverRectY->update(); + this->state.hoveredByteItem = nullptr; this->update(); emit this->hoveredAddress(std::nullopt); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.hpp index 6cf1edd4..6e780fc5 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.hpp @@ -97,9 +97,6 @@ namespace Widgets QGraphicsRectItem* rubberBandRectItem = nullptr; std::optional rubberBandInitPoint = std::nullopt; - QGraphicsRectItem* hoverRectX = new QGraphicsRectItem(QRect(0, 0, 0, ByteItem::HEIGHT)); - QGraphicsRectItem* hoverRectY = new QGraphicsRectItem(QRect(0, 0, ByteItem::WIDTH, 0)); - // Context menu actions QAction* selectAllByteItemsAction = new QAction("Select All", this); QAction* deselectByteItemsAction = new QAction("Deselect All", this);