fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / Contrib / ComplexSceneManagerQt / OSGCSMQT4GLWidget_qt.cpp
blob8b1b78e43d7ae8a6217db3f38b328527ae60a1df
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2006 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
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. *
18 * *
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. *
23 * *
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. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
40 // Includes
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"
53 OSG_BEGIN_NAMESPACE
55 namespace
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;
72 return 0x0001;
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;
90 #else
91 else if(0x0000 != (button & Qt::MiddleButton))
93 return MouseData::MiddleButton;
95 #endif
97 return 0x0001;
101 CSMQT4GLWidget::CSMQT4GLWidget( QWidget *pParent ,
102 const Char8 *szName ,
103 const QGLWidget *pShareWidget,
104 Qt::WindowFlags f ) :
105 Inherited (pParent,
106 szName,
107 pShareWidget,
108 f ),
109 _pOSGWindow(NULL )
113 CSMQT4GLWidget::CSMQT4GLWidget( GLContext *pContext ,
114 QWidget *pParent ,
115 const QGLWidget *pShareWidget,
116 Qt::WindowFlags f ) :
117 Inherited (pContext,
118 pParent,
119 pShareWidget,
120 f ),
121 _pOSGWindow(NULL )
125 CSMQT4GLWidget::CSMQT4GLWidget(const QGLFormat &oFormat ,
126 QWidget *pParent ,
127 const Char8 *szName ,
128 const QGLWidget *pShareWidget,
129 Qt::WindowFlags f ) :
130 Inherited (oFormat,
131 pParent,
132 szName,
133 pShareWidget,
134 f ),
135 _pOSGWindow(NULL )
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()),
164 pEvent->x(),
165 pEvent->y());
169 void CSMQT4GLWidget::mouseReleaseEvent(QMouseEvent *pEvent)
171 if(_pOSGWindow != NULL)
173 _pOSGWindow->mouse(mapButton(pEvent->button()),
174 MouseData::ButtonUp,
175 mapModifier(pEvent->modifiers()),
176 pEvent->x(),
177 pEvent->y());
181 void CSMQT4GLWidget::mouseMoveEvent(QMouseEvent *pEvent)
183 if(_pOSGWindow != NULL)
185 _pOSGWindow->motion(pEvent->x(),
186 pEvent->y(),
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()),
200 pEvent->x(),
201 pEvent->y());
203 else
205 _pOSGWindow->mouse(MouseData::WheelDownButton,
206 MouseData::ButtonDown,
207 mapModifier(pEvent->modifiers()),
208 pEvent->x(),
209 pEvent->y());
214 void CSMQT4GLWidget::keyPressEvent(QKeyEvent *pEvent)
216 if(pEvent->key() == Qt::Key_Escape)
218 if(_pOSGWindow != NULL)
220 _pOSGWindow->_bRun = false;
223 else
225 std::string szKey = pEvent->text().toStdString();
227 if(szKey.empty() == false)
229 ComplexSceneManager::the()->key(0,
231 CSMKeyData::ButtonDown,
232 szKey[0] );
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,
246 szKey[0] );
250 OSG_END_NAMESPACE