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

View file

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