- }
-
- 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 };
-
- QList<ChatLineModel::Word> wplist; // use a temp list which we'll later copy into a QVector for efficiency
- QTextBoundaryFinder finder(QTextBoundaryFinder::Word, contents->plainText.unicode(), contents->plainText.length(), TextBoundaryFinderBuffer, TextBoundaryFinderBufferSize);
+ 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::Sender);
+ case ChatLineModel::SelectedBackgroundRole:
+ return backgroundBrush(UiStyle::Sender, true);
+ case ChatLineModel::FormatRole:
+ return QVariant::fromValue<UiStyle::FormatList>(UiStyle::FormatList()
+ << qMakePair((quint16)0, (quint32) UiStyle::formatType(_styledMsg.type()) | UiStyle::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::Contents);
+ case ChatLineModel::SelectedBackgroundRole:
+ return backgroundBrush(UiStyle::Contents, true);
+ case ChatLineModel::FormatRole:
+ return QVariant::fromValue<UiStyle::FormatList>(_styledMsg.contentsFormatList());
+ case ChatLineModel::WrapListRole:
+ if (_wrapList.isEmpty())
+ computeWrapList();
+ return QVariant::fromValue<ChatLineModel::WrapList>(_wrapList);
+ }
+ return QVariant();
+}
+
+
+quint32 ChatLineModelItem::messageLabel() const
+{
+ quint32 label = _styledMsg.senderHash() << 16;
+ if (_styledMsg.flags() & Message::Self)
+ label |= UiStyle::OwnMsg;
+ if (_styledMsg.flags() & Message::Highlight)
+ label |= UiStyle::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::Selected : 0));
+ if (fmt.hasProperty(QTextFormat::BackgroundBrush))
+ return QVariant::fromValue<QBrush>(fmt.background());
+ return QVariant();
+}
+
+
+void ChatLineModelItem::computeWrapList() const
+{
+ QString text = _styledMsg.plainContents();
+ int length = text.length();
+ if (!length)
+ return;
+
+ QList<ChatLineModel::Word> wplist; // use a temp list which we'll later copy into a QVector for efficiency
+ QTextBoundaryFinder finder(QTextBoundaryFinder::Line, _styledMsg.plainContents().unicode(), length,
+ TextBoundaryFinderBuffer, TextBoundaryFinderBufferSize);