1
//=============================================================================
3
// Audio Widget Library
6
// Copyright (C) 2002-2006 by Werner Schweer and others
8
// This program is free software; you can redistribute it and/or modify
9
// it under the terms of the GNU General Public License version 2.
11
// This program is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
// GNU General Public License for more details.
16
// You should have received a copy of the GNU General Public License
17
// along with this program; if not, write to the Free Software
18
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
//=============================================================================
21
#include "floatentry.h"
25
#include <QMouseEvent>
37
//---------------------------------------------------------
39
//---------------------------------------------------------
41
FloatEntry::FloatEntry(QWidget* parent)
50
timer = new QTimer(this);
51
connect(timer, SIGNAL(timeout()), SLOT(repeat()));
53
connect(this, SIGNAL(returnPressed()), SLOT(endEdit()));
54
setCursor(QCursor(Qt::ArrowCursor));
58
//---------------------------------------------------------
60
//---------------------------------------------------------
62
bool FloatEntry::setString(double v)
65
// if (v < _minValue || v > _maxValue) {
67
if (!_specialText.isEmpty())
68
setText(_specialText);
71
s.setNum(v, 'f', _precision);
72
if (!_suffix.isEmpty()) {
80
//---------------------------------------------------------
82
//---------------------------------------------------------
84
void FloatEntry::setSValue(const QString& s)
87
double v = s.toFloat(&ok);
88
if (ok && (v != _value)) {
99
//---------------------------------------------------------
101
//---------------------------------------------------------
103
void FloatEntry::valueChange()
105
emit valueChanged(value(), _id);
108
//---------------------------------------------------------
110
//---------------------------------------------------------
112
void FloatEntry::incValue(double)
114
if (_value + 1.0 < _maxValue) {
115
_value = _value + 1.0;
121
//---------------------------------------------------------
123
//---------------------------------------------------------
125
void FloatEntry::decValue(double)
127
if (_value - 1.0 > _minValue) {
128
_value = _value - 1.0;
134
//---------------------------------------------------------
136
//---------------------------------------------------------
138
void FloatEntry::setPrecision(int v)
144
//---------------------------------------------------------
146
//---------------------------------------------------------
148
QSize FloatEntry::sizeHint() const
150
QFontMetrics fm = fontMetrics();
151
int h = fm.height() + 4;
152
int n = _precision + 3;
153
int w = fm.width(QString("-0.")) + fm.width('0') * n + 6;
157
//---------------------------------------------------------
159
//---------------------------------------------------------
161
void FloatEntry::endEdit()
163
if (QLineEdit::isModified())
168
//---------------------------------------------------------
170
//---------------------------------------------------------
172
void FloatEntry::mousePressEvent(QMouseEvent* event)
174
button = event->button();
176
evx = double(event->x());
179
timer->start(TIMER1);
182
//---------------------------------------------------------
184
//---------------------------------------------------------
186
void FloatEntry::wheelEvent(QWheelEvent* event)
188
int delta = event->delta();
196
//---------------------------------------------------------
198
//---------------------------------------------------------
200
void FloatEntry::repeat()
202
if (timecount == 1) {
205
timer->start(TIMER2);
209
if (timecount == TIMEC) {
211
timer->start(TIMER3);
213
if (timecount == TIMEC2) {
215
timer->start(TIMER4);
224
case Qt::RightButton:
232
//---------------------------------------------------------
234
//---------------------------------------------------------
236
void FloatEntry::mouseReleaseEvent(QMouseEvent*)
238
button = Qt::NoButton;
242
//---------------------------------------------------------
244
//---------------------------------------------------------
246
void FloatEntry::mouseMoveEvent(QMouseEvent*)
253
case Qt::RightButton:
260
//---------------------------------------------------------
261
// mouseDoubleClickEvent
262
//---------------------------------------------------------
264
void FloatEntry::mouseDoubleClickEvent(QMouseEvent* event)
266
if (event->button() != Qt::LeftButton) {
267
mousePressEvent(event);
271
QLineEdit::setFrame(true);
275
//---------------------------------------------------------
277
//---------------------------------------------------------
279
void FloatEntry::setValue(double val)
285
_value = fast_log10(val) * 20.0f;
292
//---------------------------------------------------------
294
//---------------------------------------------------------
296
void FloatEntry::updateValue()
298
if (setString(_value)) {
299
// value is out of range:
300
if (_value > _maxValue)
302
else if (_value < _minValue)
307
//---------------------------------------------------------
309
//---------------------------------------------------------
311
double FloatEntry::value() const
315
rv = pow(10.0, _value * 0.05f);