From: Alex Leone Date: Tue, 1 Jun 2010 00:06:11 +0000 (-0700) Subject: Makes the "Fit Page to Selection" margin options load from the opened file. (Bug... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=e3d18ccd670462801d4938107a72ed6855c469b9;p=inkscape.git Makes the "Fit Page to Selection" margin options load from the opened file. (Bug #499942) --- diff --git a/src/document.cpp b/src/document.cpp index 101c54e30..eff6d6e81 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -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); diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index 86baa85cd..33fdf8327 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -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 diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp index e604a24ec..05de86308 100644 --- a/src/ui/widget/page-sizer.cpp +++ b/src/ui/widget/page-sizer.cpp @@ -18,25 +18,26 @@ # include #endif -#include -#include -#include - #include #include -#include "ui/widget/button.h" - -#include "ui/widget/scalar-unit.h" +#include +#include +#include -#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); + } } } diff --git a/src/ui/widget/page-sizer.h b/src/ui/widget/page-sizer.h index 718eb95b5..7c2048534 100644 --- a/src/ui/widget/page-sizer.h +++ b/src/ui/widget/page-sizer.h @@ -14,10 +14,11 @@ #include #include + +#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: