Code

pasting size
authorbuliabyak <buliabyak@users.sourceforge.net>
Sun, 26 Mar 2006 03:07:42 +0000 (03:07 +0000)
committerbuliabyak <buliabyak@users.sourceforge.net>
Sun, 26 Mar 2006 03:07:42 +0000 (03:07 +0000)
src/menus-skeleton.h
src/selection-chemistry.cpp
src/selection-chemistry.h
src/verbs.cpp
src/verbs.h

index bb497245a58b65c9cf7b1bb9f51263d8d0567855..ccc54f0b50503d5331271fa3f070b6c8ba7ed3ab 100644 (file)
@@ -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"
index 851fc3a3bf9780828aceef86cafe852a00bcd538..d01bb3e50561555d8f9ad1d16a821429406a7fbb 100644 (file)
@@ -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;
index df8b699317726bb29dbaf709ef42cfd7f0451696..1e2e4cf077be0f10ac93ab19ef0f9e96752c596b 100644 (file)
@@ -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 ();
 
index eb19eee253d6f91a7b5daff924701f04130359da..a700a3ad2b814e415866d54f45d598938ace76d1 100644 (file)
@@ -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"),
index 426b4295f0236b6b38d1118caa552fb3d33e06d1..e79fa6d43621cc98e98167051352499996bdfff0 100644 (file)
@@ -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,