Triple-clicking now also checks for distance between clicks to prevent unwanted selection.

This commit is contained in:
Cranken 2018-10-06 14:56:15 +02:00 committed by pajlada
parent 423ef19c8f
commit 49398300d6
2 changed files with 13 additions and 3 deletions

View file

@ -899,6 +899,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
if (wordStart < this->selection_.start.charIndex && if (wordStart < this->selection_.start.charIndex &&
!this->dCSelection_.selectingRight) { !this->dCSelection_.selectingRight) {
this->dCSelection_.selectingLeft = true; this->dCSelection_.selectingLeft = true;
// Ensure that the original word stays selected(Edge case)
if (wordStart > this->dCSelection_.originalEnd) { if (wordStart > this->dCSelection_.originalEnd) {
this->setSelection(this->dCSelection_.origStartItem, this->setSelection(this->dCSelection_.origStartItem,
newEnd); newEnd);
@ -909,6 +910,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
} else if (wordEnd > this->selection_.end.charIndex && } else if (wordEnd > this->selection_.end.charIndex &&
!this->dCSelection_.selectingLeft) { !this->dCSelection_.selectingLeft) {
this->dCSelection_.selectingRight = true; this->dCSelection_.selectingRight = true;
// Ensure that the original word stays selected(Edge case)
if (wordEnd < this->dCSelection_.originalStart) { if (wordEnd < this->dCSelection_.originalStart) {
this->setSelection(newStart, this->setSelection(newStart,
this->dCSelection_.origEndItem); this->dCSelection_.origEndItem);
@ -1068,15 +1070,21 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
{ {
// check if mouse was pressed // check if mouse was pressed
if (event->button() == Qt::LeftButton) { if (event->button() == Qt::LeftButton) {
this->isDoubleClick_ = this->dCSelection_.selectingLeft = this->dCSelection_.selectingLeft = this->dCSelection_.selectingRight =
this->dCSelection_.selectingRight = false; false;
if (this->isMouseDown_) { if (this->isMouseDown_ || this->isDoubleClick_) {
this->isMouseDown_ = false; this->isMouseDown_ = false;
this->isDoubleClick_ = false;
if (fabsf(distanceBetweenPoints(this->lastPressPosition_, if (fabsf(distanceBetweenPoints(this->lastPressPosition_,
event->screenPos())) > 15.f) { event->screenPos())) > 15.f) {
return; return;
} }
// Was actually not a wanted triple-click
if (fabsf(distanceBetweenPoints(this->lastDClickPosition_,
event->screenPos())) > 10.f) {
return;
}
} else { } else {
return; return;
} }
@ -1286,6 +1294,7 @@ void ChannelView::mouseDoubleClickEvent(QMouseEvent *event)
const MessageLayoutElement *hoverLayoutElement = const MessageLayoutElement *hoverLayoutElement =
layout->getElementAt(relativePos); layout->getElementAt(relativePos);
this->lastDClickPosition_ = event->screenPos();
if (hoverLayoutElement == nullptr) { if (hoverLayoutElement == nullptr) {
// Possibility for triple click which doesn't have to be over an // Possibility for triple click which doesn't have to be over an

View file

@ -155,6 +155,7 @@ private:
DoubleClickSelection dCSelection_; DoubleClickSelection dCSelection_;
QPointF lastPressPosition_; QPointF lastPressPosition_;
QPointF lastRightPressPosition_; QPointF lastRightPressPosition_;
QPointF lastDClickPosition_;
QTimer *clickTimer_; QTimer *clickTimer_;
Selection selection_; Selection selection_;