summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbulia byak <buliabyak@gmail.com>2006-03-26 03:07:42 +0000
committerbuliabyak <buliabyak@users.sourceforge.net>2006-03-26 03:07:42 +0000
commitf696df00a5d4b90bab82a53b13ab77384307b876 (patch)
treef9f1d0a61df49b9091b0aee62d1dd47e9864e5d3
parentmenu rearrange, tips copyedit (diff)
downloadinkscape-f696df00a5d4b90bab82a53b13ab77384307b876.tar.gz
inkscape-f696df00a5d4b90bab82a53b13ab77384307b876.zip
pasting size
(bzr r298)
-rw-r--r--src/menus-skeleton.h6
-rw-r--r--src/selection-chemistry.cpp71
-rw-r--r--src/selection-chemistry.h3
-rw-r--r--src/verbs.cpp30
-rw-r--r--src/verbs.h6
5 files changed, 116 insertions, 0 deletions
diff --git a/src/menus-skeleton.h b/src/menus-skeleton.h
index bb497245a..ccc54f0b5 100644
--- a/src/menus-skeleton.h
+++ b/src/menus-skeleton.h
@@ -60,6 +60,12 @@ static char const menus_skeleton[] =
" <verb verb-id=\"EditPaste\" />\n"
" <verb verb-id=\"EditPasteInPlace\" />\n"
" <verb verb-id=\"EditPasteStyle\" />\n"
+" <submenu name=\"" N_("Paste Si_ze") "\">\n"
+" <verb verb-id=\"EditPasteSize\" />\n"
+" <verb verb-id=\"EditPasteWidth\" />\n"
+" <verb verb-id=\"EditPasteHeight\" />\n"
+" <verb verb-id=\"EditPasteSizeSeparately\" />\n"
+" </submenu>\n"
" <separator/>\n"
" <verb verb-id=\"DialogFind\" />\n"
" <separator/>\n"
diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp
index 851fc3a3b..d01bb3e50 100644
--- a/src/selection-chemistry.cpp
+++ b/src/selection-chemistry.cpp
@@ -74,6 +74,7 @@ using NR::Y;
GSList *clipboard = NULL;
GSList *defs_clipboard = NULL;
SPCSSAttr *style_clipboard = NULL;
+NR::Rect size_clipboard(NR::Point(0,0), NR::Point(0,0));
static void sp_copy_stuff_used_by_item(GSList **defs_clip, SPItem *item, const GSList *items);
@@ -1042,6 +1043,8 @@ void sp_selection_copy()
g_free (query);
}
+ size_clipboard = selection->bounds();
+
g_slist_free ((GSList *) items);
}
@@ -1121,6 +1124,74 @@ void sp_selection_paste_style()
sp_document_done(SP_DT_DOCUMENT (desktop));
}
+void sp_selection_paste_size (bool apply_x, bool apply_y)
+{
+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+ if (desktop == NULL) return;
+
+ Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+
+ // check if something is in the clipboard
+ if (size_clipboard.extent(NR::X) < 1e-6 || size_clipboard.extent(NR::Y) < 1e-6) {
+ desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Nothing on the clipboard."));
+ return;
+ }
+
+ // check if something is selected
+ if (selection->isEmpty()) {
+ desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to paste size to."));
+ return;
+ }
+
+ NR::Rect current = selection->bounds();
+ if (current.extent(NR::X) < 1e-6 || current.extent(NR::Y) < 1e-6) {
+ return;
+ }
+
+ double scale_x = size_clipboard.extent(NR::X) / current.extent(NR::X);
+ double scale_y = size_clipboard.extent(NR::Y) / current.extent(NR::Y);
+
+ sp_selection_scale_relative (selection, current.midpoint(), NR::scale(apply_x? scale_x : 1.0, apply_y? scale_y : 1.0));
+
+ sp_document_done(SP_DT_DOCUMENT (desktop));
+}
+
+void sp_selection_paste_size_separately (bool apply_x, bool apply_y)
+{
+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+ if (desktop == NULL) return;
+
+ Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+
+ // check if something is in the clipboard
+ if (size_clipboard.extent(NR::X) < 1e-6 || size_clipboard.extent(NR::Y) < 1e-6) {
+ desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Nothing on the clipboard."));
+ return;
+ }
+
+ // check if something is selected
+ if (selection->isEmpty()) {
+ desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to paste size to."));
+ return;
+ }
+
+ for (GSList const *l = selection->itemList(); l != NULL; l = l->next) {
+ SPItem *item = SP_ITEM(l->data);
+
+ NR::Rect current = sp_item_bbox_desktop(item);
+ if (current.extent(NR::X) < 1e-6 || current.extent(NR::Y) < 1e-6) {
+ continue;
+ }
+
+ double scale_x = size_clipboard.extent(NR::X) / current.extent(NR::X);
+ double scale_y = size_clipboard.extent(NR::Y) / current.extent(NR::Y);
+
+ sp_item_scale_rel (item, NR::scale(apply_x? scale_x : 1.0, apply_y? scale_y : 1.0));
+ }
+
+ sp_document_done(SP_DT_DOCUMENT (desktop));
+}
+
void sp_selection_to_next_layer ()
{
SPDesktop *dt = SP_ACTIVE_DESKTOP;
diff --git a/src/selection-chemistry.h b/src/selection-chemistry.h
index df8b69931..1e2e4cf07 100644
--- a/src/selection-chemistry.h
+++ b/src/selection-chemistry.h
@@ -53,6 +53,9 @@ void sp_selection_copy();
void sp_selection_paste(bool in_place);
void sp_selection_paste_style();
+void sp_selection_paste_size(bool apply_x, bool apply_y);
+void sp_selection_paste_size_separately(bool apply_x, bool apply_y);
+
void sp_selection_to_next_layer ();
void sp_selection_to_prev_layer ();
diff --git a/src/verbs.cpp b/src/verbs.cpp
index eb19eee25..a700a3ad2 100644
--- a/src/verbs.cpp
+++ b/src/verbs.cpp
@@ -820,6 +820,24 @@ EditVerb::perform(SPAction *action, void *data, void *pdata)
case SP_VERB_EDIT_PASTE_STYLE:
sp_selection_paste_style();
break;
+ case SP_VERB_EDIT_PASTE_SIZE:
+ sp_selection_paste_size(true, true);
+ break;
+ case SP_VERB_EDIT_PASTE_SIZE_X:
+ sp_selection_paste_size(true, false);
+ break;
+ case SP_VERB_EDIT_PASTE_SIZE_Y:
+ sp_selection_paste_size(false, true);
+ break;
+ case SP_VERB_EDIT_PASTE_SIZE_SEPARATELY:
+ sp_selection_paste_size_separately(true, true);
+ break;
+ case SP_VERB_EDIT_PASTE_SIZE_SEPARATELY_X:
+ sp_selection_paste_size_separately(true, false);
+ break;
+ case SP_VERB_EDIT_PASTE_SIZE_SEPARATELY_Y:
+ sp_selection_paste_size_separately(false, true);
+ break;
case SP_VERB_EDIT_PASTE_IN_PLACE:
sp_selection_paste(true);
break;
@@ -1877,6 +1895,18 @@ Verb *Verb::_base_verbs[] = {
N_("Paste objects from clipboard to mouse point"), GTK_STOCK_PASTE),
new EditVerb(SP_VERB_EDIT_PASTE_STYLE, "EditPasteStyle", N_("Paste _Style"),
N_("Apply the style of the copied object to selection"), "selection_paste_style"),
+ new EditVerb(SP_VERB_EDIT_PASTE_SIZE, "EditPasteSize", N_("Paste Si_ze"),
+ N_("Scale selection to match the size of the copied object"), NULL),
+ new EditVerb(SP_VERB_EDIT_PASTE_SIZE_X, "EditPasteWidth", N_("Paste _Width"),
+ N_("Scale selection horizontally to match the width of the copied object"), NULL),
+ new EditVerb(SP_VERB_EDIT_PASTE_SIZE_Y, "EditPasteHeight", N_("Paste _Height"),
+ N_("Scale selection vertically to match the height of the copied object"), NULL),
+ new EditVerb(SP_VERB_EDIT_PASTE_SIZE_SEPARATELY, "EditPasteSizeSeparately", N_("Paste Size Separately"),
+ N_("Scale each selected object to match the size of the copied object"), NULL),
+ new EditVerb(SP_VERB_EDIT_PASTE_SIZE_SEPARATELY_X, "EditPasteWidthSeparately", N_("Paste Width Separately"),
+ N_("Scale each selected object horizontally to match the width of the copied object"), NULL),
+ new EditVerb(SP_VERB_EDIT_PASTE_SIZE_SEPARATELY_Y, "EditPasteHeightSeparately", N_("Paste Height Separately"),
+ N_("Scale each selected object vertically to match the height of the copied object"), NULL),
new EditVerb(SP_VERB_EDIT_PASTE_IN_PLACE, "EditPasteInPlace", N_("Paste _In Place"),
N_("Paste objects from clipboard to the original location"), "selection_paste_in_place"),
new EditVerb(SP_VERB_EDIT_DELETE, "EditDelete", N_("_Delete"),
diff --git a/src/verbs.h b/src/verbs.h
index 426b4295f..e79fa6d43 100644
--- a/src/verbs.h
+++ b/src/verbs.h
@@ -47,6 +47,12 @@ enum {
SP_VERB_EDIT_COPY,
SP_VERB_EDIT_PASTE,
SP_VERB_EDIT_PASTE_STYLE,
+ SP_VERB_EDIT_PASTE_SIZE,
+ SP_VERB_EDIT_PASTE_SIZE_X,
+ SP_VERB_EDIT_PASTE_SIZE_Y,
+ SP_VERB_EDIT_PASTE_SIZE_SEPARATELY,
+ SP_VERB_EDIT_PASTE_SIZE_SEPARATELY_X,
+ SP_VERB_EDIT_PASTE_SIZE_SEPARATELY_Y,
SP_VERB_EDIT_PASTE_IN_PLACE,
SP_VERB_EDIT_DELETE,
SP_VERB_EDIT_DUPLICATE,