Code

Makes the "Fit Page to Selection" margin options load from the opened file. (Bug...
authorAlex Leone <acleone~AT~gmail.com>
Tue, 1 Jun 2010 00:06:11 +0000 (17:06 -0700)
committerAlex Leone <acleone~AT~gmail.com>
Tue, 1 Jun 2010 00:06:11 +0000 (17:06 -0700)
src/document.cpp
src/ui/dialog/document-properties.cpp
src/ui/widget/page-sizer.cpp
src/ui/widget/page-sizer.h

index 101c54e30b687d38160ac0d9e2c55d4d0227e93a..eff6d6e818b86f9db51ef9a8e3f087e820deb9bf 100644 (file)
@@ -682,7 +682,7 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins)
                 margin_units = sp_unit_get_by_abbreviation(units_abbr);
             }
             if (margin_units == NULL) {
-                margin_units = &sp_unit_get_by_id(SP_UNIT_PX);
+                margin_units = &px;
             }
             margin_top = getMarginLength(nv_repr, "fit-margin-top",
                                          margin_units, &px, w, h, false);
index 86baa85cd973489a5a8dd8251327114e15c4c97f..33fdf8327932f5c5fdddd93cfdc6a04796df2fdf 100644 (file)
@@ -825,6 +825,7 @@ DocumentProperties::update()
     double const doc_w_px = sp_document_width(sp_desktop_document(dt));
     double const doc_h_px = sp_document_height(sp_desktop_document(dt));
     _page_sizer.setDim (doc_w_px, doc_h_px);
+    _page_sizer.updateFitMarginsUI(SP_OBJECT_REPR(nv));
 
     //-----------------------------------------------------------guide page
 
index e604a24ecc387cca3c7c2f952871ead081d8ffc0..05de86308fc666ac3449af601b15339fa8638345 100644 (file)
 # include <config.h>
 #endif
 
-#include <string.h>
-#include <vector>
-#include <string>
-
 #include <cmath>
 #include <gtkmm.h>
-#include "ui/widget/button.h"
-
-#include "ui/widget/scalar-unit.h"
+#include <string>
+#include <string.h>
+#include <vector>
 
-#include "helper/units.h"
-#include "inkscape.h"
-#include "verbs.h"
 #include "desktop-handles.h"
 #include "document.h"
 #include "desktop.h"
-#include "page-sizer.h"
 #include "helper/action.h"
+#include "helper/units.h"
+#include "inkscape.h"
+#include "page-sizer.h"
+#include "sp-namedview.h"
 #include "sp-root.h"
+#include "ui/widget/button.h"
+#include "ui/widget/scalar-unit.h"
+#include "verbs.h"
+#include "xml/node.h"
+#include "xml/repr.h"
 
 using std::pair;
 
@@ -320,11 +321,11 @@ PageSizer::PageSizer(Registry & _wr)
     _marginTable.set_border_width(4);
     _marginTable.set_row_spacings(4);
     _marginTable.set_col_spacings(4);
-    _marginTable.attach(_fitPageButtonAlign, 0,2, 0,1);
-    _marginTable.attach(_marginTopAlign,     0,2, 1,2);
-    _marginTable.attach(_marginLeftAlign,    0,1, 2,3);
-    _marginTable.attach(_marginRightAlign,   1,2, 2,3);
-    _marginTable.attach(_marginBottomAlign,  0,2, 3,4);
+    _marginTable.attach(_marginTopAlign,     0,2, 0,1);
+    _marginTable.attach(_marginLeftAlign,    0,1, 1,2);
+    _marginTable.attach(_marginRightAlign,   1,2, 1,2);
+    _marginTable.attach(_marginBottomAlign,  0,2, 2,3);
+    _marginTable.attach(_fitPageButtonAlign, 0,2, 3,4);
     
     _marginTopAlign.set(0.5, 0.5, 0.0, 1.0);
     _marginTopAlign.add(_marginTop);
@@ -437,6 +438,28 @@ PageSizer::setDim (double w, double h, bool changeList)
     _called = false;
 }
 
+/**
+ * Updates the scalar widgets for the fit margins.  (Just changes the value
+ * of the ui widgets to match the xml).
+ */
+void 
+PageSizer::updateFitMarginsUI(Inkscape::XML::Node *nv_repr)
+{
+    double value = 0.0;
+    if (sp_repr_get_double(nv_repr, "fit-margin-top", &value)) {
+        _marginTop.setValue(value);
+    }
+    if (sp_repr_get_double(nv_repr, "fit-margin-left", &value)) {
+        _marginLeft.setValue(value);
+    }
+    if (sp_repr_get_double(nv_repr, "fit-margin-right", &value)) {
+        _marginRight.setValue(value);
+    }
+    if (sp_repr_get_double(nv_repr, "fit-margin-bottom", &value)) {
+        _marginBottom.setValue(value);
+    }
+}
+
 
 /**
  * Returns an iterator pointing to a row in paperSizeListStore which
@@ -492,11 +515,23 @@ PageSizer::fire_fit_canvas_to_selection_or_drawing()
     if (!dt) {
         return;
     }
+    SPDocument *doc;
+    SPNamedView *nv;
+    Inkscape::XML::Node *nv_repr;
+    if ((doc = sp_desktop_document(SP_ACTIVE_DESKTOP))
+            && (nv = sp_document_namedview(doc, 0))
+            && (nv_repr = SP_OBJECT_REPR(nv))) {
+        sp_repr_set_svg_double(nv_repr, "fit-margin-top", _marginTop.getValue());
+        sp_repr_set_svg_double(nv_repr, "fit-margin-left", _marginLeft.getValue());
+        sp_repr_set_svg_double(nv_repr, "fit-margin-right", _marginRight.getValue());
+        sp_repr_set_svg_double(nv_repr, "fit-margin-bottom", _marginBottom.getValue());
+    }
     Verb *verb = Verb::get( SP_VERB_FIT_CANVAS_TO_SELECTION_OR_DRAWING );
     if (verb) {
         SPAction *action = verb->get_action(dt);
-        if (action)
+        if (action) {
             sp_action_perform(action, NULL);
+        }
     }
 }
 
index 718eb95b592449898c134643514f0a50fcd32034..7c20485345c2968166e794a3a257dbcc6175269a 100644 (file)
 
 #include <gtkmm.h>
 #include <sigc++/sigc++.h>
+
+#include "helper/units.h"
 #include "ui/widget/registry.h"
 #include "ui/widget/registered-widget.h"
-#include "helper/units.h"
-
+#include "xml/node.h"
 
 namespace Inkscape {    
 namespace UI {
@@ -141,6 +142,12 @@ public:
      * true, then reset the paper size list to the closest match
      */
     void setDim (double w, double h, bool changeList=true);
+    
+    /**
+     * Updates the scalar widgets for the fit margins.  (Just changes the value
+     * of the ui widgets to match the xml).
+     */
+    void updateFitMarginsUI(Inkscape::XML::Node *nv_repr);
  
 protected: