From: Steinar H. Gunderson Date: Thu, 6 Oct 2016 18:14:30 +0000 (+0200) Subject: Make NonlinearFader work with fixed 0..1000 range, not 0..height(). X-Git-Tag: 1.4.0~37 X-Git-Url: https://git.sesse.net/?p=nageru;a=commitdiff_plain;h=adaf88f2a3544bfd62bcdafa9b11d190f6658010 Make NonlinearFader work with fixed 0..1000 range, not 0..height(). In particular, this fixes an issue where the range could be wrong just after the widget is created, but the page it is not is not shown yet (so there hasn't been a resize event yet). Also makes for more consistent scroll wheel and arrow key behavior, as it is not longer dependent on widget size. --- diff --git a/nonlinear_fader.cpp b/nonlinear_fader.cpp index 7c26434..b548c29 100644 --- a/nonlinear_fader.cpp +++ b/nonlinear_fader.cpp @@ -17,35 +17,35 @@ namespace { vector> fader_control_points = { // The main area is from +6 to -12 dB (18 dB), and we use half the slider range for it. - { 6.0, 0.0 }, + { 6.0, 1.0 }, { -12.0, 0.5 }, // -12 to -21 is half the range (9 dB). Halve. - { -21.0, 0.625 }, + { -21.0, 0.325 }, // -21 to -30 (9 dB) gets the same range as the previous one. - { -30.0, 0.75 }, + { -30.0, 0.25 }, // -30 to -48 (18 dB) gets half of half. - { -48.0, 0.875 }, + { -48.0, 0.125 }, // -48 to -84 (36 dB) gets half of half of half. - { -84.0, 1.0 }, + { -84.0, 0.0 }, }; double slider_fraction_to_db(double db) { - if (db <= fader_control_points[0].second) { + if (db >= fader_control_points[0].second) { return fader_control_points[0].first; } - if (db >= fader_control_points.back().second) { + if (db <= fader_control_points.back().second) { return fader_control_points.back().first; } for (unsigned i = 1; i < fader_control_points.size(); ++i) { - const double x0 = fader_control_points[i - 1].second; - const double x1 = fader_control_points[i].second; - const double y0 = fader_control_points[i - 1].first; - const double y1 = fader_control_points[i].first; + const double x0 = fader_control_points[i].second; + const double x1 = fader_control_points[i - 1].second; + const double y0 = fader_control_points[i].first; + const double y1 = fader_control_points[i - 1].first; if (db >= x0 && db <= x1) { const double t = (db - x0) / (x1 - x0); return y0 + t * (y1 - y0); @@ -100,8 +100,8 @@ void NonLinearFader::paintEvent(QPaintEvent *event) // FIXME: Where does the slider_length / 2 come from? I can't really find it // in the Qt code, but it seems to match up with reality. int slider_length = sr.height(); - int slider_min = gr.top() + (slider_length / 2); - int slider_max = gr.bottom() + (slider_length / 2) - slider_length + 1; + int slider_max = gr.top() + (slider_length / 2); + int slider_min = gr.bottom() + (slider_length / 2) - slider_length + 1; QPainter p(this); @@ -119,15 +119,6 @@ void NonLinearFader::paintEvent(QPaintEvent *event) QSlider::paintEvent(event); } -void NonLinearFader::resizeEvent(QResizeEvent *event) -{ - QSlider::resizeEvent(event); - inhibit_updates = true; - setRange(0, event->size().height() - 1); - inhibit_updates = false; - update_slider_position(); -} - void NonLinearFader::sliderChange(SliderChange change) { QSlider::sliderChange(change); @@ -135,7 +126,7 @@ void NonLinearFader::sliderChange(SliderChange change) if (value() == 0) { db_value = -HUGE_VAL; } else { - double frac = 1.0 - value() / (height() - 1.0); + double frac = double(value() - minimum()) / (maximum() - minimum()); db_value = slider_fraction_to_db(frac); } emit dbValueChanged(db_value); @@ -145,6 +136,7 @@ void NonLinearFader::sliderChange(SliderChange change) void NonLinearFader::update_slider_position() { inhibit_updates = true; - setValue(lrint((1.0 - db_to_slider_fraction(db_value)) * (height() - 1.0))); + double val = db_to_slider_fraction(db_value) * (maximum() - minimum()) + minimum(); + setValue(lrint(val)); inhibit_updates = false; } diff --git a/nonlinear_fader.h b/nonlinear_fader.h index 4126fbd..cd844be 100644 --- a/nonlinear_fader.h +++ b/nonlinear_fader.h @@ -15,7 +15,6 @@ signals: protected: void paintEvent(QPaintEvent *event) override; - void resizeEvent(QResizeEvent *event) override; void sliderChange(SliderChange change) override; private: diff --git a/ui_audio_expanded_view.ui b/ui_audio_expanded_view.ui index 8e431b4..489e4b2 100644 --- a/ui_audio_expanded_view.ui +++ b/ui_audio_expanded_view.ui @@ -406,6 +406,15 @@ + + 1000 + + + 10 + + + 100 + Qt::Vertical diff --git a/ui_audio_miniview.ui b/ui_audio_miniview.ui index 0761931..7aa1aa0 100644 --- a/ui_audio_miniview.ui +++ b/ui_audio_miniview.ui @@ -261,14 +261,17 @@ - -390 + 0 - 60 + 1000 - + 10 + + 100 + Qt::Vertical