mirror of
https://github.com/tumic0/QtPBFImagePlugin.git
synced 2024-11-24 03:35:54 +01:00
Code cleanup
This commit is contained in:
parent
95da309a3c
commit
2637594c0a
@ -310,6 +310,7 @@ QFont Style::Layer::Layout::font(int zoom) const
|
|||||||
{
|
{
|
||||||
QFont font(_font);
|
QFont font(_font);
|
||||||
font.setPixelSize(_textSize.value(zoom));
|
font.setPixelSize(_textSize.value(zoom));
|
||||||
|
font.setCapitalization(textTransform(zoom));
|
||||||
|
|
||||||
return font;
|
return font;
|
||||||
}
|
}
|
||||||
@ -330,16 +331,16 @@ Text::Anchor Style::Layer::Layout::textAnchor(int zoom) const
|
|||||||
return Text::Center;
|
return Text::Center;
|
||||||
}
|
}
|
||||||
|
|
||||||
Text::Transform Style::Layer::Layout::textTransform(int zoom) const
|
QFont::Capitalization Style::Layer::Layout::textTransform(int zoom) const
|
||||||
{
|
{
|
||||||
QString transform(_textTransform.value(zoom));
|
QString transform(_textTransform.value(zoom));
|
||||||
|
|
||||||
if (transform == "uppercase")
|
if (transform == "uppercase")
|
||||||
return Text::Uppercase;
|
return QFont::AllUppercase;
|
||||||
else if (transform == "lowercase")
|
else if (transform == "lowercase")
|
||||||
return Text::Lowercase;
|
return QFont::AllLowercase;
|
||||||
else
|
else
|
||||||
return Text::None;
|
return QFont::MixedCase;
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::PenCapStyle Style::Layer::Layout::lineCap(int zoom) const
|
Qt::PenCapStyle Style::Layer::Layout::lineCap(int zoom) const
|
||||||
@ -445,7 +446,6 @@ void Style::Layer::setTextProperties(Tile &tile) const
|
|||||||
prop.maxWidth = _layout.maxTextWidth(tile.zoom());
|
prop.maxWidth = _layout.maxTextWidth(tile.zoom());
|
||||||
prop.maxAngle = _layout.maxTextAngle(tile.zoom());
|
prop.maxAngle = _layout.maxTextAngle(tile.zoom());
|
||||||
prop.anchor = _layout.textAnchor(tile.zoom());
|
prop.anchor = _layout.textAnchor(tile.zoom());
|
||||||
prop.transform = _layout.textTransform(tile.zoom());
|
|
||||||
|
|
||||||
tile.text().setProperties(prop);
|
tile.text().setProperties(prop);
|
||||||
}
|
}
|
||||||
|
@ -111,11 +111,11 @@ private:
|
|||||||
Qt::PenCapStyle lineCap(int zoom) const;
|
Qt::PenCapStyle lineCap(int zoom) const;
|
||||||
Qt::PenJoinStyle lineJoin(int zoom) const;
|
Qt::PenJoinStyle lineJoin(int zoom) const;
|
||||||
Text::Anchor textAnchor(int zoom) const;
|
Text::Anchor textAnchor(int zoom) const;
|
||||||
Text::Transform textTransform(int zoom) const;
|
|
||||||
|
|
||||||
bool viewportAlignment() const {return _viewportAlignment;}
|
bool viewportAlignment() const {return _viewportAlignment;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QFont::Capitalization textTransform(int zoom) const;
|
||||||
|
|
||||||
Template _text;
|
Template _text;
|
||||||
Template _icon;
|
Template _icon;
|
||||||
FunctionF _textSize;
|
FunctionF _textSize;
|
||||||
|
18
src/text.cpp
18
src/text.cpp
@ -178,19 +178,19 @@ void Text::addLabel(const QString &text, const QPainterPath &path,
|
|||||||
if (tp.isEmpty())
|
if (tp.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
TextPathItem *pi = new TextPathItem(text, reverse(tp) ? tp.toReversed()
|
TextPathItem *ti = new TextPathItem(text, reverse(tp) ? tp.toReversed()
|
||||||
: tp, painter.font(), _properties);
|
: tp, painter.font());
|
||||||
if (!_sceneRect.contains(pi->boundingRect())) {
|
if (!_sceneRect.contains(ti->boundingRect())) {
|
||||||
delete pi;
|
delete ti;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pi->setPen(painter.pen());
|
ti->setPen(painter.pen());
|
||||||
|
|
||||||
addItem(pi);
|
addItem(ti);
|
||||||
|
|
||||||
QList<TextItem*> ci = collidingItems(pi);
|
QList<TextItem*> ci = collidingItems(ti);
|
||||||
for (int j = 0; j < ci.size(); j++)
|
for (int i = 0; i < ci.size(); i++)
|
||||||
ci[j]->setVisible(false);
|
ci[i]->setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<TextItem*> Text::collidingItems(const TextItem *item) const
|
QList<TextItem*> Text::collidingItems(const TextItem *item) const
|
||||||
|
@ -16,17 +16,10 @@ public:
|
|||||||
Bottom
|
Bottom
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Transform {
|
|
||||||
None,
|
|
||||||
Uppercase,
|
|
||||||
Lowercase
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Properties {
|
struct Properties {
|
||||||
int maxWidth;
|
int maxWidth;
|
||||||
int maxAngle;
|
int maxAngle;
|
||||||
Anchor anchor;
|
Anchor anchor;
|
||||||
Transform transform;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,9 +4,7 @@
|
|||||||
|
|
||||||
|
|
||||||
TextPathItem::TextPathItem(const QString &text, const QPainterPath &path,
|
TextPathItem::TextPathItem(const QString &text, const QPainterPath &path,
|
||||||
const QFont &font, const Text::Properties &prop)
|
const QFont &font) : TextItem(text), _path(path), _font(font)
|
||||||
: TextItem(prop.transform == Text::Uppercase ? text.toUpper() : text),
|
|
||||||
_path(path), _font(font)
|
|
||||||
{
|
{
|
||||||
QPainterPathStroker s;
|
QPainterPathStroker s;
|
||||||
s.setWidth(font.pixelSize());
|
s.setWidth(font.pixelSize());
|
||||||
|
@ -10,7 +10,7 @@ class TextPathItem : public TextItem
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TextPathItem(const QString &text, const QPainterPath &path,
|
TextPathItem(const QString &text, const QPainterPath &path,
|
||||||
const QFont &font, const Text::Properties &prop);
|
const QFont &font);
|
||||||
|
|
||||||
QPainterPath shape() const {return _shape;}
|
QPainterPath shape() const {return _shape;}
|
||||||
QRectF boundingRect() const {return _boundingRect;}
|
QRectF boundingRect() const {return _boundingRect;}
|
||||||
|
@ -28,7 +28,7 @@ static QRectF fuzzyBoundingRect(const QString &str, const QFont &font,
|
|||||||
const Text::Properties &prop)
|
const Text::Properties &prop)
|
||||||
{
|
{
|
||||||
int limit = font.pixelSize() * prop.maxWidth;
|
int limit = font.pixelSize() * prop.maxWidth;
|
||||||
qreal acw = (prop.transform == Text::Uppercase) ? 0.66 : 0.55;
|
qreal acw = (font.capitalization() == QFont::AllUppercase) ? 0.66 : 0.55;
|
||||||
qreal cw = font.pixelSize() * acw;
|
qreal cw = font.pixelSize() * acw;
|
||||||
if (font.bold())
|
if (font.bold())
|
||||||
acw *= 1.1;
|
acw *= 1.1;
|
||||||
@ -101,8 +101,7 @@ QRectF TextPointItem::computeTextRect(BoundingRectFunction brf) const
|
|||||||
|
|
||||||
TextPointItem::TextPointItem(const QString &text, const QPointF &pos,
|
TextPointItem::TextPointItem(const QString &text, const QPointF &pos,
|
||||||
const QFont &font, const Text::Properties &prop, const QImage &icon)
|
const QFont &font, const Text::Properties &prop, const QImage &icon)
|
||||||
: TextItem(prop.transform == Text::Uppercase ? text.toUpper() : text),
|
: TextItem(text), _pos(pos), _font(font), _icon(icon), _properties(prop)
|
||||||
_pos(pos), _font(font), _icon(icon), _properties(prop)
|
|
||||||
{
|
{
|
||||||
_boundingRect = computeTextRect(fuzzyBoundingRect);
|
_boundingRect = computeTextRect(fuzzyBoundingRect);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user