00001 /**************************************************************************** 00002 * VCGLib o o * 00003 * Visual and Computer Graphics Library o o * 00004 * _ O _ * 00005 * Copyright(C) 2007 \/)\/ * 00006 * Visual Computing Lab /\/| * 00007 * ISTI - Italian National Research Council | * 00008 * \ * 00009 * All rights reserved. * 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 * This program is distributed in the hope that it will be useful, * 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * 00020 * for more details. * 00021 * * 00022 ****************************************************************************/ 00023 00024 #ifndef QT_TRACKBALL_H 00025 #define QT_TRACKBALL_H 00026 #include <wrap/qt/device_to_logical.h> 00027 00031 inline float QT2VCG_X( QWidget *qw, QMouseEvent *e) 00032 { 00033 return QTLogicalToDevice(qw,e->x()); 00034 } 00035 00039 00040 inline float QT2VCG_Y( QWidget *qw, QMouseEvent *e) 00041 { 00042 return QTLogicalToDevice(qw,qw->height () - e->y ()); 00043 } 00044 00046 inline vcg::Trackball::Button QT2VCG (Qt::MouseButton qtbt, Qt::KeyboardModifiers modifiers) 00047 { 00048 int vcgbt = vcg::Trackball::BUTTON_NONE; 00049 00050 if (qtbt & Qt::LeftButton) vcgbt |= vcg::Trackball::BUTTON_LEFT; 00051 if (qtbt & Qt::RightButton) vcgbt |= vcg::Trackball::BUTTON_RIGHT; 00052 if (qtbt & Qt::MidButton) vcgbt |= vcg::Trackball::BUTTON_MIDDLE; 00053 00054 if (modifiers & Qt::ShiftModifier) vcgbt |= vcg::Trackball::KEY_SHIFT; 00055 if (modifiers & Qt::ControlModifier) vcgbt |= vcg::Trackball::KEY_CTRL; 00056 if (modifiers & Qt::AltModifier) vcgbt |= vcg::Trackball::KEY_ALT; 00057 00058 return vcg::Trackball::Button (vcgbt); 00059 } 00060 00062 inline vcg::Trackball::Button QTWheel2VCG (Qt::KeyboardModifiers modifiers) 00063 { 00064 int vcgbt = vcg::Trackball::WHEEL; 00065 00066 if (modifiers & Qt::ShiftModifier) vcgbt |= vcg::Trackball::KEY_SHIFT; 00067 if (modifiers & Qt::ControlModifier) vcgbt |= vcg::Trackball::KEY_CTRL; 00068 if (modifiers & Qt::AltModifier) vcgbt |= vcg::Trackball::KEY_ALT; 00069 00070 return vcg::Trackball::Button (vcgbt); 00071 } 00072 00074 inline vcg::Trackball::Button QTKey2VCG (int key, Qt::KeyboardModifiers modifiers) 00075 { 00076 int vcgbt = 0; 00077 switch (key) { 00078 case Qt::Key_W : 00079 case Qt::Key_Up : vcgbt = vcg::Trackball::KEY_UP ; break; 00080 case Qt::Key_A : 00081 case Qt::Key_Left : vcgbt = vcg::Trackball::KEY_LEFT ; break; 00082 case Qt::Key_S : 00083 case Qt::Key_Down : vcgbt = vcg::Trackball::KEY_DOWN ; break; 00084 case Qt::Key_D : 00085 case Qt::Key_Right: vcgbt = vcg::Trackball::KEY_RIGHT; break; 00086 case Qt::Key_R : 00087 case Qt::Key_PageUp: vcgbt = vcg::Trackball::KEY_PGUP ; break; 00088 case Qt::Key_F : 00089 case Qt::Key_PageDown: vcgbt = vcg::Trackball::KEY_PGDOWN; break; 00090 default : vcgbt = 0; 00091 } 00092 00093 if (modifiers & Qt::ShiftModifier) vcgbt |= vcg::Trackball::KEY_SHIFT; 00094 if (modifiers & Qt::ControlModifier) vcgbt |= vcg::Trackball::KEY_CTRL; 00095 if (modifiers & Qt::AltModifier) vcgbt |= vcg::Trackball::KEY_ALT; 00096 00097 return vcg::Trackball::Button (vcgbt); 00098 } 00099 00100 #endif // QT_TRACKBALL_H