Developer Documentation
Loading...
Searching...
No Matches
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//=============================================================================
46//
47// QtWidget Object
48//
49//=============================================================================
50
51//== INCLUDES =================================================================
52#include "QtWidgetObject.hh"
53#include "QtWidget.hh"
54
55//== DEFINES ==================================================================
56
57//== TYPEDEFS =================================================================
60 widgetNode_(NULL)
61{
63 setTypeIcon(DATA_QT_WIDGET,"QtWidgetType.png");
64 init(NULL);
65}
66
71 BaseObjectData(_object),
72 widgetNode_(NULL)
73{
74 init(_object.widget());
75 setName( name() );
76}
77
82{
83 // Delete the data attached to this object ( this will remove all perObject data)
84 // Not the best way to do it but it will work.
85 // This is only necessary if people use references to the light below and
86 // they do something with the light in the destructor of their
87 // perObjectData.
88 deleteData();
89
90 // Move children to parent
91 BaseNode* parent = static_cast<BaseNode*>(widgetNode_)->parent();
92
93 // First, collect all children as the iterator will get invalid if we delete while iterating!
94 std::vector< BaseNode*> children;
96 children.push_back( (*cIt) );
97
98 // Move the children
99 for (unsigned int i = 0 ; i < children.size(); ++i )
100 children[i]->set_parent(parent);
101
102 // Delete the scenegraph node
103 delete widgetNode_;
104}
105
110
112
113 widgetNode_ = NULL;
114
116 setTypeIcon(DATA_QT_WIDGET,"QtWidgetType.png");
117
118}
119
124 QtWidgetObject* object = new QtWidgetObject(*this);
125 return dynamic_cast< BaseObject* >(object);
126}
127
130void QtWidgetObject::init(QWidget* _widget) {
131
132 widgetNode_ = new QtWidgetNode( _widget ,materialNode() , "QtWidgetNode");
133}
134
135// ===============================================================================
136// Name/Path Handling
137// ===============================================================================
138
142void QtWidgetObject::setName( QString _name ) {
144
145 std::string nodename = std::string("Qt WidgetNode " + _name.toUtf8() );
146 widgetNode_->name( nodename );
147}
148
149// ===============================================================================
150// Visualization
151// ===============================================================================
152
156
157
159 if ( BaseObjectData::hasNode(_node) )
160 return true;
161
162 if ( _node == widgetNode_ )
163 return true;
164
165 return false;
166}
167
168// ===============================================================================
169// Object information
170// ===============================================================================
171
178 QString output;
179
180 output += "========================================================================\n";
182
183 if ( dataType( DATA_QT_WIDGET ) ) {
184 output += "Qt Accessible Name: ";
185 output += widgetNode_->widget()->accessibleName();
186 output += "\n";
187 } else {
188 output += "!!Unable to access data type DATA_QT_WIDGET ";
189 }
190 output += "========================================================================\n";
191 return output;
192}
193
194// ===============================================================================
195// Picking
196// ===============================================================================
197
204bool QtWidgetObject::picked( uint _node_idx ) {
205 return ( _node_idx == widgetNode_->id() );
206}
207
208void QtWidgetObject::enablePicking( bool _enable ) {
209 widgetNode_->enablePicking( _enable );
210}
211
215
217 if ( !visible_ ) {
219 visible_ = true;
220
221 static_cast<BaseNode*>(widgetNode_)->show();
222
223 emit visibilityChanged( id() );
224 }
225}
226
228 if ( visible_ ) {
230 visible_ = false;
231 static_cast<BaseNode*>(widgetNode_)->hide();
232
233 emit visibilityChanged( id() );
234 }
235}
236
237void QtWidgetObject::visible(bool _visible) {
238 if ( _visible )
239 show();
240 else
241 hide();
242}
243
245 return visible_;
246}
247
248
249// ===============================================================================
250// Update
251// ===============================================================================
252
256
257
258//=============================================================================
259
DLLEXPORT void setTypeIcon(DataType _id, const QString &_icon)
Set an Icon for a given DataType.
Definition Types.cc:223
ACG::SceneGraph::QtWidgetNode QtWidgetNode
Simple Name for QtWidgetNode.
#define DATA_QT_WIDGET
Definition QtWidget.hh:59
ChildIter childrenBegin()
Returns: begin-iterator of children.
Definition BaseNode.hh:294
ChildIter childrenEnd()
Returns: end-iterator of children.
Definition BaseNode.hh:298
void enablePicking(bool _enable)
Definition BaseNode.hh:265
std::vector< BaseNode * >::iterator ChildIter
allows to iterate over children
Definition BaseNode.hh:286
unsigned int id() const
Definition BaseNode.hh:423
std::string name() const
Returns: name of node (needs not be unique)
Definition BaseNode.hh:415
virtual void show()
Sets the whole Scenegraph subtree of this node to visible.
virtual void hide()
Sets the whole Scenegraph subtree of this node to invisible.
virtual void setName(QString _name) override
path to the file from which the object is loaded ( defaults to "." )
MaterialNode * materialNode()
get a pointer to the materialnode
virtual void cleanup() override
virtual bool hasNode(BaseNode *_node)
Check if the given node is owned by this object.
virtual QString getObjectinfo()
Get all Info for the Object as a string.
QString name() const
return the name of the object. The name defaults to NONAME if unset.
BaseObject * parent()
Get the parent item ( 0 if rootitem )
void setDataType(DataType _type)
void visibilityChanged(int _objectId)
virtual void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
void deleteData()
Delete all data attached to this object ( calls delete on each object )
DataType dataType() const
void enablePicking(bool _enable)
Enable or disable picking for this Object.
QtWidgetObject()
constructor
bool pickingEnabled()
Check if picking is enabled for this Object.
QtWidgetNode * widgetNode_
Get the scenegraph Node.
virtual ~QtWidgetObject()
destructor
virtual void init(QWidget *_widget)
Initialize current object, including all related nodes.
ACG::SceneGraph::QtWidgetNode * qtWidgetNode()
Get the scenegraph Node.
BaseObject * copy()
QString getObjectinfo()
Get all Info for the Object as a string.
virtual void show()
Show Node.
virtual void hide()
Hide Node.
void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
bool picked(uint _node_idx)
detect if the node has been picked
virtual bool visible()
Show Node.
virtual void cleanup()
Reset current object, including all related nodes.
void setName(QString _name)
Set the name of the Object.
virtual bool hasNode(BaseNode *_node)
Get the scenegraph Node.
Update type class.
Definition UpdateType.hh:59