Go to the documentation of this file.00001 #include <QtGui>
00002 #include <QWidget>
00003 #include <AntTweakBar.h>
00004 #include <wrap/qt/device_to_logical.h>
00005
00006 void TW_CALL CopyCDStringToClient(char **destPtr, const char *src)
00007 {
00008 size_t srcLen = (src!=NULL) ? strlen(src) : 0;
00009 size_t destLen = (*destPtr!=NULL) ? strlen(*destPtr) : 0;
00010
00011
00012 if( *destPtr==NULL )
00013 *destPtr = (char *)malloc(srcLen+1);
00014 else if( srcLen>destLen )
00015 *destPtr = (char *)realloc(*destPtr, srcLen+1);
00016
00017
00018 if( srcLen>0 )
00019 strncpy(*destPtr, src, srcLen);
00020 (*destPtr)[srcLen] = '\0';
00021 }
00022
00023 void TW_CALL CopyStdStringToClient(std::string& destClientString, const std::string& srcLibraryString)
00024 {
00025 destClientString = srcLibraryString;
00026 }
00027
00028 TwMouseButtonID Qt2TwMouseButtonId(QMouseEvent *e)
00029 {
00030 if(e->button() && Qt::LeftButton) return TW_MOUSE_LEFT;
00031 if(e->button() && Qt::MidButton) return TW_MOUSE_MIDDLE;
00032 if(e->button() && Qt::RightButton) return TW_MOUSE_RIGHT;
00033 return TW_MOUSE_LEFT;
00034
00035 }
00036
00037 int TwMousePressQt(QMouseEvent *e)
00038 {
00039 TwMouseMotion(e->x (), e->y ());
00040 return TwMouseButton(TW_MOUSE_PRESSED, Qt2TwMouseButtonId(e));
00041 }
00042
00043 int TwMousePressQt(QWidget *qw, QMouseEvent *e)
00044 {
00045 TwMouseMotion(QTLogicalToDevice(qw, e->x()), QTLogicalToDevice(qw, e->y()));
00046 return TwMouseButton(TW_MOUSE_PRESSED, Qt2TwMouseButtonId(e));
00047 }
00048
00049 int TwMouseReleaseQt(QMouseEvent *e)
00050 {
00051 TwMouseMotion(e->x (), e->y ());
00052 return TwMouseButton(TW_MOUSE_RELEASED, Qt2TwMouseButtonId(e));
00053 }
00054
00055 int TwMouseReleaseQt(QWidget *qw, QMouseEvent *e)
00056 {
00057 TwMouseMotion(QTLogicalToDevice(qw, e->x()), QTLogicalToDevice(qw, e->y()));
00058 return TwMouseButton(TW_MOUSE_RELEASED, Qt2TwMouseButtonId(e));
00059 }
00060
00061 int TwKeyPressQt(QKeyEvent *e)
00062 {
00063 int kmod = 0;
00064 if(e->modifiers() & Qt::ShiftModifier ) kmod |= TW_KMOD_SHIFT;
00065 if(e->modifiers() & Qt::ControlModifier ) kmod |= TW_KMOD_CTRL;
00066 if(e->modifiers() & Qt::AltModifier ) kmod |= TW_KMOD_ALT;
00067 int key = e->key();
00068 int k = 0;
00069
00070 if( key>0 && key<0x7e ) k=key;
00071
00072 if( key>=Qt::Key_F1 && key<=Qt::Key_F15 )
00073 k = TW_KEY_F1 + (key-Qt::Key_F1 );
00074 else
00075 if ( key>=Qt::Key_A && key<=Qt::Key_Z)
00076 k = (kmod & TW_KMOD_SHIFT) ? key : (int)'a' + (key-(int)'A');
00077 else
00078 {
00079 switch( key )
00080 {
00081 case Qt::Key_Left: k = TW_KEY_LEFT; break;
00082 case Qt::Key_Up: k = TW_KEY_UP; break;
00083 case Qt::Key_Right: k = TW_KEY_RIGHT; break;
00084 case Qt::Key_Down: k = TW_KEY_DOWN; break;
00085 case Qt::Key_PageUp: k = TW_KEY_PAGE_UP; break;
00086 case Qt::Key_PageDown: k = TW_KEY_PAGE_DOWN; break;
00087 case Qt::Key_Home: k = TW_KEY_HOME; break;
00088 case Qt::Key_End: k = TW_KEY_END; break;
00089 case Qt::Key_Insert: k = TW_KEY_INSERT; break;
00090 case Qt::Key_Backspace: k = TW_KEY_BACKSPACE; break;
00091 case Qt::Key_Delete: k = TW_KEY_DELETE; break;
00092 case Qt::Key_Return: k = TW_KEY_RETURN; break;
00093 case Qt::Key_Enter: k = TW_KEY_RETURN; break;
00094 case Qt::Key_Escape: k = TW_KEY_ESCAPE; break;
00095 case Qt::Key_Tab: k = TW_KEY_TAB; break;
00096 case Qt::Key_Space: k = TW_KEY_SPACE; break;
00097 }
00098 }
00099
00100 return TwKeyPressed(k, kmod);
00101 }