Code Search for Developers
 
 
  

CTypeWidget.cpp from osgDesigner at Krugle


Show CTypeWidget.cpp syntax highlighted

#include <osgDesigner/core/CTypeWidget.h>

#include <osgDesigner/core/CTypeModel.h>
#include <osgDesigner/core/CPropertyInfoModel.h>

#include <QtGui/QPushButton>
#include <QtGui/QLabel>
#include <QtCore/QEvent>
#include <QtGui/QInputEvent>

#include <iostream>


namespace osgDesigner
{
    CTypeWidget::CTypeWidget()
    {   
        _gridLayout = new QGridLayout(this);
        
        _splitter = new QSplitter(Qt::Vertical);
            _typeListView = new QListView(_splitter);
        
            _typeInfoToolBox = new QToolBox( _splitter);

                _inheritsFrame = new QFrame();
                    _inheritsLayout = new FlowLayout();

                _inheritedByFrame = new QFrame();
                    _inheritedByLayout = new FlowLayout();

                _propertyView = new QTreeView();


        _gridLayout->addWidget(_splitter);
        
        _typeInfoToolBox->addItem(_inheritsFrame, "Inherits");
        _typeInfoToolBox->addItem(_inheritedByFrame, "Inherited by");
        _typeInfoToolBox->addItem(_propertyView, "Properties");
        
        _inheritsFrame->setLayout(_inheritsLayout);
        
        _inheritedByFrame->setLayout(_inheritedByLayout);
        
        _typeModel = new CTypeModel;
        _typeListView->setModel(_typeModel);
        
        _typeModel->resetSlot();
        
        _propertyInfoModel = new CPropertyInfoModel;
        _propertyView->setModel(_propertyInfoModel);
        
        connect(_typeListView, SIGNAL(doubleClicked(const QModelIndex&)), 
                         this, SLOT(initTypeInfoView(const QModelIndex&)));
        connect(_propertyInfoModel, SIGNAL(modelReset()), this, SLOT(reziseColumnRequest()));
    }
    
    CTypeWidget::~CTypeWidget()
    {
    }
    
    
    
    bool                                CTypeWidget::eventFilter(QObject *obj, QEvent *event)
    {
        if (obj->inherits("QPushButton"))
        {
            if (event->type() == QEvent::MouseButtonPress) 
            {
                QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
                QPushButton *pushButton = static_cast<QPushButton*>(obj);
                if (mouseEvent->button() & Qt::LeftButton)
                {
                    initDialog(pushButton->text().toStdString());
                    return (true);
                }
            }
            return (false);
        } 
        else
        {
            // pass the event on to the parent class
            return QWidget::eventFilter(obj, event);
        }
    }
    
    void                                CTypeWidget::initTypeInfoView(const QModelIndex& index)
    {   
        osgIntrospectionToolKit::NameList       nl;
        _typeModel->getBaseNameList(index, nl);
        
        clearLayout(_inheritsLayout);
        initLayoutButton(nl, _inheritsLayout);
        _inheritsLayout->addItem(new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum));
        
        nl.clear();
        _typeModel->getDerivedNameList(index, nl);
        
        clearLayout(_inheritedByLayout);
        initLayoutButton(nl, _inheritedByLayout);
        _inheritedByLayout->addItem(new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum));            
        
        _propertyInfoModel->type(_typeModel->type(index));
    }
    
    void                                CTypeWidget::clearLayout(QLayout* layout)
    {
        QLayoutItem *child;
        while ((child = layout->takeAt(0)) != 0)
        {
            if (child->widget())
                delete child->widget();
            delete child;
        }
    }
    
    void                                CTypeWidget::initLayoutButton(const osgIntrospectionToolKit::NameList& nl, QLayout* layout)
    {
        osgIntrospectionToolKit::NameList::const_iterator   it;
        
        for (it = nl.begin(); it != nl.end(); ++it)
            layout->addWidget(addTypeButton(*it));
    }
    
    QPushButton*                        CTypeWidget::addTypeButton(const std::string& typeName)
    {
        QPushButton*    pushButton = new QPushButton(typeName.data());
        pushButton->installEventFilter(this);
        pushButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
        pushButton->setMaximumHeight(16);
        return (pushButton);
    }
    
    void                                CTypeWidget::initDialog(std::string typeName)
    {
        QModelIndex index = _typeModel->getIndexOfType(typeName);
        if (index.isValid() == false) return;
        
        _typeListView->setCurrentIndex(index);    
        initTypeInfoView(index);
    }
    
    void                                CTypeWidget::reziseColumnRequest()
    {
        for (int i = 0; i < CPropertyInfoModel::eNbColumn; ++i)
            _propertyView->resizeColumnToContents(i);
    }
}




See more files for this project here

osgDesigner

osgDesigner is a graphical tool used to modify an OpenSceneGraph (OSG) scene using the osgIntrospection framework. OpenSceneGraph developpers will be able to extend osgDesigner at need using (editor | render | osgIntrospection wrapper) plugin system.

Project homepage: http://sourceforge.net/projects/osgdesigner
Programming language(s): C++,Shell Script
License: other

  CFileMenu.cpp
  CMainWindow.cpp
  CPropertiesModel.cpp
  CPropertiesView.cpp
  CPropertiesWidget.cpp
  CPropertyInfoModel.cpp
  CSceneGraphEditMenu.cpp
  CSceneGraphModel.cpp
  CSceneGraphView.cpp
  CSceneGraphWidget.cpp
  CTypeModel.cpp
  CTypeWidget.cpp
  CValueModel.cpp
  CValueView.cpp
  FlagsConstructorDialog.cpp
  FlowLayout.cpp
  PluginManagerDialog.cpp
  SConfigManager.cpp
  SWorkSpace.cpp
  osgDesigner.cpp