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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
//=========================================================
// MusE
// Linux Music Editor
// $Id: doublelabel.cpp,v 1.1.1.1 2003/10/29 10:06:27 wschweer Exp $
// (C) Copyright 1999 Werner Schweer (ws@seh.de)
//=========================================================
#include <stdio.h>
#include "doublelabel.h"
#include <qvalidator.h>
#include <qpalette.h>
#include <stdio.h>
#include <values.h>
#include "utils.h"
//---------------------------------------------------------
// DoubleLabel
//---------------------------------------------------------
DoubleLabel::DoubleLabel(QWidget* parent, const char* name)
: Dentry(parent, name), _specialText("---")
{
min = 0.0;
max = 1.0;
_precision = 3;
setValue(0.0);
}
DoubleLabel::DoubleLabel(double _val, double m, double mx, QWidget* parent)
: Dentry(parent), _specialText("---")
{
min = m;
max = mx;
_precision = 3;
setValue(_val);
}
//---------------------------------------------------------
// setString
//---------------------------------------------------------
bool DoubleLabel::setString(double v)
{
QString s;
if (v < min || v > max) {
setText(_specialText);
return true;
}
s.setNum(v, 'f', _precision);
if (!_suffix.isEmpty()) {
s += " ";
s += _suffix;
}
setText(s);
return false;
}
//---------------------------------------------------------
// setSValue
//---------------------------------------------------------
bool DoubleLabel::setSValue(const QString& s)
{
bool ok;
double v = s.toDouble(&ok);
if (ok && (v != val)) {
if (v < min)
v = min;
if (v > max)
v = max;
setValue(v);
emit valueChanged(val, _id);
}
return false;
}
//---------------------------------------------------------
// incValue
//---------------------------------------------------------
void DoubleLabel::incValue(double)
{
if (val + 1.0 < max) {
setValue(val + 1.0);
emit valueChanged(val, _id);
}
}
//---------------------------------------------------------
// decValue
//---------------------------------------------------------
void DoubleLabel::decValue(double)
{
if (val - 1.0 > min) {
setValue(val - 1.0);
emit valueChanged(val, _id);
}
}
//---------------------------------------------------------
// setPrecision
//---------------------------------------------------------
void DoubleLabel::setPrecision(int v)
{
_precision = v;
setString(val);
}
//---------------------------------------------------------
// sizeHint
//---------------------------------------------------------
QSize DoubleLabel::sizeHint() const
{
QFontMetrics fm = fontMetrics();
int h = fm.height() + 4;
int n = _precision + 3;
#if 0
double aval = fabs(val);
if (aval >= 10.0)
++n;
if (aval >= 100.0)
++n;
if (aval >= 1000.0)
++n;
if (aval >= 10000.0)
++n;
if (aval >= 100000.0)
++n;
#endif
int w = fm.width(QString("-0.")) + fm.width('0') * n + 6;
return QSize(w, h);
}
|