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
00105 class SoQtDevice : public QObject{
00106
00107 Q_OBJECT
00108
00109
00110
00111
00112 public:
00118 virtual void enable(QWidget *w, XtEventHandler f, XtPointer data, void* unused=NULL) = 0;
00122 virtual void disable(QWidget *w, XtEventHandler f, XtPointer data) = 0;
00123
00130 virtual const SoEvent * translateEvent(QEvent *event) = 0;
00131
00141 inline void setWindowSize(const SbVec2s &s);
00145 const SbVec2s & getWindowSize() const { return winSize; }
00146
00147 private:
00156 inline void setEventPosition(SoEvent *event, float x, float y) const;
00157
00158
00159
00160 QWidget * deviceWidget;
00161
00162 private:
00163 SbVec2s winSize;
00164
00165 };
00166
00167
00168 void
00169 SoQtDevice::setEventPosition(SoEvent *event, float x, float y) const
00170 {
00171
00172
00173
00174
00175 float ratio = 1.0f;
00176 if ( deviceWidget != NULL )
00177 ratio = deviceWidget->nativeParentWidget()->windowHandle()->devicePixelRatio();
00178
00179 event->setPosition(SbVec2f(ratio*x, (((float)winSize[1]) - 1.f) - ratio*y));
00180 }
00181
00182 void
00183 SoQtDevice::setWindowSize(const SbVec2s &s)
00184 {
00185 winSize = s;
00186 }
00187
00188 #endif
00189
00190
00191