00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _SO_QT_DEVICE_
00027 #define _SO_QT_DEVICE_
00028 #include <Inventor/Qt/OivQtCompat.h>
00029 #include <Inventor/SbLinear.h>
00030 #include <Inventor/events/SoEvent.h>
00031
00032 #include <QObject>
00033 # include <QEvent>
00034 #include <QScreen>
00035 #include <QApplication>
00036 #include <QWindow>
00037 #include <Inventor/Qt/SoQtDef.h>
00038 #include <Inventor/Qt/SoQtComponent.h>
00039
00040
00041
00042 #define EventMask int
00043 #ifdef _WIN32
00044 #define ButtonPressMask 0x01
00045 #define ButtonReleaseMask 0x02
00046 #define PointerMotionMask 0x04
00047 #define ButtonMotionMask 0x08
00048 #define KeyPressMask 0x10
00049 #define KeyReleaseMask 0x20
00050 #define EnterWindowMask 0x40
00051 #define LeaveWindowMask 0x80
00052 #elif defined __APPLE__
00053 #define ButtonPressMask 0x01
00054 #define ButtonReleaseMask 0x02
00055 #define PointerMotionMask 0x04
00056 #define ButtonMotionMask 0x08
00057 #define KeyPressMask 0x10
00058 #define KeyReleaseMask 0x20
00059 #define EnterWindowMask 0x40
00060 #define LeaveWindowMask 0x80
00061 #else
00062 #define NoEventMask 0L
00063 #define KeyPressMask (1L<<0)
00064 #define KeyReleaseMask (1L<<1)
00065 #define ButtonPressMask (1L<<2)
00066 #define ButtonReleaseMask (1L<<3)
00067 #define EnterWindowMask (1L<<4)
00068 #define LeaveWindowMask (1L<<5)
00069 #define PointerMotionMask (1L<<6)
00070 #define PointerMotionHintMask (1L<<7)
00071 #define Button1MotionMask (1L<<8)
00072 #define Button2MotionMask (1L<<9)
00073 #define Button3MotionMask (1L<<10)
00074 #define Button4MotionMask (1L<<11)
00075 #define Button5MotionMask (1L<<12)
00076 #define ButtonMotionMask (1L<<13)
00077 #endif
00078
00079 class QEvent;
00080
00103 class SoQtDevice : public QObject{
00104
00105 Q_OBJECT
00106
00107
00108
00109
00110 public:
00116 virtual void enable(QWidget *w, XtEventHandler f, XtPointer data, void* unused=NULL) = 0;
00120 virtual void disable(QWidget *w, XtEventHandler f, XtPointer data) = 0;
00121
00128 virtual const SoEvent * translateEvent(QEvent *event) = 0;
00129
00139 inline void setWindowSize(const SbVec2s &s);
00143 const SbVec2s & getWindowSize() const { return winSize; }
00144
00145 private:
00154 inline void setEventPosition(SoEvent *event, float x, float y) const;
00155
00156
00157
00158 QWidget * deviceWidget;
00159
00160 private:
00161 SbVec2s winSize;
00162
00163 };
00164
00165
00166 void
00167 SoQtDevice::setEventPosition(SoEvent *event, float x, float y) const
00168 {
00169
00170
00171
00172
00173 float ratio = 1.0f;
00174 if ( deviceWidget != NULL )
00175 ratio = deviceWidget->nativeParentWidget()->windowHandle()->devicePixelRatio();
00176
00177 event->setPosition(SbVec2f(ratio*x, (((float)winSize[1]) - 1.f) - ratio*y));
00178 }
00179
00180 void
00181 SoQtDevice::setWindowSize(const SbVec2s &s)
00182 {
00183 winSize = s;
00184 }
00185
00186 #endif
00187
00188
00189