Skip to content

Commit

Permalink
Merge pull request #159 from cristian64/adjust_memory_viewer_font_size
Browse files Browse the repository at this point in the history
Use correct font in painter in **Memory Viewer** dialog.
  • Loading branch information
dreamsyntax authored May 31, 2024
2 parents 82e1314 + ff6308f commit 9ab59e3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
25 changes: 14 additions & 11 deletions Source/GUI/MemViewer/MemViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ MemViewer::~MemViewer()

void MemViewer::initialise()
{
updateFontSize(m_memoryFontSize);
updateFontSize();
m_curosrRect = new QRect();
m_updatedRawMemoryData = new char[m_numCells];
m_lastRawMemoryData = new char[m_numCells];
Expand Down Expand Up @@ -356,9 +356,14 @@ void MemViewer::wheelEvent(QWheelEvent* event)
if (event->modifiers().testFlag(Qt::ControlModifier))
{
if (event->angleDelta().y() < 0 && m_memoryFontSize > 5)
updateFontSize(m_memoryFontSize - 1);
{
m_memoryFontSize -= 1;
}
else if (event->angleDelta().y() > 0)
updateFontSize(m_memoryFontSize + 1);
{
m_memoryFontSize += 1;
}
updateFontSize();

viewport()->update();
}
Expand All @@ -368,19 +373,16 @@ void MemViewer::wheelEvent(QWheelEvent* event)
}
}

void MemViewer::updateFontSize(int newSize)
void MemViewer::updateFontSize()
{
m_memoryFontSize = newSize;
if (m_memoryFontSize == -1)
{
m_memoryFontSize = static_cast<int>(font().pointSize() * 1.5);
}

#ifdef __linux__
setFont(QFont("Monospace", m_memoryFontSize));
#elif _WIN32
setFont(QFont("Courier New", m_memoryFontSize));
#elif __APPLE__
QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
fixedFont.setPointSize(m_memoryFontSize);
setFont(fixedFont);
#endif

m_charWidthEm = fontMetrics().horizontalAdvance(QLatin1Char('M'));
m_charHeight = fontMetrics().height();
Expand Down Expand Up @@ -1013,6 +1015,7 @@ void MemViewer::paintEvent(QPaintEvent* event)
(void)event;

QPainter painter(viewport());
painter.setFont(font());
painter.setPen(QColor(Qt::black));

renderSeparatorLines(painter);
Expand Down
4 changes: 2 additions & 2 deletions Source/GUI/MemViewer/MemViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class MemViewer : public QAbstractScrollArea

void initialise();

void updateFontSize(int newSize);
void updateFontSize();
bytePosFromMouse mousePosToBytePos(QPoint pos);
void scrollToSelection();
void copySelection(Common::MemType type) const;
Expand All @@ -93,7 +93,7 @@ class MemViewer : public QAbstractScrollArea
const int m_numRows = 16;
const int m_numColumns = 16; // Should be a multiple of 16, or the header doesn't make much sense
const int m_numCells = m_numRows * m_numColumns;
int m_memoryFontSize = 15;
int m_memoryFontSize = -1;
int m_StartBytesSelectionPosX = 0;
int m_StartBytesSelectionPosY = 0;
int m_EndBytesSelectionPosX = 0;
Expand Down

0 comments on commit 9ab59e3

Please sign in to comment.