Commit 9825f10c authored by Matthias Möller's avatar Matthias Möller

add QtWidgetType as a new ObjectType

refs #1411

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@16809 383ad7c9-94d9-4d36-a494-682f7c89f535
parent f2a2ee91
/*===========================================================================*\
* *
* 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: 15085 $ *
* $LastChangedBy: moebius $ *
* $Date: 2012-07-25 08:57:39 +0200 (Wed, 25 Jul 2012) $ *
* *
\*===========================================================================*/
//=============================================================================
//
// Plugin Functions for QtWidgets
//
//=============================================================================
#include <OpenFlipper/common/Types.hh>
#include "PluginFunctionsQtWidget.hh"
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
namespace PluginFunctions {
// ===============================================================================
// Get objects
// ===============================================================================
bool getObject( int _identifier , QtWidgetObject*& _object ) {
if ( _identifier == -1 ) {
_object = 0;
return false;
}
// Get object by using the map accelerated plugin function
BaseObjectData* object = 0;
PluginFunctions::getObject(_identifier,object);
_object = dynamic_cast< QtWidgetObject* >(object);
return ( _object != 0 );
}
// ===============================================================================
// Getting data from objects and casting between them
// ===============================================================================
QtWidgetNode* qtWidgetNode( BaseObjectData* _object ) {
if ( _object->dataType(DATA_QT_WIDGET) ) {
QtWidgetObject* object = dynamic_cast< QtWidgetObject* >(_object);
return object->qtWidgetNode();
} else
return 0;
}
QtWidgetObject* qtWidgetObject( BaseObjectData* _object ) {
if ( ! _object->dataType(DATA_QT_WIDGET) )
return 0;
return dynamic_cast< QtWidgetObject* >( _object );
}
}
/*===========================================================================*\
* *
* 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: 10745 $ *
* $LastChangedBy: moebius $ *
* $Date: 2011-01-26 10:23:50 +0100 (Wed, 26 Jan 2011) $ *
* *
\*===========================================================================*/
//=============================================================================
//
// Standard Functions
//
//=============================================================================
/**
* \file PluginFunctionsQtWidget.hh
* This file contains functions which can be used by plugins to access QtWidgets in the framework.
*/
//
#ifndef PLUGINFUNCTIONSQTWIDGET_HH
#define PLUGINFUNCTIONSQTWIDGET_HH
#include <OpenFlipper/common/Types.hh>
#include "QtWidget.hh"
/** The Namespace PluginFunctions contains functions for all plugins. */
namespace PluginFunctions {
/** This functions returns the object with the given id if it is a QtWidgetObject.
* See get_object( int _identifier , BaseObject*& _object ) for more details.
*/
DLLEXPORT
bool getObject( int _identifier , QtWidgetObject*& _object );
/** \brief Get a QtWidgetNode from an object.
*
* @param _object The object should be of type BaseDataObject. If the content is a QtWidget, a
* QtWidgetNode will be returned. Otherwise a NULL pointer is returned.
*/
DLLEXPORT
QtWidgetNode* qtWidgetNode( BaseObjectData* _object );
/** \brief Cast an BaseObject to a QtWidgetObject if possible
*
* @param _object The object should be of type BaseDataObject. If the content is a QtWidget, a
* a QtWidgetObject is returned. Otherwise a NULL pointer is returned.
*/
DLLEXPORT
QtWidgetObject* qtWidgetObject( BaseObjectData* _object );
}
#endif // PLUGINFUNCTIONSQTWIDGET_HH
/*===========================================================================*\
* *
* 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: 13619 $ *
* $LastChangedBy: moebius $ *
* $Date: 2012-02-01 14:48:01 +0100 (Wed, 01 Feb 2012) $ *
* *
\*===========================================================================*/
/**
* \file QtWidget.hh
* This File contains all required includes for using Qt widgets in scenegraph
*/
#ifndef QT_WIDGET_INCLUDE_HH
#define QT_WIDGET_INCLUDE_HH
//== INCLUDES =================================================================
/** \def DATA_QT_WIDGET
* Use this macro to reference qt widget objects
*/
#define DATA_QT_WIDGET typeId("QtWidget")
#include <ObjectTypes/QtWidget/QtWidgetObject.hh>
#include <ObjectTypes/QtWidget/PluginFunctionsQtWidget.hh>
#include <ObjectTypes/QtWidget/QtWidgetTypes.hh>
//=============================================================================
#endif // QT_WIDGET_INCLUDE_HH defined
//=============================================================================
/*===========================================================================*\
* *
* 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: 14482 $ *
* $LastChangedBy: moebius $ *
* $Date: 2012-04-30 13:31:46 +0200 (Mon, 30 Apr 2012) $ *
* *
\*===========================================================================*/
//=============================================================================
//
// QtWidget Object
//
//=============================================================================
//== INCLUDES =================================================================
#include "QtWidgetObject.hh"
#include "QtWidget.hh"
//== DEFINES ==================================================================
//== TYPEDEFS =================================================================
QtWidgetObject::QtWidgetObject( ) :
BaseObjectData(),
widgetNode_(NULL)
{
setDataType(DATA_QT_WIDGET);
setTypeIcon(DATA_QT_WIDGET,"QtWidgetType.png");
init(NULL);
}
/**
* Copy Constructor - generates a copy of the given object
*/
QtWidgetObject::QtWidgetObject(const QtWidgetObject & _object) :
BaseObjectData(_object),
widgetNode_(NULL)
{
init(_object.widget());
setName( name() );
}
/** Destructor for Light Objects. The destructor deletes the light and all
* Scenegraph nodes associated with the Light or the object.
*/
QtWidgetObject::~QtWidgetObject()
{
// Delete the data attached to this object ( this will remove all perObject data)
// Not the best way to do it but it will work.
// This is only necessary if people use references to the light below and
// they do something with the light in the destructor of their
// perObjectData.
deleteData();
// Move children to parent
BaseNode* parent = static_cast<BaseNode*>(widgetNode_)->parent();
// First, collect all children as the iterator will get invalid if we delete while iterating!
std::vector< BaseNode*> children;
for (BaseNode::ChildIter cIt=widgetNode_->childrenBegin(); cIt!=widgetNode_->childrenEnd(); ++cIt)
children.push_back( (*cIt) );
// Move the children
for (unsigned int i = 0 ; i < children.size(); ++i )
children[i]->set_parent(parent);
// Delete the scenegraph node
delete widgetNode_;
}
/** Cleanup Function for Light Objects. Deletes the contents of the whole object and
* calls QtWidgetObject::init afterwards.
*/
void QtWidgetObject::cleanup() {
BaseObjectData::cleanup();
widgetNode_ = NULL;
setDataType(DATA_QT_WIDGET);
setTypeIcon(DATA_QT_WIDGET,"QtWidgetType.png");
}
/**
* Generate a copy
*/
BaseObject* QtWidgetObject::copy() {
QtWidgetObject* object = new QtWidgetObject(*this);
return dynamic_cast< BaseObject* >(object);
}
/** This function initializes the light object. It creates the scenegraph nodes.
*/
void QtWidgetObject::init(QWidget* _widget) {
widgetNode_ = new QtWidgetNode( _widget ,materialNode() , "QtWidgetNode");
}
// ===============================================================================
// Name/Path Handling
// ===============================================================================
/** Set the name of an object. All Scenegraph nodes are renamed too. It also calls
* BaseObjectData::setName.
*/
void QtWidgetObject::setName( QString _name ) {
BaseObjectData::setName(_name);
std::string nodename = std::string("Qt WidgetNode " + _name.toUtf8() );
widgetNode_->name( nodename );
}
// ===============================================================================
// Visualization
// ===============================================================================
QtWidgetNode* QtWidgetObject::qtWidgetNode() {
return widgetNode_;
}
bool QtWidgetObject::hasNode(BaseNode* _node) {
if ( BaseObjectData::hasNode(_node) )
return true;
if ( _node == widgetNode_ )
return true;
return false;
}
// ===============================================================================
// Object information
// ===============================================================================
/** Returns a string containing all information about the current object. This also
* includes the information provided by BaseObjectData::getObjectinfo
*
* @return String containing the object information
*/
QString QtWidgetObject::getObjectinfo() {
QString output;
output += "========================================================================\n";
output += BaseObjectData::getObjectinfo();
if ( dataType( DATA_QT_WIDGET ) )
output += "Qt Accessible Name: ";
output += widgetNode_->widget()->accessibleName();
output += "\n";
output += "========================================================================\n";
return output;
}
// ===============================================================================
// Picking
// ===============================================================================
/** Given an node index from PluginFunctions::scenegraphPick this function can be used to
* check if the lightNode of the object has been picked.
*
* @param _node_idx Index of the picked light node
* @return bool if the lightNode of this object is the picking target.
*/
bool QtWidgetObject::picked( uint _node_idx ) {
return ( _node_idx == widgetNode_->id() );
}
void QtWidgetObject::enablePicking( bool _enable ) {
widgetNode_->enablePicking( _enable );
}
bool QtWidgetObject::pickingEnabled() {
return widgetNode_->pickingEnabled();
}
void QtWidgetObject::show() {
if ( !visible_ ) {
BaseObjectData::show();
visible_ = true;
static_cast<BaseNode*>(widgetNode_)->show();
emit visibilityChanged( id() );
}
}
void QtWidgetObject::hide() {
if ( visible_ ) {
BaseObjectData::hide();
visible_ = false;
static_cast<BaseNode*>(widgetNode_)->hide();
emit visibilityChanged( id() );
}
}
void QtWidgetObject::visible(bool _visible) {
if ( _visible )
show();
else
hide();
}
bool QtWidgetObject::visible() {
return visible_;
}
//=============================================================================
/*===========================================================================*\
* *
* 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: 14482 $ *
* $LastChangedBy: moebius $ *
* $Date: 2012-04-30 13:31:46 +0200 (Mon, 30 Apr 2012) $ *
* *
\*===========================================================================*/
//=============================================================================
//
// Types
//
//=============================================================================
/**
* \file QtWidgetObject.hh
* This File contains the QtWidget Object
*/
#ifndef QT_WIDGET_OBJECT_HH
#define QT_WIDGET_OBJECT_HH
//== INCLUDES =================================================================
#include <OpenFlipper/common/BaseObjectData.hh>
#include <QWidget>
#include "QtWidgetTypes.hh"
//== TYPEDEFS =================================================================
// //== CLASS DEFINITION =========================================================
class DLLEXPORT QtWidgetObject : public BaseObjectData {
public:
/// constructor
QtWidgetObject();
/** \brief copy constructor
*
* Create a copy of this object
*/
QtWidgetObject(const QtWidgetObject& _object);
/// destructor
virtual ~QtWidgetObject();
/// Reset current object, including all related nodes.
virtual void cleanup();
/** return a full copy of this object ( All scenegraph nodes will be created )
* but the object will not be a part of the object tree.
*/
BaseObject* copy();
protected:
/// Initialize current object, including all related nodes.
virtual void init(QWidget* _widget);
//===========================================================================
/** @name Name and Path handling
* @{ */
//===========================================================================
public:
/// Set the name of the Object
void setName( QString _name );
/** @} */
//===========================================================================
/** @name Contents
* @{ */
//===========================================================================
public:
QWidget* widget()const{return widgetNode_->widget();}
void setWidget(QWidget* _widget){widgetNode_->setWidget(_widget);}
/** @} */
//===========================================================================
/** @name Visualization
* @{ */
//===========================================================================
public:
/// Get the scenegraph Node
ACG::SceneGraph::QtWidgetNode* qtWidgetNode();
virtual bool hasNode(BaseNode* _node);
private:
QtWidgetNode* widgetNode_;
/** @} */
//===========================================================================
/** @name Object Information
* @{ */
//===========================================================================
public:
/// Get all Info for the Object as a string
QString getObjectinfo();
/** @} */
//===========================================================================
/** @name Picking
* @{ */
//===========================================================================
public:
/// detect if the node has been picked
bool picked( uint _node_idx );
/// Enable or disable picking for this Object
void enablePicking( bool _enable );
/// Check if picking is enabled for this Object
bool pickingEnabled();
void mouseEvent(QMouseEvent* _event){widgetNode_->mouseEvent(_event);}
/** @} */
public:
/// Show Node
virtual void visible(bool _visible);
/// Show Node
virtual bool visible();