diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2015-03-11 14:01:37 +0000 |
|---|---|---|
| committer | tavmjong-free <tavmjong@free.fr> | 2015-03-11 14:01:37 +0000 |
| commit | e312688492eabdd9d4af9c6feadf3b1411f1541d (patch) | |
| tree | 0bb2d856a82fdb34bbdd0ccb77d7775e22ac7675 /src | |
| parent | packaging/macosx: follow-up to r13992 (forgot to add the new files for py-gob... (diff) | |
| download | inkscape-e312688492eabdd9d4af9c6feadf3b1411f1541d.tar.gz inkscape-e312688492eabdd9d4af9c6feadf3b1411f1541d.zip | |
Allow changing document scale (via changing viewBox). Start of GUI.
(bzr r13994)
Diffstat (limited to 'src')
| -rw-r--r-- | src/document.cpp | 24 | ||||
| -rw-r--r-- | src/document.h | 2 | ||||
| -rw-r--r-- | src/ui/dialog/document-properties.cpp | 5 | ||||
| -rw-r--r-- | src/ui/widget/page-sizer.cpp | 118 | ||||
| -rw-r--r-- | src/ui/widget/page-sizer.h | 19 |
5 files changed, 165 insertions, 3 deletions
diff --git a/src/document.cpp b/src/document.cpp index 2a50d00bd..62e2f5b46 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -611,7 +611,25 @@ Inkscape::Util::Unit const& SPDocument::getSVGUnit() const return nv ? nv->getSVGUnit() : *unit_table.getUnit("px"); } -/// Returns document scale as defined by width/height and viewBox (real world to user-units). +/// Sets document scale (by changing viewBox) +void SPDocument::setDocumentScale( double scaleX, double scaleY ) { + + root->viewBox = Geom::Rect::from_xywh( + root->viewBox.left(), + root->viewBox.top(), + root->width.computed * scaleX, + root->height.computed * scaleY ); + root->viewBox_set = true; + root->updateRepr(); +} + +/// Sets document scale (by changing viewBox, x and y scaling equal) +void SPDocument::setDocumentScale( double scale ) { + setDocumentScale( scale, scale ); +} + +/// Returns document scale as defined by width/height (in pixels) and viewBox (real world to +/// user-units). Geom::Scale SPDocument::getDocumentScale() const { Geom::Scale scale; @@ -660,10 +678,12 @@ void SPDocument::setWidthAndHeight(const Inkscape::Util::Quantity &width, const root->height.value = height.quantity; root->height.unit = (SVGLength::Unit) height.unit->svgUnit(); - if (root->viewBox_set && changeSize) + // viewBox scaled by relative change in page size (maintains document scale). + if (root->viewBox_set && changeSize) { root->viewBox.setMax(Geom::Point( root->viewBox.left() + (root->width.value / old_width_converted ) * root->viewBox.width(), root->viewBox.top() + (root->height.value / old_height_converted) * root->viewBox.height())); + } root->updateRepr(); } diff --git a/src/document.h b/src/document.h index a33b476cc..ed19d123b 100644 --- a/src/document.h +++ b/src/document.h @@ -242,6 +242,8 @@ public: SPDocument *doUnref(); Inkscape::Util::Unit const* getDisplayUnit() const; Inkscape::Util::Unit const& getSVGUnit() const; + void setDocumentScale( const double scaleX, const double scaleY ); + void setDocumentScale( const double scale ); Geom::Scale getDocumentScale() const; Inkscape::Util::Quantity getWidth() const; Inkscape::Util::Quantity getHeight() const; diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index f324f285d..c381ed755 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -1473,6 +1473,7 @@ void DocumentProperties::update() } _page_sizer.setDim(Inkscape::Util::Quantity(doc_w, doc_w_unit), Inkscape::Util::Quantity(doc_h, doc_h_unit)); _page_sizer.updateFitMarginsUI(nv->getRepr()); + _page_sizer.updateScaleUI(); //-----------------------------------------------------------guide page @@ -1655,6 +1656,8 @@ void DocumentProperties::onRemoveGrid() } /** Callback for document unit change. */ +/* This should not effect anything in the SVG tree (other than "inkscape:document-units"). + This should only effect values displayed in the GUI. */ void DocumentProperties::onDocUnitChange() { SPDocument *doc = SP_ACTIVE_DOCUMENT; @@ -1680,6 +1683,8 @@ void DocumentProperties::onDocUnitChange() os << doc_unit->abbr; repr->setAttribute("inkscape:document-units", os.str().c_str()); + _page_sizer.updateScaleUI(); + // Disable changing of SVG Units. The intent here is to change the units in the UI, not the units in SVG. // This code should be moved (and fixed) once we have an "SVG Units" setting that sets what units are used in SVG data. #if 0 diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp index 8c3b44bf5..afece6df2 100644 --- a/src/ui/widget/page-sizer.cpp +++ b/src/ui/widget/page-sizer.cpp @@ -26,6 +26,7 @@ #include <cmath> #include <string> #include <string.h> +#include <sstream> #include <vector> #include <glibmm/i18n.h> @@ -240,6 +241,8 @@ PageSizer::PageSizer(Registry & _wr) _marginRight( _("Ri_ght:"), _("Right margin"), "fit-margin-right", _wr), _marginBottom( _("Botto_m:"), _("Bottom margin"), "fit-margin-bottom", _wr), _lockMarginUpdate(false), + _scaleX(_("Scale _x:"), _("Scale X"), "scale-x", _wr), + _lockScaleUpdate(false), _widgetRegistry(&_wr) { // set precision of scalar entry boxes @@ -250,6 +253,8 @@ PageSizer::PageSizer(Registry & _wr) _marginLeft.setDigits(5); _marginRight.setDigits(5); _marginBottom.setDigits(5); + _scaleX.setDigits(5); + _scaleX.setRange( 0.00001, 100000 ); _wr.setUpdating (false); //# Set up the Paper Size combo box @@ -318,6 +323,7 @@ PageSizer::PageSizer(Registry & _wr) } _wr.setUpdating (false); + //## Set up custom size frame _customFrame.set_label(_("Custom size")); pack_start (_customFrame, false, false, 0); @@ -419,6 +425,34 @@ PageSizer::PageSizer(Registry & _wr) _fitPageButton.set_label(_("_Resize page to drawing or selection")); _fitPageButton.set_tooltip_text(_("Resize the page to fit the current selection, or the entire drawing if there is no selection")); + _scaleFrame.set_label(_("Scale")); + pack_start (_scaleFrame, false, false, 0); + _scaleFrame.add(_scaleTable); + + _scaleTable.set_border_width(4); + +#if WITH_GTKMM_3_0 + _scaleTable.set_row_spacing(4); + _scaleTable.set_column_spacing(4); + + _dimensionWidth.set_hexpand(); + _dimensionWidth.set_vexpand(); + _scaleTable.attach(_scaleX, 0, 0, 1, 1); + + _dimensionUnits.set_hexpand(); + _dimensionUnits.set_vexpand(); + _scaleTable.attach(_scaleLabel, 1, 0, 1, 1); +#else + _scaleTable.resize(2, 1); + _scaleTable.set_row_spacings(4); + _scaleTable.set_col_spacings(4); + _scaleTable.attach(_scaleX, 0,1, 0,1); + _scaleTable.attach(_scaleLabel, 1,2, 0,1); +#endif + + _wr.setUpdating (true); + updateScaleUI(); + _wr.setUpdating (false); } @@ -444,7 +478,7 @@ PageSizer::init () _changedh_connection = _dimensionHeight.signal_value_changed().connect (sigc::mem_fun (*this, &PageSizer::on_value_changed)); _changedu_connection = _dimensionUnits.getUnitMenu()->signal_changed().connect (sigc::mem_fun (*this, &PageSizer::on_units_changed)); _fitPageButton.signal_clicked().connect(sigc::mem_fun(*this, &PageSizer::fire_fit_canvas_to_selection_or_drawing)); - + _changeds_connection = _scaleX.signal_value_changed().connect (sigc::mem_fun (*this, &PageSizer::on_scale_changed)); show_all_children(); } @@ -512,6 +546,7 @@ PageSizer::setDim (Inkscape::Util::Quantity w, Inkscape::Util::Quantity h, bool _dimensionHeight.setUnit(h.unit->abbr); _dimensionHeight.setValue (h.quantity); + _paper_size_list_connection.unblock(); _landscape_connection.unblock(); _portrait_connection.unblock(); @@ -701,6 +736,61 @@ PageSizer::on_landscape() } } + +/** + * Update scale widgets + */ +void +PageSizer::updateScaleUI() +{ + + if (_lockScaleUpdate) { + return; + } + + static bool _called = false; + if (_called) { + return; + } + + _called = true; + + _changeds_connection.block(); + + SPDesktop *dt = SP_ACTIVE_DESKTOP; + if (dt) { + SPDocument *doc = dt->getDocument(); + Geom::Scale scale = doc->getDocumentScale(); + + SPNamedView *nv = dt->getNamedView(); + + std::stringstream ss; + ss << _("User units per ") << nv->display_units->abbr << "." ; + _scaleLabel.set_text( ss.str() ); + + double scaleX_inv = + Inkscape::Util::Quantity::convert( scale[Geom::X], "px", nv->display_units ); + if( scaleX_inv > 0 ) { + _scaleX.setValue(1.0/scaleX_inv); + } else { + // Should never happen + std::cerr << "PageSizer::updateScaleUI(): Invalid scale value: " << scaleX_inv << std::endl; + _scaleX.setValue(1.0); + } + + } else { + // Should never happen + std::cerr << "PageSizer::updateScaleUI(): No active desktop." << std::endl; + _scaleLabel.set_text( "Unknown scale" ); + } + + sleep( 0.1 ); + _changeds_connection.unblock(); + + _called = false; +} + + /** * Callback for the dimension widgets */ @@ -722,6 +812,32 @@ PageSizer::on_units_changed() true, false); } +/** + * Callback for scale widgets + */ +void +PageSizer::on_scale_changed() +{ + if (_widgetRegistry->isUpdating()) return; + + double value = _scaleX.getValue(); + if( value > 0 ) { + + SPDesktop *dt = SP_ACTIVE_DESKTOP; + if (dt) { + SPDocument *doc = dt->getDocument(); + SPNamedView *nv = dt->getNamedView(); + + double scaleX_inv = Inkscape::Util::Quantity(1.0/value, nv->display_units ).value("px"); + + _lockScaleUpdate = true; + doc->setDocumentScale( 1.0/scaleX_inv ); + _lockScaleUpdate = false; + DocumentUndo::done(doc, SP_VERB_NONE, _("Set page scale")); + } + } +} + } // namespace Widget } // namespace UI } // namespace Inkscape diff --git a/src/ui/widget/page-sizer.h b/src/ui/widget/page-sizer.h index bed117e5a..f9a72d9f3 100644 --- a/src/ui/widget/page-sizer.h +++ b/src/ui/widget/page-sizer.h @@ -169,6 +169,11 @@ public: */ void updateFitMarginsUI(Inkscape::XML::Node *nv_repr); + /** + * Updates the scale widgets. (Just changes the values of the ui widgets.) + */ + void updateScaleUI(); + protected: /** @@ -250,12 +255,26 @@ protected: Gtk::Button _fitPageButton; bool _lockMarginUpdate; + // Document scale + Gtk::Frame _scaleFrame; +#if WITH_GTKMM_3_0 + Gtk::Grid _scaleTable; +#else + Gtk::Table _scaleTable; +#endif + + Gtk::Label _scaleLabel; + RegisteredScalar _scaleX; + bool _lockScaleUpdate; + //callback void on_value_changed(); void on_units_changed(); + void on_scale_changed(); sigc::connection _changedw_connection; sigc::connection _changedh_connection; sigc::connection _changedu_connection; + sigc::connection _changeds_connection; Registry *_widgetRegistry; |
