Let Entry of FaderOption react on ENTER and allow only numerical input.
authorAndré Nusser <andre.nusser@googlemail.com>
Wed, 4 Nov 2015 22:10:27 +0000 (23:10 +0100)
committerAndré Nusser <andre.nusser@googlemail.com>
Wed, 4 Nov 2015 22:23:12 +0000 (23:23 +0100)
This enables setting click gain and solo gain in the preferences using
the text field. -- fixes #6668

gtk2_ardour/option_editor.cc
gtk2_ardour/option_editor.h

index a8c35f250fb018808874ba7446086566b77baed0..9ce4997bb82a1e34abc17156f74d3f7cbc17f3f7 100644 (file)
 #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<gain_t>
        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)
 {
index 67835b291a7460cfe269fe382e512f03f3fc15ce..c69d4e03a494f90721a63ab500e9b8bd5b361aa4 100644 (file)
@@ -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;