Code

Punctuation in UI
[inkscape.git] / src / ui / dialog / transformation.cpp
index 5927dc74031207e1378605c043b5919fca85e9d3..c25e9a8c4bbd647f505538c170d59cf052b4914a 100644 (file)
@@ -1,12 +1,11 @@
-/**
- * \brief Object Transformation dialog
- *
- * Authors:
+/** @file
+ * \brief Transform dialog - implementation
+ */
+/* Authors:
  *   Bryce W. Harrington <bryce@bryceharrington.org>
  *   buliabyak@gmail.com
  *
  * Copyright (C) 2004, 2005 Authors
- *
  * Released under GNU GPL.  Read the file 'COPYING' for more information.
  */
 
@@ -26,7 +25,8 @@
 #include "selection.h"
 #include "selection-chemistry.h"
 #include "verbs.h"
-#include "prefs-utils.h"
+#include "preferences.h"
+#include "sp-namedview.h"
 #include "sp-item-transform.h"
 #include "macros.h"
 #include "sp-item.h"
@@ -74,33 +74,33 @@ void on_selection_modified( Inkscape::Application */*inkscape*/,
  *
  */
 Transformation::Transformation()
-    : UI::Widget::Panel ("", "dialogs.transformation", SP_VERB_DIALOG_TRANSFORM),
+    : UI::Widget::Panel ("", "/dialogs/transformation", SP_VERB_DIALOG_TRANSFORM),
       _page_move              (4, 2),
       _page_scale             (4, 2),
       _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,
-                               "", "arrows_hor", &_units_move),
-      _scalar_move_vertical   (_("_Vertical"),  _("Vertical displacement (relative) or position (absolute)"), UNIT_TYPE_LINEAR,
-                               "", "arrows_ver", &_units_move),
-      _scalar_scale_horizontal(_("_Width"), _("Horizontal size (absolute or percentage of current)"), UNIT_TYPE_DIMENSIONLESS,
-                               "", "transform_scale_hor", &_units_scale),
-      _scalar_scale_vertical  (_("_Height"),  _("Vertical size (absolute or percentage of current)"), UNIT_TYPE_DIMENSIONLESS,
-                               "", "transform_scale_ver", &_units_scale),
-      _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,
-                               "", "transform_scew_hor", &_units_skew),
-      _scalar_skew_vertical   (_("_Vertical"),  _("Vertical skew angle (positive = counterclockwise), or absolute displacement, or percentage displacement"),  UNIT_TYPE_LINEAR,
-                               "", "transform_scew_ver", &_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_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,
+                               "", "transform-move-vertical", &_units_move),
+      _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,
+                               "", "transform-scale-vertical", &_units_scale),
+      _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,
+                               "", "transform-skew-horizontal", &_units_skew),
+      _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")),
 
       _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")),
@@ -134,7 +134,8 @@ Transformation::Transformation()
 
     // Apply separately
     contents->pack_start(_check_apply_separately, true, true);
-    _check_apply_separately.set_active(prefs_get_int_attribute_limited ("dialogs.transformation", "applyseparately", 0, 0, 1));
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    _check_apply_separately.set_active(prefs->getBool("/dialogs/transformation/applyseparately"));
     _check_apply_separately.signal_toggled().connect(sigc::mem_fun(*this, &Transformation::onApplySeparatelyToggled));
 
     // make sure all spinbuttons activate Apply on pressing Enter
@@ -198,6 +199,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);
@@ -457,13 +466,14 @@ Transformation::updatePageMove(Inkscape::Selection *selection)
 {
     if (selection && !selection->isEmpty()) {
         if (!_check_move_relative.get_active()) {
-            boost::optional<Geom::Rect> bbox = selection->bounds();
+            Geom::OptRect bbox = selection->bounds();
             if (bbox) {
                 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
@@ -478,7 +488,7 @@ void
 Transformation::updatePageScale(Inkscape::Selection *selection)
 {
     if (selection && !selection->isEmpty()) {
-        boost::optional<Geom::Rect> bbox = selection->bounds();
+        Geom::OptRect bbox = selection->bounds();
         if (bbox) {
             double w = bbox->dimensions()[Geom::X];
             double h = bbox->dimensions()[Geom::Y];
@@ -508,7 +518,7 @@ void
 Transformation::updatePageSkew(Inkscape::Selection *selection)
 {
     if (selection && !selection->isEmpty()) {
-        boost::optional<Geom::Rect> bbox = selection->bounds();
+        Geom::OptRect bbox = selection->bounds();
         if (bbox) {
             double w = bbox->dimensions()[Geom::X];
             double h = bbox->dimensions()[Geom::Y];
@@ -599,12 +609,13 @@ Transformation::applyPageMove(Inkscape::Selection *selection)
     double x = _scalar_move_horizontal.getValue("px");
     double y = _scalar_move_vertical.getValue("px");
 
-    if (prefs_get_int_attribute_limited ("dialogs.transformation", "applyseparately", 0, 0, 1) == 0) {
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    if (!prefs->getBool("/dialogs/transformation/applyseparately")) {
         // move selection as a whole
         if (_check_move_relative.get_active()) {
             sp_selection_move_relative(selection, x, y);
         } else {
-            boost::optional<Geom::Rect> bbox = selection->bounds();
+            Geom::OptRect bbox = selection->bounds();
             if (bbox) {
                 sp_selection_move_relative(selection,
                                            x - bbox->min()[Geom::X], y - bbox->min()[Geom::Y]);
@@ -625,7 +636,7 @@ Transformation::applyPageMove(Inkscape::Selection *selection)
                      it != selected.end();
                      ++it)
                 {
-                    boost::optional<Geom::Rect> bbox = sp_item_bbox_desktop(*it);
+                    Geom::OptRect bbox = sp_item_bbox_desktop(*it);
                     if (bbox) {
                         sorted.push_back(BBoxSort(*it, *bbox, Geom::X, x > 0? 1. : 0., x > 0? 0. : 1.));
                     }
@@ -649,7 +660,7 @@ Transformation::applyPageMove(Inkscape::Selection *selection)
                      it != selected.end();
                      ++it)
                 {
-                    boost::optional<Geom::Rect> bbox = sp_item_bbox_desktop(*it);
+                    Geom::OptRect bbox = sp_item_bbox_desktop(*it);
                     if (bbox) {
                         sorted.push_back(BBoxSort(*it, *bbox, Geom::Y, y > 0? 1. : 0., y > 0? 0. : 1.));
                     }
@@ -668,7 +679,7 @@ Transformation::applyPageMove(Inkscape::Selection *selection)
                 }
             }
         } else {
-            boost::optional<Geom::Rect> bbox = selection->bounds();
+            Geom::OptRect bbox = selection->bounds();
             if (bbox) {
                 sp_selection_move_relative(selection,
                                            x - bbox->min()[Geom::X], y - bbox->min()[Geom::Y]);
@@ -686,13 +697,14 @@ Transformation::applyPageScale(Inkscape::Selection *selection)
     double scaleX = _scalar_scale_horizontal.getValue("px");
     double scaleY = _scalar_scale_vertical.getValue("px");
 
-    if (prefs_get_int_attribute_limited ("dialogs.transformation", "applyseparately", 0, 0, 1) == 1) {
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    if (prefs->getBool("/dialogs/transformation/applyseparately")) {
         for (GSList const *l = selection->itemList(); l != NULL; l = l->next) {
             SPItem *item = SP_ITEM(l->data);
             Geom::Scale scale (0,0);
             // the values are increments!
             if (_units_scale.isAbsolute()) {
-                boost::optional<Geom::Rect> bbox(sp_item_bbox_desktop(item));
+                Geom::OptRect bbox(sp_item_bbox_desktop(item));
                 if (bbox) {
                     double new_width = scaleX;
                     if (fabs(new_width) < 1e-6) new_width = 1e-6; // not 0, as this would result in a nasty no-bbox object
@@ -710,7 +722,7 @@ Transformation::applyPageScale(Inkscape::Selection *selection)
             sp_item_scale_rel (item, scale);
         }
     } else {
-        boost::optional<Geom::Rect> bbox(selection->bounds());
+        Geom::OptRect bbox(selection->bounds());
         if (bbox) {
             Geom::Point center(bbox->midpoint()); // use rotation center?
             Geom::Scale scale (0,0);
@@ -741,7 +753,8 @@ Transformation::applyPageRotate(Inkscape::Selection *selection)
 {
     double angle = _scalar_rotate.getValue("deg");
 
-    if (prefs_get_int_attribute_limited ("dialogs.transformation", "applyseparately", 0, 0, 1) == 1) {
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    if (prefs->getBool("/dialogs/transformation/applyseparately")) {
         for (GSList const *l = selection->itemList(); l != NULL; l = l->next) {
             SPItem *item = SP_ITEM(l->data);
             sp_item_rotate_rel(item, Geom::Rotate (angle*M_PI/180.0));
@@ -760,7 +773,8 @@ Transformation::applyPageRotate(Inkscape::Selection *selection)
 void
 Transformation::applyPageSkew(Inkscape::Selection *selection)
 {
-    if (prefs_get_int_attribute_limited ("dialogs.transformation", "applyseparately", 0, 0, 1) == 1) {
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    if (prefs->getBool("/dialogs/transformation/applyseparately")) {
         for (GSList const *l = selection->itemList(); l != NULL; l = l->next) {
             SPItem *item = SP_ITEM(l->data);
 
@@ -777,7 +791,7 @@ Transformation::applyPageSkew(Inkscape::Selection *selection)
             } else { // absolute displacement
                 double skewX = _scalar_skew_horizontal.getValue("px");
                 double skewY = _scalar_skew_vertical.getValue("px");
-                boost::optional<Geom::Rect> bbox(sp_item_bbox_desktop(item));
+                Geom::OptRect bbox(sp_item_bbox_desktop(item));
                 if (bbox) {
                     double width = bbox->dimensions()[Geom::X];
                     double height = bbox->dimensions()[Geom::Y];
@@ -786,7 +800,7 @@ Transformation::applyPageSkew(Inkscape::Selection *selection)
             }
         }
     } else { // transform whole selection
-        boost::optional<Geom::Rect> bbox = selection->bounds();
+        Geom::OptRect bbox = selection->bounds();
         boost::optional<Geom::Point> center = selection->center();
 
         if ( bbox && center ) {
@@ -826,7 +840,7 @@ Transformation::applyPageTransform(Inkscape::Selection *selection)
     double e = _scalar_transform_e.getValue();
     double f = _scalar_transform_f.getValue();
 
-    NR::Matrix displayed(a, b, c, d, e, f);
+    Geom::Matrix displayed(a, b, c, d, e, f);
 
     if (_check_replace_matrix.get_active()) {
         for (GSList const *l = selection->itemList(); l != NULL; l = l->next) {
@@ -867,19 +881,21 @@ 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);
 
-    boost::optional<Geom::Rect> bbox = selection->bounds();
+    Geom::OptRect bbox = selection->bounds();
 
     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);
         }
     }
 
@@ -1009,7 +1025,7 @@ Transformation::onClear()
             _scalar_move_horizontal.setValue(0);
             _scalar_move_vertical.setValue(0);
         } else {
-            boost::optional<Geom::Rect> bbox = selection->bounds();
+            Geom::OptRect bbox = selection->bounds();
             if (bbox) {
                 _scalar_move_horizontal.setValue(bbox->min()[Geom::X], "px");
                 _scalar_move_vertical.setValue(bbox->min()[Geom::Y], "px");
@@ -1046,7 +1062,8 @@ Transformation::onClear()
 void
 Transformation::onApplySeparatelyToggled()
 {
-    prefs_set_int_attribute ("dialogs.transformation", "applyseparately", _check_apply_separately.get_active()? 1 : 0);
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    prefs->setBool("/dialogs/transformation/applyseparately", _check_apply_separately.get_active());
 }
 
 
@@ -1054,8 +1071,6 @@ Transformation::onApplySeparatelyToggled()
 } // namespace UI
 } // namespace Inkscape
 
-
-
 /*
   Local Variables:
   mode:c++