[network/ruqola] src/widgets/room/delegate/messagelistlayout: Fix uneven author-line spacing under date headers in Normal style
Till Adam <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit bb12ddfa457bf29d9cee43ed8487182124499a58 by Till Adam.
Committed on 26/07/2026 at 21:58.
Pushed by tilladam into branch 'master'.
Fix uneven author-line spacing under date headers in Normal style
A message that starts a new date (so a "24 June" header is drawn above it)
sat with a looser gap between its author line and its text than a regular
new-sender message — and its avatar was offset from the name — because the
date-header case shifted only the sender baseline down (by fontMetrics.height()
minus an unexplained "- 4"), while the message text was shifted by the full
header height via usableRect, and the sender rect (hence the avatar) was left
unshifted.
Shift the whole author line — name baseline, sender rect, and therefore the
avatar — down by the header height, the same amount the text moves. A date row
is then exactly a regular new-sender row plus one header line, so its spacing
and avatar alignment match. The "- 4" fudge is gone.
M +9 -4 src/widgets/room/delegate/messagelistlayout/messagelistnormallayout.cpp
https://invent.kde.org/network/ruqola/-/commit/bb12ddfa457bf29d9cee43ed8487182124499a58
diff --git a/src/widgets/room/delegate/messagelistlayout/messagelistnormallayout.cpp b/src/widgets/room/delegate/messagelistlayout/messagelistnormallayout.cpp
index ac2e33cf26..6da8486a76 100644
--- a/src/widgets/room/delegate/messagelistlayout/messagelistnormallayout.cpp
+++ b/src/widgets/room/delegate/messagelistlayout/messagelistnormallayout.cpp
@@ -141,10 +141,15 @@ MessageListLayoutBase::Layout MessageListNormalLayout::doLayout(const QStyleOpti
layout.senderRect =
QRectF(senderX, layout.baseLine - senderAscent, senderTextSize.width(), (layout.sameSenderAsPreviousMessage ? 0 : senderTextSize.height()));
if (index.data(MessagesModel::DateDiffersFromPrevious).toBool()) {
- layout.baseLine += option.fontMetrics.height() - 4; // TODO fix -4 !
- const auto height = layout.senderRect.height();
- layout.senderRect.setTop(layout.senderRect.top() + senderAscent);
- layout.senderRect.setHeight(height);
+ // A date header occupies the row's top line (drawn by drawDate), and usableRect
+ // already pushed the message text down by that line's height. Shift the whole
+ // author line — the name baseline, its rect, and therefore the avatar — down by
+ // the same height, so a date row is exactly a regular new-sender row plus one
+ // header line. (Replaces an "- 4" fudge that moved only the baseline, leaving the
+ // author line looser above its text than a normal new-sender row.)
+ const int headerHeight = option.fontMetrics.height();
+ layout.baseLine += headerHeight;
+ layout.senderRect.moveTop(layout.senderRect.top() + headerHeight);
}
// Align top of avatar with top of sender rect
const double senderRectY{layout.senderRect.y()};