Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / ui / dialog / transformation.cpp
index 62f0f38aa18720df3956a40755ed690af2c179c8..c895f0be9d3650e92a745e7a19496a6bcd032b92 100644 (file)
@@ -4,6 +4,7 @@
 /* Authors:
  *   Bryce W. Harrington <bryce@bryceharrington.org>
  *   buliabyak@gmail.com
+ *   Abhishek Sharma
  *
  * Copyright (C) 2004, 2005 Authors
  * Released under GNU GPL.  Read the file 'COPYING' for more information.
@@ -26,6 +27,7 @@
 #include "selection-chemistry.h"
 #include "verbs.h"
 #include "preferences.h"
+#include "sp-namedview.h"
 #include "sp-item-transform.h"
 #include "macros.h"
 #include "sp-item.h"
@@ -79,27 +81,27 @@ Transformation::Transformation()
       _page_rotate            (4, 2),
       _page_skew              (4, 2),
       _page_transform         (3, 3),
-      _scalar_move_horizontal (_("_Horizontal"), _("Horizontal displacement (relative) or position (absolute)"), UNIT_TYPE_LINEAR,
+      _scalar_move_horizontal (_("_Horizontal:"), _("Horizontal displacement (relative) or position (absolute)"), UNIT_TYPE_LINEAR,
                                "", "transform-move-horizontal", &_units_move),
-      _scalar_move_vertical   (_("_Vertical"),  _("Vertical displacement (relative) or position (absolute)"), UNIT_TYPE_LINEAR,
+      _scalar_move_vertical   (_("_Vertical:"),  _("Vertical displacement (relative) or position (absolute)"), UNIT_TYPE_LINEAR,
                                "", "transform-move-vertical", &_units_move),
-      _scalar_scale_horizontal(_("_Width"), _("Horizontal size (absolute or percentage of current)"), UNIT_TYPE_DIMENSIONLESS,
+      _scalar_scale_horizontal(_("_Width:"), _("Horizontal size (absolute or percentage of current)"), UNIT_TYPE_DIMENSIONLESS,
                                "", "transform-scale-horizontal", &_units_scale),
-      _scalar_scale_vertical  (_("_Height"),  _("Vertical size (absolute or percentage of current)"), UNIT_TYPE_DIMENSIONLESS,
+      _scalar_scale_vertical  (_("_Height:"),  _("Vertical size (absolute or percentage of current)"), UNIT_TYPE_DIMENSIONLESS,
                                "", "transform-scale-vertical", &_units_scale),
-      _scalar_rotate          (_("A_ngle"), _("Rotation angle (positive = counterclockwise)"), UNIT_TYPE_RADIAL,
+      _scalar_rotate          (_("A_ngle:"), _("Rotation angle (positive = counterclockwise)"), UNIT_TYPE_RADIAL,
                                "", "transform-rotate", &_units_rotate),
-      _scalar_skew_horizontal (_("_Horizontal"), _("Horizontal skew angle (positive = counterclockwise), or absolute displacement, or percentage displacement"), UNIT_TYPE_LINEAR,
+      _scalar_skew_horizontal (_("_Horizontal:"), _("Horizontal skew angle (positive = counterclockwise), or absolute displacement, or percentage displacement"), UNIT_TYPE_LINEAR,
                                "", "transform-skew-horizontal", &_units_skew),
-      _scalar_skew_vertical   (_("_Vertical"),  _("Vertical skew angle (positive = counterclockwise), or absolute displacement, or percentage displacement"),  UNIT_TYPE_LINEAR,
+      _scalar_skew_vertical   (_("_Vertical:"),  _("Vertical skew angle (positive = counterclockwise), or absolute displacement, or percentage displacement"),  UNIT_TYPE_LINEAR,
                                "", "transform-skew-vertical", &_units_skew),
 
-      _scalar_transform_a     ("_A", _("Transformation matrix element A")),
-      _scalar_transform_b     ("_B", _("Transformation matrix element B")),
-      _scalar_transform_c     ("_C", _("Transformation matrix element C")),
-      _scalar_transform_d     ("_D", _("Transformation matrix element D")),
-      _scalar_transform_e     ("_E", _("Transformation matrix element E")),
-      _scalar_transform_f     ("_F", _("Transformation matrix element F")),
+      _scalar_transform_a     ("_A:", _("Transformation matrix element A")),
+      _scalar_transform_b     ("_B:", _("Transformation matrix element B")),
+      _scalar_transform_c     ("_C:", _("Transformation matrix element C")),
+      _scalar_transform_d     ("_D:", _("Transformation matrix element D")),
+      _scalar_transform_e     ("_E:", _("Transformation matrix element E")),
+      _scalar_transform_f     ("_F:", _("Transformation matrix element F")),
 
       _check_move_relative    (_("Rela_tive move"), _("Add the specified relative displacement to the current position; otherwise, edit the current absolute position directly")),
       _check_scale_proportional (_("Scale proportionally"), _("Preserve the width/height ratio of the scaled objects")),
@@ -198,6 +200,14 @@ void
 Transformation::layoutPageMove()
 {
     _units_move.setUnitType(UNIT_TYPE_LINEAR);
+    
+    // Setting default unit to document unit
+    SPDesktop *dt = getDesktop();
+    SPNamedView *nv = sp_desktop_namedview(dt);
+    if (nv->doc_units) {
+        _units_move.setUnit(nv->doc_units->abbr);
+    }
+    
     _scalar_move_horizontal.initScalar(-1e6, 1e6);
     _scalar_move_horizontal.setDigits(3);
     _scalar_move_horizontal.setIncrements(0.1, 1.0);
@@ -462,8 +472,9 @@ Transformation::updatePageMove(Inkscape::Selection *selection)
                 double x = bbox->min()[Geom::X];
                 double y = bbox->min()[Geom::Y];
 
-                _scalar_move_horizontal.setValue(x, "px");
-                _scalar_move_vertical.setValue(y, "px");
+                double conversion = _units_move.getConversion("px");
+                _scalar_move_horizontal.setValue(x / conversion);
+                _scalar_move_vertical.setValue(y / conversion);
             }
         } else {
             // do nothing, so you can apply the same relative move to many objects in turn
@@ -677,8 +688,8 @@ Transformation::applyPageMove(Inkscape::Selection *selection)
         }
     }
 
-    SPDocumentUndo::done ( sp_desktop_document (selection->desktop()) , SP_VERB_DIALOG_TRANSFORM,
-                       _("Move"));
+    DocumentUndo::done( sp_desktop_document(selection->desktop()) , SP_VERB_DIALOG_TRANSFORM,
+                        _("Move"));
 }
 
 void
@@ -734,8 +745,8 @@ Transformation::applyPageScale(Inkscape::Selection *selection)
         }
     }
 
-    SPDocumentUndo::done(sp_desktop_document(selection->desktop()), SP_VERB_DIALOG_TRANSFORM,
-                     _("Scale"));
+    DocumentUndo::done(sp_desktop_document(selection->desktop()), SP_VERB_DIALOG_TRANSFORM,
+                       _("Scale"));
 }
 
 void
@@ -756,8 +767,8 @@ Transformation::applyPageRotate(Inkscape::Selection *selection)
         }
     }
 
-    SPDocumentUndo::done(sp_desktop_document(selection->desktop()), SP_VERB_DIALOG_TRANSFORM,
-                     _("Rotate"));
+    DocumentUndo::done(sp_desktop_document(selection->desktop()), SP_VERB_DIALOG_TRANSFORM,
+                       _("Rotate"));
 }
 
 void
@@ -815,8 +826,8 @@ Transformation::applyPageSkew(Inkscape::Selection *selection)
         }
     }
 
-    SPDocumentUndo::done(sp_desktop_document(selection->desktop()), SP_VERB_DIALOG_TRANSFORM,
-                     _("Skew"));
+    DocumentUndo::done(sp_desktop_document(selection->desktop()), SP_VERB_DIALOG_TRANSFORM,
+                       _("Skew"));
 }
 
 
@@ -842,8 +853,8 @@ Transformation::applyPageTransform(Inkscape::Selection *selection)
         sp_selection_apply_affine(selection, displayed); // post-multiply each object's transform
     }
 
-    SPDocumentUndo::done(sp_desktop_document(selection->desktop()), SP_VERB_DIALOG_TRANSFORM,
-                     _("Edit transformation matrix"));
+    DocumentUndo::done(sp_desktop_document(selection->desktop()), SP_VERB_DIALOG_TRANSFORM,
+                       _("Edit transformation matrix"));
 }
 
 
@@ -871,6 +882,8 @@ Transformation::onMoveRelativeToggled()
     double x = _scalar_move_horizontal.getValue("px");
     double y = _scalar_move_vertical.getValue("px");
 
+    double conversion = _units_move.getConversion("px");
+
     //g_message("onMoveRelativeToggled: %f, %f px\n", x, y);
 
     Geom::OptRect bbox = selection->bounds();
@@ -878,12 +891,12 @@ Transformation::onMoveRelativeToggled()
     if (bbox) {
         if (_check_move_relative.get_active()) {
             // From absolute to relative
-            _scalar_move_horizontal.setValue(x - bbox->min()[Geom::X], "px");
-            _scalar_move_vertical.setValue(  y - bbox->min()[Geom::Y], "px");
+            _scalar_move_horizontal.setValue((x - bbox->min()[Geom::X]) / conversion);
+            _scalar_move_vertical.setValue((  y - bbox->min()[Geom::Y]) / conversion);
         } else {
             // From relative to absolute
-            _scalar_move_horizontal.setValue(bbox->min()[Geom::X] + x, "px");
-            _scalar_move_vertical.setValue(  bbox->min()[Geom::Y] + y, "px");
+            _scalar_move_horizontal.setValue((bbox->min()[Geom::X] + x) / conversion);
+            _scalar_move_vertical.setValue((  bbox->min()[Geom::Y] + y) / conversion);
         }
     }
 
@@ -1068,4 +1081,4 @@ Transformation::onApplySeparatelyToggled()
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :