00001 #pragma once
00002
00003 #include <QKeyEvent>
00004 #include <QMouseEvent>
00005 #include <QTouchEvent>
00006 #include <QWheelEvent>
00007
00008 #include <Inventor/ViewerComponents/SoEventBuilder.h>
00009
00013 class QTVIEWERCOMPONENTS_API QtEventToSoEvent
00014 {
00015 public:
00021 static SoMouseButtonEvent*
00022 getMousePressEvent( QMouseEvent* qevent, QPoint eventPosition )
00023 {
00024 return m_ivEvent.getMousePressEvent( eventPosition.x(),
00025 eventPosition.y(),
00026 getButtonId( qevent ),
00027 qevent->modifiers() & Qt::AltModifier,
00028 qevent->modifiers() & Qt::ControlModifier,
00029 qevent->modifiers() & Qt::ShiftModifier );
00030 }
00031
00037 static SoMouseButtonEvent*
00038 getMouseReleaseEvent( QMouseEvent* qevent, QPoint eventPosition )
00039 {
00040 return m_ivEvent.getMouseReleaseEvent( eventPosition.x(),
00041 eventPosition.y(),
00042 getButtonId( qevent ),
00043 qevent->modifiers() & Qt::AltModifier,
00044 qevent->modifiers() & Qt::ControlModifier,
00045 qevent->modifiers() & Qt::ShiftModifier );
00046 }
00047
00053 static SoMouseButtonEvent*
00054 getMouseDoubleClickEvent( QMouseEvent* qevent, QPoint eventPosition )
00055 {
00056 return m_ivEvent.getMouseDoubleClickEvent( eventPosition.x(),
00057 eventPosition.y(),
00058 getButtonId( qevent ),
00059 qevent->modifiers() & Qt::AltModifier,
00060 qevent->modifiers() & Qt::ControlModifier,
00061 qevent->modifiers() & Qt::ShiftModifier );
00062 }
00063
00068 static SoMouseWheelEvent*
00069 getMouseWheelEvent( QWheelEvent* qevent )
00070 {
00071 return m_ivEvent.getMouseWheelEvent( qevent->angleDelta().y(),
00072 qevent->modifiers() & Qt::AltModifier,
00073 qevent->modifiers() & Qt::ControlModifier,
00074 qevent->modifiers() & Qt::ShiftModifier );
00075 }
00076
00082 static SoLocation2Event*
00083 getMouseMoveEvent( QMouseEvent* qevent, QPoint eventPosition )
00084 {
00085 return m_ivEvent.getMouseMoveEvent( eventPosition.x(),
00086 eventPosition.y(),
00087 qevent->modifiers() & Qt::AltModifier,
00088 qevent->modifiers() & Qt::ControlModifier,
00089 qevent->modifiers() & Qt::ShiftModifier );
00090 }
00091
00095 static SoLocation2Event*
00096 getMouseEnterEvent()
00097 {
00098 return m_ivEvent.getMouseEnterEvent( 0, 0, false, false, false );
00099 }
00100
00104 static SoLocation2Event*
00105 getMouseLeaveEvent()
00106 {
00107 return m_ivEvent.getMouseLeaveEvent( 0, 0, false, false, false );
00108 }
00109
00115 static SoLocation2Event*
00116 getHoverMouseEvent( QHoverEvent* qevent, QPoint eventPosition )
00117 {
00118 return m_ivEvent.getMouseMoveEvent( eventPosition.x(),
00119 eventPosition.y(),
00120 qevent->modifiers() & Qt::AltModifier,
00121 qevent->modifiers() & Qt::ControlModifier,
00122 qevent->modifiers() & Qt::ShiftModifier );
00123 }
00124
00129 static SoKeyboardEvent*
00130 getKeyPressEvent( QKeyEvent* qevent )
00131 {
00132 SoKeyboardEvent::Key ivKey = getIvKey( qevent );
00133 return m_ivEvent.getKeyPressEvent( ivKey,
00134 qevent->modifiers() & Qt::AltModifier,
00135 qevent->modifiers() & Qt::ControlModifier,
00136 qevent->modifiers() & Qt::ShiftModifier );
00137 }
00138
00143 static SoKeyboardEvent*
00144 getKeyReleaseEvent( QKeyEvent* qevent )
00145 {
00146 SoKeyboardEvent::Key ivKey = getIvKey( qevent );
00147 return m_ivEvent.getKeyReleaseEvent( ivKey,
00148 qevent->modifiers() & Qt::AltModifier,
00149 qevent->modifiers() & Qt::ControlModifier,
00150 qevent->modifiers() & Qt::ShiftModifier );
00151 }
00152
00158 const std::vector<const SoEvent*>& getTouchEvents( QTouchEvent* qevent, int height );
00159
00160 private:
00161
00166 static SoMouseButtonEvent::Button getButtonId( QMouseEvent* qevent );
00167
00171 static SoEventBuilder m_ivEvent;
00172
00173 private:
00174 static bool initClass();
00175 static bool s_init;
00176
00177 static SoKeyboardEvent::Key getIvKey( QKeyEvent* qevent );
00178
00179 std::vector<const SoEvent*> m_soeventlist;
00180
00181
00182 static SoKeyboardEvent::Key keyMap[256];
00183 static SoKeyboardEvent::Key keyMap2[97];
00184 static int keyMapInitFlag;
00185 };
00186