Styling disabled byte items in hex viewer widget
This commit is contained in:
@@ -12,11 +12,15 @@ void ByteAddressItem::setAddressHex(const QString& addressHex) {
|
|||||||
void ByteAddressItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
|
void ByteAddressItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
|
||||||
painter->setRenderHints(QPainter::RenderHint::Antialiasing | QPainter::RenderHint::SmoothPixmapTransform, true);
|
painter->setRenderHints(QPainter::RenderHint::Antialiasing | QPainter::RenderHint::SmoothPixmapTransform, true);
|
||||||
|
|
||||||
static const auto fontColor = QColor(0x8F, 0x91, 0x92);
|
|
||||||
static const auto widgetRect = this->boundingRect();
|
static const auto widgetRect = this->boundingRect();
|
||||||
|
auto fontColor = QColor(0x8F, 0x91, 0x92);
|
||||||
static auto font = painter->font();
|
static auto font = painter->font();
|
||||||
font.setPixelSize(12);
|
font.setPixelSize(12);
|
||||||
|
|
||||||
|
if (!this->isEnabled()) {
|
||||||
|
fontColor.setAlpha(100);
|
||||||
|
}
|
||||||
|
|
||||||
painter->setFont(font);
|
painter->setFont(font);
|
||||||
painter->setPen(fontColor);
|
painter->setPen(fontColor);
|
||||||
painter->drawText(widgetRect, Qt::AlignCenter, this->addressHex);
|
painter->drawText(widgetRect, Qt::AlignCenter, this->addressHex);
|
||||||
|
|||||||
@@ -19,11 +19,10 @@ namespace Bloom::Widgets
|
|||||||
static constexpr int BOTTOM_MARGIN = 5;
|
static constexpr int BOTTOM_MARGIN = 5;
|
||||||
|
|
||||||
std::size_t byteIndex;
|
std::size_t byteIndex;
|
||||||
unsigned char value = 0x00;
|
|
||||||
std::uint32_t address = 0x00;
|
std::uint32_t address = 0x00;
|
||||||
|
|
||||||
QString addressHex;
|
QString addressHex;
|
||||||
QString relativeAddressHex;
|
QString relativeAddressHex;
|
||||||
bool valueInitialised = false;
|
|
||||||
|
|
||||||
std::size_t currentRowIndex = 0;
|
std::size_t currentRowIndex = 0;
|
||||||
std::size_t currentColumnIndex = 0;
|
std::size_t currentColumnIndex = 0;
|
||||||
@@ -33,6 +32,7 @@ namespace Bloom::Widgets
|
|||||||
std::uint32_t address,
|
std::uint32_t address,
|
||||||
std::optional<ByteItem*>& hoveredByteItem
|
std::optional<ByteItem*>& hoveredByteItem
|
||||||
);
|
);
|
||||||
|
|
||||||
void setValue(unsigned char value);
|
void setValue(unsigned char value);
|
||||||
|
|
||||||
[[nodiscard]] QRectF boundingRect() const override {
|
[[nodiscard]] QRectF boundingRect() const override {
|
||||||
@@ -46,6 +46,8 @@ namespace Bloom::Widgets
|
|||||||
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
|
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
unsigned char value = 0x00;
|
||||||
|
bool valueInitialised = false;
|
||||||
bool valueChanged = false;
|
bool valueChanged = false;
|
||||||
|
|
||||||
QString hexValue;
|
QString hexValue;
|
||||||
|
|||||||
@@ -35,6 +35,14 @@ ByteItemContainerGraphicsView::ByteItemContainerGraphicsView(
|
|||||||
this->setScene(this->scene);
|
this->setScene(this->scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ByteItemContainerGraphicsView::event(QEvent* event) {
|
||||||
|
if (event->type() == QEvent::Type::EnabledChange) {
|
||||||
|
this->scene->setEnabled(this->isEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
return QGraphicsView::event(event);
|
||||||
|
}
|
||||||
|
|
||||||
void ByteItemContainerGraphicsView::resizeEvent(QResizeEvent* event) {
|
void ByteItemContainerGraphicsView::resizeEvent(QResizeEvent* event) {
|
||||||
Logger::warning("Resizing");
|
Logger::warning("Resizing");
|
||||||
this->scene->adjustByteWidgets();
|
this->scene->adjustByteWidgets();
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ namespace Bloom::Widgets
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
bool event(QEvent* event) override;
|
||||||
void resizeEvent(QResizeEvent* event) override;
|
void resizeEvent(QResizeEvent* event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ parent(parent) {
|
|||||||
const auto address = startAddress + i;
|
const auto address = startAddress + i;
|
||||||
|
|
||||||
auto* byteWidget = new ByteItem(i, address, this->hoveredByteWidget);
|
auto* byteWidget = new ByteItem(i, address, this->hoveredByteWidget);
|
||||||
this->byteWidgetsByAddress.insert(std::pair(
|
this->byteItemsByAddress.insert(std::pair(
|
||||||
address,
|
address,
|
||||||
byteWidget
|
byteWidget
|
||||||
));
|
));
|
||||||
@@ -59,7 +59,7 @@ parent(parent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ByteItemGraphicsScene::updateValues(const Targets::TargetMemoryBuffer& buffer) {
|
void ByteItemGraphicsScene::updateValues(const Targets::TargetMemoryBuffer& buffer) {
|
||||||
for (auto& [address, byteWidget] : this->byteWidgetsByAddress) {
|
for (auto& [address, byteWidget] : this->byteItemsByAddress) {
|
||||||
byteWidget->setValue(buffer.at(byteWidget->byteIndex));
|
byteWidget->setValue(buffer.at(byteWidget->byteIndex));
|
||||||
byteWidget->update();
|
byteWidget->update();
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,7 @@ void ByteItemGraphicsScene::adjustByteWidgets() {
|
|||||||
std::floor((width - margins.left() - margins.right() - ByteAddressContainer::WIDTH) / 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->byteItemsByAddress.size()) / static_cast<double>(rowCapacity))
|
||||||
);
|
);
|
||||||
|
|
||||||
this->setSceneRect(
|
this->setSceneRect(
|
||||||
@@ -86,14 +86,14 @@ void ByteItemGraphicsScene::adjustByteWidgets() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Don't bother recalculating the byte item positions if the number of rows have not changed.
|
// Don't bother recalculating the byte item positions if the number of rows have not changed.
|
||||||
if (rowCount == this->byteWidgetsByRowIndex.size()) {
|
if (rowCount == this->byteItemsByRowIndex.size()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::size_t, std::vector<ByteItem*>> byteWidgetsByRowIndex;
|
std::map<std::size_t, std::vector<ByteItem*>> byteWidgetsByRowIndex;
|
||||||
std::map<std::size_t, std::vector<ByteItem*>> byteWidgetsByColumnIndex;
|
std::map<std::size_t, std::vector<ByteItem*>> byteWidgetsByColumnIndex;
|
||||||
|
|
||||||
for (auto& [address, byteWidget] : this->byteWidgetsByAddress) {
|
for (auto& [address, byteWidget] : this->byteItemsByAddress) {
|
||||||
const auto rowIndex = static_cast<std::size_t>(
|
const auto rowIndex = static_cast<std::size_t>(
|
||||||
std::ceil(static_cast<double>(byteWidget->byteIndex + 1) / static_cast<double>(rowCapacity)) - 1
|
std::ceil(static_cast<double>(byteWidget->byteIndex + 1) / static_cast<double>(rowCapacity)) - 1
|
||||||
);
|
);
|
||||||
@@ -116,10 +116,23 @@ void ByteItemGraphicsScene::adjustByteWidgets() {
|
|||||||
byteWidget->update();
|
byteWidget->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
this->byteWidgetsByRowIndex = std::move(byteWidgetsByRowIndex);
|
this->byteItemsByRowIndex = std::move(byteWidgetsByRowIndex);
|
||||||
this->byteWidgetsByColumnIndex = std::move(byteWidgetsByColumnIndex);
|
this->byteItemsByColumnIndex = std::move(byteWidgetsByColumnIndex);
|
||||||
|
|
||||||
this->byteAddressContainer->adjustAddressLabels(this->byteWidgetsByRowIndex);
|
this->byteAddressContainer->adjustAddressLabels(this->byteItemsByRowIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ByteItemGraphicsScene::setEnabled(bool enabled) {
|
||||||
|
if (this->enabled != enabled) {
|
||||||
|
this->enabled = enabled;
|
||||||
|
|
||||||
|
for (auto& [byteAddress, byteItem] : this->byteItemsByAddress) {
|
||||||
|
byteItem->setEnabled(this->enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->byteAddressContainer->setEnabled(enabled);
|
||||||
|
this->update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ByteItemGraphicsScene::onTargetStateChanged(Targets::TargetState newState) {
|
void ByteItemGraphicsScene::onTargetStateChanged(Targets::TargetState newState) {
|
||||||
@@ -144,12 +157,12 @@ void ByteItemGraphicsScene::onByteWidgetEnter(ByteItem* widget) {
|
|||||||
"Relative Address (Absolute Address): " + widget->relativeAddressHex + " (" + widget->addressHex + ")"
|
"Relative Address (Absolute Address): " + widget->relativeAddressHex + " (" + widget->addressHex + ")"
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!this->byteWidgetsByRowIndex.empty()) {
|
if (!this->byteItemsByRowIndex.empty()) {
|
||||||
for (auto& byteWidget : this->byteWidgetsByColumnIndex.at(widget->currentColumnIndex)) {
|
for (auto& byteWidget : this->byteItemsByColumnIndex.at(widget->currentColumnIndex)) {
|
||||||
byteWidget->update();
|
byteWidget->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& byteWidget : this->byteWidgetsByRowIndex.at(widget->currentRowIndex)) {
|
for (auto& byteWidget : this->byteItemsByRowIndex.at(widget->currentRowIndex)) {
|
||||||
byteWidget->update();
|
byteWidget->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -161,12 +174,12 @@ void ByteItemGraphicsScene::onByteWidgetLeave() {
|
|||||||
|
|
||||||
this->hoveredAddressLabel->setText("Relative Address (Absolute Address):");
|
this->hoveredAddressLabel->setText("Relative Address (Absolute Address):");
|
||||||
|
|
||||||
if (!this->byteWidgetsByRowIndex.empty()) {
|
if (!this->byteItemsByRowIndex.empty()) {
|
||||||
for (auto& byteWidget : this->byteWidgetsByColumnIndex.at(byteItem->currentColumnIndex)) {
|
for (auto& byteWidget : this->byteItemsByColumnIndex.at(byteItem->currentColumnIndex)) {
|
||||||
byteWidget->update();
|
byteWidget->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& byteWidget : this->byteWidgetsByRowIndex.at(byteItem->currentRowIndex)) {
|
for (auto& byteWidget : this->byteItemsByRowIndex.at(byteItem->currentRowIndex)) {
|
||||||
byteWidget->update();
|
byteWidget->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,9 +29,9 @@ namespace Bloom::Widgets
|
|||||||
public:
|
public:
|
||||||
std::optional<ByteItem*> hoveredByteWidget;
|
std::optional<ByteItem*> hoveredByteWidget;
|
||||||
|
|
||||||
std::map<std::uint32_t, ByteItem*> byteWidgetsByAddress;
|
std::map<std::uint32_t, ByteItem*> byteItemsByAddress;
|
||||||
std::map<std::size_t, std::vector<ByteItem*>> byteWidgetsByRowIndex;
|
std::map<std::size_t, std::vector<ByteItem*>> byteItemsByRowIndex;
|
||||||
std::map<std::size_t, std::vector<ByteItem*>> byteWidgetsByColumnIndex;
|
std::map<std::size_t, std::vector<ByteItem*>> byteItemsByColumnIndex;
|
||||||
|
|
||||||
ByteItemGraphicsScene(
|
ByteItemGraphicsScene(
|
||||||
const Targets::TargetMemoryDescriptor& targetMemoryDescriptor,
|
const Targets::TargetMemoryDescriptor& targetMemoryDescriptor,
|
||||||
@@ -44,6 +44,8 @@ namespace Bloom::Widgets
|
|||||||
|
|
||||||
void adjustByteWidgets();
|
void adjustByteWidgets();
|
||||||
|
|
||||||
|
void setEnabled(bool enabled);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void byteWidgetsAdjusted();
|
void byteWidgetsAdjusted();
|
||||||
|
|
||||||
@@ -61,6 +63,8 @@ namespace Bloom::Widgets
|
|||||||
|
|
||||||
ByteAddressContainer* byteAddressContainer = nullptr;
|
ByteAddressContainer* byteAddressContainer = nullptr;
|
||||||
|
|
||||||
|
bool enabled = true;
|
||||||
|
|
||||||
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