Skip to content

Commit

Permalink
Avoid hardcoding initial font size in **Memory Viewer** dialog.
Browse files Browse the repository at this point in the history
The initial font size for the **Memory Viewer** dialog is now based on a
percentage of the default font size.
  • Loading branch information
cristian64 committed May 31, 2024
1 parent 5ef5be8 commit ff6308f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
18 changes: 13 additions & 5 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,9 +373,12 @@ 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);
}

QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
fixedFont.setPointSize(m_memoryFontSize);
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 ff6308f

Please sign in to comment.