diff --git a/DFTFringe.pro b/DFTFringe.pro index 8b1d528f..07b86821 100644 --- a/DFTFringe.pro +++ b/DFTFringe.pro @@ -151,7 +151,7 @@ SOURCES += SingleApplication/singleapplication.cpp \ astigpolargraph.cpp \ astigscatterplot.cpp \ astigstatsdlg.cpp \ - autoinvertdlg.cpp \ + autoinvertdlg.cpp \ averagewavefrontfilesdlg.cpp \ batchigramwizard.cpp \ bathastigdlg.cpp \ @@ -171,6 +171,7 @@ SOURCES += SingleApplication/singleapplication.cpp \ contourview.cpp \ counterrotationdlg.cpp \ cpoint.cpp \ + custom3dinputhandler.cpp \ defocusdlg.cpp \ dftarea.cpp \ dftcolormap.cpp \ @@ -293,6 +294,7 @@ HEADERS += bezier/bezier.h \ contourview.h \ counterrotationdlg.h \ cpoint.h \ + custom3dinputhandler.h \ defocusdlg.h \ dftarea.h \ dftcolormap.h \ diff --git a/DFTFringe_Dale.pro b/DFTFringe_Dale.pro index 76fd813f..082bf3b9 100644 --- a/DFTFringe_Dale.pro +++ b/DFTFringe_Dale.pro @@ -33,6 +33,7 @@ SOURCES += main.cpp \ astigpolargraph.cpp \ autoinvertdlg.cpp \ cpoint.cpp \ + custom3dinputhandler.cpp \ defocusdlg.cpp \ edgeplot.cpp \ hotkeysdlg.cpp \ @@ -153,6 +154,7 @@ HEADERS += mainwindow.h \ astigpolargraph.h \ autoinvertdlg.h \ cpoint.h \ + custom3dinputhandler.h \ defocusdlg.h \ edgeplot.h \ IgramArea.h \ @@ -411,7 +413,7 @@ RC_FILE = DFTFringe.rc QMAKE_CXXFLAGS += -std=c++11 # The application version -VERSION = Dale7.3.2 +VERSION = 3Dmouse_08/24/26 # Define the preprocessor macro to get the application version in our application. DEFINES += APP_VERSION=\\\"$$VERSION\\\" diff --git a/DFTFringe_QT5.pro b/DFTFringe_QT5.pro index 65573323..f14f748c 100644 --- a/DFTFringe_QT5.pro +++ b/DFTFringe_QT5.pro @@ -175,6 +175,7 @@ SOURCES += SingleApplication/singleapplication.cpp \ contourview.cpp \ counterrotationdlg.cpp \ cpoint.cpp \ + custom3dinputhandler.cpp \ defocusdlg.cpp \ dftarea.cpp \ dftcolormap.cpp \ @@ -297,6 +298,7 @@ HEADERS += bezier/bezier.h \ contourview.h \ counterrotationdlg.h \ cpoint.h \ + custom3dinputhandler.h \ defocusdlg.h \ dftarea.h \ dftcolormap.h \ diff --git a/custom3dinputhandler.cpp b/custom3dinputhandler.cpp new file mode 100644 index 00000000..04e5a269 --- /dev/null +++ b/custom3dinputhandler.cpp @@ -0,0 +1,110 @@ +#include "custom3dinputhandler.h" +#include +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(), + 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(), + 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(), + event->button(), mappedButtons, event->modifiers()); +#endif + Q3DInputHandler::mouseMoveEvent(&customEvent, mousePos); +} diff --git a/custom3dinputhandler.h b/custom3dinputhandler.h new file mode 100644 index 00000000..41014383 --- /dev/null +++ b/custom3dinputhandler.h @@ -0,0 +1,30 @@ +#ifndef CUSTOM3DINPUTHANDLER_H +#define CUSTOM3DINPUTHANDLER_H + +#include +#include +#include +#include + +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +//keep compatiblity with Qt5 +using namespace QtDataVisualization; +#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 diff --git a/surfacegraph.cpp b/surfacegraph.cpp index 432e7e41..076e4819 100644 --- a/surfacegraph.cpp +++ b/surfacegraph.cpp @@ -36,17 +36,24 @@ #include #include #include - +#include "custom3dinputhandler.h" int sampleCountX = 50; int sampleCountZ = 50; const float sampleMin = -8.0f; const float sampleMax = 8.0f; #include + + + + 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 +485,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));