-QVariant Chatline::data(int column, int role) const {
- switch(role) {
- case ChatlineModel::DisplayRole:
- switch(column) {
- case ChatlineModel::TimestampColumn: return _msg.timestamp.text;
- case ChatlineModel::SenderColumn: return _msg.sender.text;
- case ChatlineModel::TextColumn: return _msg.text.text;
- }
- break;
- case ChatlineModel::FormatRole:
- switch(column) {
- case ChatlineModel::TimestampColumn: return QVariant::fromValue<UiStyle::FormatList>(_msg.timestamp.formats);
- case ChatlineModel::SenderColumn: return QVariant::fromValue<UiStyle::FormatList>(_msg.sender.formats);
- case ChatlineModel::TextColumn: return QVariant::fromValue<UiStyle::FormatList>(_msg.text.formats);
- }
- break;
+// NOTE: contentsPos is in ChatLines coordinate system!
+void ChatLine::setSecondColumn(const qreal &senderWidth, const qreal &contentsWidth,
+ const QPointF &contentsPos, qreal &linePos) {
+ // contentsItem doesn't need a geom change as it's Pos is changed (ensured by void ChatScene::firstHandlePositionChanged(qreal xpos))
+ qreal height = _contentsItem.setGeometryByWidth(contentsWidth);
+ linePos -= height;
+ bool needGeometryChange = linePos == pos().y();
+
+ if(needGeometryChange) {
+ _timestampItem.prepareGeometryChange();
+ _senderItem.prepareGeometryChange();
+ }
+ _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) {
+ qreal height = _contentsItem.setGeometryByWidth(contentsWidth);
+ linePos -= height;
+ bool needGeometryChange = linePos == pos().y();
+
+ if(needGeometryChange) {
+ _timestampItem.prepareGeometryChange();
+ _senderItem.prepareGeometryChange();
+ }
+ _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();
+ }