+void ChatScene::updateSelection(const QPointF &pos) {
+ // This is somewhat hacky... we look at the contents item that is at the cursor's y position (ignoring x), since
+ // it has the full height. From this item, we can then determine the row index and hence the ChatLine.
+ ChatItem *contentItem = static_cast<ChatItem *>(itemAt(QPointF(secondColHandle->sceneRight() + 1, pos.y())));
+ if(!contentItem) return;
+
+ int curRow = contentItem->row();
+ int curColumn;
+ if(pos.x() > secondColHandle->sceneRight()) curColumn = ChatLineModel::ContentsColumn;
+ else if(pos.x() > firstColHandlePos) curColumn = ChatLineModel::SenderColumn;
+ else curColumn = ChatLineModel::TimestampColumn;
+
+ ChatLineModel::ColumnType minColumn = (ChatLineModel::ColumnType)qMin(curColumn, _selectionStartCol);
+ if(minColumn != _selectionMinCol) {
+ _selectionMinCol = minColumn;
+ for(int l = qMin(_selectionStart, _selectionEnd); l <= qMax(_selectionStart, _selectionEnd); l++) {
+ _lines[l]->setSelected(true, minColumn);
+ }
+ }
+ int newstart = qMin(curRow, _firstSelectionRow);
+ int newend = qMax(curRow, _firstSelectionRow);
+ if(newstart < _selectionStart) {
+ for(int l = newstart; l < _selectionStart; l++)
+ _lines[l]->setSelected(true, minColumn);
+ }
+ if(newstart > _selectionStart) {
+ for(int l = _selectionStart; l < newstart; l++)
+ _lines[l]->setSelected(false);
+ }
+ if(newend > _selectionEnd) {
+ for(int l = _selectionEnd+1; l <= newend; l++)
+ _lines[l]->setSelected(true, minColumn);
+ }
+ if(newend < _selectionEnd) {
+ for(int l = newend+1; l <= _selectionEnd; l++)
+ _lines[l]->setSelected(false);
+ }
+
+ _selectionStart = newstart;
+ _selectionEnd = newend;
+ _lastSelectionRow = curRow;