Commit 281fca87 authored by vmartinet@IRCAD.FR's avatar vmartinet@IRCAD.FR
Browse files

Added support for keyboard events in scene2D

--HG--
branch : fw4spl_0.7.7
parent c9d6b32c
......@@ -31,6 +31,10 @@ public :
/// Events
SCENE2D_API void keyPressEvent(QKeyEvent* _event);
SCENE2D_API void keyReleaseEvent(QKeyEvent* _event);
SCENE2D_API void resizeEvent(QResizeEvent *_event);
SCENE2D_API void mouseReleaseEvent ( QMouseEvent * _event );
......@@ -57,7 +61,7 @@ protected :
WPTR(::scene2D::Render) m_scene2DRender;
::scene2D::data::Event::Button getScene2DButtonFromEvent( QMouseEvent* _event );
::scene2D::data::Event::Modifier getScene2DModifierFromEvent( QMouseEvent* _event );
::scene2D::data::Event::Modifier getScene2DModifierFromEvent( QInputEvent* _event );
void paintEvent ( QPaintEvent * event );
......
......@@ -12,6 +12,8 @@
#include <fwData/Object.hpp>
#include <Qt>
#include "scene2D/config.hpp"
#include "scene2D/data/Coord.hpp"
#include "scene2D/data/Size.hpp"
......@@ -37,7 +39,9 @@ public:
MouseButtonRelease,
MouseMove,
MouseWheelUp,
MouseWheelDown
MouseWheelDown,
KeyPress,
KeyRelease
} Type;
typedef enum
......@@ -67,6 +71,7 @@ public:
fwGettersSettersDocMacro(Button, button, Button, no comment);
fwGettersSettersDocMacro(Accepted, accepted, bool, no comment);
fwGettersSettersDocMacro(Modifier, modifier, Modifier, no comment);
fwGettersSettersDocMacro(Key, key, int, no comment);
private:
......@@ -77,6 +82,7 @@ private:
Size m_size;
Size m_oldSize;
bool m_accepted;
int m_key;
};
......
......@@ -52,6 +52,32 @@ void Scene2DGraphicsView::setSceneRender( SPTR(::scene2D::Render) sceneRender )
//-----------------------------------------------------------------------------
void Scene2DGraphicsView::keyPressEvent(QKeyEvent* _event)
{
::scene2D::data::Event::NewSptr sceneEvent;
sceneEvent->setType( ::scene2D::data::Event::KeyPress);
sceneEvent->setButton( ::scene2D::data::Event::NoButton);
sceneEvent->setModifier( this->getScene2DModifierFromEvent( _event) );
sceneEvent->setKey(_event->key());
m_scene2DRender.lock()->dispatchInteraction( sceneEvent );
}
//-----------------------------------------------------------------------------
void Scene2DGraphicsView::keyReleaseEvent(QKeyEvent* _event)
{
::scene2D::data::Event::NewSptr sceneEvent;
sceneEvent->setType( ::scene2D::data::Event::KeyRelease);
sceneEvent->setButton( ::scene2D::data::Event::NoButton);
sceneEvent->setModifier( this->getScene2DModifierFromEvent( _event) );
sceneEvent->setKey(_event->key());
m_scene2DRender.lock()->dispatchInteraction( sceneEvent );
}
//-----------------------------------------------------------------------------
void Scene2DGraphicsView::resizeEvent(QResizeEvent *_event)
{
this->updateFromViewport();
......@@ -85,7 +111,7 @@ void Scene2DGraphicsView::mousePressEvent ( QMouseEvent * _event )
//-----------------------------------------------------------------------------
::scene2D::data::Event::Modifier Scene2DGraphicsView::getScene2DModifierFromEvent( QMouseEvent* _event )
::scene2D::data::Event::Modifier Scene2DGraphicsView::getScene2DModifierFromEvent( QInputEvent* _event )
{
::scene2D::data::Event::Modifier modifier;
......
......@@ -24,6 +24,7 @@ Event::Event() throw()
: m_type(NoType),
m_button(NoButton),
m_modifier(NoModifier),
m_key(Qt::Key_unknown),
m_accepted(false)
{}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment