Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken knob interaction on touchscreens #3512

Merged
merged 1 commit into from
Jan 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/widget/knobeventhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ class KnobEventHandler {

double valueFromMouseEvent(T* pWidget, QMouseEvent* e) {
QPoint cur(e->globalPos());
QPoint diff(cur - m_startPos);
QPoint diff(cur - m_prevPos);
double dist = sqrt(static_cast<double>(diff.x() * diff.x() + diff.y() * diff.y()));
bool y_dominant = abs(diff.y()) > abs(diff.x());

// if y is dominant, then thread an increase in dy as negative (y is
// if y is dominant, then treat an increase in dy as negative (y is
// pointed downward). Otherwise, if y is not dominant and x has
// decreased, then thread it as negative.
// decreased, then treat it as negative.
if ((y_dominant && diff.y() > 0) || (!y_dominant && diff.x() < 0)) {
dist = -dist;
}
Expand All @@ -44,10 +44,10 @@ class KnobEventHandler {

void mouseMoveEvent(T* pWidget, QMouseEvent* e) {
if (!m_bRightButtonPressed) {
QCursor::setPos(m_startPos);
double value = valueFromMouseEvent(pWidget, e);
pWidget->setControlParameterDown(value);
pWidget->inputActivity();
m_prevPos = e->globalPos();
}
}

Expand All @@ -60,6 +60,7 @@ class KnobEventHandler {
case Qt::LeftButton:
case Qt::MiddleButton:
m_startPos = e->globalPos();
m_prevPos = m_startPos;
// Somehow using Qt::BlankCursor does not work on Windows
// https://mixxx.org/forums/viewtopic.php?p=40298#p40298
QApplication::setOverrideCursor(m_blankCursor);
Expand Down Expand Up @@ -107,5 +108,6 @@ class KnobEventHandler {

// Starting point when left mouse button is pressed
QPoint m_startPos;
QPoint m_prevPos;
QCursor m_blankCursor;
};