Qt: Memory view alignment adjustment
Jeffrey Pfau jeffrey@endrift.com
Thu, 30 Apr 2015 22:58:06 -0700
4 files changed,
105 insertions(+),
9 deletions(-)
M
src/platform/qt/MemoryModel.cpp
→
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 @@ verticalScrollBar()->setValue(0);
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 @@ for (int y = 0; y < height; ++y) {
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]); } }
M
src/platform/qt/MemoryModel.h
→
src/platform/qt/MemoryModel.h
@@ -27,6 +27,7 @@
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 @@ int m_letterWidth;
uint32_t m_base; uint32_t m_size; int m_top; + int m_align; QMargins m_margins; QVector<QStaticText> m_staticNumbers; QVector<QStaticText> m_staticAscii;
M
src/platform/qt/MemoryView.cpp
→
src/platform/qt/MemoryView.cpp
@@ -24,6 +24,10 @@ m_ui.hexfield->setController(controller);
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())); }
M
src/platform/qt/MemoryView.ui
→
src/platform/qt/MemoryView.ui
@@ -6,8 +6,8 @@ <property name="geometry">
<rect> <x>0</x> <y>0</y> - <width>527</width> - <height>544</height> + <width>550</width> + <height>610</height> </rect> </property> <property name="windowTitle">@@ -85,12 +85,6 @@ <spacer name="horizontalSpacer">
<property name="orientation"> <enum>Qt::Horizontal</enum> </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> </spacer> </item> <item>@@ -109,6 +103,69 @@ <property name="maxLength">
<number>10</number> </property> </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Set Alignment:</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </spacer> + </item> + <item> + <widget class="QRadioButton" name="width8"> + <property name="text"> + <string>1 Byte</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_4"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </spacer> + </item> + <item> + <widget class="QRadioButton" name="width16"> + <property name="text"> + <string>2 Bytes</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_5"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </spacer> + </item> + <item> + <widget class="QRadioButton" name="width32"> + <property name="text"> + <string>4 Bytes</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_3"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </spacer> </item> </layout> </item>