OpenFrames
QWidgetPanel.hpp
Go to the documentation of this file.
1 /***********************************
2  Copyright 2017 Ravishankar Mathur
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 ***********************************/
16 
21 #ifndef _OF_QWIDGETPANEL_
22 #define _OF_QWIDGETPANEL_
23 
24 // OpenFrames and OpenSceneGraph headers
25 #include <OpenFrames/Export.h>
27 #include <osg/Geode>
28 #include <osg/Geometry>
29 #include <osgViewer/ViewerEventHandlers>
30 
31 // Qt forward declarations
32 #include <qglobal.h> // for QT_FORWARD_DECLARE_CLASS
33 QT_FORWARD_DECLARE_CLASS(QWidget);
34 
35 // OpenFrames forward declarations
36 namespace OpenFrames
37 {
38  class QWidgetImage;
39 }
40 
41 namespace OpenFrames
42 {
51  class OF_EXPORT QWidgetPanel : public ReferenceFrame
52  {
53  public:
54  QWidgetPanel( const std::string &name );
55  QWidgetPanel( const std::string &name, const osg::Vec3 &color );
56  QWidgetPanel( const std::string &name, const osg::Vec4 &color );
57  QWidgetPanel( const std::string &name , float r, float g, float b, float a = 1.0 );
58 
59  // Show/hide this frame's contents, e.g. everything a frame shows (excluding axes, labels, and children)
60  // Inherited from ReferenceFrame
61  virtual void showContents(bool showContents);
62  virtual bool getContentsShown() const;
63 
65  void setSize(const double &width, const double &height);
66  void getSize(double &width, double &height);
67 
69  bool setWidget( QWidget *widget );
70 
72  void setIgnoreWidget( QWidget *widget, bool ignore );
73 
76  osg::Image* getImage() { return (osg::Image*)_image.get(); }
77 
79  void setImageHandler(osgViewer::InteractiveImageHandler *handler);
80  osgViewer::InteractiveImageHandler* getImageHandler() const;
81 
85  virtual void setColor( const osg::Vec4 &color );
86  using ReferenceFrame::setColor; // Unhide other setColor() functions
87 
89  virtual const osg::BoundingSphere& getBound() const;
90 
91  protected:
92  virtual ~QWidgetPanel();
93 
94  osg::ref_ptr<osg::Geode> _geode; // Node containing the box
95  osg::ref_ptr<osg::Geometry> _panel; // A panel for rendering the controls
96  osg::ref_ptr<osg::Geometry> _panelBack; // Controls mirrored on back of panel
97  osg::ref_ptr<QWidgetImage> _image; // The image to which controls are drawn
98 
99  private:
100  static const double DEFAULT_LENGTH;
101  static const double DEFAULT_PIXELS_PER_UNIT; // Only when QWidget has an invalid preferred size
102 
103  std::vector<QWidget *> _ignoredWidgets;
104 
105  void _init();
106  void _rescaleWidget();
107  };
108 
109 } // !namespace OpenFrames
110 
111 #endif
ReferenceFrame with Qt control panel on plane.
Definition: QWidgetPanel.hpp:51
Definition: CoordinateAxes.hpp:29
Definition: ReferenceFrame.hpp:54
osg::Image * getImage()
Definition: QWidgetPanel.hpp:76