DisplayFlagWidget.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003  *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004  *                                                                             *
00005  * This program is free software; you can redistribute it and/or modify it     *
00006  * under the terms of the GNU General Public License as published by the Free  *
00007  * Software Foundation; either version 2 of the License, or (at your option)   *
00008  * any later version.                                                          *
00009  *                                                                             *
00010  * This program is distributed in the hope that it will be useful, but WITHOUT *
00011  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for    *
00013  * more details.                                                               *
00014  *                                                                             *
00015  * You should have received a copy of the GNU General Public License along     *
00016  * with this program; if not, write to the Free Software Foundation, Inc., 51  *
00017  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.                   *
00018  *******************************************************************************
00019  *                            SOFA :: Applications                             *
00020  *                                                                             *
00021  * Authors: M. Adam, J. Allard, B. Andre, P-J. Bensoussan, S. Cotin, C. Duriez,*
00022  * H. Delingette, F. Falipou, F. Faure, S. Fonteneau, L. Heigeas, C. Mendoza,  *
00023  * M. Nesme, P. Neumann, J-P. de la Plata Alcade, F. Poyer and F. Roy          *
00024  *                                                                             *
00025  * Contact information: contact@sofa-framework.org                             *
00026  ******************************************************************************/
00027 
00028 #include <sofa/gui/qt/DisplayFlagWidget.h>
00029 
00030 namespace sofa
00031 {
00032 
00033   namespace gui
00034   {
00035 
00036     namespace qt
00037     {
00038 
00039       DisplayFlagWidget::DisplayFlagWidget(QWidget* parent, const char* name,  Qt::WFlags f ):
00040     Q3ListView(parent,name,f)
00041       {
00042     addColumn(QString::null);
00043     setRootIsDecorated( TRUE );
00044     setTreeStepSize( 12 );
00045     header()->hide();
00046     clear();
00047 
00048     setMouseTracking(false);
00049 
00050 #ifdef SOFA_QT4
00051     setFocusPolicy(Qt::NoFocus);
00052 #else
00053     setFocusPolicy(QWidget::NoFocus);
00054 #endif
00055     
00056     setFrameShadow(QFrame::Plain);
00057     setFrameShape(QFrame::NoFrame );
00058 
00059     setSortColumn(-1);
00060     Q3CheckListItem* itemShowAll = new Q3CheckListItem(this, "All", Q3CheckListItem::CheckBoxController);
00061     itemShowAll->setOpen(true);
00062     Q3CheckListItem* itemShowVisual    = new Q3CheckListItem(itemShowAll, "Visual", Q3CheckListItem::CheckBoxController);
00063     itemShowVisual->setOpen(true);
00064     itemShowFlag[VISUAL]   = new Q3CheckListItem(itemShowVisual, "Visual Models", Q3CheckListItem::CheckBox);
00065     Q3CheckListItem* itemShowBehavior  = new Q3CheckListItem(itemShowAll, itemShowVisual, "Behavior", Q3CheckListItem::CheckBoxController);
00066     itemShowBehavior->setOpen(true);
00067     itemShowFlag[BEHAVIOR]   = new Q3CheckListItem(itemShowBehavior,  "Behavior Models", Q3CheckListItem::CheckBox);
00068     itemShowFlag[FORCEFIELD]   = new Q3CheckListItem(itemShowBehavior, itemShowFlag[BEHAVIOR], "Force Fields", Q3CheckListItem::CheckBox);
00069     itemShowFlag[INTERACTION]   = new Q3CheckListItem(itemShowBehavior, itemShowFlag[FORCEFIELD],  "Interactions", Q3CheckListItem::CheckBox);
00070     Q3CheckListItem* itemShowCollision = new Q3CheckListItem(itemShowAll, itemShowBehavior, "Collision", Q3CheckListItem::CheckBoxController);
00071     itemShowCollision->setOpen(true);
00072     itemShowFlag[COLLISION]   = new Q3CheckListItem(itemShowCollision,  "Collision Models", Q3CheckListItem::CheckBox);
00073     itemShowFlag[BOUNDING]   = new Q3CheckListItem(itemShowCollision, itemShowFlag[COLLISION], "Bounding Trees", Q3CheckListItem::CheckBox);
00074     Q3CheckListItem* itemShowMapping   = new Q3CheckListItem(itemShowAll, itemShowCollision, "Mapping", Q3CheckListItem::CheckBoxController);
00075     itemShowMapping->setOpen(true);
00076     itemShowFlag[MAPPING]   = new Q3CheckListItem(itemShowMapping,  "Visual Mappings", Q3CheckListItem::CheckBox);
00077     itemShowFlag[MECHANICALMAPPING]   = new Q3CheckListItem(itemShowMapping, itemShowFlag[MAPPING],  "Mechanical Mappings", Q3CheckListItem::CheckBox);
00078     Q3ListViewItem*  itemShowOptions   = new Q3ListViewItem(this, itemShowAll, "Options");
00079     itemShowOptions->setOpen(true);
00080     itemShowFlag[WIREFRAME]   = new Q3CheckListItem(itemShowOptions, "Wire Frame", Q3CheckListItem::CheckBox);
00081     itemShowFlag[NORMALS]   = new Q3CheckListItem(itemShowOptions, itemShowFlag[WIREFRAME], "Normals", Q3CheckListItem::CheckBox);
00082 
00083     insertItem(itemShowAll); 
00084     itemShowAll->insertItem(itemShowVisual); itemShowAll->setOpen(true);
00085     itemShowVisual->insertItem(itemShowFlag[VISUAL]);
00086     itemShowAll->insertItem(itemShowBehavior); 
00087     itemShowBehavior->insertItem(itemShowFlag[BEHAVIOR]);   
00088     itemShowBehavior->insertItem(itemShowFlag[FORCEFIELD]);
00089     itemShowBehavior->insertItem(itemShowFlag[INTERACTION]);
00090     itemShowAll->insertItem(itemShowCollision); 
00091     itemShowCollision->insertItem(itemShowFlag[COLLISION]);
00092     itemShowCollision->insertItem(itemShowFlag[BOUNDING]);
00093     itemShowAll->insertItem(itemShowMapping); 
00094     itemShowMapping->insertItem(itemShowFlag[MAPPING]);
00095     itemShowMapping->insertItem(itemShowFlag[MECHANICALMAPPING]);
00096               
00097     insertItem(itemShowOptions); itemShowOptions->setOpen(true);
00098     itemShowOptions->insertItem(itemShowFlag[WIREFRAME]);
00099     itemShowOptions->insertItem(itemShowFlag[NORMALS]);
00100 
00101     for (int i=0;i<10;++i)  mapFlag.insert(std::make_pair(itemShowFlag[i],i));
00102       }
00103 
00104       void DisplayFlagWidget::findChildren(Q3CheckListItem *item, std::vector<Q3CheckListItem* > &children)
00105       { 
00106     Q3CheckListItem * child = (Q3CheckListItem * )item->firstChild();
00107     while(child) {
00108       children.push_back(child);
00109       findChildren(child,children);
00110       child = (Q3CheckListItem * )child->nextSibling();
00111     }
00112       }
00113 
00114 
00115       void DisplayFlagWidget::contentsMousePressEvent ( QMouseEvent * e )
00116     {
00117 
00118       if ( Q3CheckListItem *item = dynamic_cast<Q3CheckListItem *>(itemAt(contentsToViewport(e->pos()))) )
00119         {
00120           std::vector< Q3CheckListItem *> childDepending;
00121           findChildren(item, childDepending);
00122 
00123           bool value=!item->isOn();
00124           item->setOn(value);
00125  
00126           if (mapFlag.find(item) != mapFlag.end()) emit change(mapFlag[item],value);
00127           for (unsigned int idxChild=0;idxChild<childDepending.size();++idxChild)
00128         {
00129           if (mapFlag.find(childDepending[idxChild]) != mapFlag.end()) emit change(mapFlag[childDepending[idxChild]],value);
00130         }
00131           emit clicked();
00132         }
00133     }
00134 
00135     } // namespace qt
00136 
00137   } // namespace gui
00138 
00139 } // namespace sofa
00140 

Generated on Sun Nov 23 02:28:35 2008 for Sofa by  doxygen 1.5.7.1