summaryrefslogtreecommitdiffstats
path: root/src/ui/widget/page-sizer.cpp
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2015-03-11 14:01:37 +0000
committertavmjong-free <tavmjong@free.fr>2015-03-11 14:01:37 +0000
commite312688492eabdd9d4af9c6feadf3b1411f1541d (patch)
tree0bb2d856a82fdb34bbdd0ccb77d7775e22ac7675 /src/ui/widget/page-sizer.cpp
parentpackaging/macosx: follow-up to r13992 (forgot to add the new files for py-gob... (diff)
downloadinkscape-e312688492eabdd9d4af9c6feadf3b1411f1541d.tar.gz
inkscape-e312688492eabdd9d4af9c6feadf3b1411f1541d.zip
Allow changing document scale (via changing viewBox). Start of GUI.
(bzr r13994)
Diffstat (limited to 'src/ui/widget/page-sizer.cpp')
-rw-r--r--src/ui/widget/page-sizer.cpp118
1 files changed, 117 insertions, 1 deletions
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