OpenToonz - An open-source full-featured 2D animation creation software
C
Fix touch controls for touchpad and stylus issue by artisteacher (modified) (#1963)
shun-iwasawaf602b3870b42
diff --git a/toonz/sources/toonz/sceneviewer.h b/toonz/sources/toonz/sceneviewer.hindex 5db5910a8..97a30665a 100644--- a/toonz/sources/toonz/sceneviewer.h+++ b/toonz/sources/toonz/sceneviewer.h@@ -23,6 +23,7 @@#include "previewer.h"#include <QMatrix4x4>+#include <QTouchDevice>//=====================================================================@@ -80,12 +81,13 @@ class SceneViewer final : public GLWidgetForHighDpi,} m_tabletState = None;// used to handle wrong mouse drag events!bool m_buttonClicked, m_toolSwitched;- bool m_shownOnce = false;- bool m_gestureActive = false;- bool m_touchActive = false;- bool m_rotating = false;- bool m_zooming = false;- bool m_panning = false;+ bool m_shownOnce = false;+ bool m_gestureActive = false;+ bool m_touchActive = false;+ QTouchDevice::DeviceType m_touchDevice = QTouchDevice::TouchScreen;+ bool m_rotating = false;+ bool m_zooming = false;+ bool m_panning = false;QPointF m_firstPanPoint;QPointF m_undoPoint;double m_scaleFactor; // used for zoom gesturediff --git a/toonz/sources/toonz/sceneviewerevents.cpp b/toonz/sources/toonz/sceneviewerevents.cppindex 06c61fef6..f997fac9d 100644--- a/toonz/sources/toonz/sceneviewerevents.cpp+++ b/toonz/sources/toonz/sceneviewerevents.cpp@@ -100,6 +100,9 @@ void initToonzEvent(TMouseEvent &toonzEvent, QTabletEvent *event,toonzEvent.m_buttons = event->buttons();toonzEvent.m_button = event->button();toonzEvent.m_isTablet = true;+ // this delays autosave during stylus button press until after the next+ // brush stroke - this minimizes problems from interruptions to tablet input+ TApp::instance()->getCurrentTool()->setToolBusy(true);}//-----------------------------------------------------------------------------@@ -404,7 +407,8 @@ void SceneViewer::onEnter() {void SceneViewer::mouseMoveEvent(QMouseEvent *event) {// if this is called just after tabletEvent, skip the executionif (m_tabletEvent) return;- if (m_gestureActive) {+ // and touchscreens but not touchpads...+ if (m_gestureActive && m_touchDevice == QTouchDevice::TouchScreen) {return;}// there are three cases to come here :@@ -572,7 +576,8 @@ void SceneViewer::mousePressEvent(QMouseEvent *event) {int source = event->source();// if this is called just after tabletEvent, skip the executionif (m_tabletEvent) return;- if (m_gestureActive) {+ // and touchscreens but not touchpads...+ if (m_gestureActive && m_touchDevice == QTouchDevice::TouchScreen) {return;}// For now OSX has a critical problem that mousePressEvent is called just@@ -687,7 +692,8 @@ void SceneViewer::mouseReleaseEvent(QMouseEvent *event) {m_tabletEvent = false;return;}- if (m_gestureActive) {+ // for touchscreens but not touchpads...+ if (m_gestureActive && m_touchDevice == QTouchDevice::TouchScreen) {m_gestureActive = false;m_rotating = false;m_zooming = false;@@ -854,7 +860,12 @@ void SceneViewer::wheelEvent(QWheelEvent *event) {} else if (delta > 0) {CommandManager::instance()->execute("MI_PrevDrawing");}- } else {+ }+ // Mouse wheel zoom interfered with touchpad panning (touch enabled)+ // Now if touch is enabled, touchpads ignore the mouse wheel zoom+ else if ((m_gestureActive == true &&+ m_touchDevice == QTouchDevice::TouchScreen) ||+ m_gestureActive == false) {zoomQt(event->pos() * getDevPixRatio(), exp(0.001 * delta));}}@@ -944,30 +955,40 @@ void SceneViewer::touchEvent(QTouchEvent *e, int type) {m_touchActive = true;m_firstPanPoint = e->touchPoints().at(0).pos();m_undoPoint = m_firstPanPoint;- }- if (e->touchPoints().count() == 1 && m_touchActive) {- QTouchEvent::TouchPoint panPoint = e->touchPoints().at(0);- if (!m_panning) {- QPointF deltaPoint = panPoint.pos() - m_firstPanPoint;- if (deltaPoint.manhattanLength() > 100) {- m_panning = true;+ // obtain device type+ m_touchDevice = e->device()->type();+ } else if (m_touchActive) {+ // touchpads must have 2 finger panning for tools and navigation to be+ // functional+ // on other devices, 1 finger panning is preferred+ if ((e->touchPoints().count() == 2 &&+ m_touchDevice == QTouchDevice::TouchPad) ||+ (e->touchPoints().count() == 1 &&+ m_touchDevice == QTouchDevice::TouchScreen)) {+ QTouchEvent::TouchPoint panPoint = e->touchPoints().at(0);+ if (!m_panning) {+ QPointF deltaPoint = panPoint.pos() - m_firstPanPoint;+ // minimize accidental and jerky zooming/rotating during 2 finger+ // panning+ if ((deltaPoint.manhattanLength() > 100) && !m_zooming && !m_rotating) {+ m_panning = true;+ }+ }+ if (m_panning) {+ QPointF centerDelta = (panPoint.pos() * getDevPixRatio()) -+ (panPoint.lastPos() * getDevPixRatio());+ panQt(centerDelta.toPoint());+ }+ } else if (e->touchPoints().count() == 3) {+ QPointF newPoint = e->touchPoints().at(0).pos();+ if (m_undoPoint.x() - newPoint.x() > 100) {+ CommandManager::instance()->execute("MI_Undo");+ m_undoPoint = newPoint;+ }+ if (m_undoPoint.x() - newPoint.x() < -100) {+ CommandManager::instance()->execute("MI_Redo");+ m_undoPoint = newPoint;}- }- if (m_panning) {- QPointF centerDelta = (panPoint.pos() * getDevPixRatio()) -- (panPoint.lastPos() * getDevPixRatio());- panQt(centerDelta.toPoint());- }- }- if (e->touchPoints().count() == 3 && m_touchActive) {- QPointF newPoint = e->touchPoints().at(0).pos();- if (m_undoPoint.x() - newPoint.x() > 100) {- CommandManager::instance()->execute("MI_Undo");- m_undoPoint = newPoint;- }- if (m_undoPoint.x() - newPoint.x() < -100) {- CommandManager::instance()->execute("MI_Redo");- m_undoPoint = newPoint;}}if (type == QEvent::TouchEnd || type == QEvent::TouchCancel) {