Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[Qt] Fix map aspect ratio
Browse files Browse the repository at this point in the history
Take QGuiApplication::devicePixelRatio() in consideration when resizing
the map.

Fixes #4889.
  • Loading branch information
brunoabinader committed May 13, 2016
1 parent d36111a commit c1dde52
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
9 changes: 6 additions & 3 deletions platform/qt/app/mapwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,16 @@ void MapWindow::initializeGL()

void MapWindow::resizeGL(int w, int h)
{
m_map.resize(QSize(w, h));
QSize size(w, h);
#if QT_VERSION >= 0x050000
size /= qApp->devicePixelRatio();
#endif
m_map.resize(size);
glViewport(0, 0, size.width(), size.height());
}

void MapWindow::paintGL()
{
glViewport(0, 0, width(), height());

m_frameDraws++;
m_map.render();
}
9 changes: 9 additions & 0 deletions platform/qt/src/qmapboxgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
#include <mbgl/util/geo.hpp>
#include <mbgl/util/traits.hpp>

#if QT_VERSION >= 0x050000
#include <QGuiApplication>
#else
#include <QCoreApplication>
#endif

#include <QImage>
#include <QMapboxGL>
#include <QMargins>
Expand Down Expand Up @@ -636,8 +641,12 @@ QMapboxGLPrivate::~QMapboxGLPrivate()

float QMapboxGLPrivate::getPixelRatio() const
{
#if QT_VERSION >= 0x050000
return qApp->devicePixelRatio();
#else
// FIXME: Should handle pixel ratio.
return 1.0;
#endif
}

std::array<uint16_t, 2> QMapboxGLPrivate::getSize() const
Expand Down
3 changes: 2 additions & 1 deletion platform/qt/src/qquickmapboxglrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <QMapboxGL>
#include <QQuickMapboxGL>

#include <QGuiApplication>
#include <QSize>
#include <QOpenGLFramebufferObject>
#include <QOpenGLFramebufferObjectFormat>
Expand All @@ -27,7 +28,7 @@ QQuickMapboxGLRenderer::~QQuickMapboxGLRenderer()

QOpenGLFramebufferObject* QQuickMapboxGLRenderer::createFramebufferObject(const QSize &size)
{
m_map->resize(size);
m_map->resize(size / qApp->devicePixelRatio());

QOpenGLFramebufferObjectFormat format;
format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
Expand Down

0 comments on commit c1dde52

Please sign in to comment.