1/* -*-c++-*- */ 2/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph 3 * Copyright 2016 Pelican Mapping 4 * http://osgearth.org 5 * 6 * osgEarth is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU Lesser General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/> 18 */ 19#ifndef OSGEARTHQT_VIEWERWIDGET_H 20#define OSGEARTHQT_VIEWERWIDGET_H 1 21 22#include <osgEarthQt/Common> 23 24#include <osgEarth/Map> 25 26#include <osgQt/GraphicsWindowQt> 27#include <osgViewer/ViewerBase> 28 29#include <QtCore/QTimer> 30 31namespace osgEarth { namespace QtGui 32{ 33 using namespace osgEarth; 34 35 /** 36 * Qt widget that encapsulates an osgViewer::Viewer. 37 */ 38 class OSGEARTHQT_EXPORT ViewerWidget : public osgQt::GLWidget 39 { 40 Q_OBJECT; 41 42 public: 43 /** 44 * Constructs a new ViewerWidget, creating an underlying viewer. 45 * @param[in ] scene Scene graph to attach to the viewer (optional) 46 */ 47 ViewerWidget(osg::Node* scene=0L); 48 49 /** 50 * Constructs a new ViewerWidget, attaching an existing viewer. 51 * @param[in ] viewer Viewer to attach to this widget. The widget will install 52 * a new camera in the viewer. (NOTE: this widget does not take 53 * ownership of the Viewer. You are still respsonsile for its 54 * destruction) 55 */ 56 ViewerWidget(osgViewer::ViewerBase* viewer); 57 58 /** 59 * Access the underlying viewer. 60 */ 61 osgViewer::ViewerBase* getViewer() { return _viewer.get(); } 62 63 /** 64 * Populates the incoming collection with the views comprising this viewer. 65 */ 66 template<typename T> 67 void getViews( T& views ) const { 68 osgViewer::ViewerBase::Views temp; 69 _viewer->getViews(temp); 70 views.insert(views.end(), temp.begin(), temp.end()); 71 } 72 73 virtual ~ViewerWidget(); 74 75 public slots: 76 77 /** 78 * Change the underlying timer's interval 79 */ 80 void setTimerInterval( int milliseconds ); 81 82 83 protected: 84 85 QTimer _timer; 86 87 void installFrameTimer(); 88 89 void createViewer(); 90 void reconfigure( osgViewer::View* ); 91 void paintEvent( QPaintEvent* ); 92 93 osg::observer_ptr<osgViewer::ViewerBase> _viewer; 94 osg::ref_ptr<osg::GraphicsContext> _gc; 95 }; 96} } 97 98#endif // OSGEARTHQT_VIEWERWIDGET_H 99