diff --git a/toonz/sources/toonz/sceneviewer.cpp b/toonz/sources/toonz/sceneviewer.cpp index 9016ac6..cb0a19c 100644 --- a/toonz/sources/toonz/sceneviewer.cpp +++ b/toonz/sources/toonz/sceneviewer.cpp @@ -472,6 +472,10 @@ SceneViewer::SceneViewer(ImageUtils::FullScreenWidget *parent) , m_mouseButton(Qt::NoButton) , m_foregroundDrawing(false) , m_tabletEvent(false) + , m_tabletActive(false) + , m_tabletMove(false) + , m_tabletPressed(false) + , m_tabletReleased(false) , m_buttonClicked(false) , m_referenceMode(NORMAL_REFERENCE) , m_previewMode(NO_PREVIEW) diff --git a/toonz/sources/toonz/sceneviewer.h b/toonz/sources/toonz/sceneviewer.h index 8e2c3b3..e87e1bb 100644 --- a/toonz/sources/toonz/sceneviewer.h +++ b/toonz/sources/toonz/sceneviewer.h @@ -66,7 +66,7 @@ class SceneViewer final : public GLWidgetForHighDpi, Qt::MouseButton m_mouseButton; bool m_foregroundDrawing; - bool m_tabletEvent; + bool m_tabletEvent, m_tabletPressed, m_tabletReleased, m_tabletMove, m_tabletActive; // used to handle wrong mouse drag events! bool m_buttonClicked, m_toolSwitched; bool m_shownOnce = false; diff --git a/toonz/sources/toonz/sceneviewerevents.cpp b/toonz/sources/toonz/sceneviewerevents.cpp index 0498cd7..de274bf 100644 --- a/toonz/sources/toonz/sceneviewerevents.cpp +++ b/toonz/sources/toonz/sceneviewerevents.cpp @@ -203,7 +203,13 @@ void SceneViewer::tabletEvent(QTabletEvent *e) { m_tabletEvent = true; m_pressure = e->pressure(); - + m_tabletPressed = false; + m_tabletReleased = false; + m_tabletMove = false; + int type = e->type(); + if (type == 92) m_tabletPressed = true; + if (type == 93) m_tabletReleased = true; + if (type == 87) m_tabletMove = true; // Management of the Eraser pointer ToolHandle *toolHandle = TApp::instance()->getCurrentTool(); if (e->pointerType() == QTabletEvent::Eraser) { @@ -376,7 +382,15 @@ void SceneViewer::mouseMoveEvent(QMouseEvent *event) { // qDebug() << "mouseMoveEvent. " << (m_tabletEvent?"tablet":"mouse") // << " pressure=" << m_pressure << " mouseButton=" << m_mouseButton // << " buttonClicked=" << m_buttonClicked; - if ((m_tabletEvent && m_pressure > 0) || m_mouseButton == Qt::LeftButton) { + + //separate tablet events from mouse events + //don't perform a drag event if tablet not active + if (m_tabletActive && !m_tabletMove) return; + if (m_tabletEvent && m_tabletActive && m_tabletMove) { + tool->leftButtonDrag(pos, toonzEvent); + } + + else if (m_mouseButton == Qt::LeftButton) { // sometimes the mousePressedEvent is postponed to a wrong mouse move // event! if (m_buttonClicked && !m_toolSwitched) @@ -387,6 +401,7 @@ void SceneViewer::mouseMoveEvent(QMouseEvent *event) { } if (!cursorSet) setToolCursor(this, tool->getCursorId()); m_pos = curPos; + m_tabletMove = false; } else if (m_mouseButton == Qt::MidButton) { if ((event->buttons() & Qt::MidButton) == 0) m_mouseButton = Qt::NoButton; @@ -474,9 +489,6 @@ void SceneViewer::mousePressEvent(QMouseEvent *event) { } TMouseEvent toonzEvent; - if (m_pressure > 0 && !m_tabletEvent) m_tabletEvent = true; - - if (TApp::instance()->isPenCloseToTablet()) m_tabletEvent = true; initToonzEvent(toonzEvent, event, height(), m_pressure, m_tabletEvent, true, getDevPixRatio()); // if(!m_tabletEvent) qDebug() << "-----------------MOUSE PRESS 'PURO'. @@ -488,11 +500,17 @@ void SceneViewer::mousePressEvent(QMouseEvent *event) { pos.x /= m_dpiScale.x; pos.y /= m_dpiScale.y; } - if (m_mouseButton == Qt::LeftButton) { + // separate tablet and mouse events + if (m_tabletEvent && m_tabletPressed) { + m_tabletActive = true; + tool->leftButtonDown(pos, toonzEvent); + } + else if (m_mouseButton == Qt::LeftButton) { TApp::instance()->getCurrentTool()->setToolBusy(true); tool->leftButtonDown(pos, toonzEvent); } if (m_mouseButton == Qt::RightButton) tool->rightButtonDown(pos, toonzEvent); + m_tabletPressed = false; } //----------------------------------------------------------------------------- @@ -513,6 +531,8 @@ void SceneViewer::mouseReleaseEvent(QMouseEvent *event) { if (m_mouseButton != event->button()) return; + //reject if tablet was active and the up button is not actually the pen. + if (m_tabletActive && !m_tabletReleased) return; if (m_current3DDevice != NONE) { m_mouseButton = Qt::NoButton; m_tabletEvent = false; @@ -554,7 +574,7 @@ void SceneViewer::mouseReleaseEvent(QMouseEvent *event) { pos.y /= m_dpiScale.y; } - if (m_mouseButton == Qt::LeftButton) { + if (m_mouseButton == Qt::LeftButton || m_tabletReleased) { if (!m_toolSwitched) tool->leftButtonUp(pos, toonzEvent); TApp::instance()->getCurrentTool()->setToolBusy(false); } @@ -564,6 +584,10 @@ quit: m_mouseButton = Qt::NoButton; m_tabletEvent = false; + m_tabletPressed = false; + m_tabletActive = false; + m_tabletReleased = false; + m_tabletMove = false; m_pressure = 0; } @@ -666,7 +690,7 @@ bool SceneViewer::event(QEvent *e) { clock.start(); } - /* +/* switch(e->type()) { case QEvent::Enter: