Moved painting of hex viewer hover rectangles to scene renderer (it's faster and more efficient)
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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->update();
|
||||
|
||||
emit this->hoveredAddress(std::nullopt);
|
||||
|
||||
@@ -97,9 +97,6 @@ namespace Widgets
|
||||
QGraphicsRectItem* rubberBandRectItem = nullptr;
|
||||
std::optional<QPointF> 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);
|
||||
|
||||
Reference in New Issue
Block a user