From d6219416e63dcf3e45593b2ffb6a5953709b492b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Wed, 4 Nov 2015 23:10:27 +0100 Subject: [PATCH] Let Entry of FaderOption react on ENTER and allow only numerical input. This enables setting click gain and solo gain in the preferences using the text field. -- fixes #6668 --- gtk2_ardour/option_editor.cc | 27 +++++++++++++++++++++++++-- gtk2_ardour/option_editor.h | 2 ++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/gtk2_ardour/option_editor.cc b/gtk2_ardour/option_editor.cc index a8c35f250f..9ce4997bb8 100644 --- a/gtk2_ardour/option_editor.cc +++ b/gtk2_ardour/option_editor.cc @@ -31,9 +31,10 @@ #include "pbd/configuration.h" #include "pbd/replace_all.h" -#include "public_editor.h" -#include "option_editor.h" #include "gui_thread.h" +#include "option_editor.h" +#include "public_editor.h" +#include "utils.h" #include "i18n.h" using namespace std; @@ -289,6 +290,8 @@ FaderOption::FaderOption (string const & i, string const & n, sigc::slot set_size_request_to_display_given_text (_db_display, "-99.00", 12, 12); _db_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &FaderOption::db_changed)); + _db_display.signal_activate().connect (sigc::mem_fun (*this, &FaderOption::on_activate)); + _db_display.signal_key_press_event().connect (sigc::mem_fun (*this, &FaderOption::on_key_press), false); } void @@ -314,6 +317,26 @@ FaderOption::db_changed () _set (slider_position_to_gain_with_max (_db_adjustment.get_value (), Config->get_max_gain())); } +void +FaderOption::on_activate () +{ + float db_val = atof (_db_display.get_text ().c_str ()); + gain_t coeff_val = dB_to_coefficient (db_val); + + _db_adjustment.set_value (gain_to_slider_position_with_max (coeff_val, Config->get_max_gain ())); +} + +bool +FaderOption::on_key_press (GdkEventKey* ev) +{ + if (ARDOUR_UI_UTILS::key_is_legal_for_numeric_entry (ev->keyval)) { + /* drop through to normal handling */ + return false; + } + /* illegal key for gain entry */ + return true; +} + void FaderOption::add_to_page (OptionEditorPage* p) { diff --git a/gtk2_ardour/option_editor.h b/gtk2_ardour/option_editor.h index 67835b291a..c69d4e03a4 100644 --- a/gtk2_ardour/option_editor.h +++ b/gtk2_ardour/option_editor.h @@ -582,6 +582,8 @@ public: private: void db_changed (); + void on_activate (); + bool on_key_press (GdkEventKey* ev); Gtk::Adjustment _db_adjustment; Gtkmm2ext::HSliderController* _db_slider;