}
QFontMetricsF *ContentsChatItem::fontMetrics() const {
- return QtUi::style()->fontMetrics(data(ChatLineModel::FormatRole).value<UiStyle::FormatList>().at(0).second);
+ return QtUi::style()->fontMetrics(data(ChatLineModel::FormatRole).value<UiStyle::FormatList>().at(0).second, 0);
}
ContentsChatItem::~ContentsChatItem() {
}
qreal ContentsChatItem::setGeometryByWidth(qreal w) {
- if(w != width()) {
+ // We use this for reloading layout info as well, so we can't bail out if the width doesn't change
+
+ // compute height
+ int lines = 1;
+ WrapColumnFinder finder(this);
+ while(finder.nextWrapColumn(w) > 0)
+ lines++;
+ qreal h = lines * fontMetrics()->lineSpacing();
+ delete _data;
+ _data = 0;
+
+ if(w != width() || h != height()) {
prepareGeometryChange();
- setWidth(w);
- // compute height
- int lines = 1;
- WrapColumnFinder finder(this);
- while(finder.nextWrapColumn() > 0)
- lines++;
- setHeight(lines * fontMetrics()->lineSpacing());
- delete _data;
- _data = 0;
+ setGeometry(w, h);
}
- return height();
+ return h;
}
void ContentsChatItem::doLayout(QTextLayout *layout) const {
if(!line.isValid())
break;
- int col = finder.nextWrapColumn();
+ int col = finder.nextWrapColumn(width());
line.setNumColumns(col >= 0 ? col - line.textStart() : layout->text().length());
line.setPosition(QPointF(0, h));
h += fontMetrics()->lineSpacing();
ContentsChatItem::WrapColumnFinder::~WrapColumnFinder() {
}
-qint16 ContentsChatItem::WrapColumnFinder::nextWrapColumn() {
+qint16 ContentsChatItem::WrapColumnFinder::nextWrapColumn(qreal width) {
if(wordidx >= wrapList.count())
return -1;
lineCount++;
- qreal targetWidth = lineCount * item->width() + choppedTrailing;
+ qreal targetWidth = lineCount * width + choppedTrailing;
qint16 start = wordidx;
qint16 end = wrapList.count() - 1;