Handle rowsInserted() and add new messages to the scene.
[quassel.git] / src / qtui / chatitem.cpp
index 2e3e22d..c518c5f 100644 (file)
 
 #include "chatitem.h"
 
-ChatItem::ChatItem(QGraphicsItem *parent) : QGraphicsItem(parent) {
-  _width = 0;
-  //if(_wrapMode == WordWrap) {
-  //  setFlags(QGraphicsItem::ItemClipsToShape, true);
-  //}
+ChatItem::ChatItem(const QPersistentModelIndex &index_, QGraphicsItem *parent) : QGraphicsItem(parent), _index(index_) {
+  _width = _height = 0;
 }
 
 ChatItem::~ChatItem() {
 
 }
 
-void ChatItem::setWidth(int w) {
+QVariant ChatItem::data(int role) const {
+  if(!_index.isValid()) {
+    qWarning() << "ChatItem::data(): Model index is invalid!" << _index;
+    return QVariant();
+  }
+  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);
+
+  painter->drawText(boundingRect(), data(MessageModel::DisplayRole).toString());
+  painter->setPen(Qt::DotLine);
+  painter->drawRect(boundingRect());
+}
+
+
+
+int ChatItem::setWidth(int w) {
   _width = w;
-  layout();
+  _height = 20; // FIXME
+  return _height;
 }
 
+/*
+
 void ChatItem::setTextOption(const QTextOption &option) {
   _textOption = option;
   layout();
@@ -58,7 +80,7 @@ QString ChatItem::text() const {
 
 void ChatItem::setText(const UiStyle::StyledText &text) {
   _layout.setText(text.text);
-  _layout.setAdditionalFormats(text.formats);
+  _layout.setAdditionalFormats(text.formatList);
   layout();
 }
 
@@ -91,7 +113,9 @@ void ChatItem::layout() {
   }
   _layout.endLayout();
   update();
-}
+}    QDateTime _timestamp;
+    MsgId _msgId;
+
 
 QRectF ChatItem::boundingRect() const {
   return _layout.boundingRect();
@@ -102,6 +126,7 @@ void ChatItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
   _layout.draw(painter, QPointF(0, 0));
 
 }
+*/
 
 /*
 void ChatItem::mouseMoveEvent ( QGraphicsSceneMouseEvent * event ) {