+#include "columnhandleitem.h"
+#include "messagemodel.h"
+#include "networkmodel.h"
+#include "qtui.h"
+#include "qtuisettings.h"
+#include "qtuistyle.h"
+
+ChatLine::ChatLine(int row, QAbstractItemModel *model,
+ const qreal &width,
+ const qreal ×tampWidth, const qreal &senderWidth, const qreal &contentsWidth,
+ const QPointF &senderPos, const QPointF &contentsPos,
+ QGraphicsItem *parent)
+ : QGraphicsItem(parent),
+ _row(row), // needs to be set before the items
+ _model(model),
+ _contentsItem(contentsWidth, contentsPos, this),
+ _senderItem(senderWidth, _contentsItem.height(), senderPos, this),
+ _timestampItem(timestampWidth, _contentsItem.height(), this),
+ _width(width),
+ _height(_contentsItem.height()),
+ _selection(0)
+{
+ Q_ASSERT(model);
+ QModelIndex index = model->index(row, ChatLineModel::ContentsColumn);
+ setZValue(0);
+ setHighlighted(model->data(index, MessageModel::FlagsRole).toInt() & Message::Highlight);
+}
+
+ChatItem &ChatLine::item(ChatLineModel::ColumnType column) {
+ switch(column) {
+ case ChatLineModel::TimestampColumn:
+ return _timestampItem;
+ case ChatLineModel::SenderColumn:
+ return _senderItem;
+ case ChatLineModel::ContentsColumn:
+ return _contentsItem;
+ default:
+ return *(ChatItem *)0; // provoke an error
+ }
+}
+
+// WARNING: setColumns should not be used without either:
+// a) calling prepareGeometryChange() immediately before setColumns()
+// b) calling Chatline::setPos() immediately afterwards
+//
+// NOTE: senderPos and contentsPos are in ChatLines coordinate system!
+qreal ChatLine::setColumns(const qreal ×tampWidth, const qreal &senderWidth, const qreal &contentsWidth,
+ const QPointF &senderPos, const QPointF &contentsPos) {
+ prepareGeometryChange();
+ qreal height = _contentsItem.setGeometryByWidth(contentsWidth);
+ _senderItem.setGeometry(senderWidth, height);
+ _timestampItem.setGeometry(timestampWidth, height);