#include "chatitem.h"
ChatItem::ChatItem(const QPersistentModelIndex &index_, QGraphicsItem *parent) : QGraphicsItem(parent), _index(index_) {
- _width = _height = 0;
+
}
ChatItem::~ChatItem() {
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);
int ChatItem::setWidth(int w) {
- _width = w;
- _height = 20; // FIXME
- return _height;
+ _boundingRect.setWidth(w);
+ _boundingRect.setHeight(20); // FIXME
+ return 20;
}
/*
inline const MessageModel *model() const { return _index.isValid() ? qobject_cast<const MessageModel *>(_index.model()) : 0; }
inline int row() const { return _index.isValid() ? _index.row() : 0; }
- virtual QRectF boundingRect() const;
+ inline virtual QRectF boundingRect() const { return _boundingRect; }
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
virtual QVariant data(int role) const;
//void mouseMoveEvent ( QGraphicsSceneMouseEvent * event );
private:
- int _width;
- int _height;
+ QRectF _boundingRect;
//QTextLayout _layout;
//QTextOption _textOption;
QPersistentModelIndex _index;
for(int i = end+1; i < _lines.count(); i++) {
_lines.value(i)->moveBy(0, h);
}
- setSceneRect(QRectF(0, 0, _width, _height));
+ //setSceneRect(0, 0, _width, _height);
}
}
line->setPos(0, _height);
_height += line->setColumnWidths(_timestampWidth, _senderWidth, w - _timestampWidth - _senderWidth);
}
- setSceneRect(QRectF(0, 0, _width, _height));
+ qDebug() << "setting width";
+ setSceneRect(0, 0, _width, _height * 2);
}
void ChatScene::mousePressEvent ( QGraphicsSceneMouseEvent * mouseEvent ) {
ChatView::ChatView(Buffer *buf, QWidget *parent) : QGraphicsView(parent), AbstractChatView() {
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ setOptimizationFlags(QGraphicsView::DontClipPainter
+ |QGraphicsView::DontSavePainterState
+ |QGraphicsView::DontAdjustForAntialiasing);
_scene = new ChatScene(Client::messageModel(), this);
_scene->setWidth(width());
setScene(_scene);
void ChatView::resizeEvent(QResizeEvent *event) {
scene()->setWidth(event->size().width());
-
+ qDebug() << "resize";
}
void ChatView::clear()