1 /* This file is part of Clementine.
2    Copyright 2010, David Sansome <me@davidsansome.com>
3 
4    Clementine is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8 
9    Clementine is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with Clementine.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #include "equalizerslider.h"
19 #include "ui_equalizerslider.h"
20 
21 #include <QFontMetrics>
22 
EqualizerSlider(const QString & label,QWidget * parent)23 EqualizerSlider::EqualizerSlider(const QString& label, QWidget* parent)
24     : QWidget(parent), ui_(new Ui_EqualizerSlider) {
25   ui_->setupUi(this);
26   ui_->band->setText(label);  // Band [Hz]
27 
28   QFontMetrics fm = ui_->gain->fontMetrics();
29   int longestLabelWidth = fm.width(tr("%1 dB").arg(-99.99));
30   ui_->gain->setMinimumWidth(longestLabelWidth);
31   ui_->gain->setText(tr("%1 dB").arg(0));  // Gain [dB]
32 
33   ui_->slider->setValue(0);
34 
35   connect(ui_->slider, SIGNAL(valueChanged(int)), this,
36           SLOT(onValueChanged(int)));
37 }
38 
onValueChanged(int value)39 void EqualizerSlider::onValueChanged(int value) {
40   // Converting % to dB as per GstEnginePipeline::UpdateEqualizer():
41   float gain = (value < 0) ? value * 0.24 : value * 0.12;
42 
43   ui_->gain->setText(tr("%1 dB").arg(gain));  // Gain [dB]
44   emit ValueChanged(value);
45 }
46 
~EqualizerSlider()47 EqualizerSlider::~EqualizerSlider() { delete ui_; }
48 
value() const49 int EqualizerSlider::value() const { return ui_->slider->value(); }
50 
set_value(int value)51 void EqualizerSlider::set_value(int value) { ui_->slider->setValue(value); }
52