+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();
+}
+
+void ChatLine::setMouseGrabberItem(ChatItem *item) {
+ _mouseGrabberItem = item;
+}
+
+bool ChatLine::sceneEvent(QEvent *event) {
+ if(event->type() == QEvent::GrabMouse) {
+ // get mouse cursor pos relative to us
+ ChatView *view = chatScene()->chatView();
+ QPointF linePos = mapFromScene(view->mapToScene(view->mapFromGlobal(QCursor::pos())));
+ setMouseGrabberItem(itemAt(linePos));
+ } else if(event->type() == QEvent::UngrabMouse) {
+ setMouseGrabberItem(0);
+ }
+ return QGraphicsItem::sceneEvent(event);
+}
+
+void ChatLine::setFirstColumn(const qreal ×tampWidth, const qreal &senderWidth, const QPointF &senderPos) {
+ _timestampItem.setGeometry(timestampWidth, _height);
+ _senderItem.setGeometry(senderWidth, _height);
+ _senderItem.setPos(senderPos);
+}
+
+void ChatLine::setSecondColumn(const qreal &senderWidth, const qreal &contentsWidth, const QPointF &contentsPos, qreal &linePos) {
+ // linepos is the *bottom* position for the line
+ qreal height = _contentsItem.setGeometryByWidth(contentsWidth);
+ linePos -= height;
+ bool needGeometryChange = (height != _height);
+
+ _timestampItem.setHeight(height);
+ _senderItem.setGeometry(senderWidth, height);
+ _contentsItem.setPos(contentsPos);
+
+ if(needGeometryChange)