X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatitem.cpp;h=568cdccf233c14bd0b86d125dfc67b790498bd6f;hp=63d92e689397bf1c440a8753c1dbd1d7f98c4f29;hb=3a9668461efb05bd5b24ba5eb741a7f7f75086c9;hpb=bedd08ea58926e41e6ad1d0bf256a97cae97fb3c diff --git a/src/qtui/chatitem.cpp b/src/qtui/chatitem.cpp index 63d92e68..568cdccf 100644 --- a/src/qtui/chatitem.cpp +++ b/src/qtui/chatitem.cpp @@ -26,9 +26,12 @@ #include #include "chatitem.h" +#include "chatlinemodel.h" +#include "qtui.h" ChatItem::ChatItem(const QPersistentModelIndex &index_, QGraphicsItem *parent) : QGraphicsItem(parent), _index(index_) { - + QFontMetricsF *metrics = QtUi::style()->fontMetrics(data(ChatLineModel::FormatRole).value().at(0).second); + _lineHeight = metrics->lineSpacing(); } ChatItem::~ChatItem() { @@ -57,12 +60,33 @@ void ChatItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, painter->drawRect(boundingRect()); } - - int ChatItem::setWidth(int w) { + if(w == _boundingRect.width()) return _boundingRect.height(); + int h = heightForWidth(w); _boundingRect.setWidth(w); - _boundingRect.setHeight(20); // FIXME - return 20; + _boundingRect.setHeight(h); + return h; +} + +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(); + int lines = 1; + int offset = 0; + for(int i = 0; i < wrapList.count(); i+=2) { + if(wrapList.at(i+1).toUInt() - offset < width) continue; + lines++; + if(i > 0) { + if(offset != wrapList.at(i-1).toUInt()) offset = wrapList.at(i-1).toUInt(); + else offset += width; + } else { + offset += width; + } + i-=2; + } + return lines * _lineHeight; } /*