51 #include "QtSceneGraphWidget.hh" 52 #include "QtMaterialDialog.hh" 53 #include "QtTextureDialog.hh" 54 #include "QtClippingDialog.hh" 55 #include "QtCoordFrameDialog.hh" 56 #include "QtShaderDialog.hh" 58 #include "../Scenegraph/MaterialNode.hh" 59 #include "../Scenegraph/TextureNode.hh" 60 #include "../Scenegraph/ClippingNode.hh" 61 #include "../Scenegraph/ShaderNode.hh" 62 #include "../Scenegraph/CoordFrameNode.hh" 64 #include "ui_QtMaterialDialogUi.h" 82 SceneGraphWidgetGenerator::SceneGraphWidgetGenerator() {
87 std::cerr <<
"SceneGraphWidgetGenerator::getWidget not implemented!" << std::endl;
93 std::cerr <<
"SceneGraphWidgetGenerator::canHandle not implemented!" << _className << std::endl;
99 std::cerr <<
"SceneGraphWidgetGenerator::canHandle not implemented!" << std::endl;
100 return std::string(
"Unset Type");
105 std::cerr <<
"SceneGraphWidgetGenerator::contextMenuName not implemented!" << std::endl;
106 return QString(
"Context Menu name unset");
112 QTreeWidget( _parent ),
118 setRootIsDecorated(
true);
120 setSortingEnabled(
false );
122 setSelectionMode( QAbstractItemView::SingleSelection );
127 QStringList column_names;
128 column_names.append(
"Node" );
129 column_names.append(
"Type" );
130 column_names.append(
"Status" );
131 column_names.append(
"Mode" );
133 setHeaderLabels( column_names );
135 modeMenu_ =
new QMenu(
this );
142 statusActions_.menu_ =
new QMenu(
this );
144 QActionGroup * status_ag =
new QActionGroup( statusActions_.menu_ );
145 status_ag->setExclusive(
true );
147 statusActions_.actionActive_ =
new QAction(
"Active", status_ag );
148 statusActions_.actionActive_->setCheckable(
true );
151 statusActions_.actionHideNode_ =
new QAction(
"Hide Node", status_ag );
152 statusActions_.actionHideNode_->setCheckable(
true );
155 statusActions_.actionHideChildren_ =
new QAction(
"Hide Children", status_ag );
156 statusActions_.actionHideChildren_->setCheckable(
true );
159 statusActions_.actionHideSubtree_ =
new QAction(
"Hide Subtree", status_ag );
160 statusActions_.actionHideSubtree_->setCheckable(
true );
163 statusActions_.menu_->addActions( status_ag->actions() );
165 connect( status_ag, SIGNAL( triggered( QAction * ) ),
166 this, SLOT( slotStatusMenu( QAction * ) ) );
170 connect(
this, SIGNAL(itemPressed(QTreeWidgetItem*,
int) ),
171 this, SLOT(slotItemPressed(QTreeWidgetItem*,
int)) );
173 connect(
this, SIGNAL(itemExpanded(QTreeWidgetItem*) ),
174 this, SLOT(slotItemExpandedOrCollapsed(QTreeWidgetItem*)) );
175 connect(
this, SIGNAL(itemCollapsed(QTreeWidgetItem*) ),
176 this, SLOT(slotItemExpandedOrCollapsed(QTreeWidgetItem*)) );
180 setMinimumWidth( 600 );
181 setMinimumHeight( 400 );
197 Item * item =
new Item(
this, _node );
201 for (; cRIt != cREnd; ++cRIt)
206 resizeColumnToContents( 0 );
207 resizeColumnToContents( 1 );
208 resizeColumnToContents( 2 );
209 resizeColumnToContents( 3 );
211 setMinimumWidth( columnWidth(0) + columnWidth(1) + columnWidth(2) + columnWidth(3) );
223 Item* item =
new Item( _parent, _node );
228 for (; cRIt != cREnd; ++cRIt)
238 slotItemExpandedOrCollapsed( QTreeWidgetItem* )
240 resizeColumnToContents( 0 );
249 slotItemPressed( QTreeWidgetItem * _item,
255 curItem_ =
static_cast<Item*
>(_item);
262 statusActions_.actionActive_ ->setChecked(
false );
263 statusActions_.actionHideNode_ ->setChecked(
false );
264 statusActions_.actionHideChildren_->setChecked(
false );
265 statusActions_.actionHideSubtree_ ->setChecked(
false );
270 statusActions_.actionActive_->setChecked(
true );
273 statusActions_.actionHideNode_->setChecked(
true );
276 statusActions_.actionHideChildren_->setChecked(
true );
279 statusActions_.actionHideSubtree_->setChecked(
true );
282 statusActions_.menu_->popup( QCursor::pos() );
291 QActionGroup * modeGroup =
new QActionGroup( modeMenu_ );
292 modeGroup->setExclusive(
true );
293 connect( modeGroup, SIGNAL( triggered( QAction * ) ),
294 this, SLOT( slotModeMenu( QAction * ) ) );
301 std::vector< ACG::SceneGraph::DrawModes::DrawMode > available_modes( availDrawModes.getAtomicDrawModes() );
304 for (
unsigned int i = 0; i < available_modes.size(); ++i )
309 QAction * action =
new QAction( descr.c_str(), modeGroup );
310 action->setCheckable(
true );
311 action->setChecked ( currentDrawMode.containsAtomicDrawMode(
id ) ) ;
312 action->setData( QVariant( quint64(
id.getIndex()) ) );
315 modeMenu_->addActions( modeGroup->actions() );
317 if ( dynamic_cast<SceneGraph::MaterialNode*>( node ) )
319 modeMenu_->addSeparator();
320 QAction * action = modeMenu_->addAction(
"Edit material" );
321 connect( action, SIGNAL( triggered() ),
322 this, SLOT( slotEditMaterial() ) );
325 if ( dynamic_cast<SceneGraph::TextureNode*>( node ) )
327 modeMenu_->addSeparator();
328 QAction * action = modeMenu_->addAction(
"Edit texture" );
329 connect( action, SIGNAL( triggered() ),
330 this, SLOT( slotEditTexture() ) );
333 if ( dynamic_cast<SceneGraph::ShaderNode*>( node ) )
335 modeMenu_->addSeparator();
336 QAction * action = modeMenu_->addAction(
"Edit shaders" );
337 connect( action, SIGNAL( triggered() ),
338 this, SLOT( slotEditShader() ) );
341 if ( dynamic_cast<SceneGraph::ClippingNode*>( node ) )
343 modeMenu_->addSeparator();
344 QAction * action = modeMenu_->addAction(
"Edit clip planes" );
345 connect( action, SIGNAL( triggered() ),
346 this, SLOT( slotEditClipPlanes() ) );
349 if ( dynamic_cast<SceneGraph::CoordFrameNode*>( node ) )
351 modeMenu_->addSeparator();
352 QAction * action = modeMenu_->addAction(
"Edit coord frame" );
353 connect( action, SIGNAL( triggered() ),
354 this, SLOT( slotEditCoordinateFrame() ) );
358 if ( generatorMap_.contains( node->
className() ) ) {
359 QWidget* widget = generatorMap_[node->
className()]->getWidget( node );
360 modeMenu_->addAction( generatorMap_[node->
className()]->contextMenuName() , widget, SLOT(show()) );
363 modeMenu_->popup( QCursor::pos() );
376 void QtSceneGraphWidget::slotEditMaterial()
397 void QtSceneGraphWidget::slotEditTexture()
418 void QtSceneGraphWidget::slotEditShader()
440 void QtSceneGraphWidget::slotEditClipPlanes()
462 void QtSceneGraphWidget::slotEditCoordinateFrame()
484 void QtSceneGraphWidget::slotModeMenu( QAction * _action )
488 curItem_->node()->
drawMode( new_drawmode );
497 void QtSceneGraphWidget::slotStatusMenu( QAction * _action )
501 unsigned int status = _action->data().toUInt();
516 switch(_event->key())
518 case Qt::Key_Shift: shiftPressed_ =
true;
break;
519 default : _event->ignore();
526 switch(_event->key())
528 case Qt::Key_Shift: shiftPressed_ =
false;
break;
529 default : _event->ignore();
536 void QtSceneGraphWidget::expandAll() {
538 QTreeWidget::expandAll();
540 resizeColumnToContents(0);
543 void QtSceneGraphWidget::updateAll() {
547 QTreeWidget::expandAll();
550 resizeColumnToContents(0);
566 if ( generatorMap_.contains( _generator->
handles() ) ) {
567 std::cerr <<
"Already handled" << std::endl;
572 generatorMap_[_generator->
handles() ] = _generator;
583 QtSceneGraphWidget::Item::Item( QTreeWidget * _parent,
585 : QTreeWidgetItem(_parent), node_(_node)
594 QtSceneGraphWidget::Item::Item(
Item * _parent,
596 : QTreeWidgetItem(_parent), node_(_node)
606 QtSceneGraphWidget::Item::update()
608 QString name = tr(
"%1 @ 0x%2")
609 .arg(node_->name().c_str())
610 .arg(reinterpret_cast<uintptr_t>(node_), 0, 16);
611 setText( 0, name.toStdString().c_str());
612 setText( 1, node_->className().c_str());
614 switch (node_->status())
622 setText( 3, node_->drawMode().description().c_str());
630 QtSceneGraphDialog( QWidget* _parent,
636 QVBoxLayout* l =
new QVBoxLayout(
this );
638 QWidget* buttons =
new QWidget(
this);
639 QHBoxLayout* butLayout =
new QHBoxLayout(buttons);
645 QPushButton* expAll =
new QPushButton(
"Expand all");
646 QPushButton* collAll =
new QPushButton(
"Collapse all");
647 QPushButton* updAll =
new QPushButton(
"Update all");
649 butLayout->addWidget(expAll);
650 butLayout->addWidget(collAll);
651 butLayout->addWidget(updAll);
653 l->addWidget(buttons);
661 connect(expAll, SIGNAL(pressed()), sgw_, SLOT(expandAll()));
662 connect(collAll, SIGNAL(pressed()), sgw_, SLOT(collapseAll()));
663 connect(updAll, SIGNAL(pressed()), sgw_, SLOT(updateAll()));
685 sgw_->update(_rootNode);
virtual bool canHandle(std::string _className)
returns if the widgets can handle the given class
Draw this node, but hide children.
Namespace providing different geometric functions concerning angles.
void signalNodeChanged(ACG::SceneGraph::BaseNode *_node)
void keyReleaseEvent(QKeyEvent *_event)
key events
virtual const std::string & className() const =0
Return class name (implemented by the ACG_CLASSNAME macro)
ACG::SceneGraph::BaseNode BaseNode
Base Node.
virtual QString contextMenuName()
Return a name for your widget in the context menu.
ChildRIter childrenREnd()
Returns: reverse end-iterator of children.
void set_status(StatusMode _s)
Set the status of this node.
virtual std::string handles()
return the type this generator handles
Hide this node, but draw children.
std::vector< BaseNode * >::reverse_iterator ChildRIter
allows to reverse iterate over children
Hide this node and its children.
DrawModes::DrawMode drawMode() const
Return the own draw modes of this node.
void update(ACG::SceneGraph::BaseNode *_rootNode)
Update recursively from _rootNode on.
DrawMode DEFAULT
use the default (global) draw mode and not the node's own.
virtual DrawModes::DrawMode availableDrawModes() const
void keyPressEvent(QKeyEvent *_event)
key events
void update(ACG::SceneGraph::BaseNode *_rootNode)
Update recursively from _rootNode on.
std::string description() const
virtual QWidget * getWidget(SceneGraph::BaseNode *_node)
Get a widget for this Node.
QtSceneGraphWidget(QWidget *_parent=0, SceneGraph::BaseNode *_rootNode=0)
default constructor
bool addWidgetGenerator(SceneGraphWidgetGenerator *_generator)
Add a node widget handler.
ChildRIter childrenRBegin()
Returns: reverse begin-iterator of children.
StatusMode status() const
Get node's status.