TuiNodeDouble.cpp   TuiNodeDouble.cpp 
skipping to change at line 27 skipping to change at line 27
*/ */
#include "TuiNodeDouble.hpp" #include "TuiNodeDouble.hpp"
#include <QKeyEvent> #include <QKeyEvent>
TuiNodeDouble::TuiNodeDouble(const QString& text, QObject* receiver, const char* method, double defValue, TuiNodeDouble::TuiNodeDouble(const QString& text, QObject* receiver, const char* method, double defValue,
double min, double max, double inc, TuiNode* p arent, TuiNode* prev) double min, double max, double inc, TuiNode* p arent, TuiNode* prev)
: TuiNodeEditable(text, parent, prev), value(defValue), minimum(min) , maximum(max), increment(inc), typing(false), typedDecimal(false) : TuiNodeEditable(text, parent, prev), value(defValue), minimum(min) , maximum(max), increment(inc), typing(false), typedDecimal(false)
{ {
this->connect(this, SIGNAL(setValue(double)), receiver, method); this->connect(this, SIGNAL(setValue(double)), receiver, method);
stringValue.setNum(value,'g',-1);
} }
TuiNodeResponse TuiNodeDouble::handleEditingKey(int key) TuiNodeResponse TuiNodeDouble::handleEditingKey(int key)
{ {
TuiNodeResponse response; TuiNodeResponse response;
response.accepted = false; response.accepted = false;
response.newNode = this; response.newNode = this;
if (key==Qt::Key_Left || key==Qt::Key_Return) if (key==Qt::Key_Left || key==Qt::Key_Return)
{ {
typing = false; typing = false;
typedDecimal = false; typedDecimal = false;
editing = false; editing = false;
response.accepted = true; response.accepted = true;
response.newNode = this; response.newNode = this;
stringValue.setNum(value,'g',-1);
emit(setValue(value)); emit(setValue(value));
return response; return response;
} }
else if (key==Qt::Key_Up) else if (key==Qt::Key_Up)
{ {
typing = false; typing = false;
typedDecimal = false; typedDecimal = false;
value+=increment; value+=increment;
if (value > maximum) if (value > maximum)
value = maximum; value = maximum;
response.accepted = true; response.accepted = true;
response.newNode = this; response.newNode = this;
stringValue.setNum(value,'g',-1);
emit(setValue(value)); emit(setValue(value));
return response; return response;
} }
else if (key==Qt::Key_Down) else if (key==Qt::Key_Down)
{ {
typing = false; typing = false;
typedDecimal = false; typedDecimal = false;
value-=increment; value-=increment;
if (value < minimum) if (value < minimum)
value = minimum; value = minimum;
response.accepted = true; response.accepted = true;
response.newNode = this; response.newNode = this;
stringValue.setNum(value,'g',-1);
emit(setValue(value)); emit(setValue(value));
return response; return response;
} }
else if (key==Qt::Key_Period) else if (key==Qt::Key_Period)
{ {
QString s;
if (!typing) if (!typing)
{ {
value = 0; value = 0;
stringValue.clear();
typedDecimal = true; typedDecimal = true;
} }
else else
{ {
// first check if there already a decimal point // first check if there already a decimal point
s = QString("%1").arg(value); if (!stringValue.contains('.'))
if (!s.contains("."))
{ {
s = QString("%1%2").arg(value).arg(key - Qt: :Key_0); stringValue.setNum(value,'g',-1).append('.') ;
typedDecimal = true; typedDecimal = true;
} }
} }
response.accepted = true; response.accepted = true;
response.newNode = this; response.newNode = this;
} }
else if (key>=Qt::Key_0 && key<=Qt::Key_9) else if (key>=Qt::Key_0 && key<=Qt::Key_9)
{ {
QString s;
if (!typing) if (!typing)
{
typing = true; typing = true;
if (typedDecimal)
s = QString("0.%1").arg(key - Qt::Key_0); stringValue.append(QString::number(key - Qt::Key_0));
else
s = QString("%1").arg(key - Qt::Key_0);
}
else
{
if (typedDecimal)
s = QString("%1.%2").arg(value).arg(key - Qt
::Key_0);
else
s = QString("%1%2").arg(value).arg(key - Qt:
:Key_0);
}
bool ok; bool ok;
double d = s.toDouble(&ok); double d = stringValue.toDouble(&ok);
if (ok && d>=minimum && d<=maximum) if (ok && d>=minimum && d<=maximum)
{ {
value = d; value = d;
typedDecimal = false; typedDecimal = false;
} }
response.accepted = true; response.accepted = true;
response.newNode = this; response.newNode = this;
emit(setValue(value)); emit(setValue(value));
return response; return response;
} }
else if (key==Qt::Key_Backspace) else if (key==Qt::Key_Backspace)
{ {
typing = true; typing = true;
typedDecimal = false; typedDecimal = false;
QString s = QString("%1").arg(value); if (stringValue.length() == 1)
if (s.length()==1)
{ {
value = 0; value = 0;
stringValue.clear();
} }
else else
{ {
s = s.left(s.length()-1); stringValue.chop(1);
bool ok; bool ok;
double d = s.toDouble(&ok); double d = stringValue.toDouble(&ok);
if (ok && d>=minimum && d<=maximum) if (ok && d>=minimum && d<=maximum)
{ {
value = d; value = d;
} }
} }
response.accepted = true; response.accepted = true;
response.newNode = this; response.newNode = this;
emit(setValue(value)); emit(setValue(value));
return response; return response;
} }
else if (key==Qt::Key_Minus) else if (key==Qt::Key_Minus)
{ {
typing = true; typing = true;
int i = value *= -1; int i = value *= -1; //BM: Is this deliberate?
if (i>=minimum && i<=maximum) if (i>=minimum && i<=maximum)
value = i; value = i;
stringValue.setNum(value,'g',-1);;
response.accepted = true; response.accepted = true;
response.newNode = this; response.newNode = this;
emit(setValue(value)); emit(setValue(value));
return response; return response;
} }
return response; return response;
} }
QString TuiNodeDouble::getDisplayText() QString TuiNodeDouble::getDisplayText()
{ {
if (!editing) if (!editing)
{ {
return displayText + QString(": %1").arg(value); return displayText + QString(": %1").arg(value);
} }
else else
{ {
if (typedDecimal) return displayText + QString(": >%1<").arg(stringValue);
return displayText + QString(": >%1.<").arg(value);
else
return displayText + QString(": >%1<").arg(value);
} }
} }
 End of changes. 19 change blocks. 
30 lines changed or deleted 18 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/