+#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(contentsPos, contentsWidth, this),
+ _senderItem(QRectF(senderPos, QSizeF(senderWidth, _contentsItem.height())), this),
+ _timestampItem(QRectF(0, 0, timestampWidth, _contentsItem.height()), this),
+ _width(width),
+ _height(_contentsItem.height()),
+ _selection(0),
+ _mouseGrabberItem(0),
+ _hoverItem(0)
+{
+ Q_ASSERT(model);
+ QModelIndex index = model->index(row, ChatLineModel::ContentsColumn);
+ setZValue(0);
+ setAcceptHoverEvents(true);
+ setHighlighted(index.data(MessageModel::FlagsRole).toInt() & Message::Highlight);
+}
+
+
+ChatLine::~ChatLine()
+{
+ if (chatView())
+ chatView()->setHasCache(this, false);
+}
+
+
+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 0;
+ }
+}
+
+
+ChatItem *ChatLine::itemAt(const QPointF &pos)
+{
+ if (_contentsItem.boundingRect().contains(pos))
+ return &_contentsItem;
+ if (_senderItem.boundingRect().contains(pos))
+ return &_senderItem;
+ if (_timestampItem.boundingRect().contains(pos))
+ return &_timestampItem;
+ return 0;
+}
+
+
+void ChatLine::clearCache()
+{
+ _timestampItem.clearCache();
+ _senderItem.clearCache();
+ _contentsItem.clearCache();
+}