ByteAddressContainer and ByteAddressItem QGraphicsItems
This commit is contained in:
@@ -180,6 +180,8 @@ add_executable(Bloom
|
|||||||
src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemContainerGraphicsView.cpp
|
src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemContainerGraphicsView.cpp
|
||||||
src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.cpp
|
src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.cpp
|
||||||
src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItem.cpp
|
src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItem.cpp
|
||||||
|
src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressContainer.cpp
|
||||||
|
src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressItem.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties(Bloom PROPERTIES OUTPUT_NAME bloom)
|
set_target_properties(Bloom PROPERTIES OUTPUT_NAME bloom)
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
#include "ByteAddressContainer.hpp"
|
||||||
|
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QTableWidget>
|
||||||
|
#include <QScrollBar>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
#include "src/Logger/Logger.hpp"
|
||||||
|
|
||||||
|
using namespace Bloom::Widgets;
|
||||||
|
|
||||||
|
ByteAddressContainer::ByteAddressContainer() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void ByteAddressContainer::adjustAddressLabels(
|
||||||
|
const std::map<std::size_t, std::vector<ByteItem*>>& byteItemsByRowIndex
|
||||||
|
) {
|
||||||
|
static const auto margins = QMargins(0, 10, 0, 0);
|
||||||
|
|
||||||
|
const auto rowCount = byteItemsByRowIndex.size();
|
||||||
|
const auto addressLabelCount = this->addressItemsByRowIndex.size();
|
||||||
|
const auto layoutItemMaxIndex = static_cast<int>(addressLabelCount - 1);
|
||||||
|
for (const auto& mappingPair : byteItemsByRowIndex) {
|
||||||
|
const auto rowIndex = static_cast<std::size_t>(mappingPair.first);
|
||||||
|
const auto& byteWidgets = mappingPair.second;
|
||||||
|
|
||||||
|
if (byteWidgets.empty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ByteAddressItem* addressLabel;
|
||||||
|
if (static_cast<int>(rowIndex) > layoutItemMaxIndex) {
|
||||||
|
addressLabel = new ByteAddressItem(this);
|
||||||
|
this->addressItemsByRowIndex.insert(std::pair(rowIndex, addressLabel));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
addressLabel = this->addressItemsByRowIndex.at(rowIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
addressLabel->setAddressHex(byteWidgets.front()->relativeAddressHex);
|
||||||
|
addressLabel->setPos(
|
||||||
|
0,
|
||||||
|
margins.top() + static_cast<double>(rowIndex * (ByteAddressItem::HEIGHT + ByteItem::BOTTOM_MARGIN))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rowCount > 0 && rowCount > byteItemsByRowIndex.size()) {
|
||||||
|
const auto rowCount = static_cast<int>(byteItemsByRowIndex.size());
|
||||||
|
for (std::size_t i = rowCount - 1; i >= rowCount; i--) {
|
||||||
|
delete this->addressItemsByRowIndex.at(i);
|
||||||
|
this->addressItemsByRowIndex.erase(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger::error("Done with rows: " + std::to_string(this->addressItemsByRowIndex.size()));
|
||||||
|
|
||||||
|
this->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ByteAddressContainer::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
|
||||||
|
static const auto backgroundColor = QColor(0x35, 0x36, 0x33);
|
||||||
|
static const auto borderColor = QColor(0x41, 0x42, 0x3F);
|
||||||
|
|
||||||
|
painter->setPen(Qt::PenStyle::NoPen);
|
||||||
|
painter->setBrush(backgroundColor);
|
||||||
|
painter->drawRect(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
ByteAddressContainer::WIDTH,
|
||||||
|
static_cast<int>(this->boundingRect().height())
|
||||||
|
);
|
||||||
|
|
||||||
|
painter->setPen(borderColor);
|
||||||
|
painter->drawLine(
|
||||||
|
ByteAddressContainer::WIDTH - 1,
|
||||||
|
0,
|
||||||
|
ByteAddressContainer::WIDTH - 1,
|
||||||
|
static_cast<int>(this->boundingRect().height())
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -4,9 +4,13 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
|
#include <QFont>
|
||||||
|
#include <QColor>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/ClickableWidget.hpp"
|
#include "ByteItem.hpp"
|
||||||
|
#include "ByteAddressItem.hpp"
|
||||||
|
|
||||||
namespace Bloom::Widgets
|
namespace Bloom::Widgets
|
||||||
{
|
{
|
||||||
@@ -15,19 +19,6 @@ namespace Bloom::Widgets
|
|||||||
public:
|
public:
|
||||||
static constexpr int WIDTH = 85;
|
static constexpr int WIDTH = 85;
|
||||||
|
|
||||||
static constexpr int RIGHT_MARGIN = 5;
|
|
||||||
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;
|
|
||||||
|
|
||||||
ByteAddressContainer();
|
ByteAddressContainer();
|
||||||
|
|
||||||
[[nodiscard]] QRectF boundingRect() const override {
|
[[nodiscard]] QRectF boundingRect() const override {
|
||||||
@@ -39,8 +30,10 @@ namespace Bloom::Widgets
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
|
||||||
|
void adjustAddressLabels(const std::map<std::size_t, std::vector<ByteItem*>>& byteItemsByRowIndex);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::map<std::size_t, ByteAddressItem*> addressItemsByRowIndex;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#include "ByteAddressItem.hpp"
|
||||||
|
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QStyle>
|
||||||
|
|
||||||
|
using namespace Bloom::Widgets;
|
||||||
|
|
||||||
|
void ByteAddressItem::setAddressHex(const QString& addressHex) {
|
||||||
|
this->addressHex = 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();
|
||||||
|
static auto font = painter->font();
|
||||||
|
font.setPixelSize(12);
|
||||||
|
|
||||||
|
painter->setFont(font);
|
||||||
|
painter->setPen(fontColor);
|
||||||
|
painter->drawText(widgetRect, Qt::AlignCenter, this->addressHex);
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <QEvent>
|
||||||
|
#include <QGraphicsItem>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
|
#include "ByteItem.hpp"
|
||||||
|
|
||||||
|
namespace Bloom::Widgets
|
||||||
|
{
|
||||||
|
class ByteAddressItem: public QGraphicsItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static constexpr int WIDTH = 84;
|
||||||
|
static constexpr int HEIGHT = ByteItem::HEIGHT;
|
||||||
|
|
||||||
|
ByteAddressItem(QGraphicsItem* parent): QGraphicsItem(parent) {};
|
||||||
|
|
||||||
|
void setAddressHex(const QString& address);
|
||||||
|
|
||||||
|
[[nodiscard]] QRectF boundingRect() const override {
|
||||||
|
return QRectF(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
ByteAddressItem::WIDTH,
|
||||||
|
ByteAddressItem::HEIGHT
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString addressHex;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -25,6 +25,9 @@ hoveredAddressLabel(hoveredAddressLabel),
|
|||||||
parent(parent) {
|
parent(parent) {
|
||||||
this->setObjectName("byte-widget-container");
|
this->setObjectName("byte-widget-container");
|
||||||
|
|
||||||
|
this->byteAddressContainer = new ByteAddressContainer();
|
||||||
|
this->addItem(this->byteAddressContainer);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Construct ByteWidget objects
|
* Construct ByteWidget objects
|
||||||
*
|
*
|
||||||
@@ -72,7 +75,7 @@ void ByteItemGraphicsScene::adjustByteWidgets() {
|
|||||||
constexpr auto byteWidgetWidth = ByteItem::WIDTH + ByteItem::RIGHT_MARGIN;
|
constexpr auto byteWidgetWidth = ByteItem::WIDTH + ByteItem::RIGHT_MARGIN;
|
||||||
constexpr auto byteWidgetHeight = ByteItem::HEIGHT + ByteItem::BOTTOM_MARGIN;
|
constexpr auto byteWidgetHeight = ByteItem::HEIGHT + ByteItem::BOTTOM_MARGIN;
|
||||||
const auto rowCapacity = static_cast<std::size_t>(
|
const auto rowCapacity = static_cast<std::size_t>(
|
||||||
std::floor((width - margins.left() - margins.right()) / byteWidgetWidth)
|
std::floor((width - margins.left() - margins.right() - ByteAddressContainer::WIDTH) / byteWidgetWidth)
|
||||||
);
|
);
|
||||||
const auto rowCount = static_cast<int>(
|
const auto rowCount = static_cast<int>(
|
||||||
std::ceil(static_cast<double>(this->byteWidgetsByAddress.size()) / static_cast<double>(rowCapacity))
|
std::ceil(static_cast<double>(this->byteWidgetsByAddress.size()) / static_cast<double>(rowCapacity))
|
||||||
@@ -88,7 +91,7 @@ void ByteItemGraphicsScene::adjustByteWidgets() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
byteWidget->setPos(
|
byteWidget->setPos(
|
||||||
static_cast<int>(columnIndex * byteWidgetWidth + static_cast<std::size_t>(margins.left())),
|
static_cast<int>(columnIndex * byteWidgetWidth + margins.left() + ByteAddressContainer::WIDTH),
|
||||||
static_cast<int>(rowIndex * byteWidgetHeight + static_cast<std::size_t>(margins.top()))
|
static_cast<int>(rowIndex * byteWidgetHeight + static_cast<std::size_t>(margins.top()))
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -109,7 +112,7 @@ void ByteItemGraphicsScene::adjustByteWidgets() {
|
|||||||
this->byteWidgetsByRowIndex = std::move(byteWidgetsByRowIndex);
|
this->byteWidgetsByRowIndex = std::move(byteWidgetsByRowIndex);
|
||||||
this->byteWidgetsByColumnIndex = std::move(byteWidgetsByColumnIndex);
|
this->byteWidgetsByColumnIndex = std::move(byteWidgetsByColumnIndex);
|
||||||
|
|
||||||
emit this->byteWidgetsAdjusted();
|
this->byteAddressContainer->adjustAddressLabels(this->byteWidgetsByRowIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ByteItemGraphicsScene::onTargetStateChanged(Targets::TargetState newState) {
|
void ByteItemGraphicsScene::onTargetStateChanged(Targets::TargetState newState) {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include "src/Insight/InsightWorker/InsightWorker.hpp"
|
#include "src/Insight/InsightWorker/InsightWorker.hpp"
|
||||||
|
|
||||||
#include "ByteItem.hpp"
|
#include "ByteItem.hpp"
|
||||||
|
#include "ByteAddressContainer.hpp"
|
||||||
|
|
||||||
namespace Bloom::Widgets
|
namespace Bloom::Widgets
|
||||||
{
|
{
|
||||||
@@ -57,6 +58,8 @@ namespace Bloom::Widgets
|
|||||||
QWidget* parent = nullptr;
|
QWidget* parent = nullptr;
|
||||||
QLabel* hoveredAddressLabel = nullptr;
|
QLabel* hoveredAddressLabel = nullptr;
|
||||||
|
|
||||||
|
ByteAddressContainer* byteAddressContainer = nullptr;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onTargetStateChanged(Targets::TargetState newState);
|
void onTargetStateChanged(Targets::TargetState newState);
|
||||||
void onByteWidgetEnter(Bloom::Widgets::ByteItem* widget);
|
void onByteWidgetEnter(Bloom::Widgets::ByteItem* widget);
|
||||||
|
|||||||
Reference in New Issue
Block a user