- }
-
- inline const QString &plainText(MessageModel::ColumnType column) {
- if(needsStyling())
- style();
- return partByColumn(column)->plainText;
- }
-
- inline const UiStyle::FormatList &formatList(MessageModel::ColumnType column) {
- if(needsStyling())
- style();
- return partByColumn(column)->formatList;
- }
-
- inline const ChatLineModel::WrapList &wrapList() {
- if(needsStyling())
- style();
- if(_wrapList.isEmpty())
- computeWrapList();
- return _wrapList;
- }
-
-private:
- inline void style() {
- QtUiStyle::StyledMessage m = QtUi::style()->styleMessage(*_msgBuffer);
-
- timestamp = new ChatLinePart(m.timestamp.plainText, m.timestamp.formatList);
- sender = new ChatLinePart(m.sender.plainText, m.sender.formatList);
- contents = new ChatLinePart(m.contents.plainText, m.contents.formatList);
-
- delete _msgBuffer;
- _msgBuffer = 0;
- }
-
- inline void computeWrapList() {
- if(contents->plainText.isEmpty())
- return;
-
- enum Mode { SearchStart, SearchEnd };
+ return QVariant();
+}
+
+QVariant ChatLineModelItem::senderData(int role) const
+{
+ switch (role) {
+ case ChatLineModel::DisplayRole:
+ return _styledMsg.decoratedSender();
+ case ChatLineModel::EditRole:
+ return _styledMsg.plainSender();
+ case ChatLineModel::BackgroundRole:
+ return backgroundBrush(UiStyle::FormatType::Sender);
+ case ChatLineModel::SelectedBackgroundRole:
+ return backgroundBrush(UiStyle::FormatType::Sender, true);
+ case ChatLineModel::FormatRole:
+ return QVariant::fromValue(UiStyle::FormatList{
+ std::make_pair(quint16{0}, UiStyle::Format{UiStyle::formatType(_styledMsg.type()) | UiStyle::FormatType::Sender, {}, {}})});
+ }
+ return QVariant();
+}
+
+QVariant ChatLineModelItem::contentsData(int role) const
+{
+ switch (role) {
+ case ChatLineModel::DisplayRole:
+ case ChatLineModel::EditRole:
+ return _styledMsg.plainContents();
+ case ChatLineModel::BackgroundRole:
+ return backgroundBrush(UiStyle::FormatType::Contents);
+ case ChatLineModel::SelectedBackgroundRole:
+ return backgroundBrush(UiStyle::FormatType::Contents, true);
+ case ChatLineModel::FormatRole:
+ return QVariant::fromValue(_styledMsg.contentsFormatList());
+ case ChatLineModel::WrapListRole:
+ if (_wrapList.isEmpty())
+ computeWrapList();
+ return QVariant::fromValue(_wrapList);
+ }
+ return QVariant();
+}
+
+UiStyle::MessageLabel ChatLineModelItem::messageLabel() const
+{
+ using MessageLabel = UiStyle::MessageLabel;
+
+ auto label = static_cast<MessageLabel>(_styledMsg.senderHash() << 16);
+ if (_styledMsg.flags() & Message::Self)
+ label |= MessageLabel::OwnMsg;
+ if (_styledMsg.flags() & Message::Highlight)
+ label |= MessageLabel::Highlight;
+ return label;
+}
+
+QVariant ChatLineModelItem::backgroundBrush(UiStyle::FormatType subelement, bool selected) const
+{
+ QTextCharFormat fmt = QtUi::style()->format({UiStyle::formatType(_styledMsg.type()) | subelement, {}, {}},
+ messageLabel() | (selected ? UiStyle::MessageLabel::Selected : UiStyle::MessageLabel::None));
+ if (fmt.hasProperty(QTextFormat::BackgroundBrush))
+ return QVariant::fromValue(fmt.background());
+ return QVariant();
+}
+
+void ChatLineModelItem::computeWrapList() const
+{
+ QString text = _styledMsg.plainContents();
+ int length = text.length();
+ if (!length)
+ return;