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) {
|
||||
painter->setRenderHints(QPainter::RenderHint::Antialiasing | QPainter::RenderHint::SmoothPixmapTransform, true);
|
||||
|
||||
static const auto fontColor = QColor(0x8F, 0x91, 0x92);
|
||||
static const auto widgetRect = this->boundingRect();
|
||||
auto fontColor = QColor(0x8F, 0x91, 0x92);
|
||||
static auto font = painter->font();
|
||||
font.setPixelSize(12);
|
||||
|
||||
if (!this->isEnabled()) {
|
||||
fontColor.setAlpha(100);
|
||||
}
|
||||
|
||||
painter->setFont(font);
|
||||
painter->setPen(fontColor);
|
||||
painter->drawText(widgetRect, Qt::AlignCenter, this->addressHex);
|
||||
|
||||
@@ -19,11 +19,10 @@ namespace Bloom::Widgets
|
||||
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;
|
||||
@@ -33,6 +32,7 @@ namespace Bloom::Widgets
|
||||
std::uint32_t address,
|
||||
std::optional<ByteItem*>& hoveredByteItem
|
||||
);
|
||||
|
||||
void setValue(unsigned char value);
|
||||
|
||||
[[nodiscard]] QRectF boundingRect() const override {
|
||||
@@ -46,6 +46,8 @@ namespace Bloom::Widgets
|
||||
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
|
||||
|
||||
private:
|
||||
unsigned char value = 0x00;
|
||||
bool valueInitialised = false;
|
||||
bool valueChanged = false;
|
||||
|
||||
QString hexValue;
|
||||
|
||||
@@ -35,6 +35,14 @@ ByteItemContainerGraphicsView::ByteItemContainerGraphicsView(
|
||||
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) {
|
||||
Logger::warning("Resizing");
|
||||
this->scene->adjustByteWidgets();
|
||||
|
||||
@@ -39,6 +39,7 @@ namespace Bloom::Widgets
|
||||
}
|
||||
|
||||
protected:
|
||||
bool event(QEvent* event) override;
|
||||
void resizeEvent(QResizeEvent* event) override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -40,7 +40,7 @@ parent(parent) {
|
||||
const auto address = startAddress + i;
|
||||
|
||||
auto* byteWidget = new ByteItem(i, address, this->hoveredByteWidget);
|
||||
this->byteWidgetsByAddress.insert(std::pair(
|
||||
this->byteItemsByAddress.insert(std::pair(
|
||||
address,
|
||||
byteWidget
|
||||
));
|
||||
@@ -59,7 +59,7 @@ parent(parent) {
|
||||
}
|
||||
|
||||
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->update();
|
||||
}
|
||||
@@ -75,7 +75,7 @@ void ByteItemGraphicsScene::adjustByteWidgets() {
|
||||
std::floor((width - margins.left() - margins.right() - ByteAddressContainer::WIDTH) / byteWidgetWidth)
|
||||
);
|
||||
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(
|
||||
@@ -86,14 +86,14 @@ void ByteItemGraphicsScene::adjustByteWidgets() {
|
||||
);
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
std::map<std::size_t, std::vector<ByteItem*>> byteWidgetsByRowIndex;
|
||||
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>(
|
||||
std::ceil(static_cast<double>(byteWidget->byteIndex + 1) / static_cast<double>(rowCapacity)) - 1
|
||||
);
|
||||
@@ -116,10 +116,23 @@ void ByteItemGraphicsScene::adjustByteWidgets() {
|
||||
byteWidget->update();
|
||||
}
|
||||
|
||||
this->byteWidgetsByRowIndex = std::move(byteWidgetsByRowIndex);
|
||||
this->byteWidgetsByColumnIndex = std::move(byteWidgetsByColumnIndex);
|
||||
this->byteItemsByRowIndex = std::move(byteWidgetsByRowIndex);
|
||||
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) {
|
||||
@@ -144,12 +157,12 @@ void ByteItemGraphicsScene::onByteWidgetEnter(ByteItem* widget) {
|
||||
"Relative Address (Absolute Address): " + widget->relativeAddressHex + " (" + widget->addressHex + ")"
|
||||
);
|
||||
|
||||
if (!this->byteWidgetsByRowIndex.empty()) {
|
||||
for (auto& byteWidget : this->byteWidgetsByColumnIndex.at(widget->currentColumnIndex)) {
|
||||
if (!this->byteItemsByRowIndex.empty()) {
|
||||
for (auto& byteWidget : this->byteItemsByColumnIndex.at(widget->currentColumnIndex)) {
|
||||
byteWidget->update();
|
||||
}
|
||||
|
||||
for (auto& byteWidget : this->byteWidgetsByRowIndex.at(widget->currentRowIndex)) {
|
||||
for (auto& byteWidget : this->byteItemsByRowIndex.at(widget->currentRowIndex)) {
|
||||
byteWidget->update();
|
||||
}
|
||||
}
|
||||
@@ -161,12 +174,12 @@ void ByteItemGraphicsScene::onByteWidgetLeave() {
|
||||
|
||||
this->hoveredAddressLabel->setText("Relative Address (Absolute Address):");
|
||||
|
||||
if (!this->byteWidgetsByRowIndex.empty()) {
|
||||
for (auto& byteWidget : this->byteWidgetsByColumnIndex.at(byteItem->currentColumnIndex)) {
|
||||
if (!this->byteItemsByRowIndex.empty()) {
|
||||
for (auto& byteWidget : this->byteItemsByColumnIndex.at(byteItem->currentColumnIndex)) {
|
||||
byteWidget->update();
|
||||
}
|
||||
|
||||
for (auto& byteWidget : this->byteWidgetsByRowIndex.at(byteItem->currentRowIndex)) {
|
||||
for (auto& byteWidget : this->byteItemsByRowIndex.at(byteItem->currentRowIndex)) {
|
||||
byteWidget->update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,9 +29,9 @@ namespace Bloom::Widgets
|
||||
public:
|
||||
std::optional<ByteItem*> hoveredByteWidget;
|
||||
|
||||
std::map<std::uint32_t, ByteItem*> byteWidgetsByAddress;
|
||||
std::map<std::size_t, std::vector<ByteItem*>> byteWidgetsByRowIndex;
|
||||
std::map<std::size_t, std::vector<ByteItem*>> byteWidgetsByColumnIndex;
|
||||
std::map<std::uint32_t, ByteItem*> byteItemsByAddress;
|
||||
std::map<std::size_t, std::vector<ByteItem*>> byteItemsByRowIndex;
|
||||
std::map<std::size_t, std::vector<ByteItem*>> byteItemsByColumnIndex;
|
||||
|
||||
ByteItemGraphicsScene(
|
||||
const Targets::TargetMemoryDescriptor& targetMemoryDescriptor,
|
||||
@@ -44,6 +44,8 @@ namespace Bloom::Widgets
|
||||
|
||||
void adjustByteWidgets();
|
||||
|
||||
void setEnabled(bool enabled);
|
||||
|
||||
signals:
|
||||
void byteWidgetsAdjusted();
|
||||
|
||||
@@ -61,6 +63,8 @@ namespace Bloom::Widgets
|
||||
|
||||
ByteAddressContainer* byteAddressContainer = nullptr;
|
||||
|
||||
bool enabled = true;
|
||||
|
||||
private slots:
|
||||
void onTargetStateChanged(Targets::TargetState newState);
|
||||
void onByteWidgetEnter(Bloom::Widgets::ByteItem* widget);
|
||||
|
||||
Reference in New Issue
Block a user