From 28f174fb664677000169d215377b2077e552fae7 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Thu, 30 Apr 2015 22:58:06 -0700 Subject: [PATCH] Qt: Memory view alignment adjustment --- src/platform/qt/MemoryModel.cpp | 35 +++++++++++++++- src/platform/qt/MemoryModel.h | 2 + src/platform/qt/MemoryView.cpp | 4 ++ src/platform/qt/MemoryView.ui | 73 +++++++++++++++++++++++++++++---- 4 files changed, 105 insertions(+), 9 deletions(-) diff --git a/src/platform/qt/MemoryModel.cpp b/src/platform/qt/MemoryModel.cpp index fe823de2b..c34f5f7a0 100644 --- a/src/platform/qt/MemoryModel.cpp +++ b/src/platform/qt/MemoryModel.cpp @@ -23,6 +23,7 @@ MemoryModel::MemoryModel(QWidget* parent) : QAbstractScrollArea(parent) , m_cpu(nullptr) , m_top(0) + , m_align(1) { m_font.setFamily("Source Code Pro"); m_font.setStyleHint(QFont::Monospace); @@ -74,6 +75,14 @@ void MemoryModel::setRegion(uint32_t base, uint32_t size, const QString& name) { viewport()->update(); } +void MemoryModel::setAlignment(int width) { + if (width != 1 && width != 2 && width != 4) { + return; + } + m_align = width; + viewport()->update(); +} + void MemoryModel::resizeEvent(QResizeEvent*) { verticalScrollBar()->setRange(0, (m_size >> 4) + 1 - viewport()->size().height() / m_cellHeight); boundsCheck(); @@ -95,9 +104,33 @@ void MemoryModel::paintEvent(QPaintEvent* event) { int yp = m_cellHeight * y + m_margins.top(); QString data = QString("%0").arg((y + m_top) * 16 + m_base, 8, 16, c0).toUpper(); painter.drawText(QRectF(QPointF(0, yp), QSizeF(m_margins.left(), m_cellHeight)), Qt::AlignHCenter, data); + switch (m_align) { + case 2: + for (int x = 0; x < 16; x += 2) { + uint16_t b = m_cpu->memory.load16(m_cpu, (y + m_top) * 16 + x + m_base, nullptr); + painter.drawStaticText(QPointF(cellSize.width() * (x + 1.0) - 2 * m_letterWidth + m_margins.left(), yp), m_staticNumbers[(b >> 8) & 0xFF]); + painter.drawStaticText(QPointF(cellSize.width() * (x + 1.0) + m_margins.left(), yp), m_staticNumbers[b & 0xFF]); + } + break; + case 4: + for (int x = 0; x < 16; x += 4) { + uint32_t b = m_cpu->memory.load32(m_cpu, (y + m_top) * 16 + x + m_base, nullptr); + painter.drawStaticText(QPointF(cellSize.width() * (x + 2.0) - 4 * m_letterWidth + m_margins.left(), yp), m_staticNumbers[(b >> 24) & 0xFF]); + painter.drawStaticText(QPointF(cellSize.width() * (x + 2.0) - 2 * m_letterWidth + m_margins.left(), yp), m_staticNumbers[(b >> 16) & 0xFF]); + painter.drawStaticText(QPointF(cellSize.width() * (x + 2.0) + m_margins.left(), yp), m_staticNumbers[(b >> 8) & 0xFF]); + painter.drawStaticText(QPointF(cellSize.width() * (x + 2.0) + 2 * m_letterWidth + m_margins.left(), yp), m_staticNumbers[b & 0xFF]); + } + break; + case 1: + default: + for (int x = 0; x < 16; ++x) { + uint8_t b = m_cpu->memory.load8(m_cpu, (y + m_top) * 16 + x + m_base, nullptr); + painter.drawStaticText(QPointF(cellSize.width() * (x + 0.5) - m_letterWidth + m_margins.left(), yp), m_staticNumbers[b]); + } + break; + } for (int x = 0; x < 16; ++x) { uint8_t b = m_cpu->memory.load8(m_cpu, (y + m_top) * 16 + x + m_base, nullptr); - painter.drawStaticText(QPointF(cellSize.width() * (x + 0.5) - m_letterWidth + m_margins.left(), yp), m_staticNumbers[b]); painter.drawStaticText(QPointF(viewport()->size().width() - (16 - x) * m_margins.right() / 17.0 - m_letterWidth * 0.5, yp), b < 0x80 ? m_staticAscii[b] : m_staticAscii[0]); } } diff --git a/src/platform/qt/MemoryModel.h b/src/platform/qt/MemoryModel.h index 911657e36..272b29833 100644 --- a/src/platform/qt/MemoryModel.h +++ b/src/platform/qt/MemoryModel.h @@ -27,6 +27,7 @@ public: void setController(GameController* controller); void setRegion(uint32_t base, uint32_t size, const QString& name = QString()); + void setAlignment(int); protected: void resizeEvent(QResizeEvent*) override; @@ -43,6 +44,7 @@ private: uint32_t m_base; uint32_t m_size; int m_top; + int m_align; QMargins m_margins; QVector m_staticNumbers; QVector m_staticAscii; diff --git a/src/platform/qt/MemoryView.cpp b/src/platform/qt/MemoryView.cpp index 62a899d7d..195f957e3 100644 --- a/src/platform/qt/MemoryView.cpp +++ b/src/platform/qt/MemoryView.cpp @@ -24,6 +24,10 @@ MemoryView::MemoryView(GameController* controller, QWidget* parent) connect(m_ui.regions, SIGNAL(currentIndexChanged(int)), this, SLOT(setIndex(int))); + connect(m_ui.width8, &QAbstractButton::clicked, [this]() { m_ui.hexfield->setAlignment(1); }); + connect(m_ui.width16, &QAbstractButton::clicked, [this]() { m_ui.hexfield->setAlignment(2); }); + connect(m_ui.width32, &QAbstractButton::clicked, [this]() { m_ui.hexfield->setAlignment(4); }); + connect(controller, SIGNAL(gameStopped(GBAThread*)), this, SLOT(close())); } diff --git a/src/platform/qt/MemoryView.ui b/src/platform/qt/MemoryView.ui index 550d40e70..25ca12d0a 100644 --- a/src/platform/qt/MemoryView.ui +++ b/src/platform/qt/MemoryView.ui @@ -6,8 +6,8 @@ 0 0 - 527 - 544 + 550 + 610 @@ -85,12 +85,6 @@ Qt::Horizontal - - - 40 - 20 - - @@ -112,6 +106,69 @@ + + + + + + Set Alignment: + + + + + + + Qt::Horizontal + + + + + + + 1 Byte + + + true + + + + + + + Qt::Horizontal + + + + + + + 2 Bytes + + + + + + + Qt::Horizontal + + + + + + + 4 Bytes + + + + + + + Qt::Horizontal + + + + +