1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 11:45:53 +01:00

Added missing HiDPI mode support

This commit is contained in:
Martin Tůma 2020-12-28 14:05:51 +01:00
parent 26cbbee135
commit 85d6357cb9
2 changed files with 44 additions and 20 deletions

View File

@ -5,7 +5,7 @@
the supported Qt5 versions up to the last one (5.15). In Qt6 the class the supported Qt5 versions up to the last one (5.15). In Qt6 the class
might change or even disappear in the future, but this is very unlikely might change or even disappear in the future, but this is very unlikely
as there were no changes for several years and The Qt Company's politics as there were no changes for several years and The Qt Company's politics
is: "do not invest any resources into any desktop related stuff unless is: "do not invest any resources into any desktop related stuff unless
absolutely necessary". There is an issue (QTBUG-3897) since the year 2009 to absolutely necessary". There is an issue (QTBUG-3897) since the year 2009 to
include the ZIP reader into the public API, which aptly illustrates the include the ZIP reader into the public API, which aptly illustrates the
effort The Qt Company is willing to make about anything desktop related... effort The Qt Company is willing to make about anything desktop related...
@ -30,9 +30,9 @@
KMZMap::Overlay::Overlay(const QString &path, const QSize &size, KMZMap::Overlay::Overlay(const QString &path, const QSize &size,
const RectC &bbox, double rotation, const Projection *proj) const RectC &bbox, double rotation, const Projection *proj, qreal ratio)
: _path(path), _size(size), _bbox(bbox), _rotation(rotation), _img(0), : _path(path), _size(size), _bbox(bbox), _rotation(rotation), _img(0),
_proj(proj) _proj(proj), _ratio(ratio)
{ {
ReferencePoint tl(PointD(0, 0), _proj->ll2xy(bbox.topLeft())); ReferencePoint tl(PointD(0, 0), _proj->ll2xy(bbox.topLeft()));
ReferencePoint br(PointD(size.width(), size.height()), ReferencePoint br(PointD(size.width(), size.height()),
@ -62,13 +62,15 @@ qreal KMZMap::Overlay::resolution(const QRectF &rect) const
void KMZMap::Overlay::draw(QPainter *painter, const QRectF &rect, Flags flags) void KMZMap::Overlay::draw(QPainter *painter, const QRectF &rect, Flags flags)
{ {
if (_img) { if (_img) {
QRectF rr(rect.topLeft() / _ratio, rect.size());
if (_rotation) { if (_rotation) {
painter->save(); painter->save();
painter->rotate(-_rotation); painter->rotate(-_rotation);
_img->draw(painter, rect, flags); _img->draw(painter, rr, flags);
painter->restore(); painter->restore();
} else } else
_img->draw(painter, rect, flags); _img->draw(painter, rr, flags);
} }
//painter->setPen(Qt::red); //painter->setPen(Qt::red);
@ -80,6 +82,7 @@ void KMZMap::Overlay::load(QZipReader *zip)
if (!_img) { if (!_img) {
QByteArray ba(zip->fileData(_path)); QByteArray ba(zip->fileData(_path));
_img = new Image(QImage::fromData(ba)); _img = new Image(QImage::fromData(ba));
_img->setDevicePixelRatio(_ratio);
} }
} }
@ -106,6 +109,14 @@ void KMZMap::Overlay::setProjection(const Projection *proj)
_transform = Transform(tl, br); _transform = Transform(tl, br);
} }
void KMZMap::Overlay::setDevicePixelRatio(qreal ratio)
{
_ratio = ratio;
if (_img)
_img->setDevicePixelRatio(_ratio);
}
bool KMZMap::resCmp(const Overlay &m1, const Overlay &m2) bool KMZMap::resCmp(const Overlay &m1, const Overlay &m2)
{ {
@ -246,7 +257,8 @@ void KMZMap::groundOverlay(QXmlStreamReader &reader, QZipReader &zip)
QSize size(ir.size()); QSize size(ir.size());
if (size.isValid()) if (size.isValid())
_maps.append(Overlay(image, size, rect, rotation, &_projection)); _maps.append(Overlay(image, size, rect, rotation, &_projection,
_ratio));
else else
reader.raiseError(image + ": Invalid image file"); reader.raiseError(image + ": Invalid image file");
} else } else
@ -295,7 +307,7 @@ void KMZMap::kml(QXmlStreamReader &reader, QZipReader &zip)
KMZMap::KMZMap(const QString &fileName, QObject *parent) KMZMap::KMZMap(const QString &fileName, QObject *parent)
: Map(fileName, parent), _zoom(0), _mapIndex(-1), _zip(0) : Map(fileName, parent), _zoom(0), _mapIndex(-1), _zip(0), _ratio(1.0)
{ {
QZipReader zip(fileName, QIODevice::ReadOnly); QZipReader zip(fileName, QIODevice::ReadOnly);
QByteArray xml(zip.fileData("doc.kml")); QByteArray xml(zip.fileData("doc.kml"));
@ -438,17 +450,9 @@ Coordinates KMZMap::xy2ll(const QPointF &p)
void KMZMap::draw(QPainter *painter, const QRectF &rect, Flags flags) void KMZMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
{ {
QRectF er = rect.adjusted(-_adjust, -_adjust, _adjust, _adjust); QRectF er = rect.adjusted(-_adjust * _ratio, -_adjust * _ratio,
_adjust * _ratio, _adjust * _ratio);
// All in one map
for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).last; i++) {
if (_bounds.at(i).xy.contains(er)) {
draw(painter, er, i, flags);
return;
}
}
// Multiple maps
for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).last; i++) { for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).last; i++) {
QRectF ir = er.intersected(_bounds.at(i).xy); QRectF ir = er.intersected(_bounds.at(i).xy);
if (!ir.isNull()) if (!ir.isNull())
@ -485,6 +489,22 @@ void KMZMap::setInputProjection(const Projection &projection)
computeBounds(); computeBounds();
} }
void KMZMap::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
{
Q_UNUSED(deviceRatio);
if (mapRatio == _ratio)
return;
_ratio = mapRatio;
for (int i = 0; i < _maps.size(); i++)
_maps[i].setDevicePixelRatio(_ratio);
_bounds.clear();
computeBounds();
}
void KMZMap::draw(QPainter *painter, const QRectF &rect, int mapIndex, void KMZMap::draw(QPainter *painter, const QRectF &rect, int mapIndex,
Flags flags) Flags flags)
{ {

View File

@ -36,6 +36,7 @@ public:
void unload(); void unload();
void setInputProjection(const Projection &projection); void setInputProjection(const Projection &projection);
void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio);
bool isValid() const {return _valid;} bool isValid() const {return _valid;}
QString errorString() const {return _errorString;} QString errorString() const {return _errorString;}
@ -44,14 +45,14 @@ private:
class Overlay { class Overlay {
public: public:
Overlay(const QString &path, const QSize &size, const RectC &bbox, Overlay(const QString &path, const QSize &size, const RectC &bbox,
double rotation, const Projection *proj); double rotation, const Projection *proj, qreal ratio);
bool operator==(const Overlay &other) const bool operator==(const Overlay &other) const
{return _path == other._path;} {return _path == other._path;}
QPointF ll2xy(const Coordinates &c) const QPointF ll2xy(const Coordinates &c) const
{return QPointF(_transform.proj2img(_proj->ll2xy(c)));} {return QPointF(_transform.proj2img(_proj->ll2xy(c))) / _ratio;}
Coordinates xy2ll(const QPointF &p) const Coordinates xy2ll(const QPointF &p) const
{return _proj->xy2ll(_transform.img2proj(p));} {return _proj->xy2ll(_transform.img2proj(p * _ratio));}
const QString &path() const {return _path;} const QString &path() const {return _path;}
const RectC &bbox() const {return _bbox;} const RectC &bbox() const {return _bbox;}
@ -65,6 +66,7 @@ private:
void unload(); void unload();
void setProjection(const Projection *proj); void setProjection(const Projection *proj);
void setDevicePixelRatio(qreal ratio);
private: private:
QString _path; QString _path;
@ -75,6 +77,7 @@ private:
Image *_img; Image *_img;
const Projection *_proj; const Projection *_proj;
Transform _transform; Transform _transform;
qreal _ratio;
}; };
struct Zoom { struct Zoom {
@ -117,6 +120,7 @@ private:
QZipReader *_zip; QZipReader *_zip;
qreal _adjust; qreal _adjust;
Projection _projection; Projection _projection;
qreal _ratio;
bool _valid; bool _valid;
QString _errorString; QString _errorString;