1 // Licensed GNU LGPL v3 or later: http://www.gnu.org/licenses/lgpl.html
2 
3 #include "smpropertyview.hh"
4 #include "smlabel.hh"
5 #include "smoperatorlayout.hh"
6 
7 using namespace SpectMorph;
8 
9 using std::string;
10 using std::vector;
11 
PropertyView(Property & property)12 PropertyView::PropertyView (Property& property) :
13   property (property)
14 {
15 }
16 
17 void
set_enabled(bool enabled)18 PropertyView::set_enabled (bool enabled)
19 {
20   title->set_enabled (enabled);
21   slider->set_enabled (enabled);
22   label->set_enabled (enabled);
23 }
24 
25 void
set_visible(bool visible)26 PropertyView::set_visible (bool visible)
27 {
28   title->set_visible (visible);
29   slider->set_visible (visible);
30   label->set_visible (visible);
31 }
32 
33 int
init_ui(Widget * parent,FixedGrid & grid,int yoffset)34 PropertyView::init_ui (Widget *parent, FixedGrid& grid, int yoffset)
35 {
36   slider = new Slider (parent, 0);
37 
38   slider->set_int_range (property.min(), property.max());
39   label = new Label (parent, property.value_label());
40   title = new Label (parent, property.label());
41   slider->set_int_value (property.get());
42 
43   connect (slider->signal_int_value_changed, this, &PropertyView::on_value_changed);
44 
45   grid.add_widget (title, 0, yoffset, 9, 2);
46   grid.add_widget (slider,  9, yoffset, 25, 2);
47   grid.add_widget (label, 35, yoffset, 5, 2);
48 
49   return 2;
50 }
51 
52 void
init_ui(Widget * parent,OperatorLayout & op_layout)53 PropertyView::init_ui (Widget *parent, OperatorLayout& op_layout)
54 {
55   slider = new Slider (parent, 0);
56 
57   slider->set_int_range (property.min(), property.max());
58   label = new Label (parent, property.value_label());
59   title = new Label (parent, property.label());
60   slider->set_int_value (property.get());
61 
62   connect (slider->signal_int_value_changed, this, &PropertyView::on_value_changed);
63 
64   op_layout.add_row (2, title, slider, label);
65 }
66 
67 void
on_value_changed(int value)68 PropertyView::on_value_changed (int value)
69 {
70   property.set (value);
71   label->set_text (property.value_label());
72 
73   signal_value_changed();
74 }
75 
76 void
on_update_value()77 PropertyView::on_update_value()
78 {
79   slider->set_int_value (property.get());
80   label->set_text (property.value_label());
81 }
82