ChatBubbleDelegate
Delegate that paints chat bubble chrome and provides persistent editors for complex content.
| Inherits | QStyledItemDelegate |
| Group | libwidgets |
Declared in src/libs/libwidgets/widgets/chat/ChatBubbleDelegate.hpp.
Detailed description
Handles two rendering paths:
- Painted — simple content (plain text, markdown, images) is drawn directly by
paint()using QTextDocument. - Persistent editor — complex content (code blocks, task plan cards, error action buttons) gets a composite QWidget returned by
createEditor().
Bubble chrome (background, border, role label, timestamp) is always painted by the delegate regardless of which content path is used.
Bounded caches
The delegate keeps two caches per row: the painted row (the text document, the image sources and the header geometry) and the measured size. Each one is a least-recently-used cache of a fixed number of rows, set with setDocumentCacheRows() and setSizeCacheRows(). Before the bound, a stream of one million events held one document per row after one full layout, an estimated 10 GB (trove-parts §TPN-10). Both caches use the key of ChatMessageModel::KeyRole, which stays with its message when older rows load at the top. A font zoom clears both, so no document laid out at the old size survives it. paintCount() counts the rows painted.
Collapsible cards
A message whose metadata carries ChatBubbleKeys::cardTitle() is a card (trove §UI-3.6). Under the header it shows a caret and the title. Collapsed, which is the default, it shows only that line, and it needs no document and no editor. A click on the line emits cardToggled(), and ChatStreamWidget writes ChatBubbleKeys::cardExpanded(). Expanded, the body follows the line, painted or in a composite editor, as for any other row. This generalizes the metadata-keyed expand state of the task plan card (taskPlanJsonExpanded) to every message.
See also ChatStreamWidget, ChatMessageModel, ChatRowLru.