/usr/share/openscenegraph/examples/osgQtBrowser/osgQtBrowser.cpp is in openscenegraph-examples 3.0.1-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | /* OpenSceneGraph example, osgcompositeviewer.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <iostream>
#include <osg/Notify>
#include <osg/io_utils>
#include <osg/ArgumentParser>
#include <osgDB/WriteFile>
#include <osgGA/TrackballManipulator>
#include <osgGA/StateSetManipulator>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgWidget/Browser>
#include <QtWebKit/QWebSettings>
#include <QtWebKit/QtWebKit>
#include <QtGui/QGraphicsScene>
#include <QtGui/QGraphicsView>
#include <QtGui/QApplication>
#include <QtGui/QPainter>
#include <QtGui/QtEvents>
#include <osgQt/QGraphicsViewAdapter>
#include <osgQt/QWebViewImage>
// Thread that runs the viewer's frame loop as we can't run Qt in the background...
class ViewerFrameThread : public OpenThreads::Thread
{
public:
ViewerFrameThread(osgViewer::ViewerBase* viewerBase, bool doQApplicationExit):
_viewerBase(viewerBase),
_doQApplicationExit(doQApplicationExit) {}
~ViewerFrameThread()
{
cancel();
while(isRunning())
{
OpenThreads::Thread::YieldCurrentThread();
}
}
int cancel()
{
_viewerBase->setDone(true);
return 0;
}
void run()
{
int result = _viewerBase->run();
if (_doQApplicationExit) QApplication::exit(result);
}
osg::ref_ptr<osgViewer::ViewerBase> _viewerBase;
bool _doQApplicationExit;
};
int main(int argc, char **argv)
{
// Qt requires that we construct the global QApplication before creating any widgets.
QApplication app(argc, argv);
// use an ArgumentParser object to manage the program arguments.
osg::ArgumentParser arguments(&argc,argv);
bool useFrameLoopThread = false;
if (arguments.read("--no-frame-thread")) useFrameLoopThread = false;
if (arguments.read("--frame-thread")) useFrameLoopThread = true;
osg::ref_ptr<osgQt::QWebViewImage> image = new osgQt::QWebViewImage;
if (arguments.argc()>1) image->navigateTo((arguments[1]));
else image->navigateTo("http://www.youtube.com/");
osgWidget::GeometryHints hints(osg::Vec3(0.0f,0.0f,0.0f),
osg::Vec3(1.0f,0.0f,0.0f),
osg::Vec3(0.0f,0.0f,1.0f),
osg::Vec4(1.0f,1.0f,1.0f,1.0f),
osgWidget::GeometryHints::RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO);
osg::ref_ptr<osgWidget::Browser> browser = new osgWidget::Browser;
browser->assign(image.get(), hints);
// image->focusBrowser(true);
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer(arguments);
viewer->setSceneData(browser.get());
viewer->setCameraManipulator(new osgGA::TrackballManipulator());
viewer->addEventHandler(new osgViewer::StatsHandler);
viewer->addEventHandler(new osgViewer::WindowSizeHandler);
if (useFrameLoopThread)
{
// create a thread to run the viewer's frame loop
ViewerFrameThread viewerThread(viewer.get(), true);
viewerThread.startThread();
// now start the standard Qt event loop, then exists when the viewerThead sends the QApplication::exit() signal.
return QApplication::exec();
}
else
{
// run the frame loop, interleaving Qt and the main OSG frame loop
while(!viewer->done())
{
// process Qt events - this handles both events and paints the browser image
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
viewer->frame();
}
return 0;
}
}
|