diff options
| author | Jabier Arraiza <jabier.arraiza@marker.es> | 2017-11-03 00:10:02 +0000 |
|---|---|---|
| committer | Jabier Arraiza <jabier.arraiza@marker.es> | 2017-11-03 00:10:02 +0000 |
| commit | d2df0412f728dd5bb54537dfdfe7c35b34d40e0e (patch) | |
| tree | e2703384779e83312c456399999997fcc289c5cf /src/live_effects/parameter | |
| parent | Merge branch 'master' into powerpencil (diff) | |
| parent | change assignment to equality (diff) | |
| download | inkscape-d2df0412f728dd5bb54537dfdfe7c35b34d40e0e.tar.gz inkscape-d2df0412f728dd5bb54537dfdfe7c35b34d40e0e.zip | |
Merge branch 'master' into powerpencil
Diffstat (limited to 'src/live_effects/parameter')
41 files changed, 1330 insertions, 129 deletions
diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index e65d3b55c..c66d53266 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -67,6 +67,10 @@ public: gchar * str = g_strdup(os.str().c_str()); return str; } + + virtual gchar * param_getDefaultSVGValue() const { + return g_strdup(""); + } void param_setValue(std::vector<StorageType> const &new_vector) { _vector = new_vector; diff --git a/src/live_effects/parameter/bool.cpp b/src/live_effects/parameter/bool.cpp index f291a8104..1a01f269b 100644 --- a/src/live_effects/parameter/bool.cpp +++ b/src/live_effects/parameter/bool.cpp @@ -61,6 +61,13 @@ BoolParam::param_getSVGValue() const return str; } +gchar * +BoolParam::param_getDefaultSVGValue() const +{ + gchar * str = g_strdup(defvalue ? "true" : "false"); + return str; +} + Gtk::Widget * BoolParam::param_newWidget() { diff --git a/src/live_effects/parameter/bool.h b/src/live_effects/parameter/bool.h index 417752050..1aa0e3c4a 100644 --- a/src/live_effects/parameter/bool.h +++ b/src/live_effects/parameter/bool.h @@ -32,6 +32,7 @@ public: virtual bool param_readSVGValue(const gchar * strvalue); virtual gchar * param_getSVGValue() const; + virtual gchar * param_getDefaultSVGValue() const; void param_setValue(bool newvalue); virtual void param_set_default(); diff --git a/src/live_effects/parameter/colorpicker.cpp b/src/live_effects/parameter/colorpicker.cpp new file mode 100644 index 000000000..f6521d0c0 --- /dev/null +++ b/src/live_effects/parameter/colorpicker.cpp @@ -0,0 +1,151 @@ +/* + * Authors: + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include <gtkmm.h> +#include "ui/widget/registered-widget.h" +#include "live_effects/parameter/colorpicker.h" +#include "live_effects/effect.h" +#include "ui/widget/color-picker.h" +#include "svg/svg.h" +#include "svg/svg-color.h" +#include "color.h" +#include "inkscape.h" +#include "svg/stringstream.h" +#include "verbs.h" +#include "document.h" +#include "document-undo.h" + +#include <glibmm/i18n.h> + +namespace Inkscape { + +namespace LivePathEffect { + +ColorPickerParam::ColorPickerParam( const Glib::ustring& label, const Glib::ustring& tip, + const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, + Effect* effect, const guint32 default_color ) + : Parameter(label, tip, key, wr, effect), + value(default_color), + defvalue(default_color) +{ + +} + +void +ColorPickerParam::param_set_default() +{ + param_setValue(defvalue); +} + +static guint32 sp_read_color_alpha(gchar const *str, guint32 def) +{ + guint32 val = 0; + if (str == NULL) return def; + while ((*str <= ' ') && *str) str++; + if (!*str) return def; + + if (str[0] == '#') { + gint i; + for (i = 1; str[i]; i++) { + int hexval; + if (str[i] >= '0' && str[i] <= '9') + hexval = str[i] - '0'; + else if (str[i] >= 'A' && str[i] <= 'F') + hexval = str[i] - 'A' + 10; + else if (str[i] >= 'a' && str[i] <= 'f') + hexval = str[i] - 'a' + 10; + else + break; + val = (val << 4) + hexval; + } + if (i != 1 + 8) { + return def; + } + } + return val; +} + +void +ColorPickerParam::param_update_default(const gchar * default_value) +{ + defvalue = sp_read_color_alpha(default_value, 0x000000ff); +} + +bool +ColorPickerParam::param_readSVGValue(const gchar * strvalue) +{ + param_setValue(sp_read_color_alpha(strvalue, 0x000000ff)); + return true; +} + +gchar * +ColorPickerParam::param_getSVGValue() const +{ + gchar c[32]; + sprintf(c, "#%08x", value); + return strdup(c); +} + +gchar * +ColorPickerParam::param_getDefaultSVGValue() const +{ + gchar c[32]; + sprintf(c, "#%08x", defvalue); + return strdup(c); +} + +Gtk::Widget * +ColorPickerParam::param_newWidget() +{ + Gtk::HBox *hbox = Gtk::manage(new Gtk::HBox()); + + hbox->set_border_width(5); + hbox->set_homogeneous(false); + hbox->set_spacing(2); + Inkscape::UI::Widget::RegisteredColorPicker * colorpickerwdg = Gtk::manage( + new Inkscape::UI::Widget::RegisteredColorPicker( param_label, + param_label, + param_tooltip, + param_key, + param_key + "_opacity_LPE", + *param_wr, + param_effect->getRepr(), + param_effect->getSPDoc() ) ); + Gtk::Label * label = new Gtk::Label (param_label, Gtk::ALIGN_END); + label->set_use_underline (true); + label->set_mnemonic_widget (*colorpickerwdg); + SPDocument *document = SP_ACTIVE_DOCUMENT; + bool saved = DocumentUndo::getUndoSensitive(document); + DocumentUndo::setUndoSensitive(document, false); + colorpickerwdg->setRgba32(value); + DocumentUndo::setUndoSensitive(document, saved); + colorpickerwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change color button parameter")); + hbox->pack_start(*dynamic_cast<Gtk::Widget *> (label), true, true); + hbox->pack_start(*dynamic_cast<Gtk::Widget *> (colorpickerwdg), true, true); + return dynamic_cast<Gtk::Widget *> (hbox); +} + +void +ColorPickerParam::param_setValue(const guint32 newvalue) +{ + value = newvalue; +} + + +} /* namespace LivePathEffect */ + +} /* namespace Inkscape */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/colorpicker.h b/src/live_effects/parameter/colorpicker.h new file mode 100644 index 000000000..84ae2f6d5 --- /dev/null +++ b/src/live_effects/parameter/colorpicker.h @@ -0,0 +1,61 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_COLOR_BUTTON_H +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_COLOR_BUTTON_H + +/* + * Inkscape::LivePathEffectParameters + * + * Authors: + * Released under GNU GPL, read the file 'COPYING' for more information + */ +#include <glib.h> +#include "live_effects/parameter/parameter.h" + +namespace Inkscape { + +namespace LivePathEffect { + +class ColorPickerParam : public Parameter { +public: + ColorPickerParam( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + const guint32 default_color = 0x000000ff); + virtual ~ColorPickerParam() {} + + virtual Gtk::Widget * param_newWidget(); + virtual bool param_readSVGValue(const gchar * strvalue); + void param_update_default(const gchar * default_value); + virtual gchar * param_getSVGValue() const; + virtual gchar * param_getDefaultSVGValue() const; + + void param_setValue(guint32 newvalue); + + virtual void param_set_default(); + + const guint32 get_value() const { return value; }; + +private: + ColorPickerParam(const ColorPickerParam&); + ColorPickerParam& operator=(const ColorPickerParam&); + guint32 value; + guint32 defvalue; +}; + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/enum.h b/src/live_effects/parameter/enum.h index 78fa87a4f..ca237c0f7 100644 --- a/src/live_effects/parameter/enum.h +++ b/src/live_effects/parameter/enum.h @@ -64,7 +64,12 @@ public: gchar * str = g_strdup( enumdataconv->get_key(value).c_str() ); return str; }; - + + gchar * param_getDefaultSVGValue() const { + gchar * str = g_strdup( enumdataconv->get_key(defvalue).c_str() ); + return str; + }; + E get_value() const { return value; } diff --git a/src/live_effects/parameter/fontbutton.cpp b/src/live_effects/parameter/fontbutton.cpp index ca8908f0e..49edb850a 100644 --- a/src/live_effects/parameter/fontbutton.cpp +++ b/src/live_effects/parameter/fontbutton.cpp @@ -55,6 +55,14 @@ FontButtonParam::param_getSVGValue() const return g_strdup(value.c_str()); } +gchar * +FontButtonParam::param_getDefaultSVGValue() const +{ + return g_strdup(defvalue.c_str()); +} + + + Gtk::Widget * FontButtonParam::param_newWidget() { diff --git a/src/live_effects/parameter/fontbutton.h b/src/live_effects/parameter/fontbutton.h index 60e1aa46e..e2d0e1bb2 100644 --- a/src/live_effects/parameter/fontbutton.h +++ b/src/live_effects/parameter/fontbutton.h @@ -28,6 +28,7 @@ public: virtual bool param_readSVGValue(const gchar * strvalue); void param_update_default(const gchar * default_value); virtual gchar * param_getSVGValue() const; + virtual gchar * param_getDefaultSVGValue() const; void param_setValue(Glib::ustring newvalue); diff --git a/src/live_effects/parameter/hidden.cpp b/src/live_effects/parameter/hidden.cpp index e8c55ebd3..e08881f6d 100644 --- a/src/live_effects/parameter/hidden.cpp +++ b/src/live_effects/parameter/hidden.cpp @@ -59,6 +59,15 @@ HiddenParam::param_getSVGValue() const return str; } +gchar * +HiddenParam::param_getDefaultSVGValue() const +{ + Inkscape::SVGOStringStream os; + os << defvalue; + gchar * str = g_strdup(os.str().c_str()); + return str; +} + Gtk::Widget * HiddenParam::param_newWidget() { diff --git a/src/live_effects/parameter/hidden.h b/src/live_effects/parameter/hidden.h index c3fba5575..b41c6c93c 100644 --- a/src/live_effects/parameter/hidden.h +++ b/src/live_effects/parameter/hidden.h @@ -37,6 +37,7 @@ public: virtual bool param_readSVGValue(const gchar * strvalue); virtual gchar * param_getSVGValue() const; + virtual gchar * param_getDefaultSVGValue() const; void param_setValue(Glib::ustring newvalue, bool write = false); virtual void param_set_default(); diff --git a/src/live_effects/parameter/item.cpp b/src/live_effects/parameter/item.cpp index 71134b118..bf7402d99 100644 --- a/src/live_effects/parameter/item.cpp +++ b/src/live_effects/parameter/item.cpp @@ -43,6 +43,7 @@ ItemParam::ItemParam( const Glib::ustring& label, const Glib::ustring& tip, href(NULL), ref( (SPObject*)effect->getLPEObj() ) { + last_transform = Geom::identity(); defvalue = g_strdup(default_value); ref_changed_connection = ref.changedSignal().connect(sigc::mem_fun(*this, &ItemParam::ref_changed)); } @@ -101,7 +102,16 @@ ItemParam::param_readSVGValue(const gchar * strvalue) gchar * ItemParam::param_getSVGValue() const { - return g_strdup(href); + if (href) { + return g_strdup(href); + } + return g_strdup(""); +} + +gchar * +ItemParam::param_getDefaultSVGValue() const +{ + return g_strdup(defvalue); } Gtk::Widget * @@ -204,9 +214,18 @@ ItemParam::linked_modified_callback(SPObject *linked_obj, guint /*flags*/) { emit_changed(); SP_OBJECT(param_effect->getLPEObj())->requestModified(SP_OBJECT_MODIFIED_FLAG); + last_transform = Geom::identity(); } void +ItemParam::linked_transformed_callback(Geom::Affine const *rel_transf, SPItem */*moved_item*/) +{ + last_transform = *rel_transf; + SP_OBJECT(param_effect->getLPEObj())->requestModified(SP_OBJECT_MODIFIED_FLAG); +} + + +void ItemParam::on_link_button_click() { Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get(); diff --git a/src/live_effects/parameter/item.h b/src/live_effects/parameter/item.h index 89c32f9bd..d32098db5 100644 --- a/src/live_effects/parameter/item.h +++ b/src/live_effects/parameter/item.h @@ -34,14 +34,14 @@ public: virtual bool param_readSVGValue(const gchar * strvalue); virtual gchar * param_getSVGValue() const; - + virtual gchar * param_getDefaultSVGValue() const; virtual void param_set_default(); virtual void param_update_default(const gchar * default_value); void param_set_and_write_default(); virtual void addCanvasIndicators(SPLPEItem const* lpeitem, std::vector<Geom::PathVector> &hp_vec); - sigc::signal <void> signal_item_pasted; sigc::signal <void> signal_item_changed; + Geom::Affine last_transform; bool changed; /* this gets set whenever the path is changed (this is set to true, and then the signal_item_changed signal is emitted). * the user must set it back to false if she wants to use it sensibly */ protected: @@ -60,7 +60,7 @@ protected: void linked_modified(SPObject *linked_obj, guint flags); void linked_transformed(Geom::Affine const *rel_transf, SPItem *moved_item); virtual void linked_modified_callback(SPObject *linked_obj, guint flags); - virtual void linked_transformed_callback(Geom::Affine const * /*rel_transf*/, SPItem * /*moved_item*/) {}; + virtual void linked_transformed_callback(Geom::Affine const *rel_transf, SPItem */*moved_item*/); void on_link_button_click(); void emit_changed(); diff --git a/src/live_effects/parameter/makefile.in b/src/live_effects/parameter/makefile.in deleted file mode 100644 index af48c8e7a..000000000 --- a/src/live_effects/parameter/makefile.in +++ /dev/null @@ -1,17 +0,0 @@ -# Convenience stub makefile to call the real Makefile. - -@SET_MAKE@ - -OBJEXT = @OBJEXT@ - -# Explicit so that it's the default rule. -all: - cd ../.. && $(MAKE) live_effects/parameter/all - -clean %.a %.$(OBJEXT): - cd ../.. && $(MAKE) live_effects/parameter/$@ - -.PHONY: all clean - -.SUFFIXES: -.SUFFIXES: .a .$(OBJEXT) diff --git a/src/live_effects/parameter/message.cpp b/src/live_effects/parameter/message.cpp new file mode 100644 index 000000000..39d8f12c7 --- /dev/null +++ b/src/live_effects/parameter/message.cpp @@ -0,0 +1,101 @@ +/* + * Authors: + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include <gtkmm.h> +#include "live_effects/parameter/message.h" +#include "live_effects/effect.h" +#include <glibmm/i18n.h> + +namespace Inkscape { + +namespace LivePathEffect { + +MessageParam::MessageParam( const Glib::ustring& label, const Glib::ustring& tip, + const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, + Effect* effect, const gchar * default_message ) + : Parameter(label, tip, key, wr, effect), + message(g_strdup(default_message)), + defmessage(g_strdup(default_message)) +{ + +} + +void +MessageParam::param_set_default() +{ + param_setValue(defmessage); +} + +void +MessageParam::param_update_default(const gchar * default_message) +{ + defmessage = g_strdup(default_message); +} + +bool +MessageParam::param_readSVGValue(const gchar * strvalue) +{ + param_setValue(strvalue); + return true; +} + +gchar * +MessageParam::param_getSVGValue() const +{ + return message; +} + +gchar * +MessageParam::param_getDefaultSVGValue() const +{ + return defmessage; +} + +Gtk::Widget * +MessageParam::param_newWidget() +{ + Gtk::Frame * frame = new Gtk::Frame (param_label); + Gtk::Widget * widg_frame = frame->get_label_widget(); + widg_frame->set_margin_right(5); + widg_frame->set_margin_left(5); + Gtk::Label * label = new Gtk::Label (message, Gtk::ALIGN_END); + label->set_use_underline (true); + label->set_use_markup(); + label->set_line_wrap(true); + Gtk::Widget * widg_label = dynamic_cast<Gtk::Widget *> (label); + widg_label->set_margin_top(8); + widg_label->set_margin_bottom(10); + widg_label->set_margin_right(6); + widg_label->set_margin_left(6); + + frame->add(*widg_label); + return dynamic_cast<Gtk::Widget *> (frame); +} + +void +MessageParam::param_setValue(const gchar * strvalue) +{ + if (strcmp(strvalue, message) != 0) { + param_effect->upd_params = true; + } + message = g_strdup(strvalue); +} + + +} /* namespace LivePathEffect */ + +} /* namespace Inkscape */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/message.h b/src/live_effects/parameter/message.h new file mode 100644 index 000000000..63075cf96 --- /dev/null +++ b/src/live_effects/parameter/message.h @@ -0,0 +1,61 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_MESSAGE_H +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_MESSAGE_H + +/* + * Inkscape::LivePathEffectParameters + * + * Authors: + * Released under GNU GPL, read the file 'COPYING' for more information + */ +#include <glib.h> +#include "live_effects/parameter/parameter.h" + +namespace Inkscape { + +namespace LivePathEffect { + +class MessageParam : public Parameter { +public: + MessageParam( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + const gchar * default_message = "Default message"); + virtual ~MessageParam() {} + + virtual Gtk::Widget * param_newWidget(); + virtual bool param_readSVGValue(const gchar * strvalue); + void param_update_default(const gchar * default_value); + virtual gchar * param_getSVGValue() const; + virtual gchar * param_getDefaultSVGValue() const; + + void param_setValue(const gchar * message); + + virtual void param_set_default(); + + const gchar * get_value() const { return message; }; + +private: + MessageParam(const MessageParam&); + MessageParam& operator=(const MessageParam&); + gchar * message; + gchar * defmessage; +}; + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/originalitem.cpp b/src/live_effects/parameter/originalitem.cpp index 81ab41c56..e828e1800 100644 --- a/src/live_effects/parameter/originalitem.cpp +++ b/src/live_effects/parameter/originalitem.cpp @@ -87,17 +87,16 @@ OriginalItemParam::param_newWidget() void OriginalItemParam::linked_modified_callback(SPObject *linked_obj, guint /*flags*/) { - if (!inverse) { - emit_changed(); - SP_OBJECT(param_effect->getLPEObj())->requestModified(SP_OBJECT_MODIFIED_FLAG); - } + emit_changed(); + SP_OBJECT(param_effect->getLPEObj())->requestModified(SP_OBJECT_MODIFIED_FLAG); + last_transform = Geom::identity(); } void -OriginalItemParam::linked_transformed_callback(Geom::Affine const * /*rel_transf*/, SPItem * /*moved_item*/) +OriginalItemParam::linked_transformed_callback(Geom::Affine const * rel_transf, SPItem *moved_item) { -/** \todo find good way to compensate for referenced item transform, like done for normal clones. - * See sp-use.cpp: sp_use_move_compensate */ + last_transform = *rel_transf; + SP_OBJECT(param_effect->getLPEObj())->requestModified(SP_OBJECT_MODIFIED_FLAG); } diff --git a/src/live_effects/parameter/originalitem.h b/src/live_effects/parameter/originalitem.h index 58d04e05a..168728f86 100644 --- a/src/live_effects/parameter/originalitem.h +++ b/src/live_effects/parameter/originalitem.h @@ -23,7 +23,6 @@ public: Inkscape::UI::Widget::Registry* wr, Effect* effect); virtual ~OriginalItemParam(); - void setInverse(bool inversed) { inverse = inversed; } bool linksToItem() const { return (href != NULL); } SPItem * getObject() const { return ref.getObject(); } @@ -36,7 +35,6 @@ protected: void on_select_original_button_click(); private: - bool inverse; OriginalItemParam(const OriginalItemParam&); OriginalItemParam& operator=(const OriginalItemParam&); }; diff --git a/src/live_effects/parameter/originalitemarray.cpp b/src/live_effects/parameter/originalitemarray.cpp new file mode 100644 index 000000000..f45de4ad8 --- /dev/null +++ b/src/live_effects/parameter/originalitemarray.cpp @@ -0,0 +1,470 @@ +/* + * Copyright (C) Theodore Janeczko 2012 <flutterguy317@gmail.com> + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "live_effects/parameter/originalitemarray.h" + +#include <gtkmm/widget.h> +#include <gtkmm/icontheme.h> +#include <gtkmm/imagemenuitem.h> +#include <gtkmm/separatormenuitem.h> +#include <gtkmm/scrolledwindow.h> + +#include <glibmm/i18n.h> + +#include "inkscape.h" +#include "ui/clipboard.h" +#include "svg/svg.h" +#include "svg/stringstream.h" +#include "originalitem.h" +#include "uri.h" + +#include "live_effects/effect.h" + +#include "verbs.h" +#include "document-undo.h" +#include "document.h" + +namespace Inkscape { + +namespace LivePathEffect { + +class OriginalItemArrayParam::ModelColumns : public Gtk::TreeModel::ColumnRecord +{ +public: + + ModelColumns() + { + add(_colObject); + add(_colLabel); + add(_colActive); + } + virtual ~ModelColumns() {} + + Gtk::TreeModelColumn<ItemAndActive*> _colObject; + Gtk::TreeModelColumn<Glib::ustring> _colLabel; + Gtk::TreeModelColumn<bool> _colActive; +}; + +OriginalItemArrayParam::OriginalItemArrayParam( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect ) +: Parameter(label, tip, key, wr, effect), + _vector(), + _tree(), + _text_renderer(), + _toggle_active(), + _scroller() +{ + _model = new ModelColumns(); + _store = Gtk::TreeStore::create(*_model); + _tree.set_model(_store); + + _tree.set_reorderable(true); + _tree.enable_model_drag_dest (Gdk::ACTION_MOVE); + + Gtk::CellRendererToggle * _toggle_active = manage(new Gtk::CellRendererToggle()); + int activeColNum = _tree.append_column(_("Active"), *_toggle_active) - 1; + Gtk::TreeViewColumn* col_active = _tree.get_column(activeColNum); + _toggle_active->set_activatable(true); + _toggle_active->signal_toggled().connect(sigc::mem_fun(*this, &OriginalItemArrayParam::on_active_toggled)); + col_active->add_attribute(_toggle_active->property_active(), _model->_colActive); + + _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); + + _scroller.add(_tree); + _scroller.set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC ); + //_scroller.set_shadow_type(Gtk::SHADOW_IN); + + oncanvas_editable = true; +} + +OriginalItemArrayParam::~OriginalItemArrayParam() +{ + while (!_vector.empty()) { + ItemAndActive *w = _vector.back(); + _vector.pop_back(); + unlink(w); + delete w; + } + delete _model; +} + +void OriginalItemArrayParam::on_active_toggled(const Glib::ustring& item) +{ + Gtk::TreeModel::iterator iter = _store->get_iter(item); + Gtk::TreeModel::Row row = *iter; + ItemAndActive *w = row[_model->_colObject]; + row[_model->_colActive] = !row[_model->_colActive]; + w->actived = row[_model->_colActive]; + + gchar * full = param_getSVGValue(); + param_write_to_repr(full); + g_free(full); + DocumentUndo::done(param_effect->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, + _("Link item parameter to item")); +} + +void OriginalItemArrayParam::param_set_default() +{ + +} + +Gtk::Widget* OriginalItemArrayParam::param_newWidget() +{ + Gtk::VBox* vbox = Gtk::manage(new Gtk::VBox()); + Gtk::HBox* hbox = Gtk::manage(new Gtk::HBox()); + + vbox->pack_start(_scroller, Gtk::PACK_EXPAND_WIDGET); + + + { // Paste item to link button + Gtk::Image *pIcon = Gtk::manage(new Gtk::Image()); + pIcon->set_from_icon_name("edit-clone", Gtk::ICON_SIZE_BUTTON); + Gtk::Button *pButton = Gtk::manage(new Gtk::Button()); + pButton->set_relief(Gtk::RELIEF_NONE); + pIcon->show(); + pButton->add(*pIcon); + pButton->show(); + pButton->signal_clicked().connect(sigc::mem_fun(*this, &OriginalItemArrayParam::on_link_button_click)); + hbox->pack_start(*pButton, Gtk::PACK_SHRINK); + pButton->set_tooltip_text(_("Link to item")); + } + + { // Remove linked item + Gtk::Image *pIcon = Gtk::manage(new Gtk::Image()); + pIcon->set_from_icon_name("gtk-remove", Gtk::ICON_SIZE_BUTTON); + Gtk::Button *pButton = Gtk::manage(new Gtk::Button()); + pButton->set_relief(Gtk::RELIEF_NONE); + pIcon->show(); + pButton->add(*pIcon); + pButton->show(); + pButton->signal_clicked().connect(sigc::mem_fun(*this, &OriginalItemArrayParam::on_remove_button_click)); + hbox->pack_start(*pButton, Gtk::PACK_SHRINK); + pButton->set_tooltip_text(_("Remove Item")); + } + + { // Move Down + Gtk::Image *pIcon = Gtk::manage(new Gtk::Image()); + pIcon->set_from_icon_name( "gtk-go-down", Gtk::ICON_SIZE_BUTTON); + Gtk::Button *pButton = Gtk::manage(new Gtk::Button()); + pButton->set_relief(Gtk::RELIEF_NONE); + pIcon->show(); + pButton->add(*pIcon); + pButton->show(); + pButton->signal_clicked().connect(sigc::mem_fun(*this, &OriginalItemArrayParam::on_down_button_click)); + hbox->pack_end(*pButton, Gtk::PACK_SHRINK); + pButton->set_tooltip_text(_("Move Down")); + } + + { // Move Down + Gtk::Image *pIcon = Gtk::manage(new Gtk::Image()); + pIcon->set_from_icon_name( "gtk-go-up", Gtk::ICON_SIZE_BUTTON); + Gtk::Button *pButton = Gtk::manage(new Gtk::Button()); + pButton->set_relief(Gtk::RELIEF_NONE); + pIcon->show(); + pButton->add(*pIcon); + pButton->show(); + pButton->signal_clicked().connect(sigc::mem_fun(*this, &OriginalItemArrayParam::on_up_button_click)); + hbox->pack_end(*pButton, Gtk::PACK_SHRINK); + pButton->set_tooltip_text(_("Move Up")); + } + + vbox->pack_end(*hbox, Gtk::PACK_SHRINK); + + vbox->show_all_children(true); + + return vbox; +} + +bool OriginalItemArrayParam::_selectIndex(const Gtk::TreeIter& iter, int* i) +{ + if ((*i)-- <= 0) { + _tree.get_selection()->select(iter); + return true; + } + return false; +} + +void OriginalItemArrayParam::on_up_button_click() +{ + Gtk::TreeModel::iterator iter = _tree.get_selection()->get_selected(); + if (iter) { + Gtk::TreeModel::Row row = *iter; + + int i = -1; + std::vector<ItemAndActive*>::iterator piter = _vector.begin(); + for (std::vector<ItemAndActive*>::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]); + break; + } + } + + gchar * full = param_getSVGValue(); + param_write_to_repr(full); + g_free(full); + + DocumentUndo::done(param_effect->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, + _("Move item up")); + + _store->foreach_iter(sigc::bind<int*>(sigc::mem_fun(*this, &OriginalItemArrayParam::_selectIndex), &i)); + } +} + +void OriginalItemArrayParam::on_down_button_click() +{ + Gtk::TreeModel::iterator iter = _tree.get_selection()->get_selected(); + if (iter) { + Gtk::TreeModel::Row row = *iter; + + int i = 0; + for (std::vector<ItemAndActive*>::iterator iter = _vector.begin(); iter != _vector.end(); i++, ++iter) { + if (*iter == row[_model->_colObject]) { + std::vector<ItemAndActive*>::iterator niter = _vector.erase(iter); + if (niter != _vector.end()) { + ++niter; + i++; + } + _vector.insert(niter, row[_model->_colObject]); + break; + } + } + + gchar * full = param_getSVGValue(); + param_write_to_repr(full); + g_free(full); + + DocumentUndo::done(param_effect->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, + _("Move item down")); + + _store->foreach_iter(sigc::bind<int*>(sigc::mem_fun(*this, &OriginalItemArrayParam::_selectIndex), &i)); + } +} + +void OriginalItemArrayParam::on_remove_button_click() +{ + Gtk::TreeModel::iterator iter = _tree.get_selection()->get_selected(); + if (iter) { + Gtk::TreeModel::Row row = *iter; + remove_link(row[_model->_colObject]); + + gchar * full = param_getSVGValue(); + param_write_to_repr(full); + g_free(full); + + DocumentUndo::done(param_effect->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, + _("Remove item")); + } + +} + +void +OriginalItemArrayParam::on_link_button_click() +{ + Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get(); + //without second parameter populate all elements filled inside the called function + std::vector<Glib::ustring> itemsid = cm->getElementsOfType(SP_ACTIVE_DESKTOP); + + if (itemsid.empty()) { + return; + } + + bool foundOne = false; + Inkscape::SVGOStringStream os; + for (std::vector<ItemAndActive*>::const_iterator iter = _vector.begin(); iter != _vector.end(); ++iter) { + if (foundOne) { + os << "|"; + } else { + foundOne = true; + } + os << (*iter)->href << "," << ((*iter)->actived ? "1" : "0"); + } + for (auto i=itemsid.begin();i!=itemsid.end();++i) { + Glib::ustring itemid = *i; + // add '#' at start to make it an uri. + itemid.insert(itemid.begin(), '#'); + + if (foundOne) { + os << "|"; + } else { + foundOne = true; + } + os << itemid.c_str() << ",1"; + } + param_write_to_repr(os.str().c_str()); + DocumentUndo::done(param_effect->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, + _("Link itemarray parameter to item")); +} + +void OriginalItemArrayParam::unlink(ItemAndActive* to) +{ + to->linked_modified_connection.disconnect(); + to->linked_delete_connection.disconnect(); + to->ref.detach(); + if (to->href) { + g_free(to->href); + to->href = NULL; + } +} + +void OriginalItemArrayParam::remove_link(ItemAndActive* to) +{ + unlink(to); + for (std::vector<ItemAndActive*>::iterator iter = _vector.begin(); iter != _vector.end(); ++iter) { + if (*iter == to) { + ItemAndActive *w = *iter; + _vector.erase(iter); + delete w; + return; + } + } +} + +void OriginalItemArrayParam::linked_delete(SPObject */*deleted*/, ItemAndActive* /*to*/) +{ + //remove_link(to); + + gchar * full = param_getSVGValue(); + param_write_to_repr(full); + g_free(full); +} + +bool OriginalItemArrayParam::_updateLink(const Gtk::TreeIter& iter, ItemAndActive* pd) +{ + Gtk::TreeModel::Row row = *iter; + if (row[_model->_colObject] == pd) { + SPObject *obj = pd->ref.getObject(); + row[_model->_colLabel] = obj && obj->getId() ? ( obj->label() ? obj->label() : obj->getId() ) : pd->href; + return true; + } + return false; +} + +void OriginalItemArrayParam::linked_changed(SPObject */*old_obj*/, SPObject *new_obj, ItemAndActive* 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<ItemAndActive*>(sigc::mem_fun(*this, &OriginalItemArrayParam::linked_delete), to)); + to->linked_modified_connection = new_obj->connectModified(sigc::bind<ItemAndActive*>(sigc::mem_fun(*this, &OriginalItemArrayParam::linked_modified), to)); + to->linked_transformed_connection = SP_ITEM(new_obj)->connectTransformed(sigc::bind<ItemAndActive*>(sigc::mem_fun(*this, &OriginalItemArrayParam::linked_transformed), to)); + + linked_modified(new_obj, SP_OBJECT_MODIFIED_FLAG, to); + } else { + SP_OBJECT(param_effect->getLPEObj())->requestModified(SP_OBJECT_MODIFIED_FLAG); + _store->foreach_iter(sigc::bind<ItemAndActive*>(sigc::mem_fun(*this, &OriginalItemArrayParam::_updateLink), to)); + } +} + +void OriginalItemArrayParam::linked_modified(SPObject *linked_obj, guint flags, ItemAndActive* to) +{ + if (!to) { + return; + } + SP_OBJECT(param_effect->getLPEObj())->requestModified(SP_OBJECT_MODIFIED_FLAG); + _store->foreach_iter(sigc::bind<ItemAndActive*>(sigc::mem_fun(*this, &OriginalItemArrayParam::_updateLink), to)); +} + +bool OriginalItemArrayParam::param_readSVGValue(const gchar* strvalue) +{ + if (strvalue) { + while (!_vector.empty()) { + ItemAndActive *w = _vector.back(); + unlink(w); + _vector.pop_back(); + delete w; + } + _store->clear(); + + gchar ** strarray = g_strsplit(strvalue, "|", 0); + for (gchar ** iter = strarray; *iter != NULL; iter++) { + if ((*iter)[0] == '#') { + gchar ** substrarray = g_strsplit(*iter, ",", 0); + ItemAndActive* w = new ItemAndActive((SPObject *)param_effect->getLPEObj()); + w->href = g_strdup(*substrarray); + w->actived = *(substrarray+1) != NULL && (*(substrarray+1))[0] == '1'; + w->linked_changed_connection = w->ref.changedSignal().connect(sigc::bind<ItemAndActive *>(sigc::mem_fun(*this, &OriginalItemArrayParam::linked_changed), w)); + w->ref.attach(URI(w->href)); + + _vector.push_back(w); + + Gtk::TreeModel::iterator iter = _store->append(); + Gtk::TreeModel::Row row = *iter; + SPObject *obj = w->ref.getObject(); + + row[_model->_colObject] = w; + row[_model->_colLabel] = obj ? ( obj->label() ? obj->label() : obj->getId() ) : w->href; + row[_model->_colActive] = w->actived; + g_strfreev (substrarray); + } + } + g_strfreev (strarray); + return true; + } + return false; +} + +gchar * OriginalItemArrayParam::param_getSVGValue() const +{ + Inkscape::SVGOStringStream os; + bool foundOne = false; + for (std::vector<ItemAndActive*>::const_iterator iter = _vector.begin(); iter != _vector.end(); ++iter) { + if (foundOne) { + os << "|"; + } else { + foundOne = true; + } + os << (*iter)->href << "," << ((*iter)->actived ? "1" : "0"); + } + gchar * str = g_strdup(os.str().c_str()); + return str; +} + +gchar * OriginalItemArrayParam::param_getDefaultSVGValue() const +{ + return g_strdup(""); +} + +void OriginalItemArrayParam::update() +{ + for (std::vector<ItemAndActive*>::iterator iter = _vector.begin(); iter != _vector.end(); ++iter) { + SPObject *linked_obj = (*iter)->ref.getObject(); + linked_modified(linked_obj, SP_OBJECT_MODIFIED_FLAG, *iter); + } +} + +} /* namespace LivePathEffect */ + +} /* namespace Inkscape */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/originalitemarray.h b/src/live_effects/parameter/originalitemarray.h new file mode 100644 index 000000000..f93d865ec --- /dev/null +++ b/src/live_effects/parameter/originalitemarray.h @@ -0,0 +1,122 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_ORIGINALITEMARRAY_H +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_ORIGINALITEMARRAY_H + +/* + * Inkscape::LivePathEffectParameters + * + * Copyright (C) Theodore Janeczko 2012 <flutterguy317@gmail.com> + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include <vector> + +#include <gtkmm/box.h> +#include <gtkmm/treeview.h> +#include <gtkmm/treestore.h> +#include <gtkmm/scrolledwindow.h> + +#include "live_effects/parameter/parameter.h" +#include "live_effects/parameter/item-reference.h" + +#include "svg/svg.h" +#include "svg/stringstream.h" +#include "item-reference.h" +#include "sp-object.h" + +namespace Inkscape { + +namespace LivePathEffect { + +class ItemAndActive { +public: + ItemAndActive(SPObject *owner) + : href(NULL), + ref(owner), + actived(true) + { + + } + gchar *href; + URIReference ref; + bool actived; + + sigc::connection linked_changed_connection; + sigc::connection linked_delete_connection; + sigc::connection linked_modified_connection; + sigc::connection linked_transformed_connection; +}; + +class OriginalItemArrayParam : public Parameter { +public: + class ModelColumns; + + OriginalItemArrayParam( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect); + + virtual ~OriginalItemArrayParam(); + + virtual Gtk::Widget * param_newWidget(); + virtual bool param_readSVGValue(const gchar * strvalue); + virtual gchar * param_getSVGValue() const; + virtual gchar * param_getDefaultSVGValue() const; + virtual void param_set_default(); + virtual void param_update_default(const gchar * default_value){}; + /** Disable the canvas indicators of parent class by overriding this method */ + virtual void param_editOncanvas(SPItem * /*item*/, SPDesktop * /*dt*/) {}; + /** Disable the canvas indicators of parent class by overriding this method */ + virtual void addCanvasIndicators(SPLPEItem const* /*lpeitem*/, std::vector<Geom::PathVector> & /*hp_vec*/) {}; + + std::vector<ItemAndActive*> _vector; + +protected: + bool _updateLink(const Gtk::TreeIter& iter, ItemAndActive* pd); + bool _selectIndex(const Gtk::TreeIter& iter, int* i); + void unlink(ItemAndActive* to); + void remove_link(ItemAndActive* to); + void setItem(SPObject *linked_obj, guint flags, ItemAndActive* to); + + void linked_changed(SPObject *old_obj, SPObject *new_obj, ItemAndActive* to); + void linked_modified(SPObject *linked_obj, guint flags, ItemAndActive* to); + void linked_transformed(Geom::Affine const *, SPItem *, ItemAndActive*) {} + void linked_delete(SPObject *deleted, ItemAndActive* to); + + ModelColumns *_model; + Glib::RefPtr<Gtk::TreeStore> _store; + Gtk::TreeView _tree; + Gtk::CellRendererText *_text_renderer; + Gtk::CellRendererToggle *_toggle_active; + Gtk::TreeView::Column *_name_column; + Gtk::ScrolledWindow _scroller; + + void on_link_button_click(); + void on_remove_button_click(); + void on_up_button_click(); + void on_down_button_click(); + void on_active_toggled(const Glib::ustring& item); + +private: + void update(); + OriginalItemArrayParam(const OriginalItemArrayParam&); + OriginalItemArrayParam& operator=(const OriginalItemArrayParam&); +}; + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/originalpath.cpp b/src/live_effects/parameter/originalpath.cpp index 62483d7fb..3f833d2ac 100644 --- a/src/live_effects/parameter/originalpath.cpp +++ b/src/live_effects/parameter/originalpath.cpp @@ -36,6 +36,7 @@ OriginalPathParam::OriginalPathParam( const Glib::ustring& label, const Glib::us : PathParam(label, tip, key, wr, effect, "") { oncanvas_editable = false; + _from_original_d = false; } OriginalPathParam::~OriginalPathParam() @@ -90,7 +91,11 @@ OriginalPathParam::linked_modified_callback(SPObject *linked_obj, guint /*flags* { SPCurve *curve = NULL; if (SP_IS_SHAPE(linked_obj)) { - curve = SP_SHAPE(linked_obj)->getCurve(); + if (_from_original_d) { + curve = SP_SHAPE(linked_obj)->getCurveBeforeLPE(); + } else { + curve = SP_SHAPE(linked_obj)->getCurve(); + } } if (SP_IS_TEXT(linked_obj)) { curve = SP_TEXT(linked_obj)->getNormalizedBpath(); diff --git a/src/live_effects/parameter/originalpath.h b/src/live_effects/parameter/originalpath.h index b3feec41f..ec80d1026 100644 --- a/src/live_effects/parameter/originalpath.h +++ b/src/live_effects/parameter/originalpath.h @@ -32,6 +32,7 @@ public: virtual void param_editOncanvas(SPItem * /*item*/, SPDesktop * /*dt*/) {}; /** Disable the canvas indicators of parent class by overriding this method */ virtual void addCanvasIndicators(SPLPEItem const* /*lpeitem*/, std::vector<Geom::PathVector> & /*hp_vec*/) {}; + void setFromOriginalD(bool from_original_d){ _from_original_d = from_original_d; }; protected: virtual void linked_modified_callback(SPObject *linked_obj, guint flags); @@ -40,6 +41,7 @@ protected: void on_select_original_button_click(); private: + bool _from_original_d; OriginalPathParam(const OriginalPathParam&); OriginalPathParam& operator=(const OriginalPathParam&); }; diff --git a/src/live_effects/parameter/originalpatharray.cpp b/src/live_effects/parameter/originalpatharray.cpp index 92859de05..a98c91770 100644 --- a/src/live_effects/parameter/originalpatharray.cpp +++ b/src/live_effects/parameter/originalpatharray.cpp @@ -9,6 +9,10 @@ #endif #include "live_effects/parameter/originalpatharray.h" +#include "live_effects/lpe-spiro.h" +#include "live_effects/lpe-bspline.h" +#include "live_effects/lpeobject.h" +#include "live_effects/lpeobject-reference.h" #include <gtkmm/widget.h> #include <gtkmm/icontheme.h> @@ -19,7 +23,6 @@ #include <glibmm/i18n.h> #include "inkscape.h" -#include "icon-size.h" #include "ui/clipboard.h" #include "svg/svg.h" #include "svg/stringstream.h" @@ -50,12 +53,14 @@ public: add(_colObject); add(_colLabel); add(_colReverse); + add(_colVisible); } virtual ~ModelColumns() {} - Gtk::TreeModelColumn<PathAndDirection*> _colObject; + Gtk::TreeModelColumn<PathAndDirectionAndVisible*> _colObject; Gtk::TreeModelColumn<Glib::ustring> _colLabel; Gtk::TreeModelColumn<bool> _colReverse; + Gtk::TreeModelColumn<bool> _colVisible; }; OriginalPathArrayParam::OriginalPathArrayParam( const Glib::ustring& label, @@ -67,7 +72,8 @@ OriginalPathArrayParam::OriginalPathArrayParam( const Glib::ustring& label, _vector(), _tree(), _text_renderer(), - _toggle_renderer(), + _toggle_reverse(), + _toggle_visible(), _scroller() { _model = new ModelColumns(); @@ -77,6 +83,22 @@ OriginalPathArrayParam::OriginalPathArrayParam( const Glib::ustring& label, _tree.set_reorderable(true); _tree.enable_model_drag_dest (Gdk::ACTION_MOVE); + + Gtk::CellRendererToggle * _toggle_reverse = manage(new Gtk::CellRendererToggle()); + int reverseColNum = _tree.append_column(_("Reverse"), *_toggle_reverse) - 1; + Gtk::TreeViewColumn* col_reverse = _tree.get_column(reverseColNum); + _toggle_reverse->set_activatable(true); + _toggle_reverse->signal_toggled().connect(sigc::mem_fun(*this, &OriginalPathArrayParam::on_reverse_toggled)); + col_reverse->add_attribute(_toggle_reverse->property_active(), _model->_colReverse); + + + Gtk::CellRendererToggle * _toggle_visible = manage(new Gtk::CellRendererToggle()); + int visibleColNum = _tree.append_column(_("Visible"), *_toggle_visible) - 1; + Gtk::TreeViewColumn* col_visible = _tree.get_column(visibleColNum); + _toggle_visible->set_activatable(true); + _toggle_visible->signal_toggled().connect(sigc::mem_fun(*this, &OriginalPathArrayParam::on_visible_toggled)); + col_visible->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); @@ -85,13 +107,6 @@ OriginalPathArrayParam::OriginalPathArrayParam( const Glib::ustring& label, _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; - Gtk::TreeViewColumn* col = _tree.get_column(toggleColNum); - _toggle_renderer->set_activatable(true); - _toggle_renderer->signal_toggled().connect(sigc::mem_fun(*this, &OriginalPathArrayParam::on_reverse_toggled)); - col->add_attribute(_toggle_renderer->property_active(), _model->_colReverse); - //quick little hack -- newer versions of gtk gave the item zero space allotment _scroller.set_size_request(-1, 120); @@ -100,13 +115,15 @@ OriginalPathArrayParam::OriginalPathArrayParam( const Glib::ustring& label, //_scroller.set_shadow_type(Gtk::SHADOW_IN); oncanvas_editable = true; + _from_original_d = false; + _allow_only_bspline_spiro = false; } OriginalPathArrayParam::~OriginalPathArrayParam() { while (!_vector.empty()) { - PathAndDirection *w = _vector.back(); + PathAndDirectionAndVisible *w = _vector.back(); _vector.pop_back(); unlink(w); delete w; @@ -118,7 +135,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]; @@ -129,6 +146,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() { @@ -217,8 +249,8 @@ void OriginalPathArrayParam::on_up_button_click() Gtk::TreeModel::Row row = *iter; int i = -1; - std::vector<PathAndDirection*>::iterator piter = _vector.begin(); - for (std::vector<PathAndDirection*>::iterator iter = _vector.begin(); iter != _vector.end(); piter = iter, i++, ++iter) { + std::vector<PathAndDirectionAndVisible*>::iterator piter = _vector.begin(); + for (std::vector<PathAndDirectionAndVisible*>::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]); @@ -244,9 +276,9 @@ void OriginalPathArrayParam::on_down_button_click() Gtk::TreeModel::Row row = *iter; int i = 0; - for (std::vector<PathAndDirection*>::iterator iter = _vector.begin(); iter != _vector.end(); i++, ++iter) { + for (std::vector<PathAndDirectionAndVisible*>::iterator iter = _vector.begin(); iter != _vector.end(); i++, ++iter) { if (*iter == row[_model->_colObject]) { - std::vector<PathAndDirection*>::iterator niter = _vector.erase(iter); + std::vector<PathAndDirectionAndVisible*>::iterator niter = _vector.erase(iter); if (niter != _vector.end()) { ++niter; i++; @@ -288,37 +320,40 @@ void OriginalPathArrayParam::on_link_button_click() { Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get(); - Glib::ustring pathid = cm->getShapeOrTextObjectId(SP_ACTIVE_DESKTOP); - - if (pathid == "") { + std::vector<Glib::ustring> pathsid = cm->getElementsOfType(SP_ACTIVE_DESKTOP, "svg:path"); + std::vector<Glib::ustring> textsid = cm->getElementsOfType(SP_ACTIVE_DESKTOP, "svg:text"); + pathsid.insert(pathsid.end(), textsid.begin(), textsid.end()); + 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<PathAndDirection*>::const_iterator iter = _vector.begin(); iter != _vector.end(); ++iter) { + Inkscape::SVGOStringStream os; + for (std::vector<PathAndDirectionAndVisible*>::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"); } - - if (foundOne) { - os << "|"; + 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(), '#'); + + if (foundOne) { + os << "|"; + } else { + foundOne = true; + } + os << pathid.c_str() << ",0,1"; } - - 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")); + _("Link patharray parameter to path")); } -void OriginalPathArrayParam::unlink(PathAndDirection* to) +void OriginalPathArrayParam::unlink(PathAndDirectionAndVisible* to) { to->linked_modified_connection.disconnect(); to->linked_delete_connection.disconnect(); @@ -327,15 +362,15 @@ void OriginalPathArrayParam::unlink(PathAndDirection* to) if (to->href) { g_free(to->href); to->href = NULL; - } + } } -void OriginalPathArrayParam::remove_link(PathAndDirection* to) +void OriginalPathArrayParam::remove_link(PathAndDirectionAndVisible* to) { unlink(to); - for (std::vector<PathAndDirection*>::iterator iter = _vector.begin(); iter != _vector.end(); ++iter) { + for (std::vector<PathAndDirectionAndVisible*>::iterator iter = _vector.begin(); iter != _vector.end(); ++iter) { if (*iter == to) { - PathAndDirection *w = *iter; + PathAndDirectionAndVisible *w = *iter; _vector.erase(iter); delete w; return; @@ -343,7 +378,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); @@ -352,7 +387,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) { @@ -363,35 +398,54 @@ 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<PathAndDirection*>(sigc::mem_fun(*this, &OriginalPathArrayParam::linked_delete), to)); - to->linked_modified_connection = new_obj->connectModified(sigc::bind<PathAndDirection*>(sigc::mem_fun(*this, &OriginalPathArrayParam::linked_modified), to)); - to->linked_transformed_connection = SP_ITEM(new_obj)->connectTransformed(sigc::bind<PathAndDirection*>(sigc::mem_fun(*this, &OriginalPathArrayParam::linked_transformed), to)); + to->linked_delete_connection = new_obj->connectDelete(sigc::bind<PathAndDirectionAndVisible*>(sigc::mem_fun(*this, &OriginalPathArrayParam::linked_delete), to)); + to->linked_modified_connection = new_obj->connectModified(sigc::bind<PathAndDirectionAndVisible*>(sigc::mem_fun(*this, &OriginalPathArrayParam::linked_modified), to)); + to->linked_transformed_connection = SP_ITEM(new_obj)->connectTransformed(sigc::bind<PathAndDirectionAndVisible*>(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<PathAndDirection*>(sigc::mem_fun(*this, &OriginalPathArrayParam::_updateLink), to)); + _store->foreach_iter(sigc::bind<PathAndDirectionAndVisible*>(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; } SPCurve *curve = NULL; if (SP_IS_SHAPE(linked_obj)) { - curve = SP_SHAPE(linked_obj)->getCurve(); - } - if (SP_IS_TEXT(linked_obj)) { + SPLPEItem * lpe_item = SP_LPE_ITEM(linked_obj); + if (_from_original_d) { + curve = SP_SHAPE(linked_obj)->getCurveBeforeLPE(); + } else if (_allow_only_bspline_spiro && lpe_item && lpe_item->hasPathEffect()){ + curve = SP_SHAPE(linked_obj)->getCurveBeforeLPE(); + PathEffectList lpelist = lpe_item->getEffectList(); + PathEffectList::iterator i; + for (i = lpelist.begin(); i != lpelist.end(); ++i) { + LivePathEffectObject *lpeobj = (*i)->lpeobject; + if (lpeobj) { + Inkscape::LivePathEffect::Effect *lpe = lpeobj->get_lpe(); + if (dynamic_cast<Inkscape::LivePathEffect::LPEBSpline *>(lpe)) { + LivePathEffect::sp_bspline_do_effect(curve, 0); + } else if (dynamic_cast<Inkscape::LivePathEffect::LPESpiro *>(lpe)) { + LivePathEffect::sp_spiro_do_effect(curve); + } + } + } + } else { + curve = SP_SHAPE(linked_obj)->getCurve(); + } + } else if (SP_IS_TEXT(linked_obj)) { curve = SP_TEXT(linked_obj)->getNormalizedBpath(); } @@ -404,21 +458,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<PathAndDirection*>(sigc::mem_fun(*this, &OriginalPathArrayParam::_updateLink), to)); + _store->foreach_iter(sigc::bind<PathAndDirectionAndVisible*>(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; @@ -429,11 +483,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<PathAndDirection *>(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<PathAndDirectionAndVisible *>(sigc::mem_fun(*this, &OriginalPathArrayParam::linked_changed), w)); w->ref.attach(URI(w->href)); _vector.push_back(w); @@ -445,6 +500,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); } } @@ -458,18 +514,31 @@ gchar * OriginalPathArrayParam::param_getSVGValue() const { Inkscape::SVGOStringStream os; bool foundOne = false; - for (std::vector<PathAndDirection*>::const_iterator iter = _vector.begin(); iter != _vector.end(); ++iter) { + for (std::vector<PathAndDirectionAndVisible*>::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; } +gchar * OriginalPathArrayParam::param_getDefaultSVGValue() const +{ + return ""; +} + +void OriginalPathArrayParam::update() +{ + for (std::vector<PathAndDirectionAndVisible*>::iterator iter = _vector.begin(); iter != _vector.end(); ++iter) { + SPObject *linked_obj = (*iter)->ref.getObject(); + linked_modified(linked_obj, SP_OBJECT_MODIFIED_FLAG, *iter); + } +} + } /* namespace LivePathEffect */ } /* namespace Inkscape */ diff --git a/src/live_effects/parameter/originalpatharray.h b/src/live_effects/parameter/originalpatharray.h index fe9371644..c80d5daf3 100644 --- a/src/live_effects/parameter/originalpatharray.h +++ b/src/live_effects/parameter/originalpatharray.h @@ -28,13 +28,14 @@ namespace Inkscape { namespace LivePathEffect { -class PathAndDirection { +class PathAndDirectionAndVisible { public: - PathAndDirection(SPObject *owner) + PathAndDirectionAndVisible(SPObject *owner) : href(NULL), ref(owner), _pathvector(Geom::PathVector()), - reversed(false) + reversed(false), + visibled(true) { } @@ -42,6 +43,7 @@ public: URIReference ref; Geom::PathVector _pathvector; bool reversed; + bool visibled; sigc::connection linked_changed_connection; sigc::connection linked_delete_connection; @@ -64,31 +66,36 @@ public: virtual Gtk::Widget * param_newWidget(); virtual bool param_readSVGValue(const gchar * strvalue); virtual gchar * param_getSVGValue() const; + virtual gchar * param_getDefaultSVGValue() const; virtual void param_set_default(); virtual void param_update_default(const gchar * default_value){}; /** Disable the canvas indicators of parent class by overriding this method */ virtual void param_editOncanvas(SPItem * /*item*/, SPDesktop * /*dt*/) {}; /** Disable the canvas indicators of parent class by overriding this method */ virtual void addCanvasIndicators(SPLPEItem const* /*lpeitem*/, std::vector<Geom::PathVector> & /*hp_vec*/) {}; - std::vector<PathAndDirection*> _vector; - + void setFromOriginalD(bool from_original_d){ _from_original_d = from_original_d; update();}; + void allowOnlyBsplineSpiro(bool allow_only_bspline_spiro){ _allow_only_bspline_spiro = allow_only_bspline_spiro; update();}; + + std::vector<PathAndDirectionAndVisible*> _vector; + protected: - bool _updateLink(const Gtk::TreeIter& iter, PathAndDirection* pd); + bool _updateLink(const Gtk::TreeIter& iter, PathAndDirectionAndVisible* pd); bool _selectIndex(const Gtk::TreeIter& iter, int* i); - void unlink(PathAndDirection* to); - void remove_link(PathAndDirection* to); - void setPathVector(SPObject *linked_obj, guint flags, PathAndDirection* to); + void unlink(PathAndDirectionAndVisible* to); + void remove_link(PathAndDirectionAndVisible* to); + void setPathVector(SPObject *linked_obj, guint flags, PathAndDirectionAndVisible* to); - void linked_changed(SPObject *old_obj, SPObject *new_obj, PathAndDirection* to); - void linked_modified(SPObject *linked_obj, guint flags, PathAndDirection* to); - void linked_transformed(Geom::Affine const *, SPItem *, PathAndDirection*) {} - void linked_delete(SPObject *deleted, PathAndDirection* to); + void linked_changed(SPObject *old_obj, SPObject *new_obj, PathAndDirectionAndVisible* to); + void linked_modified(SPObject *linked_obj, guint flags, PathAndDirectionAndVisible* to); + void linked_transformed(Geom::Affine const *, SPItem *, PathAndDirectionAndVisible*) {} + void linked_delete(SPObject *deleted, PathAndDirectionAndVisible* to); ModelColumns *_model; Glib::RefPtr<Gtk::TreeStore> _store; Gtk::TreeView _tree; Gtk::CellRendererText *_text_renderer; - Gtk::CellRendererToggle *_toggle_renderer; + Gtk::CellRendererToggle *_toggle_reverse; + Gtk::CellRendererToggle *_toggle_visible; Gtk::TreeView::Column *_name_column; Gtk::ScrolledWindow _scroller; @@ -97,8 +104,12 @@ protected: void on_up_button_click(); void on_down_button_click(); void on_reverse_toggled(const Glib::ustring& path); + void on_visible_toggled(const Glib::ustring& path); private: + bool _from_original_d; + bool _allow_only_bspline_spiro; + void update(); OriginalPathArrayParam(const OriginalPathArrayParam&); OriginalPathArrayParam& operator=(const OriginalPathArrayParam&); }; diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index 2f73488aa..319ab3fe8 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -95,6 +95,15 @@ ScalarParam::param_getSVGValue() const return str; } +gchar * +ScalarParam::param_getDefaultSVGValue() const +{ + Inkscape::SVGOStringStream os; + os << defvalue; + gchar * str = g_strdup(os.str().c_str()); + return str; +} + void ScalarParam::param_set_default() { diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index 7ab7e30dd..1586ef346 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -57,6 +57,7 @@ public: virtual bool param_readSVGValue(const gchar * strvalue) = 0; // returns true if new value is valid / accepted. virtual gchar * param_getSVGValue() const = 0; + virtual gchar * param_getDefaultSVGValue() const = 0; virtual void param_widget_is_visible(bool is_visible) {widget_is_visible = is_visible;} void write_to_SVG(); @@ -109,6 +110,7 @@ public: virtual bool param_readSVGValue(const gchar * strvalue); virtual gchar * param_getSVGValue() const; + virtual gchar * param_getDefaultSVGValue() const; virtual void param_set_default(); void param_update_default(gdouble default_value); diff --git a/src/live_effects/parameter/path.cpp b/src/live_effects/parameter/path.cpp index ec011b855..bd6608737 100644 --- a/src/live_effects/parameter/path.cpp +++ b/src/live_effects/parameter/path.cpp @@ -68,6 +68,7 @@ PathParam::PathParam( const Glib::ustring& label, const Glib::ustring& tip, defvalue = g_strdup(default_value); param_readSVGValue(defvalue); oncanvas_editable = true; + _from_original_d = false; _edit_button = true; _copy_button = true; _paste_button = true; @@ -78,21 +79,24 @@ PathParam::PathParam( const Glib::ustring& label, const Glib::ustring& tip, PathParam::~PathParam() { remove_link(); - using namespace Inkscape::UI; - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - if (desktop) { - if (tools_isactive(desktop, TOOLS_NODES)) { - SPItem * item = SP_ACTIVE_DESKTOP->getSelection()->singleItem(); - if (item != NULL) { - Inkscape::UI::Tools::NodeTool *nt = static_cast<Inkscape::UI::Tools::NodeTool*>(desktop->event_context); - std::set<ShapeRecord> shapes; - ShapeRecord r; - r.item = item; - shapes.insert(r); - nt->_multipath->setItems(shapes); - } - } - } +//TODO: Removed to fix a bug https://bugs.launchpad.net/inkscape/+bug/1716926 +// Maybe wee need to resurrect, not know when this code is added, but seems also not working now in a few test I do. +// in the future and do a deeper fix in multi-path-manipulator +// using namespace Inkscape::UI; +// SPDesktop *desktop = SP_ACTIVE_DESKTOP; +// if (desktop) { +// if (tools_isactive(desktop, TOOLS_NODES)) { +// SPItem * item = SP_ACTIVE_DESKTOP->getSelection()->singleItem(); +// if (item) { +// Inkscape::UI::Tools::NodeTool *nt = static_cast<Inkscape::UI::Tools::NodeTool*>(desktop->event_context); +// std::set<ShapeRecord> shapes; +// ShapeRecord r; +// r.item = item; +// shapes.insert(r); +// nt->_multipath->setItems(shapes); +// } +// } +// } g_free(defvalue); } @@ -169,6 +173,12 @@ PathParam::param_getSVGValue() const } } +gchar * +PathParam::param_getDefaultSVGValue() const +{ + return g_strdup(defvalue); +} + void PathParam::set_buttons(bool edit_button, bool copy_button, bool paste_button, bool link_button) { @@ -444,7 +454,11 @@ PathParam::linked_modified_callback(SPObject *linked_obj, guint /*flags*/) { SPCurve *curve = NULL; if (SP_IS_SHAPE(linked_obj)) { - curve = SP_SHAPE(linked_obj)->getCurve(); + if (_from_original_d) { + curve = SP_SHAPE(linked_obj)->getCurveBeforeLPE(); + } else { + curve = SP_SHAPE(linked_obj)->getCurve(); + } } if (SP_IS_TEXT(linked_obj)) { curve = SP_TEXT(linked_obj)->getNormalizedBpath(); diff --git a/src/live_effects/parameter/path.h b/src/live_effects/parameter/path.h index ff5e4f1b8..635056772 100644 --- a/src/live_effects/parameter/path.h +++ b/src/live_effects/parameter/path.h @@ -38,6 +38,7 @@ public: virtual bool param_readSVGValue(const gchar * strvalue); virtual gchar * param_getSVGValue() const; + virtual gchar * param_getDefaultSVGValue() const; virtual void param_set_default(); virtual void param_update_default(const gchar * default_value); @@ -50,6 +51,7 @@ public: virtual void addCanvasIndicators(SPLPEItem const* lpeitem, std::vector<Geom::PathVector> &hp_vec); virtual void param_transform_multiply(Geom::Affine const& /*postmul*/, bool /*set*/); + void setFromOriginalD(bool from_original_d){ _from_original_d = from_original_d; }; sigc::signal <void> signal_path_pasted; sigc::signal <void> signal_path_changed; @@ -91,6 +93,7 @@ protected: gchar * defvalue; private: + bool _from_original_d; bool _edit_button; bool _copy_button; bool _paste_button; diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index 331a86f81..da6edf812 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -115,6 +115,15 @@ PointParam::param_getSVGValue() const return str; } +gchar * +PointParam::param_getDefaultSVGValue() const +{ + Inkscape::SVGOStringStream os; + os << defvalue; + gchar * str = g_strdup(os.str().c_str()); + return str; +} + void PointParam::param_transform_multiply(Geom::Affine const& postmul, bool /*set*/) { diff --git a/src/live_effects/parameter/point.h b/src/live_effects/parameter/point.h index a5153ad80..03256f6d0 100644 --- a/src/live_effects/parameter/point.h +++ b/src/live_effects/parameter/point.h @@ -38,6 +38,7 @@ public: bool param_readSVGValue(const gchar * strvalue); gchar * param_getSVGValue() const; + gchar * param_getDefaultSVGValue() const; inline const gchar *handleTip() const { return handle_tip ? handle_tip : param_tooltip.c_str(); } void param_setValue(Geom::Point newpoint, bool write = false); void param_set_default(); diff --git a/src/live_effects/parameter/random.cpp b/src/live_effects/parameter/random.cpp index b1375adda..c2c1b5440 100644 --- a/src/live_effects/parameter/random.cpp +++ b/src/live_effects/parameter/random.cpp @@ -71,6 +71,15 @@ RandomParam::param_getSVGValue() const return str; } +gchar * +RandomParam::param_getDefaultSVGValue() const +{ + Inkscape::SVGOStringStream os; + os << defvalue << ';' << defseed; + gchar * str = g_strdup(os.str().c_str()); + return str; +} + void RandomParam::param_set_default() { diff --git a/src/live_effects/parameter/random.h b/src/live_effects/parameter/random.h index 5fb6027ac..c10473e85 100644 --- a/src/live_effects/parameter/random.h +++ b/src/live_effects/parameter/random.h @@ -31,6 +31,7 @@ public: virtual bool param_readSVGValue(const gchar * strvalue); virtual gchar * param_getSVGValue() const; + virtual gchar * param_getDefaultSVGValue() const; virtual void param_set_default(); virtual Gtk::Widget * param_newWidget(); diff --git a/src/live_effects/parameter/text.cpp b/src/live_effects/parameter/text.cpp index f40708917..7e56b2c75 100644 --- a/src/live_effects/parameter/text.cpp +++ b/src/live_effects/parameter/text.cpp @@ -9,7 +9,7 @@ */ #include "ui/widget/registered-widget.h" -#include <glibmm/i18n.h> +#include <gtkmm/alignment.h> #include "live_effects/parameter/text.h" #include "live_effects/effect.h" @@ -18,9 +18,10 @@ #include "inkscape.h" #include "verbs.h" #include "display/canvas-text.h" - #include <2geom/sbasis-geometric.h> +#include <glibmm/i18n.h> + namespace Inkscape { namespace LivePathEffect { @@ -115,6 +116,23 @@ TextParam::param_getSVGValue() const return str; } +gchar * +TextParam::param_getDefaultSVGValue() const +{ + Inkscape::SVGOStringStream os; + os << defvalue; + gchar * str = g_strdup(os.str().c_str()); + return str; +} + +void +TextParam::setTextParam(Inkscape::UI::Widget::RegisteredText *rsu) +{ + Glib::ustring str(rsu->getText()); + param_setValue(str); + write_to_SVG(); +} + Gtk::Widget * TextParam::param_newWidget() { @@ -122,9 +140,16 @@ TextParam::param_newWidget() param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc())); rsu->setText(value); rsu->setProgrammatically = false; - rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change text parameter")); - return dynamic_cast<Gtk::Widget *> (rsu); + Gtk::Box *text_container = Gtk::manage(new Gtk::Box()); + Gtk::Button *set = Gtk::manage(new Gtk::Button(Glib::ustring("✔"))); + set->signal_clicked() + .connect(sigc::bind<Inkscape::UI::Widget::RegisteredText *>(sigc::mem_fun(*this, &TextParam::setTextParam),rsu)); + text_container->pack_start(*rsu, false, false, 2); + text_container->pack_start(*set, false, false, 2); + Gtk::Widget *return_widg = dynamic_cast<Gtk::Widget *> (text_container); + return_widg->set_halign(Gtk::ALIGN_END); + return return_widg; } void diff --git a/src/live_effects/parameter/text.h b/src/live_effects/parameter/text.h index 137f3ee02..a9de26a52 100644 --- a/src/live_effects/parameter/text.h +++ b/src/live_effects/parameter/text.h @@ -38,9 +38,11 @@ public: virtual bool param_readSVGValue(const gchar * strvalue); virtual gchar * param_getSVGValue() const; + virtual gchar * param_getDefaultSVGValue() const; void param_setValue(Glib::ustring newvalue); void param_hide_canvas_text(); + void setTextParam(Inkscape::UI::Widget::RegisteredText *rsu); virtual void param_set_default(); virtual void param_update_default(const gchar * default_value); void setPos(Geom::Point pos); diff --git a/src/live_effects/parameter/togglebutton.cpp b/src/live_effects/parameter/togglebutton.cpp index 6aad8b3a6..e26884d6a 100644 --- a/src/live_effects/parameter/togglebutton.cpp +++ b/src/live_effects/parameter/togglebutton.cpp @@ -59,6 +59,13 @@ ToggleButtonParam::param_getSVGValue() const return str; } +gchar * +ToggleButtonParam::param_getDefaultSVGValue() const +{ + gchar * str = g_strdup(defvalue ? "true" : "false"); + return str; +} + void ToggleButtonParam::param_update_default(bool default_value) { @@ -140,21 +147,25 @@ ToggleButtonParam::refresh_button() if(!box_button){ return; } - GList * childs = gtk_container_get_children(GTK_CONTAINER(box_button->gobj())); - guint total_widgets = g_list_length (childs); + std::vector<Gtk::Widget*> children = Glib::wrap(GTK_CONTAINER(box_button))->get_children(); if (!param_label.empty()) { + Gtk::Label *lab = dynamic_cast<Gtk::Label*>(children[children.size()-1]); + if (!lab) return; if(value || inactive_label.empty()){ - gtk_label_set_text(GTK_LABEL(g_list_nth_data(childs, total_widgets-1)), param_label.c_str()); + lab->set_text(param_label.c_str()); }else{ - gtk_label_set_text(GTK_LABEL(g_list_nth_data(childs, total_widgets-1)), inactive_label.c_str()); + lab->set_text(inactive_label.c_str()); } } if ( _icon_active ) { GdkPixbuf * icon_pixbuf = NULL; + Gtk::Image *im = dynamic_cast<Gtk::Image*>(children[0]); + Gtk::IconSize is(_icon_size); + if (!im) return; if(!value){ - gtk_image_set_from_icon_name (GTK_IMAGE(g_list_nth_data(childs, 0)), _icon_inactive, _icon_size); + im->set_from_icon_name(_icon_inactive, is); } else { - gtk_image_set_from_icon_name (GTK_IMAGE(g_list_nth_data(childs, 0)), _icon_active, _icon_size); + im->set_from_icon_name(_icon_active, is); } } } diff --git a/src/live_effects/parameter/togglebutton.h b/src/live_effects/parameter/togglebutton.h index 02b9d5127..c5f8a3c28 100644 --- a/src/live_effects/parameter/togglebutton.h +++ b/src/live_effects/parameter/togglebutton.h @@ -12,7 +12,6 @@ #include <sigc++/signal.h> #include "live_effects/parameter/parameter.h" -#include "icon-size.h" #include "ui/widget/registered-widget.h" namespace Inkscape { @@ -41,6 +40,7 @@ public: virtual bool param_readSVGValue(const gchar * strvalue); virtual gchar * param_getSVGValue() const; + virtual gchar * param_getDefaultSVGValue() const; void param_setValue(bool newvalue); virtual void param_set_default(); diff --git a/src/live_effects/parameter/transformedpoint.cpp b/src/live_effects/parameter/transformedpoint.cpp index 22d5ba3a4..6ec2d0943 100644 --- a/src/live_effects/parameter/transformedpoint.cpp +++ b/src/live_effects/parameter/transformedpoint.cpp @@ -82,6 +82,15 @@ TransformedPointParam::param_getSVGValue() const return str; } +gchar * +TransformedPointParam::param_getDefaultSVGValue() const +{ + Inkscape::SVGOStringStream os; + os << defvalue; + gchar * str = g_strdup(os.str().c_str()); + return str; +} + void TransformedPointParam::param_update_default(Geom::Point default_point) { diff --git a/src/live_effects/parameter/transformedpoint.h b/src/live_effects/parameter/transformedpoint.h index 269cc508e..8b92d81ba 100644 --- a/src/live_effects/parameter/transformedpoint.h +++ b/src/live_effects/parameter/transformedpoint.h @@ -37,6 +37,7 @@ public: virtual bool param_readSVGValue(const gchar * strvalue); virtual gchar * param_getSVGValue() const; + virtual gchar * param_getDefaultSVGValue() const; Geom::Point getVector() const { return vector; }; Geom::Point getOrigin() const { return origin; }; diff --git a/src/live_effects/parameter/unit.cpp b/src/live_effects/parameter/unit.cpp index b9b91c1e6..9199e592d 100644 --- a/src/live_effects/parameter/unit.cpp +++ b/src/live_effects/parameter/unit.cpp @@ -48,6 +48,12 @@ UnitParam::param_getSVGValue() const return g_strdup(unit->abbr.c_str()); } +gchar * +UnitParam::param_getDefaultSVGValue() const +{ + return g_strdup(defunit->abbr.c_str()); +} + void UnitParam::param_set_default() { diff --git a/src/live_effects/parameter/unit.h b/src/live_effects/parameter/unit.h index c662b6edc..86e1a24b3 100644 --- a/src/live_effects/parameter/unit.h +++ b/src/live_effects/parameter/unit.h @@ -31,6 +31,7 @@ public: virtual bool param_readSVGValue(const gchar * strvalue); virtual gchar * param_getSVGValue() const; + virtual gchar * param_getDefaultSVGValue() const; virtual void param_set_default(); void param_set_value(Inkscape::Util::Unit const &val); virtual void param_update_default(const gchar * default_unit); diff --git a/src/live_effects/parameter/vector.cpp b/src/live_effects/parameter/vector.cpp index 470fa9c2d..6b565536e 100644 --- a/src/live_effects/parameter/vector.cpp +++ b/src/live_effects/parameter/vector.cpp @@ -101,6 +101,15 @@ VectorParam::param_getSVGValue() const return str; } +gchar * +VectorParam::param_getDefaultSVGValue() const +{ + Inkscape::SVGOStringStream os; + os << defvalue; + gchar * str = g_strdup(os.str().c_str()); + return str; +} + Gtk::Widget * VectorParam::param_newWidget() { diff --git a/src/live_effects/parameter/vector.h b/src/live_effects/parameter/vector.h index d270e9f43..8c842e805 100644 --- a/src/live_effects/parameter/vector.h +++ b/src/live_effects/parameter/vector.h @@ -36,6 +36,7 @@ public: virtual bool param_readSVGValue(const gchar * strvalue); virtual gchar * param_getSVGValue() const; + virtual gchar * param_getDefaultSVGValue() const; Geom::Point getVector() const { return vector; }; Geom::Point getOrigin() const { return origin; }; |
