Qt: Fix status size on non-HiDPI displays

This commit is contained in:
Jeffrey Pfau 2015-04-27 02:00:58 -07:00
parent 711c7e9903
commit 57999df85e
1 changed files with 10 additions and 11 deletions

View File

@ -160,7 +160,7 @@ PainterGL::PainterGL(QGLWidget* parent)
{ {
m_messageFont.setFamily("Source Code Pro"); m_messageFont.setFamily("Source Code Pro");
m_messageFont.setStyleHint(QFont::Monospace); m_messageFont.setStyleHint(QFont::Monospace);
m_messageFont.setPixelSize(6); m_messageFont.setPixelSize(13);
connect(&m_messageTimer, SIGNAL(timeout()), this, SLOT(clearMessage())); connect(&m_messageTimer, SIGNAL(timeout()), this, SLOT(clearMessage()));
m_messageTimer.setSingleShot(true); m_messageTimer.setSingleShot(true);
m_messageTimer.setInterval(5000); m_messageTimer.setInterval(5000);
@ -189,8 +189,8 @@ void PainterGL::setBacking(const uint32_t* backing) {
void PainterGL::resize(const QSize& size) { void PainterGL::resize(const QSize& size) {
m_size = size; m_size = size;
int w = m_size.width() * m_gl->devicePixelRatio(); int w = m_size.width();
int h = m_size.height() *m_gl->devicePixelRatio(); int h = m_size.height();
int drawW = w; int drawW = w;
int drawH = h; int drawH = h;
if (m_lockAspectRatio) { if (m_lockAspectRatio) {
@ -202,11 +202,9 @@ void PainterGL::resize(const QSize& size) {
} }
m_viewport = QRect((w - drawW) / 2, (h - drawH) / 2, drawW, drawH); m_viewport = QRect((w - drawW) / 2, (h - drawH) / 2, drawW, drawH);
m_painter.begin(m_gl->context()->device()); m_painter.begin(m_gl->context()->device());
m_world = QTransform( m_world.reset();
qreal(drawW) / VIDEO_HORIZONTAL_PIXELS, 0, m_world.translate(m_viewport.x(), m_viewport.y());
0, qreal(drawH) / VIDEO_VERTICAL_PIXELS, m_world.scale(qreal(drawW) / VIDEO_HORIZONTAL_PIXELS, qreal(drawH) / VIDEO_VERTICAL_PIXELS);
m_viewport.x() / 2,
m_viewport.y() / 2);
m_painter.setWorldTransform(m_world); m_painter.setWorldTransform(m_world);
m_painter.setFont(m_messageFont); m_painter.setFont(m_messageFont);
m_message.prepare(m_world, m_messageFont); m_message.prepare(m_world, m_messageFont);
@ -319,7 +317,8 @@ void PainterGL::performDraw() {
glViewport(0, 0, m_size.width() * m_gl->devicePixelRatio(), m_size.height() * m_gl->devicePixelRatio()); glViewport(0, 0, m_size.width() * m_gl->devicePixelRatio(), m_size.height() * m_gl->devicePixelRatio());
glClearColor(0, 0, 0, 0); glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
glViewport(m_viewport.x(), m_viewport.y(), m_viewport.width(), m_viewport.height()); QRect viewport(m_viewport.topLeft() * m_gl->devicePixelRatio(), m_viewport.size() * m_gl->devicePixelRatio());
glViewport(viewport.x(), viewport.y(), viewport.width(), viewport.height());
glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
if (m_context->sync.videoFrameWait) { if (m_context->sync.videoFrameWait) {
glFlush(); glFlush();
@ -328,10 +327,10 @@ void PainterGL::performDraw() {
m_painter.setRenderHint(QPainter::Antialiasing); m_painter.setRenderHint(QPainter::Antialiasing);
m_painter.setFont(m_messageFont); m_painter.setFont(m_messageFont);
m_painter.setPen(Qt::black); m_painter.setPen(Qt::black);
m_painter.translate(1, 72); m_painter.translate(1, VIDEO_VERTICAL_PIXELS - m_messageFont.pixelSize() - 1);
for (int i = 0; i < 16; ++i) { for (int i = 0; i < 16; ++i) {
m_painter.save(); m_painter.save();
m_painter.translate(cos(i * M_PI / 8.0) * 0.4, sin(i * M_PI / 8.0) * 0.4); m_painter.translate(cos(i * M_PI / 8.0) * 0.8, sin(i * M_PI / 8.0) * 0.8);
m_painter.drawStaticText(0, 0, m_message); m_painter.drawStaticText(0, 0, m_message);
m_painter.restore(); m_painter.restore();
} }