00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <QTextBrowser>
00031
00032 #include <yaml-cpp/emitter.h>
00033 #include <yaml-cpp/node.h>
00034
00035 #include "rviz/properties/property.h"
00036 #include "rviz/properties/property_tree_widget.h"
00037 #include "rviz/properties/yaml_helpers.h"
00038
00039 #include "rviz/properties/property_tree_with_help.h"
00040
00041 namespace rviz
00042 {
00043
00044 PropertyTreeWithHelp::PropertyTreeWithHelp( QWidget* parent )
00045 : QSplitter( parent )
00046 {
00047 setOrientation( Qt::Vertical );
00048
00049 property_tree_ = new PropertyTreeWidget;
00050
00051 help_ = new QTextBrowser;
00052 help_->setOpenExternalLinks( true );
00053
00054 addWidget( property_tree_ );
00055 addWidget( help_ );
00056
00057 setStretchFactor( 0, 1000 );
00058 setCollapsible( 0, false );
00059
00060 QList<int> _sizes;
00061 _sizes.push_back( 1000 );
00062 _sizes.push_back( 1 );
00063 setSizes( _sizes );
00064
00065 connect( property_tree_, SIGNAL( currentPropertyChanged( const Property* )),
00066 this, SLOT( showHelpForProperty( const Property* )));
00067 }
00068
00069 void PropertyTreeWithHelp::showHelpForProperty( const Property* property )
00070 {
00071 if( property )
00072 {
00073 QString body_text = property->getDescription();
00074 QString heading = property->getName();
00075 QString html = "<html><body bgcolor=\"#EFEBE7\"><strong>" + heading + "</strong><br>" + body_text + "</body></html>";
00076 help_->setHtml( html );
00077 }
00078 else
00079 {
00080 help_->setHtml( "" );
00081 }
00082 }
00083
00084 void PropertyTreeWithHelp::save( YAML::Emitter& emitter )
00085 {
00086 emitter << YAML::BeginMap;
00087
00088
00089 emitter << YAML::Key << "Property Tree Widget";
00090 emitter << YAML::Value;
00091 property_tree_->save( emitter );
00092
00093 QList<int> _sizes = sizes();
00094 emitter << YAML::Key << "Tree Height";
00095 emitter << YAML::Value << _sizes.at( 0 );
00096
00097 emitter << YAML::Key << "Help Height";
00098 emitter << YAML::Value << _sizes.at( 1 );
00099
00100 emitter << YAML::EndMap;
00101 }
00102
00103 void PropertyTreeWithHelp::load( const YAML::Node& yaml_node )
00104 {
00105 if( const YAML::Node *tree_node = yaml_node.FindValue( "Property Tree Widget" ))
00106 {
00107 property_tree_->load( *tree_node );
00108 }
00109
00110 if( const YAML::Node *tree_height_node = yaml_node.FindValue( "Tree Height" ))
00111 {
00112 int tree_height;
00113 *tree_height_node >> tree_height;
00114 if( const YAML::Node *help_height_node = yaml_node.FindValue( "Help Height" ))
00115 {
00116 int help_height;
00117 *help_height_node >> help_height;
00118
00119 QList<int> _sizes;
00120 _sizes.push_back( tree_height );
00121 _sizes.push_back( help_height );
00122 setSizes( _sizes );
00123 }
00124 }
00125 }
00126
00127
00128 }