From ae598c51295d2018f1f8e5853b9be255eab449ed Mon Sep 17 00:00:00 2001 From: Carlos Lopez Date: Sun, 12 Dec 2010 13:52:57 +0100 Subject: [PATCH] Enable tooltips and allow use the 'hint' descriptor for some types for the linkable value node child parameters. This allows to use enum widgets for integer values on linkable value node child parameters. It still seeing the bug of set the enum when the value is =1 that probably is due to the Gtk::OptionMenu is deprecated. --- .../src/gui/cellrenderer/cellrenderer_value.cpp | 62 ++++++++++++++-------- .../src/gui/cellrenderer/cellrenderer_value.h | 3 ++ synfig-studio/src/gui/trees/canvastreestore.cpp | 6 ++- synfig-studio/src/gui/trees/canvastreestore.h | 2 + synfig-studio/src/gui/trees/layertree.cpp | 1 + synfig-studio/src/gui/widgets/widget_value.cpp | 33 +++++++----- synfig-studio/src/gui/widgets/widget_value.h | 4 ++ 7 files changed, 74 insertions(+), 37 deletions(-) diff --git a/synfig-studio/src/gui/cellrenderer/cellrenderer_value.cpp b/synfig-studio/src/gui/cellrenderer/cellrenderer_value.cpp index 553a517..3c9c699 100644 --- a/synfig-studio/src/gui/cellrenderer/cellrenderer_value.cpp +++ b/synfig-studio/src/gui/cellrenderer/cellrenderer_value.cpp @@ -197,6 +197,12 @@ public: valuewidget->set_param_desc(data); } + void set_child_param_desc(const synfig::ParamDesc &data) + { + if(valuewidget) + valuewidget->set_child_param_desc(data); + } + const synfig::ValueBase &get_value() { if(valuewidget) @@ -265,7 +271,8 @@ CellRenderer_ValueBase::CellRenderer_ValueBase(): Gtk::CellRendererText (), property_value_ (*this,"value",synfig::ValueBase()), property_canvas_(*this,"canvas",etl::handle()), - property_param_desc_(*this,"param_desc",synfig::ParamDesc()) + property_param_desc_(*this,"param_desc",synfig::ParamDesc()), + property_child_param_desc_(*this,"child_param_desc", synfig::ParamDesc()) { CellRendererText::signal_edited().connect(sigc::mem_fun(*this,&CellRenderer_ValueBase::string_edited_)); value_entry=new ValueBase_Entry(); @@ -359,31 +366,39 @@ CellRenderer_ValueBase::render_vfunc( property_text()=(Glib::ustring)strprintf("%.2fᵒ",(Real)Angle::deg(data.get(Angle())).get()); break; case ValueBase::TYPE_INTEGER: - if(((synfig::ParamDesc)property_param_desc_).get_hint()!="enum") - { - property_text()=(Glib::ustring)strprintf("%i",data.get(int())); - } - else { - property_text()=(Glib::ustring)strprintf("(%i)",data.get(int())); - std::list enum_list=((synfig::ParamDesc)property_param_desc_).get_enum_list(); - std::list::iterator iter; - - for(iter=enum_list.begin();iter!=enum_list.end();iter++) - if(iter->value==data.get(int())) - { - // don't show the key_board s_hortcut under_scores - String local_name = iter->local_name; - String::size_type pos = local_name.find_first_of('_'); - if (pos != String::npos) - property_text() = local_name.substr(0,pos) + local_name.substr(pos+1); - else - property_text() = local_name; - break; - } + String param_hint, child_param_hint; + param_hint=get_param_desc().get_hint(); + child_param_hint=get_child_param_desc().get_hint(); + if(param_hint!="enum" && child_param_hint!="enum") + { + property_text()=(Glib::ustring)strprintf("%i",data.get(int())); + } + else + { + property_text()=(Glib::ustring)strprintf("(%i)",data.get(int())); + std::list enum_list; + if(param_hint=="enum") + enum_list=((synfig::ParamDesc)property_param_desc_).get_enum_list(); + else if(child_param_hint=="enum") + enum_list=((synfig::ParamDesc)property_child_param_desc_).get_enum_list(); + std::list::iterator iter; + for(iter=enum_list.begin();iter!=enum_list.end();iter++) + if(iter->value==data.get(int())) + { + // don't show the key_board s_hortcut under_scores + String local_name = iter->local_name; + String::size_type pos = local_name.find_first_of('_'); + if (pos != String::npos) + property_text() = local_name.substr(0,pos) + local_name.substr(pos+1); + else + property_text() = local_name; + break; + } + } } - break; + case ValueBase::TYPE_VECTOR: { Vector vector=data.get(Vector()); @@ -570,6 +585,7 @@ CellRenderer_ValueBase::start_editing_vfunc( value_entry->set_path(path); value_entry->set_canvas(get_canvas()); value_entry->set_param_desc(get_param_desc()); + value_entry->set_child_param_desc(get_child_param_desc()); value_entry->set_value(data); value_entry->set_parent(&widget); value_entry->signal_editing_done().connect(sigc::mem_fun(*this, &CellRenderer_ValueBase::on_value_editing_done)); diff --git a/synfig-studio/src/gui/cellrenderer/cellrenderer_value.h b/synfig-studio/src/gui/cellrenderer/cellrenderer_value.h index 14a425d..2d1e21f 100644 --- a/synfig-studio/src/gui/cellrenderer/cellrenderer_value.h +++ b/synfig-studio/src/gui/cellrenderer/cellrenderer_value.h @@ -81,6 +81,7 @@ class CellRenderer_ValueBase : public Gtk::CellRendererText Glib::Property property_value_; Glib::Property > property_canvas_; Glib::Property property_param_desc_; + Glib::Property property_child_param_desc_; void string_edited_(const Glib::ustring&,const Glib::ustring&); @@ -98,10 +99,12 @@ public: Glib::PropertyProxy property_value() { return property_value_.get_proxy();} Glib::PropertyProxy > property_canvas() { return property_canvas_.get_proxy();} Glib::PropertyProxy property_param_desc() { return property_param_desc_.get_proxy(); } + Glib::PropertyProxy property_child_param_desc() { return property_child_param_desc_.get_proxy(); } Glib::PropertyProxy property_inconsistent() { return property_foreground_set(); } etl::handle get_canvas()const { return property_canvas_; } synfig::ParamDesc get_param_desc()const { return property_param_desc_; } + synfig::ParamDesc get_child_param_desc()const { return property_child_param_desc_; } CellRenderer_ValueBase(); ~CellRenderer_ValueBase(); diff --git a/synfig-studio/src/gui/trees/canvastreestore.cpp b/synfig-studio/src/gui/trees/canvastreestore.cpp index 6b928f1..77ffe4b 100644 --- a/synfig-studio/src/gui/trees/canvastreestore.cpp +++ b/synfig-studio/src/gui/trees/canvastreestore.cpp @@ -427,12 +427,16 @@ CanvasTreeStore::set_row(Gtk::TreeRow row,synfigapp::ValueDesc value_desc, bool if(linkable && do_children) { row[model.link_count] = linkable->link_count(); - for(int i=0;ilink_count();i++) + LinkableValueNode::Vocab vocab(linkable->get_param_vocab()); + LinkableValueNode::Vocab::iterator iter(vocab.begin()); + for(int i=0;ilink_count();i++, iter++) { Gtk::TreeRow child_row=*(append(row.children())); child_row[model.link_id] = i; child_row[model.canvas] = static_cast(row[model.canvas]); child_row[model.name] = linkable->link_local_name(i); + child_row[model.tooltip] = iter->get_description(); + child_row[model.child_param_desc] = *iter; set_row(child_row,synfigapp::ValueDesc(linkable,i)); } } diff --git a/synfig-studio/src/gui/trees/canvastreestore.h b/synfig-studio/src/gui/trees/canvastreestore.h index d7e119a..b302db1 100644 --- a/synfig-studio/src/gui/trees/canvastreestore.h +++ b/synfig-studio/src/gui/trees/canvastreestore.h @@ -87,6 +87,7 @@ public: Gtk::TreeModelColumn is_exported; Gtk::TreeModelColumn value_desc; + Gtk::TreeModelColumn child_param_desc; Gtk::TreeModelColumn tooltip; @@ -107,6 +108,7 @@ public: add(is_exported); add(is_editable); add(value_desc); + add(child_param_desc); add(link_count); add(link_id); diff --git a/synfig-studio/src/gui/trees/layertree.cpp b/synfig-studio/src/gui/trees/layertree.cpp index a17529e..66884c4 100644 --- a/synfig-studio/src/gui/trees/layertree.cpp +++ b/synfig-studio/src/gui/trees/layertree.cpp @@ -315,6 +315,7 @@ LayerTree::create_param_tree() cellrenderer_value->signal_edited().connect(sigc::mem_fun(*this, &studio::LayerTree::on_edited_value)); cellrenderer_value->property_value()=synfig::ValueBase(); column->add_attribute(cellrenderer_value->property_param_desc(), param_model.param_desc); + column->add_attribute(cellrenderer_value->property_child_param_desc(), param_model.child_param_desc); column->add_attribute(cellrenderer_value->property_inconsistent(),param_model.is_inconsistent); //cellrenderer_value->property_canvas()=canvas_interface->get_canvas(); // Is this line necessary? cellrenderer_value->property_attributes()=attr_list; diff --git a/synfig-studio/src/gui/widgets/widget_value.cpp b/synfig-studio/src/gui/widgets/widget_value.cpp index ee0366f..be291fa 100644 --- a/synfig-studio/src/gui/widgets/widget_value.cpp +++ b/synfig-studio/src/gui/widgets/widget_value.cpp @@ -221,7 +221,7 @@ Widget_ValueBase::set_value(const synfig::ValueBase &data) vector_widget->show(); break; case ValueBase::TYPE_REAL: - if(param_desc.get_is_distance() && canvas) + if(( child_param_desc.get_is_distance() || param_desc.get_is_distance() )&& canvas) { Distance dist(value.get(Real()),Distance::SYSTEM_UNITS); dist.convert(App::distance_system,canvas->rend_desc()); @@ -244,16 +244,23 @@ Widget_ValueBase::set_value(const synfig::ValueBase &data) angle_widget->show(); break; case ValueBase::TYPE_INTEGER: - if(param_desc.get_hint()!="enum") - { - integer_widget->set_value(value.get(int())); - integer_widget->show(); - } - else { - enum_widget->set_param_desc(param_desc); - enum_widget->set_value(value.get(int())); - enum_widget->show(); + String child_param_hint(child_param_desc.get_hint()); + String param_hint(param_desc.get_hint()); + if(child_param_hint!="enum" && param_hint!="enum") + { + integer_widget->set_value(value.get(int())); + integer_widget->show(); + } + else + { + if(child_param_hint=="enum") + enum_widget->set_param_desc(child_param_desc); + else + enum_widget->set_param_desc(param_desc); + enum_widget->set_value(value.get(int())); + enum_widget->show(); + } } break; case ValueBase::TYPE_CANVAS: @@ -267,7 +274,7 @@ Widget_ValueBase::set_value(const synfig::ValueBase &data) bool_widget->show(); break; case ValueBase::TYPE_STRING: - if(param_desc.get_hint()!="filename") + if(child_param_desc.get_hint()!="filename" && param_desc.get_hint()!="filename") { string_widget->set_text(value.get(string())); string_widget->show(); @@ -324,7 +331,7 @@ Widget_ValueBase::get_value() value=canvas_widget->get_value(); break; case ValueBase::TYPE_INTEGER: - if(param_desc.get_hint()!="enum") + if(child_param_desc.get_hint()!="enum" && param_desc.get_hint()!="enum") { value=integer_widget->get_value_as_int(); } @@ -395,7 +402,7 @@ Widget_ValueBase::on_grab_focus() canvas_widget->grab_focus(); break; case ValueBase::TYPE_INTEGER: - if(param_desc.get_hint()!="enum") + if(child_param_desc.get_hint()!="enum" && param_desc.get_hint()!="enum") { integer_widget->grab_focus(); } diff --git a/synfig-studio/src/gui/widgets/widget_value.h b/synfig-studio/src/gui/widgets/widget_value.h index 18f272f..6b15397 100644 --- a/synfig-studio/src/gui/widgets/widget_value.h +++ b/synfig-studio/src/gui/widgets/widget_value.h @@ -99,6 +99,7 @@ class Widget_ValueBase : public Gtk::HBox // std::string hint; synfig::ParamDesc param_desc; + synfig::ParamDesc child_param_desc; etl::handle canvas; sigc::signal signal_value_changed_; sigc::signal signal_activate_; @@ -118,6 +119,9 @@ public: void set_param_desc(const synfig::ParamDesc &x) { param_desc=x; } const synfig::ParamDesc &get_param_desc() { return param_desc; } + void set_child_param_desc(const synfig::ParamDesc &x) { child_param_desc=x; } + const synfig::ParamDesc &get_child_param_desc() { return child_param_desc; } + void set_sensitive(bool x); //void set_hint(std::string x) { hint=x; } -- 2.7.4