diff --git a/Documentation/release/dev/add-qt-toucheventproessing-flag.md b/Documentation/release/dev/add-qt-toucheventproessing-flag.md new file mode 100644 index 0000000000000000000000000000000000000000..5381e48dc1f3093d1da1f0ad0fb86e0aac4acc5f --- /dev/null +++ b/Documentation/release/dev/add-qt-toucheventproessing-flag.md @@ -0,0 +1,4 @@ +## Add EnableTouchEventProcessing flag to QVTKOpenGL*Widgets & QVTKOpenGLWindow + +As Qt touch event will automatically be translated to mouse event, so the mouse event will be processed twice for one touch in VTK interactor. +With this new flag for QVTKOpenGL*Widget/QVTKOpenGLWindow, you can switch on/off the Qt touch event processing by purpose. diff --git a/GUISupport/Qt/QVTKInteractorAdapter.cxx b/GUISupport/Qt/QVTKInteractorAdapter.cxx index 5e9e614e3dbc731f209e8bb687dc8c1af31911b3..37b1b445df0b7efaa250f95f3afde9d4e03762f5 100644 --- a/GUISupport/Qt/QVTKInteractorAdapter.cxx +++ b/GUISupport/Qt/QVTKInteractorAdapter.cxx @@ -44,6 +44,11 @@ QVTKInteractorAdapter::QVTKInteractorAdapter(QObject* parentObject) QVTKInteractorAdapter::~QVTKInteractorAdapter() = default; +void QVTKInteractorAdapter::SetEnableTouchEventProcessing(bool val) +{ + this->EnableTouchEventProcessing = val; +} + void QVTKInteractorAdapter::SetDevicePixelRatio(float ratio, vtkRenderWindowInteractor* iren) { if (ratio != DevicePixelRatio) @@ -192,8 +197,14 @@ bool QVTKInteractorAdapter::ProcessEvent(QEvent* e, vtkRenderWindowInteractor* i } return true; } + if (t == QEvent::TouchBegin || t == QEvent::TouchUpdate || t == QEvent::TouchEnd) { + if (!this->EnableTouchEventProcessing) + { + return false; + } + QTouchEvent* e2 = dynamic_cast<QTouchEvent*>(e); #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) Q_FOREACH (const QTouchEvent::TouchPoint& point, e2->touchPoints()) diff --git a/GUISupport/Qt/QVTKInteractorAdapter.h b/GUISupport/Qt/QVTKInteractorAdapter.h index 8454e411b33ddcd7283862ef2687861e4374f156..038c1ded8b0c4a5f79f0137eee2ead09473eaa14 100644 --- a/GUISupport/Qt/QVTKInteractorAdapter.h +++ b/GUISupport/Qt/QVTKInteractorAdapter.h @@ -39,6 +39,11 @@ public: // Destructor ~QVTKInteractorAdapter() override; + // Description: + // Enable/disable the touch event processing + void SetEnableTouchEventProcessing(bool val); + bool GetEnableTouchEventProcessing() const { return this->EnableTouchEventProcessing; } + // Description: // Set the device pixel ratio, this defaults to 1.0, but in Qt 5 can be != 1.0. void SetDevicePixelRatio(float ratio, vtkRenderWindowInteractor* iren = nullptr); @@ -51,6 +56,7 @@ public: protected: int AccumulatedDelta; + bool EnableTouchEventProcessing = true; float DevicePixelRatio; static const double DevicePixelRatioTolerance; }; diff --git a/GUISupport/Qt/QVTKOpenGLNativeWidget.cxx b/GUISupport/Qt/QVTKOpenGLNativeWidget.cxx index 130891546756425a59fdf4349c2e7ed6b32ae411..a0f00debdedc6a59614c1ca08b3d7ceb29752bf6 100644 --- a/GUISupport/Qt/QVTKOpenGLNativeWidget.cxx +++ b/GUISupport/Qt/QVTKOpenGLNativeWidget.cxx @@ -153,6 +153,16 @@ QSurfaceFormat QVTKOpenGLNativeWidget::defaultFormat(bool stereo_capable) return QVTKRenderWindowAdapter::defaultFormat(stereo_capable); } +//------------------------------------------------------------------------------ +void QVTKOpenGLNativeWidget::setEnableTouchEventProcessing(bool enable) +{ + this->EnableTouchEventProcessing = enable; + if (this->RenderWindowAdapter) + { + this->RenderWindowAdapter->setEnableTouchEventProcessing(enable); + } +} + //------------------------------------------------------------------------------ void QVTKOpenGLNativeWidget::setEnableHiDPI(bool enable) { @@ -240,6 +250,7 @@ void QVTKOpenGLNativeWidget::initializeGL() this->RenderWindowAdapter.reset( new QVTKRenderWindowAdapter(this->context(), this->RenderWindow, this)); this->RenderWindowAdapter->setDefaultCursor(this->defaultCursor()); + this->RenderWindowAdapter->setEnableTouchEventProcessing(this->EnableTouchEventProcessing); this->RenderWindowAdapter->setEnableHiDPI(this->EnableHiDPI); this->RenderWindowAdapter->setUnscaledDPI(this->UnscaledDPI); this->RenderWindowAdapter->setCustomDevicePixelRatio(this->CustomDevicePixelRatio); diff --git a/GUISupport/Qt/QVTKOpenGLNativeWidget.h b/GUISupport/Qt/QVTKOpenGLNativeWidget.h index 888d8feccad444af53abd84a9dd45a47ca85322b..4d502fdf4b59f881674fbac84b028117517a59b3 100644 --- a/GUISupport/Qt/QVTKOpenGLNativeWidget.h +++ b/GUISupport/Qt/QVTKOpenGLNativeWidget.h @@ -142,6 +142,16 @@ public: */ static QSurfaceFormat defaultFormat(bool stereo_capable = false); + ///@{ + /** + * Enable or disable support for touch event processing. When enabled, this widget + * will process Qt::TouchBegin/TouchUpdate/TouchEnd event, otherwise, these events + * will be ignored. Default is true. + */ + void setEnableTouchEventProcessing(bool enable); + bool enableTouchEventProcesing() const { return this->EnableTouchEventProcessing; } + ///@} + ///@{ /** * Enable or disable support for HiDPI displays. When enabled, this enabled @@ -219,6 +229,7 @@ protected: // NOLINT(readability-redundant-access-specifiers) private: Q_DISABLE_COPY(QVTKOpenGLNativeWidget); + bool EnableTouchEventProcessing = true; bool EnableHiDPI; int UnscaledDPI; double CustomDevicePixelRatio; diff --git a/GUISupport/Qt/QVTKOpenGLStereoWidget.h b/GUISupport/Qt/QVTKOpenGLStereoWidget.h index 8622f1504b14f8bc7cb744c57f54c295a0d5c167..ca3ca50e9303728d83f1f718240c87222b42ec36 100644 --- a/GUISupport/Qt/QVTKOpenGLStereoWidget.h +++ b/GUISupport/Qt/QVTKOpenGLStereoWidget.h @@ -94,6 +94,18 @@ public: return QVTKOpenGLWindow::defaultFormat(stereo_capable); } + /** + * @copydoc QVTKOpenGLWindow::setEnableTouchEventProcessing() + */ + void setEnableTouchEventProcessing(bool enable) + { + this->VTKOpenGLWindow->setEnableTouchEventProcessing(enable); + } + bool enableTouchEventProcessing() const + { + return this->VTKOpenGLWindow->enableTouchEventProcessing(); + } + /** * @copydoc QVTKOpenGLWindow::setEnableHiDPI() */ diff --git a/GUISupport/Qt/QVTKOpenGLWindow.cxx b/GUISupport/Qt/QVTKOpenGLWindow.cxx index e34ff815b79e47383a3e16396e78572f9f2636ea..2fb5f3169f0cb5c124209bdd15ffcde5a2f963d6 100644 --- a/GUISupport/Qt/QVTKOpenGLWindow.cxx +++ b/GUISupport/Qt/QVTKOpenGLWindow.cxx @@ -139,6 +139,16 @@ QSurfaceFormat QVTKOpenGLWindow::defaultFormat(bool stereo_capable) return QVTKRenderWindowAdapter::defaultFormat(stereo_capable); } +//------------------------------------------------------------------------------ +void QVTKOpenGLWindow::setEnableTouchEventProcessing(bool enable) +{ + this->EnableTouchEventProcessing = enable; + if (this->RenderWindowAdapter) + { + this->RenderWindowAdapter->setEnableTouchEventProcessing(enable); + } +} + //------------------------------------------------------------------------------ void QVTKOpenGLWindow::setEnableHiDPI(bool enable) { @@ -217,6 +227,7 @@ void QVTKOpenGLWindow::initializeGL() this->RenderWindowAdapter.reset( new QVTKRenderWindowAdapter(this->context(), this->RenderWindow, this)); this->RenderWindowAdapter->setDefaultCursor(this->defaultCursor()); + this->RenderWindowAdapter->setEnableTouchEventProcessing(this->EnableTouchEventProcessing); this->RenderWindowAdapter->setEnableHiDPI(this->EnableHiDPI); this->RenderWindowAdapter->setUnscaledDPI(this->UnscaledDPI); this->RenderWindowAdapter->setCustomDevicePixelRatio(this->CustomDevicePixelRatio); diff --git a/GUISupport/Qt/QVTKOpenGLWindow.h b/GUISupport/Qt/QVTKOpenGLWindow.h index bddfaab4a91c2485d23d2ae82f007a86baa47dfa..b208bfc9bee8c8ed339dbcca0b6d59cd5c2d9fd0 100644 --- a/GUISupport/Qt/QVTKOpenGLWindow.h +++ b/GUISupport/Qt/QVTKOpenGLWindow.h @@ -93,6 +93,18 @@ public: */ static QSurfaceFormat defaultFormat(bool stereo_capable = false); + ///@{ + /** + * Enable or disable support for touch event processing. When enabled, this widget + * will process Qt::TouchBegin/TouchUpdate/TouchEnd event, otherwise, these events + * will be ignored. For some vtk widgets like vtkDistanceWidget, if this option is + * enabled, it will received leftButtonPressed/leftButtonRelease twice for one touch, + * this breaks its designed logics. Default is true. + */ + void setEnableTouchEventProcessing(bool enable); + bool enableTouchEventProcessing() const { return this->EnableTouchEventProcessing; } + ///@} + ///@{ /** * Enable or disable support for HiDPI displays. When enabled, this enabled @@ -175,6 +187,7 @@ protected: // NOLINT(readability-redundant-access-specifiers) private: Q_DISABLE_COPY(QVTKOpenGLWindow); + bool EnableTouchEventProcessing = true; bool EnableHiDPI; int UnscaledDPI; double CustomDevicePixelRatio; diff --git a/GUISupport/Qt/QVTKRenderWindowAdapter.cxx b/GUISupport/Qt/QVTKRenderWindowAdapter.cxx index c2069d67f01614c57b4b1de7e6c53ee1d2497616..ca7c08ed3448d343157395d69b2d609e35c96774 100644 --- a/GUISupport/Qt/QVTKRenderWindowAdapter.cxx +++ b/GUISupport/Qt/QVTKRenderWindowAdapter.cxx @@ -382,6 +382,11 @@ public: : this->ParentWidget->setCursor(cursor); } + void setEnableTouchEventProcessing(bool val) + { + this->InteractorAdapter.SetEnableTouchEventProcessing(val); + } + void setEnableHiDPI(bool val) { if (this->EnableHiDPI != val) @@ -564,6 +569,15 @@ bool QVTKRenderWindowAdapter::handleEvent(QEvent* evt) : false; } +//------------------------------------------------------------------------------ +void QVTKRenderWindowAdapter::setEnableTouchEventProcessing(bool value) +{ + if (this->Internals) + { + this->Internals->setEnableTouchEventProcessing(value); + } +} + //------------------------------------------------------------------------------ void QVTKRenderWindowAdapter::setEnableHiDPI(bool value) { diff --git a/GUISupport/Qt/QVTKRenderWindowAdapter.h b/GUISupport/Qt/QVTKRenderWindowAdapter.h index 2e40de5b2d745c1057b511ee98e11dcdf27f9344..370ff0377b01abe0947cd623f6b79efd4917d323 100644 --- a/GUISupport/Qt/QVTKRenderWindowAdapter.h +++ b/GUISupport/Qt/QVTKRenderWindowAdapter.h @@ -134,6 +134,14 @@ public: const QCursor& defaultCursor() const { return this->DefaultCursor; } ///@} + ///@{ + /** + * Enable/disable Qt touch event processing. Basic QEvent::TouchBegin/ + TouchUpdate/TouchEnd event will be/not be processed. Default is true. + */ + void setEnableTouchEventProcessing(bool value); + ///@} + ///@{ /** * Enable/disable DPI scaling. When enabled call to `resize` (which must