X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatitem.cpp;h=17189f949bd75bdc32d3654edbf2056357dd935d;hp=c12d5c5b92b5fe1712b1c52c42415fbad3d5be8f;hb=042ef1118ea58763c20653b90cf5d732b5b12767;hpb=84ff541e038763977a99642a90af11ee995c440d diff --git a/src/qtui/chatitem.cpp b/src/qtui/chatitem.cpp index c12d5c5b..17189f94 100644 --- a/src/qtui/chatitem.cpp +++ b/src/qtui/chatitem.cpp @@ -47,10 +47,12 @@ QVariant ChatItem::data(int role) const { } 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; } @@ -58,25 +60,27 @@ int ChatItem::heightForWidth(int width) { if(data(ChatLineModel::ColumnTypeRole).toUInt() != ChatLineModel::ContentsColumn) return _lineHeight; // only contents can be multi-line - QVariantList wrapList = data(ChatLineModel::WrapListRole).toList(); + ChatLineModel::WrapList wrapList = data(ChatLineModel::WrapListRole).value(); int lines = 1; - int offset = 0; - for(int i = 0; i < wrapList.count(); i+=2) { - if(wrapList.at(i+1).toUInt() - offset < width) continue; + qreal w = 0; + for(int i = 0; i < wrapList.count(); i++) { + w += wrapList.at(i).width; + if(w <= width) { + w += wrapList.at(i).trailing; + continue; + } lines++; - if(i > 0) { - if(offset < wrapList.at(i-1).toUInt()) offset = wrapList.at(i-1).toUInt(); - else offset += width; - } else { - offset += width; + w = wrapList.at(i).width; + while(w >= width) { + lines++; + w -= width; } - i-=2; } return lines * _lineHeight; } void ChatItem::layout() { - if(_layout) return; + if(haveLayout()) return; _layout = new QTextLayout(data(MessageModel::DisplayRole).toString()); // Convert format information into a FormatRange @@ -92,6 +96,11 @@ void ChatItem::layout() { } 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; @@ -118,6 +127,13 @@ void ChatItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q_UNUSED(option); Q_UNUSED(widget); layout(); _layout->draw(painter, QPointF(0,0), QVector(), boundingRect()); + painter->drawRect(boundingRect()); + int width = 0; + QVariantList wrapList = data(ChatLineModel::WrapListRole).toList(); + for(int i = 2; i < wrapList.count(); i+=2) { + QRect r(wrapList[i-1].toUInt(), 0, wrapList[i+1].toUInt() - wrapList[i-1].toUInt(), _lineHeight); + painter->drawRect(r); + } } /*