- return _contentsItem;
- default:
- return *(ChatItem *)0; // provoke an error
- }
-}
-
-qreal ChatLine::setGeometry(qreal width, qreal firstHandlePos, qreal secondHandlePos) {
- if(width != _width)
- prepareGeometryChange();
- qreal firstsep = QtUi::style()->firstColumnSeparator()/2;
- qreal secondsep = QtUi::style()->secondColumnSeparator()/2;
-
- _timestampItem.setWidth(firstHandlePos - firstsep);
- _senderItem.setWidth(secondHandlePos - firstHandlePos - (firstsep+secondsep));
- _height = _contentsItem.setWidth(width - secondHandlePos - secondsep);
-
- _senderItem.setPos(firstHandlePos + firstsep, 0);
- _contentsItem.setPos(secondHandlePos + secondsep, 0);
-
- _width = width;
- return _height;
-}
-
-void ChatLine::setSelected(bool selected, ChatLineModel::ColumnType minColumn) {
- if(selected) {
- quint8 sel = (_selection & 0x80) | 0x40 | minColumn;
- if(sel != _selection) {
- _selection = sel;
- for(int i = 0; i < minColumn; i++)
- item((ChatLineModel::ColumnType)i).clearSelection();
- for(int i = minColumn; i <= ChatLineModel::ContentsColumn; i++)
- item((ChatLineModel::ColumnType)i).setFullSelection();
- update();
+ 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();
+}
+
+
+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)
+ prepareGeometryChange();
+
+ _height = height;
+
+ setPos(0, linePos);
+}
+
+
+void ChatLine::setGeometryByWidth(const qreal &width, const qreal &contentsWidth, qreal &linePos)
+{
+ // linepos is the *bottom* position for the line
+ qreal height = _contentsItem.setGeometryByWidth(contentsWidth);
+ linePos -= height;
+ bool needGeometryChange = (height != _height || width != _width);
+
+ if (height != _height) {
+ _timestampItem.setHeight(height);
+ _senderItem.setHeight(height);
+ }
+
+ if (needGeometryChange) {
+ prepareGeometryChange();
+ _height = height;
+ _width = width;
+ }
+
+ setPos(0, linePos); // set pos is _very_ cheap if nothing changes.
+}
+
+
+void ChatLine::setSelected(bool selected, ChatLineModel::ColumnType minColumn)
+{
+ if (selected) {
+ quint8 sel = (_selection & Highlighted) | Selected | minColumn;
+ if (sel != _selection) {
+ _selection = sel;
+ for (int i = 0; i < minColumn; i++)
+ item((ChatLineModel::ColumnType)i)->clearSelection();
+ for (int i = minColumn; i <= ChatLineModel::ContentsColumn; i++)
+ item((ChatLineModel::ColumnType)i)->setFullSelection();
+ update();
+ }
+ }
+ else {
+ quint8 sel = _selection & Highlighted;
+ if (sel != _selection) {
+ _selection = sel;
+ for (int i = 0; i <= ChatLineModel::ContentsColumn; i++)
+ item((ChatLineModel::ColumnType)i)->clearSelection();
+ update();
+ }