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

Diff of /gigedit/trunk/src/gigedit/paramedit.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2169 by persson, Sun Mar 6 07:51:04 2011 UTC revision 2566 by schoenebeck, Tue May 20 14:35:36 2014 UTC
# Line 1  Line 1 
1  /*                                                         -*- c++ -*-  /*                                                         -*- c++ -*-
2   * Copyright (C) 2006-2011 Andreas Persson   * Copyright (C) 2006-2014 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# Line 24  Line 24 
24    
25  #include <cmath>  #include <cmath>
26    
27    #include <glibmm/convert.h>
28  #include <gtkmm/adjustment.h>  #include <gtkmm/adjustment.h>
29  #include <gtkmm/alignment.h>  #include <gtkmm/alignment.h>
30  #include <gtkmm/box.h>  #include <gtkmm/box.h>
# Line 33  Line 34 
34  #include <gtkmm/label.h>  #include <gtkmm/label.h>
35  #include <gtkmm/scale.h>  #include <gtkmm/scale.h>
36  #include <gtkmm/spinbutton.h>  #include <gtkmm/spinbutton.h>
37    #include <gtkmm/table.h>
38  #include <gtkmm/textview.h>  #include <gtkmm/textview.h>
39    
40  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 12) || GTKMM_MAJOR_VERSION < 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 12) || GTKMM_MAJOR_VERSION < 2
# Line 40  Line 42 
42  #include <gtkmm/tooltips.h>  #include <gtkmm/tooltips.h>
43  #endif  #endif
44    
45    
46    Glib::ustring gig_to_utf8(const gig::String& gig_string);
47    gig::String gig_from_utf8(const Glib::ustring& utf8_string);
48    
49    int note_value(const Glib::ustring& note);
50    Glib::ustring note_str(int note);
51    
52    void spin_button_show_notes(Gtk::SpinButton& spin_button);
53    
54  class LabelWidget {  class LabelWidget {
55  public:  public:
56      Gtk::Label label;      Gtk::Label label;
# Line 200  public: Line 211  public:
211  template<typename T>  template<typename T>
212  ChoiceEntry<T>::ChoiceEntry(const char* labelText) :  ChoiceEntry<T>::ChoiceEntry(const char* labelText) :
213      LabelWidget(labelText, align),      LabelWidget(labelText, align),
214      align(0, 0, 0, 0)      align(0, 0, 0, 0),
215        values(0)
216  {  {
217      combobox.signal_changed().connect(sig_changed.make_slot());      combobox.signal_changed().connect(sig_changed.make_slot());
218      align.add(combobox);      align.add(combobox);
# Line 210  template<typename T> Line 222  template<typename T>
222  void ChoiceEntry<T>::set_choices(const char** texts, const T* values)  void ChoiceEntry<T>::set_choices(const char** texts, const T* values)
223  {  {
224      for (int i = 0 ; texts[i] ; i++) {      for (int i = 0 ; texts[i] ; i++) {
225  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 24) || GTKMM_MAJOR_VERSION < 2
226          combobox.append_text(texts[i]);          combobox.append_text(texts[i]);
227  #else  #else
228          combobox.append(texts[i]);          combobox.append(texts[i]);
# Line 248  public: Line 260  public:
260      ChoiceEntryLeverageCtrl(const char* labelText);      ChoiceEntryLeverageCtrl(const char* labelText);
261      gig::leverage_ctrl_t get_value() const { return value; }      gig::leverage_ctrl_t get_value() const { return value; }
262      void set_value(gig::leverage_ctrl_t value);      void set_value(gig::leverage_ctrl_t value);
263        void set_tip(const Glib::ustring& tip_text) {
264            combobox.set_tooltip_text(tip_text);
265        }
266  };  };
267    
268    
# Line 281  public: Line 296  public:
296      void set_value(int32_t value);      void set_value(int32_t value);
297  };  };
298    
299    
300  class StringEntry : public LabelWidget {  class StringEntry : public LabelWidget {
301  private:  private:
302      Gtk::Entry entry;      Gtk::Entry entry;
303  public:  public:
304      StringEntry(const char* labelText);      StringEntry(const char* labelText);
305      gig::String get_value() const { return entry.get_text(); }      gig::String get_value() const;
306      void set_value(gig::String value) { entry.set_text(value); }      void set_value(const gig::String& value);
307      void set_width_chars(int n_chars) { entry.set_width_chars(n_chars); }      void set_width_chars(int n_chars) { entry.set_width_chars(n_chars); }
308  };  };
309    
# Line 299  private: Line 315  private:
315  public:  public:
316      StringEntryMultiLine(const char* labelText);      StringEntryMultiLine(const char* labelText);
317      gig::String get_value() const;      gig::String get_value() const;
318      void set_value(gig::String value);      void set_value(const gig::String& value);
319    };
320    
321    
322    /**
323     * Container widget for LabelWidgets.
324     */
325    class Table : public Gtk::Table
326    {
327    public:
328        Table(int x, int y);
329        void add(BoolEntry& boolentry);
330        void add(BoolEntryPlus6& boolentry);
331        void add(LabelWidget& labelwidget);
332    private:
333        int rowno;
334  };  };
335    
336    
337    /**
338     * Base class for editor components that use LabelWidgets to edit
339     * member variables of the same class. By connecting the widgets to
340     * members of the model class, the model is automatically kept
341     * updated.
342     */
343    template<class M>
344    class PropEditor {
345    public:
346        sigc::signal<void>& signal_changed() {
347            return sig_changed;
348        }
349    protected:
350        M* m;
351        int update_model; // to prevent infinite update loops
352        PropEditor() : m(0), update_model(0) { }
353        sigc::signal<void> sig_changed;
354    
355        template<class C, typename T>
356        void connect(C& widget, T M::* member) {
357            // gcc 4.1.2 needs this temporary variable to resolve the
358            // address
359            void (PropEditor::*f)(const C* w, T M::* member) =
360                &PropEditor::set_member;
361            widget.signal_value_changed().connect(
362                sigc::bind(sigc::mem_fun(*this, f), &widget, member));
363    
364            void (PropEditor::*g)(C* w, T M::* member) =
365                &PropEditor::get_member;
366            sig.connect(
367                sigc::bind(sigc::mem_fun(*this, g), &widget, member));
368        }
369    
370        template<class C, class S, typename T>
371        void connect(C& widget, void (S::*setter)(T)) {
372            void (PropEditor::*f)(const C* w, void (S::*setter)(T)) =
373                &PropEditor<M>::call_setter;
374            widget.signal_value_changed().connect(
375                sigc::bind(sigc::mem_fun(*this, f), &widget, setter));
376        }
377    
378        void connect(NoteEntry& eKeyRangeLow, NoteEntry& eKeyRangeHigh,
379                     gig::range_t M::* range) {
380            eKeyRangeLow.signal_value_changed().connect(
381                sigc::bind(
382                    sigc::mem_fun(*this, &PropEditor::key_range_low_changed),
383                    &eKeyRangeLow, &eKeyRangeHigh, range));
384            eKeyRangeHigh.signal_value_changed().connect(
385                sigc::bind(
386                    sigc::mem_fun(*this, &PropEditor::key_range_high_changed),
387                    &eKeyRangeLow, &eKeyRangeHigh, range));
388            sig.connect(
389                sigc::bind(sigc::mem_fun(*this, &PropEditor::get_key_range),
390                           &eKeyRangeLow, &eKeyRangeHigh, range));
391        }
392    
393        void update(M* m) {
394            update_model++;
395            this->m = m;
396            sig.emit();
397            update_model--;
398        }
399    
400    private:
401        sigc::signal<void> sig;
402    
403        void key_range_low_changed(NoteEntry* eKeyRangeLow,
404                                   NoteEntry* eKeyRangeHigh,
405                                   gig::range_t M::* range) {
406            if (update_model == 0) {
407                uint8_t value = eKeyRangeLow->get_value();
408                (m->*range).low = value;
409                if (value > (m->*range).high) {
410                    eKeyRangeHigh->set_value(value);
411                }
412                sig_changed();
413            }
414        }
415    
416        void key_range_high_changed(NoteEntry* eKeyRangeLow,
417                                    NoteEntry* eKeyRangeHigh,
418                                    gig::range_t M::* range) {
419            if (update_model == 0) {
420                uint8_t value = eKeyRangeHigh->get_value();
421                (m->*range).high = value;
422                if (value < (m->*range).low) {
423                    eKeyRangeLow->set_value(value);
424                }
425                sig_changed();
426            }
427        }
428    
429        template<class C, typename T>
430        void set_member(const C* w, T M::* member) {
431            if (update_model == 0) {
432                m->*member = w->get_value();
433                sig_changed();
434            }
435        }
436    
437        template<class C, typename T>
438        void get_member(C* w, T M::* member) {
439            w->set_value(m->*member);
440        }
441    
442        void get_key_range(NoteEntry* eKeyRangeLow,
443                           NoteEntry* eKeyRangeHigh,
444                           gig::range_t M::* range) {
445            eKeyRangeLow->set_value((m->*range).low);
446            eKeyRangeHigh->set_value((m->*range).high);
447        }
448    
449        template<class C, class S, typename T>
450        void call_setter(const C* w, void (S::*setter)(T)) {
451            if (update_model == 0) {
452                (static_cast<S*>(this)->*setter)(w->get_value());
453                sig_changed();
454            }
455        }
456    };
457    
458  #endif  #endif

Legend:
Removed from v.2169  
changed lines
  Added in v.2566

  ViewVC Help
Powered by ViewVC