Osgqt supports Touch Screen

Source: Internet
Author: User

1. added the osgqt constructor: setattribute (QT: wa_accepttouchevents); // wyh

2. Event () modification, supports touch time

 

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() << "\t" << "y:" << touchPos.y() << "\t";                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 );}

 

Osgqt supports Touch Screen

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.