2018-08-23 20:26:10 +02:00
|
|
|
#include <QPainter>
|
|
|
|
#include "image.h"
|
|
|
|
|
|
|
|
|
2018-08-24 12:26:32 +02:00
|
|
|
#define TILE_SIZE 256
|
|
|
|
|
2018-08-23 20:26:10 +02:00
|
|
|
void Image::draw(QPainter *painter, const QRectF &rect, Map::Flags flags)
|
|
|
|
{
|
2018-08-24 00:14:40 +02:00
|
|
|
qreal ratio = _img.devicePixelRatioF();
|
|
|
|
QRectF sr(rect.topLeft() * ratio, rect.size() * ratio);
|
2018-08-23 20:26:10 +02:00
|
|
|
|
2020-11-27 01:11:50 +01:00
|
|
|
/* 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
|
2023-02-22 23:22:18 +01:00
|
|
|
we have to tile the image ourself before it can be drawn. */
|
2018-08-23 20:26:10 +02:00
|
|
|
if (flags & Map::OpenGL) {
|
2018-08-24 12:26:32 +02:00
|
|
|
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);
|
2020-11-27 01:11:50 +01:00
|
|
|
QRect tile(tl, QSize(TILE_SIZE, TILE_SIZE));
|
2023-02-22 23:22:18 +01:00
|
|
|
QPixmap pm(QPixmap::fromImage(_img.copy(tile)));
|
|
|
|
pm.setDevicePixelRatio(ratio);
|
|
|
|
painter->drawPixmap(tl/ratio, pm);
|
2018-08-24 12:26:32 +02:00
|
|
|
}
|
|
|
|
}
|
2018-08-23 20:26:10 +02:00
|
|
|
} else
|
|
|
|
painter->drawImage(rect.topLeft(), _img, sr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Image::setDevicePixelRatio(qreal ratio)
|
|
|
|
{
|
2018-08-24 00:14:40 +02:00
|
|
|
_img.setDevicePixelRatio(ratio);
|
2018-08-23 20:26:10 +02:00
|
|
|
}
|