+#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
+ }
+}
+
+// NOTE: senderPos is in ChatLines coordinate system!
+void ChatLine::setFirstColumn(const qreal ×tampWidth, const qreal &senderWidth, const QPointF &senderPos) {
+ _timestampItem.prepareGeometryChange();
+ _timestampItem.setGeometry(timestampWidth, _height);
+ // senderItem doesn't need a geom change as it's Pos is changed (ensured by void ChatScene::firstHandlePositionChanged(qreal xpos))
+ _senderItem.setGeometry(senderWidth, _height);
+ _senderItem.setPos(senderPos);
+
+ _timestampItem.clearLayout();
+ _senderItem.clearLayout();
+}
+
+// NOTE: contentsPos is in ChatLines coordinate system!
+void ChatLine::setSecondColumn(const qreal &senderWidth, const qreal &contentsWidth,
+ const QPointF &contentsPos, qreal &linePos) {
+ // contentsItem doesn't need a geom change as it's Pos is changed (ensured by void ChatScene::firstHandlePositionChanged(qreal xpos))
+ qreal height = _contentsItem.setGeometryByWidth(contentsWidth);
+ linePos -= height;
+ bool needGeometryChange = linePos == pos().y() && height != _height;
+
+ if(needGeometryChange) {
+ _timestampItem.prepareGeometryChange();
+ _senderItem.prepareGeometryChange();
+ }
+ _timestampItem.setHeight(height);
+ _senderItem.setGeometry(senderWidth, height);
+
+ _contentsItem.setPos(contentsPos);