34 #include "base/AudioLevel.h" 36 #include <QMouseEvent> 38 #include <QWheelEvent> 39 #include <QPaintEvent> 41 #include <QInputDialog> 47 m_withoutKnob(withoutKnob),
51 m_mousePressed(false),
55 setMinimumSize(116, 23);
56 setMaximumSize(116, 23);
59 QString background_path =
":/icons/fader_background.png";
60 bool ok =
m_back.load(background_path);
62 cerr <<
"Fader: Error loading pixmap" << endl;
65 QString leds_path =
":/icons/fader_leds.png";
66 ok =
m_leds.load(leds_path);
68 cerr <<
"Error loading pixmap" << endl;
71 QString knob_path =
":/icons/fader_knob.png";
72 ok =
m_knob.load(knob_path);
74 cerr <<
"Error loading pixmap" << endl;
77 QString clip_path =
":/icons/fader_knob_red.png";
78 ok =
m_clip.load(clip_path);
80 cerr <<
"Error loading pixmap" << endl;
92 if (ev->button() == Qt::MidButton) {
103 if (diff == 0)
return;
105 int vx = AudioLevel::multiplier_to_fader
113 float fval = (float)AudioLevel::fader_to_multiplier
114 (vx,
getMaxX(), AudioLevel::LongFader);
135 float min = (float)AudioLevel::fader_to_dB
136 (0,
getMaxX(), AudioLevel::LongFader);
137 float max = (float)AudioLevel::fader_to_dB
139 float deft = (float)AudioLevel::multiplier_to_dB(
m_value);
141 float dB = (float)QInputDialog::getDouble
143 tr(
"Enter new fader level"),
144 tr(
"New fader level, from %1 to %2 dBFS:").arg(min).arg(max),
145 deft, min, max, 3, &ok);
148 float value = (float)AudioLevel::dB_to_multiplier(dB);
158 if (ev->button() == Qt::MidButton ||
159 ((ev->button() == Qt::LeftButton) &&
160 (ev->modifiers() & Qt::ControlModifier))) {
167 if (ev->button() != Qt::LeftButton)
return;
181 if (ev->delta() > 0) {
206 float max = (float)AudioLevel::dB_to_multiplier(10.0);
210 }
else if (v < 0.0) {
216 float db = (float)AudioLevel::multiplier_to_dB(
m_value);
218 if (db <= AudioLevel::DB_FLOOR) {
219 text = tr(
"Level: Off");
221 text = tr(
"Level: %1%2.%3%4 dB")
222 .arg(db < 0.0 ?
"-" :
"")
224 .arg(abs(
int(db * 10.0) % 10))
225 .arg(abs(
int(db * 100.0) % 10));
227 cerr <<
"Fader: setting tooltip to \"" << text <<
"\"" << endl;
228 QWidget::setToolTip(text);
265 QPainter painter(
this);
268 painter.drawPixmap(rect(),
m_back, QRect(0, 0, 116, 23));
270 int offset_L = AudioLevel::multiplier_to_fader(
m_peakLeft, 116,
271 AudioLevel::IEC268LongMeter);
273 painter.drawPixmap(QRect(0, 0, offset_L, 11),
m_leds,
274 QRect(0, 0, offset_L, 11));
276 int offset_R = AudioLevel::multiplier_to_fader(
m_peakRight, 116,
277 AudioLevel::IEC268LongMeter);
279 painter.drawPixmap(QRect(0, 11, offset_R, 11),
m_leds,
280 QRect(0, 11, offset_R, 11));
284 static const uint knob_width = 29;
285 static const uint knob_height = 9;
287 int x = AudioLevel::multiplier_to_fader(
m_value, 116 - knob_width,
288 AudioLevel::LongFader);
292 painter.drawPixmap(QRect(x, 7, knob_width, knob_height),
294 QRect(0, 0, knob_width, knob_height));
void paintEvent(QPaintEvent *ev) override
void mousePressEvent(QMouseEvent *ev) override
void leaveEvent(QEvent *) override
void enterEvent(QEvent *) override
void mouseReleaseEvent(QMouseEvent *ev) override
void setValue(float newValue)
void mouseMoveEvent(QMouseEvent *ev) override
Fader(QWidget *parent, bool withoutKnob=false)
Horizontal audio fader and meter widget.
void wheelEvent(QWheelEvent *ev) override
void mouseDoubleClickEvent(QMouseEvent *ev) override