From: johanengelen Date: Sat, 26 Jan 2008 16:44:00 +0000 (+0000) Subject: add copy button to LPE pathparam X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=539b02bd98b6985f91ccbf7041f88fdf93061531;p=inkscape.git add copy button to LPE pathparam --- diff --git a/src/libnr/nr-convert2geom.h b/src/libnr/nr-convert2geom.h index 67b174b3a..c9ae68bd1 100644 --- a/src/libnr/nr-convert2geom.h +++ b/src/libnr/nr-convert2geom.h @@ -11,12 +11,19 @@ #include <2geom/matrix.h> #include +#include <2geom/d2.h> +#include inline Geom::Matrix to_2geom(NR::Matrix const & mat) { Geom::Matrix mat2geom(mat[0], mat[1], mat[2], mat[3], mat[4], mat[5]); return mat2geom; } +inline NR::Rect from_2geom(Geom::Rect const & rect2geom) { + NR::Rect rect(rect2geom.min(), rect2geom.max()); + return rect; +} + #endif /* diff --git a/src/live_effects/parameter/path.cpp b/src/live_effects/parameter/path.cpp index df904b8a1..7d7679496 100644 --- a/src/live_effects/parameter/path.cpp +++ b/src/live_effects/parameter/path.cpp @@ -103,6 +103,16 @@ PathParam::param_newWidget(Gtk::Tooltips * tooltips) static_cast(_widget)->pack_start(*pButton, true, true); tooltips->set_tip(*pButton, _("Edit on-canvas")); + pIcon = Gtk::manage( sp_icon_get_icon( GTK_STOCK_COPY, Inkscape::ICON_SIZE_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, &PathParam::on_copy_button_click)); + static_cast(_widget)->pack_start(*pButton, true, true); + tooltips->set_tip(*pButton, _("Copy path")); + pIcon = Gtk::manage( sp_icon_get_icon( GTK_STOCK_PASTE, Inkscape::ICON_SIZE_BUTTON) ); pButton = Gtk::manage(new Gtk::Button()); pButton->set_relief(Gtk::RELIEF_NONE); @@ -194,6 +204,11 @@ PathParam::on_paste_button_click() } } +void +PathParam::on_copy_button_click() +{ + sp_selection_copy_lpe_pathparam(this); +} } /* namespace LivePathEffect */ diff --git a/src/live_effects/parameter/path.h b/src/live_effects/parameter/path.h index d6ea8d1cd..f02974bc7 100644 --- a/src/live_effects/parameter/path.h +++ b/src/live_effects/parameter/path.h @@ -56,6 +56,7 @@ private: void on_edit_button_click(); void on_paste_button_click(); + void on_copy_button_click(); gchar * defvalue; }; diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 381f45e0d..caf32ce3e 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -20,6 +20,8 @@ # include "config.h" #endif +#include "selection-chemistry.h" + #include #include "svg/svg.h" @@ -79,12 +81,12 @@ #include "gradient-drag.h" #include "uri-references.h" #include "live_effects/lpeobject.h" +#include "live_effects/parameter/path.h" +#include "libnr/nr-convert2geom.h" using NR::X; using NR::Y; -#include "selection-chemistry.h" - /* fixme: find a better place */ Inkscape::XML::Document *clipboard_document = NULL; GSList *clipboard = NULL; @@ -1123,6 +1125,51 @@ void sp_selection_copy() g_slist_free ((GSList *) items); } + +void sp_selection_copy_lpe_pathparam(Inkscape::LivePathEffect::PathParam * pathparam) +{ + if (pathparam == NULL) + return; + + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + if (desktop == NULL) + return; + + if (!clipboard_document) { + clipboard_document = new Inkscape::XML::SimpleDocument(); + } + + // clear old defs clipboard + while (defs_clipboard) { + Inkscape::GC::release((Inkscape::XML::Node *) defs_clipboard->data); + defs_clipboard = g_slist_remove (defs_clipboard, defs_clipboard->data); + } + + // clear style clipboard + if (style_clipboard) { + sp_repr_css_attr_unref (style_clipboard); + style_clipboard = NULL; + } + + //clear main clipboard + while (clipboard) { + Inkscape::GC::release((Inkscape::XML::Node *) clipboard->data); + clipboard = g_slist_remove(clipboard, clipboard->data); + } + + // make new path node and put svgd as 'd' attribute + Inkscape::XML::Node *newnode = clipboard_document->createElement("svg:path"); + gchar * svgd = pathparam->param_writeSVGValue(); + newnode->setAttribute("d", svgd); + g_free(svgd); + + clipboard = g_slist_prepend(clipboard, newnode); + + Geom::Rect bnds = Geom::bounds_exact(*pathparam); + size_clipboard = from_2geom(bnds); +} + + //____________________________________________________________________________ /** Paste the bitmap in the clipboard if one is in there. diff --git a/src/selection-chemistry.h b/src/selection-chemistry.h index 0dc1da7e7..501dcc520 100644 --- a/src/selection-chemistry.h +++ b/src/selection-chemistry.h @@ -20,6 +20,12 @@ namespace Inkscape { class Selection; } +namespace Inkscape { +namespace LivePathEffect { + class PathParam; +} +} + class SPCSSAttr; void sp_selection_delete(); @@ -53,6 +59,7 @@ SPCSSAttr *take_style_from_item (SPItem *item); void sp_selection_cut(); void sp_selection_copy(); +void sp_selection_copy_lpe_pathparam(Inkscape::LivePathEffect::PathParam * pathparam); void sp_selection_paste(bool in_place); void sp_selection_paste_style(); void sp_selection_paste_livepatheffect();