Commit 6cb3d497 authored by Robert Hairgrove's avatar Robert Hairgrove Committed by Ralf Habacker
Browse files

New feature allowing word wrapping in use case texts when resizing and entering line breaks

BUG: 424863
FIXED-IN:2.32.01 (KDE releases 20.08.1)
parent b0705c5c
......@@ -51,20 +51,33 @@ void UseCaseWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
font.setBold(false);
font.setItalic(m_umlObject->isAbstract());
painter->setFont(font);
const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
const int fontHeight = fm.lineSpacing();
const int w = width();
const int h = height();
//int middleX = w / 2;
const QFontMetricsF &fm = getFontMetrics(FT_NORMAL);
const qreal fontHeight = fm.lineSpacing();
const qreal w = width();
const qreal h = height();
bool drawStereotype = umlObject() && !umlObject()->stereotype().isEmpty();
const int textStartY = (h / 2) - (drawStereotype ? fontHeight / 4 : fontHeight / 2);
painter->drawEllipse(0, 0, w, h);
painter->drawEllipse(QRectF(0, 0, w, h));
painter->setPen(textColor());
QString txt;
if (drawStereotype)
painter->drawText(UC_MARGIN, textStartY-fontHeight, w - UC_MARGIN * 2, fontHeight, Qt::AlignCenter, umlObject()->stereotype(true));
{
// Prepend text of stereotype to other text:
txt = umlObject()->stereotype(true);
}
if (!txt.isEmpty())
txt.append(QLatin1String("\n"));
QString name_txt = name();
painter->drawText(UC_MARGIN, textStartY, w - UC_MARGIN * 2, fontHeight, Qt::AlignCenter, name());
// Replace user-entered "\n" with real line breaks:
name_txt.replace(QLatin1String("\\n"),QLatin1String("\n"));
txt += name_txt;
qreal dy = 0.0;
if (drawStereotype)
dy = fontHeight/2.0;
QRectF rectangle(UC_MARGIN, UC_MARGIN - dy, w - UC_MARGIN*2, h - UC_MARGIN*2);
painter->drawText(rectangle, Qt::AlignCenter | Qt::TextWordWrap, txt);
setPenFromSettings(painter);
UMLWidget::paint(painter, option, widget);
......@@ -90,9 +103,8 @@ QSizeF UseCaseWidget::minimumSize() const
const int fontHeight = fm.lineSpacing();
const int textWidth = fm.width(name());
bool drawStereotype = umlObject() && !umlObject()->stereotype().isEmpty();
int width = textWidth > UC_WIDTH?textWidth:UC_WIDTH;
int width = (textWidth / 3) > UC_WIDTH ? textWidth / 3 : UC_WIDTH;
int height = UC_HEIGHT + (drawStereotype ? 2 * fontHeight : fontHeight) + UC_MARGIN;
width += UC_MARGIN * 2;
return QSizeF(width, height);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment