Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use correct font in painter in **Memory Viewer** dialog. #159

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading