From 30faf29165b1bcd936e9e0ca3ecc8b4bad4c94d2 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 9 Sep 2017 03:54:39 +0200 Subject: This commit is based on a coment on bug #1670644. And allow to fill the fill between many LPE widget that allow attach all paths on the clipboard instead only one Also added to this widget the option visible, to allow work with multiples paths wigout getting full cracy --- src/live_effects/parameter/originalpatharray.cpp | 134 ++++++++++++++--------- 1 file changed, 83 insertions(+), 51 deletions(-) (limited to 'src/live_effects/parameter/originalpatharray.cpp') diff --git a/src/live_effects/parameter/originalpatharray.cpp b/src/live_effects/parameter/originalpatharray.cpp index 2513a0d5e..13bd23634 100644 --- a/src/live_effects/parameter/originalpatharray.cpp +++ b/src/live_effects/parameter/originalpatharray.cpp @@ -54,12 +54,14 @@ public: add(_colObject); add(_colLabel); add(_colReverse); + add(_colVisible); } virtual ~ModelColumns() {} - Gtk::TreeModelColumn _colObject; + Gtk::TreeModelColumn _colObject; Gtk::TreeModelColumn _colLabel; Gtk::TreeModelColumn _colReverse; + Gtk::TreeModelColumn _colVisible; }; OriginalPathArrayParam::OriginalPathArrayParam( const Glib::ustring& label, @@ -72,6 +74,7 @@ OriginalPathArrayParam::OriginalPathArrayParam( const Glib::ustring& label, _tree(), _text_renderer(), _toggle_renderer(), + _toggle_visible(), _scroller() { _model = new ModelColumns(); @@ -81,13 +84,6 @@ OriginalPathArrayParam::OriginalPathArrayParam( const Glib::ustring& label, _tree.set_reorderable(true); _tree.enable_model_drag_dest (Gdk::ACTION_MOVE); - _text_renderer = manage(new Gtk::CellRendererText()); - int nameColNum = _tree.append_column(_("Name"), *_text_renderer) - 1; - _name_column = _tree.get_column(nameColNum); - _name_column->add_attribute(_text_renderer->property_text(), _model->_colLabel); - - _tree.set_expander_column( *_tree.get_column(nameColNum) ); - _tree.set_search_column(_model->_colLabel); Gtk::CellRendererToggle * _toggle_renderer = manage(new Gtk::CellRendererToggle()); int toggleColNum = _tree.append_column(_("Reverse"), *_toggle_renderer) - 1; @@ -96,6 +92,22 @@ OriginalPathArrayParam::OriginalPathArrayParam( const Glib::ustring& label, _toggle_renderer->signal_toggled().connect(sigc::mem_fun(*this, &OriginalPathArrayParam::on_reverse_toggled)); col->add_attribute(_toggle_renderer->property_active(), _model->_colReverse); + + Gtk::CellRendererToggle * _toggle_visible = manage(new Gtk::CellRendererToggle()); + int toggleColNum2 = _tree.append_column(_("Visible"), *_toggle_visible) - 1; + Gtk::TreeViewColumn* col2 = _tree.get_column(toggleColNum2); + _toggle_visible->set_activatable(true); + _toggle_visible->signal_toggled().connect(sigc::mem_fun(*this, &OriginalPathArrayParam::on_visible_toggled)); + col2->add_attribute(_toggle_visible->property_active(), _model->_colVisible); + + _text_renderer = manage(new Gtk::CellRendererText()); + int nameColNum = _tree.append_column(_("Name"), *_text_renderer) - 1; + _name_column = _tree.get_column(nameColNum); + _name_column->add_attribute(_text_renderer->property_text(), _model->_colLabel); + + _tree.set_expander_column( *_tree.get_column(nameColNum) ); + _tree.set_search_column(_model->_colLabel); + //quick little hack -- newer versions of gtk gave the item zero space allotment _scroller.set_size_request(-1, 120); @@ -112,7 +124,7 @@ OriginalPathArrayParam::OriginalPathArrayParam( const Glib::ustring& label, OriginalPathArrayParam::~OriginalPathArrayParam() { while (!_vector.empty()) { - PathAndDirection *w = _vector.back(); + PathAndDirectionAndVisible *w = _vector.back(); _vector.pop_back(); unlink(w); delete w; @@ -124,7 +136,7 @@ void OriginalPathArrayParam::on_reverse_toggled(const Glib::ustring& path) { Gtk::TreeModel::iterator iter = _store->get_iter(path); Gtk::TreeModel::Row row = *iter; - PathAndDirection *w = row[_model->_colObject]; + PathAndDirectionAndVisible *w = row[_model->_colObject]; row[_model->_colReverse] = !row[_model->_colReverse]; w->reversed = row[_model->_colReverse]; @@ -135,6 +147,21 @@ void OriginalPathArrayParam::on_reverse_toggled(const Glib::ustring& path) _("Link path parameter to path")); } +void OriginalPathArrayParam::on_visible_toggled(const Glib::ustring& path) +{ + Gtk::TreeModel::iterator iter = _store->get_iter(path); + Gtk::TreeModel::Row row = *iter; + PathAndDirectionAndVisible *w = row[_model->_colObject]; + row[_model->_colVisible] = !row[_model->_colVisible]; + w->visibled = row[_model->_colVisible]; + + gchar * full = param_getSVGValue(); + param_write_to_repr(full); + g_free(full); + DocumentUndo::done(param_effect->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, + _("Toggle path parameter to path")); +} + void OriginalPathArrayParam::param_set_default() { @@ -223,8 +250,8 @@ void OriginalPathArrayParam::on_up_button_click() Gtk::TreeModel::Row row = *iter; int i = -1; - std::vector::iterator piter = _vector.begin(); - for (std::vector::iterator iter = _vector.begin(); iter != _vector.end(); piter = iter, i++, ++iter) { + std::vector::iterator piter = _vector.begin(); + for (std::vector::iterator iter = _vector.begin(); iter != _vector.end(); piter = iter, i++, ++iter) { if (*iter == row[_model->_colObject]) { _vector.erase(iter); _vector.insert(piter, row[_model->_colObject]); @@ -250,9 +277,9 @@ void OriginalPathArrayParam::on_down_button_click() Gtk::TreeModel::Row row = *iter; int i = 0; - for (std::vector::iterator iter = _vector.begin(); iter != _vector.end(); i++, ++iter) { + for (std::vector::iterator iter = _vector.begin(); iter != _vector.end(); i++, ++iter) { if (*iter == row[_model->_colObject]) { - std::vector::iterator niter = _vector.erase(iter); + std::vector::iterator niter = _vector.erase(iter); if (niter != _vector.end()) { ++niter; i++; @@ -294,37 +321,40 @@ void OriginalPathArrayParam::on_link_button_click() { Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get(); - Glib::ustring pathid = cm->getShapeOrTextObjectId(SP_ACTIVE_DESKTOP); + std::vector pathsid = cm->getElementsOfType(SP_ACTIVE_DESKTOP, "svg:path"); - if (pathid == "") { + if (pathsid.empty()) { return; } - // add '#' at start to make it an uri. - pathid.insert(pathid.begin(), '#'); - Inkscape::SVGOStringStream os; - bool foundOne = false; - for (std::vector::const_iterator iter = _vector.begin(); iter != _vector.end(); ++iter) { + for (auto i=pathsid.begin();i!=pathsid.end();++i) { + Glib::ustring pathid = *i; + // add '#' at start to make it an uri. + pathid.insert(pathid.begin(), '#'); + bool foundOne = false; + for (std::vector::const_iterator iter = _vector.begin(); iter != _vector.end(); ++iter) { + if (foundOne) { + os << "|"; + } else { + foundOne = true; + } + os << (*iter)->href << "," << ((*iter)->reversed ? "1" : "0") << "," << ((*iter)->visibled ? "1" : "0"); + } + if (foundOne) { os << "|"; - } else { - foundOne = true; } - os << (*iter)->href << "," << ((*iter)->reversed ? "1" : "0"); - } - - if (foundOne) { - os << "|"; + os << pathid.c_str() << ",0"; + if (*i != *(--pathsid.end())) { + os << "|"; + } } - - os << pathid.c_str() << ",0"; - param_write_to_repr(os.str().c_str()); DocumentUndo::done(param_effect->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Link path parameter to path")); } -void OriginalPathArrayParam::unlink(PathAndDirection* to) +void OriginalPathArrayParam::unlink(PathAndDirectionAndVisible* to) { to->linked_modified_connection.disconnect(); to->linked_delete_connection.disconnect(); @@ -336,12 +366,12 @@ void OriginalPathArrayParam::unlink(PathAndDirection* to) } } -void OriginalPathArrayParam::remove_link(PathAndDirection* to) +void OriginalPathArrayParam::remove_link(PathAndDirectionAndVisible* to) { unlink(to); - for (std::vector::iterator iter = _vector.begin(); iter != _vector.end(); ++iter) { + for (std::vector::iterator iter = _vector.begin(); iter != _vector.end(); ++iter) { if (*iter == to) { - PathAndDirection *w = *iter; + PathAndDirectionAndVisible *w = *iter; _vector.erase(iter); delete w; return; @@ -349,7 +379,7 @@ void OriginalPathArrayParam::remove_link(PathAndDirection* to) } } -void OriginalPathArrayParam::linked_delete(SPObject */*deleted*/, PathAndDirection* /*to*/) +void OriginalPathArrayParam::linked_delete(SPObject */*deleted*/, PathAndDirectionAndVisible* /*to*/) { //remove_link(to); @@ -358,7 +388,7 @@ void OriginalPathArrayParam::linked_delete(SPObject */*deleted*/, PathAndDirecti g_free(full); } -bool OriginalPathArrayParam::_updateLink(const Gtk::TreeIter& iter, PathAndDirection* pd) +bool OriginalPathArrayParam::_updateLink(const Gtk::TreeIter& iter, PathAndDirectionAndVisible* pd) { Gtk::TreeModel::Row row = *iter; if (row[_model->_colObject] == pd) { @@ -369,26 +399,26 @@ bool OriginalPathArrayParam::_updateLink(const Gtk::TreeIter& iter, PathAndDirec return false; } -void OriginalPathArrayParam::linked_changed(SPObject */*old_obj*/, SPObject *new_obj, PathAndDirection* to) +void OriginalPathArrayParam::linked_changed(SPObject */*old_obj*/, SPObject *new_obj, PathAndDirectionAndVisible* to) { to->linked_delete_connection.disconnect(); to->linked_modified_connection.disconnect(); to->linked_transformed_connection.disconnect(); if (new_obj && SP_IS_ITEM(new_obj)) { - to->linked_delete_connection = new_obj->connectDelete(sigc::bind(sigc::mem_fun(*this, &OriginalPathArrayParam::linked_delete), to)); - to->linked_modified_connection = new_obj->connectModified(sigc::bind(sigc::mem_fun(*this, &OriginalPathArrayParam::linked_modified), to)); - to->linked_transformed_connection = SP_ITEM(new_obj)->connectTransformed(sigc::bind(sigc::mem_fun(*this, &OriginalPathArrayParam::linked_transformed), to)); + to->linked_delete_connection = new_obj->connectDelete(sigc::bind(sigc::mem_fun(*this, &OriginalPathArrayParam::linked_delete), to)); + to->linked_modified_connection = new_obj->connectModified(sigc::bind(sigc::mem_fun(*this, &OriginalPathArrayParam::linked_modified), to)); + to->linked_transformed_connection = SP_ITEM(new_obj)->connectTransformed(sigc::bind(sigc::mem_fun(*this, &OriginalPathArrayParam::linked_transformed), to)); linked_modified(new_obj, SP_OBJECT_MODIFIED_FLAG, to); } else { to->_pathvector = Geom::PathVector(); SP_OBJECT(param_effect->getLPEObj())->requestModified(SP_OBJECT_MODIFIED_FLAG); - _store->foreach_iter(sigc::bind(sigc::mem_fun(*this, &OriginalPathArrayParam::_updateLink), to)); + _store->foreach_iter(sigc::bind(sigc::mem_fun(*this, &OriginalPathArrayParam::_updateLink), to)); } } -void OriginalPathArrayParam::setPathVector(SPObject *linked_obj, guint /*flags*/, PathAndDirection* to) +void OriginalPathArrayParam::setPathVector(SPObject *linked_obj, guint /*flags*/, PathAndDirectionAndVisible* to) { if (!to) { return; @@ -430,21 +460,21 @@ void OriginalPathArrayParam::setPathVector(SPObject *linked_obj, guint /*flags*/ } } -void OriginalPathArrayParam::linked_modified(SPObject *linked_obj, guint flags, PathAndDirection* to) +void OriginalPathArrayParam::linked_modified(SPObject *linked_obj, guint flags, PathAndDirectionAndVisible* to) { if (!to) { return; } setPathVector(linked_obj, flags, to); SP_OBJECT(param_effect->getLPEObj())->requestModified(SP_OBJECT_MODIFIED_FLAG); - _store->foreach_iter(sigc::bind(sigc::mem_fun(*this, &OriginalPathArrayParam::_updateLink), to)); + _store->foreach_iter(sigc::bind(sigc::mem_fun(*this, &OriginalPathArrayParam::_updateLink), to)); } bool OriginalPathArrayParam::param_readSVGValue(const gchar* strvalue) { if (strvalue) { while (!_vector.empty()) { - PathAndDirection *w = _vector.back(); + PathAndDirectionAndVisible *w = _vector.back(); unlink(w); _vector.pop_back(); delete w; @@ -455,11 +485,12 @@ bool OriginalPathArrayParam::param_readSVGValue(const gchar* strvalue) for (gchar ** iter = strarray; *iter != NULL; iter++) { if ((*iter)[0] == '#') { gchar ** substrarray = g_strsplit(*iter, ",", 0); - PathAndDirection* w = new PathAndDirection((SPObject *)param_effect->getLPEObj()); + PathAndDirectionAndVisible* w = new PathAndDirectionAndVisible((SPObject *)param_effect->getLPEObj()); w->href = g_strdup(*substrarray); w->reversed = *(substrarray+1) != NULL && (*(substrarray+1))[0] == '1'; - - w->linked_changed_connection = w->ref.changedSignal().connect(sigc::bind(sigc::mem_fun(*this, &OriginalPathArrayParam::linked_changed), w)); + //Like this to make backwards compatible, new value added in 0.93 + w->visibled = *(substrarray+2) == NULL || (*(substrarray+2))[0] == '1'; + w->linked_changed_connection = w->ref.changedSignal().connect(sigc::bind(sigc::mem_fun(*this, &OriginalPathArrayParam::linked_changed), w)); w->ref.attach(URI(w->href)); _vector.push_back(w); @@ -471,6 +502,7 @@ bool OriginalPathArrayParam::param_readSVGValue(const gchar* strvalue) row[_model->_colObject] = w; row[_model->_colLabel] = obj ? ( obj->label() ? obj->label() : obj->getId() ) : w->href; row[_model->_colReverse] = w->reversed; + row[_model->_colVisible] = w->visibled; g_strfreev (substrarray); } } @@ -484,13 +516,13 @@ gchar * OriginalPathArrayParam::param_getSVGValue() const { Inkscape::SVGOStringStream os; bool foundOne = false; - for (std::vector::const_iterator iter = _vector.begin(); iter != _vector.end(); ++iter) { + for (std::vector::const_iterator iter = _vector.begin(); iter != _vector.end(); ++iter) { if (foundOne) { os << "|"; } else { foundOne = true; } - os << (*iter)->href << "," << ((*iter)->reversed ? "1" : "0"); + os << (*iter)->href << "," << ((*iter)->reversed ? "1" : "0") << "," << ((*iter)->visibled ? "1" : "0"); } gchar * str = g_strdup(os.str().c_str()); return str; -- cgit v1.2.3