/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// #include "OdaCommon.h" #include #include "OdVisualizeQtAppWidget.h" OdTvQtRenderingWidget::OdTvQtRenderingWidget( QWidget* parent ) : QWidget( parent ) { //We need this attributes to control widget paining. setAttribute( Qt::WA_PaintOnScreen ); setBackgroundRole( QPalette::NoRole ); m_bDoPan = false; } void OdTvQtRenderingWidget::paintEvent(QPaintEvent* e) { //Render scene if( !m_deviceId.isNull() ) { m_deviceId.openObject()->update(); } } QPaintEngine* OdTvQtRenderingWidget::paintEngine() const { return NULL; } void OdTvQtRenderingWidget::resizeEvent( QResizeEvent* e ) { //resize device if( m_deviceId.isNull() ) return; OdTvDCRect rect( 0, e->size().width(), e->size().height(), 0 ); m_deviceId.openObject( OdTv::kForWrite )->onSize( rect ); } void OdTvQtRenderingWidget::wheelEvent( QWheelEvent* e ) { //Perform Zoom if( m_deviceId.isNull() ) return; OdTvGsViewId viewId = m_deviceId.openObject()->getActiveView(); if( viewId.isNull() ) return; double dScale = 0.9; //wheel DOWN if (e->angleDelta().y() > 0) dScale = 1.0 / dScale; //wheel UP viewId.openObject( OdTv::kForWrite )->zoom( dScale ); m_deviceId.openObject()->update(); e->accept(); } void OdTvQtRenderingWidget::mousePressEvent( QMouseEvent* e ) { //Begin Pan if( m_deviceId.isNull() ) return; if( e->button() != Qt::LeftButton ) return; m_bDoPan = true; m_panPoint = e->pos(); } void OdTvQtRenderingWidget::mouseReleaseEvent( QMouseEvent* e ) { //End Pan m_bDoPan = false; } void OdTvQtRenderingWidget::mouseMoveEvent( QMouseEvent* e ) { //Perform Pan if( !m_bDoPan ) return; OdTvGsViewId viewId = m_deviceId.openObject()->getActiveView(); if( viewId.isNull() ) return; #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) int x = e->x(); int y = e->y(); #else int x = e->position().x(); int y = e->position().y(); #endif OdGeVector3d vec( m_panPoint.x() - x, m_panPoint.y() - y, 0.0 ); //Convert pixels to Eye Coordinate System { OdTvGsViewPtr pView = viewId.openObject( OdTv::kForWrite ); vec.transformBy( ( pView->screenMatrix() * pView->projectionMatrix() ).inverse() ); } viewId.openObject( OdTv::kForWrite )->dolly( vec ); m_panPoint = QPoint( x, y ); m_deviceId.openObject()->update(); } void OdTvQtRenderingWidget::setRenderingDevice( OdTvGsDeviceId id ) { m_deviceId = id; if( m_deviceId.isNull() ) return; //Setup gs OdTvDCRect rect( 0, size().width(), size().height(), 0 ); OdTvGsDevicePtr pDevice = m_deviceId.openObject( OdTv::kForWrite ); pDevice->setupGs( (OSWindowHandle)(winId()), rect, OdTvGsDevice::kOpenGLES2, NULL); pDevice->onSize( rect ); pDevice->update(); }