ChatStreamWidget

Reusable Telegram-style chat widget with streaming support and interactive bubbles.

Inherits QWidget
Group libwidgets

Declared in src/libs/libwidgets/widgets/chat/ChatStreamWidget.hpp.

Detailed description

Wraps a QListView with a ChatMessageModel and ChatBubbleDelegate, adding a streaming bubble (outside the model for zero-churn token appending), a typing indicator, auto-scroll, viewport-aware persistent editor lifecycle, and a right-click context menu.

Layout is controlled by three Q_PROPERTYs: maxBubbleWidth, maxBubbleWidthPct, and leftAlignThreshold.

A stream at a million events

The widget stays a QListView over a ChatMessageModel with a ChatBubbleDelegate (trove-parts §TPN-10). openHistory() shows the newest window of a session. When the reader scrolls to the top, the widget calls ChatMessageModel::fetchMore() and keeps the row that was at the top in its place. The model uses ChatMessageModel::FetchTrigger::Owner, because a Qt view fetches when its last row shows. appendMessages() appends a batch with one insert. The view lays out in batches of kLayoutBatchRows rows (QListView::Batched), and a reader at the bottom stays at the bottom while the batches land. A click on the title line of a collapsible card writes ChatBubbleKeys::cardExpanded().

The conversation export

Every right click ends with the Conversation part of the menu: copy the conversation as text or Markdown, save it as text or PDF, open it in the system viewer, and show the folder of the saved files. The lightbox is for media: a picture opens there on a click, and the conversation stays in the stream (trove-navigation TNX-40). It is the one export of every chat: the Export menu of OpalChatOverlay calls exportConversation() too. The host sets the folder, the file name, the title, the text header, the assistant's label, the PDF runner and the opener, and shows transcriptNotice(). ChatTranscript gives the forms of the conversation and ChatPdf paints the PDF.

See also ChatMessageModel, ChatBubbleDelegate, ChatTranscript, OpalChatOverlay.

Property documentation

leftAlignThreshold property

leftAlignThreshold : float

This property holds the fraction of the view width below which every bubble aligns to the left.

When the bubble width limit is less than this fraction of the view width, the view is wide. Then the user's bubbles also align to the left, as the other bubbles do. Otherwise the user's bubbles align to the right. The default is 0.5.

Access functions:

  • float leftAlignThreshold() const
  • void setLeftAlignThreshold(float threshold)

maxBubbleWidth property

maxBubbleWidth : int

This property holds the largest width of a message bubble, in pixels.

A bubble is never wider than this value, and never wider than maxBubbleWidthPct of the view width. The smaller of the two limits applies. The default is 450.

Access functions:

  • int maxBubbleWidth() const
  • void setMaxBubbleWidth(int width)

maxBubbleWidthPct property

maxBubbleWidthPct : float

This property holds the largest width of a message bubble, as a fraction of the view width.

The value is a fraction, not a percentage: 0.9 is 90 percent. The smaller of this limit and maxBubbleWidth applies. The default is 0.9.

Access functions:

  • float maxBubbleWidthPct() const
  • void setMaxBubbleWidthPct(float pct)

Member function documentation

setAssistantLabel

void ChatStreamWidget::setAssistantLabel(const QString &label)

Name the assistant label in the text, Markdown and PDF exports of the conversation.

The default is "Assistant", and an empty label restores it. OPAL sets "OPAL". The other roles keep the names of ChatTranscript::Labels.

In this section