• osgQt支持触摸屏


    1. osgQt的构造函数添加:setAttribute(Qt::WA_AcceptTouchEvents);//wyh

    2. event()修改,支持触摸时间

    bool GLWidget::event( QEvent* event )
    {
    
        // QEvent::Hide
        //
        // workaround "Qt-workaround" that does glFinish before hiding the widget
        // (the Qt workaround was seen at least in Qt 4.6.3 and 4.7.0)
        //
        // Qt makes the context current, performs glFinish, and releases the context.
        // This makes the problem in OSG multithreaded environment as the context
        // is active in another thread, thus it can not be made current for the purpose
        // of glFinish in this thread.
    
        // QEvent::ParentChange
        //
        // Reparenting GLWidget may create a new underlying window and a new GL context.
        // Qt will then call doneCurrent on the GL context about to be deleted. The thread
        // where old GL context was current has no longer current context to render to and
        // we cannot make new GL context current in this thread.
    
        // We workaround above problems by deferring execution of problematic event requests.
        // These events has to be enqueue and executed later in a main GUI thread (GUI operations
        // outside the main thread are not allowed) just before makeCurrent is called from the
        // right thread. The good place for doing that is right after swap in a swapBuffersImplementation.
    
        if (event->type() == QEvent::Hide)
        {
            // enqueue only the last of QEvent::Hide and QEvent::Show
            enqueueDeferredEvent(QEvent::Hide, QEvent::Show);
            return true;
        }
        else if (event->type() == QEvent::Show)
        {
            // enqueue only the last of QEvent::Show or QEvent::Hide
            enqueueDeferredEvent(QEvent::Show, QEvent::Hide);
            return true;
        }
        else if (event->type() == QEvent::ParentChange)
        {
            // enqueue only the last QEvent::ParentChange
            enqueueDeferredEvent(QEvent::ParentChange);
            return true;
        }
        //wyh
        else if(event->type() == QEvent::TouchBegin ||event->type() == QEvent::TouchUpdate || event->type() == QEvent::TouchEnd)
        {
            QList<QTouchEvent::TouchPoint> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints();
            if(touchPoints.count() >= 2)
            {
                //test
                //std::cout << "touch multiViewer" << std::endl;    
                //std::cout << std::endl;
    
                osg::ref_ptr<osgGA::GUIEventAdapter> osg_event(NULL);
                foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints)
                {
                    QPointF touchPos = touchPoint.pos();
    
                    ////test
                    //std::cout << "x:" << touchPos.x() << "	" << "y:" << touchPos.y() << "	";
    
                    if(touchPoint.state() == Qt::TouchPointPressed)
                    {
                        if (!osg_event) {
                            osg_event =  _gw->getEventQueue()->touchBegan( touchPoint.id(), osgGA::GUIEventAdapter::TOUCH_BEGAN, touchPos.x()  , touchPos.y());
                        } else {
                            osg_event->addTouchPoint( touchPoint.id(), osgGA::GUIEventAdapter::TOUCH_BEGAN, touchPos.x() , touchPos.y());
                        }
                    }
                    else if(touchPoint.state() == Qt::TouchPointMoved)
                    {
                        if (!osg_event) {
                            osg_event =  _gw->getEventQueue()->touchMoved( touchPoint.id(), osgGA::GUIEventAdapter::TOUCH_MOVED, touchPos.x(), touchPos.y());
                        } else {
                            osg_event->addTouchPoint( touchPoint.id(), osgGA::GUIEventAdapter::TOUCH_MOVED, touchPos.x() , touchPos.y());
                        }
                    }
                    else if(touchPoint.state() == Qt::TouchPointReleased)
                    {
                        // No double tap detection with RAW TOUCH Events, sorry.
                        if (!osg_event) {
                            osg_event =  _gw->getEventQueue()->touchEnded( touchPoint.id(), osgGA::GUIEventAdapter::TOUCH_ENDED, touchPos.x(), touchPos.y(), 1);
                        } else {
                            osg_event->addTouchPoint( touchPoint.id(), osgGA::GUIEventAdapter::TOUCH_ENDED, touchPos.x() , touchPos.y());
                        }
                    }
                }
                return true;
            }
    
        }
    
        // perform regular event handling
        return QGLWidget::event( event );
    }
  • 相关阅读:
    R语言从基础入门到高级
    Web前端工程师职业学习路线图,分享!
    IOS中nil/Nil/NULL的区别
    Core Animation系列之CADisplayLink
    CADisplayLink 及定时器的使用
    iOS定时器NSTimer的使用方法
    IOS中定时器NSTimer的开启与关闭
    【IOS基础知识】NSTimer定时器使用
    IOS 实现自定义的导航栏背景以及自定义颜色的状态栏(支持7.0以及低版本)
    iOS7中计算UILabel中字符串的高度
  • 原文地址:https://www.cnblogs.com/yanhuiw/p/4008138.html
Copyright © 2020-2023  润新知