+// 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;
+ }
+ return width;
+}
+