}
int ChatItem::setWidth(int w) {
+ w -= 10;
if(w == _boundingRect.width()) return _boundingRect.height();
int h = heightForWidth(w);
_boundingRect.setWidth(w);
_boundingRect.setHeight(h);
+ if(haveLayout()) updateLayout();
return h;
}
}
void ChatItem::layout() {
- if(_layout) return;
+ if(haveLayout()) return;
_layout = new QTextLayout(data(MessageModel::DisplayRole).toString());
// Convert format information into a FormatRange
}
if(i > 0) formatRanges.last().length = _layout->text().length() - formatRanges.last().start;
_layout->setAdditionalFormats(formatRanges);
+ updateLayout();
+}
+
+void ChatItem::updateLayout() {
+ if(!haveLayout()) layout();
// Now layout
qreal h = 0;
Q_UNUSED(option); Q_UNUSED(widget);
layout();
_layout->draw(painter, QPointF(0,0), QVector<QTextLayout::FormatRange>(), boundingRect());
+ painter->drawRect(boundingRect());
}
/*