1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2006 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
43 #include <QtGui/QMouseEvent>
44 #include <QtGui/QKeyEvent>
45 #include <QtGui/QWheelEvent>
47 #include "OSGConfig.h"
49 #include "OSGCSMQT4GLWidget_qt.h"
50 #include "OSGCSMQT4Window.h"
51 #include "OSGComplexSceneManager.h"
57 Int32
mapModifier(Qt::KeyboardModifiers modifier
)
59 if(0x0000 != (modifier
& Qt::ShiftModifier
))
61 return MouseData::ShiftActive
;
63 else if(0x0000 != (modifier
& Qt::ControlModifier
))
65 return MouseData::CtrlActive
;
67 else if(0x0000 != (modifier
& Qt::AltModifier
))
69 return MouseData::AltActive
;
75 Int32
mapButton(Qt::MouseButton button
)
77 if(0x0000 != (button
& Qt::LeftButton
))
79 return MouseData::LeftButton
;
81 else if(0x0000 != (button
& Qt::RightButton
))
83 return MouseData::RightButton
;
85 #if QT_VERSION <= 0x040700
86 else if(0x0000 != (button
& Qt::MidButton
))
88 return MouseData::MiddleButton
;
91 else if(0x0000 != (button
& Qt::MiddleButton
))
93 return MouseData::MiddleButton
;
101 CSMQT4GLWidget::CSMQT4GLWidget( QWidget
*pParent
,
102 const Char8
*szName
,
103 const QGLWidget
*pShareWidget
,
104 Qt::WindowFlags f
) :
113 CSMQT4GLWidget::CSMQT4GLWidget( GLContext
*pContext
,
115 const QGLWidget
*pShareWidget
,
116 Qt::WindowFlags f
) :
125 CSMQT4GLWidget::CSMQT4GLWidget(const QGLFormat
&oFormat
,
127 const Char8
*szName
,
128 const QGLWidget
*pShareWidget
,
129 Qt::WindowFlags f
) :
139 CSMQT4GLWidget::~CSMQT4GLWidget(void)
144 void CSMQT4GLWidget::setQT4Window(CSMQT4Window
*pWindow
)
146 _pOSGWindow
= pWindow
;
149 void CSMQT4GLWidget::resizeEvent(QResizeEvent
*)
151 if(_pOSGWindow
!= NULL
)
153 _pOSGWindow
->reshape(width(), height());
157 void CSMQT4GLWidget::mousePressEvent(QMouseEvent
*pEvent
)
159 if(_pOSGWindow
!= NULL
)
161 _pOSGWindow
->mouse(mapButton(pEvent
->button()),
162 MouseData::ButtonDown
,
163 mapModifier(pEvent
->modifiers()),
169 void CSMQT4GLWidget::mouseReleaseEvent(QMouseEvent
*pEvent
)
171 if(_pOSGWindow
!= NULL
)
173 _pOSGWindow
->mouse(mapButton(pEvent
->button()),
175 mapModifier(pEvent
->modifiers()),
181 void CSMQT4GLWidget::mouseMoveEvent(QMouseEvent
*pEvent
)
183 if(_pOSGWindow
!= NULL
)
185 _pOSGWindow
->motion(pEvent
->x(),
187 mapModifier(pEvent
->modifiers()));
191 void CSMQT4GLWidget::wheelEvent(QWheelEvent
*pEvent
)
193 if(_pOSGWindow
!= NULL
)
195 if(pEvent
->delta() < 0)
197 _pOSGWindow
->mouse(MouseData::WheelUpButton
,
198 MouseData::ButtonDown
,
199 mapModifier(pEvent
->modifiers()),
205 _pOSGWindow
->mouse(MouseData::WheelDownButton
,
206 MouseData::ButtonDown
,
207 mapModifier(pEvent
->modifiers()),
214 void CSMQT4GLWidget::keyPressEvent(QKeyEvent
*pEvent
)
216 if(pEvent
->key() == Qt::Key_Escape
)
218 if(_pOSGWindow
!= NULL
)
220 _pOSGWindow
->_bRun
= false;
225 std::string szKey
= pEvent
->text().toStdString();
227 if(szKey
.empty() == false)
229 ComplexSceneManager::the()->key(0,
231 CSMKeyData::ButtonDown
,
237 void CSMQT4GLWidget::keyReleaseEvent(QKeyEvent
*pEvent
)
239 std::string szKey
= pEvent
->text().toStdString();
241 if(szKey
.empty() == false)
243 ComplexSceneManager::the()->key(0,
245 CSMKeyData::ButtonUp
,