WrapColumnFinder finder(this);
while(finder.nextWrapColumn(w) > 0)
lines++;
- qreal h = lines * fontMetrics()->lineSpacing();
+ qreal spacing = qMax(fontMetrics()->lineSpacing(), fontMetrics()->height()); // cope with negative leading()
+ qreal h = lines * spacing;
delete _data;
_data = 0;
}
void ContentsChatItem::doLayout(QTextLayout *layout) const {
+ // QString t = data(Qt::DisplayRole).toString(); bool d = t.contains("protien");
ChatLineModel::WrapList wrapList = data(ChatLineModel::WrapListRole).value<ChatLineModel::WrapList>();
if(!wrapList.count()) return; // empty chatitem
qreal h = 0;
+ qreal spacing = qMax(fontMetrics()->lineSpacing(), fontMetrics()->height()); // cope with negative leading()
WrapColumnFinder finder(this);
layout->beginLayout();
forever {
break;
int col = finder.nextWrapColumn(width());
- line.setNumColumns(col >= 0 ? col - line.textStart() : layout->text().length());
+ if(col < 0)
+ col = layout->text().length();
+ int num = col - line.textStart();
+
+ line.setNumColumns(num);
+
+ // Sometimes, setNumColumns will create a line that's too long (cf. Qt bug 238249)
+ // We verify this and try setting the width again, making it shorter each time until the lengths match.
+ // Dead fugly, but seems to work…
+ for(int i = line.textLength()-1; i >= 0 && line.textLength() > num; i--) {
+ line.setNumColumns(i);
+ }
+ if(num != line.textLength()) {
+ qWarning() << "WARNING: Layout engine couldn't workaround Qt bug 238249, please report!";
+ // qDebug() << num << line.textLength() << t.mid(line.textStart(), line.textLength()) << t.mid(line.textStart() + line.textLength());
+ }
+
line.setPosition(QPointF(0, h));
- h += fontMetrics()->lineSpacing();
+ h += spacing;
}
layout->endLayout();
}
QPointF topLeft = scenePos() + QPointF(x, y);
QRectF urlRect = QRectF(topLeft.x(), topLeft.y(), width, height);
- QString url = data(ChatLineModel::DisplayRole).toString().mid(click.start(), click.length());
- if(!url.contains("://"))
- url = "http://" + url;
+ QString urlstr = data(ChatLineModel::DisplayRole).toString().mid(click.start(), click.length());
+ if(!urlstr.contains("://"))
+ urlstr= "http://" + urlstr;
+ QUrl url = QUrl::fromEncoded(urlstr.toUtf8(), QUrl::TolerantMode);
chatScene()->loadWebPreview(this, url, urlRect);
#endif
}