Improved byte item selection upon the triggering a context menu in the hex viewer

This commit is contained in:
Nav
2023-03-06 20:58:05 +00:00
parent 5833aeeb26
commit 6302cab686

View File

@@ -330,19 +330,38 @@ namespace Bloom::Widgets
static const auto rubberBandRectBackgroundColor = QColor(0x3C, 0x59, 0x5C, 0x82); static const auto rubberBandRectBackgroundColor = QColor(0x3C, 0x59, 0x5C, 0x82);
static const auto rubberBandRectBorderColor = QColor(0x3C, 0x59, 0x5C, 255); static const auto rubberBandRectBorderColor = QColor(0x3C, 0x59, 0x5C, 255);
if (mouseEvent->button() != Qt::MouseButton::LeftButton) { const auto button = mouseEvent->button();
return; const auto mousePosition = mouseEvent->buttonDownScenePos(button);
}
const auto mousePosition = mouseEvent->buttonDownScenePos(Qt::MouseButton::LeftButton);
if (mousePosition.x() <= this->byteAddressContainer->boundingRect().width()) { if (mousePosition.x() <= this->byteAddressContainer->boundingRect().width()) {
return; return;
} }
this->update(); this->update();
if (button == Qt::MouseButton::RightButton) {
ByteItem* clickedByteItem = nullptr;
for (const auto& item : this->items(mousePosition)) {
auto* clickedGraphicsItem = dynamic_cast<GraphicsItem*>(item);
if (clickedGraphicsItem == nullptr) {
continue;
}
clickedByteItem = dynamic_cast<ByteItem*>(clickedGraphicsItem->hexViewerItem);
if (clickedByteItem != nullptr) {
break;
}
}
if (clickedByteItem == nullptr || clickedByteItem->selected) {
return;
}
}
const auto modifiers = mouseEvent->modifiers(); const auto modifiers = mouseEvent->modifiers();
if ((modifiers & Qt::ShiftModifier) == 0) { if ((modifiers & Qt::ShiftModifier) == 0 && button == Qt::MouseButton::LeftButton) {
this->clearSelectionRectItem(); this->clearSelectionRectItem();
this->rubberBandInitPoint = std::move(mousePosition); this->rubberBandInitPoint = std::move(mousePosition);