/[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 2507 by persson, Sun Jan 12 19:37:55 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 281  public: Line 293  public:
293      void set_value(int32_t value);      void set_value(int32_t value);
294  };  };
295    
296    
297  class StringEntry : public LabelWidget {  class StringEntry : public LabelWidget {
298  private:  private:
299      Gtk::Entry entry;      Gtk::Entry entry;
300  public:  public:
301      StringEntry(const char* labelText);      StringEntry(const char* labelText);
302      gig::String get_value() const { return entry.get_text(); }      gig::String get_value() const;
303      void set_value(gig::String value) { entry.set_text(value); }      void set_value(const gig::String& value);
304      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); }
305  };  };
306    
# Line 299  private: Line 312  private:
312  public:  public:
313      StringEntryMultiLine(const char* labelText);      StringEntryMultiLine(const char* labelText);
314      gig::String get_value() const;      gig::String get_value() const;
315      void set_value(gig::String value);      void set_value(const gig::String& value);
316    };
317    
318    
319    /**
320     * Container widget for LabelWidgets.
321     */
322    class Table : public Gtk::Table
323    {
324    public:
325        Table(int x, int y);
326        void add(BoolEntry& boolentry);
327        void add(BoolEntryPlus6& boolentry);
328        void add(LabelWidget& labelwidget);
329    private:
330        int rowno;
331  };  };
332    
333    
334    /**
335     * Base class for editor components that use LabelWidgets to edit
336     * member variables of the same class. By connecting the widgets to
337     * members of the model class, the model is automatically kept
338     * updated.
339     */
340    template<class M>
341    class PropEditor {
342    public:
343        sigc::signal<void>& signal_changed() {
344            return sig_changed;
345        }
346    protected:
347        M* m;
348        int update_model; // to prevent infinite update loops
349        PropEditor() : m(0), update_model(0) { }
350        sigc::signal<void> sig_changed;
351    
352        template<class C, typename T>
353        void connect(C& widget, T M::* member) {
354            // gcc 4.1.2 needs this temporary variable to resolve the
355            // address
356            void (PropEditor::*f)(const C* w, T M::* member) =
357                &PropEditor::set_member;
358            widget.signal_value_changed().connect(
359                sigc::bind(sigc::mem_fun(*this, f), &widget, member));
360    
361            void (PropEditor::*g)(C* w, T M::* member) =
362                &PropEditor::get_member;
363            sig.connect(
364                sigc::bind(sigc::mem_fun(*this, g), &widget, member));
365        }
366    
367        template<class C, class S, typename T>
368        void connect(C& widget, void (S::*setter)(T)) {
369            void (PropEditor::*f)(const C* w, void (S::*setter)(T)) =
370                &PropEditor<M>::call_setter;
371            widget.signal_value_changed().connect(
372                sigc::bind(sigc::mem_fun(*this, f), &widget, setter));
373        }
374    
375        void connect(NoteEntry& eKeyRangeLow, NoteEntry& eKeyRangeHigh,
376                     gig::range_t M::* range) {
377            eKeyRangeLow.signal_value_changed().connect(
378                sigc::bind(
379                    sigc::mem_fun(*this, &PropEditor::key_range_low_changed),
380                    &eKeyRangeLow, &eKeyRangeHigh, range));
381            eKeyRangeHigh.signal_value_changed().connect(
382                sigc::bind(
383                    sigc::mem_fun(*this, &PropEditor::key_range_high_changed),
384                    &eKeyRangeLow, &eKeyRangeHigh, range));
385            sig.connect(
386                sigc::bind(sigc::mem_fun(*this, &PropEditor::get_key_range),
387                           &eKeyRangeLow, &eKeyRangeHigh, range));
388        }
389    
390        void update(M* m) {
391            update_model++;
392            this->m = m;
393            sig.emit();
394            update_model--;
395        }
396    
397    private:
398        sigc::signal<void> sig;
399    
400        void key_range_low_changed(NoteEntry* eKeyRangeLow,
401                                   NoteEntry* eKeyRangeHigh,
402                                   gig::range_t M::* range) {
403            if (update_model == 0) {
404                uint8_t value = eKeyRangeLow->get_value();
405                (m->*range).low = value;
406                if (value > (m->*range).high) {
407                    eKeyRangeHigh->set_value(value);
408                }
409                sig_changed();
410            }
411        }
412    
413        void key_range_high_changed(NoteEntry* eKeyRangeLow,
414                                    NoteEntry* eKeyRangeHigh,
415                                    gig::range_t M::* range) {
416            if (update_model == 0) {
417                uint8_t value = eKeyRangeHigh->get_value();
418                (m->*range).high = value;
419                if (value < (m->*range).low) {
420                    eKeyRangeLow->set_value(value);
421                }
422                sig_changed();
423            }
424        }
425    
426        template<class C, typename T>
427        void set_member(const C* w, T M::* member) {
428            if (update_model == 0) {
429                m->*member = w->get_value();
430                sig_changed();
431            }
432        }
433    
434        template<class C, typename T>
435        void get_member(C* w, T M::* member) {
436            w->set_value(m->*member);
437        }
438    
439        void get_key_range(NoteEntry* eKeyRangeLow,
440                           NoteEntry* eKeyRangeHigh,
441                           gig::range_t M::* range) {
442            eKeyRangeLow->set_value((m->*range).low);
443            eKeyRangeHigh->set_value((m->*range).high);
444        }
445    
446        template<class C, class S, typename T>
447        void call_setter(const C* w, void (S::*setter)(T)) {
448            if (update_model == 0) {
449                (static_cast<S*>(this)->*setter)(w->get_value());
450                sig_changed();
451            }
452        }
453    };
454    
455  #endif  #endif

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

  ViewVC Help
Powered by ViewVC