X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatitem.cpp;h=0900c7e2168caed9997bc98a4a492ff910be4fba;hp=3d2e065ebe33fd817833a3764896e1abac58b6fa;hb=9ce9c0ab3ac6f4bda4e3a70bf13a9c07d2debfe6;hpb=229b87f259ab1bc2c65f481eb39c25a872080fe7 diff --git a/src/qtui/chatitem.cpp b/src/qtui/chatitem.cpp index 3d2e065e..0900c7e2 100644 --- a/src/qtui/chatitem.cpp +++ b/src/qtui/chatitem.cpp @@ -136,7 +136,7 @@ void ChatItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, // painter->drawRect(_boundingRect.adjusted(0, 0, -1, -1)); } -qint16 ChatItem::posToCursor(const QPointF &pos) { +qint16 ChatItem::posToCursor(const QPointF &pos) const { if(pos.y() > height()) return data(MessageModel::DisplayRole).toString().length(); if(pos.y() < 0) return 0; for(int l = layout()->lineCount() - 1; l >= 0; l--) { @@ -148,6 +148,23 @@ qint16 ChatItem::posToCursor(const QPointF &pos) { return 0; } +bool ChatItem::hasSelection() const { + if(_selectionMode == NoSelection) + return false; + if(_selectionMode == FullSelection) + return true; + // partial + return _selectionStart != _selectionEnd; +} + +QString ChatItem::selection() const { + if(_selectionMode == FullSelection) + return data(MessageModel::DisplayRole).toString(); + if(_selectionMode == PartialSelection) + return data(MessageModel::DisplayRole).toString().mid(qMin(_selectionStart, _selectionEnd), qAbs(_selectionStart - _selectionEnd)); + return QString(); +} + void ChatItem::setFullSelection() { if(_selectionMode != FullSelection) { _selectionMode = FullSelection; @@ -166,6 +183,16 @@ void ChatItem::continueSelecting(const QPointF &pos) { update(); } +bool ChatItem::isPosOverSelection(const QPointF &pos) const { + if(_selectionMode == FullSelection) + return true; + if(_selectionMode == PartialSelection) { + int cursor = posToCursor(pos); qDebug() << cursor << _selectionStart << _selectionEnd; + return cursor >= qMin(_selectionStart, _selectionEnd) && cursor <= qMax(_selectionStart, _selectionEnd); + } + return false; +} + QTextLayout::FormatRange ChatItem::selectionFormat() const { QTextLayout::FormatRange selectFmt; if(_selectionMode != NoSelection) { @@ -215,15 +242,12 @@ QList ChatItem::findWords(const QString &searchWord, Qt::CaseSensitivity return resultList; } -void ChatItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if(event->buttons() == Qt::LeftButton) { +void ChatItem::handleClick(const QPointF &pos, ChatScene::ClickMode clickMode) { + if(clickMode == ChatScene::SingleClick) { chatScene()->setSelectingItem(this); - _selectionStart = _selectionEnd = posToCursor(event->pos()); + _selectionStart = _selectionEnd = posToCursor(pos); _selectionMode = NoSelection; // will be set to PartialSelection by mouseMoveEvent update(); - event->accept(); - } else { - event->ignore(); } } @@ -246,6 +270,14 @@ void ChatItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { } } +void ChatItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { + if(event->buttons() == Qt::LeftButton) { + event->accept(); + } else { + event->ignore(); + } +} + void ChatItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if(_selectionMode != NoSelection && !event->buttons() & Qt::LeftButton) { _selectionEnd = posToCursor(event->pos());