Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Fix horizontal scrolling with the second mouse wheel

Dmitry Kazakov4bdaa2f4ac08
diff --git a/libs/ui/input/kis_input_manager.cpp b/libs/ui/input/kis_input_manager.cpp
index af3b7d5be3..58acc21033 100644
--- a/libs/ui/input/kis_input_manager.cpp
+++ b/libs/ui/input/kis_input_manager.cpp
@@ -321,7 +321,7 @@ bool KisInputManager::eventFilterImpl(QEvent * event)
}
if (shouldResetWheelDelta(event)) {
- d->accumulatedScrollDelta = 0;
+ d->accumulatedScrollDelta = {};
}
if (event->type() == QEvent::MouseMove ||
@@ -511,8 +511,7 @@ bool KisInputManager::eventFilterImpl(QEvent * event)
break;
}
- d->accumulatedScrollDelta += wheelEvent->angleDelta().y();
- KisSingleActionShortcut::WheelAction action;
+ d->accumulatedScrollDelta += wheelEvent->angleDelta();
/**
* When wheelEvent->phase() is not Qt::NoScrollPhase, the delta
@@ -523,32 +522,44 @@ bool KisInputManager::eventFilterImpl(QEvent * event)
break;
}
- if (wheelEvent->angleDelta().x() < 0) {
- action = KisSingleActionShortcut::WheelRight;
- } else if (wheelEvent->angleDelta().x() >0) {
- action = KisSingleActionShortcut::WheelLeft;
- }
+ bool wasScrolled = false;
- if (wheelEvent->angleDelta().y() < 0) {
- action = KisSingleActionShortcut::WheelDown;
- } else if (wheelEvent->angleDelta().y() > 0) {
- action = KisSingleActionShortcut::WheelUp;
- }
+ {
+ KisSingleActionShortcut::WheelAction yAction;
- bool wasScrolled = false;
+ if (wheelEvent->angleDelta().y() < 0) {
+ yAction = KisSingleActionShortcut::WheelDown;
+ } else if (wheelEvent->angleDelta().y() > 0) {
+ yAction = KisSingleActionShortcut::WheelUp;
+ }
- while (qAbs(d->accumulatedScrollDelta) >= QWheelEvent::DefaultDeltasPerStep) {
- //Make sure the input actions know we are active.
- KisAbstractInputAction::setInputManager(this);
- retval = d->matcher.wheelEvent(action, wheelEvent);
- d->accumulatedScrollDelta -=
- KisAlgebra2D::signPZ(d->accumulatedScrollDelta) *
- QWheelEvent::DefaultDeltasPerStep;
- wasScrolled = true;
+ while (qAbs(d->accumulatedScrollDelta.y()) >= QWheelEvent::DefaultDeltasPerStep) {
+ // Make sure the input actions know we are active.
+ KisAbstractInputAction::setInputManager(this);
+ retval = d->matcher.wheelEvent(yAction, wheelEvent);
+ d->accumulatedScrollDelta.ry() -=
+ KisAlgebra2D::signPZ(d->accumulatedScrollDelta.y()) * QWheelEvent::DefaultDeltasPerStep;
+ wasScrolled = true;
+ }
}
- if (wasScrolled) {
- d->accumulatedScrollDelta = 0;
+ {
+ KisSingleActionShortcut::WheelAction xAction;
+
+ if (wheelEvent->angleDelta().x() < 0) {
+ xAction = KisSingleActionShortcut::WheelRight;
+ } else if (wheelEvent->angleDelta().x() > 0) {
+ xAction = KisSingleActionShortcut::WheelLeft;
+ }
+
+ while (qAbs(d->accumulatedScrollDelta.x()) >= QWheelEvent::DefaultDeltasPerStep) {
+ // Make sure the input actions know we are active.
+ KisAbstractInputAction::setInputManager(this);
+ retval = d->matcher.wheelEvent(xAction, wheelEvent);
+ d->accumulatedScrollDelta.rx() -=
+ KisAlgebra2D::signPZ(d->accumulatedScrollDelta.x()) * QWheelEvent::DefaultDeltasPerStep;
+ wasScrolled = true;
+ }
}
retval = !wasScrolled;
diff --git a/libs/ui/input/kis_input_manager_p.h b/libs/ui/input/kis_input_manager_p.h
index 73ee65406e..604cd1245f 100644
--- a/libs/ui/input/kis_input_manager_p.h
+++ b/libs/ui/input/kis_input_manager_p.h
@@ -101,7 +101,7 @@ public:
KisInputEventsEater eventEater;
- int accumulatedScrollDelta = 0;
+ QPoint accumulatedScrollDelta;
class TabletLatencyTracker : public KisLatencyTracker {
protected: