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 //---------------------------------------------------------------------------
47 # include <QtWidgets/QApplication>
48 # include <QtWidgets/QDesktopWidget>
50 # include <QtGui/QApplication>
51 # include <QtGui/QDesktopWidget>
54 #include "OSGConfig.h"
56 #include "OSGCSMQT4Window.h"
57 #include "OSGCSMQT4GLWidget_qt.h"
58 #include "OSGQT4Window.h"
59 #include "OSGComplexSceneManager.h"
63 // Documentation for this class is emitted in the
64 // OSGCSMQT4WindowBase.cpp file.
65 // To modify it, please change the .fcd file (OSGCSMQT4Window.fcd) and
66 // regenerate the base file.
68 /***************************************************************************\
70 \***************************************************************************/
72 bool CSMQT4Window::_bRun
= false;
73 QApplication
*CSMQT4Window::_pApp
= NULL
;
75 /***************************************************************************\
77 \***************************************************************************/
79 void CSMQT4Window::initMethod(InitPhase ePhase
)
81 Inherited::initMethod(ePhase
);
83 if(ePhase
== TypeObject::SystemPost
)
88 /***************************************************************************\
90 \***************************************************************************/
92 /*-------------------------------------------------------------------------*\
94 \*-------------------------------------------------------------------------*/
96 /*----------------------- constructors & destructors ----------------------*/
98 CSMQT4Window::CSMQT4Window(void) :
104 CSMQT4Window::CSMQT4Window(const CSMQT4Window
&source
) :
110 CSMQT4Window::~CSMQT4Window(void)
114 void CSMQT4Window::resolveLinks(void)
116 Inherited::resolveLinks();
119 void CSMQT4Window::terminateGLContext(void)
123 _pWindow
->terminate();
126 if(_pQTWidget
!= NULL
)
134 /*----------------------------- class specific ----------------------------*/
136 void CSMQT4Window::changed(ConstFieldMaskArg whichField
,
140 Inherited::changed(whichField
, origin
, details
);
143 void CSMQT4Window::dump( UInt32
,
144 const BitVector
) const
146 SLOG
<< "Dump CSMQT4Window NI" << std::endl
;
149 void CSMQT4Window::initQtApp(void)
153 QApplication::setColorSpec(QApplication::CustomColor
);
155 static const Char8
*appName
= "testCSM";
156 static const Char8
*dispParam
= "-display";
158 std::vector
<const Char8
*> vArgs
;
160 vArgs
.push_back(appName
);
163 if(this->getPrimaryDisplayString().empty() == false)
165 vArgs
.push_back(dispParam
);
166 vArgs
.push_back(this->getPrimaryDisplayString().c_str());
170 static Int32 argc
= vArgs
.size();
171 static const Char8
**argv
= &(vArgs
[0]);
173 _pApp
= new QApplication(argc
, const_cast<Char8
**>(argv
));
177 bool CSMQT4Window::init(void)
187 const QRect screenGeometry
= QApplication::desktop()->screenGeometry();
189 if(this->getXPos() > 0.f
&& this->getYPos() > 0.f
)
191 iXPos
= Int32(this->getXPos());
192 iYPos
= Int32(this->getYPos());
195 if(this->getXSize() >= 1.f
)
197 uiWidth
= UInt32(this->getXSize());
199 else if(this->getXSize() <= 0.f
)
201 uiWidth
= screenGeometry
.width();
205 uiWidth
= UInt32(Real32(screenGeometry
.width()) *
209 if(this->getYSize() >= 1.f
)
211 uiHeight
= UInt32(this->getYSize());
213 else if(this->getYSize() <= 0.f
)
215 uiHeight
= screenGeometry
.height();
219 uiHeight
= UInt32(Real32(screenGeometry
.height()) *
225 QT4WindowUnrecPtr pQT4Window
= QT4Window::create();
227 pQT4Window
->setPrivateOSGContext(this->getPrivateContext());
231 new OSGQGLWidget::GLContext(QGLFormat::defaultFormat()),
236 _pQTWidget
->setQT4Window(this);
238 if(this->getDecorEnabled() == false)
240 _pQTWidget
->setWindowFlags(Qt::FramelessWindowHint
);
244 _pQTWidget
->setGeometry(iXPos
, iYPos
, uiWidth
, uiHeight
);
246 pQT4Window
->setGlWidget(_pQTWidget
);
248 _pApp
->processEvents();
251 pQT4Window
->resize(uiWidth
,
254 if(ComplexSceneManager::the() != NULL
)
255 ComplexSceneManager::the()->setMainloop(&CSMQT4Window::qtMainLoop
);
257 _pWindow
= pQT4Window
;
261 _pApp
->processEvents();
269 void CSMQT4Window::qtMainLoop(void)
271 if(!QGLFormat::hasOpenGL() || _pApp
== NULL
)
273 qWarning( "This system has no OpenGL support. Exiting." );
280 _pApp
->processEvents(); // execute QT main loop
282 ComplexSceneManager::the()->frame();
284 Thread::getCurrentChangeList()->commitChangesAndClear();
287 ComplexSceneManager::the()->terminate();