mirror of
https://github.com/tumic0/QtPBFImagePlugin.git
synced 2025-07-05 23:32:52 +02:00
Improved text layout handling
This commit is contained in:
69
src/text.cpp
69
src/text.cpp
@ -1,4 +1,4 @@
|
||||
#include <QFontMetrics>
|
||||
#include <QFontMetrics>
|
||||
#include <QPainter>
|
||||
#include "text.h"
|
||||
#include "textpointitem.h"
|
||||
@ -20,15 +20,36 @@ void Text::render(QPainter *painter) const
|
||||
}
|
||||
}
|
||||
|
||||
void Text::addLabel(const QString &text, const QPointF &pos, bool overlap,
|
||||
const QImage &icon)
|
||||
void Text::addLabel(const QString &text, const QImage &icon,
|
||||
const QPainterPath &path)
|
||||
{
|
||||
TextPointItem *ti = new TextPointItem(text, pos, _font, _maxWidth, _anchor,
|
||||
icon);
|
||||
if (!overlap && !_sceneRect.contains(ti->boundingRect())) {
|
||||
delete ti;
|
||||
return;
|
||||
TextItem *ti;
|
||||
|
||||
switch (_placement) {
|
||||
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);
|
||||
if (!_sceneRect.contains(ti->boundingRect()))
|
||||
ti->setVisible(false);
|
||||
break;
|
||||
case LineCenter:
|
||||
ti = new TextPointItem(text, path.pointAtPercent(0.5), _font,
|
||||
_maxWidth, _anchor, icon);
|
||||
if (!_sceneRect.contains(ti->boundingRect()))
|
||||
ti->setVisible(false);
|
||||
break;
|
||||
default:
|
||||
ti = new TextPointItem(text, path.elementAt(0), _font, _maxWidth,
|
||||
_anchor, icon);
|
||||
if (_alignment == Viewport
|
||||
&& !_sceneRect.contains(ti->boundingRect()))
|
||||
ti->setVisible(false);
|
||||
break;
|
||||
}
|
||||
|
||||
ti->setPen(_pen);
|
||||
addItem(ti);
|
||||
|
||||
@ -37,23 +58,6 @@ void Text::addLabel(const QString &text, const QPointF &pos, bool overlap,
|
||||
ci[i]->setVisible(false);
|
||||
}
|
||||
|
||||
void Text::addLabel(const QString &text, const QPainterPath &path)
|
||||
{
|
||||
TextPathItem *ti = new TextPathItem(text, path, _font, _maxAngle,
|
||||
_sceneRect);
|
||||
if (!_sceneRect.contains(ti->boundingRect())) {
|
||||
delete ti;
|
||||
return;
|
||||
}
|
||||
ti->setPen(_pen);
|
||||
|
||||
addItem(ti);
|
||||
|
||||
QList<TextItem*> ci = collidingItems(ti);
|
||||
for (int i = 0; i < ci.size(); i++)
|
||||
ci[i]->setVisible(false);
|
||||
}
|
||||
|
||||
QList<TextItem*> Text::collidingItems(const TextItem *item) const
|
||||
{
|
||||
QList<TextItem*> list;
|
||||
@ -61,7 +65,7 @@ QList<TextItem*> Text::collidingItems(const TextItem *item) const
|
||||
if (!item->isVisible())
|
||||
return list;
|
||||
|
||||
for (int i = 0; i < _items.size();i ++) {
|
||||
for (int i = 0; i < _items.size(); i++) {
|
||||
const TextItem *ti = _items.at(i);
|
||||
if (ti != item && ti->isVisible() && ti->collidesWithItem(item))
|
||||
list.append(const_cast<TextItem*>(ti));
|
||||
@ -69,3 +73,16 @@ QList<TextItem*> Text::collidingItems(const TextItem *item) const
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
void Text::setSymbolPlacement(SymbolPlacement placement)
|
||||
{
|
||||
_placement = placement;
|
||||
|
||||
if (_placement != Text::Point) {
|
||||
for (int i = 0; i < _items.size(); i++) {
|
||||
TextItem *ti = _items[i];
|
||||
if (!_sceneRect.contains(ti->boundingRect()))
|
||||
ti->setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user