diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGViewport.cpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGViewport.cpp index 292cc61e9..2c83c7651 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGViewport.cpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGViewport.cpp @@ -627,7 +627,8 @@ public: needToDoFrame = true; // h->view->getCamera()->resize(width, height); - h->view->getCamera()->getGraphicsContext()->resized(0, 0, width, height); + h->gc->resized(0, 0, width, height); + h->view->getEventQueue()->windowResize(0, 0, width, height /*, resizeTime*/); // trick to force a "home" on first few frames to absorb initial spurious resizes if (frameCount <= 2) { @@ -831,14 +832,6 @@ void OSGViewport::componentComplete() Inherited::componentComplete(); } -QPointF OSGViewport::mousePoint(QMouseEvent *event) -{ - qreal x = 2.0 * (event->x() - width() / 2) / width(); - qreal y = 2.0 * (event->y() - height() / 2) / height(); - - return QPointF(x, y); -} - void OSGViewport::mousePressEvent(QMouseEvent *event) { int button = 0; @@ -853,26 +846,7 @@ void OSGViewport::mousePressEvent(QMouseEvent *event) setKeyboardModifiers(event); QPointF pos = mousePoint(event); if (h->view.valid()) { - h->view.get()->getEventQueue()->mouseButtonPress(pos.x(), pos.y(), button); - } -} - -void OSGViewport::setKeyboardModifiers(QInputEvent *event) -{ - int modkey = event->modifiers() & (Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier); - unsigned int mask = 0; - - if (modkey & Qt::ShiftModifier) { - mask |= osgGA::GUIEventAdapter::MODKEY_SHIFT; - } - if (modkey & Qt::ControlModifier) { - mask |= osgGA::GUIEventAdapter::MODKEY_CTRL; - } - if (modkey & Qt::AltModifier) { - mask |= osgGA::GUIEventAdapter::MODKEY_ALT; - } - if (h->view.valid()) { - h->view.get()->getEventQueue()->getCurrentEventState()->setModKeyMask(mask); + h->view->getEventQueue()->mouseButtonPress(pos.x(), pos.y(), button); } } @@ -881,7 +855,7 @@ void OSGViewport::mouseMoveEvent(QMouseEvent *event) setKeyboardModifiers(event); QPointF pos = mousePoint(event); if (h->view.valid()) { - h->view.get()->getEventQueue()->mouseMotion(pos.x(), pos.y()); + h->view->getEventQueue()->mouseMotion(pos.x(), pos.y()); } } @@ -899,7 +873,7 @@ void OSGViewport::mouseReleaseEvent(QMouseEvent *event) setKeyboardModifiers(event); QPointF pos = mousePoint(event); if (h->view.valid()) { - h->view.get()->getEventQueue()->mouseButtonRelease(pos.x(), pos.y(), button); + h->view->getEventQueue()->mouseButtonRelease(pos.x(), pos.y(), button); } } @@ -911,7 +885,7 @@ void OSGViewport::wheelEvent(QWheelEvent *event) (event->delta() > 0 ? osgGA::GUIEventAdapter::SCROLL_LEFT : osgGA::GUIEventAdapter::SCROLL_RIGHT); if (h->view.valid()) { - h->view.get()->getEventQueue()->mouseScroll(motion); + h->view->getEventQueue()->mouseScroll(motion); } } @@ -920,7 +894,7 @@ void OSGViewport::keyPressEvent(QKeyEvent *event) setKeyboardModifiers(event); int value = h->keyMap.remapKey(event); if (h->view.valid()) { - h->view.get()->getEventQueue()->keyPress(value); + h->view->getEventQueue()->keyPress(value); } // this passes the event to the regular Qt key event processing, @@ -938,7 +912,7 @@ void OSGViewport::keyReleaseEvent(QKeyEvent *event) setKeyboardModifiers(event); int value = h->keyMap.remapKey(event); if (h->view.valid()) { - h->view.get()->getEventQueue()->keyRelease(value); + h->view->getEventQueue()->keyRelease(value); } } @@ -948,6 +922,39 @@ void OSGViewport::keyReleaseEvent(QKeyEvent *event) // if( _forwardKeyEvents ) // Inherited::keyReleaseEvent(event); } + +QPointF OSGViewport::mousePoint(QMouseEvent *event) +{ + qreal x, y; + + if (h->view.valid() && h->view->getEventQueue()->getUseFixedMouseInputRange()) { + x = 2.0 * (event->x() - width() / 2) / width(); + y = 2.0 * (event->y() - height() / 2) / height(); + } else { + x = event->x(); + y = event->y(); + } + return QPointF(x, y); +} + +void OSGViewport::setKeyboardModifiers(QInputEvent *event) +{ + int modkey = event->modifiers() & (Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier); + unsigned int mask = 0; + + if (modkey & Qt::ShiftModifier) { + mask |= osgGA::GUIEventAdapter::MODKEY_SHIFT; + } + if (modkey & Qt::ControlModifier) { + mask |= osgGA::GUIEventAdapter::MODKEY_CTRL; + } + if (modkey & Qt::AltModifier) { + mask |= osgGA::GUIEventAdapter::MODKEY_ALT; + } + if (h->view.valid()) { + h->view->getEventQueue()->getCurrentEventState()->setModKeyMask(mask); + } +} } // namespace osgQtQuick #include "OSGViewport.moc" diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGViewport.hpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGViewport.hpp index 08ce7f041..170de8202 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGViewport.hpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGViewport.hpp @@ -80,10 +80,10 @@ public: bool busy() const; void setBusy(bool busy); - Renderer *createRenderer() const; - osgViewer::View *asView() const; + Renderer *createRenderer() const; + signals: void sceneNodeChanged(OSGNode *node); void cameraNodeChanged(OSGCamera *node); @@ -92,9 +92,10 @@ signals: void busyChanged(bool busy); protected: -#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0) - QSGNode *updatePaintNode(QSGNode *node, QQuickItem::UpdatePaintNodeData *nodeData) override; -#endif + // QQmlParserStatus + void classBegin(); + void componentComplete(); + // QQuickItem void mousePressEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event); @@ -103,16 +104,17 @@ protected: void keyPressEvent(QKeyEvent *event); void keyReleaseEvent(QKeyEvent *event); - void setKeyboardModifiers(QInputEvent *event); - QPointF mousePoint(QMouseEvent *event); - - // QQmlParserStatus - void classBegin(); - void componentComplete(); +#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0) + // QQuickFramebufferObject + QSGNode *updatePaintNode(QSGNode *node, QQuickItem::UpdatePaintNodeData *nodeData) override; +#endif private: struct Hidden; Hidden *const h; + + void setKeyboardModifiers(QInputEvent *event); + QPointF mousePoint(QMouseEvent *event); }; } // namespace osgQtQuick