root/OpenSceneGraph/trunk/src/osgQt/QGraphicsViewAdapter.cpp @ 12597

Revision 12597, 22.3 kB (checked in by robert, 3 years ago)

Resolved warnings reported by g++ 4.6's -Wunused-but-set-variable.

Warnings were:

/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osg/ShapeDrawable.cpp: In member function ‘void PrimitiveShapeVisitor::createHalfSphere(unsigned int, unsigned int, float, int, float, const Matrix&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osg/ShapeDrawable.cpp:1409:11: warning: variable ‘nzBase’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osg/ShapeDrawable.cpp:1410:11: warning: variable ‘nRatioBase’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgUtil/DelaunayTriangulator.cpp: In function ‘osgUtil::Triangle_list osgUtil::fillHole(osg::Vec3Array*, std::vector<unsigned int, std::allocator<unsigned int> >)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgUtil/DelaunayTriangulator.cpp:569:27: warning: variable ‘ptest’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgUtil/DelaunayTriangulator.cpp: In member function ‘bool osgUtil::DelaunayTriangulator::triangulate()’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgUtil/DelaunayTriangulator.cpp:979:45: warning: variable ‘curp’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgUtil/RenderStage.cpp: In member function ‘void osgUtil::RenderStage::runCameraSetUp(osg::RenderInfo?&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgUtil/RenderStage.cpp:631:18: warning: variable ‘stencilAttached’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgText/FadeText.cpp: In member function ‘void FadeTextPolytopeData::buildPolytope()’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgText/FadeText.cpp:74:20: warning: variable ‘edge23’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgText/FadeText.cpp:75:20: warning: variable ‘edge30’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgText/Text.cpp: In member function ‘void osgText::Text::computeBackdropPositions(unsigned int) const’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgText/Text.cpp:747:10: warning: variable ‘is_valid_size’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgGA/NodeTrackerManipulator.cpp: In member function ‘virtual bool osgGA::NodeTrackerManipulator::performMovementLeftMouseButton(double, double, double)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgGA/NodeTrackerManipulator.cpp:257:21: warning: variable ‘lookVector’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgGA/NodeTrackerManipulator.cpp:259:21: warning: variable ‘upVector’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgGA/TerrainManipulator.cpp: In member function ‘virtual bool osgGA::TerrainManipulator::performMovementMiddleMouseButton(double, double, double)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgGA/TerrainManipulator.cpp:217:11: warning: variable ‘lookVector’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgGA/TerrainManipulator.cpp:219:11: warning: variable ‘upVector’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgVolume/FixedFunctionTechnique.cpp: In member function ‘virtual void osgVolume::FixedFunctionTechnique::init()’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgVolume/FixedFunctionTechnique.cpp:124:30: warning: variable ‘tf’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgParticle/FluidProgram.cpp: In member function ‘virtual void osgParticle::FluidProgram::execute(double)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgParticle/FluidProgram.cpp:38:23: warning: variable ‘velBefore’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgShadow/ParallelSplitShadowMap.cpp: In member function ‘virtual void osgShadow::ParallelSplitShadowMap::cull(osgUtil::CullVisitor?&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgShadow/ParallelSplitShadowMap.cpp:593:22: warning: variable ‘bb’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgTerrain/GeometryTechnique.cpp: In member function ‘virtual void osgTerrain::GeometryTechnique::generateGeometry(osgTerrain::GeometryTechnique::BufferData?&, osgTerrain::Locator*, const osg::Vec3d&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgTerrain/GeometryTechnique.cpp:777:12: warning: variable ‘i_sampleFactor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgTerrain/GeometryTechnique.cpp:778:12: warning: variable ‘j_sampleFactor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/dds/ReaderWriterDDS.cpp: In function ‘osg::Image* ReadDDSFile(std::istream&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/dds/ReaderWriterDDS.cpp:314:10: warning: variable ‘is3dImage’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/dds/ReaderWriterDDS.cpp: In function ‘bool WriteDDSFile(const osg::Image*, std::ostream&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/dds/ReaderWriterDDS.cpp:721:10: warning: variable ‘is3dImage’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/hdr/hdrloader.cpp: In static member function ‘static bool HDRLoader::load(const char*, bool, HDRLoaderResult&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/hdr/hdrloader.cpp:101:10: warning: variable ‘cmd’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/vtf/ReaderWriterVTF.cpp: In function ‘osg::Image* ReadVTFFile(std::istream&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/vtf/ReaderWriterVTF.cpp:360:23: warning: variable ‘base’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/jp2/ReaderWriterJP2.cpp: In function ‘int putdata(jas_stream_t*, jas_image_t*, int)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/jp2/ReaderWriterJP2.cpp:41:13: warning: variable ‘linelen’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/Inventor/ConvertToInventor.cpp: In member function ‘void ConvertToInventor::processGeometry(const osg::Geometry*, ConvertToInventor::InventorState?*)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/Inventor/ConvertToInventor.cpp:1639:10: warning: variable ‘ok’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/Inventor/ConvertFromInventor.cpp: In member function ‘virtual SbBool? SoVRMLImageTextureOsg::readInstance(SoInput?*, short unsigned int)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/Inventor/ConvertFromInventor.cpp:1264:16: warning: variable ‘retval’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/OpenFlight/GeometryRecords.cpp: In member function ‘virtual void flt::Face::readRecord(flt::RecordInputStream?&, flt::Document&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/OpenFlight/GeometryRecords.cpp:369:19: warning: variable ‘secondaryPackedColor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/OpenFlight/GeometryRecords.cpp: In member function ‘virtual void flt::Mesh::readRecord(flt::RecordInputStream?&, flt::Document&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/OpenFlight/GeometryRecords.cpp:942:19: warning: variable ‘secondaryPackedColor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp: In member function ‘virtual osgDB::ReaderWriter::ReadResult? FLTReaderWriter::readNode(std::istream&, const Options*) const’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp:427:40: warning: variable ‘pos’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ive/ShapeAttributeList.cpp: In member function ‘void ive::ShapeAttributeList::write(ive::DataOutputStream?*)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ive/ShapeAttributeList.cpp:31:48: warning: variable ‘it’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ac/Geode.cpp: In member function ‘void ac3d::Geode::ProcessGeometry?(std::ostream&, unsigned int)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ac/Geode.cpp:806:35: warning: variable ‘fRep_s’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ac/Geode.cpp:806:43: warning: variable ‘fRep_t’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ac/Geode.cpp:807:35: warning: variable ‘fOffset_s’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ac/Geode.cpp:807:46: warning: variable ‘fOffset_t’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ac/Geode.cpp:932:38: warning: variable ‘primLength’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/txp/trpage_geom.cpp: In member function ‘virtual bool trpgGeometry::Write(trpgWriteBuffer&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/txp/trpage_geom.cpp:615:19: warning: variable ‘u’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/txp/trpage_material.cpp: In member function ‘int trpgMatTable::AddMaterial?(const trpgMaterial&, bool)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/txp/trpage_material.cpp:103:10: warning: variable ‘spaceInTable’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/txp/trpage_rarchive.cpp: In member function ‘virtual bool trpgr_Archive::ReadHeader?(bool)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/txp/trpage_rarchive.cpp:261:14: warning: variable ‘headerHasTexTable’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/zip/unzip.cpp: In member function ‘ZRESULT TUnzip::Get(int, ZIPENTRY*)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/zip/unzip.cpp:4055:8: warning: variable ‘hidden’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/zip/unzip.cpp:4055:22: warning: variable ‘system’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/zip/unzip.cpp:4055:36: warning: variable ‘archive’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/zip/ZipArchive.cpp: In member function ‘virtual bool ZipArchive::getFileNames(osgDB::Archive::FileNameList?&) const’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/zip/ZipArchive.cpp:91:37: warning: variable ‘iterEnd’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/pvr/ReaderWriterPVR.cpp: In member function ‘osgDB::ReaderWriter::ReadResult? ReaderWriterPVR::readPVRStream(std::istream&) const’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/pvr/ReaderWriterPVR.cpp:155:14: warning: variable ‘hasAlpha’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/View.cpp: In function ‘osg::Geometry* create3DSphericalDisplayDistortionMesh(const Vec3&, const Vec3&, const Vec3&, double, double, osg::Image*, const Matrix&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/View.cpp:737:15: warning: variable ‘cursor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/View.cpp: In function ‘osg::Geometry* createParoramicSphericalDisplayDistortionMesh(const Vec3&, const Vec3&, const Vec3&, double, double, osg::Image*, const Matrix&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/View.cpp:1130:19: warning: variable ‘cursor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/View.cpp:1118:15: warning: variable ‘dx’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/GraphicsWindowX11.cpp: In member function ‘virtual void osgViewer::GraphicsWindowX11::checkEvents()’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/GraphicsWindowX11.cpp:1181:10: warning: variable ‘destroyWindowRequested’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/cfg/ConfigParser.cpp: In member function ‘bool osgProducer::CameraConfig::parseFile(const string&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/cfg/ConfigParser.cpp:2247:13: warning: variable ‘result’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgQt/QGraphicsViewAdapter.cpp: In member function ‘bool osgQt::QGraphicsViewAdapter::handlePointerEvent(int, int, int)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgQt/QGraphicsViewAdapter.cpp:344:17: warning: variable ‘viewportGeometry’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgdistortion/osgdistortion.cpp: In function ‘osg::Node* createDistortionSubgraph(osg::Node*, const Vec4&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgdistortion/osgdistortion.cpp:125:19: warning: variable ‘cursor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgdistortion/osgdistortion.cpp:126:19: warning: variable ‘texcoord’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgdistortion/osgdistortion.cpp: In function ‘osg::Geometry* createDomeDistortionMesh(const Vec3&, const Vec3&, const Vec3&, osg::ArgumentParser?&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgdistortion/osgdistortion.cpp:358:15: warning: variable ‘cursor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgposter/osgposter.cpp: In function ‘int main(int, char**)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgposter/osgposter.cpp:253:31: warning: variable ‘outputTiles’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgthreadedterrain/osgthreadedterrain.cpp: In function ‘int main(int, char**)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgthreadedterrain/osgthreadedterrain.cpp:669:10: warning: variable ‘readParameter’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgtext3D/TextNode.cpp: In member function ‘virtual void osgText::Layout::layout(osgText::TextNode?&) const’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgtext3D/TextNode.cpp:80:11: warning: variable ‘characterHeightScale’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgvolume/osgvolume.cpp: In function ‘int main(int, char**)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgvolume/osgvolume.cpp:678:38: warning: variable ‘internalFormatMode’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgwidgetcanvas/osgwidgetcanvas.cpp: In function ‘bool windowMouseOver(osgWidget::Event&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgwidgetcanvas/osgwidgetcanvas.cpp:27:24: warning: variable ‘xy’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgwidgetcanvas/osgwidgetcanvas.cpp: In function ‘bool widgetMouseOver(osgWidget::Event&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgwidgetcanvas/osgwidgetcanvas.cpp:35:24: warning: variable ‘xy’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/p3d/ReaderWriterP3D.cpp: In member function ‘osg::Node* ReaderWriterP3DXML::parseXmlGraph(osgDB::XmlNode?*, bool, osgDB::Options*) const’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/p3d/ReaderWriterP3D.cpp:2121:10: warning: variable ‘readSlide’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/applications/present3D/present3D.cpp: In function ‘int main(int, char**)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/applications/present3D/present3D.cpp:639:10: warning: variable ‘sizesSpecified’ set but not used [-Wunused-but-set-variable]

  • Property svn:eol-style set to native
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#include <osgQt/QGraphicsViewAdapter>
15#include <osgQt/QWidgetImage>
16
17#include <QtOpenGL/QGLWidget>
18
19#include <osg/Version>
20#include <osgGA/GUIEventAdapter>
21
22#include <osg/NodeVisitor>
23#include <osg/io_utils>
24#include <QtGui/QGraphicsItem>
25#include <QtGui/QGraphicsProxyWidget>
26
27#define MYQKEYEVENT 2000
28#define MYQPOINTEREVENT 2001
29
30namespace osgQt
31{
32
33QCoreApplication* getOrCreateQApplication()
34{
35    if (QApplication::instance()==0)
36    {
37        static char** argv = 0;
38        static int argc = 0;
39        static QApplication app(argc,argv);
40    }
41    return QApplication::instance();
42}
43
44class MyQKeyEvent : public QEvent
45{
46public:
47    MyQKeyEvent( int key, bool down ):
48        QEvent( QEvent::Type(MYQKEYEVENT) ),
49        _key(key), _down(down) {}
50
51    int         _key;
52    bool        _down;
53};
54
55struct MyQPointerEvent : public QEvent
56{
57    MyQPointerEvent(int x, int y, unsigned int buttonMask):
58        QEvent( QEvent::Type(MYQPOINTEREVENT) ),
59        _x(x), _y(y),_buttonMask(buttonMask) {}
60
61    int _x, _y;
62    unsigned int _buttonMask;
63};
64
65
66const QImage::Format s_imageFormat = QImage::Format_ARGB32_Premultiplied;
67
68QGraphicsViewAdapter::QGraphicsViewAdapter(osg::Image* image, QWidget* widget):
69    _image(image),
70    _previousQtMouseX(-1),
71    _previousQtMouseY(-1),
72    _previousSentEvent(false),
73    _qtKeyModifiers(Qt::NoModifier),
74    _backgroundColor(255, 255, 255),
75    _widget(widget)
76{
77    // make sure we have a valid QApplication before we start creating widgets.
78    getOrCreateQApplication();
79
80
81    setUpKeyMap();
82
83    _graphicsScene = new QGraphicsScene;
84    _graphicsScene->addWidget(widget);
85
86    _graphicsView = new QGraphicsView;
87    _graphicsView->setScene(_graphicsScene);
88    _graphicsView->viewport()->setParent(0);
89
90#if (QT_VERSION_CHECK(4, 5, 0) <= QT_VERSION)
91    _graphicsScene->setStickyFocus(true);
92#endif
93
94    _width = _graphicsScene->width();
95    _height = _graphicsScene->height();
96
97    _qimages[0] = QImage(QSize(_width, _height), s_imageFormat);
98    _qimages[1] = QImage(QSize(_width, _height), s_imageFormat);
99    _qimages[2] = QImage(QSize(_width, _height), s_imageFormat);
100
101    _currentRead = 0;
102    _currentWrite = 1;
103    _previousWrite = 2;
104    _previousFrameNumber = osg::UNINITIALIZED_FRAME_NUMBER;
105    _newImageAvailable = false;
106
107    connect(_graphicsScene, SIGNAL(changed(const QList<QRectF> &)),
108            this, SLOT(repaintRequestedSlot(const QList<QRectF> &)));
109    connect(_graphicsScene, SIGNAL(sceneRectChanged(const QRectF &)),
110            this, SLOT(repaintRequestedSlot(const QRectF &)));
111
112    assignImage(0);
113}
114
115void QGraphicsViewAdapter::repaintRequestedSlot(const QList<QRectF>&)
116{
117    // OSG_NOTICE<<"QGraphicsViewAdapter::repaintRequestedSlot"<<std::endl;
118    render();
119}
120
121void QGraphicsViewAdapter::repaintRequestedSlot(const QRectF&)
122{
123    // OSG_NOTICE<<"QGraphicsViewAdapter::repaintRequestedSlot"<<std::endl;
124    render();
125}
126
127void QGraphicsViewAdapter::customEvent ( QEvent * event )
128{
129    if (event->type()==MYQKEYEVENT)
130    {
131        MyQKeyEvent* keyEvent = (MyQKeyEvent*)event;
132        handleKeyEvent(keyEvent->_key, keyEvent->_down);
133    }
134    else if (event->type()==MYQPOINTEREVENT)
135    {
136        MyQPointerEvent* pointerEvent = (MyQPointerEvent*)event;
137        handlePointerEvent(pointerEvent->_x, pointerEvent->_y, pointerEvent->_buttonMask);
138    }
139}
140
141
142void QGraphicsViewAdapter::setUpKeyMap()
143{
144    _keyMap[osgGA::GUIEventAdapter::KEY_BackSpace] = Qt::Key_Backspace;
145    _keyMap[osgGA::GUIEventAdapter::KEY_Tab] = Qt::Key_Tab;
146    _keyMap[osgGA::GUIEventAdapter::KEY_Linefeed] = Qt::Key_Return; // No LineFeed in Qt!
147    _keyMap[osgGA::GUIEventAdapter::KEY_Clear] = Qt::Key_Clear;
148    _keyMap[osgGA::GUIEventAdapter::KEY_Return] = Qt::Key_Return;
149    _keyMap[osgGA::GUIEventAdapter::KEY_Pause] = Qt::Key_Pause;
150    _keyMap[osgGA::GUIEventAdapter::KEY_Scroll_Lock] = Qt::Key_ScrollLock;
151    _keyMap[osgGA::GUIEventAdapter::KEY_Sys_Req] = Qt::Key_SysReq;
152    _keyMap[osgGA::GUIEventAdapter::KEY_Escape] = Qt::Key_Escape;
153    _keyMap[osgGA::GUIEventAdapter::KEY_Delete] = Qt::Key_Delete;
154
155    _keyMap[osgGA::GUIEventAdapter::KEY_Home] = Qt::Key_Home;
156    _keyMap[osgGA::GUIEventAdapter::KEY_Left] = Qt::Key_Left;
157    _keyMap[osgGA::GUIEventAdapter::KEY_Up] = Qt::Key_Up;
158    _keyMap[osgGA::GUIEventAdapter::KEY_Right] = Qt::Key_Right;
159    _keyMap[osgGA::GUIEventAdapter::KEY_Down] = Qt::Key_Down;
160    _keyMap[osgGA::GUIEventAdapter::KEY_Prior] = Qt::Key_Left; // no Prior in Qt
161    _keyMap[osgGA::GUIEventAdapter::KEY_Page_Up] = Qt::Key_PageUp;
162    _keyMap[osgGA::GUIEventAdapter::KEY_Next] = Qt::Key_Right; // No Next in Qt
163    _keyMap[osgGA::GUIEventAdapter::KEY_Page_Down] = Qt::Key_PageDown;
164    _keyMap[osgGA::GUIEventAdapter::KEY_End] = Qt::Key_End;
165    _keyMap[osgGA::GUIEventAdapter::KEY_Begin] = Qt::Key_Home; // No Begin in Qt
166
167    _keyMap[osgGA::GUIEventAdapter::KEY_Select] = Qt::Key_Select;
168    _keyMap[osgGA::GUIEventAdapter::KEY_Print] = Qt::Key_Print;
169    _keyMap[osgGA::GUIEventAdapter::KEY_Execute] = Qt::Key_Execute;
170    _keyMap[osgGA::GUIEventAdapter::KEY_Insert] = Qt::Key_Insert;
171    //_keyMap[osgGA::GUIEventAdapter::KEY_Undo] = Qt::Key_; // no Undo
172    //_keyMap[osgGA::GUIEventAdapter::KEY_Redo] = Qt::Key_; // no Redo
173    _keyMap[osgGA::GUIEventAdapter::KEY_Menu] = Qt::Key_Menu;
174    _keyMap[osgGA::GUIEventAdapter::KEY_Find] = Qt::Key_Search; // no Qt Find
175    _keyMap[osgGA::GUIEventAdapter::KEY_Cancel] = Qt::Key_Cancel;
176    _keyMap[osgGA::GUIEventAdapter::KEY_Help] = Qt::Key_Help;
177    _keyMap[osgGA::GUIEventAdapter::KEY_Break] = Qt::Key_Escape; // no break
178    _keyMap[osgGA::GUIEventAdapter::KEY_Mode_switch] = Qt::Key_Mode_switch;
179    _keyMap[osgGA::GUIEventAdapter::KEY_Script_switch] = Qt::Key_Mode_switch; // no Script switch
180    _keyMap[osgGA::GUIEventAdapter::KEY_Num_Lock] = Qt::Key_NumLock;
181
182    _keyMap[osgGA::GUIEventAdapter::KEY_Shift_L] = Qt::Key_Shift;
183    _keyMap[osgGA::GUIEventAdapter::KEY_Shift_R] = Qt::Key_Shift;
184    _keyMap[osgGA::GUIEventAdapter::KEY_Control_L] = Qt::Key_Control;
185    _keyMap[osgGA::GUIEventAdapter::KEY_Control_R] = Qt::Key_Control;
186    _keyMap[osgGA::GUIEventAdapter::KEY_Caps_Lock] = Qt::Key_CapsLock;
187    _keyMap[osgGA::GUIEventAdapter::KEY_Shift_Lock] = Qt::Key_CapsLock;
188
189    _keyMap[osgGA::GUIEventAdapter::KEY_Meta_L] = Qt::Key_Meta; // Qt doesn't have a Meta L
190    _keyMap[osgGA::GUIEventAdapter::KEY_Meta_R] = Qt::Key_Meta; // Qt doesn't have a Meta R
191    _keyMap[osgGA::GUIEventAdapter::KEY_Alt_L] = Qt::Key_Alt; // Qt doesn't have a Alt L
192    _keyMap[osgGA::GUIEventAdapter::KEY_Alt_R] = Qt::Key_Alt; // Qt doesn't have a Alt R
193    _keyMap[osgGA::GUIEventAdapter::KEY_Super_L] = Qt::Key_Super_L;
194    _keyMap[osgGA::GUIEventAdapter::KEY_Super_R] = Qt::Key_Super_R;
195    _keyMap[osgGA::GUIEventAdapter::KEY_Hyper_L] = Qt::Key_Hyper_L;
196    _keyMap[osgGA::GUIEventAdapter::KEY_Hyper_R] = Qt::Key_Hyper_R;
197
198    _keyMap[osgGA::GUIEventAdapter::KEY_KP_Space] = Qt::Key_Space;
199    _keyMap[osgGA::GUIEventAdapter::KEY_KP_Tab] = Qt::Key_Tab;
200    _keyMap[osgGA::GUIEventAdapter::KEY_KP_Enter] = Qt::Key_Enter;
201    _keyMap[osgGA::GUIEventAdapter::KEY_KP_F1] = Qt::Key_F1;
202    _keyMap[osgGA::GUIEventAdapter::KEY_KP_F2] = Qt::Key_F2;
203    _keyMap[osgGA::GUIEventAdapter::KEY_KP_F3] = Qt::Key_F3;
204    _keyMap[osgGA::GUIEventAdapter::KEY_KP_F4] = Qt::Key_F4;
205    _keyMap[osgGA::GUIEventAdapter::KEY_KP_Home] = Qt::Key_Home;
206    _keyMap[osgGA::GUIEventAdapter::KEY_KP_Left] = Qt::Key_Left;
207    _keyMap[osgGA::GUIEventAdapter::KEY_KP_Up] = Qt::Key_Up;
208    _keyMap[osgGA::GUIEventAdapter::KEY_KP_Right] = Qt::Key_Right;
209    _keyMap[osgGA::GUIEventAdapter::KEY_KP_Down] = Qt::Key_Down;
210    _keyMap[osgGA::GUIEventAdapter::KEY_KP_Prior] = Qt::Key_Left;
211    _keyMap[osgGA::GUIEventAdapter::KEY_KP_Page_Up] = Qt::Key_PageUp;
212    _keyMap[osgGA::GUIEventAdapter::KEY_KP_Next] = Qt::Key_Right;
213    _keyMap[osgGA::GUIEventAdapter::KEY_KP_Page_Down] = Qt::Key_PageDown;
214    _keyMap[osgGA::GUIEventAdapter::KEY_KP_End] = Qt::Key_End;
215
216    // _keyMap[osgGA::GUIEventAdapter::KEY_KP_Begin] = Qt::Key_Begin;
217    _keyMap[osgGA::GUIEventAdapter::KEY_KP_Insert] = Qt::Key_Insert;
218    _keyMap[osgGA::GUIEventAdapter::KEY_KP_Delete] = Qt::Key_Delete;
219    _keyMap[osgGA::GUIEventAdapter::KEY_KP_Equal] = Qt::Key_Equal;
220    _keyMap[osgGA::GUIEventAdapter::KEY_KP_Multiply] = Qt::Key_Asterisk;
221    _keyMap[osgGA::GUIEventAdapter::KEY_KP_Add] = Qt::Key_Plus;
222    //_keyMap[osgGA::GUIEventAdapter::KEY_KP_Separator] = Qt::Key_;
223    _keyMap[osgGA::GUIEventAdapter::KEY_KP_Subtract] = Qt::Key_Minus;
224    _keyMap[osgGA::GUIEventAdapter::KEY_KP_Decimal] = Qt::Key_Period;
225    _keyMap[osgGA::GUIEventAdapter::KEY_KP_Divide] = Qt::Key_division;
226    _keyMap[osgGA::GUIEventAdapter::KEY_KP_0] = Qt::Key_0;
227    _keyMap[osgGA::GUIEventAdapter::KEY_KP_1] = Qt::Key_1;
228    _keyMap[osgGA::GUIEventAdapter::KEY_KP_2] = Qt::Key_2;
229    _keyMap[osgGA::GUIEventAdapter::KEY_KP_3] = Qt::Key_3;
230    _keyMap[osgGA::GUIEventAdapter::KEY_KP_4] = Qt::Key_4;
231    _keyMap[osgGA::GUIEventAdapter::KEY_KP_5] = Qt::Key_5;
232    _keyMap[osgGA::GUIEventAdapter::KEY_KP_6] = Qt::Key_6;
233    _keyMap[osgGA::GUIEventAdapter::KEY_KP_7] = Qt::Key_7;
234    _keyMap[osgGA::GUIEventAdapter::KEY_KP_8] = Qt::Key_8;
235    _keyMap[osgGA::GUIEventAdapter::KEY_KP_9] = Qt::Key_9;
236
237    _keyMap[osgGA::GUIEventAdapter::KEY_F1] = Qt::Key_F1;
238    _keyMap[osgGA::GUIEventAdapter::KEY_F2] = Qt::Key_F2;
239    _keyMap[osgGA::GUIEventAdapter::KEY_F3] = Qt::Key_F3;
240    _keyMap[osgGA::GUIEventAdapter::KEY_F4] = Qt::Key_F4;
241    _keyMap[osgGA::GUIEventAdapter::KEY_F5] = Qt::Key_F5;
242    _keyMap[osgGA::GUIEventAdapter::KEY_F6] = Qt::Key_F6;
243    _keyMap[osgGA::GUIEventAdapter::KEY_F7] = Qt::Key_F7;
244    _keyMap[osgGA::GUIEventAdapter::KEY_F8] = Qt::Key_F8;
245    _keyMap[osgGA::GUIEventAdapter::KEY_F9] = Qt::Key_F9;
246    _keyMap[osgGA::GUIEventAdapter::KEY_F10] = Qt::Key_F10;
247    _keyMap[osgGA::GUIEventAdapter::KEY_F11] = Qt::Key_F11;
248    _keyMap[osgGA::GUIEventAdapter::KEY_F12] = Qt::Key_F12;
249    _keyMap[osgGA::GUIEventAdapter::KEY_F13] = Qt::Key_F13;
250    _keyMap[osgGA::GUIEventAdapter::KEY_F14] = Qt::Key_F14;
251    _keyMap[osgGA::GUIEventAdapter::KEY_F15] = Qt::Key_F15;
252    _keyMap[osgGA::GUIEventAdapter::KEY_F16] = Qt::Key_F16;
253    _keyMap[osgGA::GUIEventAdapter::KEY_F17] = Qt::Key_F17;
254    _keyMap[osgGA::GUIEventAdapter::KEY_F18] = Qt::Key_F18;
255    _keyMap[osgGA::GUIEventAdapter::KEY_F19] = Qt::Key_F19;
256    _keyMap[osgGA::GUIEventAdapter::KEY_F20] = Qt::Key_F20;
257    _keyMap[osgGA::GUIEventAdapter::KEY_F21] = Qt::Key_F21;
258    _keyMap[osgGA::GUIEventAdapter::KEY_F22] = Qt::Key_F22;
259    _keyMap[osgGA::GUIEventAdapter::KEY_F23] = Qt::Key_F23;
260    _keyMap[osgGA::GUIEventAdapter::KEY_F24] = Qt::Key_F24;
261    _keyMap[osgGA::GUIEventAdapter::KEY_F25] = Qt::Key_F25;
262    _keyMap[osgGA::GUIEventAdapter::KEY_F26] = Qt::Key_F26;
263    _keyMap[osgGA::GUIEventAdapter::KEY_F27] = Qt::Key_F27;
264    _keyMap[osgGA::GUIEventAdapter::KEY_F28] = Qt::Key_F28;
265    _keyMap[osgGA::GUIEventAdapter::KEY_F29] = Qt::Key_F29;
266    _keyMap[osgGA::GUIEventAdapter::KEY_F30] = Qt::Key_F30;
267    _keyMap[osgGA::GUIEventAdapter::KEY_F31] = Qt::Key_F31;
268    _keyMap[osgGA::GUIEventAdapter::KEY_F32] = Qt::Key_F32;
269    _keyMap[osgGA::GUIEventAdapter::KEY_F33] = Qt::Key_F33;
270    _keyMap[osgGA::GUIEventAdapter::KEY_F34] = Qt::Key_F34;
271    _keyMap[osgGA::GUIEventAdapter::KEY_F35] = Qt::Key_F35;
272
273}
274
275QWidget* QGraphicsViewAdapter::getWidgetAt(const QPoint& pos)
276{
277   QWidget* childAt = _graphicsView->childAt(pos);
278   if(childAt)
279   {
280       return childAt;
281   }
282 
283   QGraphicsItem* item = _graphicsView->itemAt(pos);
284   if(item && item->contains(item->mapFromScene(pos)))
285   {
286      QGraphicsProxyWidget* p = dynamic_cast<QGraphicsProxyWidget*>(item);
287      if(p)
288      { 
289         childAt = p->widget();
290         QWidget* c;
291         while( (c = childAt->childAt(childAt->mapFromGlobal(pos)))!=0 )
292         {
293            childAt = c;
294         }
295         return childAt;
296      }
297   }
298   return NULL;
299}
300
301bool QGraphicsViewAdapter::sendPointerEvent(int x, int y, int buttonMask)
302{
303    _previousQtMouseX = x;
304    _previousQtMouseY = _graphicsView->size().height() - y;
305   
306    QPoint pos(_previousQtMouseX, _previousQtMouseY);
307   
308    if (getWidgetAt(pos) != NULL || (_previousSentEvent && buttonMask != 0))
309    {
310        QCoreApplication::postEvent(this, new MyQPointerEvent(x,y,buttonMask));
311        OSG_INFO<<"sendPointerEvent("<<x<<", "<<y<<") sent"<<std::endl;
312        _previousSentEvent = true;
313        return true;
314    }
315   
316    OSG_INFO<<"sendPointerEvent("<<x<<", "<<y<<") not sent"<<std::endl;
317    _previousSentEvent = false;
318    return false;
319}
320
321bool QGraphicsViewAdapter::handlePointerEvent(int x, int y, int buttonMask)
322{
323    OSG_INFO<<"dispatchPointerEvent("<<x<<", "<<y<<", "<<buttonMask<<")"<<std::endl;
324
325    y = _graphicsView->size().height()-y;
326
327    bool leftButtonPressed = (buttonMask & osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)!=0;
328    bool middleButtonPressed = (buttonMask & osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON)!=0;
329    bool rightButtonPressed = (buttonMask & osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)!=0;
330
331    bool prev_leftButtonPressed = (_previousButtonMask & osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)!=0;
332    bool prev_middleButtonPressed = (_previousButtonMask & osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON)!=0;
333    bool prev_rightButtonPressed = (_previousButtonMask & osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)!=0;
334
335    OSG_INFO<<"leftButtonPressed "<<leftButtonPressed<<std::endl;
336    OSG_INFO<<"middleButtonPressed "<<middleButtonPressed<<std::endl;
337    OSG_INFO<<"rightButtonPressed "<<rightButtonPressed<<std::endl;
338
339    Qt::MouseButtons qtMouseButtons =
340        (leftButtonPressed ? Qt::LeftButton : Qt::NoButton) |
341        (middleButtonPressed ? Qt::MidButton : Qt::NoButton) |
342        (rightButtonPressed ? Qt::RightButton : Qt::NoButton);
343
344    const QPoint globalPos(x, y);
345     
346    if (buttonMask != _previousButtonMask)
347    {
348        Qt::MouseButton qtButton = Qt::NoButton;
349        QEvent::Type eventType = QEvent::None;
350        if (leftButtonPressed != prev_leftButtonPressed)
351        {
352            qtButton = Qt::LeftButton;
353            eventType = leftButtonPressed ? QEvent::MouseButtonPress : QEvent::MouseButtonRelease ;
354        }
355        else if (middleButtonPressed != prev_middleButtonPressed)
356        {
357            qtButton = Qt::MidButton;
358            eventType = middleButtonPressed ? QEvent::MouseButtonPress : QEvent::MouseButtonRelease ;
359        }
360        else if (rightButtonPressed != prev_rightButtonPressed)
361        {
362            qtButton = Qt::RightButton;
363            eventType = rightButtonPressed ? QEvent::MouseButtonPress : QEvent::MouseButtonRelease ;
364            if(!rightButtonPressed)
365            {
366               QWidget* targetWidget = getWidgetAt(globalPos);
367               if(targetWidget)
368               {
369                  QPoint localPos = targetWidget->mapFromGlobal(globalPos);
370                  QContextMenuEvent* cme = new QContextMenuEvent(QContextMenuEvent::Mouse, localPos, globalPos);
371                  QCoreApplication::postEvent(targetWidget, cme);
372               }               
373            }
374        }
375     
376        if (eventType==QEvent::MouseButtonPress)
377        {
378            _image->sendFocusHint(true);
379        }
380
381        QMouseEvent event(eventType, globalPos, qtButton, qtMouseButtons, 0);
382        QCoreApplication::sendEvent(_graphicsView->viewport(), &event );
383
384        _previousButtonMask = buttonMask;
385    }
386    else if (x != _previousMouseX || y != _previousMouseY)
387    {
388        QMouseEvent event(QEvent::MouseMove, globalPos, Qt::NoButton, qtMouseButtons, 0);
389        QCoreApplication::sendEvent(_graphicsView->viewport(), &event);
390
391        _previousMouseX = x;
392        _previousMouseY = y;
393    }
394
395    return true;
396}
397
398bool QGraphicsViewAdapter::sendKeyEvent(int key, bool keyDown)
399{
400    QPoint pos(_previousQtMouseX, _previousQtMouseY);
401    if (getWidgetAt(pos) != NULL)
402    {
403        QCoreApplication::postEvent(this, new MyQKeyEvent(key,keyDown));
404        return true;
405    }
406
407    return false;
408}
409
410bool QGraphicsViewAdapter::handleKeyEvent(int key, bool keyDown)
411{
412    QEvent::Type eventType = keyDown ? QEvent::KeyPress : QEvent::KeyRelease;
413
414    OSG_INFO<<"sendKeyEvent("<<key<<", "<<keyDown<<")"<<std::endl;
415
416    if (key==osgGA::GUIEventAdapter::KEY_Shift_L || key==osgGA::GUIEventAdapter::KEY_Shift_R)
417    {
418        _qtKeyModifiers = (_qtKeyModifiers & ~Qt::ShiftModifier) | (keyDown ? Qt::ShiftModifier : Qt::NoModifier);
419    }
420
421    if (key==osgGA::GUIEventAdapter::KEY_Control_L || key==osgGA::GUIEventAdapter::KEY_Control_R)
422    {
423        _qtKeyModifiers = (_qtKeyModifiers & ~Qt::ControlModifier) | (keyDown ? Qt::ControlModifier : Qt::NoModifier);
424    }
425
426    if (key==osgGA::GUIEventAdapter::KEY_Alt_L || key==osgGA::GUIEventAdapter::KEY_Alt_R)
427    {
428        _qtKeyModifiers = (_qtKeyModifiers & ~Qt::ControlModifier) | (keyDown ? Qt::ControlModifier : Qt::NoModifier);
429    }
430
431    if (key==osgGA::GUIEventAdapter::KEY_Meta_L || key==osgGA::GUIEventAdapter::KEY_Meta_R)
432    {
433        _qtKeyModifiers = (_qtKeyModifiers & ~Qt::MetaModifier) | (keyDown ? Qt::MetaModifier : Qt::NoModifier);
434    }
435
436    Qt::Key qtkey;
437    QChar input;
438
439    KeyMap::iterator itr = _keyMap.find(key);
440    if (itr != _keyMap.end())
441    {
442        qtkey = itr->second;
443    }
444    else
445    {
446        qtkey = (Qt::Key)key;
447        input = QChar(key);
448    }
449
450    QKeyEvent event(eventType, qtkey, _qtKeyModifiers, input);
451    QCoreApplication::sendEvent(_graphicsScene.data(), &event);
452    return true;
453}
454
455void QGraphicsViewAdapter::setFrameLastRendered(const osg::FrameStamp* frameStamp)
456{
457    OSG_INFO<<"setFrameLastRendered("<<frameStamp->getFrameNumber()<<")"<<std::endl;
458
459    if (_newImageAvailable && _previousFrameNumber!=frameStamp->getFrameNumber())
460    {
461        {
462            OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_qimagesMutex);
463
464            // make sure that _previousFrameNumber hasn't been updated by another thread since we entered this branch.
465            if (_previousFrameNumber==frameStamp->getFrameNumber()) return;
466            _previousFrameNumber = frameStamp->getFrameNumber();
467
468            std::swap(_currentRead, _previousWrite);
469            _newImageAvailable = false;
470        }
471
472        assignImage(_currentRead);
473    }
474}
475
476void QGraphicsViewAdapter::clearWriteBuffer()
477{
478    QImage& image = _qimages[_currentWrite];
479    image.fill(_backgroundColor.rgba ());
480    image = QGLWidget::convertToGLFormat(image);
481
482    // swap the write buffers in a thread safe way
483    OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_qimagesMutex);
484    std::swap(_currentWrite, _previousWrite);
485    _newImageAvailable = true;
486}
487
488void QGraphicsViewAdapter::render()
489{
490    OSG_INFO<<"Current write = "<<_currentWrite<<std::endl;
491    QImage& image = _qimages[_currentWrite];
492
493    // If we got a resize, act on it, first by resizing the view, then the current image
494
495    {
496        OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_qresizeMutex);
497        if (_graphicsView->size().width() != _width || _graphicsView->size().height() != _height)
498        {
499            _graphicsView->setGeometry(0, 0, _width, _height);
500            _graphicsView->viewport()->setGeometry(0, 0, _width, _height);
501
502            _widget->setGeometry(0, 0, _width, _height);
503        }
504
505        if (image.width() != _width || image.height() != _height)
506        {
507            _qimages[_currentWrite] = QImage(_width, _height, s_imageFormat);
508            image = _qimages[_currentWrite];
509        }
510        OSG_INFO << "render image " << _currentWrite << " with size (" << _width << "," << _height << ")" <<std::endl;
511    }
512   
513#if 1
514    // paint the image with the graphics view
515    QPainter painter(&image);
516
517    // Clear the image otherwise there are artifacts for some widgets that overpaint.
518    painter.setCompositionMode(QPainter::CompositionMode_Source);
519    painter.fillRect(0, 0, image.width(), image.height(), _backgroundColor);
520    painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
521
522    QRectF destinationRect(0, 0, image.width(), image.height());
523    QRect sourceRect(0, 0, image.width(), image.height());
524    _graphicsView->render(&painter, destinationRect, sourceRect, Qt::IgnoreAspectRatio);
525    painter.end();
526#elif 0
527    QPixmap pixmap(QPixmap::grabWidget(_graphicsView.data(), QRect(0, 0, image.width(), image.height())));
528    image = pixmap.toImage();
529#else
530    // paint the image with the graphics view
531    QPixmap pixmap(image.width(), image.height());
532    // Clear the image otherwise there are artifacts for some widgets that overpaint.
533    pixmap.fill(Qt::transparent);
534    QPainter painter(&pixmap);
535
536    QRectF destinationRect(0, 0, image.width(), image.height());
537    QRect sourceRect(0, 0, image.width(), image.height());
538    _graphicsView->render(&painter, destinationRect, _graphicsView->viewport()->rect());
539    painter.end();
540
541    image = pixmap.toImage();
542#endif
543
544    // convert into OpenGL format - flipping around the Y axis and swizzling the pixels
545    image = QGLWidget::convertToGLFormat(image);
546
547    // swap the write buffers in a thread safe way
548    OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_qimagesMutex);
549    std::swap(_currentWrite, _previousWrite);
550    _newImageAvailable = true;
551}
552
553void QGraphicsViewAdapter::assignImage(unsigned int i)
554{
555    QImage& image = _qimages[i];
556    unsigned char* data = image.bits();
557
558    OSG_INFO<<"assignImage("<<i<<") image = "<<&image<<" size = ("<<image.width()<<","<<image.height()<<") data = "<<(void*)data<<std::endl;
559
560    _image->setImage(image.width(), image.height(), 1,
561                     4, GL_RGBA, GL_UNSIGNED_BYTE,
562                     data, osg::Image::NO_DELETE, 1);
563}
564
565void QGraphicsViewAdapter::resize(int width, int height)
566{
567    OSG_INFO << "resize to (" << width << "," << height << ")" <<std::endl;
568
569    // Save the new width and height which will take effect on the next render() (in the Qt thread).
570   
571    {
572        OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_qresizeMutex);
573        _width = width;
574        _height = height;
575    }
576
577    // Force an update so render() will be called.
578    _graphicsScene->update(_graphicsScene->sceneRect());
579}
580
581}
Note: See TracBrowser for help on using the browser.