return QString();
}
+void ChatItem::setSelection(SelectionMode mode, qint16 start, qint16 end) {
+ _selectionMode = mode;
+ _selectionStart = start;
+ _selectionEnd = end;
+ update();
+}
+
void ChatItem::setFullSelection() {
if(_selectionMode != FullSelection) {
_selectionMode = FullSelection;
}
void ChatItem::clearSelection() {
- _selectionMode = NoSelection;
- update();
+ if(_selectionMode != NoSelection) {
+ _selectionMode = NoSelection;
+ update();
+ }
}
void ChatItem::continueSelecting(const QPointF &pos) {
_selectionStart = _selectionEnd = posToCursor(pos);
_selectionMode = NoSelection; // will be set to PartialSelection by mouseMoveEvent
update();
- } else if(clickMode == ChatScene::DoubleClick) {
- //_selectionMode = PartialSelection;
-
- } else if(clickMode == ChatScene::TripleClick) {
-
}
}
}
void ChatItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
- if(event->buttons() == Qt::LeftButton) {
+ if(event->buttons() == Qt::LeftButton)
event->accept();
- } else {
+ else
event->ignore();
- }
}
void ChatItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
if(_selectionMode != NoSelection && !event->buttons() & Qt::LeftButton) {
- _selectionEnd = posToCursor(event->pos());
QString selection
= data(MessageModel::DisplayRole).toString().mid(qMin(_selectionStart, _selectionEnd), qAbs(_selectionStart - _selectionEnd));
chatScene()->putToClipboard(selection);
event->accept();
- } else {
+ } else
event->ignore();
- }
}
// ************************************************************
break;
}
}
+ } else if(clickMode == ChatScene::DoubleClick) {
+ chatScene()->setSelectingItem(this);
+ setSelectionMode(PartialSelection);
+ Clickable click = privateData()->currentClickable;
+ if(click.isValid()) {
+ setSelectionStart(click.start);
+ setSelectionEnd(click.start + click.length);
+ } else {
+ // find word boundary
+ QString str = data(ChatLineModel::DisplayRole).toString();
+ qint16 cursor = posToCursor(pos);
+ qint16 start = str.lastIndexOf(QRegExp("\\W"), cursor) + 1;
+ qint16 end = qMin(str.indexOf(QRegExp("\\W"), cursor), str.length());
+ if(end < 0) end = str.length();
+ setSelectionStart(start);
+ setSelectionEnd(end);
+ }
+ update();
+ } else if(clickMode == ChatScene::TripleClick) {
+ setSelection(PartialSelection, 0, data(ChatLineModel::DisplayRole).toString().length());
}
ChatItem::handleClick(pos, clickMode);
}
showWebPreview(click);
} else if(click.type == Clickable::Channel) {
// TODO: don't make clickable if it's our own name
- //onClickable = true; //FIXME disabled for now
+ // onClickable = true; //FIXME disabled for now
}
if(onClickable) {
setCursor(Qt::PointingHandCursor);