+}
+
+QVector<QTextLayout::FormatRange> ChatItem::additionalFormats() const {
+ return selectionFormats();
+}
+
+QVector<QTextLayout::FormatRange> ChatItem::selectionFormats() const {
+ if(!hasSelection())
+ return QVector<QTextLayout::FormatRange>();
+
+ int start, end;
+ if(_selectionMode == FullSelection) {
+ start = 0;
+ end = data(MessageModel::DisplayRole).toString().length();
+ } else {
+ start = qMin(_selectionStart, _selectionEnd);
+ end = qMax(_selectionStart, _selectionEnd);
+ }
+
+ UiStyle::FormatList fmtList = formatList();
+
+ while(fmtList.count() > 1 && fmtList.at(1).first <= start)
+ fmtList.removeFirst();
+
+ fmtList.first().first = start;
+
+ while(fmtList.count() > 1 && fmtList.last().first >= end)
+ fmtList.removeLast();
+
+ return QtUi::style()->toTextLayoutList(fmtList, end, UiStyle::Selected|data(ChatLineModel::MsgLabelRole).toUInt()).toVector();
+}
+
+bool ChatItem::hasSelection() const {
+ if(_selectionMode == NoSelection)
+ return false;
+ if(_selectionMode == FullSelection)
+ return true;
+ // partial
+ return _selectionStart != _selectionEnd;
+}
+
+QString ChatItem::selection() const {
+ if(_selectionMode == FullSelection)
+ return data(MessageModel::DisplayRole).toString();
+ if(_selectionMode == PartialSelection)
+ return data(MessageModel::DisplayRole).toString().mid(qMin(_selectionStart, _selectionEnd), qAbs(_selectionStart - _selectionEnd));
+ return QString();
+}
+
+void ChatItem::setSelection(SelectionMode mode, qint16 start, qint16 end) {
+ _selectionMode = mode;
+ _selectionStart = start;
+ _selectionEnd = end;
+ chatLine()->update();