Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
QtWidgetObject.cc
1 
2 /*===========================================================================*\
3 * *
4 * OpenFlipper *
5  * Copyright (c) 2001-2015, RWTH-Aachen University *
6  * Department of Computer Graphics and Multimedia *
7  * All rights reserved. *
8  * www.openflipper.org *
9  * *
10  *---------------------------------------------------------------------------*
11  * This file is part of OpenFlipper. *
12  *---------------------------------------------------------------------------*
13  * *
14  * Redistribution and use in source and binary forms, with or without *
15  * modification, are permitted provided that the following conditions *
16  * are met: *
17  * *
18  * 1. Redistributions of source code must retain the above copyright notice, *
19  * this list of conditions and the following disclaimer. *
20  * *
21  * 2. Redistributions in binary form must reproduce the above copyright *
22  * notice, this list of conditions and the following disclaimer in the *
23  * documentation and/or other materials provided with the distribution. *
24  * *
25  * 3. Neither the name of the copyright holder nor the names of its *
26  * contributors may be used to endorse or promote products derived from *
27  * this software without specific prior written permission. *
28  * *
29  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
30  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
31  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
32  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
33  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
34  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
35  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
36  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
37  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
38  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
39  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
40 * *
41 \*===========================================================================*/
42 
43 /*===========================================================================*\
44 * *
45 * $Revision$ *
46 * $LastChangedBy$ *
47 * $Date$ *
48 * *
49 \*===========================================================================*/
50 
51 //=============================================================================
52 //
53 // QtWidget Object
54 //
55 //=============================================================================
56 
57 //== INCLUDES =================================================================
58 #include "QtWidgetObject.hh"
59 #include "QtWidget.hh"
60 
61 //== DEFINES ==================================================================
62 
63 //== TYPEDEFS =================================================================
66  widgetNode_(NULL)
67 {
69  setTypeIcon(DATA_QT_WIDGET,"QtWidgetType.png");
70  init(NULL);
71 }
72 
77  BaseObjectData(_object),
78  widgetNode_(NULL)
79 {
80  init(_object.widget());
81  setName( name() );
82 }
83 
88 {
89  // Delete the data attached to this object ( this will remove all perObject data)
90  // Not the best way to do it but it will work.
91  // This is only necessary if people use references to the light below and
92  // they do something with the light in the destructor of their
93  // perObjectData.
94  deleteData();
95 
96  // Move children to parent
97  BaseNode* parent = static_cast<BaseNode*>(widgetNode_)->parent();
98 
99  // First, collect all children as the iterator will get invalid if we delete while iterating!
100  std::vector< BaseNode*> children;
102  children.push_back( (*cIt) );
103 
104  // Move the children
105  for (unsigned int i = 0 ; i < children.size(); ++i )
106  children[i]->set_parent(parent);
107 
108  // Delete the scenegraph node
109  delete widgetNode_;
110 }
111 
116 
118 
119  widgetNode_ = NULL;
120 
122  setTypeIcon(DATA_QT_WIDGET,"QtWidgetType.png");
123 
124 }
125 
130  QtWidgetObject* object = new QtWidgetObject(*this);
131  return dynamic_cast< BaseObject* >(object);
132 }
133 
136 void QtWidgetObject::init(QWidget* _widget) {
137 
138  widgetNode_ = new QtWidgetNode( _widget ,materialNode() , "QtWidgetNode");
139 }
140 
141 // ===============================================================================
142 // Name/Path Handling
143 // ===============================================================================
144 
148 void QtWidgetObject::setName( QString _name ) {
150 
151  std::string nodename = std::string("Qt WidgetNode " + _name.toUtf8() );
152  widgetNode_->name( nodename );
153 }
154 
155 // ===============================================================================
156 // Visualization
157 // ===============================================================================
158 
160  return widgetNode_;
161 }
162 
163 
165  if ( BaseObjectData::hasNode(_node) )
166  return true;
167 
168  if ( _node == widgetNode_ )
169  return true;
170 
171  return false;
172 }
173 
174 // ===============================================================================
175 // Object information
176 // ===============================================================================
177 
184  QString output;
185 
186  output += "========================================================================\n";
187  output += BaseObjectData::getObjectinfo();
188 
189  if ( dataType( DATA_QT_WIDGET ) )
190  output += "Qt Accessible Name: ";
191  output += widgetNode_->widget()->accessibleName();
192  output += "\n";
193  output += "========================================================================\n";
194  return output;
195 }
196 
197 // ===============================================================================
198 // Picking
199 // ===============================================================================
200 
207 bool QtWidgetObject::picked( uint _node_idx ) {
208  return ( _node_idx == widgetNode_->id() );
209 }
210 
211 void QtWidgetObject::enablePicking( bool _enable ) {
212  widgetNode_->enablePicking( _enable );
213 }
214 
216  return widgetNode_->pickingEnabled();
217 }
218 
220  if ( !visible_ ) {
222  visible_ = true;
223 
224  static_cast<BaseNode*>(widgetNode_)->show();
225 
226  emit visibilityChanged( id() );
227  }
228 }
229 
231  if ( visible_ ) {
233  visible_ = false;
234  static_cast<BaseNode*>(widgetNode_)->hide();
235 
236  emit visibilityChanged( id() );
237  }
238 }
239 
240 void QtWidgetObject::visible(bool _visible) {
241  if ( _visible )
242  show();
243  else
244  hide();
245 }
246 
248  return visible_;
249 }
250 
251 
252 // ===============================================================================
253 // Update
254 // ===============================================================================
255 
257  BaseObject::update(_type);
258 }
259 
260 
261 //=============================================================================
262 
virtual void show()
Show Node.
DLLEXPORT void setTypeIcon(DataType _id, QString _icon)
Set an Icon for a given DataType.
Definition: Types.cc:234
void setName(QString _name)
Set the name of the Object.
ACG::SceneGraph::QtWidgetNode QtWidgetNode
Simple Name for QtWidgetNode.
BaseObject * parent()
Get the parent item ( 0 if rootitem )
Definition: BaseObject.cc:477
virtual void cleanup()
Reset current object, including all related nodes.
std::string name() const
Returns: name of node (needs not be unique)
Definition: MeshNode2T.cc:391
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:255
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:741
bool visible_
Definition: BaseObject.hh:286
QtWidgetObject()
constructor
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:823
Update type class.
Definition: UpdateType.hh:70
ChildIter childrenEnd()
Returns: end-iterator of children.
Definition: MeshNode2T.cc:274
virtual void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
Definition: BaseObject.cc:756
bool pickingEnabled()
Check if picking is enabled for this Object.
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
virtual void show()
Sets the whole Scenegraph subtree of this node to visible.
MaterialNode * materialNode()
get a pointer to the materialnode
BaseObject * copy()
DataType dataType() const
Definition: BaseObject.cc:240
virtual void hide()
Sets the whole Scenegraph subtree of this node to invisible.
virtual void cleanup()
virtual bool hasNode(BaseNode *_node)
Check if the given node is owned by this object.
std::list< BaseNode * >::iterator ChildIter
allows to iterate over children
Definition: BaseNode.hh:262
virtual void hide()
Hide Node.
virtual void init(QWidget *_widget)
Initialize current object, including all related nodes.
QtWidgetNode * widgetNode_
Get the scenegraph Node.
virtual bool hasNode(BaseNode *_node)
Get the scenegraph Node.
void setDataType(DataType _type)
Definition: BaseObject.cc:244
#define DATA_QT_WIDGET
Definition: QtWidget.hh:65
ChildIter childrenBegin()
Returns: begin-iterator of children.
Definition: MeshNode2T.cc:270
void visibilityChanged(int _objectId)
void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
void enablePicking(bool _enable)
Enable or disable picking for this Object.
virtual bool visible()
Show Node.
bool picked(uint _node_idx)
detect if the node has been picked
virtual ~QtWidgetObject()
destructor
QString getObjectinfo()
Get all Info for the Object as a string.
ACG::SceneGraph::QtWidgetNode * qtWidgetNode()
Get the scenegraph Node.