- if(!_isSelecting) return QString();
- int start = qMin(_selectionStart, _selectionEnd);
- int end = qMax(_selectionStart, _selectionEnd);
- if(start < 0 || end >= _lines.count()) {
- qDebug() << "Invalid selection range:" << start << end;
- return QString();
- }
- QString result;
- for(int l = start; l <= end; l++) {
- if(_selectionMinCol == ChatLineModel::TimestampColumn)
- result += _lines[l]->item(ChatLineModel::TimestampColumn).data(MessageModel::DisplayRole).toString() + " ";
- if(_selectionMinCol <= ChatLineModel::SenderColumn)
- result += _lines[l]->item(ChatLineModel::SenderColumn).data(MessageModel::DisplayRole).toString() + " ";
- result += _lines[l]->item(ChatLineModel::ContentsColumn).data(MessageModel::DisplayRole).toString() + "\n";
+ if(hasGlobalSelection()) {
+ int start = qMin(_selectionStart, _selectionEnd);
+ int end = qMax(_selectionStart, _selectionEnd);
+ if(start < 0 || end >= _lines.count()) {
+ qDebug() << "Invalid selection range:" << start << end;
+ return QString();
+ }
+ QString result;
+ for(int l = start; l <= end; l++) {
+ if(_selectionMinCol == ChatLineModel::TimestampColumn)
+ result += _lines[l]->item(ChatLineModel::TimestampColumn)->data(MessageModel::DisplayRole).toString() + " ";
+ if(_selectionMinCol <= ChatLineModel::SenderColumn)
+ result += _lines[l]->item(ChatLineModel::SenderColumn)->data(MessageModel::DisplayRole).toString() + " ";
+ result += _lines[l]->item(ChatLineModel::ContentsColumn)->data(MessageModel::DisplayRole).toString() + "\n";
+ }
+ return result;
+ } else if(selectingItem())
+ return selectingItem()->selection();
+ return QString();
+}
+
+bool ChatScene::hasSelection() const {
+ return hasGlobalSelection() || (selectingItem() && selectingItem()->hasSelection());
+}
+
+bool ChatScene::hasGlobalSelection() const {
+ return _selectionStart >= 0;
+}
+
+bool ChatScene::isGloballySelecting() const {
+ return _isSelecting;
+}
+
+void ChatScene::clearGlobalSelection() {
+ if(hasGlobalSelection()) {
+ for(int l = qMin(_selectionStart, _selectionEnd); l <= qMax(_selectionStart, _selectionEnd); l++)
+ _lines[l]->setSelected(false);
+ _isSelecting = false;
+ _selectionStart = -1;