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 #ifndef PG_PROPERTYFIELD_CHECKBOX_H
00031 #define PG_PROPERTYFIELD_CHECKBOX_H
00032
00033 #include "pgpropertyeditor.h"
00034 #include "pgcheckbutton.h"
00035
00042 template<typename B>
00043 class PG_PropertyField_Checkbox : public PG_PropertyEditor::PG_PropertyEditorField, public SigC::Object {
00044 B* myProperty;
00045 PG_CheckButton* checkbox;
00046 bool switchInverted;
00047
00048 bool click( bool b) {
00049 sigValueChanged(this,b);
00050 return true;
00051 }
00052
00053 public:
00054 typedef PG_Signal2<PG_PropertyField_Checkbox*, B> CheckboxPropertySignal;
00055 CheckboxPropertySignal sigValueChanged;
00056 CheckboxPropertySignal sigValueApplied;
00057
00064 PG_PropertyField_Checkbox( PG_PropertyEditor* propertyEditor, const std::string& name, B* b, bool inverted = false ) : myProperty( b ), switchInverted( inverted ) {
00065 PG_Rect r = propertyEditor->RegisterProperty( name, this );
00066 checkbox = new PG_CheckButton( propertyEditor, r, PG_NULLSTR, -1, propertyEditor->GetStyleName("BoolProperty") );
00067 checkbox->sigClick.connect( SigC::slot(*this, &PG_PropertyField_Checkbox::click));
00068 Reload();
00069 };
00070
00077 PG_PropertyField_Checkbox( PG_PropertyEditor* propertyEditor, const std::string& name, const B& b, bool inverted = false ) : myProperty( NULL ), switchInverted( inverted ) {
00078 PG_Rect r = propertyEditor->RegisterProperty( name, this );
00079 checkbox = new PG_CheckButton( propertyEditor, r, PG_NULLSTR, -1, propertyEditor->GetStyleName("BoolProperty") );
00080 checkbox->sigClick.connect( SigC::slot(*this, &PG_PropertyField_Checkbox::click));
00081
00082 if ( bool(b) ^ switchInverted )
00083 checkbox->SetPressed();
00084 else
00085 checkbox->SetUnpressed();
00086 };
00087
00088 bool Valid() {
00089 return true;
00090 };
00091 bool Apply() {
00092 if ( myProperty )
00093 *myProperty = checkbox->GetPressed() ^ switchInverted;
00094
00095 sigValueApplied( this, checkbox->GetPressed() ^ switchInverted );
00096 return true;
00097 };
00098 void Reload() {
00099 if ( myProperty ) {
00100 if ( bool(*myProperty) ^ switchInverted )
00101 checkbox->SetPressed();
00102 else
00103 checkbox->SetUnpressed();
00104 }
00105 };
00106 };
00107
00108 #endif