-// compute the width of a text snippet
-qreal ChatLineModelItem::snippetWidth(int start, int end, QFontMetricsF *&metrics, int &formatListIdx, int &formatEnd) {
- qreal width = 0;
- while(start < end) {
- if(formatEnd <= start) {
- formatListIdx++;
- formatEnd = _contents.formatList.count() > formatListIdx+1 ? _contents.formatList[formatListIdx+1].first
- : _contents.plainText.length();
- metrics = QtUi::style()->fontMetrics(_contents.formatList[formatListIdx].second);
- Q_ASSERT(formatEnd > start);
- }
- int i = qMin(end, formatEnd);
- width += metrics->width(_contents.plainText.mid(start, i - start));
- start = i;
+bool ChatLineModelItemPrivate::needsStyling() {
+ return (bool)_msgBuffer;
+}
+
+QVariant ChatLineModelItemPrivate::data(MessageModel::ColumnType column, int role) {
+ if(needsStyling())
+ style();
+ switch(column) {
+ case ChatLineModel::TimestampColumn:
+ switch(role) {
+ case ChatLineModel::DisplayRole:
+ return _styledMsg->decoratedTimestamp();
+ case ChatLineModel::EditRole:
+ return _styledMsg->timestamp();
+ case ChatLineModel::FormatRole:
+ return QVariant::fromValue<UiStyle::FormatList>(UiStyle::FormatList()
+ << qMakePair((quint16)0, (quint32)_styledMsg->timestampFormat()));
+ }
+ break;
+ case ChatLineModel::SenderColumn:
+ switch(role) {
+ case ChatLineModel::DisplayRole:
+ return _styledMsg->decoratedSender();
+ case ChatLineModel::EditRole:
+ return _styledMsg->sender();
+ case ChatLineModel::FormatRole:
+ return QVariant::fromValue<UiStyle::FormatList>(UiStyle::FormatList()
+ << qMakePair((quint16)0, (quint32)_styledMsg->senderFormat()));
+ }
+ break;
+ case ChatLineModel::ContentsColumn:
+ switch(role) {
+ case ChatLineModel::DisplayRole:
+ case ChatLineModel::EditRole:
+ return _styledMsg->contents();
+ case ChatLineModel::FormatRole:
+ return QVariant::fromValue<UiStyle::FormatList>(_styledMsg->contentsFormatList());
+ case ChatLineModel::WrapListRole:
+ if(_wrapList.isEmpty())
+ computeWrapList();
+ return QVariant::fromValue<ChatLineModel::WrapList>(_wrapList);
+ }
+ break;
+ default:
+ Q_ASSERT(false);
+ return 0;