2018-08-23 20:26:10 +02:00
|
|
|
#include <QPainter>
|
|
|
|
#include "config.h"
|
|
|
|
#include "image.h"
|
|
|
|
|
|
|
|
|
2018-08-24 00:14:40 +02:00
|
|
|
Image::Image(const QString &fileName) : _img(fileName)
|
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
|
|
|
|
|
|
|
if (flags & Map::OpenGL) {
|
|
|
|
QImage img(_img.copy(sr.toRect()));
|
|
|
|
painter->drawImage(rect.topLeft(), img);
|
|
|
|
} else
|
|
|
|
painter->drawImage(rect.topLeft(), _img, sr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Image::setDevicePixelRatio(qreal ratio)
|
|
|
|
{
|
|
|
|
#ifdef ENABLE_HIDPI
|
2018-08-24 00:14:40 +02:00
|
|
|
_img.setDevicePixelRatio(ratio);
|
2018-08-23 20:26:10 +02:00
|
|
|
#endif // ENABLE_HIDPI
|
|
|
|
}
|