Skip to content

Commit 450406d

Browse files
authored
Fix outline shownames not centering properly (AttorneyOnline#1136)
* Fix outline shownames not centering properly Resolve AttorneyOnline#1064 Also should prevent the right-aligned name's edge from creeping past. * Reworked the outline alignment code to be more precise
1 parent ccd93a3 commit 450406d

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

src/aotextboxwidgets.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,10 @@ void AOChatboxLabel::paintEvent(QPaintEvent *event)
6666
{
6767
double w = outlineThickness();
6868
QRectF rect = this->rect();
69-
QFontMetrics metrics = QFontMetrics(this->font());
70-
QRect tr = metrics.boundingRect(text()).adjusted(0, 0, w, w);
69+
QFontMetrics metrics(this->font());
7170
int l_indent;
72-
int x;
73-
int y;
71+
qreal x;
72+
qreal y;
7473

7574
if (indent() == -1)
7675
{
@@ -88,41 +87,46 @@ void AOChatboxLabel::paintEvent(QPaintEvent *event)
8887
l_indent = indent();
8988
}
9089

90+
QPainterPath path;
91+
path.addText(0, 0, font(), text());
92+
QRectF tr = path.boundingRect().adjusted(-w, -w, w, w);
93+
9194
if (alignment() & Qt::AlignLeft)
9295
{
93-
x = rect.left() + l_indent - std::min(metrics.leftBearing(text().at(0)), 0);
96+
x = rect.left() + l_indent - tr.left();
9497
}
9598
else if (alignment() & Qt::AlignRight)
9699
{
97-
x = rect.x() + rect.width() - l_indent - tr.width();
100+
x = rect.right() - l_indent - tr.right();
98101
}
99102
else
100103
{
101-
x = (rect.width() - tr.width()) / 2;
104+
x = rect.left() + (rect.width() - tr.width()) / 2.0 - tr.left();
102105
}
103106

104107
if (alignment() & Qt::AlignTop)
105108
{
106-
y = rect.top() + l_indent + metrics.ascent();
109+
y = rect.top() + l_indent - tr.top();
107110
}
108111
else if (alignment() & Qt::AlignBottom)
109112
{
110-
y = rect.y() + rect.height() - l_indent - metrics.descent();
113+
y = rect.bottom() - l_indent - tr.bottom();
111114
}
112115
else
113116
{
114-
y = (rect.height() + metrics.ascent() - metrics.descent()) / 2;
117+
y = rect.top() + (rect.height() - tr.height()) / 2.0 - tr.top();
115118
}
116119

117120
m_pen.setWidth(w * 2);
118-
QPainterPath path;
119-
path.addText(x, y, font(), text());
120121

121122
QPainter painter(this);
122123
painter.setRenderHint(QPainter::Antialiasing);
124+
painter.translate(x, y);
123125
painter.strokePath(path, m_pen);
124126
if (1 < m_brush.style() && m_brush.style() < 15)
127+
{
125128
painter.fillPath(path, palette().window());
129+
}
126130
painter.fillPath(path, m_brush);
127131
}
128132
else

0 commit comments

Comments
 (0)