00001 #ifndef QEventToSoEvent_h
00002 #define QEventToSoEvent_h
00003
00004 #include <QWidget>
00005 #include <QMouseEvent>
00006 #include <QWheelEvent>
00007 #include <QKeyEvent>
00008 #include <QTouchEvent>
00009
00010 #include <Inventor/ViewerComponents/SoEventBuilder.h>
00011 #include <Inventor/Qt/SbQtHelper.h>
00012
00016 class QTVIEWERCOMPONENTS_API QEventToSoEvent {
00017 public:
00018
00019 static SoMouseButtonEvent* getMousePressEvent(QMouseEvent* qevent, QWidget* wsource)
00020 {
00021 const float ratio = SbQtHelper::getDevicePixelRatio(wsource);
00022 return m_ivEvent.getMousePressEvent(qevent->x()*ratio, ((wsource->height()-1)-qevent->y())*ratio,
00023 getButtonId(qevent),
00024 qevent->modifiers() & Qt::AltModifier,
00025 qevent->modifiers() & Qt::ControlModifier,
00026 qevent->modifiers() & Qt::ShiftModifier);
00027 }
00028
00029 static SoMouseButtonEvent* getMouseReleaseEvent(QMouseEvent* qevent, QWidget* wsource)
00030 {
00031 const float ratio = SbQtHelper::getDevicePixelRatio(wsource);
00032 return m_ivEvent.getMouseReleaseEvent(qevent->x()*ratio, ((wsource->height()-1)-qevent->y())*ratio,
00033 getButtonId(qevent),
00034 qevent->modifiers() & Qt::AltModifier,
00035 qevent->modifiers() & Qt::ControlModifier,
00036 qevent->modifiers() & Qt::ShiftModifier);
00037 }
00038
00039 static SoMouseButtonEvent* getMouseDoubleClickEvent(QMouseEvent* qevent, QWidget* wsource)
00040 {
00041 const float ratio = SbQtHelper::getDevicePixelRatio(wsource);
00042 return m_ivEvent.getMouseDoubleClickEvent(qevent->x()*ratio, ((wsource->height()-1)-qevent->y())*ratio,
00043 getButtonId(qevent),
00044 qevent->modifiers() & Qt::AltModifier,
00045 qevent->modifiers() & Qt::ControlModifier,
00046 qevent->modifiers() & Qt::ShiftModifier);
00047 }
00048
00049 static SoMouseWheelEvent* getMouseWheelEvent(QWheelEvent * qevent, QWidget* )
00050 {
00051 return m_ivEvent.getMouseWheelEvent(qevent->delta(),
00052 qevent->modifiers() & Qt::AltModifier,
00053 qevent->modifiers() & Qt::ControlModifier,
00054 qevent->modifiers() & Qt::ShiftModifier);
00055 }
00056
00057 static SoLocation2Event* getMouseMoveEvent( QMouseEvent* qevent, QWidget* wsource )
00058 {
00059 const float ratio = SbQtHelper::getDevicePixelRatio(wsource);
00060 return m_ivEvent.getMouseMoveEvent(qevent->x()*ratio, ((wsource->height()-1)-qevent->y())*ratio,
00061 qevent->modifiers() & Qt::AltModifier,
00062 qevent->modifiers() & Qt::ControlModifier,
00063 qevent->modifiers() & Qt::ShiftModifier);
00064 }
00065
00066 static SoLocation2Event* getMouseEnterEvent( QEvent* , QWidget* )
00067 {
00068 return m_ivEvent.getMouseEnterEvent(0, 0,
00069 false,
00070 false,
00071 false);
00072 }
00073
00074 static SoLocation2Event* getMouseLeaveEvent( QEvent* , QWidget* )
00075 {
00076 return m_ivEvent.getMouseLeaveEvent(0, 0,
00077 false,
00078 false,
00079 false);
00080 }
00081
00082 static SoKeyboardEvent* getKeyPressEvent( QKeyEvent *qevent, QWidget* )
00083 {
00084 SoKeyboardEvent::Key ivKey = getIvKey(qevent);
00085 return m_ivEvent.getKeyPressEvent(ivKey,
00086 qevent->modifiers() & Qt::AltModifier,
00087 qevent->modifiers() & Qt::ControlModifier,
00088 qevent->modifiers() & Qt::ShiftModifier);
00089 }
00090
00091 static SoKeyboardEvent* getKeyReleaseEvent( QKeyEvent *qevent, QWidget* )
00092 {
00093 SoKeyboardEvent::Key ivKey = getIvKey(qevent);
00094 return m_ivEvent.getKeyReleaseEvent(ivKey,
00095 qevent->modifiers() & Qt::AltModifier,
00096 qevent->modifiers() & Qt::ControlModifier,
00097 qevent->modifiers() & Qt::ShiftModifier);
00098 }
00099
00100 const std::vector<const SoEvent*>& getTouchEvents(QTouchEvent *qevent, QWidget* wsource );
00101
00102 private:
00103 static bool initClass();
00104 static bool s_init;
00105 static SoMouseButtonEvent::Button getButtonId(QMouseEvent* qevent);
00106 static SoKeyboardEvent::Key getIvKey(QKeyEvent *qevent);
00107 static SoEventBuilder m_ivEvent;
00108 std::vector<const SoEvent*> m_soeventlist;
00109
00110
00111 static SoKeyboardEvent::Key keyMap[256];
00112 static SoKeyboardEvent::Key keyMap2[97];
00113 static int keyMapInitFlag;
00114
00115 };
00116
00117 #endif // QEventToSoEvent
00118