-
Notifications
You must be signed in to change notification settings - Fork 66
modified how 3D mouse buttons work #381
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
Changes from all commits
a7e8b06
1ac8e11
f1375c4
a530b82
f379740
bd9360c
e4e44be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| #include "custom3dinputhandler.h" | ||
| #include <QtMath> | ||
| Custom3DInputHandler::Custom3DInputHandler(QAbstract3DGraph *graph) | ||
| : Q3DInputHandler(graph), m_isRightDragging(false), m_graphRef(graph) { | ||
| setZoomAtTargetEnabled(true); | ||
| } | ||
|
|
||
| void Custom3DInputHandler::mousePressEvent(QMouseEvent *event, const QPoint &mousePos) { | ||
| if (event->button() == Qt::RightButton) { | ||
| m_isRightDragging = true; | ||
| m_lastMousePos = event->pos(); | ||
| event->accept(); | ||
| return; // Consume event so base handler doesn't interfere | ||
| } | ||
|
|
||
| // Map Left-Click to Right-Click for standard rotation in base handler | ||
| Qt::MouseButton mappedButton = (event->button() == Qt::LeftButton) ? Qt::RightButton : event->button(); | ||
| Qt::MouseButtons mappedButtons = event->buttons(); | ||
| if (mappedButtons & Qt::LeftButton) { | ||
| mappedButtons = (mappedButtons & ~Qt::LeftButton) | Qt::RightButton; | ||
| } | ||
|
|
||
| #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) | ||
| QMouseEvent customEvent(event->type(), event->position(), event->globalPosition(), | ||
| mappedButton, mappedButtons, event->modifiers()); | ||
| #else | ||
| QMouseEvent customEvent(event->type(), event->localPos(), event->globalPos(), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnosticcustom3dinputhandler.cpp:23:51: warning: [clang-diagnostic-deprecated-declarations]
23 | QMouseEvent customEvent(event->type(), event->localPos(), event->globalPos(),
| ^
/usr/include/x86_64-linux-gnu/qt6/QtGui/qevent.h:226:5: note: 'localPos' has been explicitly marked deprecated here
226 | QT_DEPRECATED_VERSION_X_6_0("Use position()")
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qglobal.h:326:44: note: expanded from macro 'QT_DEPRECATED_VERSION_X_6_0'
326 | # define QT_DEPRECATED_VERSION_X_6_0(text) QT_DEPRECATED_X(text)
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qglobal.h:238:33: note: expanded from macro 'QT_DEPRECATED_X'
238 | # define QT_DEPRECATED_X(text) Q_DECL_DEPRECATED_X(text)
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qcompilerdetection.h:956:36: note: expanded from macro 'Q_DECL_DEPRECATED_X'
956 | # define Q_DECL_DEPRECATED_X(x) [[deprecated(x)]]
| ^clang-tidy diagnosticcustom3dinputhandler.cpp:23:70: warning: [clang-diagnostic-deprecated-declarations]
23 | QMouseEvent customEvent(event->type(), event->localPos(), event->globalPos(),
| ^
/usr/include/x86_64-linux-gnu/qt6/QtGui/qevent.h:215:5: note: 'globalPos' has been explicitly marked deprecated here
215 | QT_DEPRECATED_VERSION_X_6_0("Use globalPosition()")
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qglobal.h:326:44: note: expanded from macro 'QT_DEPRECATED_VERSION_X_6_0'
326 | # define QT_DEPRECATED_VERSION_X_6_0(text) QT_DEPRECATED_X(text)
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qglobal.h:238:33: note: expanded from macro 'QT_DEPRECATED_X'
238 | # define QT_DEPRECATED_X(text) Q_DECL_DEPRECATED_X(text)
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qcompilerdetection.h:956:36: note: expanded from macro 'Q_DECL_DEPRECATED_X'
956 | # define Q_DECL_DEPRECATED_X(x) [[deprecated(x)]]
| ^ |
||
| mappedButton, mappedButtons, event->modifiers()); | ||
| #endif | ||
| Q3DInputHandler::mousePressEvent(&customEvent, mousePos); | ||
| Q3DInputHandler::mousePressEvent(&customEvent, mousePos); | ||
| } | ||
|
|
||
| void Custom3DInputHandler::mouseReleaseEvent(QMouseEvent *event, const QPoint &mousePos) { | ||
| if (event->button() == Qt::RightButton) { | ||
| m_isRightDragging = false; | ||
| event->accept(); | ||
| return; | ||
| } | ||
|
|
||
| Qt::MouseButton mappedButton = (event->button() == Qt::LeftButton) ? Qt::RightButton : event->button(); | ||
| Qt::MouseButtons mappedButtons = event->buttons(); | ||
| if (mappedButtons & Qt::LeftButton) { | ||
| mappedButtons = (mappedButtons & ~Qt::LeftButton) | Qt::RightButton; | ||
| } | ||
|
|
||
| #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) | ||
| QMouseEvent customEvent(event->type(), event->position(), event->globalPosition(), | ||
| mappedButton, mappedButtons, event->modifiers()); | ||
| #else | ||
| QMouseEvent customEvent(event->type(), event->localPos(), event->globalPos(), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnosticcustom3dinputhandler.cpp:41:51: warning: [clang-diagnostic-deprecated-declarations]
41 | QMouseEvent customEvent(event->type(), event->localPos(), event->globalPos(),
| ^
/usr/include/x86_64-linux-gnu/qt6/QtGui/qevent.h:226:5: note: 'localPos' has been explicitly marked deprecated here
226 | QT_DEPRECATED_VERSION_X_6_0("Use position()")
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qglobal.h:326:44: note: expanded from macro 'QT_DEPRECATED_VERSION_X_6_0'
326 | # define QT_DEPRECATED_VERSION_X_6_0(text) QT_DEPRECATED_X(text)
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qglobal.h:238:33: note: expanded from macro 'QT_DEPRECATED_X'
238 | # define QT_DEPRECATED_X(text) Q_DECL_DEPRECATED_X(text)
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qcompilerdetection.h:956:36: note: expanded from macro 'Q_DECL_DEPRECATED_X'
956 | # define Q_DECL_DEPRECATED_X(x) [[deprecated(x)]]
| ^clang-tidy diagnosticcustom3dinputhandler.cpp:41:70: warning: [clang-diagnostic-deprecated-declarations]
41 | QMouseEvent customEvent(event->type(), event->localPos(), event->globalPos(),
| ^
/usr/include/x86_64-linux-gnu/qt6/QtGui/qevent.h:215:5: note: 'globalPos' has been explicitly marked deprecated here
215 | QT_DEPRECATED_VERSION_X_6_0("Use globalPosition()")
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qglobal.h:326:44: note: expanded from macro 'QT_DEPRECATED_VERSION_X_6_0'
326 | # define QT_DEPRECATED_VERSION_X_6_0(text) QT_DEPRECATED_X(text)
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qglobal.h:238:33: note: expanded from macro 'QT_DEPRECATED_X'
238 | # define QT_DEPRECATED_X(text) Q_DECL_DEPRECATED_X(text)
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qcompilerdetection.h:956:36: note: expanded from macro 'Q_DECL_DEPRECATED_X'
956 | # define Q_DECL_DEPRECATED_X(x) [[deprecated(x)]]
| ^There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnosticcustom3dinputhandler.cpp:41:51: warning: [clang-diagnostic-deprecated-declarations]
41 | QMouseEvent customEvent(event->type(), event->localPos(), event->globalPos(),
| ^
/usr/include/x86_64-linux-gnu/qt6/QtGui/qevent.h:226:5: note: 'localPos' has been explicitly marked deprecated here
226 | QT_DEPRECATED_VERSION_X_6_0("Use position()")
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qglobal.h:326:44: note: expanded from macro 'QT_DEPRECATED_VERSION_X_6_0'
326 | # define QT_DEPRECATED_VERSION_X_6_0(text) QT_DEPRECATED_X(text)
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qglobal.h:238:33: note: expanded from macro 'QT_DEPRECATED_X'
238 | # define QT_DEPRECATED_X(text) Q_DECL_DEPRECATED_X(text)
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qcompilerdetection.h:956:36: note: expanded from macro 'Q_DECL_DEPRECATED_X'
956 | # define Q_DECL_DEPRECATED_X(x) [[deprecated(x)]]
| ^clang-tidy diagnosticcustom3dinputhandler.cpp:41:70: warning: [clang-diagnostic-deprecated-declarations]
41 | QMouseEvent customEvent(event->type(), event->localPos(), event->globalPos(),
| ^
/usr/include/x86_64-linux-gnu/qt6/QtGui/qevent.h:215:5: note: 'globalPos' has been explicitly marked deprecated here
215 | QT_DEPRECATED_VERSION_X_6_0("Use globalPosition()")
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qglobal.h:326:44: note: expanded from macro 'QT_DEPRECATED_VERSION_X_6_0'
326 | # define QT_DEPRECATED_VERSION_X_6_0(text) QT_DEPRECATED_X(text)
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qglobal.h:238:33: note: expanded from macro 'QT_DEPRECATED_X'
238 | # define QT_DEPRECATED_X(text) Q_DECL_DEPRECATED_X(text)
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qcompilerdetection.h:956:36: note: expanded from macro 'Q_DECL_DEPRECATED_X'
956 | # define Q_DECL_DEPRECATED_X(x) [[deprecated(x)]]
| ^ |
||
| mappedButton, mappedButtons, event->modifiers()); | ||
| #endif | ||
| Q3DInputHandler::mousePressEvent(&customEvent, mousePos); | ||
| Q3DInputHandler::mouseReleaseEvent(&customEvent, mousePos); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| void Custom3DInputHandler::mouseMoveEvent(QMouseEvent *event, const QPoint &mousePos) { | ||
| if (m_isRightDragging && m_graphRef) { | ||
| QPoint delta = event->pos() - m_lastMousePos; | ||
| m_lastMousePos = event->pos(); | ||
|
|
||
| // Adjust camera target to pan the view | ||
| Q3DCamera *camera = m_graphRef->scene()->activeCamera(); | ||
| if (camera) { | ||
| QVector3D target = camera->target(); | ||
| float panScale = 0.003f; | ||
|
|
||
| // Extract both rotations in radians | ||
| float xRotRad = qDegreesToRadians(camera->xRotation()); // Yaw (horizontal orbit) | ||
| float yRotRad = qDegreesToRadians(camera->yRotation()); // Pitch (vertical tilt) | ||
|
|
||
| float cosX = qCos(xRotRad); | ||
| float sinX = qSin(xRotRad); | ||
| float cosY = qCos(yRotRad); | ||
| float sinY = qSin(yRotRad); | ||
|
|
||
| // Invert Y delta (flipped back so dragging down moves the scene down) | ||
| float invertedDeltaY = -delta.y(); | ||
|
|
||
| float dx = (-delta.x() * cosX - invertedDeltaY * sinX * cosY) * panScale; | ||
| float dy = (invertedDeltaY * sinY) * panScale; | ||
| float dz = (delta.x() * sinX - invertedDeltaY * cosX * cosY) * panScale; | ||
|
|
||
| target.setX(target.x() + dx); | ||
| target.setY(target.y() + dy); | ||
| target.setZ(target.z() + dz); | ||
|
|
||
| camera->setTarget(target); | ||
| } | ||
| event->accept(); | ||
| return; | ||
| } | ||
|
|
||
| Qt::MouseButtons mappedButtons = event->buttons(); | ||
| if (mappedButtons & Qt::LeftButton) { | ||
| mappedButtons = (mappedButtons & ~Qt::LeftButton) | Qt::RightButton; | ||
| } | ||
|
|
||
| #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) | ||
| QMouseEvent customEvent(event->type(), event->position(), event->globalPosition(), | ||
| event->button(), mappedButtons, event->modifiers()); | ||
| #else | ||
| QMouseEvent customEvent(event->type(), event->localPos(), event->globalPos(), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnosticcustom3dinputhandler.cpp:70:51: warning: [clang-diagnostic-deprecated-declarations]
70 | QMouseEvent customEvent(event->type(), event->localPos(), event->globalPos(),
| ^
/usr/include/x86_64-linux-gnu/qt6/QtGui/qevent.h:226:5: note: 'localPos' has been explicitly marked deprecated here
226 | QT_DEPRECATED_VERSION_X_6_0("Use position()")
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qglobal.h:326:44: note: expanded from macro 'QT_DEPRECATED_VERSION_X_6_0'
326 | # define QT_DEPRECATED_VERSION_X_6_0(text) QT_DEPRECATED_X(text)
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qglobal.h:238:33: note: expanded from macro 'QT_DEPRECATED_X'
238 | # define QT_DEPRECATED_X(text) Q_DECL_DEPRECATED_X(text)
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qcompilerdetection.h:956:36: note: expanded from macro 'Q_DECL_DEPRECATED_X'
956 | # define Q_DECL_DEPRECATED_X(x) [[deprecated(x)]]
| ^clang-tidy diagnosticcustom3dinputhandler.cpp:70:70: warning: [clang-diagnostic-deprecated-declarations]
70 | QMouseEvent customEvent(event->type(), event->localPos(), event->globalPos(),
| ^
/usr/include/x86_64-linux-gnu/qt6/QtGui/qevent.h:215:5: note: 'globalPos' has been explicitly marked deprecated here
215 | QT_DEPRECATED_VERSION_X_6_0("Use globalPosition()")
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qglobal.h:326:44: note: expanded from macro 'QT_DEPRECATED_VERSION_X_6_0'
326 | # define QT_DEPRECATED_VERSION_X_6_0(text) QT_DEPRECATED_X(text)
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qglobal.h:238:33: note: expanded from macro 'QT_DEPRECATED_X'
238 | # define QT_DEPRECATED_X(text) Q_DECL_DEPRECATED_X(text)
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qcompilerdetection.h:956:36: note: expanded from macro 'Q_DECL_DEPRECATED_X'
956 | # define Q_DECL_DEPRECATED_X(x) [[deprecated(x)]]
| ^There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnosticcustom3dinputhandler.cpp:90:51: warning: [clang-diagnostic-deprecated-declarations]
90 | QMouseEvent customEvent(event->type(), event->localPos(), event->globalPos(),
| ^
/usr/include/x86_64-linux-gnu/qt6/QtGui/qevent.h:226:5: note: 'localPos' has been explicitly marked deprecated here
226 | QT_DEPRECATED_VERSION_X_6_0("Use position()")
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qglobal.h:326:44: note: expanded from macro 'QT_DEPRECATED_VERSION_X_6_0'
326 | # define QT_DEPRECATED_VERSION_X_6_0(text) QT_DEPRECATED_X(text)
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qglobal.h:238:33: note: expanded from macro 'QT_DEPRECATED_X'
238 | # define QT_DEPRECATED_X(text) Q_DECL_DEPRECATED_X(text)
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qcompilerdetection.h:956:36: note: expanded from macro 'Q_DECL_DEPRECATED_X'
956 | # define Q_DECL_DEPRECATED_X(x) [[deprecated(x)]]
| ^clang-tidy diagnosticcustom3dinputhandler.cpp:90:70: warning: [clang-diagnostic-deprecated-declarations]
90 | QMouseEvent customEvent(event->type(), event->localPos(), event->globalPos(),
| ^
/usr/include/x86_64-linux-gnu/qt6/QtGui/qevent.h:215:5: note: 'globalPos' has been explicitly marked deprecated here
215 | QT_DEPRECATED_VERSION_X_6_0("Use globalPosition()")
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qglobal.h:326:44: note: expanded from macro 'QT_DEPRECATED_VERSION_X_6_0'
326 | # define QT_DEPRECATED_VERSION_X_6_0(text) QT_DEPRECATED_X(text)
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qglobal.h:238:33: note: expanded from macro 'QT_DEPRECATED_X'
238 | # define QT_DEPRECATED_X(text) Q_DECL_DEPRECATED_X(text)
| ^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qcompilerdetection.h:956:36: note: expanded from macro 'Q_DECL_DEPRECATED_X'
956 | # define Q_DECL_DEPRECATED_X(x) [[deprecated(x)]]
| ^ |
||
| event->button(), mappedButtons, event->modifiers()); | ||
| #endif | ||
| Q3DInputHandler::mouseMoveEvent(&customEvent, mousePos); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #ifndef CUSTOM3DINPUTHANDLER_H | ||
| #define CUSTOM3DINPUTHANDLER_H | ||
|
|
||
| #include <QtDataVisualization/Q3DInputHandler> | ||
| #include <QtDataVisualization/QAbstract3DGraph> | ||
| #include <QtDataVisualization/Q3DCamera> | ||
| #include <QMouseEvent> | ||
|
|
||
| #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) | ||
| //keep compatiblity with Qt5 | ||
| using namespace QtDataVisualization; | ||
|
atsju marked this conversation as resolved.
|
||
| #endif | ||
|
|
||
| class Custom3DInputHandler : public Q3DInputHandler { | ||
| Q_OBJECT | ||
| public: | ||
| Custom3DInputHandler(QAbstract3DGraph *graph = nullptr); | ||
|
|
||
| protected: | ||
| void mousePressEvent(QMouseEvent *event, const QPoint &mousePos) override; | ||
| void mouseReleaseEvent(QMouseEvent *event, const QPoint &mousePos) override; | ||
| void mouseMoveEvent(QMouseEvent *event, const QPoint &mousePos) override; | ||
|
|
||
| private: | ||
| bool m_isRightDragging; | ||
| QPoint m_lastMousePos; | ||
| QAbstract3DGraph *m_graphRef; | ||
| }; | ||
|
|
||
| #endif // CUSTOM3DINPUTHANDLER_H | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy diagnostic
custom3dinputhandler.cpp:23:51: warning: [clang-diagnostic-deprecated-declarations]
clang-tidy diagnostic
custom3dinputhandler.cpp:23:70: warning: [clang-diagnostic-deprecated-declarations]