summaryrefslogtreecommitdiffstats
path: root/src/ui/widget
diff options
context:
space:
mode:
authorSebastian Wüst <sebi@timewaster.de>2013-10-20 15:32:08 +0000
committerSebastian Wüst <sebi@timewaster.de>2013-10-20 15:32:08 +0000
commit82908f949129e1fcbf62002799ee7b1b77986eed (patch)
treec02098dd7720cdf424f2793ecd3ddac2ea86b969 /src/ui/widget
parentchanged text (diff)
parentFix build errors with clang 3.3 and c++11 enabled. (diff)
downloadinkscape-82908f949129e1fcbf62002799ee7b1b77986eed.tar.gz
inkscape-82908f949129e1fcbf62002799ee7b1b77986eed.zip
merge from trunk
(bzr r12417.1.24)
Diffstat (limited to 'src/ui/widget')
-rw-r--r--src/ui/widget/Makefile_insert4
-rw-r--r--src/ui/widget/color-preview.cpp11
-rw-r--r--src/ui/widget/page-sizer.cpp220
-rw-r--r--src/ui/widget/page-sizer.h16
-rw-r--r--src/ui/widget/preferences-widget.cpp2
-rw-r--r--src/ui/widget/registered-widget.cpp5
-rw-r--r--src/ui/widget/registered-widget.h6
-rw-r--r--src/ui/widget/rendering-options.cpp6
-rw-r--r--src/ui/widget/scalar-unit.cpp13
-rw-r--r--src/ui/widget/scalar-unit.h2
-rw-r--r--src/ui/widget/selected-style.cpp47
-rw-r--r--src/ui/widget/selected-style.h11
-rw-r--r--src/ui/widget/spinbutton.cpp24
-rw-r--r--src/ui/widget/spinbutton.h15
-rw-r--r--src/ui/widget/style-swatch.cpp10
-rw-r--r--src/ui/widget/style-swatch.h8
-rw-r--r--src/ui/widget/unit-menu.cpp45
-rw-r--r--src/ui/widget/unit-menu.h5
-rw-r--r--src/ui/widget/unit-tracker.cpp264
-rw-r--r--src/ui/widget/unit-tracker.h74
20 files changed, 575 insertions, 213 deletions
diff --git a/src/ui/widget/Makefile_insert b/src/ui/widget/Makefile_insert
index 2de954674..710b95c2b 100644
--- a/src/ui/widget/Makefile_insert
+++ b/src/ui/widget/Makefile_insert
@@ -79,5 +79,7 @@ ink_common_sources += \
ui/widget/tolerance-slider.cpp \
ui/widget/tolerance-slider.h \
ui/widget/unit-menu.cpp \
- ui/widget/unit-menu.h
+ ui/widget/unit-menu.h \
+ ui/widget/unit-tracker.h \
+ ui/widget/unit-tracker.cpp
diff --git a/src/ui/widget/color-preview.cpp b/src/ui/widget/color-preview.cpp
index 4b4a7b738..5bcd16528 100644
--- a/src/ui/widget/color-preview.cpp
+++ b/src/ui/widget/color-preview.cpp
@@ -73,9 +73,9 @@ ColorPreview::on_expose_event (GdkEventExpose *event)
if (get_is_drawable())
{
Cairo::RefPtr<Cairo::Context> cr = get_window()->create_cairo_context();
- cr->rectangle(event->area.x, event->area.y,
+ cr->rectangle(event->area.x, event->area.y,
event->area.width, event->area.height);
- cr->clip();
+ cr->clip();
result = on_draw(cr);
}
@@ -176,12 +176,7 @@ ColorPreview::toPixbuf (int width, int height)
cairo_destroy(ct);
cairo_surface_flush(s);
- GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data( cairo_image_surface_get_data(s),
- GDK_COLORSPACE_RGB, TRUE, 8,
- width, height, cairo_image_surface_get_stride(s),
- ink_cairo_pixbuf_cleanup, s);
- convert_pixbuf_argb32_to_normal(pixbuf);
-
+ GdkPixbuf* pixbuf = ink_pixbuf_create_from_cairo_surface(s);
return pixbuf;
}
diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp
index 988c4e5de..b13567adb 100644
--- a/src/ui/widget/page-sizer.cpp
+++ b/src/ui/widget/page-sizer.cpp
@@ -37,7 +37,7 @@
#include "desktop.h"
#include "helper/action.h"
#include "helper/action-context.h"
-#include "helper/units.h"
+#include "util/units.h"
#include "inkscape.h"
#include "sp-namedview.h"
#include "sp-root.h"
@@ -48,6 +48,7 @@
#include "xml/repr.h"
using std::pair;
+using Inkscape::Util::unit_table;
namespace Inkscape {
namespace UI {
@@ -96,7 +97,7 @@ struct PaperSizeRec {
char const * const name; //name
double const smaller; //lesser dimension
double const larger; //greater dimension
- SPUnitId const unit; //units
+ Glib::ustring const unit; //units
};
// list of page formats that should be in landscape automatically
@@ -114,31 +115,31 @@ fill_landscape_papers() {
}
static PaperSizeRec const inkscape_papers[] = {
- { "A4", 210, 297, SP_UNIT_MM },
- { "US Letter", 8.5, 11, SP_UNIT_IN },
- { "US Legal", 8.5, 14, SP_UNIT_IN },
- { "US Executive", 7.25, 10.5, SP_UNIT_IN },
- { "A0", 841, 1189, SP_UNIT_MM },
- { "A1", 594, 841, SP_UNIT_MM },
- { "A2", 420, 594, SP_UNIT_MM },
- { "A3", 297, 420, SP_UNIT_MM },
- { "A5", 148, 210, SP_UNIT_MM },
- { "A6", 105, 148, SP_UNIT_MM },
- { "A7", 74, 105, SP_UNIT_MM },
- { "A8", 52, 74, SP_UNIT_MM },
- { "A9", 37, 52, SP_UNIT_MM },
- { "A10", 26, 37, SP_UNIT_MM },
- { "B0", 1000, 1414, SP_UNIT_MM },
- { "B1", 707, 1000, SP_UNIT_MM },
- { "B2", 500, 707, SP_UNIT_MM },
- { "B3", 353, 500, SP_UNIT_MM },
- { "B4", 250, 353, SP_UNIT_MM },
- { "B5", 176, 250, SP_UNIT_MM },
- { "B6", 125, 176, SP_UNIT_MM },
- { "B7", 88, 125, SP_UNIT_MM },
- { "B8", 62, 88, SP_UNIT_MM },
- { "B9", 44, 62, SP_UNIT_MM },
- { "B10", 31, 44, SP_UNIT_MM },
+ { "A4", 210, 297, "mm" },
+ { "US Letter", 8.5, 11, "in" },
+ { "US Legal", 8.5, 14, "in" },
+ { "US Executive", 7.25, 10.5, "in" },
+ { "A0", 841, 1189, "mm" },
+ { "A1", 594, 841, "mm" },
+ { "A2", 420, 594, "mm" },
+ { "A3", 297, 420, "mm" },
+ { "A5", 148, 210, "mm" },
+ { "A6", 105, 148, "mm" },
+ { "A7", 74, 105, "mm" },
+ { "A8", 52, 74, "mm" },
+ { "A9", 37, 52, "mm" },
+ { "A10", 26, 37, "mm" },
+ { "B0", 1000, 1414, "mm" },
+ { "B1", 707, 1000, "mm" },
+ { "B2", 500, 707, "mm" },
+ { "B3", 353, 500, "mm" },
+ { "B4", 250, 353, "mm" },
+ { "B5", 176, 250, "mm" },
+ { "B6", 125, 176, "mm" },
+ { "B7", 88, 125, "mm" },
+ { "B8", 62, 88, "mm" },
+ { "B9", 44, 62, "mm" },
+ { "B10", 31, 44, "mm" },
@@ -150,63 +151,63 @@ static PaperSizeRec const inkscape_papers[] = {
don't know what D and E series are used for.
*/
- { "C0", 917, 1297, SP_UNIT_MM },
- { "C1", 648, 917, SP_UNIT_MM },
- { "C2", 458, 648, SP_UNIT_MM },
- { "C3", 324, 458, SP_UNIT_MM },
- { "C4", 229, 324, SP_UNIT_MM },
- { "C5", 162, 229, SP_UNIT_MM },
- { "C6", 114, 162, SP_UNIT_MM },
- { "C7", 81, 114, SP_UNIT_MM },
- { "C8", 57, 81, SP_UNIT_MM },
- { "C9", 40, 57, SP_UNIT_MM },
- { "C10", 28, 40, SP_UNIT_MM },
- { "D1", 545, 771, SP_UNIT_MM },
- { "D2", 385, 545, SP_UNIT_MM },
- { "D3", 272, 385, SP_UNIT_MM },
- { "D4", 192, 272, SP_UNIT_MM },
- { "D5", 136, 192, SP_UNIT_MM },
- { "D6", 96, 136, SP_UNIT_MM },
- { "D7", 68, 96, SP_UNIT_MM },
- { "E3", 400, 560, SP_UNIT_MM },
- { "E4", 280, 400, SP_UNIT_MM },
- { "E5", 200, 280, SP_UNIT_MM },
- { "E6", 140, 200, SP_UNIT_MM },
+ { "C0", 917, 1297, "mm" },
+ { "C1", 648, 917, "mm" },
+ { "C2", 458, 648, "mm" },
+ { "C3", 324, 458, "mm" },
+ { "C4", 229, 324, "mm" },
+ { "C5", 162, 229, "mm" },
+ { "C6", 114, 162, "mm" },
+ { "C7", 81, 114, "mm" },
+ { "C8", 57, 81, "mm" },
+ { "C9", 40, 57, "mm" },
+ { "C10", 28, 40, "mm" },
+ { "D1", 545, 771, "mm" },
+ { "D2", 385, 545, "mm" },
+ { "D3", 272, 385, "mm" },
+ { "D4", 192, 272, "mm" },
+ { "D5", 136, 192, "mm" },
+ { "D6", 96, 136, "mm" },
+ { "D7", 68, 96, "mm" },
+ { "E3", 400, 560, "mm" },
+ { "E4", 280, 400, "mm" },
+ { "E5", 200, 280, "mm" },
+ { "E6", 140, 200, "mm" },
//#endif
- { "CSE", 462, 649, SP_UNIT_PT },
- { "US #10 Envelope", 4.125, 9.5, SP_UNIT_IN },
+ { "CSE", 462, 649, "pt" },
+ { "US #10 Envelope", 4.125, 9.5, "in" },
/* See http://www.hbp.com/content/PCR_envelopes.cfm for a much larger list of US envelope
sizes. */
- { "DL Envelope", 110, 220, SP_UNIT_MM },
- { "Ledger/Tabloid", 11, 17, SP_UNIT_IN },
+ { "DL Envelope", 110, 220, "mm" },
+ { "Ledger/Tabloid", 11, 17, "in" },
/* Note that `Folio' (used in QPrinter/KPrinter) is deliberately absent from this list, as it
means different sizes to different people: different people may expect the width to be
either 8, 8.25 or 8.5 inches, and the height to be either 13 or 13.5 inches, even
restricting our interpretation to foolscap folio. If you wish to introduce a folio-like
page size to the list, then please consider using a name more specific than just `Folio' or
`Foolscap Folio'. */
- { "Banner 468x60", 60, 468, SP_UNIT_PX },
- { "Icon 16x16", 16, 16, SP_UNIT_PX },
- { "Icon 32x32", 32, 32, SP_UNIT_PX },
- { "Icon 48x48", 48, 48, SP_UNIT_PX },
+ { "Banner 468x60", 60, 468, "px" },
+ { "Icon 16x16", 16, 16, "px" },
+ { "Icon 32x32", 32, 32, "px" },
+ { "Icon 48x48", 48, 48, "px" },
/* business cards */
- { "Business Card (ISO 7810)", 53.98, 85.60, SP_UNIT_MM },
- { "Business Card (US)", 2, 3.5, SP_UNIT_IN },
- { "Business Card (Europe)", 55, 85, SP_UNIT_MM },
- { "Business Card (Aus/NZ)", 55, 90, SP_UNIT_MM },
+ { "Business Card (ISO 7810)", 53.98, 85.60, "mm" },
+ { "Business Card (US)", 2, 3.5, "in" },
+ { "Business Card (Europe)", 55, 85, "mm" },
+ { "Business Card (Aus/NZ)", 55, 90, "mm" },
// Start Arch Series List
- { "Arch A", 9, 12, SP_UNIT_IN }, // 229 x 305 mm
- { "Arch B", 12, 18, SP_UNIT_IN }, // 305 x 457 mm
- { "Arch C", 18, 24, SP_UNIT_IN }, // 457 x 610 mm
- { "Arch D", 24, 36, SP_UNIT_IN }, // 610 x 914 mm
- { "Arch E", 36, 48, SP_UNIT_IN }, // 914 x 1219 mm
- { "Arch E1", 30, 42, SP_UNIT_IN }, // 762 x 1067 mm
+ { "Arch A", 9, 12, "in" }, // 229 x 305 mm
+ { "Arch B", 12, 18, "in" }, // 305 x 457 mm
+ { "Arch C", 18, 24, "in" }, // 457 x 610 mm
+ { "Arch D", 24, 36, "in" }, // 610 x 914 mm
+ { "Arch E", 36, 48, "in" }, // 914 x 1219 mm
+ { "Arch E1", 30, 42, "in" }, // 762 x 1067 mm
/*
* The above list of Arch sizes were taken from the following site:
@@ -217,7 +218,7 @@ static PaperSizeRec const inkscape_papers[] = {
* September 2009 - DAK
*/
- { NULL, 0, 0, SP_UNIT_PX },
+ { NULL, 0, 0, "px" },
};
@@ -226,10 +227,6 @@ static PaperSizeRec const inkscape_papers[] = {
//# P A G E S I Z E R
//########################################################################
-//The default unit for this widget and its calculations
-static const SPUnit _px_unit = sp_unit_get_by_id (SP_UNIT_PX);
-
-
/**
* Constructor
*/
@@ -280,13 +277,8 @@ PageSizer::PageSizer(Registry & _wr)
char formatBuf[80];
snprintf(formatBuf, 79, "%0.1f x %0.1f", p->smaller, p->larger);
Glib::ustring desc = formatBuf;
- if (p->unit == SP_UNIT_IN)
- desc.append(" in");
- else if (p->unit == SP_UNIT_MM)
- desc.append(" mm");
- else if (p->unit == SP_UNIT_PX)
- desc.append(" px");
- PaperSize paper(name, p->smaller, p->larger, p->unit);
+ desc.append(" " + p->unit);
+ PaperSize paper(name, p->smaller, p->larger, unit_table.getUnit(p->unit));
_paperSizeTable[name] = paper;
Gtk::TreeModel::Row row = *(_paperSizeListStore->append());
row[_paperSizeListColumns.nameColumn] = name;
@@ -320,9 +312,9 @@ PageSizer::PageSizer(Registry & _wr)
SPNamedView *nv = sp_desktop_namedview(dt);
_wr.setUpdating (true);
if (nv->units) {
- _dimensionUnits.setUnit(nv->units);
+ _dimensionUnits.setUnit(nv->units->abbr);
} else if (nv->doc_units) {
- _dimensionUnits.setUnit(nv->doc_units);
+ _dimensionUnits.setUnit(nv->doc_units->abbr);
}
_wr.setUpdating (false);
@@ -450,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();
@@ -462,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) {
@@ -481,14 +474,16 @@ PageSizer::setDim (double w, double h, bool changeList)
_changedw_connection.block();
_changedh_connection.block();
+ _unit = w.unit->abbr;
+
if (SP_ACTIVE_DESKTOP && !_widgetRegistry->isUpdating()) {
SPDocument *doc = sp_desktop_document(SP_ACTIVE_DESKTOP);
- double const old_height = doc->getHeight();
- doc->setWidth (w, &_px_unit);
- doc->setHeight (h, &_px_unit);
+ 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"));
}
@@ -511,9 +506,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();
@@ -555,12 +551,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());
@@ -569,9 +565,8 @@ PageSizer::find_paper_size (double w, double h) const
for (iter = _paperSizeTable.begin() ;
iter != _paperSizeTable.end() ; ++iter) {
PaperSize paper = iter->second;
- SPUnit const &i_unit = sp_unit_get_by_id(paper.unit);
- double smallX = sp_units_get_pixels(paper.smaller, i_unit);
- double largeX = sp_units_get_pixels(paper.larger, i_unit);
+ double smallX = Inkscape::Util::Quantity::convert(paper.smaller, paper.unit, w.unit);
+ double largeX = Inkscape::Util::Quantity::convert(paper.larger, paper.unit, w.unit);
g_return_val_if_fail(smallX <= largeX, _paperSizeListStore->children().end());
@@ -651,8 +646,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
@@ -662,10 +657,6 @@ PageSizer::on_paper_size_list_changed()
_landscape = _landscapeButton.get_active();
}
- SPUnit const &src_unit = sp_unit_get_by_id (paper.unit);
- sp_convert_distance (&w, &src_unit, &_px_unit);
- sp_convert_distance (&h, &src_unit, &_px_unit);
-
if (_landscape)
setDim (h, w, false);
else
@@ -682,8 +673,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);
}
@@ -698,8 +689,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);
}
@@ -712,11 +703,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 d1fbb56e0..dc8e34d82 100644
--- a/src/ui/widget/page-sizer.h
+++ b/src/ui/widget/page-sizer.h
@@ -18,7 +18,7 @@
#include "ui/widget/registered-widget.h"
#include <sigc++/sigc++.h>
-#include "helper/units.h"
+#include "util/units.h"
#include <gtkmm/alignment.h>
#include <gtkmm/expander.h>
@@ -64,7 +64,7 @@ public:
PaperSize(const Glib::ustring &nameArg,
double smallerArg,
double largerArg,
- SPUnitId unitArg)
+ Inkscape::Util::Unit const *unitArg)
{
name = nameArg;
smaller = smallerArg;
@@ -108,7 +108,7 @@ public:
/**
* The units (px, pt, mm, etc) of this specification
*/
- SPUnitId unit;
+ Inkscape::Util::Unit const *unit; /// pointer to object in UnitTable, do not delete
private:
@@ -117,7 +117,7 @@ private:
name = "";
smaller = 0.0;
larger = 0.0;
- unit = SP_UNIT_PX;
+ unit = unit_table.getUnit("px");
}
void assign(const PaperSize &other)
@@ -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/preferences-widget.cpp b/src/ui/widget/preferences-widget.cpp
index 567f29f91..3ba00c083 100644
--- a/src/ui/widget/preferences-widget.cpp
+++ b/src/ui/widget/preferences-widget.cpp
@@ -354,7 +354,7 @@ void PrefSpinUnit::on_my_value_changed()
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
if (getWidget()->get_visible()) //only take action if user changed value
{
- prefs->setDoubleUnit(_prefs_path, getValue(getUnit().abbr), getUnit().abbr);
+ prefs->setDoubleUnit(_prefs_path, getValue(getUnit()->abbr), getUnit()->abbr);
}
}
diff --git a/src/ui/widget/registered-widget.cpp b/src/ui/widget/registered-widget.cpp
index ea2bac867..ae6a7d1e0 100644
--- a/src/ui/widget/registered-widget.cpp
+++ b/src/ui/widget/registered-widget.cpp
@@ -27,7 +27,6 @@
#include "ui/widget/random.h"
#include "widgets/spinbutton-events.h"
-#include "helper/units.h"
#include "xml/repr.h"
#include "svg/svg-color.h"
#include "svg/stringstream.h"
@@ -118,9 +117,9 @@ RegisteredUnitMenu::RegisteredUnitMenu (const Glib::ustring& label, const Glib::
}
void
-RegisteredUnitMenu::setUnit (const SPUnit* unit)
+RegisteredUnitMenu::setUnit (Glib::ustring unit)
{
- getUnitMenu()->setUnit (sp_unit_get_abbreviation (unit));
+ getUnitMenu()->setUnit(unit);
}
void
diff --git a/src/ui/widget/registered-widget.h b/src/ui/widget/registered-widget.h
index fa35b815e..883a9e1a2 100644
--- a/src/ui/widget/registered-widget.h
+++ b/src/ui/widget/registered-widget.h
@@ -32,7 +32,6 @@
#include <gtkmm/checkbutton.h>
-struct SPUnit;
class SPDocument;
namespace Gtk {
@@ -128,6 +127,7 @@ private:
repr = NULL;
doc = NULL;
write_undo = false;
+ event_type = -1;
}
};
@@ -166,8 +166,8 @@ public:
Inkscape::XML::Node* repr_in = NULL,
SPDocument *doc_in = NULL );
- void setUnit (const SPUnit*);
- Unit getUnit() const { return static_cast<UnitMenu*>(_widget)->getUnit(); };
+ void setUnit (const Glib::ustring);
+ Unit const * getUnit() const { return static_cast<UnitMenu*>(_widget)->getUnit(); };
UnitMenu* getUnitMenu() const { return static_cast<UnitMenu*>(_widget); };
sigc::connection _changed_connection;
diff --git a/src/ui/widget/rendering-options.cpp b/src/ui/widget/rendering-options.cpp
index f26e71553..d6248df69 100644
--- a/src/ui/widget/rendering-options.cpp
+++ b/src/ui/widget/rendering-options.cpp
@@ -13,7 +13,7 @@
#endif
#include "rendering-options.h"
-#include "unit-constants.h"
+#include "util/units.h"
#include <glibmm/i18n.h>
namespace Inkscape {
@@ -59,8 +59,8 @@ RenderingOptions::RenderingOptions () :
_radio_bitmap.signal_toggled().connect(sigc::mem_fun(*this, &RenderingOptions::_toggled));
// configure default DPI
- _dpi.setRange(PT_PER_IN,2400.0);
- _dpi.setValue(PT_PER_IN);
+ _dpi.setRange(Inkscape::Util::Quantity::convert(1, "in", "pt"),2400.0);
+ _dpi.setValue(Inkscape::Util::Quantity::convert(1, "in", "pt"));
_dpi.setIncrements(1.0,10.0);
_dpi.setDigits(0);
_dpi.update();
diff --git a/src/ui/widget/scalar-unit.cpp b/src/ui/widget/scalar-unit.cpp
index 99ff70846..4fa1a7584 100644
--- a/src/ui/widget/scalar-unit.cpp
+++ b/src/ui/widget/scalar-unit.cpp
@@ -16,6 +16,8 @@
#include "scalar-unit.h"
#include "spinbutton.h"
+using Inkscape::Util::unit_table;
+
namespace Inkscape {
namespace UI {
namespace Widget {
@@ -100,7 +102,7 @@ void ScalarUnit::resetUnitType(UnitType unit_type)
lastUnits = _unit_menu->getUnitAbbr();
}
-Unit ScalarUnit::getUnit() const
+Unit const * ScalarUnit::getUnit() const
{
g_assert(_unit_menu != NULL);
return _unit_menu->getUnit();
@@ -226,14 +228,13 @@ void ScalarUnit::on_unit_changed()
Glib::ustring abbr = _unit_menu->getUnitAbbr();
_suffix->set_label(abbr);
- Inkscape::Util::UnitTable &table = _unit_menu->getUnitTable();
- Inkscape::Util::Unit new_unit = (table.getUnit(abbr));
- Inkscape::Util::Unit old_unit = (table.getUnit(lastUnits));
+ Inkscape::Util::Unit const *new_unit = unit_table.getUnit(abbr);
+ Inkscape::Util::Unit const *old_unit = unit_table.getUnit(lastUnits);
double convertedVal = 0;
- if (old_unit.type == UNIT_TYPE_DIMENSIONLESS && new_unit.type == UNIT_TYPE_LINEAR) {
+ if (old_unit->type == UNIT_TYPE_DIMENSIONLESS && new_unit->type == UNIT_TYPE_LINEAR) {
convertedVal = PercentageToAbsolute(Scalar::getValue());
- } else if (old_unit.type == UNIT_TYPE_LINEAR && new_unit.type == UNIT_TYPE_DIMENSIONLESS) {
+ } else if (old_unit->type == UNIT_TYPE_LINEAR && new_unit->type == UNIT_TYPE_DIMENSIONLESS) {
convertedVal = AbsoluteToPercentage(Scalar::getValue());
} else {
double conversion = _unit_menu->getConversion(lastUnits);
diff --git a/src/ui/widget/scalar-unit.h b/src/ui/widget/scalar-unit.h
index 4f22f438c..9e310d3bd 100644
--- a/src/ui/widget/scalar-unit.h
+++ b/src/ui/widget/scalar-unit.h
@@ -82,7 +82,7 @@ public:
/**
* Gets the object for the currently selected unit.
*/
- Unit getUnit() const;
+ Unit const * getUnit() const;
/**
* Gets the UnitType ID for the unit.
diff --git a/src/ui/widget/selected-style.cpp b/src/ui/widget/selected-style.cpp
index 18dbb984b..3a6b0c7df 100644
--- a/src/ui/widget/selected-style.cpp
+++ b/src/ui/widget/selected-style.cpp
@@ -24,8 +24,8 @@
#include "style.h"
#include "desktop-style.h"
#include "sp-namedview.h"
-#include "sp-linear-gradient-fns.h"
-#include "sp-radial-gradient-fns.h"
+#include "sp-linear-gradient.h"
+#include "sp-radial-gradient.h"
#include "sp-pattern.h"
#include "ui/dialog/dialog-manager.h"
#include "ui/dialog/fill-and-stroke.h"
@@ -50,6 +50,9 @@
#include "pixmaps/cursor-adj-a.xpm"
#include "sp-cursor.h"
#include "gradient-chemistry.h"
+#include "util/units.h"
+
+using Inkscape::Util::unit_table;
static gdouble const _sw_presets[] = { 32 , 16 , 10 , 8 , 6 , 4 , 3 , 2 , 1.5 , 1 , 0.75 , 0.5 , 0.25 , 0.1 };
static gchar const *const _sw_presets_str[] = {"32", "16", "10", "8", "6", "4", "3", "2", "1.5", "1", "0.75", "0.5", "0.25", "0.1"};
@@ -306,15 +309,17 @@ SelectedStyle::SelectedStyle(bool /*layout*/)
{
int row = 0;
- // List of units should match with Fill/Stroke dialog stroke style width list
- for (GSList *l = sp_unit_get_list(SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE); l != NULL; l = l->next) {
- SPUnit const *u = static_cast<SPUnit*>(l->data);
+ Inkscape::Util::UnitTable::UnitMap m = unit_table.units(Inkscape::Util::UNIT_TYPE_LINEAR);
+ Inkscape::Util::UnitTable::UnitMap::iterator iter = m.begin();
+ while(iter != m.end()) {
Gtk::RadioMenuItem *mi = Gtk::manage(new Gtk::RadioMenuItem(_sw_group));
- mi->add(*(new Gtk::Label(u->abbr, 0.0, 0.5)));
+ mi->add(*(new Gtk::Label(iter->first, 0.0, 0.5)));
_unit_mis = g_slist_append(_unit_mis, mi);
- mi->signal_activate().connect(sigc::bind<SPUnitId>(sigc::mem_fun(*this, &SelectedStyle::on_popup_units), u->unit_id));
+ Inkscape::Util::Unit const *u = unit_table.getUnit(iter->first);
+ mi->signal_activate().connect(sigc::bind<Inkscape::Util::Unit const *>(sigc::mem_fun(*this, &SelectedStyle::on_popup_units), u));
_popup_sw.attach(*mi, 0,1, row, row+1);
row++;
+ ++iter;
}
_popup_sw.attach(*(new Gtk::SeparatorMenuItem()), 0,1, row, row+1);
@@ -476,13 +481,13 @@ SelectedStyle::setDesktop(SPDesktop *desktop)
this )
));
- _sw_unit = const_cast<SPUnit*>(sp_desktop_namedview(desktop)->doc_units);
+ _sw_unit = sp_desktop_namedview(desktop)->doc_units;
// Set the doc default unit active in the units list
gint length = g_slist_length(_unit_mis);
for (int i = 0; i < length; i++) {
Gtk::RadioMenuItem *mi = (Gtk::RadioMenuItem *) g_slist_nth_data(_unit_mis, i);
- if (mi && mi->get_label() == Glib::ustring(_sw_unit->abbr)) {
+ if (mi && mi->get_label() == _sw_unit->abbr) {
mi->set_active();
break;
}
@@ -926,8 +931,8 @@ SelectedStyle::on_opacity_click(GdkEventButton *event)
return false;
}
-void SelectedStyle::on_popup_units(SPUnitId id) {
- _sw_unit = (SPUnit *) &(sp_unit_get_by_id(id));
+void SelectedStyle::on_popup_units(Inkscape::Util::Unit const *unit) {
+ _sw_unit = unit;
update();
}
@@ -935,7 +940,7 @@ void SelectedStyle::on_popup_preset(int i) {
SPCSSAttr *css = sp_repr_css_attr_new ();
gdouble w;
if (_sw_unit) {
- w = sp_units_get_pixels (_sw_presets[i], *_sw_unit);
+ w = Inkscape::Util::Quantity::convert(_sw_presets[i], _sw_unit, "px");
} else {
w = _sw_presets[i];
}
@@ -1114,7 +1119,7 @@ SelectedStyle::update()
{
double w;
if (_sw_unit) {
- w = sp_pixels_get_units(query->stroke_width.computed, *_sw_unit);
+ w = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", _sw_unit);
} else {
w = query->stroke_width.computed;
}
@@ -1128,7 +1133,7 @@ SelectedStyle::update()
{
gchar *str = g_strdup_printf(_("Stroke width: %.5g%s%s"),
w,
- _sw_unit? sp_unit_get_abbreviation(_sw_unit) : "px",
+ _sw_unit? _sw_unit->abbr.c_str() : "px",
(result_sw == QUERY_STYLE_MULTIPLE_AVERAGED)?
_(" (averaged)") : "");
_stroke_width_place.set_tooltip_text(str);
@@ -1351,25 +1356,25 @@ RotateableSwatch::do_motion(double by, guint modifier) {
DocumentUndo::maybeDone(sp_desktop_document(parent->getDesktop()), undokey,
SP_VERB_DIALOG_FILL_STROKE, (_("Adjust alpha")));
double ch = hsla[3];
- parent->getDesktop()->event_context->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("Adjusting <b>alpha</b>: was %.3g, now <b>%.3g</b> (diff %.3g); with <b>Ctrl</b> to adjust lightness, with <b>Shift</b> to adjust saturation, without modifiers to adjust hue"), ch - diff, ch, diff);
+ parent->getDesktop()->event_context->message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("Adjusting <b>alpha</b>: was %.3g, now <b>%.3g</b> (diff %.3g); with <b>Ctrl</b> to adjust lightness, with <b>Shift</b> to adjust saturation, without modifiers to adjust hue"), ch - diff, ch, diff);
} else if (modifier == 2) { // saturation
DocumentUndo::maybeDone(sp_desktop_document(parent->getDesktop()), undokey,
SP_VERB_DIALOG_FILL_STROKE, (_("Adjust saturation")));
double ch = hsla[1];
- parent->getDesktop()->event_context->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("Adjusting <b>saturation</b>: was %.3g, now <b>%.3g</b> (diff %.3g); with <b>Ctrl</b> to adjust lightness, with <b>Alt</b> to adjust alpha, without modifiers to adjust hue"), ch - diff, ch, diff);
+ parent->getDesktop()->event_context->message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("Adjusting <b>saturation</b>: was %.3g, now <b>%.3g</b> (diff %.3g); with <b>Ctrl</b> to adjust lightness, with <b>Alt</b> to adjust alpha, without modifiers to adjust hue"), ch - diff, ch, diff);
} else if (modifier == 1) { // lightness
DocumentUndo::maybeDone(sp_desktop_document(parent->getDesktop()), undokey,
SP_VERB_DIALOG_FILL_STROKE, (_("Adjust lightness")));
double ch = hsla[2];
- parent->getDesktop()->event_context->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("Adjusting <b>lightness</b>: was %.3g, now <b>%.3g</b> (diff %.3g); with <b>Shift</b> to adjust saturation, with <b>Alt</b> to adjust alpha, without modifiers to adjust hue"), ch - diff, ch, diff);
+ parent->getDesktop()->event_context->message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("Adjusting <b>lightness</b>: was %.3g, now <b>%.3g</b> (diff %.3g); with <b>Shift</b> to adjust saturation, with <b>Alt</b> to adjust alpha, without modifiers to adjust hue"), ch - diff, ch, diff);
} else { // hue
DocumentUndo::maybeDone(sp_desktop_document(parent->getDesktop()), undokey,
SP_VERB_DIALOG_FILL_STROKE, (_("Adjust hue")));
double ch = hsla[0];
- parent->getDesktop()->event_context->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("Adjusting <b>hue</b>: was %.3g, now <b>%.3g</b> (diff %.3g); with <b>Shift</b> to adjust saturation, with <b>Alt</b> to adjust alpha, with <b>Ctrl</b> to adjust lightness"), ch - diff, ch, diff);
+ parent->getDesktop()->event_context->message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("Adjusting <b>hue</b>: was %.3g, now <b>%.3g</b> (diff %.3g); with <b>Shift</b> to adjust saturation, with <b>Alt</b> to adjust alpha, with <b>Ctrl</b> to adjust lightness"), ch - diff, ch, diff);
}
}
@@ -1424,7 +1429,7 @@ RotateableSwatch::do_release(double by, guint modifier) {
undokey = "ssrot1";
}
- parent->getDesktop()->event_context->_message_context->clear();
+ parent->getDesktop()->event_context->message_context->clear();
startcolor_set = false;
}
@@ -1490,7 +1495,7 @@ RotateableStrokeWidth::do_motion(double by, guint modifier) {
double diff = value_adjust(startvalue, by, modifier, false);
DocumentUndo::maybeDone(sp_desktop_document(parent->getDesktop()), undokey,
SP_VERB_DIALOG_FILL_STROKE, (_("Adjust stroke width")));
- parent->getDesktop()->event_context->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("Adjusting <b>stroke width</b>: was %.3g, now <b>%.3g</b> (diff %.3g)"), startvalue, startvalue + diff, diff);
+ parent->getDesktop()->event_context->message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("Adjusting <b>stroke width</b>: was %.3g, now <b>%.3g</b> (diff %.3g)"), startvalue, startvalue + diff, diff);
}
}
@@ -1511,7 +1516,7 @@ RotateableStrokeWidth::do_release(double by, guint modifier) {
} else {
undokey = "swrot1";
}
- parent->getDesktop()->event_context->_message_context->clear();
+ parent->getDesktop()->event_context->message_context->clear();
}
void
diff --git a/src/ui/widget/selected-style.h b/src/ui/widget/selected-style.h
index e5bc4f883..21e5575ed 100644
--- a/src/ui/widget/selected-style.h
+++ b/src/ui/widget/selected-style.h
@@ -41,12 +41,15 @@
#include <sigc++/sigc++.h>
#include "rotateable.h"
-#include "helper/units.h"
class SPDesktop;
-struct SPUnit;
namespace Inkscape {
+
+namespace Util {
+ class Unit;
+}
+
namespace UI {
namespace Widget {
@@ -273,11 +276,11 @@ protected:
Gtk::Menu _popup_sw;
Gtk::RadioButtonGroup _sw_group;
GSList *_unit_mis;
- void on_popup_units(SPUnitId id);
+ void on_popup_units(Inkscape::Util::Unit const *u);
void on_popup_preset(int i);
Gtk::MenuItem _popup_sw_remove;
- SPUnit *_sw_unit;
+ Inkscape::Util::Unit const *_sw_unit; /// points to object in UnitTable, do not delete
void *_drop[2];
bool _dropEnabled[2];
diff --git a/src/ui/widget/spinbutton.cpp b/src/ui/widget/spinbutton.cpp
index c107979a8..6cbc15c1b 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 const *unit = NULL;
+ 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) ) {
+ 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;
@@ -57,7 +65,7 @@ int SpinButton::on_input(double* newvalue)
bool SpinButton::on_my_focus_in_event(GdkEventFocus* /*event*/)
{
- on_focus_in_value = get_value();
+ _on_focus_in_value = get_value();
return false; // do not consume the event
}
@@ -84,7 +92,7 @@ bool SpinButton::on_my_key_press_event(GdkEventKey* event)
void SpinButton::undo()
{
- set_value(on_focus_in_value);
+ set_value(_on_focus_in_value);
}
diff --git a/src/ui/widget/spinbutton.h b/src/ui/widget/spinbutton.h
index fe5d699e7..812b5f515 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),
@@ -37,7 +38,9 @@ class SpinButton : public Gtk::SpinButton
public:
SpinButton(double climb_rate = 0.0, guint digits = 0)
: Gtk::SpinButton(climb_rate, digits),
- _unit_menu(NULL)
+ _unit_menu(NULL),
+ _unit_tracker(NULL),
+ _on_focus_in_value(0.)
{
connect_signals();
};
@@ -47,7 +50,9 @@ public:
explicit SpinButton(Gtk::Adjustment& adjustment, double climb_rate = 0.0, guint digits = 0)
#endif
: Gtk::SpinButton(adjustment, climb_rate, digits),
- _unit_menu(NULL)
+ _unit_menu(NULL),
+ _unit_tracker(NULL),
+ _on_focus_in_value(0.)
{
connect_signals();
};
@@ -55,9 +60,13 @@ public:
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.
+ double _on_focus_in_value;
void connect_signals();
@@ -90,8 +99,6 @@ protected:
*/
void undo();
- double on_focus_in_value;
-
private:
// noncopyable
SpinButton(const SpinButton&);
diff --git a/src/ui/widget/style-swatch.cpp b/src/ui/widget/style-swatch.cpp
index aedab3fa5..a33c1d09f 100644
--- a/src/ui/widget/style-swatch.cpp
+++ b/src/ui/widget/style-swatch.cpp
@@ -20,13 +20,13 @@
#include "ui/widget/color-preview.h"
#include "style.h"
-#include "sp-linear-gradient-fns.h"
-#include "sp-radial-gradient-fns.h"
+#include "sp-linear-gradient.h"
+#include "sp-radial-gradient.h"
#include "sp-pattern.h"
#include "xml/repr.h"
#include "xml/sp-css-attr.h"
#include "widgets/widget-sizes.h"
-#include "helper/units.h"
+#include "util/units.h"
#include "helper/action.h"
#include "helper/action-context.h"
#include "preferences.h"
@@ -333,7 +333,7 @@ void StyleSwatch::setStyle(SPStyle *query)
if (has_stroke) {
double w;
if (_sw_unit) {
- w = sp_pixels_get_units(query->stroke_width.computed, *_sw_unit);
+ w = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", _sw_unit);
} else {
w = query->stroke_width.computed;
}
@@ -346,7 +346,7 @@ void StyleSwatch::setStyle(SPStyle *query)
{
gchar *str = g_strdup_printf(_("Stroke width: %.5g%s"),
w,
- _sw_unit? sp_unit_get_abbreviation(_sw_unit) : "px");
+ _sw_unit? _sw_unit->abbr.c_str() : "px");
_stroke_width_place.set_tooltip_text(str);
g_free (str);
}
diff --git a/src/ui/widget/style-swatch.h b/src/ui/widget/style-swatch.h
index 6bdb5e248..6da58a2dd 100644
--- a/src/ui/widget/style-swatch.h
+++ b/src/ui/widget/style-swatch.h
@@ -30,7 +30,6 @@
#include "button.h"
#include "preferences.h"
-struct SPUnit;
struct SPStyle;
class SPCSSAttr;
@@ -43,6 +42,11 @@ class Table;
}
namespace Inkscape {
+
+namespace Util {
+ class Unit;
+}
+
namespace UI {
namespace Widget {
@@ -93,7 +97,7 @@ private:
Gtk::EventBox _stroke_width_place;
Gtk::Label _stroke_width;
- SPUnit *_sw_unit;
+ Inkscape::Util::Unit *_sw_unit;
friend class ToolObserver;
};
diff --git a/src/ui/widget/unit-menu.cpp b/src/ui/widget/unit-menu.cpp
index 18b7bcab9..7416a2f02 100644
--- a/src/ui/widget/unit-menu.cpp
+++ b/src/ui/widget/unit-menu.cpp
@@ -15,6 +15,8 @@
#include "unit-menu.h"
+using Inkscape::Util::unit_table;
+
namespace Inkscape {
namespace UI {
namespace Widget {
@@ -30,15 +32,13 @@ UnitMenu::~UnitMenu() {
bool UnitMenu::setUnitType(UnitType unit_type)
{
// Expand the unit widget with unit entries from the unit table
- UnitTable::UnitMap m = _unit_table.units(unit_type);
- UnitTable::UnitMap::iterator iter = m.begin();
- while(iter != m.end()) {
- Glib::ustring text = (*iter).first;
- append(text);
- ++iter;
+ UnitTable::UnitMap m = unit_table.units(unit_type);
+
+ for (UnitTable::UnitMap::iterator i = m.begin(); i != m.end(); ++i) {
+ append(i->first);
}
_type = unit_type;
- set_active_text(_unit_table.primary(unit_type));
+ set_active_text(unit_table.primary(unit_type));
return true;
}
@@ -52,17 +52,17 @@ bool UnitMenu::resetUnitType(UnitType unit_type)
void UnitMenu::addUnit(Unit const& u)
{
- _unit_table.addUnit(u, false);
+ unit_table.addUnit(u, false);
append(u.abbr);
}
-Unit UnitMenu::getUnit() const
+Unit const * UnitMenu::getUnit() const
{
if (get_active_text() == "") {
g_assert(_type != UNIT_TYPE_NONE);
- return _unit_table.getUnit(_unit_table.primary(_type));
+ return unit_table.getUnit(unit_table.primary(_type));
}
- return _unit_table.getUnit(get_active_text());
+ return unit_table.getUnit(get_active_text());
}
bool UnitMenu::setUnit(Glib::ustring const & unit)
@@ -79,27 +79,27 @@ Glib::ustring UnitMenu::getUnitAbbr() const
if (get_active_text() == "") {
return "";
}
- return getUnit().abbr;
+ return getUnit()->abbr;
}
UnitType UnitMenu::getUnitType() const
{
- return getUnit().type;
+ return getUnit()->type;
}
double UnitMenu::getUnitFactor() const
{
- return getUnit().factor;
+ return getUnit()->factor;
}
int UnitMenu::getDefaultDigits() const
{
- return getUnit().defaultDigits();
+ return getUnit()->defaultDigits();
}
double UnitMenu::getDefaultStep() const
{
- int factor_digits = -1*int(log10(getUnit().factor));
+ int factor_digits = -1*int(log10(getUnit()->factor));
return pow(10.0, factor_digits);
}
@@ -110,19 +110,20 @@ double UnitMenu::getDefaultPage() const
double UnitMenu::getConversion(Glib::ustring const &new_unit_abbr, Glib::ustring const &old_unit_abbr) const
{
- double old_factor = getUnit().factor;
- if (old_unit_abbr != "no_unit")
- old_factor = _unit_table.getUnit(old_unit_abbr).factor;
- Unit new_unit = _unit_table.getUnit(new_unit_abbr);
+ double old_factor = getUnit()->factor;
+ if (old_unit_abbr != "no_unit") {
+ old_factor = unit_table.getUnit(old_unit_abbr)->factor;
+ }
+ Unit const * new_unit = unit_table.getUnit(new_unit_abbr);
// Catch the case of zero or negative unit factors (error!)
if (old_factor < 0.0000001 ||
- new_unit.factor < 0.0000001) {
+ new_unit->factor < 0.0000001) {
// TODO: Should we assert here?
return 0.00;
}
- return old_factor / new_unit.factor;
+ return old_factor / new_unit->factor;
}
bool UnitMenu::isAbsolute() const
diff --git a/src/ui/widget/unit-menu.h b/src/ui/widget/unit-menu.h
index 3104d5aef..114c536c9 100644
--- a/src/ui/widget/unit-menu.h
+++ b/src/ui/widget/unit-menu.h
@@ -74,7 +74,7 @@ public:
* Returns the Unit object corresponding to the current selection
* in the dropdown widget.
*/
- Unit getUnit() const;
+ Unit const * getUnit() const;
/**
* Returns the abbreviated unit name of the selected unit.
@@ -127,10 +127,7 @@ public:
*/
bool isRadial() const;
- UnitTable &getUnitTable() {return _unit_table;}
-
protected:
- UnitTable _unit_table;
UnitType _type;
};
diff --git a/src/ui/widget/unit-tracker.cpp b/src/ui/widget/unit-tracker.cpp
new file mode 100644
index 000000000..67eb1f48d
--- /dev/null
+++ b/src/ui/widget/unit-tracker.cpp
@@ -0,0 +1,264 @@
+/*
+ * Inkscape::UI::Widget::UnitTracker
+ * Simple mediator to synchronize changes to unit menus
+ *
+ * Authors:
+ * Jon A. Cruz <jon@joncruz.org>
+ * Matthew Petroff <matthew@mpetroff.net>
+ *
+ * Copyright (C) 2007 Jon A. Cruz
+ * Copyright (C) 2013 Matthew Petroff
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "unit-tracker.h"
+#include "ege-select-one-action.h"
+
+#define COLUMN_STRING 0
+
+using Inkscape::Util::UnitTable;
+using Inkscape::Util::unit_table;
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+UnitTracker::UnitTracker(UnitType unit_type) :
+ _active(0),
+ _isUpdating(false),
+ _activeUnit(NULL),
+ _activeUnitInitialized(false),
+ _store(0),
+ _unitList(0),
+ _actionList(0),
+ _adjList(0),
+ _priorValues()
+{
+ _store = gtk_list_store_new(1, G_TYPE_STRING);
+
+ GtkTreeIter iter;
+ UnitTable::UnitMap m = unit_table.units(unit_type);
+
+
+ for (UnitTable::UnitMap::iterator m_iter = m.begin(); m_iter != m.end(); ++m_iter) {
+ Glib::ustring text = m_iter->first;
+ gtk_list_store_append(_store, &iter);
+ gtk_list_store_set(_store, &iter, COLUMN_STRING, text.c_str(), -1);
+ }
+ gint count = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(_store), 0);
+ if ((count > 0) && (_active > count)) {
+ _setActive(--count);
+ } else {
+ _setActive(_active);
+ }
+}
+
+UnitTracker::~UnitTracker()
+{
+ // Unhook weak references to GtkActions
+ while (_actionList) {
+ g_signal_handlers_disconnect_by_func(G_OBJECT(_actionList->data), (gpointer) _unitChangedCB, this);
+ g_object_weak_unref(G_OBJECT(_actionList->data), _actionFinalizedCB, this);
+ _actionList = g_slist_delete_link(_actionList, _actionList);
+ }
+
+ // Unhook weak references to GtkAdjustments
+ while (_adjList) {
+ g_object_weak_unref(G_OBJECT(_adjList->data), _adjustmentFinalizedCB, this);
+ _adjList = g_slist_delete_link(_adjList, _adjList);
+ }
+}
+
+bool UnitTracker::isUpdating() const
+{
+ return _isUpdating;
+}
+
+Inkscape::Util::Unit const * UnitTracker::getActiveUnit() const
+{
+ return _activeUnit;
+}
+
+void UnitTracker::setActiveUnit(Inkscape::Util::Unit const *unit)
+{
+ if (unit) {
+ GtkTreeIter iter;
+ int index = 0;
+ gboolean found = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(_store), &iter);
+ while (found) {
+ gchar *storedUnit = 0;
+ gtk_tree_model_get(GTK_TREE_MODEL(_store), &iter, COLUMN_STRING, &storedUnit, -1);
+ if (storedUnit && (!unit->abbr.compare(storedUnit))) {
+ _setActive(index);
+ break;
+ }
+
+ found = gtk_tree_model_iter_next(GTK_TREE_MODEL(_store), &iter);
+ index++;
+ }
+ }
+}
+
+void UnitTracker::setActiveUnitByAbbr(gchar const *abbr)
+{
+ Inkscape::Util::Unit const *u = unit_table.getUnit(abbr);
+ setActiveUnit(u);
+}
+
+void UnitTracker::addAdjustment(GtkAdjustment *adj)
+{
+ if (!g_slist_find(_adjList, adj)) {
+ g_object_weak_ref(G_OBJECT(adj), _adjustmentFinalizedCB, this);
+ _adjList = g_slist_append(_adjList, adj);
+ }
+}
+
+void UnitTracker::addUnit(Inkscape::Util::Unit const *u)
+{
+ GtkTreeIter iter;
+ gtk_list_store_append(_store, &iter);
+ gtk_list_store_set(_store, &iter, COLUMN_STRING, u ? u->abbr.c_str() : "NULL", -1);
+}
+
+void UnitTracker::setFullVal(GtkAdjustment *adj, gdouble val)
+{
+ _priorValues[adj] = val;
+}
+
+GtkAction *UnitTracker::createAction(gchar const *name, gchar const *label, gchar const *tooltip)
+{
+ EgeSelectOneAction *act1 = ege_select_one_action_new(name, label, tooltip, NULL, GTK_TREE_MODEL(_store));
+ ege_select_one_action_set_label_column(act1, COLUMN_STRING);
+ if (_active) {
+ ege_select_one_action_set_active(act1, _active);
+ }
+
+ ege_select_one_action_set_appearance(act1, "minimal");
+ g_object_weak_ref(G_OBJECT(act1), _actionFinalizedCB, this);
+ g_signal_connect(G_OBJECT(act1), "changed", G_CALLBACK(_unitChangedCB), this);
+ _actionList = g_slist_append(_actionList, act1);
+
+ return GTK_ACTION(act1);
+}
+
+void UnitTracker::_unitChangedCB(GtkAction *action, gpointer data)
+{
+ if (action && data) {
+ EgeSelectOneAction *act = EGE_SELECT_ONE_ACTION(action);
+ gint active = ege_select_one_action_get_active(act);
+ UnitTracker *self = reinterpret_cast<UnitTracker *>(data);
+ self->_setActive(active);
+ }
+}
+
+void UnitTracker::_actionFinalizedCB(gpointer data, GObject *where_the_object_was)
+{
+ if (data && where_the_object_was) {
+ UnitTracker *self = reinterpret_cast<UnitTracker *>(data);
+ self->_actionFinalized(where_the_object_was);
+ }
+}
+
+void UnitTracker::_adjustmentFinalizedCB(gpointer data, GObject *where_the_object_was)
+{
+ if (data && where_the_object_was) {
+ UnitTracker *self = reinterpret_cast<UnitTracker *>(data);
+ self->_adjustmentFinalized(where_the_object_was);
+ }
+}
+
+void UnitTracker::_actionFinalized(GObject *where_the_object_was)
+{
+ GSList *target = g_slist_find(_actionList, where_the_object_was);
+ if (target) {
+ _actionList = g_slist_remove(_actionList, where_the_object_was);
+ } else {
+ g_warning("Received a finalization callback for unknown object %p", where_the_object_was);
+ }
+}
+
+void UnitTracker::_adjustmentFinalized(GObject *where_the_object_was)
+{
+ GSList *target = g_slist_find(_adjList, where_the_object_was);
+ if (target) {
+ _adjList = g_slist_remove(_adjList, where_the_object_was);
+ } else {
+ g_warning("Received a finalization callback for unknown object %p", where_the_object_was);
+ }
+}
+
+void UnitTracker::_setActive(gint active)
+{
+ if ( active != _active || !_activeUnitInitialized ) {
+ gint oldActive = _active;
+
+ GtkTreeIter iter;
+ gboolean found = gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(_store), &iter, NULL, oldActive);
+ if (found) {
+ gchar *abbr;
+ gtk_tree_model_get(GTK_TREE_MODEL(_store), &iter, COLUMN_STRING, &abbr, -1);
+ Inkscape::Util::Unit const *unit = unit_table.getUnit(abbr);
+
+ found = gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(_store), &iter, NULL, active);
+ if (found) {
+ gchar *newAbbr;
+ gtk_tree_model_get(GTK_TREE_MODEL(_store), &iter, COLUMN_STRING, &newAbbr, -1);
+ Inkscape::Util::Unit const *newUnit = unit_table.getUnit(newAbbr);
+ _activeUnit = newUnit;
+
+ if (_adjList) {
+ _fixupAdjustments(unit, newUnit);
+ }
+
+ } else {
+ g_warning("Did not find new unit");
+ }
+ } else {
+ g_warning("Did not find old unit");
+ }
+
+ _active = active;
+
+ for ( GSList *cur = _actionList ; cur ; cur = g_slist_next(cur) ) {
+ if (IS_EGE_SELECT_ONE_ACTION(cur->data)) {
+ EgeSelectOneAction *act = EGE_SELECT_ONE_ACTION(cur->data);
+ ege_select_one_action_set_active(act, active);
+ }
+ }
+
+ _activeUnitInitialized = true;
+ }
+}
+
+void UnitTracker::_fixupAdjustments(Inkscape::Util::Unit const *oldUnit, Inkscape::Util::Unit const *newUnit)
+{
+ _isUpdating = true;
+ for ( GSList *cur = _adjList ; cur ; cur = g_slist_next(cur) ) {
+ GtkAdjustment *adj = GTK_ADJUSTMENT(cur->data);
+ gdouble oldVal = gtk_adjustment_get_value(adj);
+ gdouble val = oldVal;
+
+ if ( (oldUnit->type != Inkscape::Util::UNIT_TYPE_DIMENSIONLESS)
+ && (newUnit->type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) )
+ {
+ val = newUnit->factor * 100;
+ _priorValues[adj] = Inkscape::Util::Quantity::convert(oldVal, oldUnit, "px");
+ } else if ( (oldUnit->type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS)
+ && (newUnit->type != Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) )
+ {
+ if (_priorValues.find(adj) != _priorValues.end()) {
+ val = Inkscape::Util::Quantity::convert(_priorValues[adj], "px", newUnit);
+ }
+ } else {
+ val = Inkscape::Util::Quantity::convert(oldVal, oldUnit, newUnit);
+ }
+
+ gtk_adjustment_set_value(adj, val);
+ }
+ _isUpdating = false;
+}
+
+} // namespace Widget
+} // namespace UI
+} // namespace Inkscape
diff --git a/src/ui/widget/unit-tracker.h b/src/ui/widget/unit-tracker.h
new file mode 100644
index 000000000..61bb556ef
--- /dev/null
+++ b/src/ui/widget/unit-tracker.h
@@ -0,0 +1,74 @@
+/*
+ * Inkscape::UI::Widget::UnitTracker
+ * Simple mediator to synchronize changes to unit menus
+ *
+ * Authors:
+ * Jon A. Cruz <jon@joncruz.org>
+ * Matthew Petroff <matthew@mpetroff.net>
+ *
+ * Copyright (C) 2007 Jon A. Cruz
+ * Copyright (C) 2013 Matthew Petroff
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef INKSCAPE_UI_WIDGET_UNIT_TRACKER_H
+#define INKSCAPE_UI_WIDGET_UNIT_TRACKER_H
+
+#include <map>
+#include <gtk/gtk.h>
+
+#include "util/units.h"
+
+using Inkscape::Util::Unit;
+using Inkscape::Util::UnitType;
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+class UnitTracker {
+public:
+ UnitTracker(UnitType unit_type);
+ virtual ~UnitTracker();
+
+ bool isUpdating() const;
+
+ void setActiveUnit(Inkscape::Util::Unit const *unit);
+ void setActiveUnitByAbbr(gchar const *abbr);
+ Inkscape::Util::Unit const * getActiveUnit() const;
+
+ void addUnit(Inkscape::Util::Unit const *u);
+ void addAdjustment(GtkAdjustment *adj);
+ void setFullVal(GtkAdjustment *adj, gdouble val);
+
+ GtkAction *createAction(gchar const *name, gchar const *label, gchar const *tooltip);
+
+protected:
+ UnitType _type;
+
+private:
+ static void _unitChangedCB(GtkAction *action, gpointer data);
+ static void _actionFinalizedCB(gpointer data, GObject *where_the_object_was);
+ static void _adjustmentFinalizedCB(gpointer data, GObject *where_the_object_was);
+ void _setActive(gint index);
+ void _fixupAdjustments(Inkscape::Util::Unit const *oldUnit, Inkscape::Util::Unit const *newUnit);
+ void _actionFinalized(GObject *where_the_object_was);
+ void _adjustmentFinalized(GObject *where_the_object_was);
+
+ gint _active;
+ bool _isUpdating;
+ Inkscape::Util::Unit const *_activeUnit;
+ bool _activeUnitInitialized;
+ GtkListStore *_store;
+ GSList *_unitList;
+ GSList *_actionList;
+ GSList *_adjList;
+ std::map <GtkAdjustment *, gdouble> _priorValues;
+};
+
+} // namespace Widget
+} // namespace UI
+} // namespace Inkscape
+
+#endif // INKSCAPE_UI_WIDGET_UNIT_TRACKER_H