[osg-users] osg+QT MODKEY How to

Fabien Lavignotte Fabien.Lavignotte at vegatechnologies.fr
Mon Mar 9 02:14:42 PDT 2009


The osgViewerQt example does not take into account modifier key. So, the
OSG modifier mask is always zero.
I have changed the conversion between Qt event and OSG event to handle
modifier properly.
Here is my code. You can adapt this code in your widget. Let me know if
you need some help.
Fabien
 
/*! Helper function which converts a Qt mouse button code into a osg
mouse button code */
inline void convertMouseEvent( osgGA::EventQueue* eventQueue,
QMouseEvent* eventQt, osgGA::GUIEventAdapter::EventType eventType )
{
eventQueue->getCurrentEventState()->setX( eventQt->x() );
eventQueue->getCurrentEventState()->setY( eventQt->y() );
int button = 0;
switch( eventQt->button() )
{
case Qt::LeftButton : 
button = osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON;
break;
case Qt::MidButton : 
button = osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON;
break;
case Qt::RightButton : 
button = osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON;
break;
}
if ( eventQt->type() == QEvent::MouseButtonPress )
eventQueue->getCurrentEventState()->setButtonMask( button |
eventQueue->getCurrentEventState()->getButtonMask());
else
eventQueue->getCurrentEventState()->setButtonMask( ~button &
eventQueue->getCurrentEventState()->getButtonMask());
unsigned int modKeyMask = 0;
if( eventQt->modifiers() & Qt::ShiftModifier)
{
modKeyMask |= osgGA::GUIEventAdapter::MODKEY_SHIFT;
}
if( eventQt->modifiers() & Qt::ControlModifier)
{
modKeyMask |= osgGA::GUIEventAdapter::MODKEY_CTRL;
}
if( eventQt->modifiers() & Qt::AltModifier)
{
modKeyMask |= osgGA::GUIEventAdapter::MODKEY_ALT;
}
osgGA::GUIEventAdapter* event = eventQueue->createEvent();
event->setEventType(eventType);
event->setTime(eventQueue->getTime());
event->setModKeyMask(modKeyMask);
event->setButton(button);
eventQueue->addEvent(event);
}

/*! overwrites the mouse pressed handler */

void Viewer::mousePressEvent( QMouseEvent* event )
{
	GLWidget::mousePressEvent(event);
	if ( _graphicsWindow.valid() )
	{
		convertMouseEvent( _graphicsWindow->getEventQueue(),
event, osgGA::GUIEventAdapter::PUSH );
	}
}

/*! overwrites the mouse released handler */
void Viewer::mouseReleaseEvent( QMouseEvent* event )
{
	GLWidget::mousePressEvent(event);
	if ( _graphicsWindow.valid() )
	{
		convertMouseEvent( _graphicsWindow->getEventQueue(),
event, osgGA::GUIEventAdapter::RELEASE );
	}
}


________________________________

From: osg-users-bounces at lists.openscenegraph.org
[mailto:osg-users-bounces at lists.openscenegraph.org] On Behalf Of Dieter
Pfeffer
Sent: lundi 9 mars 2009 09:34
To: OpenSceneGraph Users
Subject: Re: [osg-users] osg+QT MODKEY How to


Hi Legeo
 
I had a similar problem - using osg, qt4 and the AdapterWidget example.
 
In AdapterWidget::keypressEvent (...)
osgGA::GUIEventAdapter::KeySymbol) * (event->text().toAscii().data()
returns 0 in the call
_gw->getEventQueue()->keyPress( (... ) )  for keys like:
 
Qt::Key_up ... Have a look at the Qt documentation Qt::Key.
 
I have managed it with:
 
int c = *event->text().toAscii().data();

if ( c == 0)

{

switch (event->key())

{

case Qt::Key_PageDown:

_gw->getEventQueue()->keyPress(
osgGA::GUIEventAdapter::KeySymbol::KEY_Page_Down );

break;

case Qt::Key_PageUp:

_gw->getEventQueue()->keyPress(
osgGA::GUIEventAdapter::KeySymbol::KEY_Page_Up );

break;

case Qt::Key_Up:

_gw->getEventQueue()->keyPress( osgGA::GUIEventAdapter::KEY_Up);

break;

}

}
else
_gw->getEventQueue()->keyPress( (osgGA::GUIEventAdapter::KeySymbol) *
(event->text().toAscii().data() ) );

There might be a better solution but it works.
 
Dieter
 
 
 
 
Unclassified Mail
 

	-----Original Message-----
	From: osg-users-bounces at lists.openscenegraph.org
[mailto:osg-users-bounces at lists.openscenegraph.org]On Behalf Of
legeochen
	Sent: Saturday, 07 March, 2009 09:14
	To: OpenSceneGraph Users
	Subject: [osg-users] osg+QT MODKEY How to
	
	
	Hi all,
	   I'm trying to add a Modkey event handler to my application
with osg and qt4. But it seems that the getModKeyMask() fuction fails to
work. Return value of getModKeyMask() always is 0, even if I have a
MODKEY pressed. And, this is my code:
	        if ( ea.getEventType() == osgGA::GUIEventAdapter::PUSH
&&
	             ea.getButtonMask() ==
osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON &&
	             ea.getModKeyMask() ==
osgGA::GUIEventAdapter::MODKEY_SHIFT )
	         {
	            /*---------------------------------------------
	                    do something here
	            -------------------------------------------------*/
	        }
	How can I handle it? Thanks in advance!
	 
	cheers
	legeo



------------------------------------------------------------------------
------------------------------------
Disclaimer:

If you are not the intended recipient of this email, please notify the
sender and delete it. 
Any unauthorized copying, disclosure or distribution of this email or
its attachment(s) is forbidden. 
Thales Nederland BV will not accept liability for any damage caused by
this email or its attachment(s). 
Thales Nederland BV is seated in Hengelo and is registered at the
Chamber of Commerce under number 06061578.
------------------------------------------------------------------------
------------------------------------



______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________



More information about the osg-users mailing list