/***********************************************************************
**
**   doublespinbox.cpp
**
**   This file is part of Cumulus
**
************************************************************************
**
**   Copyright (c):  2002 by Eggert Ehmke
**
**   This file is distributed under the terms of the General Public
**   Licence. See the file COPYING for more information.
**
**   $Id: doublespinbox.cpp,v 1.2 2003/12/15 21:39:29 andre Exp $
**
***********************************************************************/

#include <cmath>
#include "doublespinbox.h"

DoubleSpinBox::DoubleSpinBox (double min, double max, double step, QWidget* parent)
: QSpinBox (int(min/step), int(max/step), 1, parent), _step(step)
{
	setValue(0);
}

QString DoubleSpinBox::mapValueToText(int val)
{
  QString strval;
  if (_step < 0.1)
    strval.sprintf("%1.2f", val*_step);
  else if (_step < 1.0)
    strval.sprintf("%1.1f", val*_step);
  else
    strval.sprintf("%1.0f", val*_step);
  return strval;
}

int DoubleSpinBox::mapTextToValue(bool* /*ok*/)
{
  return (int)rint(text().toDouble()/_step);
}

void DoubleSpinBox::setValue (double val)
{
  QSpinBox::setValue ((int)rint(val/_step));
}

double DoubleSpinBox::value ()
{
  return QSpinBox::value()*_step;
}

