arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

QtGutzEvent.h

Go to the documentation of this file.
00001 //------------------------------------------------------------------------
00002 //
00003 //   Joe Kniss
00004 //     7-4-02
00005 //                   ________    ____   ___ 
00006 //                  |        \  /    | /  /
00007 //                  +---+     \/     |/  /
00008 //                  +--+|  |\    /|     < 
00009 //                  |  ||  | \  / |  |\  \ 
00010 //                  |      |  \/  |  | \  \ 
00011 //                   \_____|      |__|  \__\
00012 //                       Copyright  2003 
00013 //                      Joe Michael Kniss
00014 //                   <<< jmk@cs.utah.edu >>>
00015 //               "All Your Base are Belong to Us"
00016 //-------------------------------------------------------------------------
00017 
00018 /// QtGutzEvent.h
00019 
00020 #ifndef __QT_GUTZ_EVENT_DOT_H
00021 #define __QT_GUTZ_EVENT_DOT_H
00022 
00023 #include <eventGutz.h>
00024 
00025 ////////////////////////////////////////////////////////////////////////////
00026 /// Mouse Button mapper.
00027 /// Takes a qt button and mapps it to a gutz button
00028 ////////////////////////////////////////////////////////////////////////////
00029 inline
00030 unsigned int qt2GutzButton( QMouseEvent * e )
00031 {
00032    Qt::ButtonState bs = e->button();
00033 
00034    unsigned int b = 0;
00035 
00036    if(bs & Qt::LeftButton)
00037    {
00038       b |= gutz::GUTZ_LEFT_MOUSE;
00039    }
00040    if(bs & Qt::RightButton)
00041    {
00042       b |= gutz::GUTZ_RIGHT_MOUSE;
00043    }
00044    if(bs & Qt::MidButton)
00045    {
00046       b |= gutz::GUTZ_MIDDLE_MOUSE;
00047    }
00048 
00049    return b;
00050 }
00051 
00052 ////////////////////////////////////////////////////////////////////////////
00053 /// Double click mouse button mapper
00054 /// Takes a qt double button and mapps it to a gutz button
00055 ////////////////////////////////////////////////////////////////////////////
00056 inline
00057 unsigned int qt2GutzDblButton( QMouseEvent * e )
00058 {
00059    Qt::ButtonState bs = e->button();
00060 
00061    unsigned int b = 0;
00062 
00063    if(bs & Qt::LeftButton)
00064    {
00065       b |= gutz::GUTZ_DBL_LEFT_MOUSE;
00066    }
00067    if(bs & Qt::RightButton)
00068    {
00069       b |= gutz::GUTZ_DBL_RIGHT_MOUSE;
00070    }
00071    if(bs & Qt::MidButton)
00072    {
00073       b |= gutz::GUTZ_DBL_MIDDLE_MOUSE;
00074    }
00075 
00076    return b;
00077 }
00078 
00079 ////////////////////////////////////////////////////////////////////////////
00080 /// Shift/Alt/Ctrl mapper
00081 /// Takes a qt key modifier and mapps it to a Gutz state modifer
00082 ////////////////////////////////////////////////////////////////////////////
00083 inline 
00084 unsigned int qt2GutzState( QMouseEvent * e )
00085 {
00086    unsigned int out = 0;
00087 
00088    Qt::ButtonState bs = e->state();
00089    if(bs & Qt::ShiftButton)
00090    {
00091       out |= gutz::GUTZ_SHIFT;
00092    }
00093    if(bs & Qt::AltButton)
00094    {
00095       out |= gutz::GUTZ_ALT;
00096    }
00097    if(bs & Qt::ControlButton)
00098    {
00099       out |= gutz::GUTZ_CTRL;
00100    }
00101 
00102    return out;
00103 }
00104 
00105 ////////////////////////////////////////////////////////////////////////////
00106 /// Special Key Mapper
00107 /// Takes a qt special key and mapps it to a Gutz arrow key
00108 ////////////////////////////////////////////////////////////////////////////
00109 inline 
00110 unsigned int qt2GutzSpecialKey( QKeyEvent * e )
00111 {
00112    switch(e->key())
00113    {
00114    case 100:
00115       return gutz::GUTZ_LEFT_ARROW;
00116       break;
00117    case 101:
00118       return gutz::GUTZ_UP_ARROW;
00119       break;
00120    case 102:
00121       return gutz::GUTZ_RIGHT_ARROW;
00122       break;
00123    case 103:
00124       return gutz::GUTZ_DOWN_ARROW;
00125       break;
00126    default:
00127       return 0;
00128    }
00129 
00130 }
00131 
00132 ////////////////////////////////////////////////////////////////////////////
00133 /// Map a Qt mouse event to a gutz mouse event.
00134 /// Takes an optional camera an manipulator
00135 ////////////////////////////////////////////////////////////////////////////
00136 inline 
00137 gutz::MouseEventSP qt2GutzMouse( QMouseEvent *e, 
00138                                  gutz::CameraSP cam   = 0,
00139                                  gutz::ManipSP  manip = 0)
00140 {
00141    gutz::MouseEventSP me = 
00142       new gutz::MouseEvent(gutz::vec3f(e->x(), e->y(),0), true,
00143                            qt2GutzButton(e) | qt2GutzState(e), 
00144                            cam, manip);
00145    return me;
00146 }
00147 
00148 
00149 
00150 
00151 #endif
00152 
00153 

Send questions, comments, and bug reports to:
jmk