00001 #include "LCDBigNumber.h" 00002 #include <sstream> 00003 #include <string> 00004 00005 using namespace std; 00006 00007 const int LCDBigNumber::LCD_COLON = 10; 00008 00009 LCDBigNumber::LCDBigNumber(LCDElement *parent, const string &id) : LCDWidget(id, parent, "num") 00010 { 00011 _position = 1; 00012 _number = 0; 00013 } 00014 00015 LCDBigNumber::LCDBigNumber(int number, int x, LCDElement *parent, const string &id) : LCDWidget(id, parent, "num") 00016 { 00017 _position = 1; 00018 set(number, x); 00019 } 00020 00021 void LCDBigNumber::setNumberPosition(int position) 00022 { 00023 _position = position; 00024 } 00025 00026 void LCDBigNumber::notifyChanged() 00027 { 00028 ostringstream params; 00029 00030 params << _x 00031 << " " 00032 << _number; 00033 00034 setWidgetParameters(params.str()); 00035 } 00036 00037 void LCDBigNumber::set(int number, int x) 00038 { 00039 _number = number; 00040 _x = x; 00041 notifyChanged(); 00042 } 00043 00044 void LCDBigNumber::setNumber(int number) 00045 { 00046 _number = number; 00047 notifyChanged(); 00048 } 00049 00050 int LCDBigNumber::getNumber() const 00051 { 00052 return _number; 00053 } 00054 00055 void LCDBigNumber::valueCallback(string value) 00056 { 00057 int max = value.size(); 00058 int position = max - _position; 00059 if (position < 0) 00060 { 00061 _number = 0; 00062 } 00063 else 00064 { 00065 _number = atoi(value.substr(position,1).c_str()); 00066 } 00067 notifyChanged(); 00068 }