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 History 00025 00026 $Log: trackball.h,v $ 00027 00028 ****************************************************************************/ 00029 00030 #ifndef QT_TRACKBALL_H 00031 #define QT_TRACKBALL_H 00032 00034 static vcg::Trackball::Button QT2VCG (Qt::MouseButton qtbt, Qt::KeyboardModifiers modifiers) 00035 { 00036 int vcgbt = vcg::Trackball::BUTTON_NONE; 00037 00038 if (qtbt & Qt::LeftButton) vcgbt |= vcg::Trackball::BUTTON_LEFT; 00039 if (qtbt & Qt::RightButton) vcgbt |= vcg::Trackball::BUTTON_RIGHT; 00040 if (qtbt & Qt::MidButton) vcgbt |= vcg::Trackball::BUTTON_MIDDLE; 00041 00042 if (modifiers & Qt::ShiftModifier) vcgbt |= vcg::Trackball::KEY_SHIFT; 00043 if (modifiers & Qt::ControlModifier) vcgbt |= vcg::Trackball::KEY_CTRL; 00044 if (modifiers & Qt::AltModifier) vcgbt |= vcg::Trackball::KEY_ALT; 00045 00046 return vcg::Trackball::Button (vcgbt); 00047 } 00048 00050 inline vcg::Trackball::Button QTWheel2VCG (Qt::KeyboardModifiers modifiers) 00051 { 00052 int vcgbt = vcg::Trackball::WHEEL; 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 QTKey2VCG (int key, Qt::KeyboardModifiers modifiers) 00063 { 00064 int vcgbt = 0; 00065 switch (key) { 00066 case Qt::Key_W : 00067 case Qt::Key_Up : vcgbt = vcg::Trackball::KEY_UP ; break; 00068 case Qt::Key_A : 00069 case Qt::Key_Left : vcgbt = vcg::Trackball::KEY_LEFT ; break; 00070 case Qt::Key_S : 00071 case Qt::Key_Down : vcgbt = vcg::Trackball::KEY_DOWN ; break; 00072 case Qt::Key_D : 00073 case Qt::Key_Right: vcgbt = vcg::Trackball::KEY_RIGHT; break; 00074 case Qt::Key_R : 00075 case Qt::Key_PageUp: vcgbt = vcg::Trackball::KEY_PGUP ; break; 00076 case Qt::Key_F : 00077 case Qt::Key_PageDown: vcgbt = vcg::Trackball::KEY_PGDOWN; break; 00078 default : vcgbt = 0; 00079 } 00080 00081 if (modifiers & Qt::ShiftModifier) vcgbt |= vcg::Trackball::KEY_SHIFT; 00082 if (modifiers & Qt::ControlModifier) vcgbt |= vcg::Trackball::KEY_CTRL; 00083 if (modifiers & Qt::AltModifier) vcgbt |= vcg::Trackball::KEY_ALT; 00084 00085 return vcg::Trackball::Button (vcgbt); 00086 } 00087 00088 #endif // QT_TRACKBALL_H