/[svn]/gigedit/trunk/src/propedit.h
ViewVC logotype

Annotation of /gigedit/trunk/src/propedit.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1057 - (hide annotations) (download) (as text)
Sat Mar 3 12:20:05 2007 UTC (14 years, 6 months ago) by persson
File MIME type: text/x-c++hdr
File size: 8070 byte(s)
Initial revision

1 persson 1057 /* -*- C++ -*- */
2    
3     #include <gig.h>
4    
5     #include <gtkmm/alignment.h>
6     #include <gtkmm/comboboxtext.h>
7     #include <gtkmm/label.h>
8     #include <gtkmm/spinbutton.h>
9    
10    
11     class ConverterPermille {
12     public:
13     uint16_t convert1(double x);
14     double convert2(uint16_t x);
15     };
16    
17     template<typename T>
18     class ConverterNum {
19     public:
20     T convert1(double x) { return T(x); }
21     double convert2(T x) { return x; }
22     };
23    
24     template<typename T>
25     class ConverterChoice {
26     private:
27     const T* values;
28     public:
29     T convert1(int x);
30     int convert2(T x);
31     };
32    
33     class ConverterChoiceLevCtrl {
34     public:
35     gig::leverage_ctrl_t convert1(int x);
36     int convert2(gig::leverage_ctrl_t x);
37     };
38    
39     class ConverterBool {
40     public:
41     bool convert1(bool x) { return x; }
42     bool convert2(bool x) { return x; }
43     };
44    
45    
46     template<typename T>
47     class Tjosan : public ConverterNum<T> {
48     using ConverterNum<T>::convert1;
49     private:
50     T* var;
51     public:
52     void value_changed();
53     };
54    
55    
56     template<typename T>
57     void Tjosan<T>::value_changed() {
58     var = convert1(4.2);
59     };
60    
61     // -------------------------------------------------------------------------
62     class LabelWidget {
63     public:
64     Gtk::Label label;
65     Gtk::Widget& widget;
66    
67     LabelWidget(char* labelText, Gtk::Widget& widget);
68     void set_sensitive(bool sensitive = true);
69     };
70    
71     // -------------------------------------------------------------------------
72     template<typename T2>
73     class NumEntry : public LabelWidget {
74     protected:
75     Gtk::SpinButton spinbutton;
76     Gtk::Alignment align;
77     T2* dimreg;
78     public:
79     NumEntry(char* labelText, double lower = 0, double upper = 127,
80     int decimals = 0);
81     };
82    
83     // -------------------------------------------------------------------------
84     template<typename T>
85     class NumEntryX : public NumEntry<gig::DimensionRegion> {
86     private:
87     T& (*access)(gig::DimensionRegion*);
88     void value_changed();
89     public:
90     NumEntryX(char* labelText, T& (*access)(gig::DimensionRegion*),
91     double lower = 0, double upper = 127, int decimals = 0);
92     void set_dimreg(gig::DimensionRegion* dimreg);
93     };
94    
95    
96     // -------------------------------------------------------------------------
97     template<typename T, typename T2 = gig::DimensionRegion>
98     class NumEntryTemp : public NumEntry<T2> {
99     using NumEntry<T2>::spinbutton;
100     using NumEntry<T2>::dimreg;
101     private:
102     T T2::* param;
103     void value_changed();
104     public:
105     NumEntryTemp(char* labelText, T T2::* param,
106     double lower = 0, double upper = 127, int decimals = 0);
107     void set_dimreg(gig::DimensionRegion* dimreg);
108     };
109    
110    
111     // -------------------------------------------------------------------------
112     class NumEntryPermille : public NumEntry<gig::DimensionRegion> {
113     private:
114     uint16_t gig::DimensionRegion::* param;
115     void value_changed();
116     public:
117     NumEntryPermille(char* labelText, uint16_t gig::DimensionRegion::* param,
118     double lower = 0, double upper = 127, int decimals = 0);
119     void set_dimreg(gig::DimensionRegion* dimreg);
120     };
121    
122    
123     // -------------------------------------------------------------------------
124     template<typename T>
125     class ChoiceEntry : public LabelWidget {
126     private:
127     Gtk::ComboBoxText combobox;
128     T gig::DimensionRegion::* param;
129     gig::DimensionRegion* dimreg;
130     void value_changed();
131     const T* values;
132     public:
133     ChoiceEntry(char* labelText,
134     T gig::DimensionRegion::* param);
135     void set_choices(char** texts, const T* values);
136     void set_dimreg(gig::DimensionRegion* dimreg);
137     bool get_active_row_number() { return combobox.get_active_row_number(); }
138     Glib::SignalProxy0<void> signal_changed() {
139     return combobox.signal_changed();
140     }
141     };
142    
143    
144     // -------------------------------------------------------------------------
145     class ChoiceEntryLeverageCtrl : public LabelWidget {
146     private:
147     Gtk::ComboBoxText combobox;
148     gig::leverage_ctrl_t gig::DimensionRegion::* param;
149     gig::DimensionRegion* dimreg;
150     void value_changed();
151     public:
152     ChoiceEntryLeverageCtrl(char* labelText,
153     gig::leverage_ctrl_t gig::DimensionRegion::* param);
154     void set_dimreg(gig::DimensionRegion* dimreg);
155     bool get_active_row_number() { return combobox.get_active_row_number(); }
156     Glib::SignalProxy0<void> signal_changed() {
157     return combobox.signal_changed();
158     }
159     };
160    
161    
162    
163     // -------------------------------------------------------------------------
164     class BoolEntry : public LabelWidget {
165     private:
166     Gtk::CheckButton checkbutton;
167     bool gig::DimensionRegion::* param;
168     gig::DimensionRegion* dimreg;
169     void value_changed();
170     public:
171     BoolEntry(char* labelText, bool gig::DimensionRegion::* param);
172     void set_dimreg(gig::DimensionRegion* dimreg);
173     bool get_active() { return checkbutton.get_active(); }
174     Glib::SignalProxy0<void> signal_toggled() {
175     return checkbutton.signal_toggled();
176     }
177     };
178    
179    
180    
181     // -------------------------------------------------------------------------
182     // Implementation of template functions
183    
184    
185     // -------------------------------------------------------------------------
186     template<typename T2>
187     NumEntry<T2>::NumEntry(char* labelText, double lower, double upper,
188     int decimals) :
189     align(0, 0, 0, 0),
190     LabelWidget(labelText, align)
191     {
192     spinbutton.set_range(lower, upper);
193     spinbutton.set_increments(1, 10);
194     spinbutton.set_digits(decimals);
195    
196     align.add(spinbutton);
197     }
198    
199    
200     // -------------------------------------------------------------------------
201     template<typename T>
202     NumEntryX<T>::NumEntryX(char* labelText, T& (*access)(gig::DimensionRegion*),
203     double lower, double upper, int decimals) :
204     NumEntry<gig::DimensionRegion>(labelText, lower, upper, decimals),
205     access(access)
206     {
207     spinbutton.signal_value_changed().connect(
208     sigc::mem_fun(*this, &NumEntryX::value_changed));
209     }
210    
211     template<typename T>
212     void NumEntryX<T>::value_changed()
213     {
214     if (dimreg) {
215     access(dimreg) = T(spinbutton.get_value());
216     }
217     }
218    
219     template<typename T>
220     void NumEntryX<T>::set_dimreg(gig::DimensionRegion* dimreg)
221     {
222     this->dimreg = 0;
223     spinbutton.set_value(access(dimreg));
224     this->dimreg = dimreg;
225     }
226    
227    
228     // -------------------------------------------------------------------------
229     template<typename T, typename T2>
230     NumEntryTemp<T, T2>::NumEntryTemp(char* labelText, T T2::* param,
231     double lower, double upper, int decimals) :
232     NumEntry<T2>(labelText, lower, upper, decimals),
233     param(param)
234     {
235     spinbutton.signal_value_changed().connect(
236     sigc::mem_fun(*this, &NumEntryTemp<T, T2>::value_changed));
237     }
238    
239     template<typename T, typename T2>
240     void NumEntryTemp<T, T2>::value_changed()
241     {
242     if (dimreg) {
243     dimreg->*param = T(spinbutton.get_value());
244     }
245     }
246    
247     template<typename T, typename T2>
248     void NumEntryTemp<T, T2>::set_dimreg(gig::DimensionRegion* dimreg)
249     {
250     this->dimreg = 0;
251     spinbutton.set_value(dimreg->*param);
252     this->dimreg = dimreg;
253     }
254    
255    
256     // -------------------------------------------------------------------------
257     template<typename T>
258     ChoiceEntry<T>::ChoiceEntry(char* labelText,
259     T gig::DimensionRegion::* param) :
260     LabelWidget(labelText, combobox),
261     param(param)
262     {
263     combobox.signal_changed().connect(
264     sigc::mem_fun(*this, &ChoiceEntry::value_changed));
265     }
266    
267     template<typename T>
268     void ChoiceEntry<T>::set_choices(char** texts, const T* values)
269     {
270     for (int i = 0 ; texts[i] ; i++) {
271     combobox.append_text(texts[i]);
272     }
273     this->values = values;
274     }
275    
276     template<typename T>
277     void ChoiceEntry<T>::value_changed()
278     {
279     if (dimreg) {
280     int rowno = combobox.get_active_row_number();
281     if (rowno != -1) dimreg->*param = values[rowno];
282     }
283     }
284    
285     template<typename T>
286     void ChoiceEntry<T>::set_dimreg(gig::DimensionRegion* dimreg)
287     {
288     this->dimreg = 0;
289     T value = dimreg->*param;
290     int row = 0;
291     int nb_rows = combobox.get_model()->children().size();
292     for (; row < nb_rows ; row++) {
293     if (value == values[row]) break;
294     }
295     combobox.set_active(row == nb_rows ? -1 : row);
296     this->dimreg = dimreg;
297     }
298    

  ViewVC Help
Powered by ViewVC