1
//=========================================================
4
// $Id: tempolabel.cpp,v 1.1 2002/01/30 14:54:04 muse Exp $
5
// (C) Copyright 1999 Werner Schweer (ws@seh.de)
6
//=========================================================
8
#include <qapplication.h>
10
#include <qvalidator.h>
11
#include "tempolabel.h"
13
//---------------------------------------------------------
15
//---------------------------------------------------------
17
TempoLabel::TempoLabel(QWidget* parent, const char* name = 0)
18
: QLabel(parent, name)
20
setFrameStyle(WinPanel | Sunken);
25
int fw = style().pixelMetric(QStyle::PM_DefaultFrameWidth, this);
29
//---------------------------------------------------------
31
//---------------------------------------------------------
33
void TempoLabel::setValue(int val)
35
setValue(double(val/1000.0));
38
void TempoLabel::setValue(double val)
43
QString s = QString("%1").arg(val, 3, 'f', 2);
47
//---------------------------------------------------------
49
//---------------------------------------------------------
51
QSize TempoLabel::sizeHint() const
53
QFontMetrics fm(font());
54
int fw = style().pixelMetric(QStyle::PM_DefaultFrameWidth, this);
55
int h = fm.height() + fw * 2;
56
int w = 2 + fm.width("000.00") + fw * 4;
57
return QSize(w, h).expandedTo(QApplication::globalStrut());
60
//---------------------------------------------------------
62
//---------------------------------------------------------
64
TempoSpinBox::TempoSpinBox(QWidget* parent, const char* name = 0)
65
: QSpinBox(parent, name)
70
setValidator(new QDoubleValidator(this));
71
connect(this, SIGNAL(valueChanged(int)), SLOT(tempoChanged(int)));
74
//---------------------------------------------------------
76
//---------------------------------------------------------
78
QSize TempoSpinBox::sizeHint() const
80
QFontMetrics fm(font());
81
int fw = style().pixelMetric(QStyle::PM_DefaultFrameWidth, this);
82
int h = fm.height() + fw * 2;
83
int w = 2 + fm.width("000.00") + fw * 4 + 30;
84
return QSize(w, h).expandedTo(QApplication::globalStrut());
87
//---------------------------------------------------------
89
//---------------------------------------------------------
91
QString TempoSpinBox::mapValueToText(int val)
93
double v = val / 100.0;
94
return QString("%1").arg(v, 3, 'f', 2);
97
//---------------------------------------------------------
99
//---------------------------------------------------------
101
int TempoSpinBox::mapTextToValue(bool* ok)
103
double v = text().toDouble(ok);
107
//---------------------------------------------------------
109
//---------------------------------------------------------
111
void TempoSpinBox::tempoChanged(int val)
113
emit valueChanged(double(val)/100.0);
116
//---------------------------------------------------------
118
//---------------------------------------------------------
120
void TempoSpinBox::setValue(double val)
122
QSpinBox::setValue(int(val*100));