summaryrefslogtreecommitdiff
path: root/muse2/muse/widgets/spinboxFP.cpp
blob: c2906940c3deafb08f0f8e34637d5217c6394049 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//=========================================================
//  MusE
//  Linux Music Editor
//    $Id: spinboxFP.cpp,v 1.1.1.1 2003/10/27 18:55:03 wschweer Exp $
//    (C) Copyright 2001 Werner Schweer (ws@seh.de)
//=========================================================

#include <stdio.h>
#include <cmath>

//#include <qvalidator.h>
#include <QtGui>
#include "spinboxFP.h"

//---------------------------------------------------------
//   SpinBoxFP
//---------------------------------------------------------

SpinBoxFP::SpinBoxFP(QWidget* parent, const char* name)
   : QSpinBox(parent, name)
      {
      _precision = 0;
      //setValidator(new QDoubleValidator(this)); ddskrjo
      }

SpinBoxFP::SpinBoxFP(int minValue, int maxValue, int step, QWidget* parent, const char* name)
   : QSpinBox(minValue, maxValue, step, parent, name)
      {
      _precision = 0;
      //setValidator(new QDoubleValidator(this)); ddskrjo
      }

//---------------------------------------------------------
//   setPrecision
//---------------------------------------------------------

void SpinBoxFP::setPrecision(int val)
      {
      _precision = val;
      //updateDisplay(); ddskrjo
      }

//---------------------------------------------------------
//   mapValueToText
//---------------------------------------------------------

QString SpinBoxFP::mapValueToText(int value)
      {
      if (_precision) {
            QString s;
            int div = int(exp10(_precision));
//            printf("val %d, prec %d, div %d\n", value, _precision, div);
            s.sprintf("%d.%0*d", value/div, _precision, value%div);
            return s;
            }
      return textFromValue(value); // ddskrjo
      }

//---------------------------------------------------------
//   mapTextToValue
//---------------------------------------------------------
/* ddskrjo
int SpinBoxFP::mapTextToValue(bool* ok)
      {
      QString qs = cleanText();
      if (_precision) {
            const char* s = qs.latin1();
            int a, b;
            int n = sscanf(s, "%d.%d", &a, &b);
            if (n != 2) {
                  *ok = false;
                  return 0;
                  }
            int div = int(exp10(_precision));
            return a * div + b;
            }
      return QSpinBox::mapTextToValue(ok);
      }

*/