#include "chatline.h"
#include "qtui.h"
-ChatLine::ChatLine(const QPersistentModelIndex &index_, QGraphicsItem *parent) : QGraphicsItem(parent), _index(index_) {
+ChatLine::ChatLine(const QModelIndex &index, QGraphicsItem *parent) : QGraphicsItem(parent) {
+ _timestampItem = new ChatItem(QPersistentModelIndex(index.sibling(index.row(), ChatLineModel::TimestampColumn)), this);
+ _senderItem = new ChatItem(QPersistentModelIndex(index.sibling(index.row(), ChatLineModel::SenderColumn)), this);
+ _contentsItem = new ChatItem(QPersistentModelIndex(index.sibling(index.row(), ChatLineModel::ContentsColumn)), this);
+ _timestampItem->setPos(0,0);
+ _width = _height = 0;
}
ChatLine::~ChatLine() {
-
+ delete _timestampItem;
+ delete _senderItem;
+ delete _contentsItem;
}
QRectF ChatLine::boundingRect () const {
- return childrenBoundingRect();
+ //return childrenBoundingRect();
+ return QRectF(0, 0, _width, _height);
+}
+
+int ChatLine::setColumnWidths(int ts, int sender, int contents) {
+ _timestampItem->setWidth(ts);
+ _senderItem->setWidth(sender);
+ _height = _contentsItem->setWidth(contents);
+
+ _senderItem->setPos(ts, 0);
+ _contentsItem->setPos(ts + sender, 0);
+
+ _width = ts + sender + contents;
+ return _height;
}
void ChatLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {