From 12fa4e53761a68904512089d5ac368480439be35 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Mon, 14 Sep 2009 19:57:21 +0200 Subject: [PATCH] Workaround the wordwrap issues with Qt This is a real fugly workaround for Qt bug 238249. As long as it makes Quassel wrap words correctly, I'm willing to live with it though. There's still some pathological cases where we still get it wrong (long URLs with real narrow columns, apparently), but meh. Closes #579, closes #704. --- src/qtui/chatitem.cpp | 19 ++++++++++++++++++- src/qtui/chatitem.h | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/qtui/chatitem.cpp b/src/qtui/chatitem.cpp index 8ff441c2..e255d002 100644 --- a/src/qtui/chatitem.cpp +++ b/src/qtui/chatitem.cpp @@ -438,6 +438,7 @@ qreal ContentsChatItem::setGeometryByWidth(qreal w) { } void ContentsChatItem::doLayout(QTextLayout *layout) const { + // QString t = data(Qt::DisplayRole).toString(); bool d = t.contains("protien"); ChatLineModel::WrapList wrapList = data(ChatLineModel::WrapListRole).value(); if(!wrapList.count()) return; // empty chatitem @@ -450,7 +451,23 @@ void ContentsChatItem::doLayout(QTextLayout *layout) const { 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; 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(); } diff --git a/src/qtui/chatitem.h b/src/qtui/chatitem.h index e94bda19..eb8a07ea 100644 --- a/src/qtui/chatitem.h +++ b/src/qtui/chatitem.h @@ -189,7 +189,7 @@ protected: virtual QVector additionalFormats() const; virtual inline void initLayout(QTextLayout *layout) const { - initLayoutHelper(layout, QTextOption::WrapAnywhere); + initLayoutHelper(layout, QTextOption::WrapAtWordBoundaryOrAnywhere); doLayout(layout); } virtual void doLayout(QTextLayout *layout) const; -- 2.20.1