mirror of
https://github.com/tumic0/QtPBFImagePlugin.git
synced 2024-11-24 03:35:54 +01:00
Some more text layout fiddeling
This commit is contained in:
parent
f5c15ece52
commit
044e95e061
28
src/text.cpp
28
src/text.cpp
@ -31,12 +31,26 @@ void Text::addLabel(const QString &text, const QImage &icon,
|
|||||||
{
|
{
|
||||||
TextItem *ti;
|
TextItem *ti;
|
||||||
|
|
||||||
|
if (_alignment == Viewport) {
|
||||||
|
QMap<qreal, int> map;
|
||||||
|
for (int j = 0; j < path.elementCount(); j++) {
|
||||||
|
QLineF l(path.elementAt(j), _sceneRect.center());
|
||||||
|
map.insert(l.length(), j);
|
||||||
|
}
|
||||||
|
QMap<qreal, int>::const_iterator jt = map.constBegin();
|
||||||
|
ti = new TextPointItem(text, path.elementAt(jt.value()), _font,
|
||||||
|
_maxWidth, _anchor, icon);
|
||||||
|
while (true) {
|
||||||
|
if (_sceneRect.contains(ti->boundingRect()))
|
||||||
|
break;
|
||||||
|
if (++jt == map.constEnd())
|
||||||
|
break;
|
||||||
|
static_cast<TextPointItem*>(ti)->setPos(path.elementAt(
|
||||||
|
jt.value()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
switch (_placement) {
|
switch (_placement) {
|
||||||
case Line:
|
case Line:
|
||||||
if (_alignment == Viewport)
|
|
||||||
ti = new TextPointItem(text, path.elementAt(0), _font,
|
|
||||||
_maxWidth, _anchor, icon);
|
|
||||||
else
|
|
||||||
ti = new TextPathItem(text, path, _font, _maxAngle, _sceneRect);
|
ti = new TextPathItem(text, path, _font, _maxAngle, _sceneRect);
|
||||||
break;
|
break;
|
||||||
case LineCenter:
|
case LineCenter:
|
||||||
@ -44,9 +58,9 @@ void Text::addLabel(const QString &text, const QImage &icon,
|
|||||||
_maxWidth, _anchor, icon);
|
_maxWidth, _anchor, icon);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ti = new TextPointItem(text, path.elementAt(0), _font, _maxWidth,
|
ti = new TextPointItem(text, path.elementAt(0), _font,
|
||||||
_anchor, icon);
|
_maxWidth, _anchor, icon);
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: empty path == point geometry (single move)
|
// Note: empty path == point geometry (single move)
|
||||||
|
@ -16,6 +16,8 @@ QRectF TextPointItem::exactBoundingRect() const
|
|||||||
// Italic fonts overflow the computed bounding rect, so expand it
|
// Italic fonts overflow the computed bounding rect, so expand it
|
||||||
if (font().italic())
|
if (font().italic())
|
||||||
br.adjust(-font().pixelSize() / 2.0, 0, font().pixelSize() / 2.0, 0);
|
br.adjust(-font().pixelSize() / 2.0, 0, font().pixelSize() / 2.0, 0);
|
||||||
|
if (hasHalo())
|
||||||
|
br.adjust(-1, -1, 1, 1);
|
||||||
|
|
||||||
return br;
|
return br;
|
||||||
}
|
}
|
||||||
@ -119,9 +121,18 @@ TextPointItem::TextPointItem(const QString &text, const QPointF &pos,
|
|||||||
_shape.addRect(_boundingRect);
|
_shape.addRect(_boundingRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextPointItem::setPos(const QPointF &pos)
|
||||||
|
{
|
||||||
|
QPointF d(_boundingRect.left() - _pos.x(), _boundingRect.top() - _pos.y());
|
||||||
|
_boundingRect.moveTopLeft(pos + d);
|
||||||
|
_shape = QPainterPath();
|
||||||
|
_shape.addRect(_boundingRect);
|
||||||
|
_pos = pos;
|
||||||
|
}
|
||||||
|
|
||||||
void TextPointItem::paint(QPainter *painter) const
|
void TextPointItem::paint(QPainter *painter) const
|
||||||
{
|
{
|
||||||
QRectF textRect;
|
QRectF textRect(_boundingRect);
|
||||||
|
|
||||||
if (!_icon.isNull()) {
|
if (!_icon.isNull()) {
|
||||||
textRect = computeTextRect(true);
|
textRect = computeTextRect(true);
|
||||||
@ -133,10 +144,9 @@ void TextPointItem::paint(QPainter *painter) const
|
|||||||
painter->drawImage(_pos - QPointF(_icon.width() / 2,
|
painter->drawImage(_pos - QPointF(_icon.width() / 2,
|
||||||
_icon.height() / 2), _icon);
|
_icon.height() / 2), _icon);
|
||||||
#endif // ENABLE_HIDPI
|
#endif // ENABLE_HIDPI
|
||||||
} else
|
}
|
||||||
textRect = _boundingRect;
|
|
||||||
|
|
||||||
if (halo().color().isValid() && halo().width() > 0) {
|
if (hasHalo()) {
|
||||||
QRect ir(textRect.toRect());
|
QRect ir(textRect.toRect());
|
||||||
QImage img(ir.size(), QImage::Format_ARGB32_Premultiplied);
|
QImage img(ir.size(), QImage::Format_ARGB32_Premultiplied);
|
||||||
img.fill(Qt::transparent);
|
img.fill(Qt::transparent);
|
||||||
|
@ -15,10 +15,14 @@ public:
|
|||||||
QPainterPath shape() const {return _shape;}
|
QPainterPath shape() const {return _shape;}
|
||||||
void paint(QPainter *painter) const;
|
void paint(QPainter *painter) const;
|
||||||
|
|
||||||
|
void setPos(const QPointF &pos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QRectF exactBoundingRect() const;
|
QRectF exactBoundingRect() const;
|
||||||
QRectF fuzzyBoundingRect() const;
|
QRectF fuzzyBoundingRect() const;
|
||||||
QRectF computeTextRect(bool exact) const;
|
QRectF computeTextRect(bool exact) const;
|
||||||
|
bool hasHalo() const
|
||||||
|
{return halo().color().isValid() && halo().width() > 0;}
|
||||||
|
|
||||||
QPointF _pos;
|
QPointF _pos;
|
||||||
QPainterPath _shape;
|
QPainterPath _shape;
|
||||||
|
Loading…
Reference in New Issue
Block a user