61 #include "QtSceneGraphWidget.hh"
62 #include "QtMaterialDialog.hh"
63 #include "QtTextureDialog.hh"
64 #include "QtClippingDialog.hh"
65 #include "QtCoordFrameDialog.hh"
66 #include "QtShaderDialog.hh"
68 #include "../Scenegraph/MaterialNode.hh"
69 #include "../Scenegraph/TextureNode.hh"
70 #include "../Scenegraph/ClippingNode.hh"
71 #include "../Scenegraph/ShaderNode.hh"
72 #include "../Scenegraph/CoordFrameNode.hh"
90 SceneGraphWidgetGenerator::SceneGraphWidgetGenerator() {
95 std::cerr <<
"SceneGraphWidgetGenerator::getWidget not implemented!" << std::endl;
101 std::cerr <<
"SceneGraphWidgetGenerator::canHandle not implemented!" << _className << std::endl;
107 std::cerr <<
"SceneGraphWidgetGenerator::canHandle not implemented!" << std::endl;
108 return std::string(
"Unset Type");
113 std::cerr <<
"SceneGraphWidgetGenerator::contextMenuName not implemented!" << std::endl;
114 return QString(
"Context Menu name unset");
120 QTreeWidget( _parent ),
126 setRootIsDecorated(
true);
128 setSortingEnabled(
false );
130 setSelectionMode( QAbstractItemView::SingleSelection );
135 QStringList column_names;
136 column_names.append(
"Node" );
137 column_names.append(
"Type" );
138 column_names.append(
"Status" );
139 column_names.append(
"Mode" );
141 setHeaderLabels( column_names );
143 modeMenu_ =
new QMenu(
this );
150 statusActions_.menu_ =
new QMenu(
this );
152 QActionGroup * status_ag =
new QActionGroup( statusActions_.menu_ );
153 status_ag->setExclusive(
true );
155 statusActions_.actionActive_ =
new QAction(
"Active", status_ag );
156 statusActions_.actionActive_->setCheckable(
true );
159 statusActions_.actionHideNode_ =
new QAction(
"Hide Node", status_ag );
160 statusActions_.actionHideNode_->setCheckable(
true );
163 statusActions_.actionHideChildren_ =
new QAction(
"Hide Children", status_ag );
164 statusActions_.actionHideChildren_->setCheckable(
true );
167 statusActions_.actionHideSubtree_ =
new QAction(
"Hide Subtree", status_ag );
168 statusActions_.actionHideSubtree_->setCheckable(
true );
171 statusActions_.menu_->addActions( status_ag->actions() );
173 connect( status_ag, SIGNAL( triggered( QAction * ) ),
174 this, SLOT( slotStatusMenu( QAction * ) ) );
178 connect(
this, SIGNAL(itemPressed(QTreeWidgetItem*,
int) ),
179 this, SLOT(slotItemPressed(QTreeWidgetItem*,
int)) );
181 connect(
this, SIGNAL(itemExpanded(QTreeWidgetItem*) ),
182 this, SLOT(slotItemExpandedOrCollapsed(QTreeWidgetItem*)) );
183 connect(
this, SIGNAL(itemCollapsed(QTreeWidgetItem*) ),
184 this, SLOT(slotItemExpandedOrCollapsed(QTreeWidgetItem*)) );
188 setMinimumWidth( 600 );
189 setMinimumHeight( 400 );
205 Item * item =
new Item(
this, _node );
209 for (; cRIt != cREnd; ++cRIt)
214 resizeColumnToContents( 0 );
215 resizeColumnToContents( 1 );
216 resizeColumnToContents( 2 );
217 resizeColumnToContents( 3 );
219 setMinimumWidth( columnWidth(0) + columnWidth(1) + columnWidth(2) + columnWidth(3) );
231 Item* item =
new Item( _parent, _node );
236 for (; cRIt != cREnd; ++cRIt)
246 slotItemExpandedOrCollapsed( QTreeWidgetItem* )
248 resizeColumnToContents( 0 );
257 slotItemPressed( QTreeWidgetItem * _item,
263 curItem_ =
static_cast<Item*
>(_item);
270 statusActions_.actionActive_ ->setChecked(
false );
271 statusActions_.actionHideNode_ ->setChecked(
false );
272 statusActions_.actionHideChildren_->setChecked(
false );
273 statusActions_.actionHideSubtree_ ->setChecked(
false );
278 statusActions_.actionActive_->setChecked(
true );
281 statusActions_.actionHideNode_->setChecked(
true );
284 statusActions_.actionHideChildren_->setChecked(
true );
287 statusActions_.actionHideSubtree_->setChecked(
true );
290 statusActions_.menu_->popup( QCursor::pos() );
299 QActionGroup * modeGroup =
new QActionGroup( modeMenu_ );
300 modeGroup->setExclusive(
true );
301 connect( modeGroup, SIGNAL( triggered( QAction * ) ),
302 this, SLOT( slotModeMenu( QAction * ) ) );
309 std::vector< ACG::SceneGraph::DrawModes::DrawMode > available_modes( availDrawModes.getAtomicDrawModes() );
312 for (
unsigned int i = 0; i < available_modes.size(); ++i )
317 QAction * action =
new QAction( descr.c_str(), modeGroup );
318 action->setCheckable(
true );
319 action->setChecked ( currentDrawMode.containsAtomicDrawMode(
id ) ) ;
320 action->setData( QVariant( quint64(
id.getIndex()) ) );
323 modeMenu_->addActions( modeGroup->actions() );
325 if ( dynamic_cast<SceneGraph::MaterialNode*>( node ) )
327 modeMenu_->addSeparator();
328 QAction * action = modeMenu_->addAction(
"Edit material" );
329 connect( action, SIGNAL( triggered() ),
330 this, SLOT( slotEditMaterial() ) );
333 if ( dynamic_cast<SceneGraph::TextureNode*>( node ) )
335 modeMenu_->addSeparator();
336 QAction * action = modeMenu_->addAction(
"Edit texture" );
337 connect( action, SIGNAL( triggered() ),
338 this, SLOT( slotEditTexture() ) );
341 if ( dynamic_cast<SceneGraph::ShaderNode*>( node ) )
343 modeMenu_->addSeparator();
344 QAction * action = modeMenu_->addAction(
"Edit shaders" );
345 connect( action, SIGNAL( triggered() ),
346 this, SLOT( slotEditShader() ) );
349 if ( dynamic_cast<SceneGraph::ClippingNode*>( node ) )
351 modeMenu_->addSeparator();
352 QAction * action = modeMenu_->addAction(
"Edit clip planes" );
353 connect( action, SIGNAL( triggered() ),
354 this, SLOT( slotEditClipPlanes() ) );
357 if ( dynamic_cast<SceneGraph::CoordFrameNode*>( node ) )
359 modeMenu_->addSeparator();
360 QAction * action = modeMenu_->addAction(
"Edit coord frame" );
361 connect( action, SIGNAL( triggered() ),
362 this, SLOT( slotEditCoordinateFrame() ) );
366 if ( generatorMap_.contains( node->
className() ) ) {
367 QWidget* widget = generatorMap_[node->
className()]->getWidget( node );
368 modeMenu_->addAction( generatorMap_[node->
className()]->contextMenuName() , widget, SLOT(show()) );
371 modeMenu_->popup( QCursor::pos() );
384 void QtSceneGraphWidget::slotEditMaterial()
391 QtMaterialDialog* dialog =
new QtMaterialDialog(
this, node );
405 void QtSceneGraphWidget::slotEditTexture()
409 SceneGraph::TextureNode * node =
410 dynamic_cast< SceneGraph::TextureNode *
>( curItem_->node() );
412 QtTextureDialog* dialog =
new QtTextureDialog(
this, node );
426 void QtSceneGraphWidget::slotEditShader()
433 QtShaderDialog* dialog =
new QtShaderDialog(
this, node );
448 void QtSceneGraphWidget::slotEditClipPlanes()
452 SceneGraph::ClippingNode * node =
453 dynamic_cast< SceneGraph::ClippingNode *
>( curItem_->node() );
455 QtClippingDialog * dialog =
new QtClippingDialog(
this, node );
470 void QtSceneGraphWidget::slotEditCoordinateFrame()
474 SceneGraph::CoordFrameNode * node =
475 dynamic_cast< SceneGraph::CoordFrameNode *
>( curItem_->node() );
477 QtCoordFrameDialog * dialog =
new QtCoordFrameDialog(
this, node );
492 void QtSceneGraphWidget::slotModeMenu( QAction * _action )
494 SceneGraph::DrawModes::DrawMode new_drawmode( _action->data().toUInt());
496 curItem_->node()->
drawMode( new_drawmode );
505 void QtSceneGraphWidget::slotStatusMenu( QAction * _action )
509 unsigned int status = _action->data().toUInt();
524 switch(_event->key())
526 case Qt::Key_Shift: shiftPressed_ =
true;
break;
527 default : _event->ignore();
534 switch(_event->key())
536 case Qt::Key_Shift: shiftPressed_ =
false;
break;
537 default : _event->ignore();
544 void QtSceneGraphWidget::expandAll() {
546 QTreeWidget::expandAll();
548 resizeColumnToContents(0);
551 void QtSceneGraphWidget::updateAll() {
555 QTreeWidget::expandAll();
558 resizeColumnToContents(0);
574 if ( generatorMap_.contains( _generator->
handles() ) ) {
575 std::cerr <<
"Already handled" << std::endl;
580 generatorMap_[_generator->
handles() ] = _generator;
591 QtSceneGraphWidget::Item::Item( QTreeWidget * _parent,
593 : QTreeWidgetItem(_parent), node_(_node)
602 QtSceneGraphWidget::Item::Item( Item * _parent,
604 : QTreeWidgetItem(_parent), node_(_node)
614 QtSceneGraphWidget::Item::update()
616 QString name = tr(
"%1 @ 0x%2")
617 .arg(node_->
name().c_str())
618 .arg(reinterpret_cast<uintptr_t>(node_), 0, 16);
619 setText( 0, name.toStdString().c_str());
638 QtSceneGraphDialog( QWidget* _parent,
644 QVBoxLayout* l =
new QVBoxLayout(
this );
646 QWidget* buttons =
new QWidget(
this);
647 QHBoxLayout* butLayout =
new QHBoxLayout(buttons);
653 QPushButton* expAll =
new QPushButton(
"Expand all");
654 QPushButton* collAll =
new QPushButton(
"Collapse all");
655 QPushButton* updAll =
new QPushButton(
"Update all");
657 butLayout->addWidget(expAll);
658 butLayout->addWidget(collAll);
659 butLayout->addWidget(updAll);
661 l->addWidget(buttons);
669 connect(expAll, SIGNAL(pressed()), sgw_, SLOT(expandAll()));
670 connect(collAll, SIGNAL(pressed()), sgw_, SLOT(collapseAll()));
671 connect(updAll, SIGNAL(pressed()), sgw_, SLOT(updateAll()));
ACG::SceneGraph::ShaderNode ShaderNode
Simple Name for ShaderNode.
void keyPressEvent(QKeyEvent *_event)
key events
std::vector< BaseNode * >::reverse_iterator ChildRIter
allows to reverse iterate over children
Hide this node and its children.
Namespace providing different geometric functions concerning angles.
virtual const std::string & className() const =0
Return class name (implemented by the ACG_CLASSNAME macro)
std::string name() const
Returns: name of node (needs not be unique)
virtual QWidget * getWidget(SceneGraph::BaseNode *_node)
Get a widget for this Node.
ACG::SceneGraph::MaterialNode MaterialNode
Materialnode.
virtual QString contextMenuName()
Return a name for your widget in the context menu.
bool addWidgetGenerator(SceneGraphWidgetGenerator *_generator)
Add a node widget handler.
void signalNodeChanged(ACG::SceneGraph::BaseNode *_node)
ChildRIter childrenRBegin()
Returns: reverse begin-iterator of children.
DrawModes::DrawMode drawMode() const
Return the own draw modes of this node.
Draw this node, but hide children.
virtual std::string handles()
return the type this generator handles
ChildRIter childrenREnd()
Returns: reverse end-iterator of children.
virtual DrawModes::DrawMode availableDrawModes() const
void signalNodeChanged(ACG::SceneGraph::BaseNode *_node)
ACG::SceneGraph::BaseNode BaseNode
Base Node.
void update(ACG::SceneGraph::BaseNode *_rootNode)
Update recursively from _rootNode on.
virtual bool canHandle(std::string _className)
returns if the widgets can handle the given class
Hide this node, but draw children.
DrawMode DEFAULT
use the default (global) draw mode and not the node's own.
StatusMode status() const
Get node's status.
QtSceneGraphWidget(QWidget *_parent=0, SceneGraph::BaseNode *_rootNode=0)
default constructor
void keyReleaseEvent(QKeyEvent *_event)
key events
void update(ACG::SceneGraph::BaseNode *_rootNode)
Update recursively from _rootNode on.
std::string description() const
void set_status(StatusMode _s)
Set the status of this node.