1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-12-04 16:29:09 +01:00
GPXSee/src/map/image.cpp
Martin Tůma 7a53fb8e01 Remove the qpainter/qimage draw workaround
Seems to be fixed in newer Qt versions and it did not properly work in older
Qt versions anyway...
2023-02-22 23:22:18 +01:00

33 lines
996 B
C++

#include <QPainter>
#include "image.h"
#define TILE_SIZE 256
void Image::draw(QPainter *painter, const QRectF &rect, Map::Flags flags)
{
qreal ratio = _img.devicePixelRatioF();
QRectF sr(rect.topLeft() * ratio, rect.size() * ratio);
/* When OpenGL is used, big images are rendered incredibly slow or not at
all using the QPainter::drawImage() function with a source rect set. So
we have to tile the image ourself before it can be drawn. */
if (flags & Map::OpenGL) {
for (int i = sr.left()/TILE_SIZE; i <= sr.right()/TILE_SIZE; i++) {
for (int j = sr.top()/TILE_SIZE; j <= sr.bottom()/TILE_SIZE; j++) {
QPoint tl(i * TILE_SIZE, j * TILE_SIZE);
QRect tile(tl, QSize(TILE_SIZE, TILE_SIZE));
QPixmap pm(QPixmap::fromImage(_img.copy(tile)));
pm.setDevicePixelRatio(ratio);
painter->drawPixmap(tl/ratio, pm);
}
}
} else
painter->drawImage(rect.topLeft(), _img, sr);
}
void Image::setDevicePixelRatio(qreal ratio)
{
_img.setDevicePixelRatio(ratio);
}