X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatitem.cpp;h=ed24bbaf72ce687f284fddf2a44c0d31229c56ff;hp=53bee456b85c72eab9950d17aea428ae6f7a89a4;hb=0125cf23d570d2b8ee4d3fd5407364cf6c5769df;hpb=f64ded9b73ed4eb09d3e2c14cddc0ead1e269185 diff --git a/src/qtui/chatitem.cpp b/src/qtui/chatitem.cpp index 53bee456..ed24bbaf 100644 --- a/src/qtui/chatitem.cpp +++ b/src/qtui/chatitem.cpp @@ -165,6 +165,13 @@ QString ChatItem::selection() const { 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; @@ -173,8 +180,10 @@ void ChatItem::setFullSelection() { } void ChatItem::clearSelection() { - _selectionMode = NoSelection; - update(); + if(_selectionMode != NoSelection) { + _selectionMode = NoSelection; + update(); + } } void ChatItem::continueSelecting(const QPointF &pos) { @@ -249,11 +258,6 @@ void ChatItem::handleClick(const QPointF &pos, ChatScene::ClickMode clickMode) { _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) { - } } @@ -277,23 +281,20 @@ void ChatItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { } 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(); - } } // ************************************************************ @@ -498,6 +499,26 @@ void ContentsChatItem::handleClick(const QPointF &pos, ChatScene::ClickMode clic 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); } @@ -524,7 +545,7 @@ void ContentsChatItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { 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);