mirror of
https://github.com/tumic0/QtPBFImagePlugin.git
synced 2024-11-23 19:25:55 +01:00
Added support for QT < 5.6 (and >= 5.4)
This commit is contained in:
parent
368c53307d
commit
c1af3d82a5
@ -1,7 +1,8 @@
|
||||
language: c++
|
||||
dist: xenial
|
||||
|
||||
os:
|
||||
# - linux
|
||||
- linux
|
||||
- osx
|
||||
|
||||
env:
|
||||
|
@ -20,7 +20,8 @@ HEADERS += src/pbfhandler.h \
|
||||
src/textpointitem.h \
|
||||
src/font.h \
|
||||
src/textitem.h \
|
||||
src/sprites.h
|
||||
src/sprites.h \
|
||||
src/config.h
|
||||
SOURCES += src/pbfplugin.cpp \
|
||||
src/pbfhandler.cpp \
|
||||
src/gzip.cpp \
|
||||
|
10
src/config.h
Normal file
10
src/config.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
|
||||
#define ENABLE_HIDPI
|
||||
#endif // QT >= 5.6
|
||||
|
||||
#endif // CONFIG_H
|
@ -530,34 +530,43 @@ bool Style::load(const QString &fileName)
|
||||
|
||||
QDir styleDir = QFileInfo(fileName).absoluteDir();
|
||||
loadSprites(styleDir, "sprite.json", "sprite.png", _sprites);
|
||||
#ifdef ENABLE_HIDPI
|
||||
loadSprites(styleDir, "sprite@2x.json", "sprite@2x.png", _sprites2x);
|
||||
#endif // ENABLE_HIDPI
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const Sprites &Style::sprites(const QPointF &scale) const
|
||||
{
|
||||
#ifdef ENABLE_HIDPI
|
||||
return (scale.x() > 1.0 || scale.y() > 1.0)
|
||||
&& !_sprites2x.isNull() ? _sprites2x : _sprites;
|
||||
#else // ENABLE_HIDPI
|
||||
Q_UNUSED(scale);
|
||||
return _sprites;
|
||||
#endif // ENABLE_HIDPI
|
||||
}
|
||||
|
||||
void Style::setupLayer(Tile &tile, int layer) const
|
||||
{
|
||||
const Layer &sl = _layers.at(layer);
|
||||
const Sprites &sprites = (tile.scale().x() > 1.0 || tile.scale().y() > 1.0)
|
||||
&& !_sprites2x.isNull() ? _sprites2x : _sprites;
|
||||
|
||||
if (sl.isSymbol())
|
||||
sl.setTextProperties(tile);
|
||||
else if (sl.isPath())
|
||||
sl.setPathPainter(tile, sprites);
|
||||
sl.setPathPainter(tile, sprites(tile.scale()));
|
||||
}
|
||||
|
||||
void Style::drawFeature(Tile &tile, int layer, const QPainterPath &path,
|
||||
const QVariantHash &tags) const
|
||||
{
|
||||
const Layer &sl = _layers.at(layer);
|
||||
const Sprites &sprites = (tile.scale().x() > 1.0 || tile.scale().y() > 1.0)
|
||||
&& !_sprites2x.isNull() ? _sprites2x : _sprites;
|
||||
|
||||
if (sl.isPath())
|
||||
tile.painter().drawPath(path);
|
||||
else if (sl.isSymbol())
|
||||
sl.addSymbol(tile, path, tags, sprites);
|
||||
sl.addSymbol(tile, path, tags, sprites(tile.scale()));
|
||||
}
|
||||
|
||||
void Style::drawBackground(Tile &tile) const
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <QPen>
|
||||
#include <QBrush>
|
||||
#include <QFont>
|
||||
#include "config.h"
|
||||
#include "text.h"
|
||||
#include "function.h"
|
||||
#include "sprites.h"
|
||||
@ -167,9 +168,14 @@ private:
|
||||
Paint _paint;
|
||||
};
|
||||
|
||||
const Sprites &sprites(const QPointF &scale) const;
|
||||
|
||||
QVector<Layer> _layers;
|
||||
QStringList _sourceLayers;
|
||||
Sprites _sprites, _sprites2x;
|
||||
Sprites _sprites;
|
||||
#ifdef ENABLE_HIDPI
|
||||
Sprites _sprites2x;
|
||||
#endif // QT >= 5.6
|
||||
};
|
||||
|
||||
#endif // STYLE_H
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <QPainter>
|
||||
#include <QtMath>
|
||||
#include "config.h"
|
||||
#include "textpointitem.h"
|
||||
|
||||
|
||||
@ -66,8 +67,13 @@ QRectF TextPointItem::fuzzyBoundingRect() const
|
||||
|
||||
QRectF TextPointItem::computeTextRect(bool exact) const
|
||||
{
|
||||
#ifdef ENABLE_HIDPI
|
||||
QRectF iconRect = _icon.isNull() ? QRectF()
|
||||
: QRectF(QPointF(0, 0), QSizeF(_icon.size()) / _icon.devicePixelRatioF());
|
||||
#else // ENABLE_HIDPI
|
||||
QRectF iconRect = _icon.isNull() ? QRectF() : QRectF(QPointF(0, 0),
|
||||
QSizeF(_icon.size()));
|
||||
#endif // ENABLE_HIDPI
|
||||
QRectF textRect = exact ? exactBoundingRect() : fuzzyBoundingRect();
|
||||
|
||||
switch (_anchor) {
|
||||
@ -103,8 +109,12 @@ TextPointItem::TextPointItem(const QString &text, const QPointF &pos,
|
||||
_boundingRect = computeTextRect(false);
|
||||
|
||||
if (!_icon.isNull()) {
|
||||
#ifdef ENABLE_HIDPI
|
||||
QRectF iconRect(QPointF(0, 0), QSizeF(_icon.size())
|
||||
/ _icon.devicePixelRatioF());
|
||||
#else // ENABLE_HIDPI
|
||||
QRectF iconRect(QPointF(0, 0), QSizeF(_icon.size()));
|
||||
#endif // ENABLE_HIDPI
|
||||
iconRect.moveCenter(pos);
|
||||
_boundingRect |= iconRect;
|
||||
}
|
||||
@ -121,9 +131,14 @@ void TextPointItem::paint(QPainter *painter) const
|
||||
|
||||
if (!_icon.isNull()) {
|
||||
textRect = computeTextRect(true);
|
||||
#ifdef ENABLE_HIDPI
|
||||
painter->drawImage(_pos - QPointF(_icon.width()
|
||||
/ _icon.devicePixelRatioF() / 2, _icon.height()
|
||||
/ _icon.devicePixelRatioF() / 2), _icon);
|
||||
#else // ENABLE_HIDPI
|
||||
painter->drawImage(_pos - QPointF(_icon.width() / 2,
|
||||
_icon.height() / 2), _icon);
|
||||
#endif // ENABLE_HIDPI
|
||||
} else
|
||||
textRect = _boundingRect;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user