QtWidgetNode.hh 7.42 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
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
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
 *   $Revision$                                                         *
 *   $Author$                                                      *
 *   $Date$                   *
 *                                                                           *
\*===========================================================================*/

//=============================================================================
//
//  CLASS QtWidgetNode
//
//=============================================================================

#ifndef QT_WIDGET_NODE_HH
#define QT_WIDGET_NODE_HH

//== INCLUDES =================================================================

Martin Heistermann's avatar
Martin Heistermann committed
61
#include <ACG/Geometry/Types/PlaneType.hh>
Jan Möbius's avatar
Jan Möbius committed
62
63
64
65
66
#include <ACG/Scenegraph/BaseNode.hh>
#include <ACG/Scenegraph/DrawModes.hh>
#include <ACG/GL/VertexDeclaration.hh>
#include <ACG/GL/IRenderer.hh>
#include <ACG/GL/GLPrimitives.hh>
Jan Möbius's avatar
Jan Möbius committed
67
68
#include <OpenFlipper/common/ObjectTypeDLLDefines.hh>

Jan Möbius's avatar
Jan Möbius committed
69
70
71
72
73
74
75
76
77
78
79
80
81

#include <QObject>
#include <QWidget>

//== NAMESPACES ===============================================================

namespace ACG {
namespace SceneGraph {

//== CLASS DEFINITION =========================================================

class OBJECTTYPEDLLEXPORT QtWidgetNode : public BaseNode
{
Martin Heistermann's avatar
Martin Heistermann committed
82
    using Plane = ACG::Geometry::Plane;
Jan Möbius's avatar
Jan Möbius committed
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
public:
    /** \brief Construct a QtWidget Node
     *
     * @param _widget The widget which will be rendered in the viewport
     * @param _parent The parent node in the scenegraph
     * @param _name   The name of the new node (visible in the scenegraph dialogs)
     */
    QtWidgetNode(QWidget* _widget, BaseNode *_parent = 0, std::string _name = "<QtWidgetNode>");

    /// destructor
    ~QtWidgetNode();

    /// static name of this class
    ACG_CLASSNAME(QtWidgetNode);

    /// return available draw modes
Jan Möbius's avatar
Jan Möbius committed
99
    ACG::SceneGraph::DrawModes::DrawMode availableDrawModes() const override;
Jan Möbius's avatar
Jan Möbius committed
100
101

    /// update bounding box
Jan Möbius's avatar
Jan Möbius committed
102
    void boundingBox(ACG::Vec3d & _bbMin, ACG::Vec3d & _bbMax) override;
Jan Möbius's avatar
Jan Möbius committed
103
104
105
106
107
108
109
110

    /** \brief Add the objects to the given renderer
     *
     * @param _renderer The renderer which will be used. Add your geometry into this class
     * @param _state    The current GL State when this object is called
     * @param _drawMode The active draw mode
     * @param _mat      Current material
     */
Jan Möbius's avatar
Jan Möbius committed
111
    void getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState&  _state , const ACG::SceneGraph::DrawModes::DrawMode&  _drawMode , const ACG::SceneGraph::Material* _mat) override;
Jan Möbius's avatar
Jan Möbius committed
112
113


Jan Möbius's avatar
Jan Möbius committed
114
    void mouseEvent(GLState& _state, QMouseEvent* _event) override;
Jan Möbius's avatar
Jan Möbius committed
115
116
117
118
119
120
121
122
123
124
    void mouseEvent(QMouseEvent* _event);

    QWidget* widget()const{return widget_;}
    /// set a new widget at the current widgets position (if last widget wasn't zero)
    void setWidget(QWidget* _w);

private:
    class NodeEventFilter : public QObject
    {
    public:
Jan Möbius's avatar
Jan Möbius committed
125
      explicit NodeEventFilter(QtWidgetNode* p){node_ = p;}
Jan Möbius's avatar
Jan Möbius committed
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
    protected:
      bool eventFilter(QObject *obj, QEvent *event);
    private:
      QtWidgetNode *node_;
    } *ef_;

    friend class NodeEventFilter;

    /// create and update the widget texture
    void createTexture();

    /// widgetgeometry will be screen aligned. the width/height and position is in respect to the _state projection matrix
    void createGeometry(GLState& _state);

    /// update geometry on current position with old projection/view matrix
    void updateGeometry();

    /// upload widget plane data to graphics card
    void uploadPlane();

    /// VBO used to render the plane
    unsigned int vbo_;
    GLuint texID_;
    ACG::VertexDeclaration vertexDecl_;

    /// current widget
    QWidget* widget_;

    /// initial widgetHeight/Width. Is 0, if widget is 0 or if plane wasn't initialized with current view/projMatrix
    int oldWidgetWidth_;
    int oldWidgetHeight_;

    /// plane position and dimensions
    Plane plane_;
    bool planeCreated_;

    /// last state
    GLState* state_;

    bool anisotropicSupport_;

};

//=============================================================================
} // namespace SceneGraph
} // namespace ACG

//=============================================================================
#endif // QT_WIDGET_NODE_HH defined
//=============================================================================