-
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
base: master
Are you sure you want to change the base?
Changes from all commits
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,93 @@ | ||
| #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; | ||
| } | ||
|
|
||
| QMouseEvent customEvent(event->type(), event->localPos(), event->globalPos(), | ||
|
Check warning on line 23 in custom3dinputhandler.cpp
|
||
|
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()); | ||
| 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; | ||
| } | ||
|
|
||
| QMouseEvent customEvent(event->type(), event->localPos(), event->globalPos(), | ||
|
Check warning on line 41 in custom3dinputhandler.cpp
|
||
|
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()); | ||
| 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; | ||
| } | ||
|
|
||
| QMouseEvent customEvent(event->type(), event->localPos(), event->globalPos(), | ||
|
Check warning on line 90 in custom3dinputhandler.cpp
|
||
|
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()); | ||
| 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 | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -36,17 +36,26 @@ | |||||
| #include <QLabel> | ||||||
| #include <QSettings> | ||||||
| #include <QDebug> | ||||||
|
|
||||||
| #include "custom3dinputhandler.h" | ||||||
| int sampleCountX = 50; | ||||||
| int sampleCountZ = 50; | ||||||
|
|
||||||
| const float sampleMin = -8.0f; | ||||||
| const float sampleMax = 8.0f; | ||||||
| #include <QOpenGLFunctions> | ||||||
|
|
||||||
| #include <Q3DInputHandler> | ||||||
| #include <QMouseEvent> | ||||||
|
Comment on lines
+47
to
+48
Collaborator
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. those are not needed. they are managed by #include "custom3dinputhandler.h" and ony needed by itself. Remove from here.
Suggested change
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
| SurfaceGraph::SurfaceGraph(Q3DSurface *surface) | ||||||
| : m_graph(surface),m_axisMaxSliderXValue(100),m_axisMinSliderXValue(0), m_wf(0), m_colorRange(.56) | ||||||
| { | ||||||
| m_xGridMin = 0; | ||||||
| // Replace default input handler with your custom one | ||||||
| Custom3DInputHandler *customInputHandler = new Custom3DInputHandler(m_graph); | ||||||
| m_graph->setActiveInputHandler(customInputHandler); | ||||||
| m_graph->setAxisX(new QValue3DAxis); | ||||||
| m_graph->setAxisY(new QValue3DAxis); | ||||||
| m_graph->setAxisZ(new QValue3DAxis); | ||||||
|
|
@@ -478,7 +487,6 @@ QSize SurfaceGraph::Size(){ | |||||
| QImage SurfaceGraph::render(int width, int height){ | ||||||
| QSize orgsize = m_graph->size(); | ||||||
| if (orgsize.width() < width){ | ||||||
| qDebug() << "m_graph size" << orgsize << width << height; | ||||||
| m_graph->resize(width, height); | ||||||
| } | ||||||
| QImage result = m_graph->renderToImage(0, QSize(width,height)); | ||||||
|
|
||||||
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]