summaryrefslogtreecommitdiffstats
path: root/src/ui/widget
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2013-09-20 17:43:57 +0000
committerJabiertxof <jtx@jtx.marker.es>2013-09-20 17:43:57 +0000
commit0a836d1870bb87d5be3e4d900718f903371c8e56 (patch)
tree7d218dc0e9d81e2f7d3eddcefad9640769dc89b3 /src/ui/widget
parentCompact of SVG icons whith the help of ~suv and Martin Owens (diff)
parentMerge Google Summer of Code unit improvement. (diff)
downloadinkscape-0a836d1870bb87d5be3e4d900718f903371c8e56.tar.gz
inkscape-0a836d1870bb87d5be3e4d900718f903371c8e56.zip
Update to trunk
(bzr r11950.1.146)
Diffstat (limited to 'src/ui/widget')
-rw-r--r--src/ui/widget/page-sizer.cpp62
-rw-r--r--src/ui/widget/page-sizer.h8
-rw-r--r--src/ui/widget/spinbutton.cpp18
-rw-r--r--src/ui/widget/spinbutton.h5
4 files changed, 58 insertions, 35 deletions
diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp
index 8287452d7..051937c43 100644
--- a/src/ui/widget/page-sizer.cpp
+++ b/src/ui/widget/page-sizer.cpp
@@ -442,6 +442,7 @@ PageSizer::init ()
_portrait_connection = _portraitButton.signal_toggled().connect (sigc::mem_fun (*this, &PageSizer::on_portrait));
_changedw_connection = _dimensionWidth.signal_value_changed().connect (sigc::mem_fun (*this, &PageSizer::on_value_changed));
_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));
show_all_children();
@@ -454,11 +455,11 @@ PageSizer::init ()
* 'changeList' is true, then adjust the paperSizeList to show the closest
* standard page size.
*
- * \param w, h given in px
+ * \param w, h
* \param changeList whether to modify the paper size list
*/
void
-PageSizer::setDim (double w, double h, bool changeList)
+PageSizer::setDim (Inkscape::Util::Quantity w, Inkscape::Util::Quantity h, bool changeList)
{
static bool _called = false;
if (_called) {
@@ -475,12 +476,12 @@ PageSizer::setDim (double w, double h, bool changeList)
if (SP_ACTIVE_DESKTOP && !_widgetRegistry->isUpdating()) {
SPDocument *doc = sp_desktop_document(SP_ACTIVE_DESKTOP);
- double const old_height = doc->getHeight();
- doc->setWidth (Inkscape::Util::Quantity(w, "px"));
- doc->setHeight (Inkscape::Util::Quantity(h, "px"));
+ Inkscape::Util::Quantity const old_height = doc->getHeight();
+ doc->setWidth (w);
+ doc->setHeight (h);
// The origin for the user is in the lower left corner; this point should remain stationary when
// changing the page size. The SVG's origin however is in the upper left corner, so we must compensate for this
- Geom::Translate const vert_offset(Geom::Point(0, (old_height - h)));
+ Geom::Translate const vert_offset(Geom::Point(0, (old_height.value("px") - h.value("px"))));
doc->getRoot()->translateChildItems(vert_offset);
DocumentUndo::done(doc, SP_VERB_NONE, _("Set page size"));
}
@@ -503,9 +504,10 @@ PageSizer::setDim (double w, double h, bool changeList)
_paperSizeListSelection->select(row);
}
- Unit const& unit = _dimensionUnits.getUnit();
- _dimensionWidth.setValue (w / unit.factor);
- _dimensionHeight.setValue (h / unit.factor);
+ _dimensionWidth.setUnit(w.unit->abbr);
+ _dimensionWidth.setValue (w.quantity);
+ _dimensionHeight.setUnit(h.unit->abbr);
+ _dimensionHeight.setValue (h.quantity);
_paper_size_list_connection.unblock();
_landscape_connection.unblock();
@@ -547,12 +549,12 @@ PageSizer::updateFitMarginsUI(Inkscape::XML::Node *nv_repr)
* paperSizeListStore->children().end() if no such paper exists.
*/
Gtk::ListStore::iterator
-PageSizer::find_paper_size (double w, double h) const
+PageSizer::find_paper_size (Inkscape::Util::Quantity w, Inkscape::Util::Quantity h) const
{
- double smaller = w;
- double larger = h;
+ double smaller = w.quantity;
+ double larger = h.quantity;
if ( h < w ) {
- smaller = h; larger = w;
+ smaller = h.quantity; larger = w.quantity;
}
g_return_val_if_fail(smaller <= larger, _paperSizeListStore->children().end());
@@ -562,8 +564,8 @@ PageSizer::find_paper_size (double w, double h) const
iter != _paperSizeTable.end() ; ++iter) {
PaperSize paper = iter->second;
Inkscape::Util::Unit const &i_unit = paper.unit;
- double smallX = Inkscape::Util::Quantity::convert(paper.smaller, i_unit, "px");
- double largeX = Inkscape::Util::Quantity::convert(paper.larger, i_unit, "px");
+ double smallX = Inkscape::Util::Quantity::convert(paper.smaller, i_unit, *w.unit);
+ double largeX = Inkscape::Util::Quantity::convert(paper.larger, i_unit, *w.unit);
g_return_val_if_fail(smallX <= largeX, _paperSizeListStore->children().end());
@@ -643,8 +645,8 @@ PageSizer::on_paper_size_list_changed()
return;
}
PaperSize paper = piter->second;
- double w = paper.smaller;
- double h = paper.larger;
+ Inkscape::Util::Quantity w = Inkscape::Util::Quantity(paper.smaller, paper.unit);
+ Inkscape::Util::Quantity h = Inkscape::Util::Quantity(paper.larger, paper.unit);
if (std::find(lscape_papers.begin(), lscape_papers.end(), paper.name.c_str()) != lscape_papers.end()) {
// enforce landscape mode if this is desired for the given page format
@@ -654,9 +656,6 @@ PageSizer::on_paper_size_list_changed()
_landscape = _landscapeButton.get_active();
}
- w = Inkscape::Util::Quantity::convert(w, paper.unit, "px");
- h = Inkscape::Util::Quantity::convert(h, paper.unit, "px");
-
if (_landscape)
setDim (h, w, false);
else
@@ -673,8 +672,8 @@ PageSizer::on_portrait()
{
if (!_portraitButton.get_active())
return;
- double w = _dimensionWidth.getValue ("px");
- double h = _dimensionHeight.getValue ("px");
+ Inkscape::Util::Quantity w = Inkscape::Util::Quantity(_dimensionWidth.getValue(""), _dimensionWidth.getUnit());
+ Inkscape::Util::Quantity h = Inkscape::Util::Quantity(_dimensionHeight.getValue(""), _dimensionHeight.getUnit());
if (h < w) {
setDim (h, w);
}
@@ -689,8 +688,8 @@ PageSizer::on_landscape()
{
if (!_landscapeButton.get_active())
return;
- double w = _dimensionWidth.getValue ("px");
- double h = _dimensionHeight.getValue ("px");
+ Inkscape::Util::Quantity w = Inkscape::Util::Quantity(_dimensionWidth.getValue(""), _dimensionWidth.getUnit());
+ Inkscape::Util::Quantity h = Inkscape::Util::Quantity(_dimensionHeight.getValue(""), _dimensionHeight.getUnit());
if (w < h) {
setDim (h, w);
}
@@ -703,11 +702,18 @@ void
PageSizer::on_value_changed()
{
if (_widgetRegistry->isUpdating()) return;
-
- setDim (_dimensionWidth.getValue("px"),
- _dimensionHeight.getValue("px"));
+ if (_unit != _dimensionUnits.getUnit().abbr) return;
+ setDim (Inkscape::Util::Quantity(_dimensionWidth.getValue(""), _dimensionUnits.getUnit()),
+ Inkscape::Util::Quantity(_dimensionHeight.getValue(""), _dimensionUnits.getUnit()));
+}
+void
+PageSizer::on_units_changed()
+{
+ if (_widgetRegistry->isUpdating()) return;
+ _unit = _dimensionUnits.getUnit().abbr;
+ setDim (Inkscape::Util::Quantity(_dimensionWidth.getValue(""), _dimensionUnits.getUnit()),
+ Inkscape::Util::Quantity(_dimensionHeight.getValue(""), _dimensionUnits.getUnit()));
}
-
} // namespace Widget
} // namespace UI
diff --git a/src/ui/widget/page-sizer.h b/src/ui/widget/page-sizer.h
index 34ed7592d..95836a005 100644
--- a/src/ui/widget/page-sizer.h
+++ b/src/ui/widget/page-sizer.h
@@ -161,7 +161,7 @@ public:
* Set the page size to the given dimensions. If 'changeList' is
* true, then reset the paper size list to the closest match
*/
- void setDim (double w, double h, bool changeList=true);
+ void setDim (Inkscape::Util::Quantity w, Inkscape::Util::Quantity h, bool changeList=true);
/**
* Updates the scalar widgets for the fit margins. (Just changes the value
@@ -179,7 +179,7 @@ protected:
/**
* Find the closest standard paper size in the table, to the
*/
- Gtk::ListStore::iterator find_paper_size (double w, double h) const;
+ Gtk::ListStore::iterator find_paper_size (Inkscape::Util::Quantity w, Inkscape::Util::Quantity h) const;
void fire_fit_canvas_to_selection_or_drawing();
@@ -252,13 +252,17 @@ protected:
//callback
void on_value_changed();
+ void on_units_changed();
sigc::connection _changedw_connection;
sigc::connection _changedh_connection;
+ sigc::connection _changedu_connection;
Registry *_widgetRegistry;
//### state - whether we are currently landscape or portrait
bool _landscape;
+
+ Glib::ustring _unit;
};
diff --git a/src/ui/widget/spinbutton.cpp b/src/ui/widget/spinbutton.cpp
index c107979a8..62c17f821 100644
--- a/src/ui/widget/spinbutton.cpp
+++ b/src/ui/widget/spinbutton.cpp
@@ -14,6 +14,7 @@
#include "spinbutton.h"
#include "unit-menu.h"
+#include "unit-tracker.h"
#include "util/expression-evaluator.h"
#include "event-context.h"
@@ -32,16 +33,23 @@ SpinButton::connect_signals() {
int SpinButton::on_input(double* newvalue)
{
try {
- Inkscape::Util::GimpEevlQuantity result;
- if (_unit_menu) {
- Unit unit = _unit_menu->getUnit();
- result = Inkscape::Util::gimp_eevl_evaluate (get_text().c_str(), &unit);
+ Inkscape::Util::EvaluatorQuantity result;
+ if (_unit_menu || _unit_tracker) {
+ Unit unit;
+ if (_unit_menu) {
+ unit = _unit_menu->getUnit();
+ } else {
+ unit = _unit_tracker->getActiveUnit();
+ }
+ Inkscape::Util::ExpressionEvaluator eval = Inkscape::Util::ExpressionEvaluator(get_text().c_str(), &unit);
+ result = eval.evaluate();
// check if output dimension corresponds to input unit
if (result.dimension != (unit.isAbsolute() ? 1 : 0) ) {
throw Inkscape::Util::EvaluatorException("Input dimensions do not match with parameter dimensions.","");
}
} else {
- result = Inkscape::Util::gimp_eevl_evaluate (get_text().c_str(), NULL);
+ Inkscape::Util::ExpressionEvaluator eval = Inkscape::Util::ExpressionEvaluator(get_text().c_str(), NULL);
+ result = eval.evaluate();
}
*newvalue = result.value;
diff --git a/src/ui/widget/spinbutton.h b/src/ui/widget/spinbutton.h
index fe5d699e7..c772fe2a2 100644
--- a/src/ui/widget/spinbutton.h
+++ b/src/ui/widget/spinbutton.h
@@ -25,6 +25,7 @@ namespace UI {
namespace Widget {
class UnitMenu;
+class UnitTracker;
/**
* SpinButton widget, that allows entry of simple math expressions (also units, when linked with UnitMenu),
@@ -50,14 +51,18 @@ public:
_unit_menu(NULL)
{
connect_signals();
+ _unit_tracker = NULL;
};
virtual ~SpinButton() {};
void setUnitMenu(UnitMenu* unit_menu) { _unit_menu = unit_menu; };
+
+ void addUnitTracker(UnitTracker* ut) { _unit_tracker = ut; };
protected:
UnitMenu *_unit_menu; /// Linked unit menu for unit conversion in entered expressions.
+ UnitTracker *_unit_tracker; // Linked unit tracker for unit conversion in entered expressions.
void connect_signals();