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 <stdlib.h>
00031 #include <stdio.h>
00032
00033 #include <QTimer>
00034
00035 #include "fun_display.h"
00036
00037
00038 FunDisplay* FunDisplay::previous_fun_ = NULL;
00039
00040 FunDisplay::FunDisplay()
00041 : count_( 0 )
00042 {
00043 size_ = new Property( "Size", 10, "How big, in units", this );
00044 connect( size_, SIGNAL( changed() ), this, SLOT( onSizeChanged() ));
00045
00046 master_ = new Property( "Master", "chunky", "Type of butter.", this );
00047 connect( master_, SIGNAL( changed() ), this, SLOT( onMasterChanged() ));
00048
00049 if( previous_fun_ )
00050 {
00051 connect( previous_fun_->master_, SIGNAL( changed() ), this, SLOT( onMasterChanged() ));
00052 }
00053 previous_fun_ = this;
00054
00055 new Property( "Double", 1.0, "double", this );
00056 new Property( "Float", 1.0f, "float", this );
00057
00058 slave_ = new Property( "Slave", "chunky", "Slave to the butter.", this );
00059
00060 mood_ = new EnumProperty( "Mood", "sad", "Feelings, nothing more than feelings...", this );
00061 mood_->addOption( "sad", 0 );
00062 mood_->addOption( "happy", 1 );
00063 mood_->addOption( "angry", 2 );
00064 mood_->addOption( "jumpy", 3 );
00065 mood_->addOption( "squirmy", 4 );
00066 connect( mood_, SIGNAL( changed() ), this, SLOT( onMoodChanged() ));
00067
00068 dance_ = new EditableEnumProperty( "Dance", "clown", "Stomple stomple", this );
00069 connect( dance_, SIGNAL( requestOptions( EditableEnumProperty* )), this, SLOT( makeDances( EditableEnumProperty* )));
00070
00071 QTimer* timer = new QTimer( this );
00072 connect( timer, SIGNAL( timeout() ), this, SLOT( onTimerTick() ));
00073 timer->start( 1000 );
00074 }
00075
00076 void FunDisplay::onTimerTick()
00077 {
00078 count_++;
00079 slave_->setValue( count_ );
00080 if( (count_ / 10) % 2 )
00081 {
00082 setStatus( StatusProperty::Warn, "Slave", "Too odd." );
00083 }
00084 else
00085 {
00086 setStatus( StatusProperty::Ok, "Slave", "Even enough." );
00087 }
00088 }
00089
00090 void FunDisplay::onMasterChanged()
00091 {
00092 slave_->setValue( master_->getValue() );
00093 }
00094
00095 void FunDisplay::onSizeChanged()
00096 {
00097 if( size_->getValue().toInt() > 10 )
00098 {
00099 setStatus( StatusProperty::Error, "Size", "Too large." );
00100 }
00101 else if( size_->getValue().toInt() < 5 )
00102 {
00103 setStatus( StatusProperty::Warn, "Size", "Too small." );
00104 }
00105 else
00106 {
00107 setStatus( StatusProperty::Ok, "Size", "Just fine." );
00108 }
00109 }
00110
00111 void FunDisplay::onMoodChanged()
00112 {
00113 printf( "Mood is now %d.\n", mood_->getOptionInt() );
00114 }
00115
00116 void FunDisplay::makeDances( EditableEnumProperty* prop )
00117 {
00118 QStringList dances;
00119 dances.push_back( "Robot/Turtlebot" );
00120 dances.push_back( "Robot/PR2" );
00121 dances.push_back( "Macarena/Fast" );
00122 dances.push_back( "Macarena/Slow" );
00123 dances.push_back( "Twist" );
00124 dances.push_back( "Tango" );
00125 dances.push_back( "Swing/Lindy" );
00126 dances.push_back( "Swing/Hop/Small" );
00127 dances.push_back( "Swing/Hop/Big" );
00128 dances.push_back( "Stumble" );
00129 dances.push_back( "Stomple" );
00130
00131 prop->clearOptions();
00132 for( int i = 0; i < 9; i++ )
00133 {
00134 int index = random() % dances.size();
00135 prop->addOption( dances[ index ]);
00136 }
00137 }