Commit f2a2ee91 authored by Matthias Möller's avatar Matthias Möller

replace QtWidgetNode class

refs #1411

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@16807 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 26d7f9fb
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 8876 $ *
* $Author: dekkers $ *
* $Date: 2010-04-01 14:31:02 +0200 (Do, 01. Apr 2010) $ *
* *
\*===========================================================================*/
//=============================================================================
//
// CLASS QtWidgetNode - IMPLEMENTATION
//
//=============================================================================
//== INCLUDES =================================================================
#include "QtWidgetNode.hh"
#include <ACG/GL/gl.hh>
//== NAMESPACES ===============================================================
namespace ACG {
namespace SceneGraph {
//== IMPLEMENTATION ==========================================================
// Example test code
// QWidget* testwidget = new QWidget();
// QPushButton* button = new QPushButton(testwidget);
// button->setText("Testbutton");
// ACG::SceneGraph::QtWidgetNode* node = new ACG::SceneGraph::QtWidgetNode(testwidget,glScene_,PluginFunctions::getSceneGraphRootNode());
void
QtWidgetNode::
boundingBox(Vec3d& /*_bbMin*/, Vec3d& /*_bbMax*/)
{
// No bounding box as this experiment is not really in the scene but above it
}
//----------------------------------------------------------------------------
DrawModes::DrawMode
QtWidgetNode::
availableDrawModes() const
{
return ( DrawModes::SOLID_FLAT_SHADED );
}
//----------------------------------------------------------------------------
void
QtWidgetNode::
draw(GLState& _state , const DrawModes::DrawMode& /*_drawMode*/)
{
// Project 3d point onto screen
ACG::Vec3d projected = _state.project(position_);
// Translate widget position to be at the correct position
QTransform transform;
transform.translate(projected[0],_state.viewport_height() - projected[1]);
item_->setTransform(transform);
}
//=============================================================================
} // namespace SceneGraph
} // namespace ACG
//=============================================================================
This diff is collapsed.
......@@ -34,34 +34,32 @@
/*===========================================================================*\
* *
* $Revision: 8876 $ *
* $Author: dekkers $ *
* $Date: 2010-04-01 14:31:02 +0200 (Do, 01. Apr 2010) $ *
* $Revision: 16232 $ *
* $Author: moebius $ *
* $Date: 2013-02-01 16:14:37 +0100 (Fri, 01 Feb 2013) $ *
* *
\*===========================================================================*/
//=============================================================================
//
// CLASS QtWidgetNode
//
//=============================================================================
#ifndef ACG_QTWIDGETNODE_HH
#define ACG_QTWIDGETNODE_HH
#ifndef QT_WIDGET_NODE_HH
#define QT_WIDGET_NODE_HH
//== INCLUDES =================================================================
#include <ObjectTypes/Plane/PlaneType.hh>
#include <ACG/Scenegraph/BaseNode.hh>
#include <ACG/Scenegraph/DrawModes.hh>
#include <QGraphicsScene>
#include <QGraphicsProxyWidget>
#include <ACG/GL/VertexDeclaration.hh>
#include <ACG/GL/IRenderer.hh>
#include <ACG/GL/GLPrimitives.hh>
#include <QObject>
#include <QWidget>
#include <vector>
//== NAMESPACES ===============================================================
......@@ -70,65 +68,98 @@ namespace SceneGraph {
//== CLASS DEFINITION =========================================================
class DLLEXPORT QtWidgetNode : public BaseNode
{
public:
/** \brief Construct a plane rendering node
*
* @param _parent The parent node in the scenegraph
* @param _name The name of the new node (visible in the scenegraph dialogs)
* @param _plane A pointer to an existing plane
*/
QtWidgetNode(QWidget* _widget, BaseNode *_parent = 0, std::string _name = "<QtWidgetNode>");
/** \class QtWidgetNode QtWidgetNode.hh <ACG/QtScenegraph/QtWidgetNode.hh>
/// destructor
~QtWidgetNode();
Integrates QtWidgets directly into the OpenGL scenegraph
**/
/// static name of this class
ACG_CLASSNAME(QtWidgetNode);
/// return available draw modes
ACG::SceneGraph::DrawModes::DrawMode availableDrawModes() const;
/// update bounding box
void boundingBox(ACG::Vec3d & _bbMin, ACG::Vec3d & _bbMax);
/** \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
*/
void getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::SceneGraph::DrawModes::DrawMode& _drawMode , const ACG::SceneGraph::Material* _mat);
void mouseEvent(GLState& _state, QMouseEvent* _event);
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);
class ACGDLLEXPORT QtWidgetNode : public BaseNode
{
public:
/// default constructor
QtWidgetNode( QWidget* _widget,
QGraphicsScene* _scene,
BaseNode* _parent = 0,
std::string _name="<QtWidgetNode>" )
: BaseNode(_parent, _name),
position_(ACG::Vec3d(0.0,0.0,0.0)),
widget_(_widget)
{
// Get the 3d proxxy of the widget
QGraphicsProxyWidget *proxy = _scene->addWidget(_widget);
// Store the Graphicsitem to apply transforms to it
item_ = proxy->graphicsItem ();
}
/// destructor
~QtWidgetNode() {}
/// static name of this class
ACG_CLASSNAME(QtWidgetNode);
/// return available draw modes
DrawModes::DrawMode availableDrawModes() const;
/// update bounding box
void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
/// draw points and normals
void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
void position(ACG::Vec3d _position) { position_ = _position; };
ACG::Vec3d position() { return position_; };
private:
// The 3d point which should be followed by the widget
ACG::Vec3d position_;
QWidget* widget_;
QGraphicsItem* item_;
};
class NodeEventFilter : public QObject
{
public:
NodeEventFilter(QtWidgetNode* p){node_ = p;}
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 // ACG_QTWIDGETNODE_HH defined
#endif // QT_WIDGET_NODE_HH defined
//=============================================================================
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment