X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatitem.cpp;h=6bf77a45ba53c0b0b7110e8f26fb2ea4cd836a3b;hp=c518c5fef35c7716d6f02caaa515aaad1075decd;hb=2a7928256ace73ac40b89b8c327cf08815da882d;hpb=da2b5b2e4e2b0ea1847a0a5f0cb4a3752fc655c9 diff --git a/src/qtui/chatitem.cpp b/src/qtui/chatitem.cpp index c518c5fe..6bf77a45 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_) { - _width = _height = 0; + QFontMetricsF *metrics = QtUi::style()->fontMetrics(data(ChatLineModel::FormatRole).value().at(0).second); + _lineHeight = metrics->lineSpacing(); } ChatItem::~ChatItem() { @@ -43,9 +46,11 @@ QVariant ChatItem::data(int role) const { return _index.data(role); } +/* QRectF ChatItem::boundingRect() const { return QRectF(0, 0, _width, _height); } +*/ void ChatItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option); Q_UNUSED(widget); @@ -55,12 +60,33 @@ void ChatItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, painter->drawRect(boundingRect()); } - - int ChatItem::setWidth(int w) { - _width = w; - _height = 20; // FIXME - return _height; + if(w == _boundingRect.width()) return _boundingRect.height(); + int h = heightForWidth(w); + _boundingRect.setWidth(w); + _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; } /*