diff options
author | Robert Jonsson <spamatica@gmail.com> | 2010-10-13 19:34:22 +0000 |
---|---|---|
committer | Robert Jonsson <spamatica@gmail.com> | 2010-10-13 19:34:22 +0000 |
commit | 8a2c2824a59d7644e13bc52c9a0ecbd641f21f95 (patch) | |
tree | 064ad3f2bf8daab0ad27b128abd86a9bbdb1e496 /muse2/muse/widgets/tempolabel.cpp | |
parent | a27706d9629e8b592cca4659f865b70adef24e6d (diff) |
new branch muse2, first checkin
Diffstat (limited to 'muse2/muse/widgets/tempolabel.cpp')
-rw-r--r-- | muse2/muse/widgets/tempolabel.cpp | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/muse2/muse/widgets/tempolabel.cpp b/muse2/muse/widgets/tempolabel.cpp new file mode 100644 index 00000000..35f75b09 --- /dev/null +++ b/muse2/muse/widgets/tempolabel.cpp @@ -0,0 +1,126 @@ +//========================================================= +// MusE +// Linux Music Editor +// $Id: tempolabel.cpp,v 1.1.1.1 2003/10/27 18:54:29 wschweer Exp $ +// (C) Copyright 1999 Werner Schweer (ws@seh.de) +//========================================================= + +#include <qapplication.h> +#include <qstyle.h> +#include <qvalidator.h> +//Added by qt3to4: +#include <QLabel> +#include "tempolabel.h" + +//--------------------------------------------------------- +// TempoLabel +//--------------------------------------------------------- + +TempoLabel::TempoLabel(QWidget* parent, const char* name) + : QLabel(parent, name) + { + setFrameStyle(WinPanel | Sunken); + setLineWidth(2); + setMidLineWidth(3); + _value = 1.0; + setValue(0.0); + setIndent(3); + setMinimumSize(sizeHint()); + } + +//--------------------------------------------------------- +// setVal +//--------------------------------------------------------- + +void TempoLabel::setValue(int val) + { + setValue(double(val/1000.0)); + } + +void TempoLabel::setValue(double val) + { + if (val == _value) + return; + _value = val; + QString s = QString("%1").arg(val, 3, 'f', 2); + setText(s); + } + +//--------------------------------------------------------- +// sizeHint +//--------------------------------------------------------- + +QSize TempoLabel::sizeHint() const + { + QFontMetrics fm(font()); + int fw = 4; + int h = fm.height() + fw * 2; + int w = 6 + fm.width(QString("000.00")) + fw * 2; // 6=indent + return QSize(w, h).expandedTo(QApplication::globalStrut()); + } + +//--------------------------------------------------------- +// TempoSpinBox +//--------------------------------------------------------- + +TempoEdit::TempoEdit(QWidget* parent, const char* name) + : QSpinBox(parent, name) + { + setLineStep(100); + setMaxValue(60000); + setMinValue(3000); + //setValidator(new QDoubleValidator(this)); ddskrjo + connect(this, SIGNAL(valueChanged(int)), SLOT(tempoChanged(int))); + } + +//--------------------------------------------------------- +// sizeHint +//--------------------------------------------------------- + +QSize TempoEdit::sizeHint() const + { + QFontMetrics fm(font()); + int fw = style()->pixelMetric(QStyle::PM_DefaultFrameWidth,0, this); // ddskrjo + int h = fm.height() + fw * 2; + int w = 2 + fm.width(QString("000.00")) + fw * 4 + 30; + return QSize(w, h).expandedTo(QApplication::globalStrut()); + } + +//--------------------------------------------------------- +// mapValueToText +//--------------------------------------------------------- + +QString TempoEdit::mapValueToText(int val) + { + double v = val / 100.0; + return QString("%1").arg(v, 3, 'f', 2); + } + +//--------------------------------------------------------- +// mapTextToValue +//--------------------------------------------------------- + +int TempoEdit::mapTextToValue(bool* ok) + { + double v = text().toDouble(ok); + return int(v * 100); + } + +//--------------------------------------------------------- +// tempoChanged +//--------------------------------------------------------- + +void TempoEdit::tempoChanged(int val) + { + emit valueChanged(double(val)/100.0); + } + +//--------------------------------------------------------- +// setValue +//--------------------------------------------------------- + +void TempoEdit::setValue(double val) + { + QSpinBox::setValue(int(val*100)); + } + |